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

Last change on this file since 410 was 409, checked in by alain, 6 years ago

Fix bugs in exec

File size: 2.9 KB
RevLine 
[23]1/*
[409]2 * sys_kill.c - Send a signal to a given process.
[23]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>
[409]26#include <hal_irqmask.h>
[23]27#include <errno.h>
28#include <thread.h>
29#include <printk.h>
30#include <process.h>
31#include <signal.h>
32#include <cluster.h>
33#include <rpc.h>
34
35///////////////////////////
36int sys_kill( pid_t    pid,
37              uint32_t sig_id )
38{
[409]39    uint32_t    save_sr;       // required to enable IRQs
40
41#if CONFIG_SYSCALL_DEBUG
42uint64_t    tm_start;
43uint64_t    tm_end;
44tm_start = hal_get_cycles();
45#endif
46
[23]47    thread_t  * this    = CURRENT_THREAD;
48    process_t * process = this->process;
49
50    // get owner process cluster and lpid
51    cxy_t   owner_cxy  = CXY_FROM_PID( pid );
52    lpid_t  lpid       = LPID_FROM_PID( pid );
53
[409]54    // check pid
[23]55    if( (lpid >= CONFIG_MAX_PROCESS_PER_CLUSTER) || cluster_is_undefined( owner_cxy ) )
56    {
57        printk("\n[ERROR] in %s : illegal target PID = %d for thread %x in process %x\n",
[409]58        __FUNCTION__ , pid , this->trdid , pid );
[23]59                this->errno = EINVAL;
60        return -1;
61    }
62
[409]63    // check sig_id
64    if( (sig_id != SIGSTOP) && (sig_id != SIGCONT) && (sig_id != SIGKILL) ) 
65    {
66        printk("\n[ERROR] in %s : illegal signal type for thread %x in process %x\n",
67        __FUNCTION__ , sig_id , this->trdid , pid );
68                this->errno = EINVAL;
69        return -1;
70    }
[23]71
[409]72    // enable IRQs
73    hal_enable_irq( &save_sr );
[23]74
[409]75    // execute process_make_kill() function in owner cluster
76    if( local_cxy == owner_cxy )                                // owner is local
[23]77    {
[409]78        process_make_kill( process , sig_id );
[23]79    }
[409]80    else                                                        // owner is remote
81    {
82        rpc_process_make_kill_client( owner_cxy , process , sig_id );
83    }
[23]84
[409]85    // restore IRQs
86    hal_restore_irq( save_sr );
[23]87
[124]88    hal_fence();
[23]89
[409]90#if CONFIG_SYSCALL_DEBUG
91tm_end = hal_get_cycles();
92syscall_dmsg("\n[DBG] %s exit : core[%x,%d] / thread %x in process %x / cycle %d\n"
93"process %x killed / cost = %d\n",
94__FUNCTION__ , local_cxy , this->core->lid , this->trdid , this->process->pid ,
95tm_start , pid , (uint32_t)(tm_end - tm_start) );
96#endif
97 
[23]98        return 0;
99
100}  // end sys_kill()
101
Note: See TracBrowser for help on using the repository browser.