XenevaOS
Loading...
Searching...
No Matches
stdarg.h
Go to the documentation of this file.
1
30#ifndef __STDARG_H__
31#define __STDARG_H__
32
33#ifdef __cplusplus
34extern "C" {
35#endif
36
37/* va list parameter list.
38 * On AArch64 va_list is the compiler builtin (see below); the flat
39 * pointer version only applies to the legacy x86/x64 path. */
40#if !defined(ARCH_ARM64) && !defined(__aarch64__)
41typedef unsigned char* va_list;
42#endif
43
44/* width of stack == width of int */
45#define STACKITEM int64_t
46
47/* round up width of objects pushed on stack. The expression before the
48 & ensures that we get 0 for objects of size 0. */
49#define VA_SIZE(TYPE) ((sizeof(TYPE) + sizeof(STACKITEM) - 1) & ~(sizeof(STACKITEM) - 1))
50
51#ifdef ARCH_X64
52/* &(LASTARG) points to the LEFTMOST argument of the function call
53 (before the ...) */
54#define va_start(AP, LASTARG) (AP = ((va_list) & (LASTARG) + VA_SIZE(LASTARG)))
55
56/* nothing for va_end */
57#define va_end(AP)
58
59#define va_arg(AP, TYPE) (AP += VA_SIZE(TYPE), *((TYPE*)(AP - VA_SIZE(TYPE))))
60#elif defined(ARCH_ARM64) || defined(__aarch64__)
61/* AArch64: use the compiler's native va_list/va_start/va_arg.
62 * The old hand-rolled "ap = &last + 8" pointer walk is wrong on AArch64:
63 * it only works when combined with the _store_stack_param register
64 * snapshot, which covers printf/sprintf/snprintf but NOT forwarded
65 * va_lists (vfprintf/vprintf/vsnprintf/vsprintf, I_Error, M_snprintf).
66 * The builtins are correct for the target ABI (AAPCS64 or WoA). */
67
68typedef __builtin_va_list va_list;
69
70#define va_start(ap, last) __builtin_va_start(ap, last)
71
72#define va_arg(ap, T) __builtin_va_arg(ap, T)
73
74#define va_end(ap) __builtin_va_end(ap)
75
76#define va_copy(dst, src) __builtin_va_copy(dst, src)
77#endif
78
79#ifdef __cplusplus
80}
81#endif
82
83#endif
unsigned char * va_list
Definition stdarg.h:61