-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPrivateStack.h
38 lines (30 loc) · 1.15 KB
/
PrivateStack.h
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
//
#ifndef PRIVATE_STACK_H
#define PRIVATE_STACK_H
#define MAX_STACK_NUM 4096
typedef void (*PrivateStart)(void);
// set start address of a private stack
void SetStack(int stackId, void *stack, size_t len);
// run `start` on an empty private stack until `StackSwitch` is called
void StackStart(int stackId, PrivateStart start);
// switch to a non-empty stack, e.g. running `start` and getting interrupted
// because `StackSwitch` is called
// return that calling
// so save current stack state, then resume another stack
// -1 means main (runtime) stack
void StackSwitch(int stackId);
// to setup a NF at stack#0:
// (runtime) SetStack(0, 0x4242), StackStart(0, start)
// (nf) virtual IO -> StackSwitch(-1)
// to process a packet along NFs at stack#0, #1 and #2
// (runtime) StackSwitch(0)
// (nf@stack#0) StackSwitch(1)
// (nf@stack#1) StackSwitch(2)
// (nf@stack#2) StackSwitch(-1)
// when we are jumping between pthreads, the TLS that record
// current stack ID will be lost
// call this to save/recover it, so the following StackSwitch calling
// will work even with stacks of different threads
void CrossThreadSaveStack();
void CrossThreadRestoreStack();
#endif