From 188433192c492655e68a20dd23eba243022b7e2a Mon Sep 17 00:00:00 2001 From: Giacomo Tesio Date: Thu, 14 Sep 2017 00:25:19 +0200 Subject: [PATCH] jehanne: deep refactoring of signals (WIP) --- newlib/libc/sys/jehanne/Makefile.am | 2 +- newlib/libc/sys/jehanne/Makefile.in | 10 ++- newlib/libc/sys/jehanne/libposix_conf.c | 83 ------------------------- newlib/libc/sys/jehanne/signal.c | 35 +++++++++++ newlib/libc/sys/jehanne/syscalls.c | 3 - 5 files changed, 44 insertions(+), 89 deletions(-) create mode 100644 newlib/libc/sys/jehanne/signal.c diff --git a/newlib/libc/sys/jehanne/Makefile.am b/newlib/libc/sys/jehanne/Makefile.am index a473bfdc7..e4604edd6 100644 --- a/newlib/libc/sys/jehanne/Makefile.am +++ b/newlib/libc/sys/jehanne/Makefile.am @@ -12,7 +12,7 @@ extra_objs = endif lib_a_SOURCES = getenv_r.c getenv.c malloc.c mallocr.c free.c freer.c \ - calloc.c callocr.c realloc.c reallocr.c environ.c + calloc.c callocr.c realloc.c reallocr.c environ.c signal.c lib_a_LIBADD = $(extra_objs) EXTRA_lib_a_SOURCES = libposix_conf.c syscalls.c chown.c getrusage.c \ diff --git a/newlib/libc/sys/jehanne/Makefile.in b/newlib/libc/sys/jehanne/Makefile.in index 7be137692..08ee46c3f 100644 --- a/newlib/libc/sys/jehanne/Makefile.in +++ b/newlib/libc/sys/jehanne/Makefile.in @@ -59,7 +59,7 @@ am_lib_a_OBJECTS = lib_a-getenv_r.$(OBJEXT) lib_a-getenv.$(OBJEXT) \ lib_a-free.$(OBJEXT) lib_a-freer.$(OBJEXT) \ lib_a-calloc.$(OBJEXT) lib_a-callocr.$(OBJEXT) \ lib_a-realloc.$(OBJEXT) lib_a-reallocr.$(OBJEXT) \ - lib_a-environ.$(OBJEXT) + lib_a-environ.$(OBJEXT) lib_a-signal.$(OBJEXT) lib_a_OBJECTS = $(am_lib_a_OBJECTS) DEFAULT_INCLUDES = -I.@am__isrc@ depcomp = @@ -183,7 +183,7 @@ noinst_LIBRARIES = lib.a @MAY_SUPPLY_SYSCALLS_TRUE@ chmod.o sigsets.o lib_a_SOURCES = getenv_r.c getenv.c malloc.c mallocr.c free.c freer.c \ - calloc.c callocr.c realloc.c reallocr.c environ.c + calloc.c callocr.c realloc.c reallocr.c environ.c signal.c lib_a_LIBADD = $(extra_objs) EXTRA_lib_a_SOURCES = libposix_conf.c syscalls.c chown.c getrusage.c \ @@ -322,6 +322,12 @@ lib_a-environ.o: environ.c lib_a-environ.obj: environ.c $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-environ.obj `if test -f 'environ.c'; then $(CYGPATH_W) 'environ.c'; else $(CYGPATH_W) '$(srcdir)/environ.c'; fi` +lib_a-signal.o: signal.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-signal.o `test -f 'signal.c' || echo '$(srcdir)/'`signal.c + +lib_a-signal.obj: signal.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-signal.obj `if test -f 'signal.c'; then $(CYGPATH_W) 'signal.c'; else $(CYGPATH_W) '$(srcdir)/signal.c'; fi` + lib_a-libposix_conf.o: libposix_conf.c $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-libposix_conf.o `test -f 'libposix_conf.c' || echo '$(srcdir)/'`libposix_conf.c diff --git a/newlib/libc/sys/jehanne/libposix_conf.c b/newlib/libc/sys/jehanne/libposix_conf.c index 1b666b1f1..20dfea752 100644 --- a/newlib/libc/sys/jehanne/libposix_conf.c +++ b/newlib/libc/sys/jehanne/libposix_conf.c @@ -249,25 +249,6 @@ default_timezone_reader(void *tz, const Tm *time) return 0; } -static PosixSignalAction -signal_trampoline(int signal) -{ - switch(__sigtramp(signal)){ - case -1: // unknown signal or uninitialized signals - jehanne_sysfatal("newlib: error handling signal %d or unknown signal", signal); - case 0: // catched - return SignalCatched; - case 3: // ignored - return SignalIgnored; - case 1: // default - return SignalDefault; - case 2: // error - return SignalError; - default: - jehanne_sysfatal("newlib: unexpected PosixSignalAction from signal trampoline: %d", signal); - } -} - void initialize_newlib(void) { @@ -279,73 +260,9 @@ initialize_newlib(void) libposix_translate_seek_whence(SEEK_SET, SEEK_CUR, SEEK_END); libposix_translate_access_mode(F_OK, R_OK, W_OK, X_OK); libposix_translate_open(open_translator); - libposix_set_signal_trampoline(signal_trampoline); libposix_translate_error(default_error_translator, 0); libposix_set_wait_options(0, WNOHANG, 0); - /* signals */ - libposix_define_signal(PosixSIGABRT, SIGABRT); - libposix_define_signal(PosixSIGALRM, SIGALRM); - libposix_define_signal(PosixSIGBUS, SIGBUS); - libposix_define_signal(PosixSIGCHLD, SIGCHLD); - libposix_define_signal(PosixSIGCONT, SIGCONT); - libposix_define_signal(PosixSIGFPE, SIGFPE); - libposix_define_signal(PosixSIGHUP, SIGHUP); - libposix_define_signal(PosixSIGILL, SIGILL); - libposix_define_signal(PosixSIGINT, SIGINT); - libposix_define_signal(PosixSIGKILL, SIGKILL); - libposix_define_signal(PosixSIGPIPE, SIGPIPE); - libposix_define_signal(PosixSIGQUIT, SIGQUIT); - libposix_define_signal(PosixSIGSEGV, SIGSEGV); - libposix_define_signal(PosixSIGSTOP, SIGSTOP); - libposix_define_signal(PosixSIGTERM, SIGTERM); - libposix_define_signal(PosixSIGTSTP, SIGTSTP); - libposix_define_signal(PosixSIGTTIN, SIGTTIN); - libposix_define_signal(PosixSIGTTOU, SIGTTOU); - libposix_define_signal(PosixSIGUSR1, SIGUSR1); - libposix_define_signal(PosixSIGUSR2, SIGUSR2); - libposix_define_signal(PosixSIGPOLL, SIGPOLL); - libposix_define_signal(PosixSIGPROF, SIGPROF); - libposix_define_signal(PosixSIGSYS, SIGSYS); - libposix_define_signal(PosixSIGTRAP, SIGTRAP); - libposix_define_signal(PosixSIGURG, SIGURG); - libposix_define_signal(PosixSIGVTALRM, SIGVTALRM); - libposix_define_signal(PosixSIGXCPU, SIGXCPU); - libposix_define_signal(PosixSIGXFSZ, SIGXFSZ); -#ifdef SIGIOT - libposix_define_signal(PosixSIGIOT, SIGIOT); -#endif -#ifdef SIGEMT - libposix_define_signal(PosixSIGEMT, SIGEMT); -#endif -#ifdef SIGSTKFLT - libposix_define_signal(PosixSIGSTKFLT, SIGSTKFLT); -#endif -#ifdef SIGIO - libposix_define_signal(PosixSIGIO, SIGIO); -#endif -#ifdef SIGCLD - libposix_define_signal(PosixSIGCLD, SIGCLD); -#endif -#ifdef SIGPWR - libposix_define_signal(PosixSIGPWR, SIGPWR); -#endif -#ifdef SIGINFO - libposix_define_signal(PosixSIGINFO, SIGINFO); -#endif -#ifdef SIGLOST - libposix_define_signal(PosixSIGLOST, SIGLOST); -#endif -#ifdef SIGWINCH - libposix_define_signal(PosixSIGWINCH, SIGWINCH); -#endif -#ifdef SIGUNUSED - libposix_define_signal(PosixSIGUNUSED, SIGUNUSED); -#endif -#if defined(SIGRTMIN) && defined(SIGRTMAX) - libposix_define_realtime_signals(SIGRTMIN, SIGRTMAX); -#endif - /* error numbers */ libposix_define_errno(PosixE2BIG, E2BIG); libposix_define_errno(PosixEACCES, EACCES); diff --git a/newlib/libc/sys/jehanne/signal.c b/newlib/libc/sys/jehanne/signal.c new file mode 100644 index 000000000..04ef15764 --- /dev/null +++ b/newlib/libc/sys/jehanne/signal.c @@ -0,0 +1,35 @@ +/* + * This file is part of Jehanne. + * + * Copyright (C) 2017 Giacomo Tesio + * + * Jehanne is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 2 of the License. + * + * Jehanne is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Jehanne. If not, see . + */ +#include +#include +#include +#include + +PosixSigHandler +signal(int signo, PosixSigHandler handler) +{ + int *errnop = &_REENT->_errno; + return POSIX_signal(errnop, signo, handler); +} + +int +raise(int signo) +{ + int *errnop = &_REENT->_errno; + return POSIX_kill(errnop, getpid(), signo); +} diff --git a/newlib/libc/sys/jehanne/syscalls.c b/newlib/libc/sys/jehanne/syscalls.c index 58e31d133..7f8fff94a 100644 --- a/newlib/libc/sys/jehanne/syscalls.c +++ b/newlib/libc/sys/jehanne/syscalls.c @@ -43,9 +43,6 @@ newlib(int argc, char *argv[]) /* initialize the private reentrancy structure */ _impure_ptr = &private_reent; - /* initialize signal infrastructure */ - _init_signal_r(_REENT); - libposix_init(argc, argv, initialize_newlib); }