|
在setcontext(2)中有一个数据结构:
typedef struct ucontext
{
unsigned long int uc_flags;
struct ucontext *uc_link;
stack_t uc_stack;
mcontext_t uc_mcontext;
__sigset_t uc_sigmask;
struct _fpstate __fpregs_mem;
} ucontext_t;
其中uc_stack是什么stack啊?
我写一个程序测试它:
--------------------------------------------------------------------------------
int main(int argc, char **argv) {
// change stack size
ucontext_t ut;
int resource;
int shmid;
void *pttr;
shmid = shmget(300, 4096*1024, SHM_HUGETLB|IPC_CREAT|SHM_R|SHM_W);
pttr = shmat(shmid, 0, 0);
if(pttr == -1) {
perror("shmat");
return -1;
}
if(getcontext(&ut) == 0) {
printf("ut.uc_stack\n");
printf("\tss_sp = %x\n", ut.uc_stack.ss_sp);
printf("\tss_flags = %x\n", ut.uc_stack.ss_flags);
printf("\tss_size = %x\n", ut.uc_stack.ss_size);
printf("\nNow set new value to user stack......\n");
ut.uc_stack.ss_sp = pttr;
ut.uc_stack.ss_size = 1024;
setcontext(&ut);
} else {
perror("getcontext");
}
return 0;
}
-------------------------------------------------------------------------------------
一旦使用setcontext, 上述程序会陷入getcontext的死循环。
还有ut.uc_stack.ss_sp的值和size都是0.不懂啊! |
|