3

マニュアル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 *マニュアルページに a と記載されているのに、なぜ ucontextが a なの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.
4

1 に答える 1

2

POSIX では、実際にはこれが である必要がありvoid *、 の 3 番目の引数sigactionは次のとおりです。

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

さらに、 avoid *は他の種類のデータ ポインターとの間で自由にキャストできるため、将来さまざまな型をシームレスに追加する必要がある場合に一般的なケースを使用しない理由はほとんどありません。

于 2018-08-02T00:58:55.947 に答える