source: trunk/kernel/syscalls/sys_kill.c @ 398

Last change on this file since 398 was 124, checked in by max@…, 7 years ago

rename hal_wbflush->hal_fence

File size: 3.1 KB
Line 
1/*
2 * sys_kill.c: Send a signal to a given process.
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 <kernel_config.h>
25#include <hal_types.h>
26#include <errno.h>
27#include <thread.h>
28#include <printk.h>
29#include <process.h>
30#include <signal.h>
31#include <cluster.h>
32#include <rpc.h>
33
34///////////////////////////
35int sys_kill( pid_t    pid,
36              uint32_t sig_id )
37{
38    thread_t  * this    = CURRENT_THREAD;
39    process_t * process = this->process;
40
41    // check signal index
42        if( (sig_id == 0) || (sig_id >= SIG_NR) )
43        {
44        printk("\n[ERROR] in %s : illegal signal = %d for thread %x in process %x\n",
45               __FUNCTION__ , sig_id , this->trdid , process->pid );
46                this->errno = EINVAL;
47        return -1;
48        }
49
50    // get local pointer on local cluster manager
51    cluster_t * cluster = LOCAL_CLUSTER;
52
53    // get owner process cluster and lpid
54    cxy_t   owner_cxy  = CXY_FROM_PID( pid );
55    lpid_t  lpid       = LPID_FROM_PID( pid );
56
57    // check PID
58    if( (lpid >= CONFIG_MAX_PROCESS_PER_CLUSTER) || cluster_is_undefined( owner_cxy ) )
59    {
60        printk("\n[ERROR] in %s : illegal target PID = %d for thread %x in process %x\n",
61               __FUNCTION__ , pid , this->trdid , process->pid );
62                this->errno = EINVAL;
63        return -1;
64    }
65
66    // get extended pointers on copies root and lock
67    xptr_t root_xp = XPTR( owner_cxy , &cluster->pmgr.copies_root[lpid] );
68    xptr_t lock_xp = XPTR( owner_cxy , &cluster->pmgr.copies_lock[lpid] );
69
70    // take the lock protecting the copies
71    remote_spinlock_lock( lock_xp );
72
73    // TODO the loop below sequencialize the RPCs
74    // they could be pipelined using a non-blocking RPC ...
75 
76    // loop on the process decriptor copies
77    xptr_t  iter_xp;
78    XLIST_FOREACH( root_xp , iter_xp )
79    {
80        xptr_t      process_xp  = XLIST_ELEMENT( iter_xp , process_t , copies_list );
81        cxy_t       process_cxy = GET_CXY( process_xp );
82        process_t * process_ptr = (process_t *)GET_PTR( process_xp );
83
84        if( process_cxy == local_cxy )   // process copy is local
85        {
86            signal_rise( process_ptr , sig_id );
87        }
88        else                           // process copy is remote
89        {
90            rpc_signal_rise_client( process_cxy , process_ptr , sig_id );
91        }
92    }
93
94    // release the lock
95    remote_spinlock_unlock( lock_xp );
96
97    hal_fence();
98
99        return 0;
100
101}  // end sys_kill()
102
Note: See TracBrowser for help on using the repository browser.