source: trunk/kernel/syscalls/sys_is_fg.c @ 529

Last change on this file since 529 was 506, checked in by viala@…, 6 years ago

[syscalls] add interface in implementation.

Add const where possible, fix protoypes to follow interface.

File size: 2.9 KB
RevLine 
[469]1/*
2 * sys_fg.c - Kernel function implementing the "is_fg" system call.
3 *
4 * Author    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 <kernel_config.h>
25#include <hal_kernel_types.h>
26#include <hal_uspace.h>
27#include <hal_special.h>
28#include <errno.h>
29#include <thread.h>
30#include <printk.h>
31#include <process.h>
32#include <vseg.h>
33#include <shared_syscalls.h>
34#include <cluster.h>
35
[506]36#include <syscalls.h>
37
[469]38//////////////////////////////
39int sys_is_fg( pid_t      pid,
40               uint32_t * is_fg )
41{
42    xptr_t      process_xp;       // extended pointer on process descriptor in owner cluster
43    uint32_t    is_txt_owner;     // kernel buffer for is_fg
44    vseg_t    * vseg;             // for buffer mapping check
45    error_t     error;
46
47    thread_t  * this    = CURRENT_THREAD;
48    process_t * process = this->process;
49
50#if DEBUG_SYS_IS_FG
51uint64_t    tm_start;
52uint64_t    tm_end;
53tm_start = hal_get_cycles();
54if( DEBUG_SYS_FG < tm_start )
55printk("\n[DBG] %s : thread %x in process %x enter for pid %x / cycle %d\n",
56__FUNCTION__ , this->trdid , process->pid, pid, (uint32_t)tm_start );
57#endif
58
59    // check buffer in user vspace
60        error = vmm_get_vseg( process , (intptr_t)is_fg , &vseg );
61    if( error )
62    {
63
64#if DEBUG_SYSCALLS_ERROR
65printk("\n[ERROR] in %s : unmapped owner buffer %x / thread %x in process %x\n",
66__FUNCTION__ , (intptr_t)is_fg, this->trdid, process->pid );
67vmm_display( process , false );
68#endif
69         this->errno = EINVAL;
70         return -1;
71    }
72
73    // check target process existence
74    process_xp = cluster_get_owner_process_from_pid( pid );
75
76    if( process_xp == XPTR_NULL )
77    {
78
79#if DEBUG_SYSCALLS_ERROR
80printk("\n[ERROR] in %s : process %x not found\n", __FUNCTION__ , pid );
81#endif
82        this->errno = EINVAL;
83        return -1;
84    }
85   
86    // call relevant kernel function
87    is_txt_owner = process_txt_is_owner( process_xp );
88
89    // copy to user space
90    hal_copy_to_uspace( is_fg , &is_txt_owner , sizeof(uint32_t) );
91
92    hal_fence();
93
94#if DEBUG_SYS_IS_FG
95tm_end = hal_get_cycles();
96if( DEBUG_SYS_FG < tm_end )
97printk("\n[DBG] %s : thread %x in process %x exit / is_txt_owner %d / cycle %d\n",
98__FUNCTION__, this->trdid, process->pid, is_txt_owner, (uint32_t)tm_end );
99#endif
100
101        return 0;
102
103}  // end sys_is_fg()
104
Note: See TracBrowser for help on using the repository browser.