XenevaOS
Loading...
Searching...
No Matches
stdarg.h
Go to the documentation of this file.
1
31#ifndef __STDARG_H__
32#define __STDARG_H__
33
34
35#ifdef __cplusplus
36extern "C"
37{
38#endif
39
40
41 /*
42 * __clang__ is deliberately *not* tested above. mainline's
43 * <linux/stdarg.h> forwards here, so whichever type is typedef'd
44 * below is the one every drm source sees -- and the two drm users
45 * want opposite things from it. drm_print.c needs the builtins
46 * (clang's va_start rejects a hand-rolled pointer), and
47 * KernelAA64/Drivers/uart.c:129 needs the flat one, because
48 * `va_list args = ((va_list)reg_save_area + 8)` only compiles when
49 * va_list is a pointer it can cast and add to.
50 *
51 * XEClib's userspace copy of this header
52 * (Libs/XEClib/includes/stdarg.h) *has* moved arm-64 to the builtins,
53 * with a note naming the forwarded-va_list cases the pointer walk gets
54 * wrong. When this side follows it, the thing that has to change is
55 * uart.c's register-save-area walk -- not this typedef back and forth.
56 */
57#ifdef __GNUC__
58 typedef __builtin_va_list va_list;
59#else
60 /* va list parameter list */
61 typedef unsigned char* va_list;
62#endif
63
64
65 /* width of stack == width of int */
66#define STACKITEM int64_t
67
68 /* round up width of objects pushed on stack. The expression before the
69 & ensures that we get 0 for objects of size 0. */
70#define VA_SIZE(TYPE) \
71 ((sizeof(TYPE)+sizeof(STACKITEM)-1) \
72 & ~(sizeof(STACKITEM)-1))
73
74#if defined(ARCH_X64) || defined(__x86_64__)
75 /* &(LASTARG) points to the LEFTMOST argument of the function call
76 (before the ...) */
77#define va_start(AP, LASTARG) \
78 (AP = ((va_list)&(LASTARG)+VA_SIZE(LASTARG)))
79
80 /* nothing for va_end */
81#define va_end(AP)
82
83#define va_arg(AP, TYPE) \
84 (AP += VA_SIZE(TYPE), *((TYPE *)(AP - VA_SIZE(TYPE))))
85#elif defined(ARCH_ARM64) || defined(__aarch64__)
86#ifdef __GNUC__
87#define va_start(ap, last) __builtin_va_start(ap, last)
88#define va_arg(ap, type) __builtin_va_arg(ap, type)
89#define va_end(ap) __builtin_va_end(ap)
90#else
91#define va_start(ap,last) \
92 ((ap) = (va_list)(&(last)) + 8)
93
94#define va_arg(ap,T) \
95 (*(T*)((ap) += 8, (ap) - 8))
96
97#define va_end(ap) \
98 ((ap) = (va_list)0)
99#endif
100#endif
101
102#ifdef __cplusplus
103}
104#endif
105
106
107#endif
unsigned char * va_list
Definition stdarg.h:61