为什么Sigaction处理程序中的上下文是空指针?

时间:2018-08-02 00:11:29

标签: c pointers sigaction

sigaction(2)手册页中:

The siginfo_t argument to a SA_SIGINFO handler
   When the SA_SIGINFO flag is specified in act.sa_flags, the signal
   handler address is passed via the act.sa_sigaction field.  This han‐
   dler takes three arguments, as follows:

       void
       handler(int sig, siginfo_t *info, void *ucontext)
       {
           ...
       }

当手册页指出它是void *时,为什么ucontext是ucontext_t *

ucontext
          This is a pointer to a ucontext_t structure, cast to void *.
          The structure pointed to by this field contains signal context
          information that was saved on the user-space stack by the ker‐
          nel; for details, see sigreturn(2).  Further information about
          the ucontext_t structure can be found in getcontext(3).  Com‐
          monly, the handler function doesn't make any use of the third
          argument.

1 个答案:

答案 0 :(得分:1)

POSIX实际上要求它是void *sigaction的第三个参数是:

void(*) (int, siginfo_t *, void *)

此外,由于void *可以自由地与任何其他类型的数据指针进行强制转换,因此没有理由 not 在可能要使用的情况下使用一般情况将来无缝添加不同类型。