Skip to content

Commit c52aed9

Browse files
committed
[ASan][Windows] Add __cdecl to public sanitizer functions (llvm#69625)
This is necessary for many projects which pass `/Gz` to their compiles, which makes their default calling convention `__stdcall`. (personal note, I _really_ wish there was a pragma for this) (cherry picked from commit b799080)
1 parent 361f7ab commit c52aed9

13 files changed

+698
-614
lines changed

compiler-rt/include/sanitizer/allocator_interface.h

Lines changed: 59 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -11,78 +11,80 @@
1111
#ifndef SANITIZER_ALLOCATOR_INTERFACE_H
1212
#define SANITIZER_ALLOCATOR_INTERFACE_H
1313

14+
#include <sanitizer/common_interface_defs.h>
1415
#include <stddef.h>
1516

1617
#ifdef __cplusplus
1718
extern "C" {
1819
#endif
19-
/* Returns the estimated number of bytes that will be reserved by allocator
20-
for request of "size" bytes. If allocator can't allocate that much
21-
memory, returns the maximal possible allocation size, otherwise returns
22-
"size". */
23-
size_t __sanitizer_get_estimated_allocated_size(size_t size);
20+
/* Returns the estimated number of bytes that will be reserved by allocator
21+
for request of "size" bytes. If allocator can't allocate that much
22+
memory, returns the maximal possible allocation size, otherwise returns
23+
"size". */
24+
size_t SANITIZER_CDECL __sanitizer_get_estimated_allocated_size(size_t size);
2425

25-
/* Returns true if p was returned by the allocator and
26-
is not yet freed. */
27-
int __sanitizer_get_ownership(const volatile void *p);
26+
/* Returns true if p was returned by the allocator and
27+
is not yet freed. */
28+
int SANITIZER_CDECL __sanitizer_get_ownership(const volatile void *p);
2829

29-
/* Returns the number of bytes reserved for the pointer p.
30-
Requires (get_ownership(p) == true) or (p == 0). */
31-
size_t __sanitizer_get_allocated_size(const volatile void *p);
30+
/* Returns the number of bytes reserved for the pointer p.
31+
Requires (get_ownership(p) == true) or (p == 0). */
32+
size_t SANITIZER_CDECL __sanitizer_get_allocated_size(const volatile void *p);
3233

33-
/* Number of bytes, allocated and not yet freed by the application. */
34-
size_t __sanitizer_get_current_allocated_bytes(void);
34+
/* Number of bytes, allocated and not yet freed by the application. */
35+
size_t SANITIZER_CDECL __sanitizer_get_current_allocated_bytes(void);
3536

36-
/* Number of bytes, mmaped by the allocator to fulfill allocation requests.
37-
Generally, for request of X bytes, allocator can reserve and add to free
38-
lists a large number of chunks of size X to use them for future requests.
39-
All these chunks count toward the heap size. Currently, allocator never
40-
releases memory to OS (instead, it just puts freed chunks to free
41-
lists). */
42-
size_t __sanitizer_get_heap_size(void);
37+
/* Number of bytes, mmaped by the allocator to fulfill allocation requests.
38+
Generally, for request of X bytes, allocator can reserve and add to free
39+
lists a large number of chunks of size X to use them for future requests.
40+
All these chunks count toward the heap size. Currently, allocator never
41+
releases memory to OS (instead, it just puts freed chunks to free
42+
lists). */
43+
size_t SANITIZER_CDECL __sanitizer_get_heap_size(void);
4344

44-
/* Number of bytes, mmaped by the allocator, which can be used to fulfill
45-
allocation requests. When a user program frees memory chunk, it can first
46-
fall into quarantine and will count toward __sanitizer_get_free_bytes()
47-
later. */
48-
size_t __sanitizer_get_free_bytes(void);
45+
/* Number of bytes, mmaped by the allocator, which can be used to fulfill
46+
allocation requests. When a user program frees memory chunk, it can first
47+
fall into quarantine and will count toward __sanitizer_get_free_bytes()
48+
later. */
49+
size_t SANITIZER_CDECL __sanitizer_get_free_bytes(void);
4950

50-
/* Number of bytes in unmapped pages, that are released to OS. Currently,
51-
always returns 0. */
52-
size_t __sanitizer_get_unmapped_bytes(void);
51+
/* Number of bytes in unmapped pages, that are released to OS. Currently,
52+
always returns 0. */
53+
size_t SANITIZER_CDECL __sanitizer_get_unmapped_bytes(void);
5354

54-
/* Malloc hooks that may be optionally provided by user.
55-
__sanitizer_malloc_hook(ptr, size) is called immediately after
56-
allocation of "size" bytes, which returned "ptr".
57-
__sanitizer_free_hook(ptr) is called immediately before
58-
deallocation of "ptr". */
59-
void __sanitizer_malloc_hook(const volatile void *ptr, size_t size);
60-
void __sanitizer_free_hook(const volatile void *ptr);
55+
/* Malloc hooks that may be optionally provided by user.
56+
__sanitizer_malloc_hook(ptr, size) is called immediately after
57+
allocation of "size" bytes, which returned "ptr".
58+
__sanitizer_free_hook(ptr) is called immediately before
59+
deallocation of "ptr". */
60+
void SANITIZER_CDECL __sanitizer_malloc_hook(const volatile void *ptr,
61+
size_t size);
62+
void SANITIZER_CDECL __sanitizer_free_hook(const volatile void *ptr);
6163

62-
/* Installs a pair of hooks for malloc/free.
63-
Several (currently, 5) hook pairs may be installed, they are executed
64-
in the order they were installed and after calling
65-
__sanitizer_malloc_hook/__sanitizer_free_hook.
66-
Unlike __sanitizer_malloc_hook/__sanitizer_free_hook these hooks can be
67-
chained and do not rely on weak symbols working on the platform, but
68-
require __sanitizer_install_malloc_and_free_hooks to be called at startup
69-
and thus will not be called on malloc/free very early in the process.
70-
Returns the number of hooks currently installed or 0 on failure.
71-
Not thread-safe, should be called in the main thread before starting
72-
other threads.
73-
*/
74-
int __sanitizer_install_malloc_and_free_hooks(
75-
void (*malloc_hook)(const volatile void *, size_t),
76-
void (*free_hook)(const volatile void *));
64+
/* Installs a pair of hooks for malloc/free.
65+
Several (currently, 5) hook pairs may be installed, they are executed
66+
in the order they were installed and after calling
67+
__sanitizer_malloc_hook/__sanitizer_free_hook.
68+
Unlike __sanitizer_malloc_hook/__sanitizer_free_hook these hooks can be
69+
chained and do not rely on weak symbols working on the platform, but
70+
require __sanitizer_install_malloc_and_free_hooks to be called at startup
71+
and thus will not be called on malloc/free very early in the process.
72+
Returns the number of hooks currently installed or 0 on failure.
73+
Not thread-safe, should be called in the main thread before starting
74+
other threads.
75+
*/
76+
int SANITIZER_CDECL __sanitizer_install_malloc_and_free_hooks(
77+
void (*SANITIZER_CDECL malloc_hook)(const volatile void *, size_t),
78+
void (*SANITIZER_CDECL free_hook)(const volatile void *));
7779

78-
/* Drains allocator quarantines (calling thread's and global ones), returns
79-
freed memory back to OS and releases other non-essential internal allocator
80-
resources in attempt to reduce process RSS.
81-
Currently available with ASan only.
82-
*/
83-
void __sanitizer_purge_allocator(void);
80+
/* Drains allocator quarantines (calling thread's and global ones), returns
81+
freed memory back to OS and releases other non-essential internal allocator
82+
resources in attempt to reduce process RSS.
83+
Currently available with ASan only.
84+
*/
85+
void SANITIZER_CDECL __sanitizer_purge_allocator(void);
8486
#ifdef __cplusplus
85-
} // extern "C"
87+
} // extern "C"
8688
#endif
8789

8890
#endif

0 commit comments

Comments
 (0)