source: trunk/kernel/syscalls/sys_fg.c @ 666

Last change on this file since 666 was 566, checked in by alain, 6 years ago

Complete restructuration of kernel locks.

File size: 3.2 KB
RevLine 
[421]1/*
2 * sys_fg.c - Kernel function implementing the "fg" system call.
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>
[457]25#include <hal_kernel_types.h>
[421]26#include <hal_irqmask.h>
27#include <errno.h>
28#include <thread.h>
29#include <printk.h>
30#include <process.h>
31#include <shared_syscalls.h>
32#include <cluster.h>
33#include <rpc.h>
34
[506]35#include <syscalls.h>
36
[446]37///////////////////////
38int sys_fg( pid_t pid )
[421]39{
[443]40    xptr_t      process_xp;     // extended pointer on reference process descriptor
[421]41    process_t * process_ptr;
42    cxy_t       process_cxy;
[443]43    xptr_t      file_xp;        // extended pointer on STDIN file descriptor
44    xptr_t      chdev_xp;       // extended pointer on TXT0_RX chdev
[421]45    chdev_t   * chdev_ptr;
46    cxy_t       chdev_cxy;
47
48    thread_t  * this    = CURRENT_THREAD;
49
[438]50#if DEBUG_SYS_FG
[421]51uint64_t    tm_start;
52uint64_t    tm_end;
53tm_start = hal_get_cycles();
[438]54if( DEBUG_SYS_FG < tm_start )
[436]55printk("\n[DBG] %s : thread %x enter / process %x / cycle %d\n",
56__FUNCTION__ , CURRENT_THREAD , pid, (uint32_t)tm_start );
[421]57#endif
58
59    // check process existence
60    process_xp = cluster_get_reference_process_from_pid( pid );
61
62    if( process_xp == XPTR_NULL )
63    {
[436]64
[438]65#if DEBUG_SYSCALLS_ERROR
[436]66printk("\n[ERROR] in %s : process %x not found\n", __FUNCTION__ , pid );
67#endif
[421]68        this->errno = EINVAL;
69        return -1;
70    }
71   
72    // get reference process cluster and local pointer
73    process_ptr = (process_t *)GET_PTR( process_xp );
74    process_cxy = GET_CXY( process_xp );
[443]75
76    // get extended pointer on the reference process STDIN file descriptor
[566]77    file_xp = hal_remote_l64( XPTR( process_cxy , &process_ptr->fd_array.array[0] ) );
[421]78 
79    // get extended pointer on TXT_RX chdev
[443]80    chdev_xp = chdev_from_file( file_xp );
[421]81
82    // get chdev cluster and local pointer
[436]83    chdev_ptr = GET_PTR( chdev_xp );
[421]84    chdev_cxy = GET_CXY( chdev_xp );
85
86    // set reference process owner in TXT_RX chdev
[566]87    hal_remote_s64( XPTR( chdev_cxy , &chdev_ptr->ext.txt.owner_xp ) , process_xp );
[421]88
[446]89    // reset PROCESS_TERM_WAIT and PROCESS_TERM_STOP flags in process term_state
90    hal_remote_atomic_and( XPTR( process_cxy , &process_ptr->term_state ),
91                                 ~(PROCESS_TERM_WAIT | PROCESS_TERM_STOP) ); 
92 
[421]93    hal_fence();
94
[438]95#if DEBUG_SYS_FG
[421]96tm_end = hal_get_cycles();
[438]97if( DEBUG_SYS_FG < tm_end )
[436]98printk("\n[DBG] %s : thread %x exit / process %x get TXT_%d ownership / cycle %d\n",
99__FUNCTION__ , CURRENT_THREAD , pid, 
[566]100hal_remote_l32( XPTR( chdev_cxy , &chdev_ptr->channel ) ) , (uint32_t)tm_end );
[421]101#endif
[436]102
[421]103        return 0;
104
[436]105}  // end sys_fg()
[421]106
Note: See TracBrowser for help on using the repository browser.