xref: /aosp_15_r20/external/clang/test/Analysis/Inputs/system-header-simulator.h (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li // Like the compiler, the static analyzer treats some functions differently if
2*67e74705SXin Li // they come from a system header -- for example, it is assumed that system
3*67e74705SXin Li // functions do not arbitrarily free() their parameters, and that some bugs
4*67e74705SXin Li // found in system headers cannot be fixed by the user and should be
5*67e74705SXin Li // suppressed.
6*67e74705SXin Li #pragma clang system_header
7*67e74705SXin Li 
8*67e74705SXin Li #ifdef __cplusplus
9*67e74705SXin Li #define restrict /*restrict*/
10*67e74705SXin Li #endif
11*67e74705SXin Li 
12*67e74705SXin Li typedef struct _FILE FILE;
13*67e74705SXin Li extern FILE *stdin;
14*67e74705SXin Li extern FILE *stdout;
15*67e74705SXin Li extern FILE *stderr;
16*67e74705SXin Li // Include a variant of standard streams that occur in the pre-processed file.
17*67e74705SXin Li extern FILE *__stdinp;
18*67e74705SXin Li extern FILE *__stdoutp;
19*67e74705SXin Li extern FILE *__stderrp;
20*67e74705SXin Li 
21*67e74705SXin Li int scanf(const char *restrict format, ...);
22*67e74705SXin Li int fscanf(FILE *restrict, const char *restrict, ...);
23*67e74705SXin Li int printf(const char *restrict format, ...);
24*67e74705SXin Li int fprintf(FILE *restrict, const char *restrict, ...);
25*67e74705SXin Li int getchar(void);
26*67e74705SXin Li 
27*67e74705SXin Li // Note, on some platforms errno macro gets replaced with a function call.
28*67e74705SXin Li extern int errno;
29*67e74705SXin Li 
30*67e74705SXin Li typedef __typeof(sizeof(int)) size_t;
31*67e74705SXin Li 
32*67e74705SXin Li size_t strlen(const char *);
33*67e74705SXin Li 
34*67e74705SXin Li char *strcpy(char *restrict, const char *restrict);
35*67e74705SXin Li void *memcpy(void *dst, const void *src, size_t n);
36*67e74705SXin Li 
37*67e74705SXin Li typedef unsigned long __darwin_pthread_key_t;
38*67e74705SXin Li typedef __darwin_pthread_key_t pthread_key_t;
39*67e74705SXin Li int pthread_setspecific(pthread_key_t, const void *);
40*67e74705SXin Li 
41*67e74705SXin Li typedef long long __int64_t;
42*67e74705SXin Li typedef __int64_t __darwin_off_t;
43*67e74705SXin Li typedef __darwin_off_t fpos_t;
44*67e74705SXin Li 
45*67e74705SXin Li void setbuf(FILE * restrict, char * restrict);
46*67e74705SXin Li int setvbuf(FILE * restrict, char * restrict, int, size_t);
47*67e74705SXin Li 
48*67e74705SXin Li FILE *fopen(const char * restrict, const char * restrict);
49*67e74705SXin Li int fclose(FILE *);
50*67e74705SXin Li FILE *funopen(const void *,
51*67e74705SXin Li                  int (*)(void *, char *, int),
52*67e74705SXin Li                  int (*)(void *, const char *, int),
53*67e74705SXin Li                  fpos_t (*)(void *, fpos_t, int),
54*67e74705SXin Li                  int (*)(void *));
55*67e74705SXin Li 
56*67e74705SXin Li int sqlite3_bind_text_my(int, const char*, int n, void(*)(void*));
57*67e74705SXin Li 
58*67e74705SXin Li typedef void (*freeCallback) (void*);
59*67e74705SXin Li typedef struct {
60*67e74705SXin Li   int i;
61*67e74705SXin Li   freeCallback fc;
62*67e74705SXin Li } StWithCallback;
63*67e74705SXin Li 
64*67e74705SXin Li int dealocateMemWhenDoneByVal(void*, StWithCallback);
65*67e74705SXin Li int dealocateMemWhenDoneByRef(StWithCallback*, const void*);
66*67e74705SXin Li 
67*67e74705SXin Li typedef struct CGContext *CGContextRef;
68*67e74705SXin Li CGContextRef CGBitmapContextCreate(void *data/*, size_t width, size_t height,
69*67e74705SXin Li                                    size_t bitsPerComponent, size_t bytesPerRow,
70*67e74705SXin Li                                    CGColorSpaceRef space,
71*67e74705SXin Li                                    CGBitmapInfo bitmapInfo*/);
72*67e74705SXin Li void *CGBitmapContextGetData(CGContextRef context);
73*67e74705SXin Li 
74*67e74705SXin Li // Include xpc.
75*67e74705SXin Li typedef struct _xpc_connection_s * xpc_connection_t;
76*67e74705SXin Li typedef void (*xpc_finalizer_t)(void *value);
77*67e74705SXin Li void xpc_connection_set_context(xpc_connection_t connection, void *context);
78*67e74705SXin Li void xpc_connection_set_finalizer_f(xpc_connection_t connection, xpc_finalizer_t finalizer);
79*67e74705SXin Li void xpc_connection_resume(xpc_connection_t connection);
80*67e74705SXin Li 
81*67e74705SXin Li //The following are fake system header functions for generic testing.
82*67e74705SXin Li void fakeSystemHeaderCallInt(int *);
83*67e74705SXin Li void fakeSystemHeaderCallIntPtr(int **);
84*67e74705SXin Li 
85*67e74705SXin Li // Some data strauctures may hold onto the pointer and free it later.
86*67e74705SXin Li void fake_insque(void *, void *);
87*67e74705SXin Li typedef struct fake_rb_tree { void *opaque[8]; } fake_rb_tree_t;
88*67e74705SXin Li void fake_rb_tree_init(fake_rb_tree_t *, const void *);
89*67e74705SXin Li void *fake_rb_tree_insert_node(fake_rb_tree_t *, void *);
90*67e74705SXin Li 
91*67e74705SXin Li typedef struct __SomeStruct {
92*67e74705SXin Li   char * p;
93*67e74705SXin Li } SomeStruct;
94*67e74705SXin Li void fakeSystemHeaderCall(SomeStruct *);
95*67e74705SXin Li 
96*67e74705SXin Li typedef int pid_t;
97*67e74705SXin Li pid_t fork(void);
98*67e74705SXin Li pid_t vfork(void);
99*67e74705SXin Li int execl(const char *path, const char *arg, ...);
100*67e74705SXin Li 
101*67e74705SXin Li void exit(int status) __attribute__ ((__noreturn__));
102*67e74705SXin Li void _exit(int status) __attribute__ ((__noreturn__));
103*67e74705SXin Li void _Exit(int status) __attribute__ ((__noreturn__));
104*67e74705SXin Li 
105