1 | /* |
---|
2 | * sys_thread_cancel.c - terminate execution of an user thread. |
---|
3 | * |
---|
4 | * Authors Alain Greiner (2016,2017, 2018) |
---|
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_remote.h> |
---|
26 | #include <hal_special.h> |
---|
27 | #include <thread.h> |
---|
28 | #include <errno.h> |
---|
29 | #include <printk.h> |
---|
30 | |
---|
31 | ////////////////////////////////////// |
---|
32 | int sys_thread_cancel( trdid_t trdid ) |
---|
33 | { |
---|
34 | xptr_t target_xp; // target thread extended pointer |
---|
35 | |
---|
36 | // get killer thread pointers |
---|
37 | thread_t * this = CURRENT_THREAD; |
---|
38 | process_t * process = this->process; |
---|
39 | |
---|
40 | // get extended pointer on target thread |
---|
41 | target_xp = thread_get_xptr( process->pid , trdid ); |
---|
42 | |
---|
43 | // check target_xp |
---|
44 | if( target_xp == XPTR_NULL ) |
---|
45 | { |
---|
46 | |
---|
47 | #if CONFIG_DEBUG_SYSCALLS_ERROR |
---|
48 | printk("\n[ERROR] in %s : target thread %x not found\n", __FUNCTION__, trdid ); |
---|
49 | #endif |
---|
50 | this->errno = EINVAL; |
---|
51 | return -1; |
---|
52 | } |
---|
53 | |
---|
54 | #if CONFIG_DEBUG_SYS_THREAD_CANCEL |
---|
55 | uint64_t tm_start; |
---|
56 | uint64_t tm_end; |
---|
57 | tm_start = hal_get_cycles(); |
---|
58 | if( CONFIG_DEBUG_SYS_THREAD_CANCEL < tm_start ) |
---|
59 | printk("\n[DBG] %s : thread %x enter to kill thread %x / cycle %d\n", |
---|
60 | __FUCTION__, this, GET_PTR( target_xp ), (uint32_t)tm_start ); |
---|
61 | #endif |
---|
62 | |
---|
63 | // cal the relevant kernel function |
---|
64 | thread_kill( target_xp, |
---|
65 | 0, // is_exit |
---|
66 | 0 ); // is forced |
---|
67 | |
---|
68 | #if CONFIG_DEBUG_SYS_THREAD_CANCEL |
---|
69 | tm_end = hal_get_cycles(); |
---|
70 | if( CONFIG_DEBUG_SYS_THREAD_CANCEL < tm_end ) |
---|
71 | printk("\n[DBG] %s : thread %x exit after kill thread %x / cycle %d\n", |
---|
72 | __FUCTION__, this, GET_PTR( target_xp ), (uint32_t)tm_end ); |
---|
73 | #endif |
---|
74 | |
---|
75 | return 0; |
---|
76 | |
---|
77 | } // end sys_thread_cancel() |
---|