-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreference.h
More file actions
34 lines (30 loc) · 801 Bytes
/
reference.h
File metadata and controls
34 lines (30 loc) · 801 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <string.h>
#define SPACERSIZE 200
#define PASTE_HELPER(a,b) a ## b
#define PASTE(a,b) PASTE_HELPER(a,b)
#define STRINGIFY(x) #x
#define TOSTRING(x) STRINGIFY(x)
typedef struct {
char a[SPACERSIZE];
} bigStruct;
#define by_ref(type, varName) type var){ \
long addr = 0; \
for (int i = 1; i < SPACERSIZE; i++) { \
if (!memcmp(&var, (char *) &var + i, sizeof(type))) {\
addr = (long) &var + i; \
} \
} \
if (!addr) \
return; \
long rsp; \
addr -= SPACERSIZE; \
asm( \
"mov %%rsp, %0 \n\t" \
"mov %1, %%rsp \n\t" \
"call FUNC" TOSTRING(__LINE__) "\n\t" \
"mov %0, %%rsp" \
:"=m" (rsp) \
: "m" (addr) \
); \
} \
int PASTE(FUNC, __LINE__) (bigStruct FUNCSPACER, type varName