summaryrefslogtreecommitdiff
path: root/accel-pptpd/triton/triton_p.h
blob: 0602bfa0b4e837fbc8b754b14520462e3fb42ca4 (plain)
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#ifndef TRITON_P_H
#define TRITON_P_H

#include "triton.h"
#include "list.h"

#include <stdarg.h>
#include <ucontext.h>

#define MAX_ARGS 32

struct option_t
{
	struct list_head entry;

	char *name;
	char *val;
};

struct md_handler_t
{
	struct list_head entry;

	int fd;
	int del;
	int timeout;
	int volatile in_handler;

	struct coroutine_t *coro;

	struct triton_md_handler_t *handler;
};

struct timer_t
{
	struct list_head entry;
	int del;
	struct triton_timer_t *timer;
};

struct timer_single_shot_t
{
	struct list_head entry;

	struct timeval expire_tv;
	int arg_cnt;
	void *args;
	triton_ss_func ss_func;
};

struct event_handler_t
{
	struct list_head entry;

	int arg_cnt;
	void *args;
	triton_event_func event_func;
};
struct event_t
{
	struct list_head entry;

	int ev_id;
	struct list_head handlers;
};

struct coroutine_t
{
	struct list_head entry;
	ucontext_t uc;
	struct timeval timeout;
	struct timeval time;
};


extern struct list_head components;
extern void md_run();
extern void md_terminate();
extern int timer_prepare(struct timeval *tv);
extern void timer_check(struct timeval *tv);
extern int coroutine_get_timeout(struct timeval *tv);
extern void coroutine_check_timeout(struct timeval *tv);
extern void event_init();
extern struct coroutine_t *current_coro;
void schedule(void);

//#define BROKEN_GCC

#ifdef BROKEN_GCC
#define dyn_call(func,arg_cnt,args)\
{\
	switch(arg_cnt)\
	{\
		case 0: \
		{\
			typedef void (*func0)(void);\
			((func0)func)();\
			break;\
		}\
		case 1: \
		{\
			typedef void (*func0)(long);\
			((func0)func)(*((long*)args+0));\
			break;\
		}\
		case 2: \
		{\
			typedef void (*func0)(long,long);\
			((func0)func)(*((long*)args+0),*((long*)args+1));\
			break;\
		}\
		case 3: \
		{\
			typedef void (*func0)(long,long,long);\
			((func0)func)(*((long*)args+0),*((long*)args+1),*((long*)args+2));\
			break;\
		}\
		case 4: \
		{\
			typedef void (*func0)(long,long,long,long);\
			((func0)func)(*((long*)args+0),*((long*)args+1),*((long*)args+2),*((long*)args+3));\
			break;\
		}\
	}\
}
#else
#define dyn_call(func,arg_cnt,args)\
{\
	int aaa=arg_cnt*sizeof(long);\
	asm("subl %2,%%esp; \n\
			 movl %%esp,%%edi;\n\
			 movl %0,%%esi;\n\
			 cld;\n\
			 rep movsl;\n\
			 call *%1;\n\
			 addl %2,%%esp\n"::"m" (args),"m" (func),"g" (aaa),"c"(arg_cnt):"%edi","%esi","%esp");\
}
#endif

#endif