source: trunk/kernel/kern/signal.c @ 220

Last change on this file since 220 was 23, checked in by alain, 7 years ago

Introduce syscalls.

File size: 3.0 KB
Line 
1/*
2 * signal.c - signal-management related operations implementation
3 *
4 * Author  Alain Greiner    (2016,2017)
5 *
6 * Copyright (c) UPMC Sorbonne Universites
7 *
8 * This file is part of ALMOS-MKH.
9 *
10 * ALMOS-MKH is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; version 2.0 of the License.
13 *
14 * ALMOS-MKH is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with ALMOS-MKH; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24#include <hal_types.h>
25#include <hal_atomic.h>
26#include <printk.h>
27#include <thread.h>
28#include <spinlock.h>
29#include <signal.h>
30
31//////////////////////////////////////
32void signal_rise( process_t * process, 
33                  uint32_t    sig_id )
34{
35    // get the lock protecting the set of local threads
36        spinlock_lock( &process->th_lock );
37
38    // loop on local threads
39        thread_t * thread;
40        uint32_t   i;
41        for( i = 0 ; i < process->th_nr ; i++ )
42        {
43                thread = process->th_tbl[i];
44                hal_atomic_or( &thread->signals , (1 << sig_id) );
45
46        signal_dmsg("\n[INFO] %s : thread %x in process %x received signal %d\n",
47                    __FUNCTION__, thread->trdid , process->pid , sig_id );
48        }
49
50    // release the lock
51        spinlock_unlock( &process->th_lock );
52
53}  // end signal_rise()
54
55/*
56
57SIGNAL_HANDLER(kill_sigaction)
58{
59        thread_s * this = CURRENT_THREAD;
60
61        printk("\n[INFO] %s : threadReceived signal %d, pid %d, tid %x, core %d  [ KILLED ]\n",
62               sig,
63               this->process->pid,
64               this,
65               cpu_get_id());
66
67        sys_thread_exit((void*)EINTR);
68}
69
70///////////////////////////////////////////////
71void signal_manager_init( process_t * process )
72{
73        memset(&process->sig_mgr, 0, sizeof(process->sig_mgr));
74        process->sig_mgr.sigactions[SIGCHLD] = SIG_IGNORE;
75        process->sig_mgr.sigactions[SIGURG]  = SIG_IGNORE;
76}
77
78
79/////////////////////////////////////
80void signal_notify( thread_t * this )
81{
82        uint32_t     sig_state;
83        uint32_t     sig;
84        sig_mgr_t  * sig_mgr;
85        uint32_t     irq_state;
86
87        sig_state = this->signals;
88        sig       = 0;
89 
90        while((sig_state != 0) && ((sig_state & 0x1) == 0) && (sig < SIG_NR))
91        {
92                sig ++;
93                sig_state >>= 1;
94        }
95 
96        if(sig)
97        {
98                cpu_disable_all_irq(&irq_state);
99
100                if(thread_isSignaled(this))
101                {
102                        cpu_restore_irq(irq_state);
103                        return;
104                }
105
106                thread_set_signaled(this);
107                cpu_restore_irq(irq_state);
108
109                spinlock_lock(&this->lock);
110                this->info.sig_state &= ~(1 << sig);
111                spinlock_unlock(&this->lock);
112
113                sig_mgr = &this->process->sig_mgr;
114
115                if(sig_mgr->sigactions[sig] == SIG_IGNORE)
116                        return;
117
118                if(sig_mgr->sigactions[sig] == SIG_DEFAULT)
119                        kill_sigaction(sig);
120
121                cpu_signal_notify(this, sig_mgr->sigactions[sig], sig);
122        }
123}
124*/
Note: See TracBrowser for help on using the repository browser.