source: trunk/kernel/syscalls/sys_signal.c @ 9

Last change on this file since 9 was 1, checked in by alain, 7 years ago

First import

File size: 2.3 KB
Line 
1/*
2 * sys_sem.c: interface to access signal service
3 *
4 * Copyright (c) 2008,2009,2010,2011,2012 Ghassan Almaless
5 * Copyright (c) 2011,2012,2013,2014,2015 UPMC Sorbonne Universites
6 *
7 * This file is part of ALMOS-kernel.
8 *
9 * ALMOS-kernel is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; version 2.0 of the License.
12 *
13 * ALMOS-kernel is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with ALMOS-kernel; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23#include <types.h>
24#include <errno.h>
25#include <thread.h>
26#include <task.h>
27#include <pid.h>
28#include <signal.h>
29
30
31int sys_signal(uint_t sig, sa_handler_t *handler)
32{ 
33        register struct thread_s *this;
34        int retval;
35
36        this = current_thread;
37
38        if((sig == 0) || (sig >= SIG_NR) || (sig == SIGKILL) || (sig == SIGSTOP))
39        {
40                this->info.errno = EINVAL;
41                return SIG_ERROR;
42        }
43
44        retval = (int) this->task->sig_mgr.sigactions[sig];
45        this->task->sig_mgr.sigactions[sig] = handler;
46
47        sig_dmsg(1, "%s: handler @%x has been registred for signal %d\n",
48               __FUNCTION__, 
49               handler, 
50               sig);
51
52        return retval;
53}
54
55
56int sys_sigreturn_setup(void *sigreturn_func)
57{
58        struct thread_s *this;
59
60        this = current_thread;
61        this->info.attr.sigreturn_func = sigreturn_func;
62        cpu_context_set_sigreturn(&this->pws, sigreturn_func);
63        return 0;
64}
65
66
67int sys_kill(pid_t pid, uint_t sig)
68{
69        cid_t   location;
70        error_t err;
71
72        if((sig == 0) || (sig >= SIG_NR))
73        {
74                err = EINVAL;
75        }
76        else
77        {
78                if ( PID_GET_CLUSTER(pid) == current_cid )
79                        location = current_cid;
80                else
81                        location = task_whereis(pid);
82
83                err = signal_rise(pid, location, sig);
84
85                /* No error, return 0 */
86                if (!err)
87                        return 0;
88        }
89
90        /* Error. Set errno and return */
91        current_thread->info.errno = err;
92        return -1;
93}
Note: See TracBrowser for help on using the repository browser.