From: Rémi Bernon rbernon@codeweavers.com
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/kernel32/heap.c | 10 ++++++++-- dlls/kernel32/tests/heap.c | 8 ++++++++ 2 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/dlls/kernel32/heap.c b/dlls/kernel32/heap.c index df094c94257..c1074e70e2e 100644 --- a/dlls/kernel32/heap.c +++ b/dlls/kernel32/heap.c @@ -47,6 +47,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(globalmem);
static HANDLE systemHeap; /* globally shared heap */
+BOOLEAN WINAPI RtlGetUserInfoHeap( HANDLE handle, ULONG flags, void *ptr, void **user_value, ULONG *user_flags );
/*********************************************************************** * HEAP_CreateSystemHeap @@ -171,7 +172,6 @@ C_ASSERT(sizeof(struct mem_entry) == 2 * sizeof(void *));
struct kernelbase_global_data *kernelbase_global_data;
-#define POINTER_TO_HANDLE( p ) (*(((const HGLOBAL *)( p )) - 2)) /* align the storage needed for the HLOCAL on an 8-byte boundary thus * LocalAlloc/LocalReAlloc'ing with LMEM_MOVEABLE of memory with * size = 8*k, where k=1,2,3,... allocs exactly the given size. @@ -255,6 +255,7 @@ HGLOBAL WINAPI GlobalHandle( const void *ptr ) struct mem_entry *mem; HGLOBAL handle; LPCVOID test; + ULONG flags;
TRACE_(globalmem)( "ptr %p\n", ptr );
@@ -279,7 +280,12 @@ HGLOBAL WINAPI GlobalHandle( const void *ptr ) handle = (HGLOBAL)ptr; /* valid fixed block */ break; } - handle = POINTER_TO_HANDLE( ptr ); + if (!RtlGetUserInfoHeap( GetProcessHeap(), HEAP_NO_SERIALIZE, (char *)ptr - HLOCAL_STORAGE, &handle, &flags )) + { + SetLastError( ERROR_INVALID_HANDLE ); + handle = 0; + } + break; } else handle = (HGLOBAL)ptr;
diff --git a/dlls/kernel32/tests/heap.c b/dlls/kernel32/tests/heap.c index 339921b83c3..ec2fe7479ca 100644 --- a/dlls/kernel32/tests/heap.c +++ b/dlls/kernel32/tests/heap.c @@ -1494,6 +1494,8 @@ static void test_GlobalAlloc(void) ptr = GlobalLock( mem ); ok( !!ptr, "GlobalLock failed, error %lu\n", GetLastError() ); ok( ptr != mem, "got unexpected ptr %p\n", ptr ); + tmp_mem = GlobalHandle( ptr ); + ok( tmp_mem == mem, "GlobalHandle returned unexpected handle\n" ); flags = GlobalFlags( mem ); ok( flags == 1, "GlobalFlags returned %#x, error %lu\n", flags, GetLastError() ); tmp_ptr = GlobalLock( mem ); @@ -1698,6 +1700,8 @@ static void test_GlobalAlloc(void) ok( !!mem, "GlobalAlloc failed, error %lu\n", GetLastError() ); ret = GlobalUnlock( mem ); ok( ret, "GlobalUnlock failed, error %lu\n", GetLastError() ); + tmp_mem = GlobalHandle( mem ); + ok( tmp_mem == mem, "GlobalHandle returned unexpected handle\n" ); mem = GlobalFree( mem ); ok( !mem, "GlobalFree failed, error %lu\n", GetLastError() );
@@ -1867,6 +1871,8 @@ static void test_LocalAlloc(void) ptr = LocalLock( mem ); ok( !!ptr, "LocalLock failed, error %lu\n", GetLastError() ); ok( ptr != mem, "got unexpected ptr %p\n", ptr ); + tmp_mem = LocalHandle( ptr ); + ok( tmp_mem == mem, "LocalHandle returned unexpected handle\n" ); flags = LocalFlags( mem ); ok( flags == 1, "LocalFlags returned %#x, error %lu\n", flags, GetLastError() ); tmp_ptr = LocalLock( mem ); @@ -2030,6 +2036,8 @@ static void test_LocalAlloc(void) ret = LocalUnlock( mem ); ok( !ret, "LocalUnlock succeeded\n" ); ok( GetLastError() == ERROR_NOT_LOCKED, "got error %lu\n", GetLastError() ); + tmp_mem = LocalHandle( mem ); + ok( tmp_mem == mem, "LocalHandle returned unexpected handle\n" ); mem = LocalFree( mem ); ok( !mem, "LocalFree failed, error %lu\n", GetLastError() );