use macro for getcontext (setjmp)
This commit is contained in:
parent
b4d5d19438
commit
1e05fdf92c
8 changed files with 25 additions and 56 deletions
|
|
@ -1,8 +1,8 @@
|
||||||
|
#define setcontext(u) setmcontext(&(u)->uc_mcontext)
|
||||||
|
#define getcontext(u) getmcontext(&(u)->uc_mcontext)
|
||||||
typedef struct mcontext mcontext_t;
|
typedef struct mcontext mcontext_t;
|
||||||
typedef struct ucontext ucontext_t;
|
typedef struct ucontext ucontext_t;
|
||||||
|
|
||||||
extern int getcontext(ucontext_t*);
|
|
||||||
extern void setcontext(ucontext_t*);
|
|
||||||
extern int swapcontext(ucontext_t*, ucontext_t*);
|
extern int swapcontext(ucontext_t*, ucontext_t*);
|
||||||
extern void makecontext(ucontext_t*, void(*)(), int, ...);
|
extern void makecontext(ucontext_t*, void(*)(), int, ...);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,11 +5,10 @@ _tas:
|
||||||
xchgl %eax, 0(%ecx)
|
xchgl %eax, 0(%ecx)
|
||||||
ret
|
ret
|
||||||
|
|
||||||
.globl getcontext
|
.globl getmcontext
|
||||||
getcontext:
|
getmcontext:
|
||||||
movl 4(%esp), %eax
|
movl 4(%esp), %eax
|
||||||
addl $16, %eax /* point to mcontext */
|
|
||||||
|
|
||||||
movl %fs, 8(%eax)
|
movl %fs, 8(%eax)
|
||||||
movl %es, 12(%eax)
|
movl %es, 12(%eax)
|
||||||
movl %ds, 16(%eax)
|
movl %ds, 16(%eax)
|
||||||
|
|
@ -26,16 +25,15 @@ getcontext:
|
||||||
movl %ecx, 60(%eax)
|
movl %ecx, 60(%eax)
|
||||||
leal 4(%esp), %ecx /* %esp */
|
leal 4(%esp), %ecx /* %esp */
|
||||||
movl %ecx, 72(%eax)
|
movl %ecx, 72(%eax)
|
||||||
|
|
||||||
movl 44(%eax), %ecx /* restore %ecx */
|
movl 44(%eax), %ecx /* restore %ecx */
|
||||||
movl $0, %eax
|
movl $0, %eax
|
||||||
ret
|
ret
|
||||||
|
|
||||||
.globl setcontext
|
.globl setmcontext
|
||||||
setcontext:
|
setmcontext:
|
||||||
movl 4(%esp), %eax
|
movl 4(%esp), %eax
|
||||||
addl $16, %eax /* point to mcontext */
|
|
||||||
|
|
||||||
movl 8(%eax), %fs
|
movl 8(%eax), %fs
|
||||||
movl 12(%eax), %es
|
movl 12(%eax), %es
|
||||||
movl 16(%eax), %ds
|
movl 16(%eax), %ds
|
||||||
|
|
@ -45,11 +43,10 @@ setcontext:
|
||||||
movl 28(%eax), %ebp
|
movl 28(%eax), %ebp
|
||||||
movl 36(%eax), %ebx
|
movl 36(%eax), %ebx
|
||||||
movl 40(%eax), %edx
|
movl 40(%eax), %edx
|
||||||
movl 72(%eax), %esp
|
|
||||||
|
|
||||||
movl 60(%eax), %ecx /* push new %eip */
|
|
||||||
pushl %ecx
|
|
||||||
|
|
||||||
movl 44(%eax), %ecx
|
movl 44(%eax), %ecx
|
||||||
|
|
||||||
|
movl 72(%eax), %esp
|
||||||
|
pushl 60(%eax) /* new %eip */
|
||||||
movl 48(%eax), %eax
|
movl 48(%eax), %eax
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,9 +9,8 @@ _tas:
|
||||||
mov r0, r3
|
mov r0, r3
|
||||||
mov pc, lr
|
mov pc, lr
|
||||||
|
|
||||||
.globl getcontext
|
.globl getmcontext
|
||||||
getcontext:
|
getmcontext:
|
||||||
add r0, r0, #148 /* walk to mcontext */
|
|
||||||
str r1, [r0,#4]
|
str r1, [r0,#4]
|
||||||
str r2, [r0,#8]
|
str r2, [r0,#8]
|
||||||
str r3, [r0,#12]
|
str r3, [r0,#12]
|
||||||
|
|
@ -33,9 +32,8 @@ getcontext:
|
||||||
mov r0, #0
|
mov r0, #0
|
||||||
mov pc, lr
|
mov pc, lr
|
||||||
|
|
||||||
.globl setcontext
|
.globl setmcontext
|
||||||
setcontext:
|
setmcontext:
|
||||||
add r0, r0, #148 /* walk to mcontext */
|
|
||||||
ldr r1, [r0,#4]
|
ldr r1, [r0,#4]
|
||||||
ldr r2, [r0,#8]
|
ldr r2, [r0,#8]
|
||||||
ldr r3, [r0,#12]
|
ldr r3, [r0,#12]
|
||||||
|
|
|
||||||
|
|
@ -437,8 +437,8 @@ _threadpexit(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __arm__
|
#ifdef __arm__
|
||||||
extern int getmcontext(mcontext_t*);
|
#define setcontext(u) setmcontext(&(u)->uc_mcontext)
|
||||||
extern int setmcontext(const mcontext_t*);
|
#define getcontext(u) getmcontext(&(u)->uc_mcontext)
|
||||||
|
|
||||||
void
|
void
|
||||||
makecontext(ucontext_t *uc, void (*fn)(void), int argc, ...)
|
makecontext(ucontext_t *uc, void (*fn)(void), int argc, ...)
|
||||||
|
|
|
||||||
|
|
@ -13,21 +13,6 @@ makecontext(ucontext_t *ucp, void (*func)(void), int argc, ...)
|
||||||
ucp->uc_mcontext.mc_esp = (int)sp;
|
ucp->uc_mcontext.mc_esp = (int)sp;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern int getmcontext(mcontext_t*);
|
|
||||||
extern int setmcontext(mcontext_t*);
|
|
||||||
|
|
||||||
int
|
|
||||||
getcontext(ucontext_t *uc)
|
|
||||||
{
|
|
||||||
return getmcontext(&uc->uc_mcontext);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
setcontext(ucontext_t *uc)
|
|
||||||
{
|
|
||||||
setmcontext(&uc->uc_mcontext);
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
int
|
||||||
swapcontext(ucontext_t *oucp, ucontext_t *ucp)
|
swapcontext(ucontext_t *oucp, ucontext_t *ucp)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -15,19 +15,6 @@ makecontext(ucontext_t *ucp, void (*func)(void), int argc, ...)
|
||||||
va_end(arg);
|
va_end(arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
|
||||||
getcontext(ucontext_t *uc)
|
|
||||||
{
|
|
||||||
return _getmcontext(&uc->mc);
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
setcontext(ucontext_t *uc)
|
|
||||||
{
|
|
||||||
_setmcontext(&uc->mc);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
int
|
||||||
swapcontext(ucontext_t *oucp, ucontext_t *ucp)
|
swapcontext(ucontext_t *oucp, ucontext_t *ucp)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
#define setcontext(u) _setmcontext(&(u)->uc_mcontext)
|
||||||
|
#define getcontext(u) _getmcontext(&(u)->uc_mcontext)
|
||||||
typedef struct mcontext mcontext_t;
|
typedef struct mcontext mcontext_t;
|
||||||
typedef struct ucontext ucontext_t;
|
typedef struct ucontext ucontext_t;
|
||||||
struct mcontext
|
struct mcontext
|
||||||
|
|
@ -27,8 +29,6 @@ struct ucontext
|
||||||
};
|
};
|
||||||
|
|
||||||
void makecontext(ucontext_t*, void(*)(void), int, ...);
|
void makecontext(ucontext_t*, void(*)(void), int, ...);
|
||||||
int getcontext(ucontext_t*);
|
|
||||||
int setcontext(ucontext_t*);
|
|
||||||
int swapcontext(ucontext_t*, ucontext_t*);
|
int swapcontext(ucontext_t*, ucontext_t*);
|
||||||
int _getmcontext(mcontext_t*);
|
int _getmcontext(mcontext_t*);
|
||||||
void _setmcontext(mcontext_t*);
|
void _setmcontext(mcontext_t*);
|
||||||
|
|
|
||||||
|
|
@ -13,8 +13,10 @@
|
||||||
#include "thread.h"
|
#include "thread.h"
|
||||||
|
|
||||||
#if defined(__FreeBSD__) && __FreeBSD__ < 5
|
#if defined(__FreeBSD__) && __FreeBSD__ < 5
|
||||||
extern int getcontext(ucontext_t*);
|
extern int getmcontext(mcontext_t*);
|
||||||
extern void setcontext(ucontext_t*);
|
extern void setmcontext(mcontext_t*);
|
||||||
|
#define setcontext(u) setmcontext(&(u)->uc_mcontext)
|
||||||
|
#define getcontext(u) getmcontext(&(u)->uc_mcontext)
|
||||||
extern int swapcontext(ucontext_t*, ucontext_t*);
|
extern int swapcontext(ucontext_t*, ucontext_t*);
|
||||||
extern void makecontext(ucontext_t*, void(*)(), int, ...);
|
extern void makecontext(ucontext_t*, void(*)(), int, ...);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue