- Notifications
You must be signed in to change notification settings - Fork 87
Expand file tree
/
Copy pathtaskimpl.h
More file actions
Latest commit
182 lines (159 loc) · 4.08 KB
/
Copy pathtaskimpl.h
File metadata and controls
182 lines (159 loc) · 4.08 KB
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/* Copyright (c) 2005-2006 Russ Cox, MIT; see COPYRIGHT */
#if defined(__sun__)
# define__EXTENSIONS__ 1 /* SunOS */
# if defined(__SunOS5_6__) || defined(__SunOS5_7__) || defined(__SunOS5_8__)
/* NOT USING #define __MAKECONTEXT_V2_SOURCE 1 / * SunOS */
# else
# define__MAKECONTEXT_V2_SOURCE 1
# endif
#endif
#defineUSE_UCONTEXT 1
#if defined(__OpenBSD__) || defined(__mips__)
#undef USE_UCONTEXT
#defineUSE_UCONTEXT 0
#endif
#if defined(__APPLE__)
#include<AvailabilityMacros.h>
#if defined(MAC_OS_X_VERSION_10_5)
#undef USE_UCONTEXT
#defineUSE_UCONTEXT 0
#endif
#endif
#include<errno.h>
#include<stdlib.h>
#include<unistd.h>
#include<string.h>
#include<assert.h>
#include<time.h>
#include<sys/time.h>
#include<sys/types.h>
#include<sys/wait.h>
#include<sched.h>
#include<signal.h>
#ifUSE_UCONTEXT
#include<ucontext.h>
#endif
#include<sys/utsname.h>
#include<inttypes.h>
#include"task.h"
#definenil ((void*)0)
#definenelem(x) (sizeof(x)/sizeof((x)[0]))
#defineulong task_ulong
#defineuint task_uint
#defineuchar task_uchar
#defineushort task_ushort
#defineuvlong task_uvlong
#definevlong task_vlong
typedefunsigned longulong;
typedefunsigned intuint;
typedefunsigned charuchar;
typedefunsigned shortushort;
typedefunsigned long longuvlong;
typedeflong longvlong;
#defineprint task_print
#definefprint task_fprint
#definesnprint task_snprint
#defineseprint task_seprint
#definevprint task_vprint
#definevfprint task_vfprint
#definevsnprint task_vsnprint
#definevseprint task_vseprint
#definestrecpy task_strecpy
intprint(char*, ...);
intfprint(int, char*, ...);
char*snprint(char*, uint, char*, ...);
char*seprint(char*, char*, char*, ...);
intvprint(char*, va_list);
intvfprint(int, char*, va_list);
char*vsnprint(char*, uint, char*, va_list);
char*vseprint(char*, char*, char*, va_list);
char*strecpy(char*, char*, char*);
#if defined(__FreeBSD__) &&__FreeBSD__<5
externintgetmcontext(mcontext_t*);
externvoidsetmcontext(constmcontext_t*);
#definesetcontext(u) setmcontext(&(u)->uc_mcontext)
#definegetcontext(u) getmcontext(&(u)->uc_mcontext)
externintswapcontext(ucontext_t*, constucontext_t*);
externvoidmakecontext(ucontext_t*, void(*)(), int, ...);
#endif
#if defined(__APPLE__)
# definemcontext libthread_mcontext
# definemcontext_t libthread_mcontext_t
# defineucontext libthread_ucontext
# defineucontext_t libthread_ucontext_t
# if defined(__i386__)
# include"386-ucontext.h"
# elif defined(__x86_64__)
# include"amd64-ucontext.h"
# else
# include"power-ucontext.h"
# endif
#endif
#if defined(__OpenBSD__)
# definemcontext libthread_mcontext
# definemcontext_t libthread_mcontext_t
# defineucontext libthread_ucontext
# defineucontext_t libthread_ucontext_t
# if defined __i386__
# include"386-ucontext.h"
# else
# include"power-ucontext.h"
# endif
externpid_trfork_thread(int, void*, int(*)(void*), void*);
#endif
#if0&& defined(__sun__)
# definemcontext libthread_mcontext
# definemcontext_t libthread_mcontext_t
# defineucontext libthread_ucontext
# defineucontext_t libthread_ucontext_t
# include"sparc-ucontext.h"
#endif
#if defined(__arm__)
intgetmcontext(mcontext_t*);
voidsetmcontext(constmcontext_t*);
#definesetcontext(u) setmcontext(&(u)->uc_mcontext)
#definegetcontext(u) getmcontext(&(u)->uc_mcontext)
#endif
#if defined(__mips__)
#include"mips-ucontext.h"
intgetmcontext(mcontext_t*);
voidsetmcontext(constmcontext_t*);
#definesetcontext(u) setmcontext(&(u)->uc_mcontext)
#definegetcontext(u) getmcontext(&(u)->uc_mcontext)
#endif
typedefstructContextContext;
enum
{
STACK=8192
};
structContext
{
ucontext_tuc;
};
structTask
{
charname[256]; // offset known to acid
charstate[256];
Task*next;
Task*prev;
Task*allnext;
Task*allprev;
Contextcontext;
uvlongalarmtime;
uintid;
uchar*stk;
uintstksize;
intexiting;
intalltaskslot;
intsystem;
intready;
void (*startfn)(void*);
void*startarg;
void*udata;
};
voidtaskready(Task*);
voidtaskswitch(void);
voidaddtask(Tasklist*, Task*);
voiddeltask(Tasklist*, Task*);
externTask*taskrunning;
externinttaskcount;