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

Last change on this file since 93 was 23, checked in by alain, 8 years ago

Introduce syscalls.

File size: 3.0 KB
RevLine 
[1]1/*
2 * signal.c - signal-management related operations implementation
3 *
[5]4 * Author  Alain Greiner    (2016,2017)
[1]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>
[23]25#include <hal_atomic.h>
26#include <printk.h>
[1]27#include <thread.h>
[23]28#include <spinlock.h>
[1]29#include <signal.h>
30
[5]31//////////////////////////////////////
32void signal_rise( process_t * process, 
[23]33                  uint32_t    sig_id )
[1]34{
[23]35    // get the lock protecting the set of local threads
[1]36        spinlock_lock( &process->th_lock );
37
[23]38    // loop on local threads
39        thread_t * thread;
40        uint32_t   i;
[1]41        for( i = 0 ; i < process->th_nr ; i++ )
42        {
43                thread = process->th_tbl[i];
[23]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 );
[1]48        }
49
[23]50    // release the lock
[1]51        spinlock_unlock( &process->th_lock );
52
[5]53}  // end signal_rise()
[1]54
[23]55/*
56
57SIGNAL_HANDLER(kill_sigaction)
[1]58{
[23]59        thread_s * this = CURRENT_THREAD;
[1]60
[23]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());
[1]66
[23]67        sys_thread_exit((void*)EINTR);
[1]68}
69
[23]70///////////////////////////////////////////////
71void signal_manager_init( process_t * process )
[1]72{
[23]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}
[1]77
[5]78
[23]79/////////////////////////////////////
80void signal_notify( thread_t * this )
[1]81{
[23]82        uint32_t     sig_state;
83        uint32_t     sig;
84        sig_mgr_t  * sig_mgr;
85        uint32_t     irq_state;
[1]86
[23]87        sig_state = this->signals;
[1]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}
[23]124*/
Note: See TracBrowser for help on using the repository browser.