MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / sys_sigaction

Function sys_sigaction

components/lwp/lwp_syscall.c:6439–6498  ·  view source on GitHub ↗

* @brief Changes the action taken by the system on receiving a signal. * * This system call allows a process to specify how signals should be handled. It allows you to set a * new action for a specific signal, retrieve the old action, and define the signal mask that should * be applied during the execution of the signal handler. * * @param[in] sig The signal number for which the acti

Source from the content-addressed store, hash-verified

6437 * @see sys_signal(), sys_sigprocmask()
6438 */
6439sysret_t sys_sigaction(int sig, const struct k_sigaction *act,
6440 struct k_sigaction *oact, size_t sigsetsize)
6441{
6442 int ret = -RT_EINVAL;
6443 struct rt_lwp *lwp;
6444 struct lwp_sigaction kact, *pkact = RT_NULL;
6445 struct lwp_sigaction koact, *pkoact = RT_NULL;
6446
6447 if (!sigsetsize)
6448 {
6449 SET_ERRNO(EINVAL);
6450 goto out;
6451 }
6452 if (sigsetsize > sizeof(lwp_sigset_t))
6453 {
6454 sigsetsize = sizeof(lwp_sigset_t);
6455 }
6456 if (!act && !oact)
6457 {
6458 SET_ERRNO(EINVAL);
6459 goto out;
6460 }
6461 if (oact)
6462 {
6463 if (!lwp_user_accessable((void *)oact, sizeof(*oact)))
6464 {
6465 SET_ERRNO(EFAULT);
6466 goto out;
6467 }
6468 pkoact = &koact;
6469 }
6470 if (act)
6471 {
6472 if (!lwp_user_accessable((void *)act, sizeof(*act)))
6473 {
6474 SET_ERRNO(EFAULT);
6475 goto out;
6476 }
6477 kact.sa_flags = act->flags;
6478 kact.__sa_handler._sa_handler = act->handler;
6479 lwp_memcpy(&kact.sa_mask, &act->mask, sigsetsize);
6480 kact.sa_restorer = act->restorer;
6481 pkact = &kact;
6482 }
6483
6484 lwp = lwp_self();
6485 RT_ASSERT(lwp);
6486 ret = lwp_signal_action(lwp, sig, pkact, pkoact);
6487#ifdef ARCH_MM_MMU
6488 if (ret == 0 && oact)
6489 {
6490 lwp_put_to_user(&oact->handler, &pkoact->__sa_handler._sa_handler, sizeof(void (*)(int)));
6491 lwp_put_to_user(&oact->mask, &pkoact->sa_mask, sigsetsize);
6492 lwp_put_to_user(&oact->flags, &pkoact->sa_flags, sizeof(int));
6493 lwp_put_to_user(&oact->restorer, &pkoact->sa_restorer, sizeof(void (*)(void)));
6494 }
6495#endif /* ARCH_MM_MMU */
6496out:

Callers

nothing calls this directly

Calls 5

lwp_user_accessableFunction · 0.85
lwp_memcpyFunction · 0.85
lwp_selfFunction · 0.85
lwp_signal_actionFunction · 0.85
lwp_put_to_userFunction · 0.85

Tested by

no test coverage detected