Can we reset sigsetjmp to return “0” again (Reset sigsetjmp)?

我是研究僧i 提交于 2019-12-03 22:22:39

You have misunderstood how [sig]setjmp works. If you uncomment the code that you think won't work, compile it, and run it, you will see that it does in fact work.

setjmp cannot be made to return zero by calling longjmp. If you call setjmp itself a second time, even with the same jmp_buf (as you do here), it will return zero a second time.

You have a bug, by the way: you didn't set up your sigaction parameter structure correctly. You should have done this:

struct sigaction sa;

sa.sa_handler = SIGSEGV_handler;
sigemptyset(&sa.sa_mask);
sa.sa_flags = SA_RESTART;
sigaction(SIGSEGV, &sa, 0);

The use of mmap is a little infelicitous, but not actually buggy. You don't need /dev/zero on most current platforms, you can just use MAP_ANON (some platforms spell it MAP_ANONYMOUS) and a -1 fd argument. And you should be using getpagesize and then asking for a whole number of pages.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!