linux下是否允许任何系统调用是从信号处理程序做? [英] Does linux allow any system call to be made from signal handlers?

查看:239
本文介绍了linux下是否允许任何系统调用是从信号处理程序做?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的理解是,在一般情况下,如果你调用从信号处理非异步信号安全功能的行为是不确定的,但我听说Linux允许您安全地调用任何系统调用。这是真的?此外,对于SIGSEGV处理程序的唯一便携式的行为是放弃或退出,但我明白的Linux实际上将继续执行,如果你回来,真的吗?

My understanding is that, in general, the behavior is undefined if you call a non-async signal safe function from a signal handler, but I've heard that linux allows you to call any system call safely. Is this true? Also, the only portable behavior for a SIGSEGV handler is to abort or exit, but I understand linux will actually resume execution if you return, true?

推荐答案

我相信,任何真正的系统调用可以从信号处理函数中调用。一个真正的系统调用在℃的号码; ASM / unistd.h中> (或< ASM / unistd_64.h> )。

I would believe that any real system call can be called from a signal handler. A true syscall has a number in <asm/unistd.h> (or <asm/unistd_64.h>).

<子>从手册页第2部分POSIX功能都直通了复用系统调用实现的,所以他们不是真正的系统调用在我的感觉

一个系统调用是从视图应用的点的原子操作;它几乎像一个单一的机器指令(从应用程序中)。请参见这个答案

A system call is an atomic operation from the point of view of the application; it is almost like a single machine instruction (from inside the application). See this answer.

如果你的问题是:可以在 SIGSEGV 处理程序更改直通则mprotect 故障地址映射或 MMAP 的话,我相信答案是的的(至少在X86-64&安培; X86-32架构)?作为<一个HREF =htt​​p://stackoverflow.com/a/2663​​575/841108>这里在您引用了一个问题说,但我没有尝试。我读过这样做是非常低效的( SIGSEGV 的处理是不是非常快,则mprotect MMAP 也有点慢)。特别是,模仿这种方式赫德/马赫外部寻呼机可能是低效的。

If your question is: can a SIGSEGV handler change the faulty address mapping thru mprotect or mmap ? then I believe the answer is yes (at least on x86-64 & x86-32 architectures), as said here in a question you quoted, but I did not try. I've read that doing that is quite inefficient (SIGSEGV handling is not very fast, and mprotect or mmap is also a bit slow). In particular, mimicking this way Hurd/Mach external pagers might be inefficient.

这篇关于linux下是否允许任何系统调用是从信号处理程序做?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆