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

Joseph Huber via libc-commits libc-commits at lists.llvm.org
Fri Dec 1 09:47:40 PST 2023


https://github.com/jhuber6 created https://github.com/llvm/llvm-project/pull/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.


>From 2ff9ccecca3b05f81ee23bf14aa35c8c1a0acd51 Mon Sep 17 00:00:00 2001
From: Joseph Huber <huberjn at outlook.com>
Date: Fri, 1 Dec 2023 11:46:24 -0600
Subject: [PATCH] [libc] Move the pointer to pin off the stack to the heap

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.
---
 libc/utils/gpu/loader/amdgpu/Loader.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libc/utils/gpu/loader/amdgpu/Loader.cpp b/libc/utils/gpu/loader/amdgpu/Loader.cpp
index a9a687656efcb39..d3d2c2b42080837 100644
--- a/libc/utils/gpu/loader/amdgpu/Loader.cpp
+++ b/libc/utils/gpu/loader/amdgpu/Loader.cpp
@@ -471,7 +471,7 @@ 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 = new void *;
   void *rpc_client_host = nullptr;
   if (hsa_status_t err =
           hsa_amd_memory_lock(&rpc_client_storage, sizeof(void *),



More information about the libc-commits mailing list