kernel32: Make Global* traces and identifiers more consistent.

Signed-off-by: Rémi Bernon <rbernon@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Rémi Bernon 2022-03-29 15:24:37 +02:00 committed by Alexandre Julliard
parent 48ebc410ef
commit fc12f812c3
1 changed files with 58 additions and 53 deletions

View File

@ -183,7 +183,7 @@ typedef struct __GLOBAL32_INTERN
* Lock a global memory object and return a pointer to first byte of the memory * Lock a global memory object and return a pointer to first byte of the memory
* *
* PARAMS * PARAMS
* hmem [I] Handle of the global memory object * handle [I] Handle of the global memory object
* *
* RETURNS * RETURNS
* Success: Pointer to first byte of the memory block * Success: Pointer to first byte of the memory block
@ -193,9 +193,9 @@ typedef struct __GLOBAL32_INTERN
* When the handle is invalid, last error is set to ERROR_INVALID_HANDLE * When the handle is invalid, last error is set to ERROR_INVALID_HANDLE
* *
*/ */
LPVOID WINAPI GlobalLock(HGLOBAL hmem) void *WINAPI GlobalLock( HGLOBAL handle )
{ {
return LocalLock( hmem ); return LocalLock( handle );
} }
@ -205,7 +205,7 @@ LPVOID WINAPI GlobalLock(HGLOBAL hmem)
* Unlock a global memory object. * Unlock a global memory object.
* *
* PARAMS * PARAMS
* hmem [I] Handle of the global memory object * handle [I] Handle of the global memory object
* *
* RETURNS * RETURNS
* Success: Object is still locked * Success: Object is still locked
@ -215,10 +215,10 @@ LPVOID WINAPI GlobalLock(HGLOBAL hmem)
* When the handle is invalid, last error is set to ERROR_INVALID_HANDLE * When the handle is invalid, last error is set to ERROR_INVALID_HANDLE
* *
*/ */
BOOL WINAPI GlobalUnlock(HGLOBAL hmem) BOOL WINAPI GlobalUnlock( HGLOBAL handle )
{ {
if (ISPOINTER( hmem )) return TRUE; if (ISPOINTER( handle )) return TRUE;
return LocalUnlock( hmem ); return LocalUnlock( handle );
} }
@ -231,13 +231,15 @@ BOOL WINAPI GlobalUnlock(HGLOBAL hmem)
* Handle: Success * Handle: Success
* NULL: Failure * NULL: Failure
*/ */
HGLOBAL WINAPI GlobalHandle( LPCVOID pmem ) HGLOBAL WINAPI GlobalHandle( const void *ptr )
{ {
PGLOBAL32_INTERN mem;
HGLOBAL handle; HGLOBAL handle;
PGLOBAL32_INTERN maybe_intern;
LPCVOID test; LPCVOID test;
if (!pmem) TRACE_(globalmem)( "ptr %p\n", ptr );
if (!ptr)
{ {
SetLastError( ERROR_INVALID_PARAMETER ); SetLastError( ERROR_INVALID_PARAMETER );
return 0; return 0;
@ -248,27 +250,27 @@ HGLOBAL WINAPI GlobalHandle( LPCVOID pmem )
{ {
handle = 0; handle = 0;
/* note that if pmem is a pointer to a block allocated by */ /* note that if ptr is a pointer to a block allocated by */
/* GlobalAlloc with GMEM_MOVEABLE then magic test in HeapValidate */ /* GlobalAlloc with GMEM_MOVEABLE then magic test in HeapValidate */
/* will fail. */ /* will fail. */
if (ISPOINTER( pmem )) if (ISPOINTER( ptr ))
{ {
if (HeapValidate( GetProcessHeap(), HEAP_NO_SERIALIZE, pmem )) if (HeapValidate( GetProcessHeap(), HEAP_NO_SERIALIZE, ptr ))
{ {
handle = (HGLOBAL)pmem; /* valid fixed block */ handle = (HGLOBAL)ptr; /* valid fixed block */
break; break;
} }
handle = POINTER_TO_HANDLE( pmem ); handle = POINTER_TO_HANDLE( ptr );
} }
else handle = (HGLOBAL)pmem; else handle = (HGLOBAL)ptr;
/* Now test handle either passed in or retrieved from pointer */ /* Now test handle either passed in or retrieved from pointer */
maybe_intern = HANDLE_TO_INTERN( handle ); mem = HANDLE_TO_INTERN( handle );
if (maybe_intern->Magic == MAGIC_GLOBAL_USED) if (mem->Magic == MAGIC_GLOBAL_USED)
{ {
test = maybe_intern->Pointer; test = mem->Pointer;
if (HeapValidate( GetProcessHeap(), HEAP_NO_SERIALIZE, (const char *)test - HGLOBAL_STORAGE ) && /* obj(-handle) valid arena? */ if (HeapValidate( GetProcessHeap(), HEAP_NO_SERIALIZE, (const char *)test - HGLOBAL_STORAGE ) && /* obj(-handle) valid arena? */
HeapValidate( GetProcessHeap(), HEAP_NO_SERIALIZE, maybe_intern )) /* intern valid arena? */ HeapValidate( GetProcessHeap(), HEAP_NO_SERIALIZE, mem )) /* intern valid arena? */
break; /* valid moveable block */ break; /* valid moveable block */
} }
handle = 0; handle = 0;
@ -294,9 +296,9 @@ HGLOBAL WINAPI GlobalHandle( LPCVOID pmem )
* Handle: Success * Handle: Success
* NULL: Failure * NULL: Failure
*/ */
HGLOBAL WINAPI GlobalReAlloc( HGLOBAL hmem, SIZE_T size, UINT flags ) HGLOBAL WINAPI GlobalReAlloc( HGLOBAL handle, SIZE_T size, UINT flags )
{ {
return LocalReAlloc( hmem, size, flags ); return LocalReAlloc( handle, size, flags );
} }
@ -306,7 +308,7 @@ HGLOBAL WINAPI GlobalReAlloc( HGLOBAL hmem, SIZE_T size, UINT flags )
* Get the size of a global memory object. * Get the size of a global memory object.
* *
* PARAMS * PARAMS
* hmem [I] Handle of the global memory object * handle [I] Handle of the global memory object
* *
* RETURNS * RETURNS
* Failure: 0 * Failure: 0
@ -316,44 +318,45 @@ HGLOBAL WINAPI GlobalReAlloc( HGLOBAL hmem, SIZE_T size, UINT flags )
* When the handle is invalid, last error is set to ERROR_INVALID_HANDLE * When the handle is invalid, last error is set to ERROR_INVALID_HANDLE
* *
*/ */
SIZE_T WINAPI GlobalSize(HGLOBAL hmem) SIZE_T WINAPI GlobalSize( HGLOBAL handle )
{ {
PGLOBAL32_INTERN mem;
SIZE_T retval; SIZE_T retval;
PGLOBAL32_INTERN pintern;
if (!((ULONG_PTR)hmem >> 16)) TRACE_(globalmem)( "handle %p\n", handle );
if (!((ULONG_PTR)handle >> 16))
{ {
SetLastError( ERROR_INVALID_HANDLE ); SetLastError( ERROR_INVALID_HANDLE );
return 0; return 0;
} }
if (ISPOINTER( hmem )) if (ISPOINTER( handle ))
{ {
retval = HeapSize( GetProcessHeap(), 0, hmem ); retval = HeapSize( GetProcessHeap(), 0, handle );
if (retval == ~(SIZE_T)0) /* It might be a GMEM_MOVEABLE data pointer */ if (retval == ~(SIZE_T)0) /* It might be a GMEM_MOVEABLE data pointer */
{ {
retval = HeapSize( GetProcessHeap(), 0, (char *)hmem - HGLOBAL_STORAGE ); retval = HeapSize( GetProcessHeap(), 0, (char *)handle - HGLOBAL_STORAGE );
if (retval != ~(SIZE_T)0) retval -= HGLOBAL_STORAGE; if (retval != ~(SIZE_T)0) retval -= HGLOBAL_STORAGE;
} }
} }
else else
{ {
RtlLockHeap( GetProcessHeap() ); RtlLockHeap( GetProcessHeap() );
pintern = HANDLE_TO_INTERN( hmem ); mem = HANDLE_TO_INTERN( handle );
if (mem->Magic == MAGIC_GLOBAL_USED)
if (pintern->Magic == MAGIC_GLOBAL_USED)
{ {
if (!pintern->Pointer) /* handle case of GlobalAlloc( ??,0) */ if (!mem->Pointer) /* handle case of GlobalAlloc( ??,0) */
retval = 0; retval = 0;
else else
{ {
retval = HeapSize( GetProcessHeap(), 0, (char *)pintern->Pointer - HGLOBAL_STORAGE ); retval = HeapSize( GetProcessHeap(), 0, (char *)mem->Pointer - HGLOBAL_STORAGE );
if (retval != ~(SIZE_T)0) retval -= HGLOBAL_STORAGE; if (retval != ~(SIZE_T)0) retval -= HGLOBAL_STORAGE;
} }
} }
else else
{ {
WARN( "invalid handle %p (Magic: 0x%04x)\n", hmem, pintern->Magic ); WARN_(globalmem)( "invalid handle %p\n", handle );
SetLastError( ERROR_INVALID_HANDLE ); SetLastError( ERROR_INVALID_HANDLE );
retval = 0; retval = 0;
} }
@ -367,36 +370,36 @@ SIZE_T WINAPI GlobalSize(HGLOBAL hmem)
/*********************************************************************** /***********************************************************************
* GlobalWire (KERNEL32.@) * GlobalWire (KERNEL32.@)
*/ */
LPVOID WINAPI GlobalWire(HGLOBAL hmem) void *WINAPI GlobalWire( HGLOBAL handle )
{ {
return GlobalLock( hmem ); return GlobalLock( handle );
} }
/*********************************************************************** /***********************************************************************
* GlobalUnWire (KERNEL32.@) * GlobalUnWire (KERNEL32.@)
*/ */
BOOL WINAPI GlobalUnWire(HGLOBAL hmem) BOOL WINAPI GlobalUnWire( HGLOBAL handle )
{ {
return GlobalUnlock( hmem); return GlobalUnlock( handle );
} }
/*********************************************************************** /***********************************************************************
* GlobalFix (KERNEL32.@) * GlobalFix (KERNEL32.@)
*/ */
VOID WINAPI GlobalFix(HGLOBAL hmem) VOID WINAPI GlobalFix( HGLOBAL handle )
{ {
GlobalLock( hmem ); GlobalLock( handle );
} }
/*********************************************************************** /***********************************************************************
* GlobalUnfix (KERNEL32.@) * GlobalUnfix (KERNEL32.@)
*/ */
VOID WINAPI GlobalUnfix(HGLOBAL hmem) VOID WINAPI GlobalUnfix( HGLOBAL handle )
{ {
GlobalUnlock( hmem); GlobalUnlock( handle );
} }
@ -406,34 +409,36 @@ VOID WINAPI GlobalUnfix(HGLOBAL hmem)
* Get information about a global memory object. * Get information about a global memory object.
* *
* PARAMS * PARAMS
* hmem [I] Handle of the global memory object * handle [I] Handle of the global memory object
* *
* RETURNS * RETURNS
* Failure: GMEM_INVALID_HANDLE, when the provided handle is invalid * Failure: GMEM_INVALID_HANDLE, when the provided handle is invalid
* Success: Value specifying allocation flags and lock count * Success: Value specifying allocation flags and lock count
* *
*/ */
UINT WINAPI GlobalFlags(HGLOBAL hmem) UINT WINAPI GlobalFlags( HGLOBAL handle )
{ {
PGLOBAL32_INTERN mem;
DWORD retval; DWORD retval;
PGLOBAL32_INTERN pintern;
if (ISPOINTER( hmem )) TRACE_(globalmem)( "handle %p\n", handle );
if (ISPOINTER( handle ))
{ {
retval = 0; retval = 0;
} }
else else
{ {
RtlLockHeap( GetProcessHeap() ); RtlLockHeap( GetProcessHeap() );
pintern = HANDLE_TO_INTERN( hmem ); mem = HANDLE_TO_INTERN( handle );
if (pintern->Magic == MAGIC_GLOBAL_USED) if (mem->Magic == MAGIC_GLOBAL_USED)
{ {
retval = pintern->LockCount + (pintern->Flags << 8); retval = mem->LockCount + (mem->Flags << 8);
if (pintern->Pointer == 0) retval |= GMEM_DISCARDED; if (mem->Pointer == 0) retval |= GMEM_DISCARDED;
} }
else else
{ {
WARN( "invalid handle %p (Magic: 0x%04x)\n", hmem, pintern->Magic ); WARN_(globalmem)( "invalid handle %p\n", handle );
SetLastError( ERROR_INVALID_HANDLE ); SetLastError( ERROR_INVALID_HANDLE );
retval = GMEM_INVALID_HANDLE; retval = GMEM_INVALID_HANDLE;
} }