-- v8: include/msvcrt: Add __WINE_(ALLOC_SIZE|DEALLOC) attributes to _recalloc. include/msvcrt: Add __WINE_(ALLOC_SIZE|DEALLOC|MALLOC) attributes to _aligned_malloc functions. include/msvcrt: Add __WINE_(DEALLOC|MALLOC) attributes to _strdup and _wcsdup.
From: Brendan Shanks bshanks@codeweavers.com
--- include/msvcrt/corecrt.h | 12 ++++++++++++ include/msvcrt/corecrt_wstring.h | 3 ++- include/msvcrt/string.h | 3 ++- 3 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/include/msvcrt/corecrt.h b/include/msvcrt/corecrt.h index aba9bc9422e..9f403c7d10e 100644 --- a/include/msvcrt/corecrt.h +++ b/include/msvcrt/corecrt.h @@ -342,4 +342,16 @@ typedef struct threadlocaleinfostruct { #define __WINE_CRT_SCANF_ATTR(fmt,args) #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 +#define __WINE_MALLOC +#endif + #endif /* __WINE_CORECRT_H */ diff --git a/include/msvcrt/corecrt_wstring.h b/include/msvcrt/corecrt_wstring.h index bcf9f947625..4d012800f65 100644 --- a/include/msvcrt/corecrt_wstring.h +++ b/include/msvcrt/corecrt_wstring.h @@ -7,6 +7,7 @@ #define _WSTRING_DEFINED
#include <corecrt.h> +#include <corecrt_malloc.h>
#ifdef __cplusplus extern "C" { @@ -29,7 +30,7 @@ static inline void* memccpy(void *s1, const void *s2, int c, size_t n) { return
_ACRTIMP void* __cdecl memmove(void*,const void*,size_t);
-_ACRTIMP wchar_t* __cdecl _wcsdup(const wchar_t*); +_ACRTIMP wchar_t* __cdecl _wcsdup(const wchar_t*) __WINE_DEALLOC(free) __WINE_MALLOC; _ACRTIMP int __cdecl _wcsicmp(const wchar_t*,const wchar_t*); _ACRTIMP int __cdecl _wcsicoll(const wchar_t*,const wchar_t*); _ACRTIMP int __cdecl _wcsicoll_l(const wchar_t*, const wchar_t*, _locale_t); diff --git a/include/msvcrt/string.h b/include/msvcrt/string.h index 5e3d51076c6..18d424b1e6a 100644 --- a/include/msvcrt/string.h +++ b/include/msvcrt/string.h @@ -8,6 +8,7 @@ #ifndef __WINE_STRING_H #define __WINE_STRING_H
+#include <corecrt_malloc.h> #include <corecrt_wstring.h>
#ifndef _NLSCMP_DEFINED @@ -22,7 +23,7 @@ extern "C" { _ACRTIMP size_t __cdecl __strncnt(const char*,size_t); _ACRTIMP int __cdecl _strcmpi(const char*,const char*); _ACRTIMP int __cdecl _strcoll_l(const char*, const char*, _locale_t); -_ACRTIMP char* __cdecl _strdup(const char*); +_ACRTIMP char* __cdecl _strdup(const char*) __WINE_DEALLOC(free) __WINE_MALLOC; _ACRTIMP char* __cdecl _strerror(const char*); _ACRTIMP errno_t __cdecl strerror_s(char*,size_t,int); _ACRTIMP int __cdecl _stricmp(const char*,const char*);
From: Brendan Shanks bshanks@codeweavers.com
--- include/msvcrt/corecrt.h | 6 ++++++ include/msvcrt/corecrt_malloc.h | 8 ++++---- 2 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/include/msvcrt/corecrt.h b/include/msvcrt/corecrt.h index 9f403c7d10e..4dc2ca53208 100644 --- a/include/msvcrt/corecrt.h +++ b/include/msvcrt/corecrt.h @@ -342,6 +342,12 @@ typedef struct threadlocaleinfostruct { #define __WINE_CRT_SCANF_ATTR(fmt,args) #endif
+#if defined(__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 3))) +#define __WINE_ALLOC_SIZE(...) __attribute__((__alloc_size__(__VA_ARGS__))) +#else +#define __WINE_ALLOC_SIZE(...) +#endif + #if defined(__GNUC__) && (__GNUC__ > 10) #define __WINE_DEALLOC(...) __attribute__((malloc (__VA_ARGS__))) #else diff --git a/include/msvcrt/corecrt_malloc.h b/include/msvcrt/corecrt_malloc.h index 4c0d35f7e08..4dfb9367a11 100644 --- a/include/msvcrt/corecrt_malloc.h +++ b/include/msvcrt/corecrt_malloc.h @@ -36,10 +36,10 @@ _ACRTIMP void* __cdecl _expand(void*,size_t); _ACRTIMP size_t __cdecl _msize(void*);
_ACRTIMP void __cdecl _aligned_free(void*); -_ACRTIMP void* __cdecl _aligned_malloc(size_t,size_t); -_ACRTIMP void* __cdecl _aligned_offset_malloc(size_t,size_t,size_t); -_ACRTIMP void* __cdecl _aligned_realloc(void*,size_t,size_t); -_ACRTIMP void* __cdecl _aligned_offset_realloc(void*,size_t,size_t,size_t); +_ACRTIMP void* __cdecl _aligned_malloc(size_t,size_t) __WINE_ALLOC_SIZE(1) __WINE_DEALLOC(_aligned_free) __WINE_MALLOC; +_ACRTIMP void* __cdecl _aligned_offset_malloc(size_t,size_t,size_t) __WINE_ALLOC_SIZE(1) __WINE_DEALLOC(_aligned_free) __WINE_MALLOC; +_ACRTIMP void* __cdecl _aligned_realloc(void*,size_t,size_t) __WINE_ALLOC_SIZE(2) __WINE_DEALLOC(_aligned_free); +_ACRTIMP void* __cdecl _aligned_offset_realloc(void*,size_t,size_t,size_t) __WINE_ALLOC_SIZE(2) __WINE_DEALLOC(_aligned_free);
#ifdef __cplusplus }
From: Brendan Shanks bshanks@codeweavers.com
--- include/msvcrt/corecrt_malloc.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/msvcrt/corecrt_malloc.h b/include/msvcrt/corecrt_malloc.h index 4dfb9367a11..ab3f03fcb04 100644 --- a/include/msvcrt/corecrt_malloc.h +++ b/include/msvcrt/corecrt_malloc.h @@ -30,7 +30,7 @@ _ACRTIMP void* __cdecl calloc(size_t,size_t); _ACRTIMP void __cdecl free(void*); _ACRTIMP void* __cdecl malloc(size_t); _ACRTIMP void* __cdecl realloc(void*,size_t); -_ACRTIMP void* __cdecl _recalloc(void*,size_t,size_t); +_ACRTIMP void* __cdecl _recalloc(void*,size_t,size_t) __WINE_ALLOC_SIZE(2,3) __WINE_DEALLOC(free);
_ACRTIMP void* __cdecl _expand(void*,size_t); _ACRTIMP size_t __cdecl _msize(void*);
Hi,
It looks like your patch introduced the new failures shown below. Please investigate and fix them before resubmitting your patch. If they are not new, fixing them anyway would help a lot. Otherwise please ask for the known failures list to be updated.
The tests also ran into some preexisting test failures. If you know how to fix them that would be helpful. See the TestBot job for the details:
The full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=127621
Your paranoid android.
=== debian11 (32 bit report) ===
ntoskrnl.exe: ntoskrnl.c:1715: Test succeeded inside todo block: got error 997
This merge request was approved by Alex Henrie.
The patch looks good for me. It will need to be rebased, mainly to confirm that test pipeline passes this time.
Is the version check correct for `__alloc_size__`? Kernel disables it for gcc <= 9.1 with following comment: ```c /* * Prior to 9.1, -Wno-alloc-size-larger-than (and therefore the "alloc_size" * attribute) do not work, and must be disabled. */ ```
On Wed Jan 25 17:54:16 2023 +0000, Piotr Caban wrote:
The patch looks good for me. It will need to be rebased, mainly to confirm that test pipeline passes this time. Is the version check correct for `__alloc_size__`? Kernel disables it for gcc <= 9.1 with following comment:
/* * Prior to 9.1, -Wno-alloc-size-larger-than (and therefore the "alloc_size" * attribute) do not work, and must be disabled. */
Great, I'll push a new version shortly. I don't think the [kernel's reasoning for disabling it on < 9.1](https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?i...) applies to us, they have a code-path which could return `SIZE_MAX` as an allocation size (a sentinel for overflow which is caught at runtime) and this triggered false-positive `alloc-size-larger-than` warnings on < 9.1.