Skip to content

Commit 8bea804

Browse files
authored
[libc] Move the pointer to pin off the stack to the heap (#74118)
Summary: This may be problematic to pin a stack pointer. Allocate it via the OS allocator instead as the documentation suggests. For some reason, if you attempt to free this pointer after the memory region has been unlocked, it will return an invalid pointer.
1 parent 3693f44 commit 8bea804

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

libc/utils/gpu/loader/amdgpu/Loader.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -471,10 +471,10 @@ int load(int argc, char **argv, char **envp, void *image, size_t size,
471471
handle_error(err);
472472

473473
// Pin some memory we can use to obtain the address of the rpc client.
474-
void *rpc_client_storage = nullptr;
474+
void *rpc_client_storage = malloc(sizeof(void *));
475475
void *rpc_client_host = nullptr;
476476
if (hsa_status_t err =
477-
hsa_amd_memory_lock(&rpc_client_storage, sizeof(void *),
477+
hsa_amd_memory_lock(rpc_client_storage, sizeof(void *),
478478
/*agents=*/nullptr, 0, &rpc_client_host))
479479
handle_error(err);
480480

@@ -501,6 +501,7 @@ int load(int argc, char **argv, char **envp, void *image, size_t size,
501501
handle_error(err);
502502
if (hsa_status_t err = hsa_amd_memory_unlock(rpc_client_host))
503503
handle_error(err);
504+
free(rpc_client_storage);
504505

505506
// Obtain the GPU's fixed-frequency clock rate and copy it to the GPU.
506507
// If the clock_freq symbol is missing, no work to do.

0 commit comments

Comments
 (0)