linux中获取SIGSEGV的上下文

context in linux getting SIGSEGV

本文关键字:上下文 SIGSEGV 获取 linux      更新时间:2023-10-16

我对用户定义线程的上下文内容很陌生。我写了一个关于上下文的简单程序。。。但它给了我分段错误。。。

#include<iostream>
#include<ucontext.h>
#include<stdlib.h>
using namespace std;
void fun1()
{
cout<<"from 1";
}
void fun2()
{
cout<<"from 2";
}
int main()
{
ucontext_t a,b;
cout<<"y";
getcontext(&b);
b.uc_link=0;
b.uc_stack.ss_sp=malloc(32767);
b.uc_stack.ss_size=32767;
b.uc_stack.ss_flags=0;
makecontext(&b, fun1, 0);   
getcontext(&a);
a.uc_link=&b;
a.uc_stack.ss_sp=malloc(32767);
a.uc_stack.ss_flags=0;
makecontext(&a, fun2, 0);
setcontext(&a);
return 0;
}
`
I want to know how to allocate memory using 

新的而不是malloc??有什么想法吗??

您忘记了:

a.uc_stack.ss_size=32767;