forked from alibaba/coobjc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoroutine_context.h
132 lines (107 loc) · 3.23 KB
/
coroutine_context.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
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
//
// coroutine_context.h
// coobjc
//
// Copyright © 2018 Alibaba Group Holding Limited All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef coroutine_context_h
#define coroutine_context_h
#include <stdio.h>
#import <Foundation/Foundation.h>
#if defined(__arm64__) || defined(__aarch64__)
typedef struct coroutine_ucontext {
uint64_t data[100];
} coroutine_ucontext_t;
struct coroutine_ucontext_re {
struct GPRs {
uint64_t __x[29]; // x0-x28
uint64_t __fp; // Frame pointer x29
uint64_t __lr; // Link register x30
uint64_t __sp; // Stack pointer x31
uint64_t __pc; // Program counter
uint64_t padding; // 16-byte align, for cpsr
} GR;
double VR[32];
};
#elif defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7S__)
typedef struct coroutine_ucontext {
uint32_t data[16];
} coroutine_ucontext_t;
struct coroutine_ucontext_re {
struct GPRs {
uint32_t __r[13]; // r0-r12
uint32_t __sp; // Stack pointer r13
uint32_t __lr; // Link register r14
uint32_t __pc; // Program counter r15
} GR;
};
#elif defined(__i386__)
typedef struct coroutine_ucontext {
uint32_t data[16];
} coroutine_ucontext_t;
struct coroutine_ucontext_re {
struct GPRs {
unsigned int __eax;
unsigned int __ebx;
unsigned int __ecx;
unsigned int __edx;
unsigned int __edi;
unsigned int __esi;
unsigned int __ebp;
unsigned int __esp;
unsigned int __ss;
unsigned int __eflags;
unsigned int __eip;
unsigned int __cs;
unsigned int __ds;
unsigned int __es;
unsigned int __fs;
unsigned int __gs;
} GR;
};
#elif defined(__x86_64__)
typedef struct coroutine_ucontext {
uint64_t data[21];
} coroutine_ucontext_t;
struct coroutine_ucontext_re {
struct GPRs {
uint64_t __rax;
uint64_t __rbx;
uint64_t __rcx;
uint64_t __rdx;
uint64_t __rdi;
uint64_t __rsi;
uint64_t __rbp;
uint64_t __rsp;
uint64_t __r8;
uint64_t __r9;
uint64_t __r10;
uint64_t __r11;
uint64_t __r12;
uint64_t __r13;
uint64_t __r14;
uint64_t __r15;
uint64_t __rip;
uint64_t __rflags;
uint64_t __cs;
uint64_t __fs;
uint64_t __gs;
} GR;
};
#endif
extern int coroutine_getcontext (coroutine_ucontext_t *__ucp);
extern int coroutine_setcontext (coroutine_ucontext_t *__ucp);
extern int coroutine_begin (coroutine_ucontext_t *__ucp);
extern void coroutine_makecontext (coroutine_ucontext_t *__ucp, IMP func, void *arg, void *stackTop);
#endif /* coroutine_context_h */