[libc-commits] [libc] 8bea804 - [libc] Move the pointer to pin off the stack to the heap (#74118)

via libc-commits libc-commits at lists.llvm.org
Fri Dec 1 10:31:47 PST 2023


Author: Joseph Huber
Date: 2023-12-01T12:31:34-06:00
New Revision: 8bea804923a1b028e86b177caccb3258708ca01c

URL: https://github.com/llvm/llvm-project/commit/8bea804923a1b028e86b177caccb3258708ca01c
DIFF: https://github.com/llvm/llvm-project/commit/8bea804923a1b028e86b177caccb3258708ca01c.diff

LOG: [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.

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/libc/utils/gpu/loader/amdgpu/Loader.cpp b/libc/utils/gpu/loader/amdgpu/Loader.cpp
index a9a687656efcb39..61b86bcf9c7f8bb 100644
--- a/libc/utils/gpu/loader/amdgpu/Loader.cpp
+++ b/libc/utils/gpu/loader/amdgpu/Loader.cpp
@@ -471,10 +471,10 @@ int load(int argc, char **argv, char **envp, void *image, size_t size,
     handle_error(err);
 
   // Pin some memory we can use to obtain the address of the rpc client.
-  void *rpc_client_storage = nullptr;
+  void *rpc_client_storage = malloc(sizeof(void *));
   void *rpc_client_host = nullptr;
   if (hsa_status_t err =
-          hsa_amd_memory_lock(&rpc_client_storage, sizeof(void *),
+          hsa_amd_memory_lock(rpc_client_storage, sizeof(void *),
                               /*agents=*/nullptr, 0, &rpc_client_host))
     handle_error(err);
 
@@ -501,6 +501,7 @@ int load(int argc, char **argv, char **envp, void *image, size_t size,
     handle_error(err);
   if (hsa_status_t err = hsa_amd_memory_unlock(rpc_client_host))
     handle_error(err);
+  free(rpc_client_storage);
 
   // Obtain the GPU's fixed-frequency clock rate and copy it to the GPU.
   // If the clock_freq symbol is missing, no work to do.


        


More information about the libc-commits mailing list