signal-common.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*
  2. * Emulation of Linux signals
  3. *
  4. * Copyright (c) 2003 Fabrice Bellard
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef SIGNAL_COMMON_H
  20. #define SIGNAL_COMMON_H
  21. #include "special-errno.h"
  22. /* Fallback addresses into sigtramp page. */
  23. extern abi_ulong default_sigreturn;
  24. extern abi_ulong default_rt_sigreturn;
  25. void setup_sigtramp(abi_ulong tramp_page);
  26. int on_sig_stack(unsigned long sp);
  27. int sas_ss_flags(unsigned long sp);
  28. abi_ulong target_sigsp(abi_ulong sp, struct target_sigaction *ka);
  29. void target_save_altstack(target_stack_t *uss, CPUArchState *env);
  30. abi_long target_restore_altstack(target_stack_t *uss, CPUArchState *env);
  31. static inline void target_sigemptyset(target_sigset_t *set)
  32. {
  33. memset(set, 0, sizeof(*set));
  34. }
  35. void host_to_target_sigset_internal(target_sigset_t *d,
  36. const sigset_t *s);
  37. void target_to_host_sigset_internal(sigset_t *d,
  38. const target_sigset_t *s);
  39. void tswap_siginfo(target_siginfo_t *tinfo,
  40. const target_siginfo_t *info);
  41. void set_sigmask(const sigset_t *set);
  42. void force_sig(int sig);
  43. void force_sigsegv(int oldsig);
  44. void force_sig_fault(int sig, int code, abi_ulong addr);
  45. #if defined(TARGET_ARCH_HAS_SETUP_FRAME)
  46. void setup_frame(int sig, struct target_sigaction *ka,
  47. target_sigset_t *set, CPUArchState *env);
  48. #endif
  49. void setup_rt_frame(int sig, struct target_sigaction *ka,
  50. target_siginfo_t *info,
  51. target_sigset_t *set, CPUArchState *env);
  52. void process_pending_signals(CPUArchState *cpu_env);
  53. void signal_init(void);
  54. void queue_signal(CPUArchState *env, int sig, int si_type,
  55. target_siginfo_t *info);
  56. void host_to_target_siginfo(target_siginfo_t *tinfo, const siginfo_t *info);
  57. void target_to_host_siginfo(siginfo_t *info, const target_siginfo_t *tinfo);
  58. int target_to_host_signal(int sig);
  59. int host_to_target_signal(int sig);
  60. long do_sigreturn(CPUArchState *env);
  61. long do_rt_sigreturn(CPUArchState *env);
  62. abi_long do_sigaltstack(abi_ulong uss_addr, abi_ulong uoss_addr,
  63. CPUArchState *env);
  64. int do_sigprocmask(int how, const sigset_t *set, sigset_t *oldset);
  65. abi_long do_swapcontext(CPUArchState *env, abi_ulong uold_ctx,
  66. abi_ulong unew_ctx, abi_long ctx_size);
  67. /**
  68. * block_signals: block all signals while handling this guest syscall
  69. *
  70. * Block all signals, and arrange that the signal mask is returned to
  71. * its correct value for the guest before we resume execution of guest code.
  72. * If this function returns non-zero, then the caller should immediately
  73. * return -QEMU_ERESTARTSYS to the main loop, which will take the pending
  74. * signal and restart execution of the syscall.
  75. * If block_signals() returns zero, then the caller can continue with
  76. * emulation of the system call knowing that no signals can be taken
  77. * (and therefore that no race conditions will result).
  78. * This should only be called once, because if it is called a second time
  79. * it will always return non-zero. (Think of it like a mutex that can't
  80. * be recursively locked.)
  81. * Signals will be unblocked again by process_pending_signals().
  82. *
  83. * Return value: non-zero if there was a pending signal, zero if not.
  84. */
  85. int block_signals(void); /* Returns non zero if signal pending */
  86. /**
  87. * process_sigsuspend_mask: read and apply syscall-local signal mask
  88. *
  89. * Read the guest signal mask from @sigset, length @sigsize.
  90. * Convert that to a host signal mask and save it to sigpending_mask.
  91. *
  92. * Return value: negative target errno, or zero;
  93. * store &sigpending_mask into *pset on success.
  94. */
  95. int process_sigsuspend_mask(sigset_t **pset, target_ulong sigset,
  96. target_ulong sigsize);
  97. /**
  98. * finish_sigsuspend_mask: finish a sigsuspend-like syscall
  99. *
  100. * Set in_sigsuspend if we need to use the modified sigset
  101. * during process_pending_signals.
  102. */
  103. static inline void finish_sigsuspend_mask(int ret)
  104. {
  105. if (ret != -QEMU_ERESTARTSYS) {
  106. TaskState *ts = (TaskState *)thread_cpu->opaque;
  107. ts->in_sigsuspend = 1;
  108. }
  109. }
  110. #if defined(SIGSTKFLT) && defined(TARGET_SIGSTKFLT)
  111. #define MAKE_SIG_ENTRY_SIGSTKFLT MAKE_SIG_ENTRY(SIGSTKFLT)
  112. #else
  113. #define MAKE_SIG_ENTRY_SIGSTKFLT
  114. #endif
  115. #if defined(SIGIOT) && defined(TARGET_SIGIOT)
  116. #define MAKE_SIG_ENTRY_SIGIOT MAKE_SIG_ENTRY(SIGIOT)
  117. #else
  118. #define MAKE_SIG_ENTRY_SIGIOT
  119. #endif
  120. #define MAKE_SIGNAL_LIST \
  121. MAKE_SIG_ENTRY(SIGHUP) \
  122. MAKE_SIG_ENTRY(SIGINT) \
  123. MAKE_SIG_ENTRY(SIGQUIT) \
  124. MAKE_SIG_ENTRY(SIGILL) \
  125. MAKE_SIG_ENTRY(SIGTRAP) \
  126. MAKE_SIG_ENTRY(SIGABRT) \
  127. MAKE_SIG_ENTRY(SIGBUS) \
  128. MAKE_SIG_ENTRY(SIGFPE) \
  129. MAKE_SIG_ENTRY(SIGKILL) \
  130. MAKE_SIG_ENTRY(SIGUSR1) \
  131. MAKE_SIG_ENTRY(SIGSEGV) \
  132. MAKE_SIG_ENTRY(SIGUSR2) \
  133. MAKE_SIG_ENTRY(SIGPIPE) \
  134. MAKE_SIG_ENTRY(SIGALRM) \
  135. MAKE_SIG_ENTRY(SIGTERM) \
  136. MAKE_SIG_ENTRY(SIGCHLD) \
  137. MAKE_SIG_ENTRY(SIGCONT) \
  138. MAKE_SIG_ENTRY(SIGSTOP) \
  139. MAKE_SIG_ENTRY(SIGTSTP) \
  140. MAKE_SIG_ENTRY(SIGTTIN) \
  141. MAKE_SIG_ENTRY(SIGTTOU) \
  142. MAKE_SIG_ENTRY(SIGURG) \
  143. MAKE_SIG_ENTRY(SIGXCPU) \
  144. MAKE_SIG_ENTRY(SIGXFSZ) \
  145. MAKE_SIG_ENTRY(SIGVTALRM) \
  146. MAKE_SIG_ENTRY(SIGPROF) \
  147. MAKE_SIG_ENTRY(SIGWINCH) \
  148. MAKE_SIG_ENTRY(SIGIO) \
  149. MAKE_SIG_ENTRY(SIGPWR) \
  150. MAKE_SIG_ENTRY(SIGSYS) \
  151. MAKE_SIG_ENTRY_SIGSTKFLT \
  152. MAKE_SIG_ENTRY_SIGIOT
  153. #endif