source: trunk/kernel/syscalls/sys_get_thread_info.c @ 657

Last change on this file since 657 was 642, checked in by alain, 5 years ago

Introduce two new syscalls : sys_get_thread_info() / sys_fbf()

File size: 2.5 KB
Line 
1/*
2 * sys_get_thread_info.c - get calling thread info.
3 *
4 * Author    Alain Greiner (2016,2017,2018,2019)
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_kernel_types.h>
25#include <shared_almos.h>
26#include <hal_uspace.h>
27#include <hal_vmm.h>
28#include <hal_special.h>
29#include <errno.h>
30#include <core.h>
31#include <thread.h>
32#include <process.h>
33#include <vmm.h>
34#include <printk.h>
35
36#include <syscalls.h>
37
38///////////////////////////////////////////////
39int sys_get_thread_info( thread_info_t * info )
40{
41        error_t     error;
42    vseg_t    * vseg;
43
44    thread_t  * this    = CURRENT_THREAD;
45    process_t * process = this->process;
46
47#if (DEBUG_SYS_GET_THREAD_INFO || CONFIG_INSTRUMENTATION_SYSCALLS)
48uint64_t     tm_start = hal_get_cycles();
49#endif
50
51    // check buffer in user space
52    error = vmm_get_vseg( process , (intptr_t)info , &vseg );
53
54        if( error )
55        {
56
57#if DEBUG_SYSCALLS_ERROR
58printk("\n[ERROR] in %s : user buffer unmapped %x / thread %x / process %x\n",
59__FUNCTION__ , (intptr_t)info , this->trdid , process->pid );
60#endif
61        this->errno = EFAULT;
62                return -1;
63        }
64
65    // copy thread_info_t structure to user space
66        hal_copy_to_uspace( info, 
67                        XPTR( local_cxy , &this->info),
68                        sizeof(thread_info_t) );
69
70#if (DEBUG_SYS_GET_THREAD_INFO || CONFIG_INSTRUMENTATION_SYSCALLS)
71uint64_t     tm_end = hal_get_cycles();
72#endif
73
74#if DEBUG_SYS_GET_THREAD_INFO
75if( DEBUG_SYS_GET_THREAD_INFO < tm_end )
76printk("\n[%s] thread[%x,%x] exit / cycle %d\n",
77__FUNCTION__ , process->pid, this->trdid, (uint32_t)tm_end );
78#endif
79
80#if CONFIG_INSTRUMENTATION_SYSCALLS
81hal_atomic_add( &syscalls_cumul_cost[SYS_GET_THREAD_INFO] , tm_end - tm_start );
82hal_atomic_add( &syscalls_occurences[SYS_GET_THREAD_INFO] , 1 );
83#endif
84
85        return 0; 
86
87}  // end sys_get_cycle()
Note: See TracBrowser for help on using the repository browser.