179b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney/*
279b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney * Derived from gdk/platforms/android-14/arch-arm/usr/include/signal.h
379b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney *
479b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney * Copyright (C) 2008 The Android Open Source Project
579b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney * All rights reserved.
679b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney *
779b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney * Redistribution and use in source and binary forms, with or without
879b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney * modification, are permitted provided that the following conditions
979b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney * are met:
1079b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney *  * Redistributions of source code must retain the above copyright
1179b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney *    notice, this list of conditions and the following disclaimer.
1279b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney *  * Redistributions in binary form must reproduce the above copyright
1379b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney *    notice, this list of conditions and the following disclaimer in
1479b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney *    the documentation and/or other materials provided with the
1579b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney *    distribution.
1679b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney *
1779b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1879b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1979b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
2079b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
2179b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
2279b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
2379b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
2479b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
2579b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
2679b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
2779b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2879b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney * SUCH DAMAGE.
2979b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney */
3079b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney#ifndef _SIGNAL_PORTABLE_H_
3179b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney#define _SIGNAL_PORTABLE_H_
3279b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney
3379b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney#include <portability.h>
3479b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney#include <sys/cdefs.h>
3579b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney#include <limits.h>             /* For LONG_BIT */
3679b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney#include <string.h>             /* For memset() */
376732a917fdb65b36bf0cbfc68529cf9b0450344bPete Delaney#include <signal.h>
386732a917fdb65b36bf0cbfc68529cf9b0450344bPete Delaney#include <time.h>
3979b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney#include <sys/types.h>
4079b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney#include <asm/signal_portable.h>
4179b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney#include <asm/sigcontext_portable.h>
4279b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney
4379b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney#define __ARCH_SI_UID_T __kernel_uid32_t
4479b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney#include <asm/siginfo_portable.h>
4579b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney#undef __ARCH_SI_UID_T
4679b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney
4779b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney__BEGIN_DECLS
4879b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney
4979b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaneytypedef int sig_atomic_t;
5079b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney
5179b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney#if 0
5279b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney/* _NSIG is used by the SIGRTMAX definition under <asm/signal.h>, however
5379b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney * its definition is part of a #if __KERNEL__ .. #endif block in the original
5479b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney * kernel headers and is thus not part of our cleaned-up versions.
5579b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney *
5679b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney * Looking at the current kernel sources, it is defined as 64 for all
5779b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney * architectures except for the 'mips' one which set it to 128.
5879b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney */
5979b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney#ifndef _NSIG_PORTABLE
6079b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney#  define _NSIG_PORTABLE  64
6179b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney#endif
6279b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney#endif
6379b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney
6479b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaneyextern const char * const sys_siglist[];
6579b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaneyextern const char * const sys_signame[];
6679b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney
676433ec22b1e20af20b31671b2fd4d5d235a7de52Andrew Hsiehstatic __inline__ int WRAP(sigismember)(sigset_portable_t *set, int signum)
6879b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney{
6979b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney    unsigned long *local_set = (unsigned long *)set;
7079b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney    signum--;
7179b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney    return (int)((local_set[signum/LONG_BIT] >> (signum%LONG_BIT)) & 1);
7279b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney}
7379b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney
7479b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney
756433ec22b1e20af20b31671b2fd4d5d235a7de52Andrew Hsiehstatic __inline__ int WRAP(sigaddset)(sigset_portable_t *set, int signum)
7679b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney{
7779b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney    unsigned long *local_set = (unsigned long *)set;
7879b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney    signum--;
7979b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney    local_set[signum/LONG_BIT] |= 1UL << (signum%LONG_BIT);
8079b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney    return 0;
8179b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney}
8279b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney
8379b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney
846433ec22b1e20af20b31671b2fd4d5d235a7de52Andrew Hsiehstatic __inline__ int WRAP(sigdelset)(sigset_portable_t *set, int signum)
8579b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney{
8679b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney    unsigned long *local_set = (unsigned long *)set;
8779b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney    signum--;
8879b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney    local_set[signum/LONG_BIT] &= ~(1UL << (signum%LONG_BIT));
8979b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney    return 0;
9079b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney}
9179b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney
9279b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney
936433ec22b1e20af20b31671b2fd4d5d235a7de52Andrew Hsiehstatic __inline__ int WRAP(sigemptyset)(sigset_portable_t *set)
9479b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney{
9579b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney    memset(set, 0, sizeof *set);
9679b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney    return 0;
9779b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney}
9879b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney
996433ec22b1e20af20b31671b2fd4d5d235a7de52Andrew Hsiehstatic __inline__ int WRAP(sigfillset)(sigset_portable_t *set)
10079b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney{
10179b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney    memset(set, ~0, sizeof *set);
10279b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney    return 0;
10379b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney}
10479b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney
10579b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney/* compatibility types */
10679b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaneytypedef void            (*sig_portable_t)(int);
10779b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaneytypedef sig_portable_t   sighandler_portable_t;
10879b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney
10979b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney/* Extended compatibility types, for processing a siginfo_t argument */
11079b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaneytypedef void            (*sig3_portable_t)(int, siginfo_portable_t *, void *);
11179b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaneytypedef sig3_portable_t   sig3handler_portable_t;
11279b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney
11379b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney/* differentiater between sysv and bsd behaviour 8*/
11479b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaneyextern __sighandler_t sysv_signal(int, __sighandler_portable_t);
11579b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaneyextern __sighandler_t bsd_signal(int, __sighandler_portable_t);
11679b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney
11779b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney#if 0
11879b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney/* the default is bsd */
1196433ec22b1e20af20b31671b2fd4d5d235a7de52Andrew Hsiehstatic __inline__ __sighandler_portable_t WRAP(signal)(int s, sighandler_portable_t f)
12079b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney{
12179b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney    return bsd_signal(s,f);
12279b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney}
12379b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney#endif
12479b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney
12579b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney/* the portable mapped syscall itself */
1266433ec22b1e20af20b31671b2fd4d5d235a7de52Andrew Hsiehextern __sighandler_portable_t WRAP(__signal)(int, __sighandler_portable_t);
12779b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney
1286433ec22b1e20af20b31671b2fd4d5d235a7de52Andrew Hsiehextern int WRAP(sigprocmask)(int, const sigset_portable_t *, sigset_portable_t *);
1292928edfab922ff749cc8b90610cc4c228a4a2948Pete Delaney
1306433ec22b1e20af20b31671b2fd4d5d235a7de52Andrew Hsiehextern int WRAP(sigaction)(int, const struct sigaction_portable *,
1312928edfab922ff749cc8b90610cc4c228a4a2948Pete Delaney                              struct sigaction_portable *);
13279b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney
1336433ec22b1e20af20b31671b2fd4d5d235a7de52Andrew Hsiehextern int WRAP(sigpending)(sigset_portable_t *);
1346433ec22b1e20af20b31671b2fd4d5d235a7de52Andrew Hsiehextern int WRAP(sigsuspend)(const sigset_portable_t *);
1356433ec22b1e20af20b31671b2fd4d5d235a7de52Andrew Hsiehextern int WRAP(sigwait)(const sigset_portable_t *set, int *sig);
1366433ec22b1e20af20b31671b2fd4d5d235a7de52Andrew Hsiehextern int WRAP(siginterrupt)(int  sig, int  flag);
13779b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney
1386433ec22b1e20af20b31671b2fd4d5d235a7de52Andrew Hsiehextern int WRAP(raise)(int);
1396433ec22b1e20af20b31671b2fd4d5d235a7de52Andrew Hsiehextern int WRAP(kill)(pid_t, int);
1406433ec22b1e20af20b31671b2fd4d5d235a7de52Andrew Hsiehextern int WRAP(killpg)(int pgrp, int sig);
1416433ec22b1e20af20b31671b2fd4d5d235a7de52Andrew Hsiehextern int WRAP(tkill)(int tid, int portable_signum);
1426433ec22b1e20af20b31671b2fd4d5d235a7de52Andrew Hsiehextern int WRAP(sigaltstack)(const portable_stack_t *ss, portable_stack_t *oss);
1436433ec22b1e20af20b31671b2fd4d5d235a7de52Andrew Hsiehextern int WRAP(timer_create)(clockid_t, struct sigevent *, timer_t *);
14479b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney
145c684613e19bce87e5ee3cdee5fb1e7ed5be14229Pete Delaney#if 0
1466433ec22b1e20af20b31671b2fd4d5d235a7de52Andrew Hsiehextern int WRAP(signalfd)(int fd, const sigset_portable_t *portable_sigmask, int flags);
147c684613e19bce87e5ee3cdee5fb1e7ed5be14229Pete Delaney#endif
148c684613e19bce87e5ee3cdee5fb1e7ed5be14229Pete Delaney
149c684613e19bce87e5ee3cdee5fb1e7ed5be14229Pete Delaneyextern __hidden int do_signalfd4_portable(int fd, const sigset_portable_t *portable_sigmask,
150c684613e19bce87e5ee3cdee5fb1e7ed5be14229Pete Delaney                                          int portable_sigsetsize, int flags);
1512928edfab922ff749cc8b90610cc4c228a4a2948Pete Delaney
152c684613e19bce87e5ee3cdee5fb1e7ed5be14229Pete Delaneyextern __hidden int read_signalfd_mapper(int fd, void *buf, size_t count);
15379b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaneyextern __hidden char *map_portable_signum_to_name(int portable_signum);
15479b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaneyextern __hidden char *map_mips_signum_to_name(int mips_signum);
1552928edfab922ff749cc8b90610cc4c228a4a2948Pete Delaneyextern __hidden int signum_pton(int portable_signum);
1562928edfab922ff749cc8b90610cc4c228a4a2948Pete Delaneyextern __hidden int signum_ntop(int mips_signum);
1572928edfab922ff749cc8b90610cc4c228a4a2948Pete Delaney
15879b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaneytypedef int (*sigmask_fn)(int, const sigset_t *, sigset_t *);
1596732a917fdb65b36bf0cbfc68529cf9b0450344bPete Delaneytypedef int (*rt_sigmask_fn)(int, const sigset_t *, sigset_t *, size_t);
1606732a917fdb65b36bf0cbfc68529cf9b0450344bPete Delaneytypedef int (*sigaction_fn)(int, const struct sigaction *, struct sigaction *);
1616732a917fdb65b36bf0cbfc68529cf9b0450344bPete Delaneytypedef int (*rt_sigaction_fn)(int, const struct sigaction *, struct sigaction *, size_t);
1622928edfab922ff749cc8b90610cc4c228a4a2948Pete Delaney
163c684613e19bce87e5ee3cdee5fb1e7ed5be14229Pete Delaney
1642928edfab922ff749cc8b90610cc4c228a4a2948Pete Delaneyextern __hidden int do_sigmask(int portable_how, const sigset_portable_t *portable_sigset,
1656732a917fdb65b36bf0cbfc68529cf9b0450344bPete Delaney                               sigset_portable_t *portable_oldset, sigmask_fn fn,
1666732a917fdb65b36bf0cbfc68529cf9b0450344bPete Delaney                               rt_sigmask_fn rt_fn);
1676732a917fdb65b36bf0cbfc68529cf9b0450344bPete Delaney
1686732a917fdb65b36bf0cbfc68529cf9b0450344bPete Delaney
1696732a917fdb65b36bf0cbfc68529cf9b0450344bPete Delaney/* These functions are called from syscall.c and experimental Bionic linker. */
1706433ec22b1e20af20b31671b2fd4d5d235a7de52Andrew Hsiehextern int WRAP(__rt_sigaction)(int portable_signum,
1716433ec22b1e20af20b31671b2fd4d5d235a7de52Andrew Hsieh                                const struct sigaction_portable *act,
1726433ec22b1e20af20b31671b2fd4d5d235a7de52Andrew Hsieh                                struct sigaction_portable *oldact,
1736433ec22b1e20af20b31671b2fd4d5d235a7de52Andrew Hsieh                                size_t sigsetsize);
1746732a917fdb65b36bf0cbfc68529cf9b0450344bPete Delaney
1756433ec22b1e20af20b31671b2fd4d5d235a7de52Andrew Hsiehextern int WRAP(__rt_sigprocmask)(int portable_how,
1766433ec22b1e20af20b31671b2fd4d5d235a7de52Andrew Hsieh                                  const sigset_portable_t *portable_sigset,
1776433ec22b1e20af20b31671b2fd4d5d235a7de52Andrew Hsieh                                  sigset_portable_t *portable_oldset,
1786433ec22b1e20af20b31671b2fd4d5d235a7de52Andrew Hsieh                                  size_t sigsetsize);
1796732a917fdb65b36bf0cbfc68529cf9b0450344bPete Delaney
1806433ec22b1e20af20b31671b2fd4d5d235a7de52Andrew Hsiehextern int WRAP(__rt_sigtimedwait)(const sigset_portable_t *portable_sigset,
1816433ec22b1e20af20b31671b2fd4d5d235a7de52Andrew Hsieh                                   siginfo_portable_t *portable_siginfo,
1826433ec22b1e20af20b31671b2fd4d5d235a7de52Andrew Hsieh                                   const struct timespec *timeout,
1836433ec22b1e20af20b31671b2fd4d5d235a7de52Andrew Hsieh                                   size_t portable_sigsetsize);
1846732a917fdb65b36bf0cbfc68529cf9b0450344bPete Delaney
1856732a917fdb65b36bf0cbfc68529cf9b0450344bPete Delaney
1866732a917fdb65b36bf0cbfc68529cf9b0450344bPete Delaney/* These functions are only called from syscall.c; not experimental Bionic linker. */
1876433ec22b1e20af20b31671b2fd4d5d235a7de52Andrew Hsiehextern __hidden int WRAP(rt_sigqueueinfo)(pid_t pid, int sig, siginfo_portable_t *uinfo);
1886732a917fdb65b36bf0cbfc68529cf9b0450344bPete Delaney
1896433ec22b1e20af20b31671b2fd4d5d235a7de52Andrew Hsiehextern __hidden int WRAP(rt_tgsigqueueinfo)(pid_t tgid, pid_t pid, int sig,
1906732a917fdb65b36bf0cbfc68529cf9b0450344bPete Delaney                                               siginfo_portable_t *uinfo);
19179b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney
192c684613e19bce87e5ee3cdee5fb1e7ed5be14229Pete Delaney
193c684613e19bce87e5ee3cdee5fb1e7ed5be14229Pete Delaney/* Called by clone when memory and signal handlers aren't compatable. */
194c684613e19bce87e5ee3cdee5fb1e7ed5be14229Pete Delaneyextern __hidden void signal_disable_mapping(void);
195c684613e19bce87e5ee3cdee5fb1e7ed5be14229Pete Delaney
19679b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney__END_DECLS
19779b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney
19879b607b4329fc8091c8ab85bb0041aa613432a12Pete Delaney#endif /* _SIGNAL_PORTABLE_H_ */
199