This changes the GlobalUnlock todo_wine as we previously considered the
invalid mem handle as a valid pointer, and we now instead check handle
validity.
Returning TRUE in for an invalid handle doesn't seem very important, and
a corner case, and it breaks compatibility and imm32 tests.
Signed-off-by: Rémi Bernon <rbernon(a)codeweavers.com>
---
dlls/kernel32/heap.c | 10 ++++------
dlls/kernel32/tests/heap.c | 17 +----------------
dlls/kernelbase/memory.c | 10 ++++------
3 files changed, 9 insertions(+), 28 deletions(-)
diff --git a/dlls/kernel32/heap.c b/dlls/kernel32/heap.c
index dbb240d89fc..20505b673ec 100644
--- a/dlls/kernel32/heap.c
+++ b/dlls/kernel32/heap.c
@@ -147,8 +147,6 @@ BOOL WINAPI HeapDestroy( HANDLE heap /* [in] Handle of heap */ )
* Global/local heap functions, keep in sync with kernelbase/memory.c
***********************************************************************/
-#include "pshpack1.h"
-
struct mem_entry
{
union
@@ -156,15 +154,15 @@ struct mem_entry
struct
{
WORD magic;
- void *ptr;
BYTE flags;
BYTE lock;
};
void *next_free;
};
+ void *ptr;
};
-#include "poppack.h"
+C_ASSERT(sizeof(struct mem_entry) == 2 * sizeof(void *));
struct kernelbase_global_data *kernelbase_global_data;
@@ -181,7 +179,7 @@ static inline struct mem_entry *unsafe_mem_from_HLOCAL( HLOCAL handle )
{
struct mem_entry *mem = CONTAINING_RECORD( handle, struct mem_entry, ptr );
struct kernelbase_global_data *data = kernelbase_global_data;
- if (!((ULONG_PTR)handle & 2)) return NULL;
+ if (((UINT_PTR)handle & ((sizeof(void *) << 1) - 1)) != sizeof(void *)) return NULL;
if (mem < data->mem_entries || mem >= data->mem_entries_end) return NULL;
if (mem->magic != MAGIC_LOCAL_USED) return NULL;
return mem;
@@ -189,7 +187,7 @@ static inline struct mem_entry *unsafe_mem_from_HLOCAL( HLOCAL handle )
static inline void *unsafe_ptr_from_HLOCAL( HLOCAL handle )
{
- if ((ULONG_PTR)handle & 2) return NULL;
+ if (((UINT_PTR)handle & ((sizeof(void *) << 1) - 1))) return NULL;
return handle;
}
diff --git a/dlls/kernel32/tests/heap.c b/dlls/kernel32/tests/heap.c
index 476be96cea8..5d6383a49e5 100644
--- a/dlls/kernel32/tests/heap.c
+++ b/dlls/kernel32/tests/heap.c
@@ -368,9 +368,7 @@ static void test_GlobalAlloc(void)
mem = GlobalAlloc( GMEM_MOVEABLE, alloc_size );
ok( !!mem, "GlobalAlloc failed, error %lu\n", GetLastError() );
- todo_wine
ok( ((UINT_PTR)mem & sizeof(void *)), "got unexpected entry align\n" );
- todo_wine
ok( !((UINT_PTR)mem & (sizeof(void *) - 1)), "got unexpected entry align\n" );
entry = mem_entry_from_HANDLE( mem );
@@ -414,9 +412,7 @@ static void test_GlobalAlloc(void)
ok( !tmp_mem, "GlobalFree failed, error %lu\n", GetLastError() );
ok( !!entry->flags, "got unexpected flags %#Ix\n", entry->flags );
ok( !((UINT_PTR)entry->flags & sizeof(void *)), "got unexpected ptr align\n" );
- todo_wine_if(sizeof(void *) == 4)
ok( !((UINT_PTR)entry->flags & (sizeof(void *) - 1)), "got unexpected ptr align\n" );
- todo_wine
ok( !entry->ptr, "got unexpected ptr %p\n", entry->ptr );
mem = GlobalAlloc( GMEM_MOVEABLE | GMEM_DISCARDABLE, 0 );
@@ -543,29 +539,24 @@ static void test_GlobalAlloc(void)
ok( GetLastError() == ERROR_INVALID_HANDLE, "got error %lu\n", GetLastError() );
SetLastError( 0xdeadbeef );
flags = GlobalFlags( invalid_mem );
- todo_wine
ok( flags == GMEM_INVALID_HANDLE, "GlobalFlags succeeded\n" );
- todo_wine
ok( GetLastError() == ERROR_INVALID_HANDLE, "got error %lu\n", GetLastError() );
SetLastError( 0xdeadbeef );
size = GlobalSize( invalid_mem );
ok( size == 0, "GlobalSize succeeded\n" );
- todo_wine
ok( GetLastError() == ERROR_INVALID_HANDLE, "got error %lu\n", GetLastError() );
SetLastError( 0xdeadbeef );
ptr = GlobalLock( invalid_mem );
ok( !ptr, "GlobalLock succeeded\n" );
- todo_wine
ok( GetLastError() == ERROR_INVALID_HANDLE, "got error %lu\n", GetLastError() );
SetLastError( 0xdeadbeef );
ret = GlobalUnlock( invalid_mem );
- ok( ret, "GlobalUnlock failed, error %lu\n", GetLastError() );
todo_wine
+ ok( ret, "GlobalUnlock failed, error %lu\n", GetLastError() );
ok( GetLastError() == ERROR_INVALID_HANDLE, "got error %lu\n", GetLastError() );
SetLastError( 0xdeadbeef );
tmp_mem = GlobalReAlloc( invalid_mem, 0, GMEM_MOVEABLE );
ok( !tmp_mem, "GlobalReAlloc succeeded\n" );
- todo_wine
ok( GetLastError() == ERROR_INVALID_HANDLE, "got error %lu\n", GetLastError() );
/* invalid pointers are caught */
@@ -889,29 +880,23 @@ static void test_LocalAlloc(void)
ok( GetLastError() == ERROR_INVALID_HANDLE, "got error %lu\n", GetLastError() );
SetLastError( 0xdeadbeef );
flags = LocalFlags( invalid_mem );
- todo_wine
ok( flags == LMEM_INVALID_HANDLE, "LocalFlags succeeded\n" );
- todo_wine
ok( GetLastError() == ERROR_INVALID_HANDLE, "got error %lu\n", GetLastError() );
SetLastError( 0xdeadbeef );
size = LocalSize( invalid_mem );
ok( size == 0, "LocalSize succeeded\n" );
- todo_wine
ok( GetLastError() == ERROR_INVALID_HANDLE, "got error %lu\n", GetLastError() );
SetLastError( 0xdeadbeef );
ptr = LocalLock( invalid_mem );
ok( !ptr, "LocalLock succeeded\n" );
- todo_wine
ok( GetLastError() == ERROR_INVALID_HANDLE, "got error %lu\n", GetLastError() );
SetLastError( 0xdeadbeef );
ret = LocalUnlock( invalid_mem );
ok( !ret, "LocalUnlock succeeded\n" );
- todo_wine
ok( GetLastError() == ERROR_INVALID_HANDLE, "got error %lu\n", GetLastError() );
SetLastError( 0xdeadbeef );
tmp_mem = LocalReAlloc( invalid_mem, 0, LMEM_MOVEABLE );
ok( !tmp_mem, "LocalReAlloc succeeded\n" );
- todo_wine
ok( GetLastError() == ERROR_INVALID_HANDLE, "got error %lu\n", GetLastError() );
/* invalid pointers are caught */
diff --git a/dlls/kernelbase/memory.c b/dlls/kernelbase/memory.c
index 5bdab31589d..086674ab41c 100644
--- a/dlls/kernelbase/memory.c
+++ b/dlls/kernelbase/memory.c
@@ -585,8 +585,6 @@ struct kernelbase_global_data
struct mem_entry *mem_entries_end;
};
-#include "pshpack1.h"
-
struct mem_entry
{
union
@@ -594,15 +592,15 @@ struct mem_entry
struct
{
WORD magic;
- void *ptr;
BYTE flags;
BYTE lock;
};
void *next_free;
};
+ void *ptr;
};
-#include "poppack.h"
+C_ASSERT(sizeof(struct mem_entry) == 2 * sizeof(void *));
#define MAX_MEM_HANDLES 0x10000
static struct mem_entry mem_entries[MAX_MEM_HANDLES];
@@ -626,7 +624,7 @@ static inline struct mem_entry *unsafe_mem_from_HLOCAL( HLOCAL handle )
{
struct mem_entry *mem = CONTAINING_RECORD( handle, struct mem_entry, ptr );
struct kernelbase_global_data *data = &kernelbase_global_data;
- if (!((ULONG_PTR)handle & 2)) return NULL;
+ if (((UINT_PTR)handle & ((sizeof(void *) << 1) - 1)) != sizeof(void *)) return NULL;
if (mem < data->mem_entries || mem >= data->mem_entries_end) return NULL;
if (mem->magic != MAGIC_LOCAL_USED) return NULL;
return mem;
@@ -639,7 +637,7 @@ static inline HLOCAL HLOCAL_from_mem( struct mem_entry *mem )
static inline void *unsafe_ptr_from_HLOCAL( HLOCAL handle )
{
- if ((ULONG_PTR)handle & 2) return NULL;
+ if (((UINT_PTR)handle & ((sizeof(void *) << 1) - 1))) return NULL;
return handle;
}
--
2.35.1