MushOS  0.1
A UNIX-like OS prototype, written from scratch
Loading...
Searching...
No Matches
vararg.h
1#ifndef MUSHLIB_VARARG_H
2#define MUSHLIB_VARARG_H
3
4#include "heap.h"
5#include "math.h"
6
7
8#define init_vararg(skip) ({\
9 u_dword offset = skip & 0xfffffffc;\
10 if (skip % 4 != 0) offset += 4;\
11 offset;\
12})
13
14#define get_vararg(offset, type) ({\
15 type result = get_arg(offset, type);\
16 offset += max(sizeof(type), 4);\
17 result;\
18})
19
20
21// TODO: check stack base with error!
22#define get_arg(skip, type) ({\
23 type* arg;\
24 asm volatile(\
25 "add %%ebp, %1\n"\
26 "mov %1, %0"\
27 : "=r"(arg): "r"(8 + skip)\
28 );\
29 *arg;\
30})
31
32void* extract_dword_args(u_dword args_num, ...);
33
34#endif // MUSHLIB_VARARG_H
This is a standard MushLib heap header. See standard implementation in lib/base/heap....