Fix a code object memory corruption
The lifetime of the buffer given to hsa_code_object_reader_create_from_memory must exceed that of the code object reader. We need to create a copy of the code object binary memory (file) that is kept allocated until the code object reader is destroyed.
This commit is contained in:
@@ -200,7 +200,7 @@ public:
|
||||
std::function<void(hsa_code_object_reader_t*)>>;
|
||||
std::pair<
|
||||
std::mutex,
|
||||
std::vector<RAII_code_reader>> code_readers;
|
||||
std::vector<std::pair<std::unique_ptr<char[]>, RAII_code_reader>>> code_readers;
|
||||
|
||||
program_state_impl() {
|
||||
// Create placeholder for each agent for the per-agent members.
|
||||
@@ -390,8 +390,14 @@ public:
|
||||
};
|
||||
|
||||
RAII_code_reader tmp{new hsa_code_object_reader_t, cor_deleter};
|
||||
// The lifetime of the buffer must exceed that of the associated
|
||||
// code object reader. Create a copy of the file, which will be
|
||||
// released at the same time the code object reader is destroyed.
|
||||
std::unique_ptr<char[]> buffer(new char[file.size()]);
|
||||
memcpy(buffer.get(), file.data(), file.size());
|
||||
|
||||
hsa_code_object_reader_create_from_memory(
|
||||
file.data(), file.size(), tmp.get());
|
||||
buffer.get(), file.size(), tmp.get());
|
||||
|
||||
hsa_executable_load_agent_code_object(
|
||||
executable, agent, *tmp, nullptr, nullptr);
|
||||
@@ -399,7 +405,7 @@ public:
|
||||
hsa_executable_freeze(executable, nullptr);
|
||||
|
||||
std::lock_guard<std::mutex> lck{code_readers.first};
|
||||
code_readers.second.push_back(move(tmp));
|
||||
code_readers.second.emplace_back(move(buffer), move(tmp));
|
||||
}
|
||||
|
||||
|
||||
|
||||
Verwijs in nieuw issue
Block a user