With this patch, lib/wine/x86_64-windows/ ends up 100 KB smaller, and I would expect performance benefits too.
From https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-mal...:
Attribute malloc indicates that a function is malloc-like, i.e., that the pointer P returned by the function cannot alias any other pointer valid when the function returns, and moreover no pointers to valid objects occur in any storage addressed by P. In addition, the GCC predicts that a function with the attribute returns non-null in most cases.
Using the attribute with no arguments is designed to improve optimization by relying on the aliasing property it implies. Functions like malloc and calloc have this property because they return a pointer to uninitialized or zeroed-out, newly obtained storage. However, functions like realloc do not have this property, as they may return pointers to storage containing pointers to existing objects. Additionally, since all such functions are assumed to return null only infrequently, callers can be optimized based on that assumption.
-- v2: crypt32/tests: Fix mismatched deallocation function. include: Add __WINE_DEALLOC attribute and use it for allocation functions. include: Add __WINE_MALLOC attribute and use it for allocation functions.
From: Brendan Shanks bshanks@codeweavers.com
Signed-off-by: Brendan Shanks bshanks@codeweavers.com --- include/ddk/wdm.h | 12 ++++++------ include/objbase.h | 2 +- include/oleauto.h | 6 +++--- include/rpcndr.h | 8 ++++---- include/winbase.h | 6 +++--- include/wincrypt.h | 2 +- include/wine/heap.h | 6 +++--- include/winnt.h | 6 ++++++ include/winternl.h | 2 +- 9 files changed, 28 insertions(+), 22 deletions(-)
diff --git a/include/ddk/wdm.h b/include/ddk/wdm.h index b75f452d0da..8517f6dca39 100644 --- a/include/ddk/wdm.h +++ b/include/ddk/wdm.h @@ -1656,10 +1656,10 @@ BOOLEAN WINAPI ExAcquireResourceExclusiveLite(ERESOURCE*,BOOLEAN); BOOLEAN WINAPI ExAcquireResourceSharedLite(ERESOURCE*,BOOLEAN); BOOLEAN WINAPI ExAcquireSharedStarveExclusive(ERESOURCE*,BOOLEAN); BOOLEAN WINAPI ExAcquireSharedWaitForExclusive(ERESOURCE*,BOOLEAN); -PVOID WINAPI ExAllocatePool(POOL_TYPE,SIZE_T) __WINE_ALLOC_SIZE(2); -PVOID WINAPI ExAllocatePoolWithQuota(POOL_TYPE,SIZE_T) __WINE_ALLOC_SIZE(2); -PVOID WINAPI ExAllocatePoolWithTag(POOL_TYPE,SIZE_T,ULONG) __WINE_ALLOC_SIZE(2); -PVOID WINAPI ExAllocatePoolWithQuotaTag(POOL_TYPE,SIZE_T,ULONG) __WINE_ALLOC_SIZE(2); +PVOID WINAPI ExAllocatePool(POOL_TYPE,SIZE_T) __WINE_ALLOC_SIZE(2) __WINE_MALLOC; +PVOID WINAPI ExAllocatePoolWithQuota(POOL_TYPE,SIZE_T) __WINE_ALLOC_SIZE(2) __WINE_MALLOC; +PVOID WINAPI ExAllocatePoolWithTag(POOL_TYPE,SIZE_T,ULONG) __WINE_ALLOC_SIZE(2) __WINE_MALLOC; +PVOID WINAPI ExAllocatePoolWithQuotaTag(POOL_TYPE,SIZE_T,ULONG) __WINE_ALLOC_SIZE(2) __WINE_MALLOC; void WINAPI ExDeleteNPagedLookasideList(PNPAGED_LOOKASIDE_LIST); void WINAPI ExDeletePagedLookasideList(PPAGED_LOOKASIDE_LIST); NTSTATUS WINAPI ExDeleteResourceLite(ERESOURCE*); @@ -1791,8 +1791,8 @@ BOOLEAN WINAPI KeSignalCallDpcSynchronize(void*); NTSTATUS WINAPI KeWaitForMultipleObjects(ULONG,void*[],WAIT_TYPE,KWAIT_REASON,KPROCESSOR_MODE,BOOLEAN,LARGE_INTEGER*,KWAIT_BLOCK*); NTSTATUS WINAPI KeWaitForSingleObject(void*,KWAIT_REASON,KPROCESSOR_MODE,BOOLEAN,LARGE_INTEGER*);
-PVOID WINAPI MmAllocateContiguousMemory(SIZE_T,PHYSICAL_ADDRESS) __WINE_ALLOC_SIZE(1); -PVOID WINAPI MmAllocateNonCachedMemory(SIZE_T) __WINE_ALLOC_SIZE(1); +PVOID WINAPI MmAllocateContiguousMemory(SIZE_T,PHYSICAL_ADDRESS) __WINE_ALLOC_SIZE(1) __WINE_MALLOC; +PVOID WINAPI MmAllocateNonCachedMemory(SIZE_T) __WINE_ALLOC_SIZE(1) __WINE_MALLOC; PMDL WINAPI MmAllocatePagesForMdl(PHYSICAL_ADDRESS,PHYSICAL_ADDRESS,PHYSICAL_ADDRESS,SIZE_T); void WINAPI MmBuildMdlForNonPagedPool(MDL*); NTSTATUS WINAPI MmCopyVirtualMemory(PEPROCESS,void*,PEPROCESS,void*,SIZE_T,KPROCESSOR_MODE,SIZE_T*); diff --git a/include/objbase.h b/include/objbase.h index 11bfc95d989..4b499ffdc0f 100644 --- a/include/objbase.h +++ b/include/objbase.h @@ -317,7 +317,7 @@ HRESULT WINAPI CoGetInstanceFromFile(COSERVERINFO* pServerInfo, CLSID* pClsid, I HRESULT WINAPI CoGetInstanceFromIStorage(COSERVERINFO* pServerInfo, CLSID* pClsid, IUnknown* punkOuter, DWORD dwClsCtx, IStorage* pstg, DWORD dwCount, MULTI_QI* pResults);
HRESULT WINAPI CoGetMalloc(DWORD dwMemContext, LPMALLOC* lpMalloc); -LPVOID WINAPI CoTaskMemAlloc(SIZE_T size) __WINE_ALLOC_SIZE(1); +LPVOID WINAPI CoTaskMemAlloc(SIZE_T size) __WINE_ALLOC_SIZE(1) __WINE_MALLOC; void WINAPI CoTaskMemFree(LPVOID ptr); LPVOID WINAPI CoTaskMemRealloc(LPVOID ptr, SIZE_T size) __WINE_ALLOC_SIZE(2);
diff --git a/include/oleauto.h b/include/oleauto.h index 1d15efd26f3..6427ff55696 100644 --- a/include/oleauto.h +++ b/include/oleauto.h @@ -38,9 +38,9 @@ DEFINE_OLEGUID(IID_StdOle, 0x00020430,0,0); ULONG WINAPI OaBuildVersion(void);
/* BSTR functions */ -BSTR WINAPI SysAllocString(const OLECHAR*); -BSTR WINAPI SysAllocStringByteLen(LPCSTR,UINT); -BSTR WINAPI SysAllocStringLen(const OLECHAR*,UINT); +BSTR WINAPI SysAllocString(const OLECHAR*) __WINE_MALLOC; +BSTR WINAPI SysAllocStringByteLen(LPCSTR,UINT) __WINE_MALLOC; +BSTR WINAPI SysAllocStringLen(const OLECHAR*,UINT) __WINE_MALLOC; void WINAPI SysFreeString(BSTR); INT WINAPI SysReAllocString(LPBSTR,const OLECHAR*); int WINAPI SysReAllocStringLen(BSTR*,const OLECHAR*,UINT); diff --git a/include/rpcndr.h b/include/rpcndr.h index 13711f2f2df..b7a5c8c4029 100644 --- a/include/rpcndr.h +++ b/include/rpcndr.h @@ -658,7 +658,7 @@ RPCRTAPI LONG RPC_ENTRY NdrDcomAsyncStubCall( struct IRpcStubBuffer* pThis, struct IRpcChannelBuffer* pChannel, PRPC_MESSAGE pRpcMsg, DWORD * pdwStubPhase );
RPCRTAPI void* RPC_ENTRY - NdrAllocate( PMIDL_STUB_MESSAGE pStubMsg, SIZE_T Len ) __WINE_ALLOC_SIZE(2); + NdrAllocate( PMIDL_STUB_MESSAGE pStubMsg, SIZE_T Len ) __WINE_ALLOC_SIZE(2) __WINE_MALLOC;
RPCRTAPI void RPC_ENTRY NdrClearOutParameters( PMIDL_STUB_MESSAGE pStubMsg, PFORMAT_STRING pFormat, void *ArgAddr ); @@ -668,7 +668,7 @@ RPCRTAPI RPC_STATUS RPC_ENTRY ULONG *pFaultStatus, RPC_STATUS Status_ );
RPCRTAPI void* RPC_ENTRY - NdrOleAllocate( SIZE_T Size ) __WINE_ALLOC_SIZE(1); + NdrOleAllocate( SIZE_T Size ) __WINE_ALLOC_SIZE(1) __WINE_MALLOC; RPCRTAPI void RPC_ENTRY NdrOleFree( void* NodeToFree );
@@ -729,11 +729,11 @@ RPCRTAPI void RPC_ENTRY RPCRTAPI void RPC_ENTRY NdrRpcSmSetClientToOsf( PMIDL_STUB_MESSAGE pMessage ); RPCRTAPI void * RPC_ENTRY - NdrRpcSmClientAllocate( SIZE_T Size ) __WINE_ALLOC_SIZE(1); + NdrRpcSmClientAllocate( SIZE_T Size ) __WINE_ALLOC_SIZE(1) __WINE_MALLOC; RPCRTAPI void RPC_ENTRY NdrRpcSmClientFree( void *NodeToFree ); RPCRTAPI void * RPC_ENTRY - NdrRpcSsDefaultAllocate( SIZE_T Size ) __WINE_ALLOC_SIZE(1); + NdrRpcSsDefaultAllocate( SIZE_T Size ) __WINE_ALLOC_SIZE(1) __WINE_MALLOC; RPCRTAPI void RPC_ENTRY NdrRpcSsDefaultFree( void *NodeToFree );
diff --git a/include/winbase.h b/include/winbase.h index 9fbaa466b54..748a248f56a 100644 --- a/include/winbase.h +++ b/include/winbase.h @@ -2350,7 +2350,7 @@ WINBASEAPI BOOL WINAPI GetXStateFeaturesMask(CONTEXT*,DWORD64*); WINBASEAPI ATOM WINAPI GlobalAddAtomA(LPCSTR); WINBASEAPI ATOM WINAPI GlobalAddAtomW(LPCWSTR); #define GlobalAddAtom WINELIB_NAME_AW(GlobalAddAtom) -WINBASEAPI HGLOBAL WINAPI GlobalAlloc(UINT,SIZE_T) __WINE_ALLOC_SIZE(2); +WINBASEAPI HGLOBAL WINAPI GlobalAlloc(UINT,SIZE_T) __WINE_ALLOC_SIZE(2) __WINE_MALLOC; WINBASEAPI SIZE_T WINAPI GlobalCompact(DWORD); WINBASEAPI ATOM WINAPI GlobalDeleteAtom(ATOM); WINBASEAPI ATOM WINAPI GlobalFindAtomA(LPCSTR); @@ -2373,7 +2373,7 @@ WINBASEAPI BOOL WINAPI GlobalUnlock(HGLOBAL); WINBASEAPI BOOL WINAPI GlobalUnWire(HGLOBAL); WINBASEAPI LPVOID WINAPI GlobalWire(HGLOBAL); #define HasOverlappedIoCompleted(lpOverlapped) ((lpOverlapped)->Internal != STATUS_PENDING) -WINBASEAPI LPVOID WINAPI HeapAlloc(HANDLE,DWORD,SIZE_T) __WINE_ALLOC_SIZE(3); +WINBASEAPI LPVOID WINAPI HeapAlloc(HANDLE,DWORD,SIZE_T) __WINE_ALLOC_SIZE(3) __WINE_MALLOC; WINBASEAPI SIZE_T WINAPI HeapCompact(HANDLE,DWORD); WINBASEAPI HANDLE WINAPI HeapCreate(DWORD,SIZE_T,SIZE_T); WINBASEAPI BOOL WINAPI HeapDestroy(HANDLE); @@ -2440,7 +2440,7 @@ WINBASEAPI HMODULE WINAPI LoadLibraryExW(LPCWSTR,HANDLE,DWORD); WINBASEAPI DWORD WINAPI LoadModule(LPCSTR,LPVOID); WINBASEAPI HMODULE WINAPI LoadPackagedLibrary(LPCWSTR,DWORD); WINBASEAPI HGLOBAL WINAPI LoadResource(HMODULE,HRSRC); -WINBASEAPI HLOCAL WINAPI LocalAlloc(UINT,SIZE_T) __WINE_ALLOC_SIZE(2); +WINBASEAPI HLOCAL WINAPI LocalAlloc(UINT,SIZE_T) __WINE_ALLOC_SIZE(2) __WINE_MALLOC; WINBASEAPI SIZE_T WINAPI LocalCompact(UINT); WINBASEAPI UINT WINAPI LocalFlags(HLOCAL); WINBASEAPI HLOCAL WINAPI LocalFree(HLOCAL); diff --git a/include/wincrypt.h b/include/wincrypt.h index 77b2fb5d7cf..8adbd2c1300 100644 --- a/include/wincrypt.h +++ b/include/wincrypt.h @@ -4043,7 +4043,7 @@ WINADVAPI BOOL WINAPI CryptVerifySignatureW (HCRYPTHASH, const BYTE *, DWORD, HC #define CryptVerifySignature WINELIB_NAME_AW(CryptVerifySignature)
/* crypt32.dll functions */ -LPVOID WINAPI CryptMemAlloc(ULONG cbSize) __WINE_ALLOC_SIZE(1); +LPVOID WINAPI CryptMemAlloc(ULONG cbSize) __WINE_ALLOC_SIZE(1) __WINE_MALLOC; LPVOID WINAPI CryptMemRealloc(LPVOID pv, ULONG cbSize) __WINE_ALLOC_SIZE(2); VOID WINAPI CryptMemFree(LPVOID pv);
diff --git a/include/wine/heap.h b/include/wine/heap.h index fb687c92393..f88942bbb00 100644 --- a/include/wine/heap.h +++ b/include/wine/heap.h @@ -24,12 +24,12 @@
#include <winbase.h>
-static inline void * __WINE_ALLOC_SIZE(1) heap_alloc(SIZE_T len) +static inline void * __WINE_ALLOC_SIZE(1) __WINE_MALLOC heap_alloc(SIZE_T len) { return HeapAlloc(GetProcessHeap(), 0, len); }
-static inline void * __WINE_ALLOC_SIZE(1) heap_alloc_zero(SIZE_T len) +static inline void * __WINE_ALLOC_SIZE(1) __WINE_MALLOC heap_alloc_zero(SIZE_T len) { return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len); } @@ -46,7 +46,7 @@ static inline void heap_free(void *mem) HeapFree(GetProcessHeap(), 0, mem); }
-static inline void * __WINE_ALLOC_SIZE(1,2) heap_calloc(SIZE_T count, SIZE_T size) +static inline void * __WINE_ALLOC_SIZE(1,2) __WINE_MALLOC heap_calloc(SIZE_T count, SIZE_T size) { SIZE_T len = count * size;
diff --git a/include/winnt.h b/include/winnt.h index 79df4259f59..a0b430b47d6 100644 --- a/include/winnt.h +++ b/include/winnt.h @@ -204,6 +204,12 @@ extern "C" { #define __WINE_ALLOC_SIZE(...) #endif
+#if defined(__GNUC__) && (__GNUC__ > 2) +#define __WINE_MALLOC __attribute__((malloc)) +#else +#define __WINE_MALLOC +#endif + /* Anonymous union/struct handling */
#ifndef NONAMELESSSTRUCT diff --git a/include/winternl.h b/include/winternl.h index a4cbcb316cb..43a4ddf2f39 100644 --- a/include/winternl.h +++ b/include/winternl.h @@ -4200,7 +4200,7 @@ NTSYSAPI PVOID WINAPI RtlAddVectoredExceptionHandler(ULONG,PVECTORED_EXCEPTI NTSYSAPI NTSTATUS WINAPI RtlAdjustPrivilege(ULONG,BOOLEAN,BOOLEAN,PBOOLEAN); NTSYSAPI NTSTATUS WINAPI RtlAllocateAndInitializeSid(PSID_IDENTIFIER_AUTHORITY,BYTE,DWORD,DWORD,DWORD,DWORD,DWORD,DWORD,DWORD,DWORD,PSID *); NTSYSAPI RTL_HANDLE * WINAPI RtlAllocateHandle(RTL_HANDLE_TABLE *,ULONG *); -NTSYSAPI PVOID WINAPI RtlAllocateHeap(HANDLE,ULONG,SIZE_T) __WINE_ALLOC_SIZE(3); +NTSYSAPI PVOID WINAPI RtlAllocateHeap(HANDLE,ULONG,SIZE_T) __WINE_ALLOC_SIZE(3) __WINE_MALLOC; NTSYSAPI WCHAR WINAPI RtlAnsiCharToUnicodeChar(LPSTR *); NTSYSAPI DWORD WINAPI RtlAnsiStringToUnicodeSize(const STRING *); NTSYSAPI NTSTATUS WINAPI RtlAnsiStringToUnicodeString(PUNICODE_STRING,PCANSI_STRING,BOOLEAN);
From: Brendan Shanks bshanks@codeweavers.com
Signed-off-by: Brendan Shanks bshanks@codeweavers.com --- include/ddk/wdm.h | 16 ++++++++-------- include/objbase.h | 4 ++-- include/oleauto.h | 6 +++--- include/rpcndr.h | 10 +++++----- include/winbase.h | 18 +++++++++--------- include/wincrypt.h | 4 ++-- include/winnt.h | 6 ++++++ include/winternl.h | 3 ++- 8 files changed, 37 insertions(+), 30 deletions(-)
diff --git a/include/ddk/wdm.h b/include/ddk/wdm.h index 8517f6dca39..0aad83ade8c 100644 --- a/include/ddk/wdm.h +++ b/include/ddk/wdm.h @@ -1656,15 +1656,15 @@ BOOLEAN WINAPI ExAcquireResourceExclusiveLite(ERESOURCE*,BOOLEAN); BOOLEAN WINAPI ExAcquireResourceSharedLite(ERESOURCE*,BOOLEAN); BOOLEAN WINAPI ExAcquireSharedStarveExclusive(ERESOURCE*,BOOLEAN); BOOLEAN WINAPI ExAcquireSharedWaitForExclusive(ERESOURCE*,BOOLEAN); -PVOID WINAPI ExAllocatePool(POOL_TYPE,SIZE_T) __WINE_ALLOC_SIZE(2) __WINE_MALLOC; -PVOID WINAPI ExAllocatePoolWithQuota(POOL_TYPE,SIZE_T) __WINE_ALLOC_SIZE(2) __WINE_MALLOC; -PVOID WINAPI ExAllocatePoolWithTag(POOL_TYPE,SIZE_T,ULONG) __WINE_ALLOC_SIZE(2) __WINE_MALLOC; -PVOID WINAPI ExAllocatePoolWithQuotaTag(POOL_TYPE,SIZE_T,ULONG) __WINE_ALLOC_SIZE(2) __WINE_MALLOC; +void WINAPI ExFreePool(PVOID); +PVOID WINAPI ExAllocatePool(POOL_TYPE,SIZE_T) __WINE_ALLOC_SIZE(2) __WINE_DEALLOC(ExFreePool) __WINE_MALLOC; +PVOID WINAPI ExAllocatePoolWithQuota(POOL_TYPE,SIZE_T) __WINE_ALLOC_SIZE(2) __WINE_DEALLOC(ExFreePool) __WINE_MALLOC; +void WINAPI ExFreePoolWithTag(PVOID,ULONG); +PVOID WINAPI ExAllocatePoolWithTag(POOL_TYPE,SIZE_T,ULONG) __WINE_ALLOC_SIZE(2) __WINE_DEALLOC(ExFreePoolWithTag) __WINE_MALLOC; +PVOID WINAPI ExAllocatePoolWithQuotaTag(POOL_TYPE,SIZE_T,ULONG) __WINE_ALLOC_SIZE(2) __WINE_DEALLOC(ExFreePoolWithTag) __WINE_MALLOC; void WINAPI ExDeleteNPagedLookasideList(PNPAGED_LOOKASIDE_LIST); void WINAPI ExDeletePagedLookasideList(PPAGED_LOOKASIDE_LIST); NTSTATUS WINAPI ExDeleteResourceLite(ERESOURCE*); -void WINAPI ExFreePool(PVOID); -void WINAPI ExFreePoolWithTag(PVOID,ULONG); ULONG WINAPI ExGetExclusiveWaiterCount(ERESOURCE*); ULONG WINAPI ExGetSharedWaiterCount(ERESOURCE*); void WINAPI ExInitializeNPagedLookasideList(PNPAGED_LOOKASIDE_LIST,PALLOCATE_FUNCTION,PFREE_FUNCTION,ULONG,SIZE_T,ULONG,USHORT); @@ -1792,11 +1792,11 @@ NTSTATUS WINAPI KeWaitForMultipleObjects(ULONG,void*[],WAIT_TYPE,KWAIT_REASON,K NTSTATUS WINAPI KeWaitForSingleObject(void*,KWAIT_REASON,KPROCESSOR_MODE,BOOLEAN,LARGE_INTEGER*);
PVOID WINAPI MmAllocateContiguousMemory(SIZE_T,PHYSICAL_ADDRESS) __WINE_ALLOC_SIZE(1) __WINE_MALLOC; -PVOID WINAPI MmAllocateNonCachedMemory(SIZE_T) __WINE_ALLOC_SIZE(1) __WINE_MALLOC; +void WINAPI MmFreeNonCachedMemory(PVOID,SIZE_T); +PVOID WINAPI MmAllocateNonCachedMemory(SIZE_T) __WINE_ALLOC_SIZE(1) __WINE_DEALLOC(MmFreeNonCachedMemory) __WINE_MALLOC; PMDL WINAPI MmAllocatePagesForMdl(PHYSICAL_ADDRESS,PHYSICAL_ADDRESS,PHYSICAL_ADDRESS,SIZE_T); void WINAPI MmBuildMdlForNonPagedPool(MDL*); NTSTATUS WINAPI MmCopyVirtualMemory(PEPROCESS,void*,PEPROCESS,void*,SIZE_T,KPROCESSOR_MODE,SIZE_T*); -void WINAPI MmFreeNonCachedMemory(PVOID,SIZE_T); void * WINAPI MmGetSystemRoutineAddress(UNICODE_STRING*); PVOID WINAPI MmMapLockedPagesSpecifyCache(PMDLX,KPROCESSOR_MODE,MEMORY_CACHING_TYPE,PVOID,ULONG,MM_PAGE_PRIORITY); MM_SYSTEMSIZE WINAPI MmQuerySystemSize(void); diff --git a/include/objbase.h b/include/objbase.h index 4b499ffdc0f..66d72910207 100644 --- a/include/objbase.h +++ b/include/objbase.h @@ -317,9 +317,9 @@ HRESULT WINAPI CoGetInstanceFromFile(COSERVERINFO* pServerInfo, CLSID* pClsid, I HRESULT WINAPI CoGetInstanceFromIStorage(COSERVERINFO* pServerInfo, CLSID* pClsid, IUnknown* punkOuter, DWORD dwClsCtx, IStorage* pstg, DWORD dwCount, MULTI_QI* pResults);
HRESULT WINAPI CoGetMalloc(DWORD dwMemContext, LPMALLOC* lpMalloc); -LPVOID WINAPI CoTaskMemAlloc(SIZE_T size) __WINE_ALLOC_SIZE(1) __WINE_MALLOC; void WINAPI CoTaskMemFree(LPVOID ptr); -LPVOID WINAPI CoTaskMemRealloc(LPVOID ptr, SIZE_T size) __WINE_ALLOC_SIZE(2); +LPVOID WINAPI CoTaskMemAlloc(SIZE_T size) __WINE_ALLOC_SIZE(1) __WINE_DEALLOC(CoTaskMemFree) __WINE_MALLOC; +LPVOID WINAPI CoTaskMemRealloc(LPVOID ptr, SIZE_T size) __WINE_ALLOC_SIZE(2) __WINE_DEALLOC(CoTaskMemFree);
HRESULT WINAPI CoRegisterMallocSpy(LPMALLOCSPY pMallocSpy); HRESULT WINAPI CoRevokeMallocSpy(void); diff --git a/include/oleauto.h b/include/oleauto.h index 6427ff55696..27929701088 100644 --- a/include/oleauto.h +++ b/include/oleauto.h @@ -38,10 +38,10 @@ DEFINE_OLEGUID(IID_StdOle, 0x00020430,0,0); ULONG WINAPI OaBuildVersion(void);
/* BSTR functions */ -BSTR WINAPI SysAllocString(const OLECHAR*) __WINE_MALLOC; -BSTR WINAPI SysAllocStringByteLen(LPCSTR,UINT) __WINE_MALLOC; -BSTR WINAPI SysAllocStringLen(const OLECHAR*,UINT) __WINE_MALLOC; void WINAPI SysFreeString(BSTR); +BSTR WINAPI SysAllocString(const OLECHAR*) __WINE_DEALLOC(SysFreeString) __WINE_MALLOC; +BSTR WINAPI SysAllocStringByteLen(LPCSTR,UINT) __WINE_DEALLOC(SysFreeString) __WINE_MALLOC; +BSTR WINAPI SysAllocStringLen(const OLECHAR*,UINT) __WINE_DEALLOC(SysFreeString) __WINE_MALLOC; INT WINAPI SysReAllocString(LPBSTR,const OLECHAR*); int WINAPI SysReAllocStringLen(BSTR*,const OLECHAR*,UINT); UINT WINAPI SysStringByteLen(BSTR); diff --git a/include/rpcndr.h b/include/rpcndr.h index b7a5c8c4029..498aa4ddd40 100644 --- a/include/rpcndr.h +++ b/include/rpcndr.h @@ -667,10 +667,10 @@ RPCRTAPI RPC_STATUS RPC_ENTRY NdrMapCommAndFaultStatus( PMIDL_STUB_MESSAGE pStubMsg, ULONG *pCommStatus, ULONG *pFaultStatus, RPC_STATUS Status_ );
-RPCRTAPI void* RPC_ENTRY - NdrOleAllocate( SIZE_T Size ) __WINE_ALLOC_SIZE(1) __WINE_MALLOC; RPCRTAPI void RPC_ENTRY NdrOleFree( void* NodeToFree ); +RPCRTAPI void* RPC_ENTRY + NdrOleAllocate( SIZE_T Size ) __WINE_ALLOC_SIZE(1) __WINE_DEALLOC(NdrOleFree) __WINE_MALLOC;
RPCRTAPI void RPC_ENTRY NdrClientInitialize( PRPC_MESSAGE pRpcMessage, PMIDL_STUB_MESSAGE pStubMsg, @@ -728,14 +728,14 @@ RPCRTAPI void RPC_ENTRY NdrRpcSsDisableAllocate( PMIDL_STUB_MESSAGE pMessage ); RPCRTAPI void RPC_ENTRY NdrRpcSmSetClientToOsf( PMIDL_STUB_MESSAGE pMessage ); -RPCRTAPI void * RPC_ENTRY - NdrRpcSmClientAllocate( SIZE_T Size ) __WINE_ALLOC_SIZE(1) __WINE_MALLOC; RPCRTAPI void RPC_ENTRY NdrRpcSmClientFree( void *NodeToFree ); RPCRTAPI void * RPC_ENTRY - NdrRpcSsDefaultAllocate( SIZE_T Size ) __WINE_ALLOC_SIZE(1) __WINE_MALLOC; + NdrRpcSmClientAllocate( SIZE_T Size ) __WINE_ALLOC_SIZE(1) __WINE_DEALLOC(NdrRpcSmClientFree) __WINE_MALLOC; RPCRTAPI void RPC_ENTRY NdrRpcSsDefaultFree( void *NodeToFree ); +RPCRTAPI void * RPC_ENTRY + NdrRpcSsDefaultAllocate( SIZE_T Size ) __WINE_ALLOC_SIZE(1) __WINE_DEALLOC(NdrRpcSsDefaultFree) __WINE_MALLOC;
RPCRTAPI RPC_STATUS RPC_ENTRY NdrGetUserMarshalInfo( ULONG *pFlags, ULONG InformationLevel, NDR_USER_MARSHAL_INFO *pMarshalInfo ); diff --git a/include/winbase.h b/include/winbase.h index 748a248f56a..f853392cced 100644 --- a/include/winbase.h +++ b/include/winbase.h @@ -2350,7 +2350,8 @@ WINBASEAPI BOOL WINAPI GetXStateFeaturesMask(CONTEXT*,DWORD64*); WINBASEAPI ATOM WINAPI GlobalAddAtomA(LPCSTR); WINBASEAPI ATOM WINAPI GlobalAddAtomW(LPCWSTR); #define GlobalAddAtom WINELIB_NAME_AW(GlobalAddAtom) -WINBASEAPI HGLOBAL WINAPI GlobalAlloc(UINT,SIZE_T) __WINE_ALLOC_SIZE(2) __WINE_MALLOC; +WINBASEAPI HGLOBAL WINAPI GlobalFree(HGLOBAL); +WINBASEAPI HGLOBAL WINAPI GlobalAlloc(UINT,SIZE_T) __WINE_ALLOC_SIZE(2) __WINE_DEALLOC(GlobalFree) __WINE_MALLOC; WINBASEAPI SIZE_T WINAPI GlobalCompact(DWORD); WINBASEAPI ATOM WINAPI GlobalDeleteAtom(ATOM); WINBASEAPI ATOM WINAPI GlobalFindAtomA(LPCSTR); @@ -2358,7 +2359,6 @@ WINBASEAPI ATOM WINAPI GlobalFindAtomW(LPCWSTR); #define GlobalFindAtom WINELIB_NAME_AW(GlobalFindAtom) WINBASEAPI VOID WINAPI GlobalFix(HGLOBAL); WINBASEAPI UINT WINAPI GlobalFlags(HGLOBAL); -WINBASEAPI HGLOBAL WINAPI GlobalFree(HGLOBAL); WINBASEAPI UINT WINAPI GlobalGetAtomNameA(ATOM,LPSTR,INT); WINBASEAPI UINT WINAPI GlobalGetAtomNameW(ATOM,LPWSTR,INT); #define GlobalGetAtomName WINELIB_NAME_AW(GlobalGetAtomName) @@ -2366,20 +2366,20 @@ WINBASEAPI HGLOBAL WINAPI GlobalHandle(LPCVOID); WINBASEAPI LPVOID WINAPI GlobalLock(HGLOBAL); WINBASEAPI VOID WINAPI GlobalMemoryStatus(LPMEMORYSTATUS); WINBASEAPI BOOL WINAPI GlobalMemoryStatusEx(LPMEMORYSTATUSEX); -WINBASEAPI HGLOBAL WINAPI GlobalReAlloc(HGLOBAL,SIZE_T,UINT) __WINE_ALLOC_SIZE(2); +WINBASEAPI HGLOBAL WINAPI GlobalReAlloc(HGLOBAL,SIZE_T,UINT) __WINE_ALLOC_SIZE(2) __WINE_DEALLOC(GlobalFree); WINBASEAPI SIZE_T WINAPI GlobalSize(HGLOBAL); WINBASEAPI VOID WINAPI GlobalUnfix(HGLOBAL); WINBASEAPI BOOL WINAPI GlobalUnlock(HGLOBAL); WINBASEAPI BOOL WINAPI GlobalUnWire(HGLOBAL); WINBASEAPI LPVOID WINAPI GlobalWire(HGLOBAL); #define HasOverlappedIoCompleted(lpOverlapped) ((lpOverlapped)->Internal != STATUS_PENDING) -WINBASEAPI LPVOID WINAPI HeapAlloc(HANDLE,DWORD,SIZE_T) __WINE_ALLOC_SIZE(3) __WINE_MALLOC; +WINBASEAPI BOOL WINAPI HeapFree(HANDLE,DWORD,LPVOID); +WINBASEAPI LPVOID WINAPI HeapAlloc(HANDLE,DWORD,SIZE_T) __WINE_ALLOC_SIZE(3) __WINE_DEALLOC(HeapFree,3) __WINE_MALLOC; WINBASEAPI SIZE_T WINAPI HeapCompact(HANDLE,DWORD); WINBASEAPI HANDLE WINAPI HeapCreate(DWORD,SIZE_T,SIZE_T); WINBASEAPI BOOL WINAPI HeapDestroy(HANDLE); -WINBASEAPI BOOL WINAPI HeapFree(HANDLE,DWORD,LPVOID); WINBASEAPI BOOL WINAPI HeapLock(HANDLE); -WINBASEAPI LPVOID WINAPI HeapReAlloc(HANDLE,DWORD,LPVOID,SIZE_T) __WINE_ALLOC_SIZE(4); +WINBASEAPI LPVOID WINAPI HeapReAlloc(HANDLE,DWORD,LPVOID,SIZE_T) __WINE_ALLOC_SIZE(4) __WINE_DEALLOC(HeapFree); WINBASEAPI BOOL WINAPI HeapQueryInformation(HANDLE,HEAP_INFORMATION_CLASS,PVOID,SIZE_T,PSIZE_T); WINBASEAPI BOOL WINAPI HeapSetInformation(HANDLE,HEAP_INFORMATION_CLASS,PVOID,SIZE_T); WINBASEAPI SIZE_T WINAPI HeapSize(HANDLE,DWORD,LPCVOID); @@ -2440,13 +2440,13 @@ WINBASEAPI HMODULE WINAPI LoadLibraryExW(LPCWSTR,HANDLE,DWORD); WINBASEAPI DWORD WINAPI LoadModule(LPCSTR,LPVOID); WINBASEAPI HMODULE WINAPI LoadPackagedLibrary(LPCWSTR,DWORD); WINBASEAPI HGLOBAL WINAPI LoadResource(HMODULE,HRSRC); -WINBASEAPI HLOCAL WINAPI LocalAlloc(UINT,SIZE_T) __WINE_ALLOC_SIZE(2) __WINE_MALLOC; +WINBASEAPI HLOCAL WINAPI LocalFree(HLOCAL); +WINBASEAPI HLOCAL WINAPI LocalAlloc(UINT,SIZE_T) __WINE_ALLOC_SIZE(2) __WINE_DEALLOC(LocalFree) __WINE_MALLOC; WINBASEAPI SIZE_T WINAPI LocalCompact(UINT); WINBASEAPI UINT WINAPI LocalFlags(HLOCAL); -WINBASEAPI HLOCAL WINAPI LocalFree(HLOCAL); WINBASEAPI HLOCAL WINAPI LocalHandle(LPCVOID); WINBASEAPI LPVOID WINAPI LocalLock(HLOCAL); -WINBASEAPI HLOCAL WINAPI LocalReAlloc(HLOCAL,SIZE_T,UINT) __WINE_ALLOC_SIZE(2); +WINBASEAPI HLOCAL WINAPI LocalReAlloc(HLOCAL,SIZE_T,UINT) __WINE_ALLOC_SIZE(2) __WINE_DEALLOC(LocalFree); WINBASEAPI SIZE_T WINAPI LocalShrink(HGLOBAL,UINT); WINBASEAPI SIZE_T WINAPI LocalSize(HLOCAL); WINBASEAPI BOOL WINAPI LocalUnlock(HLOCAL); diff --git a/include/wincrypt.h b/include/wincrypt.h index 8adbd2c1300..59a8d6650bb 100644 --- a/include/wincrypt.h +++ b/include/wincrypt.h @@ -4043,9 +4043,9 @@ WINADVAPI BOOL WINAPI CryptVerifySignatureW (HCRYPTHASH, const BYTE *, DWORD, HC #define CryptVerifySignature WINELIB_NAME_AW(CryptVerifySignature)
/* crypt32.dll functions */ -LPVOID WINAPI CryptMemAlloc(ULONG cbSize) __WINE_ALLOC_SIZE(1) __WINE_MALLOC; -LPVOID WINAPI CryptMemRealloc(LPVOID pv, ULONG cbSize) __WINE_ALLOC_SIZE(2); VOID WINAPI CryptMemFree(LPVOID pv); +LPVOID WINAPI CryptMemAlloc(ULONG cbSize) __WINE_ALLOC_SIZE(1) __WINE_DEALLOC(CryptMemFree) __WINE_MALLOC; +LPVOID WINAPI CryptMemRealloc(LPVOID pv, ULONG cbSize) __WINE_ALLOC_SIZE(2) __WINE_DEALLOC(CryptMemFree);
BOOL WINAPI CryptBinaryToStringA(const BYTE *pbBinary, DWORD cbBinary, DWORD dwFlags, LPSTR pszString, DWORD *pcchString); diff --git a/include/winnt.h b/include/winnt.h index a0b430b47d6..5ca106d1031 100644 --- a/include/winnt.h +++ b/include/winnt.h @@ -204,6 +204,12 @@ extern "C" { #define __WINE_ALLOC_SIZE(...) #endif
+#if defined(__GNUC__) && (__GNUC__ > 10) +#define __WINE_DEALLOC(...) __attribute__((malloc (__VA_ARGS__))) +#else +#define __WINE_DEALLOC(...) +#endif + #if defined(__GNUC__) && (__GNUC__ > 2) #define __WINE_MALLOC __attribute__((malloc)) #else diff --git a/include/winternl.h b/include/winternl.h index 43a4ddf2f39..ca265cf074c 100644 --- a/include/winternl.h +++ b/include/winternl.h @@ -4200,7 +4200,8 @@ NTSYSAPI PVOID WINAPI RtlAddVectoredExceptionHandler(ULONG,PVECTORED_EXCEPTI NTSYSAPI NTSTATUS WINAPI RtlAdjustPrivilege(ULONG,BOOLEAN,BOOLEAN,PBOOLEAN); NTSYSAPI NTSTATUS WINAPI RtlAllocateAndInitializeSid(PSID_IDENTIFIER_AUTHORITY,BYTE,DWORD,DWORD,DWORD,DWORD,DWORD,DWORD,DWORD,DWORD,PSID *); NTSYSAPI RTL_HANDLE * WINAPI RtlAllocateHandle(RTL_HANDLE_TABLE *,ULONG *); -NTSYSAPI PVOID WINAPI RtlAllocateHeap(HANDLE,ULONG,SIZE_T) __WINE_ALLOC_SIZE(3) __WINE_MALLOC; +NTSYSAPI BOOLEAN WINAPI RtlFreeHeap(HANDLE,ULONG,PVOID); +NTSYSAPI PVOID WINAPI RtlAllocateHeap(HANDLE,ULONG,SIZE_T) __WINE_ALLOC_SIZE(3) __WINE_DEALLOC(RtlFreeHeap,3) __WINE_MALLOC; NTSYSAPI WCHAR WINAPI RtlAnsiCharToUnicodeChar(LPSTR *); NTSYSAPI DWORD WINAPI RtlAnsiStringToUnicodeSize(const STRING *); NTSYSAPI NTSTATUS WINAPI RtlAnsiStringToUnicodeString(PUNICODE_STRING,PCANSI_STRING,BOOLEAN);
From: Brendan Shanks bshanks@codeweavers.com
--- dlls/crypt32/tests/encode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/dlls/crypt32/tests/encode.c b/dlls/crypt32/tests/encode.c index 9dabe58efba..b65ffde3a84 100644 --- a/dlls/crypt32/tests/encode.c +++ b/dlls/crypt32/tests/encode.c @@ -2603,7 +2603,7 @@ static void test_decodeRsaPublicKey_Bcrypt(DWORD dwEncoding) rsaPubKeys[i].modulus, rsaPubKeys[i].decodedModulusLen), "Unexpected modulus\n"); LocalFree(buf); - LocalFree(leModulus); + HeapFree(GetProcessHeap(), 0, leModulus); } } }
On Mon May 16 04:34:00 2022 +0000, **** wrote:
Zebediah Figura replied on the mailing list:
On 5/15/22 23:27, Brendan Shanks (@bshanks) wrote: > I was going to use a separate define (something like __WINE_DEALLOC), since as mentioned it could also be useful for non-malloc functions like fopen/fclose, SysAllocString/SysFreeString, etc. Is SysAllocString not malloc-like? It has a header, but I assume that shouldn't matter...
That's true, it does qualify for attribute(malloc), I've added that now.