vfs: check userland buffers before reading them.
[haiku.git] / src / system / libroot / posix / signal / signal.cpp
blobe99c51c9b57c690a98eaa109360c8440f1197c63
1 /*
2 * Copyright 2002-2011, Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT license.
5 * Author:
6 * Daniel Reinhold, danielre@users.sf.net
7 * Ingo Weinhold, ingo_weinhold@gmx.de
8 */
11 #include <signal.h>
13 #include <errno.h>
14 #include <stdio.h>
16 #include <symbol_versioning.h>
18 #include <errno_private.h>
19 #include <signal_private.h>
22 static __sighandler_t
23 signal_common(int signal, __sighandler_t signalHandler, int flags)
25 struct sigaction newAction, oldAction;
27 // setup the replacement sigaction
28 newAction.sa_handler = signalHandler;
29 newAction.sa_mask = 0;
30 newAction.sa_flags = flags;
32 if (__sigaction(signal, &newAction, &oldAction) != 0)
33 return SIG_ERR;
35 // success, return the original handler
36 return oldAction.sa_handler;
40 __sighandler_t
41 __signal_beos(int signal, __sighandler_t signalHandler)
43 // check signal range
44 if (signal < 0 || signal > MAX_SIGNAL_NUMBER_BEOS) {
45 __set_errno(EINVAL);
46 return SIG_ERR;
49 // set the signal handler
50 __sighandler_t result = signal_common(signal, signalHandler,
51 SA_BEOS_COMPATIBLE_HANDLER);
52 if (result == SIG_ERR)
53 return SIG_ERR;
55 // If the signal is SIGSEGV, set the same signal handler for SIGBUS. Those
56 // constants had the same value under BeOS.
57 if (signal == SIGSEGV)
58 signal_common(SIGBUS, signalHandler, SA_BEOS_COMPATIBLE_HANDLER);
60 return result;
64 __sighandler_t
65 __signal(int signal, __sighandler_t signalHandler)
67 return signal_common(signal, signalHandler, 0);
71 DEFINE_LIBROOT_KERNEL_SYMBOL_VERSION("__signal_beos", "signal@", "BASE");
73 DEFINE_LIBROOT_KERNEL_SYMBOL_VERSION("__signal", "signal@@", "1_ALPHA4");