Почему контекст в обработчике 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)
       {
           ...
       }

Почему UContext является void * когда страница руководства утверждает, что это 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 ответ

Решение

POSIX на самом деле требует, чтобы это было void * третий аргумент sigaction является:

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

Кроме того, так как void * может быть свободно приведен к любому другому виду указателя данных, поэтому нет оснований не использовать общий случай в ситуации, когда вам может потребоваться плавное добавление различных типов в будущем.

Другие вопросы по тегам