From e01c43578cdd1d7629b6bc613d5debb0713a3b51 Mon Sep 17 00:00:00 2001 From: Sean Keely Date: Thu, 10 Nov 2016 02:58:59 -0600 Subject: [PATCH] Restrict stack usage in interop map to a more reasonable level. Change-Id: I663f262a391d1e7f8a6fc3028ea9acbe37d8bcf0 --- runtime/hsa-runtime/core/runtime/hsa_ext_amd.cpp | 7 ++++--- runtime/hsa-runtime/core/runtime/runtime.cpp | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/runtime/hsa-runtime/core/runtime/hsa_ext_amd.cpp b/runtime/hsa-runtime/core/runtime/hsa_ext_amd.cpp index a35d7368c6..4e4b2111e2 100644 --- a/runtime/hsa-runtime/core/runtime/hsa_ext_amd.cpp +++ b/runtime/hsa-runtime/core/runtime/hsa_ext_amd.cpp @@ -562,6 +562,7 @@ hsa_status_t hsa_amd_interop_map_buffer(uint32_t num_agents, uint32_t flags, size_t* size, void** ptr, size_t* metadata_size, const void** metadata) { + static const int tinyArraySize=8; IS_OPEN(); IS_BAD_PTR(agents); IS_BAD_PTR(size); @@ -569,9 +570,9 @@ hsa_status_t hsa_amd_interop_map_buffer(uint32_t num_agents, if (flags != 0) return HSA_STATUS_ERROR_INVALID_ARGUMENT; if (num_agents == 0) return HSA_STATUS_ERROR_INVALID_ARGUMENT; - core::Agent* short_agents[64]; + core::Agent* short_agents[tinyArraySize]; core::Agent** core_agents = short_agents; - if (num_agents > 64) { + if (num_agents > tinyArraySize) { core_agents = new core::Agent* [num_agents]; if (core_agents == NULL) return HSA_STATUS_ERROR_OUT_OF_RESOURCES; } @@ -586,7 +587,7 @@ hsa_status_t hsa_amd_interop_map_buffer(uint32_t num_agents, num_agents, core_agents, interop_handle, flags, size, ptr, metadata_size, metadata); - if (num_agents > 64) delete[] core_agents; + if (num_agents > tinyArraySize) delete[] core_agents; return ret; } diff --git a/runtime/hsa-runtime/core/runtime/runtime.cpp b/runtime/hsa-runtime/core/runtime/runtime.cpp index 1d5deea838..1384bd8d5b 100644 --- a/runtime/hsa-runtime/core/runtime/runtime.cpp +++ b/runtime/hsa-runtime/core/runtime/runtime.cpp @@ -590,16 +590,17 @@ hsa_status_t Runtime::InteropMap(uint32_t num_agents, Agent** agents, int interop_handle, uint32_t flags, size_t* size, void** ptr, size_t* metadata_size, const void** metadata) { + static const int tinyArraySize=8; HsaGraphicsResourceInfo info; - HSAuint32 short_nodes[64]; + HSAuint32 short_nodes[tinyArraySize]; HSAuint32* nodes = short_nodes; - if (num_agents > 64) { + if (num_agents > tinyArraySize) { nodes = new HSAuint32[num_agents]; if (nodes == NULL) return HSA_STATUS_ERROR_OUT_OF_RESOURCES; } MAKE_SCOPE_GUARD([&]() { - if (num_agents > 64) delete[] nodes; + if (num_agents > tinyArraySize) delete[] nodes; }); for (int i = 0; i < num_agents; i++)