Changeset 407 for trunk/kernel/syscalls
- Timestamp:
- Nov 7, 2017, 3:08:12 PM (6 years ago)
- Location:
- trunk/kernel/syscalls
- Files:
-
- 27 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/syscalls/sys_chdir.c
r301 r407 41 41 process_t * process = this->process; 42 42 43 // get pathname copy in kernel space 44 error = hal_strcpy_from_uspace( kbuf, pathname, CONFIG_VFS_MAX_PATH_LENGTH ); 45 46 if( error ) 43 // check pathname length 44 if( hal_strlen_from_uspace( pathname ) >= CONFIG_VFS_MAX_PATH_LENGTH ) 47 45 { 48 printk("\n[ERROR] in %s : pathname too long for thread %x in process %x\n", 49 __FUNCTION__ , this->trdid , process->pid ); 46 printk("\n[ERROR] in %s : pathname too long\n", __FUNCTION__ ); 50 47 this->errno = ENFILE; 51 48 return -1; 52 49 } 50 51 // copy pathname in kernel space 52 hal_strcpy_from_uspace( kbuf , pathname , CONFIG_VFS_MAX_PATH_LENGTH ); 53 53 54 54 // get cluster and local pointer on reference process -
trunk/kernel/syscalls/sys_chmod.c
r302 r407 40 40 process_t * process = this->process; 41 41 42 // get pathname copy in kernel space 43 error = hal_strcpy_from_uspace( kbuf , pathname , CONFIG_VFS_MAX_PATH_LENGTH ); 44 45 if( error ) 42 // check pathname length 43 if( hal_strlen_from_uspace( pathname ) >= CONFIG_VFS_MAX_PATH_LENGTH ) 46 44 { 47 45 printk("\n[ERROR] in %s : pathname too long\n", __FUNCTION__ ); … … 49 47 return -1; 50 48 } 49 50 // copy pathname in kernel space 51 hal_strcpy_from_uspace( kbuf , pathname , CONFIG_VFS_MAX_PATH_LENGTH ); 51 52 52 53 // get cluster and local pointer on reference process -
trunk/kernel/syscalls/sys_closedir.c
r23 r407 24 24 #include <hal_types.h> 25 25 #include <vfs.h> 26 #include <printk.h> 26 27 #include <thread.h> 27 #include <printk.h>28 28 #include <process.h> 29 #include <errno.h> 30 #include <syscalls.h> 31 #include <shared_syscalls.h> 29 32 30 /////////////////////////////// //////31 int sys_closedir ( uint32_t file_id)33 /////////////////////////////// 34 int sys_closedir ( DIR * dirp ) 32 35 { 33 error_t error; 34 xptr_t file_xp; // extended pointer on searched directory file descriptor 35 36 thread_t * this = CURRENT_THREAD; 37 process_t * process = this->process; 38 39 // check file_id argument 40 if( file_id >= CONFIG_PROCESS_FILE_MAX_NR ) 41 { 42 printk("\n[ERROR] in %s : illegal file descriptor index %d\n", 43 __FUNCTION__ , file_id ); 44 this->errno = EBADFD; 45 return -1; 46 } 47 48 // get extended pointer on remote file descriptor 49 file_xp = process_fd_get_xptr( process , file_id ); 50 51 if( file_xp == XPTR_NULL ) 52 { 53 printk("\n[ERROR] in %s : undefined file descriptor index = %d\n", 54 __FUNCTION__ , file_id ); 55 this->errno = EBADFD; 56 return -1; 57 } 58 59 // call relevant VFS function 60 error = vfs_close( file_xp , file_id ); 61 62 if( error ) 63 { 64 printk("\n[ERROR] in %s : cannot close the directory = %d\n", 65 __FUNCTION__ , file_id ); 66 this->errno = error; 67 return -1; 68 } 69 70 return 0; 71 36 printk("\n[ERROR] in %s : not implemented yet\n", __FUNCTION__ ); 37 CURRENT_THREAD->errno = ENOMEM; 38 return -1; 72 39 } // end sys_closedir() -
trunk/kernel/syscalls/sys_creat.c
r23 r407 25 25 #include <vfs.h> 26 26 #include <syscalls.h> 27 #include <shared_syscalls.h> 27 28 28 29 //////////////////////////////////// -
trunk/kernel/syscalls/sys_exec.c
r406 r407 38 38 39 39 ////////////////////////////////////////////////i////////////////////////////////////// 40 // This static function is called by the sys_exec() function to register the .elf41 // pathname in the exec_info structure, from a string stored in user space.42 ////////////////////////////////////////////////i//////////////////////////////////////43 // @ exec_info : pointer on the exec_info structure.44 // @ pathname : string containing the path to the .elf file (user space).45 // return 0 if success / non-zero if one string too long, or too many strings.46 ///////////////////////////////////////////////////////////////////////////////////////47 static error_t process_exec_get_path( exec_info_t * exec_info,48 char * pathname )49 {50 error_t error;51 52 // copy string to exec_info53 error = hal_strcpy_from_uspace( &exec_info->path[0] , pathname ,54 CONFIG_VFS_MAX_PATH_LENGTH );55 if( error )56 return EINVAL;57 58 return 0;59 }60 61 ////////////////////////////////////////////////i//////////////////////////////////////62 40 // This static function is called twice by the sys_exec() function : 63 41 // - to register the main() arguments (args) in the exec_info structure. … … 71 49 // to store the (args) and (envs) strings are configuration parameters. 72 50 /////////////////////////////////////////////////////////////////////////////////////// 73 // @ exec_info : pointer on the exec_info structure.74 // @ is_args : true if called for (args) / false if called for (envs).75 // @ pointers : array of pointers on the strings (in user space).51 // @ exec_info : pointer on the exec_info structure. 52 // @ is_args : true if called for (args) / false if called for (envs). 53 // @ u_pointers : array of pointers on the strings (in user space). 76 54 // @ return 0 if success / non-zero if too many strings or no more memory. 77 55 /////////////////////////////////////////////////////////////////////////////////////// … … 173 151 // This function build an exec_info_t structure containing all informations 174 152 // required to create the new process descriptor and the associated thread. 175 // It calls the static process_exec_get_path() and process_exec_get_strings() functions 176 // to copy the .elf pathname, the main() arguments and the environment variables from 177 // user buffers to the exec_info_t structure, and call the process_make_exec() function. 153 // It calls the process_exec_get_strings() functions to copy the main() arguments and 154 // the environment variables from user buffers to the exec_info_t structure, allocate 155 // and call the process_make_exec() function. 156 // Finally, it destroys the calling thread and process. 157 // TODO : the args & envs arguments are not supported yet : both must be NULL 178 158 ///////////////////////////////////////////////////////////////////////////////////////// 179 int sys_exec( char * filename, // .elf file pathname159 int sys_exec( char * pathname, // .elf file pathname 180 160 char ** args, // process arguments 181 161 char ** envs ) // environment variables 182 162 { 183 exec_info_t exec_info; // structure to pass to process_make_exec() 184 error_t error; 185 paddr_t paddr; 186 163 exec_info_t exec_info; // structure to pass to process_make_exec() 164 error_t error; 165 166 uint64_t tm_start; 167 uint64_t tm_end; 168 169 tm_start = hal_get_cycles(); 170 171 // get pointers on parent process and thread 187 172 thread_t * this = CURRENT_THREAD; 188 173 process_t * process = this->process; 189 190 // check argument fileme 191 error = vmm_v2p_translate( false , filename , &paddr ); 174 pid_t pid = process->pid; 175 176 exec_dmsg("\n[DBG] %s : core[%x,%d] enters for process %x / cycle %d\n", 177 __FUNCTION__, local_cxy, this->core->lid, pid, (uint32_t)hal_get_cycles() ); 178 179 sched_display( 0 ); 180 181 // check pathname length 182 if( hal_strlen_from_uspace( pathname ) >= CONFIG_VFS_MAX_PATH_LENGTH ) 183 { 184 printk("\n[ERROR] in %s : pathname too long\n", __FUNCTION__ ); 185 this->errno = ENFILE; 186 return -1; 187 } 188 189 // copy pathname in exec_info structure (kernel space) 190 hal_strcpy_from_uspace( exec_info.path , pathname , CONFIG_VFS_MAX_PATH_LENGTH ); 191 // check args argument 192 assert( (args == NULL) , __FUNCTION__ , 193 "args not supported yet\n" ); 194 195 // check envs argument 196 assert( (envs == NULL) , __FUNCTION__ , 197 "args not supported yet\n" ); 198 199 // compute client_cxy (local cluster) and server_cxy (target cluster) 200 cxy_t cxy_server = CXY_FROM_PID( pid ); 201 cxy_t cxy_client = local_cxy; 202 203 // register parent process in exec_info 204 exec_info.parent_xp = process->ref_xp; 205 206 // new process keep the parent process PID 207 exec_info.keep_pid = true; 208 209 // check and store args in exec_info structure if required 210 if( args != NULL ) 211 { 212 if( process_exec_get_strings( &exec_info , true , args ) ) 213 { 214 printk("\n[ERROR] in %s : cannot access args\n", __FUNCTION__ ); 215 this->errno = error; 216 return -1; 217 } 218 } 219 220 // check and store envs in exec_info structure if required 221 if( envs != NULL ) 222 { 223 if( process_exec_get_strings( &exec_info , false , envs ) ) 224 { 225 printk("\n[ERROR] in %s : cannot access envs\n", __FUNCTION__ ); 226 this->errno = error; 227 return -1; 228 } 229 } 230 231 // call process_make_exec (local or remote) 232 if( cxy_server == cxy_client ) 233 { 234 error = process_make_exec( &exec_info ); 235 } 236 else 237 { 238 rpc_process_exec_client( cxy_server , &exec_info , &error ); 239 } 192 240 193 241 if( error ) 194 242 { 195 printk("\n[ERROR] in %s : filename unmapped\n", __FUNCTION__ ); 196 this->errno = EINVAL; 197 return -1; 198 } 199 200 // check argument fileme 201 error = vmm_v2p_translate( false , args , &paddr ); 202 203 if( error ) 204 { 205 printk("\n[ERROR] in %s : args unmapped\n", __FUNCTION__ ); 206 this->errno = EINVAL; 207 return -1; 208 } 209 210 // check argument fileme 211 error = vmm_v2p_translate( false , envs , &paddr ); 212 213 if( error ) 214 { 215 printk("\n[ERROR] in %s : envs unmapped\n", __FUNCTION__ ); 216 this->errno = EINVAL; 217 return -1; 218 } 219 220 // compute client_cxy (local cluster) and server_cxy (target cluster) 221 cxy_t cxy_server = CXY_FROM_PID( process->pid ); 222 cxy_t cxy_client = local_cxy; 223 bool_t is_local = (cxy_server == cxy_client); 224 225 exec_dmsg("\n[DMSG] %s starts for process %x on core %d in cluster %x" 226 " / target_cluster = %x / cycle %d\n", 227 __FUNCTION__, process->pid , CURRENT_CORE->lid, 228 cxy_client, cxy_server, hal_get_cycles()); 229 230 // register reference parent process in exec_info 231 exec_info.parent_xp = process->ref_xp; 232 233 // check pathname and store it in exec_info structure 234 error = process_exec_get_path( &exec_info , filename ); 235 236 if ( error ) 237 { 238 printk("\n[ERROR] in %s : elf pathname too long\n", __FUNCTION__ ); 243 printk("\n[ERROR] in %s : cannot create new process %x in cluster %x\n", 244 __FUNCTION__, pid, cxy_server ); 239 245 this->errno = error; 240 246 return -1; 241 247 } 242 248 243 // check and store args in exec_info structure 244 error = process_exec_get_strings( &exec_info , true , args ); 245 246 if( error ) 247 { 248 printk("\n[ERROR] in %s : cannot access args\n", __FUNCTION__ ); 249 this->errno = error; 250 return -1; 251 } 252 253 // check and store envs in exec_info structure 254 error = process_exec_get_strings( &exec_info , false , envs ); 255 256 if( error ) 257 { 258 printk("\n[ERROR] in %s : cannot access envs\n", __FUNCTION__ ); 259 this->errno = error; 260 return -1; 261 } 262 263 exec_dmsg("\n[DMSG] %s starts exec for process %x at cycle %d\n", 264 __FUNCTION__, process->pid, hal_get_cycles() ); 265 266 if( is_local ) error = process_make_exec( &exec_info ); 267 else rpc_process_exec_client( cxy_server , &exec_info , &error ); 268 269 if( error ) 270 { 271 printk("\n[ERROR] in %s : cannot create new process %x\n", 272 __FUNCTION__ , process->pid ); 273 this->errno = error; 274 return -1; 275 } 276 277 exec_dmsg("\n[DMSG] %s completes exec for process %x at cycle %d\n", 278 __FUNCTION__, process->pid , hal_get_cycles() ); 279 280 // delete the calling thread an process 281 thread_kill( CURRENT_THREAD ); 282 process_kill( CURRENT_THREAD->process ); 249 // FIXME delete the local process descriptor 250 // process_kill( process ); 251 252 tm_end = hal_get_cycles(); 253 254 exec_dmsg("\n[DBG] %s : core[%x,%d] exit for process %x / cycle %d\n" 255 " pathname = %s / cost = %d\n", 256 __FUNCTION__, local_cxy, this->core->lid, pid, (uint32_t)tm_start, 257 exec_info.path , (uint32_t)(tm_end - tm_start) ); 283 258 284 259 return 0; -
trunk/kernel/syscalls/sys_fork.c
r406 r407 24 24 #include <kernel_config.h> 25 25 #include <hal_types.h> 26 #include <hal_context.h> 27 #include <hal_switch.h> 26 28 #include <hal_atomic.h> 27 29 #include <errno.h> … … 45 47 pid_t child_pid; // child process identifier 46 48 thread_t * child_thread; // pointer on child main thread descriptor 47 trdid_t child_trdid; // child main thread identifier 48 lid_t child_core_lid; // core local index for the child main thread 49 cxy_t target_cxy; // final target cluster for forked child process 49 cxy_t target_cxy; // target cluster for forked child process 50 50 error_t error; 51 52 uint64_t tm_start; 53 uint64_t tm_end; 54 55 tm_start = hal_get_cycles(); 51 56 52 57 // get pointers on parent process and thread … … 55 60 parent_pid = parent_process->pid; 56 61 62 fork_dmsg("\n[DBG] %s : core[%x,%d] enters for process %x / cycle %d\n", 63 __FUNCTION__ , local_cxy , parent_thread->core->lid , parent_pid , (uint32_t)tm_start ); 64 57 65 // check parent process children number 58 66 if( hal_atomic_add( &parent_process->children_nr , 1 ) >= CONFIG_PROCESS_MAX_CHILDREN ) … … 61 69 hal_atomic_add ( &parent_process->children_nr , -1 ); 62 70 return EAGAIN; 63 }64 65 fork_dmsg("\n[DMSG] %s : enters for process %d at cycle [%d]\n",66 __FUNCTION__, parent_process->pid, hal_get_cycles());67 68 // save FPU state in fpu_context if parent process is FPU owner69 // because we want the child process to share the FPU context70 if( CURRENT_CORE->fpu_owner == parent_thread )71 {72 hal_fpu_context_save( parent_thread );73 fork_dmsg("\n[DMSG] %s : save FPU\n", __FUNCTION__);74 71 } 75 72 … … 95 92 } 96 93 97 fork_dmsg("INFO : %s selecttarget_cluster = %x\n",98 __FUNCTION__, target_cxy );94 //printk("\n[DBG] %s : core[%x,%d] for process %x selects target_cluster = %x\n", 95 //__FUNCTION__ , local_cxy , parent_thread->core->lid , parent_pid , target_cxy ); 99 96 100 97 // allocates memory in local cluster for the child process descriptor … … 127 124 128 125 // initialize and register the child process descriptor 129 process_reference_init( child_process , child_pid , parent_pid ); 130 131 fork_dmsg("\n[DMSG] : %s created child process : pid = %x / ppid = %x\n", 132 __FUNCTION__, child_pid , parent_pid ); 126 process_reference_init( child_process , child_pid , XPTR(local_cxy, parent_process) ); 133 127 134 128 // initialises child process standard files structures … … 148 142 XPTR( local_cxy , &parent_process->fd_array ) ); 149 143 150 fork_dmsg("\n[DMSG] %s : duplicated child process from parent process\n",151 __FUNCTION__);152 153 // replicate s virtual memory manager144 //printk("\n[DBG] %s : core[%x,%d] for process %x created child process %x\n", 145 //__FUNCTION__ , local_cxy , parent_thread->core->lid , parent_pid , child_pid ); 146 147 // replicate VMM 154 148 error = vmm_copy( child_process , parent_process ); 155 149 … … 162 156 } 163 157 164 fork_dmsg("\n[DMSG] %s : parent vmm duplicated in child process\n", __FUNCTION__ ); 165 166 // create child main thread descriptor in local cluster 167 error = thread_user_fork( parent_process , &child_thread ); 168 158 //printk("\n[DBG] %s : core[%x,%d] for process %x duplicated vmm in child process\n", 159 //__FUNCTION__ , local_cxy , parent_thread->core->lid , parent_pid ); 160 //vmm_display( parent_process , true ); 161 //vmm_display( child_process , true ); 162 163 // create child main thread in local cluster 164 error = thread_user_fork( child_process, 165 parent_thread->u_stack_size, 166 parent_thread->u_stack_base, 167 &child_thread ); 169 168 if( error ) 170 169 { 171 printk("\n[ERROR] in %s : cannot duplicate thread\n", __FUNCTION__ );170 printk("\n[ERROR] in %s : cannot duplicate main thread\n", __FUNCTION__ ); 172 171 hal_atomic_add( &parent_process->children_nr , -1 ); 173 172 process_destroy( child_process ); … … 175 174 } 176 175 177 // register child thread in child process, and get a TRDID 178 spinlock_lock( &child_process->th_lock ); 179 error = process_register_thread( child_process, child_thread , &child_trdid ); 180 spinlock_unlock( &child_process->th_lock ); 181 182 if( error ) 183 { 184 printk("\n[ERROR] in %s : cannot register thread\n", __FUNCTION__ ); 185 hal_atomic_add ( &parent_process->children_nr , -1 ); 186 thread_destroy( child_thread ); 187 process_destroy( child_process ); 188 return EAGAIN; 189 } 190 191 // get a local core to execute child thread 192 child_core_lid = cluster_select_local_core(); 193 194 // Update child thread descriptor 195 child_thread->core = &LOCAL_CLUSTER->core_tbl[child_core_lid]; 196 child_thread->process = child_process; 197 child_thread->trdid = child_trdid; 198 199 fork_dmsg("\n[DMSG] %s : initialised child main thread\n", __FUNCTION__ ); 200 201 // register local child thread into local child process th_tbl[] 202 // we don't use the th_lock because there is no concurrent access 203 ltid_t ltid = LTID_FROM_TRDID( child_trdid ); 204 child_process->th_tbl[ltid] = child_thread; 205 child_process->th_nr = 1; 206 207 // register child thread in scheduler 208 sched_register_thread( child_thread->core , child_thread ); 209 210 fork_dmsg("\n[DMSG] %s : registered main thread in scheduler\n", __FUNCTION__); 176 //printk("\n[DBG] %s : core[%x,%d] initialised child main thread\n", 177 //__FUNCTION__ , local_cxy , parent_thread->core->lid ); 211 178 212 179 // update DQDT for the child thread 213 180 dqdt_local_update_threads( 1 ); 214 181 215 fork_dmsg("\n[DMSG] %s : completed / parent pid = %x / child pid = %x / at cycle [%d]\n", 216 __FUNCTION__, parent_process->pid, child_process->pid, hal_get_cycles() ); 217 218 return child_process->pid; 182 // set child_thread FPU_context from parent_thread register values 183 // only when the parent process is the FPU owner 184 if( CURRENT_THREAD->core->fpu_owner == parent_thread ) 185 { 186 hal_fpu_context_save( child_thread->fpu_context ); 187 } 188 189 // set child_thread CPU context from parent_thread register values 190 hal_do_cpu_save( child_thread->cpu_context, 191 child_thread, 192 (int)((intptr_t)child_thread - (intptr_t)parent_thread) ); 193 194 195 // from this point, both parent and child threads execute the following code 196 // but child execute it only when it has been unblocked by its parent 197 198 thread_t * current = CURRENT_THREAD; 199 200 if( current == parent_thread ) 201 { 202 // parent_thread unblock child_thread 203 thread_unblock( XPTR( local_cxy , child_thread ) , THREAD_BLOCKED_GLOBAL ); 204 205 tm_end = hal_get_cycles(); 206 207 fork_dmsg("\n[DBG] %s : core[%x,%d] parent_process %x exit / cycle %d\n" 208 " child_process %x / child_thread = %x / cost = %d\n", 209 __FUNCTION__, local_cxy, parent_thread->core->lid, parent_pid, (uint32_t)tm_start, 210 child_pid, child_thread->trdid , (uint32_t)(tm_end - tm_start) ); 211 212 return child_pid; 213 } 214 else // current == child_thread 215 { 216 assert( (current == child_thread) , __FUNCTION__ , 217 "current thread %x is not the child thread %x\n", current , child_thread ); 218 219 fork_dmsg("\n[DBG] %s : core[%x,%d] child process %x exit / cycle %d\n", 220 __FUNCTION__, local_cxy, parent_thread->core->lid, child_pid, (uint32_t)hal_get_cycles() ); 221 222 return 0; 223 } 219 224 220 225 } // end sys_fork() -
trunk/kernel/syscalls/sys_get_cycle.c
r405 r407 1 1 /* 2 * sys_ clock: get calling core cycles count2 * sys_get_cycle.c - get calling core cycles count. 3 3 * 4 4 * Author Alain Greiner (2016,2017) … … 32 32 #include <printk.h> 33 33 34 ////////////////////////////////// 35 int sys_ clock (uint64_t * cycles)34 ////////////////////////////////////// 35 int sys_get_cycle ( uint64_t * cycle ) 36 36 { 37 37 error_t error; 38 38 paddr_t paddr; 39 uint64_t k_cycle s;39 uint64_t k_cycle; 40 40 41 41 thread_t * this = CURRENT_THREAD; … … 43 43 44 44 // check buffer in user space 45 error = vmm_v2p_translate( false , cycle s, &paddr );45 error = vmm_v2p_translate( false , cycle , &paddr ); 46 46 47 47 if( error ) … … 54 54 55 55 // call relevant core function 56 k_cycle s= hal_get_cycles();56 k_cycle = hal_get_cycles(); 57 57 58 58 // copy to user space 59 hal_copy_to_uspace( cycle s , &k_cycles, sizeof(uint64_t) );59 hal_copy_to_uspace( cycle , &k_cycle , sizeof(uint64_t) ); 60 60 61 61 return 0; 62 62 63 } // end sys_ clock()63 } // end sys_get_cycle() -
trunk/kernel/syscalls/sys_mkdir.c
r303 r407 1 1 /* 2 * sys_mkdir.c - Create a new directory 2 * sys_mkdir.c - Create a new directory in file system. 3 3 * 4 4 * Author Alain Greiner (2016,2017) … … 50 50 } 51 51 52 // get pathname copy in kernel space 53 error = hal_strcpy_from_uspace( kbuf , pathname , CONFIG_VFS_MAX_PATH_LENGTH ); 54 55 if( error ) 52 // check pathname length 53 if( hal_strlen_from_uspace( pathname ) >= CONFIG_VFS_MAX_PATH_LENGTH ) 56 54 { 57 55 printk("\n[ERROR] in %s : pathname too long\n", __FUNCTION__ ); … … 59 57 return -1; 60 58 } 59 60 // copy pathname in kernel space 61 hal_strcpy_from_uspace( kbuf , pathname , CONFIG_VFS_MAX_PATH_LENGTH ); 61 62 62 63 // get cluster and local pointer on reference process -
trunk/kernel/syscalls/sys_mkfifo.c
r304 r407 48 48 } 49 49 50 // get pathname copy in kernel space 51 error = hal_strcpy_from_uspace( kbuf , pathname , CONFIG_VFS_MAX_PATH_LENGTH ); 52 53 if( error ) 50 // check pathname length 51 if( hal_strlen_from_uspace( pathname ) >= CONFIG_VFS_MAX_PATH_LENGTH ) 54 52 { 55 53 printk("\n[ERROR] in %s : pathname too long\n", __FUNCTION__ ); … … 57 55 return -1; 58 56 } 57 58 // copy pathname in kernel space 59 hal_strcpy_from_uspace( kbuf , pathname , CONFIG_VFS_MAX_PATH_LENGTH ); 59 60 60 61 // get cluster and local pointer on reference process -
trunk/kernel/syscalls/sys_mmap.c
r23 r407 24 24 25 25 #include <hal_types.h> 26 #include <hal_uspace.h> 27 #include <shared_syscalls.h> 26 28 #include <errno.h> 27 29 #include <thread.h> 28 30 #include <printk.h> 31 #include <mapper.h> 29 32 #include <vfs.h> 30 33 #include <process.h> 31 34 #include <vmm.h> 32 35 33 ////////////////////////////////// /36 ////////////////////////////////// 34 37 int sys_mmap( mmap_attr_t * attr ) 35 38 { 36 printk("\n[WARNING] function %s not implemented\n", __FUNCTION__ ); 37 return 0; 38 /* 39 error_t err; 40 uint_t count; 41 struct thread_s *this; 42 struct process_s *process; 43 struct vfs_file_s *file; 44 mmap_attr_t attr; 45 size_t isize; 46 int retval; 39 vseg_t * vseg; 40 cxy_t vseg_cxy; 41 vseg_type_t vseg_type; 42 mmap_attr_t k_attr; // attributes copy in kernel space 43 xptr_t mapper_xp; 44 error_t error; 45 paddr_t paddr; // unused, but required for user space checking 46 47 uint64_t tm_start; 48 uint64_t tm_end; 49 50 tm_start = hal_get_cycles(); 51 52 thread_t * this = CURRENT_THREAD; 53 process_t * process = this->process; 54 55 // check arguments in user space 56 error = vmm_v2p_translate( false , attr , &paddr ); 57 58 if ( error ) 59 { 60 printk("\n[ERROR] in %s : arguments not in used space = %x\n", 61 __FUNCTION__ , (intptr_t)attr ); 62 this->errno = EINVAL; 63 return -1; 64 } 65 66 // copy arguments from uspace 67 hal_copy_from_uspace( &k_attr , attr , sizeof(mmap_attr_t) ); 68 69 // get fdid, offset, and length arguments 70 uint32_t fdid = k_attr.fdid; 71 uint32_t offset = k_attr.offset; 72 uint32_t length = k_attr.length; 73 74 // get flags 75 bool_t map_fixed = ( (k_attr.flags & MAP_FIXED) != 0 ); 76 bool_t map_anon = ( (k_attr.flags & MAP_ANON) != 0 ); 77 bool_t map_remote = ( (k_attr.flags & MAP_REMOTE) != 0 ); 78 bool_t map_shared = ( (k_attr.flags & MAP_SHARED) != 0 ); 79 bool_t map_private = ( (k_attr.flags & MAP_PRIVATE) != 0 ); 80 81 // MAP_FIXED not supported 82 if( map_fixed ) 83 { 84 printk("\n[ERROR] in %s : MAP_FIXED not supported\n", __FUNCTION__ ); 85 this->errno = EINVAL; 86 return -1; 87 } 88 89 if( map_shared == map_private ) 90 { 91 printk("\n[ERROR] in %s : MAP_SHARED xor MAP_PRIVATE\n", __FUNCTION__ ); 92 this->errno = EINVAL; 93 return -1; 94 } 95 96 // FIXME handle Copy_On_Write for MAP_PRIVATE... 97 98 // get access rigths 99 bool_t prot_read = ( (k_attr.prot & PROT_READ ) != 0 ); 100 bool_t prot_write = ( (k_attr.prot & PROT_WRITE) != 0 ); 101 102 // test mmap type : can be FILE / ANON / REMOTE 103 104 if( (map_anon == false) && (map_remote == false) ) // FILE 105 { 106 // FIXME: handle concurent delete of file by another thread closing it 107 108 if( fdid >= CONFIG_PROCESS_FILE_MAX_NR ) 109 { 110 printk("\n[ERROR] in %s: bad file descriptor = %d\n", __FUNCTION__ , fdid ); 111 this->errno = EBADFD; 112 return -1; 113 } 114 115 // get extended pointer on file descriptor 116 xptr_t file_xp = process_fd_get_xptr( process , fdid ); 117 118 if( file_xp == XPTR_NULL ) 119 { 120 printk("\n[ERROR] in %s: file %d not found\n", __FUNCTION__ , fdid ); 121 this->errno = EBADFD; 122 return -1; 123 } 124 125 // get file cluster and local pointer 126 cxy_t file_cxy = GET_CXY( file_xp ); 127 vfs_file_t * file_ptr = (vfs_file_t *)GET_PTR( file_xp ); 128 129 // get inode pointer, mapper pointer and file attributes 130 vfs_inode_t * inode_ptr = hal_remote_lpt(XPTR(file_cxy , &file_ptr->inode )); 131 uint32_t file_attr = hal_remote_lw (XPTR(file_cxy , &file_ptr->attr )); 132 mapper_t * mapper_ptr = hal_remote_lpt(XPTR(file_cxy , &file_ptr->mapper)); 133 134 // get file size 135 uint32_t size = hal_remote_lw( XPTR( file_cxy , &inode_ptr->size ) ); 136 137 // chek offset and length arguments 138 if( (offset + length) > size) 139 { 140 printk("\n[ERROR] in %s: offset (%d) + len (%d) >= file's size (%d)\n", 141 __FUNCTION__, k_attr.offset, k_attr.length, size ); 142 this->errno = ERANGE; 143 return -1; 144 } 145 146 // check access rights 147 if( (prot_read && !(file_attr & FD_ATTR_READ_ENABLE)) || 148 (prot_write && !(file_attr & FD_ATTR_WRITE_ENABLE)) ) 149 { 150 printk("\n[ERROR] in %s: prot = %x / file_attr = %x)\n", 151 __FUNCTION__ , k_attr.prot , file_attr ); 152 this->errno = EACCES; 153 return -1; 154 } 155 156 // increment file refcount 157 vfs_file_count_up( file_xp ); 158 159 mapper_xp = XPTR( file_cxy , mapper_ptr ); 160 vseg_type = VSEG_TYPE_FILE; 161 vseg_cxy = file_cxy; 162 } 163 else // ANON or REMOTE 164 { 165 // no mapper for ANON or REMOTE 166 mapper_xp = XPTR_NULL; 167 168 if( map_anon ) 169 { 170 vseg_type = VSEG_TYPE_ANON; 171 vseg_cxy = local_cxy; 172 } 173 else 174 { 175 vseg_type = VSEG_TYPE_REMOTE; 176 vseg_cxy = k_attr.fdid; 47 177 48 this = current_thread; 49 process = this->process; 50 err = EINVAL; 51 file = NULL; 52 53 if((err = cpu_copy_from_uspace(&attr, attr, sizeof(mmap_attr_t)))) 54 { 55 printk(INFO, "%s: failed, copying from uspace @%x\n", 56 __FUNCTION__, 57 attr); 58 59 this->info.errno = EFAULT; 60 return (int)VM_FAILED; 61 } 62 63 if((attr.flags & VM_REG_HEAP) || 64 ((attr.flags & VM_REG_PVSH) == VM_REG_PVSH) || 65 ((attr.flags & VM_REG_PVSH) == 0) || 66 (attr.length == 0) || 67 (attr.offset & PMM_PAGE_MASK) || 68 ((attr.addr != NULL) && (((uint_t)attr.addr & PMM_PAGE_MASK) || 69 (NOT_IN_USPACE(attr.length + (uint_t)attr.addr)) || 70 (NOT_IN_USPACE((uint_t)attr.addr)) ))) 71 { 72 printk(INFO, "%s: failed, we don't like flags (%x), length (%d), or addr (%x)\n", 73 __FUNCTION__, 74 attr.flags, 75 attr.length, 76 attr.addr); 77 78 this->info.errno = EINVAL; 79 return (int)VM_FAILED; 80 } 81 82 if(attr.flags & VM_REG_ANON) 83 { 84 attr.offset = 0; 85 attr.addr = (attr.flags & VM_REG_FIXED) ? attr.addr : NULL; 86 } 87 else 88 { 89 // FIXME: possible concurent delete of file from another bugy thread closing it 90 if((attr.fd >= CONFIG_TASK_FILE_MAX_NR) || (process_fd_lookup(process, attr.fd, &file))) 91 { 92 printk(INFO, "%s: failed, bad file descriptor (%d)\n", 93 __FUNCTION__, 94 attr.fd); 95 96 this->info.errno = EBADFD; 97 return (int)VM_FAILED; 98 } 99 100 //atomic_add(&file->f_count, 1); 101 vfs_file_up(file);//FIXME coalsce access to remote node info 102 103 //FIXME: does we really to get the size... 104 isize = vfs_inode_size_get_remote(file->f_inode.ptr, file->f_inode.cid); 105 if((attr.offset + attr.length) > isize) 106 { 107 printk(INFO, "%s: failed, offset (%d) + len (%d) >= file's size (%d)\n", 108 __FUNCTION__, 109 attr.offset, 110 attr.length, 111 isize); 112 113 this->info.errno = ERANGE; 114 goto SYS_MMAP_FILE_ERR; 115 } 116 117 if(((attr.prot & VM_REG_RD) && !(VFS_IS(file->f_flags, VFS_O_RDONLY))) || 118 ((attr.prot & VM_REG_WR) && !(VFS_IS(file->f_flags, VFS_O_WRONLY))) || 119 ((attr.prot & VM_REG_WR) && (VFS_IS(file->f_flags, VFS_O_APPEND))))// || 120 //(!(attr.prot & VM_REG_RD) && (attr.flags & VM_REG_PRIVATE))) 121 { 122 printk(INFO, "%s: failed, EACCES prot (%x), f_flags (%x)\n", 123 __FUNCTION__, 124 attr.prot, 125 file->f_flags); 126 127 this->info.errno = EACCES; 128 goto SYS_MMAP_FILE_ERR; 129 } 130 } 131 132 retval = (int) vmm_mmap(process, 133 file, 134 attr.addr, 135 attr.length, 136 attr.prot, 137 attr.flags, 138 attr.offset); 139 140 if((retval != (int)VM_FAILED) || (attr.flags & VM_REG_ANON)) 141 return retval; 142 143 SYS_MMAP_FILE_ERR: 144 printk(INFO, "%s: Failed, Droping file count \n", 145 __FUNCTION__); 146 147 vfs_close( file , &count ); 148 149 if(count == 1) process_fd_put( process , attr.fd ); 150 151 return (int)VM_FAILED; 152 */ 178 if( cluster_is_undefined( vseg_cxy ) ) 179 { 180 printk("\n[ERROR] in %s : illegal cxy for MAP_REMOTE\n", __FUNCTION__ ); 181 this->errno = EINVAL; 182 return -1; 183 } 184 } 185 } 186 187 // get reference process cluster and local pointer 188 xptr_t ref_xp = process->ref_xp; 189 cxy_t ref_cxy = GET_CXY( ref_xp ); 190 process_t * ref_ptr = (process_t *)GET_PTR( ref_xp ); 191 192 // create the vseg in reference cluster 193 if( local_cxy == ref_cxy ) 194 { 195 vseg = vmm_create_vseg( process, 196 vseg_type, 197 0, // base address unused for mmap() 198 length, 199 offset, 200 0, // file_size unused for mmap() 201 mapper_xp, 202 vseg_cxy ); 203 } 204 else 205 { 206 rpc_vmm_create_vseg_client( ref_cxy, 207 ref_ptr, 208 vseg_type, 209 0, // base address unused for mmap() 210 length, 211 offset, 212 0, // file size unused for mmap() 213 mapper_xp, 214 vseg_cxy, 215 &vseg ); 216 } 217 218 if( vseg == NULL ) 219 { 220 printk("\n[ERROR] in %s : cannot create vseg\n", __FUNCTION__ ); 221 this->errno = ENOMEM; 222 return -1; 223 } 224 225 // copy vseg base address to user space 226 hal_copy_to_uspace( &attr->addr , &vseg->min , sizeof(intptr_t) ); 227 228 tm_end = hal_get_cycles(); 229 230 syscall_dmsg("\n[DBG] %s : core[%x,%d] created vseg %s in cluster %x / cycle %d\n" 231 " base = %x / length = %x / cost = %d\n", 232 __FUNCTION__, local_cxy , this->core->lid , vseg_type_str(vseg->type) , 233 vseg->cxy , (uint32_t)tm_start , vseg->min , length , (uint32_t)(tm_end - tm_start) ); 234 235 return 0; 236 153 237 } // end sys_mmap() 238 -
trunk/kernel/syscalls/sys_open.c
r305 r407 55 55 } 56 56 57 // get pathname copy in kernel space 58 error = hal_strcpy_from_uspace( kbuf , pathname , CONFIG_VFS_MAX_PATH_LENGTH ); 59 60 if( error ) 57 // check pathname length 58 if( hal_strlen_from_uspace( pathname ) >= CONFIG_VFS_MAX_PATH_LENGTH ) 61 59 { 62 60 printk("\n[ERROR] in %s : pathname too long\n", __FUNCTION__ ); … … 65 63 } 66 64 65 // copy pathname in kernel space 66 hal_strcpy_from_uspace( kbuf , pathname , CONFIG_VFS_MAX_PATH_LENGTH ); 67 67 68 // get cluster and local pointer on reference process 68 69 xptr_t ref_xp = process->ref_xp; … … 70 71 cxy_t ref_cxy = GET_CXY( ref_xp ); 71 72 72 // get extended pointer on cwd inode73 xptr_t cwd_xp = hal_remote_lwd( XPTR( ref_cxy , &ref_ptr->vfs_cwd_xp ) );74 75 73 // get the cwd lock in read mode from reference process 76 74 remote_rwlock_rd_lock( XPTR( ref_cxy , &ref_ptr->cwd_lock ) ); 77 75 78 76 // call the relevant VFS function 79 error = vfs_open( cwd_xp,77 error = vfs_open( process, 80 78 kbuf, 81 79 flags, -
trunk/kernel/syscalls/sys_opendir.c
r23 r407 23 23 24 24 #include <hal_types.h> 25 #include <thread.h> 26 #include <process.h> 27 #include <printk.h> 28 #include <errno.h> 25 29 #include <vfs.h> 26 30 #include <syscalls.h> 31 #include <shared_syscalls.h> 27 32 28 33 /////////////////////////////////// 29 int sys_opendir ( char * pathname ) 34 int sys_opendir ( char * pathname, 35 DIR ** dirp ) 30 36 { 31 uint32_t mode = 0; 32 uint32_t flags = O_DIR; 33 34 return sys_open( pathname , flags , mode ); 35 } 37 printk("\n[ERROR] in %s : not implemented yet\n", __FUNCTION__ ); 38 CURRENT_THREAD->errno = ENOMEM; 39 return -1; 40 } // end sys opendir() -
trunk/kernel/syscalls/sys_pipe.c
r23 r407 36 36 this->errno = ENOSYS; 37 37 return -1; 38 39 38 } -
trunk/kernel/syscalls/sys_read.c
r313 r407 33 33 #include <process.h> 34 34 35 /* TODO: user page(s) need to be locked [AG] */ 35 // TODO: concurrent user page(s) munmap need to be handled [AG] 36 37 // instrumentation 38 extern uint32_t enter_sys_read; 39 extern uint32_t enter_devfs_move; 40 extern uint32_t enter_txt_read; 41 extern uint32_t enter_chdev_cmd; 42 extern uint32_t enter_chdev_server; 43 extern uint32_t enter_tty_cmd; 44 extern uint32_t enter_tty_isr; 45 extern uint32_t exit_tty_isr; 46 extern uint32_t exit_tty_cmd; 47 extern uint32_t exit_chdev_server; 48 extern uint32_t exit_chdev_cmd; 49 extern uint32_t exit_txt_read; 50 extern uint32_t exit_devfs_move; 51 extern uint32_t exit_sys_read; 52 36 53 37 54 ///////////////////////////////// 38 55 int sys_read( uint32_t file_id, 39 void * buf,56 void * vaddr, 40 57 uint32_t count ) 41 58 { … … 43 60 paddr_t paddr; // required for user space checking 44 61 xptr_t file_xp; // remote file extended pointer 62 uint32_t nbytes; // number of bytes actually read 63 64 uint32_t tm_start; 65 uint32_t tm_end; 66 67 tm_start = hal_get_cycles(); 68 69 #if CONFIG_READ_START 70 enter_sys_read = tm_start; 71 #endif 45 72 46 73 thread_t * this = CURRENT_THREAD; … … 51 78 { 52 79 printk("\n[ERROR] in %s : illegal file descriptor index = %d\n", 53 80 __FUNCTION__ , file_id ); 54 81 this->errno = EBADFD; 55 82 return -1; … … 57 84 58 85 // check user buffer in user space 59 error = vmm_v2p_translate( false , buf, &paddr );86 error = vmm_v2p_translate( false , vaddr , &paddr ); 60 87 61 88 if ( error ) 62 89 { 63 90 printk("\n[ERROR] in %s : user buffer unmapped = %x\n", 64 __FUNCTION__ , (intptr_t)buf);91 __FUNCTION__ , (intptr_t)vaddr ); 65 92 this->errno = EINVAL; 66 93 return -1; … … 72 99 if( file_xp == XPTR_NULL ) 73 100 { 74 printk("\n[ERROR] in %s : undefined file descriptor index = %d \n",75 __FUNCTION__ , file_id );101 printk("\n[ERROR] in %s : undefined file descriptor index = %d in process %x\n", 102 __FUNCTION__ , file_id , process->pid ); 76 103 this->errno = EBADFD; 77 104 return -1; … … 86 113 if( (attr & FD_ATTR_READ_ENABLE) == 0 ) 87 114 { 88 printk("\n[ERROR] in %s : file %d not readable \n",89 __FUNCTION__ , file_id );115 printk("\n[ERROR] in %s : file %d not readable in process %x\n", 116 __FUNCTION__ , file_id , process->pid ); 90 117 this->errno = EBADFD; 91 118 return -1; 92 119 } 93 120 94 // transfer count bytes directly from mapper to user buffer 95 error = vfs_user_move( true, // to_buffer 96 file_xp , 97 buf, 98 count ); 121 // get file type 122 vfs_inode_type_t type = hal_remote_lw( XPTR( file_cxy , &file_ptr->type ) ); 99 123 100 if( error ) 124 // action depend on file type 125 if( type == INODE_TYPE_FILE ) // transfer count bytes from file mapper 101 126 { 102 printk("\n[ERROR] in %s cannot read data from file %d\n", 103 __FUNCTION__ , file_id ); 127 nbytes = vfs_user_move( true, // from mapper to buffer 128 file_xp, 129 vaddr, 130 count ); 131 } 132 else if( type == INODE_TYPE_DEV ) // transfer count bytes from device 133 { 134 nbytes = devfs_user_move( true, // from device to buffer 135 file_xp, 136 vaddr, 137 count ); 138 } 139 else 140 { 141 nbytes = 0; 142 panic("file type %d non supported yet", type ); 143 } 144 145 if( nbytes != count ) 146 { 147 printk("\n[ERROR] in %s cannot read data from file %d in process %x\n", 148 __FUNCTION__ , file_id , process->pid ); 104 149 this->errno = error; 105 150 return -1; … … 108 153 hal_fence(); 109 154 110 return 0; 155 tm_end = hal_get_cycles(); 156 157 #if CONFIG_READ_DEBUG 158 exit_sys_read = tm_end; 159 160 printk("\n@@@@@@@@@@@@ timing ro read character %c\n" 161 " - enter_sys_read = %d / delta %d\n" 162 " - enter_devfs_move = %d / delta %d\n" 163 " - enter_txt_read = %d / delta %d\n" 164 " - enter_chdev_cmd = %d / delta %d\n" 165 " - enter_chdev_server = %d / delta %d\n" 166 " - enter_tty_cmd = %d / delta %d\n" 167 " - enter_tty_isr = %d / delta %d\n" 168 " - exit_tty_isr = %d / delta %d\n" 169 " - exit_tty_cmd = %d / delta %d\n" 170 " - exit_chdev_server = %d / delta %d\n" 171 " - exit_chdev_cmd = %d / delta %d\n" 172 " - exit_txt_read = %d / delta %d\n" 173 " - exit_devfs_move = %d / delta %d\n" 174 " - exit_sys_read = %d / delta %d\n", 175 *((char *)(intptr_t)paddr) , 176 enter_sys_read , 0 , 177 enter_devfs_move , enter_devfs_move - enter_sys_read , 178 enter_txt_read , enter_txt_read - enter_devfs_move , 179 enter_chdev_cmd , enter_chdev_cmd - enter_txt_read , 180 enter_chdev_server , enter_chdev_server - enter_chdev_cmd , 181 enter_tty_cmd , enter_tty_cmd - enter_chdev_server , 182 enter_tty_isr , enter_tty_isr - enter_tty_cmd , 183 exit_tty_isr , exit_tty_isr - enter_tty_isr , 184 exit_tty_cmd , exit_tty_cmd - exit_tty_isr , 185 exit_chdev_server , exit_chdev_server - exit_tty_cmd , 186 exit_chdev_cmd , exit_chdev_cmd - exit_chdev_server , 187 exit_txt_read , exit_txt_read - exit_chdev_cmd , 188 exit_devfs_move , exit_devfs_move - exit_txt_read , 189 exit_sys_read , exit_sys_read - exit_devfs_move ); 190 #endif 191 192 syscall_dmsg("\n[DBG] %s : core[%x,%d] / thread %x / nbytes = %d / cycle %d\n" 193 " first byte = %c / file_id = %d / cost = %d\n", 194 __FUNCTION__ , local_cxy , this->core->lid , this->trdid , nbytes , tm_start , 195 *((char *)(intptr_t)paddr) , file_id , tm_end - tm_start ); 196 197 return nbytes; 111 198 112 199 } // end sys_read() -
trunk/kernel/syscalls/sys_readdir.c
r23 r407 31 31 #include <process.h> 32 32 #include <syscalls.h> 33 #include <shared_syscalls.h> 33 34 34 /////////////////////////////////////// ///35 int sys_readdir ( uint32_t file_id,36 vfs_dirent_t * dirent)35 /////////////////////////////////////// 36 int sys_readdir( DIR * dirp, 37 struct dirent ** dentp ) 37 38 { 38 error_t error; 39 paddr_t paddr; 40 xptr_t file_xp; // extended pointer on searched directory file descriptor 41 vfs_dirent_t k_dirent; // kernel copy of dirent 42 43 thread_t * this = CURRENT_THREAD; 44 process_t * process = this->process; 45 46 // check file_id argument 47 if( file_id >= CONFIG_PROCESS_FILE_MAX_NR ) 48 { 49 printk("\n[ERROR] in %s : illegal file descriptor index\n", __FUNCTION__ ); 50 this->errno = EBADFD; 51 return -1; 52 } 53 54 // check dirent structure in user space 55 error = vmm_v2p_translate( false , dirent , &paddr ); 56 57 if ( error ) 58 { 59 printk("\n[ERROR] in %s : user buffer for dirent unmapped = %x\n", 60 __FUNCTION__ , (intptr_t)dirent ); 61 this->errno = EFAULT; 62 return -1; 63 } 64 65 // get extended pointer on remote file descriptor 66 file_xp = process_fd_get_xptr( process , file_id ); 67 68 if( file_xp == XPTR_NULL ) 69 { 70 printk("\n[ERROR] in %s : undefined file descriptor index = %d\n", 71 __FUNCTION__ , file_id ); 72 this->errno = EBADFD; 73 return -1; 74 } 75 76 // call the relevant VFS function 77 error = vfs_readdir( file_xp , &k_dirent ); 78 79 if( error ) 80 { 81 printk("\n[ERROR] in %s : cannot access directory %d\n", 82 __FUNCTION__ , file_id ); 83 this->errno = error; 84 return -1; 85 } 86 87 // copy dirent to user space 88 hal_copy_to_uspace( dirent , &k_dirent , sizeof(vfs_dirent_t) ); 89 90 return 0; 91 39 printk("\n[ERROR] in %s : not implemented yet\n", __FUNCTION__ ); 40 CURRENT_THREAD->errno = ENOMEM; 41 return -1; 92 42 } // end sys_readdir() -
trunk/kernel/syscalls/sys_rmdir.c
r305 r407 40 40 process_t * process = this->process; 41 41 42 // get pathname copy in kernel space 43 error = hal_strcpy_from_uspace( kbuf , pathname , CONFIG_VFS_MAX_PATH_LENGTH ); 44 45 if( error ) 42 // check pathname length 43 if( hal_strlen_from_uspace( pathname ) >= CONFIG_VFS_MAX_PATH_LENGTH ) 46 44 { 47 45 printk("\n[ERROR] in %s : pathname too long\n", __FUNCTION__ ); 48 46 this->errno = ENFILE; 49 47 return -1; 50 48 } 49 50 // copy pathname in kernel space 51 hal_strcpy_from_uspace( kbuf , pathname , CONFIG_VFS_MAX_PATH_LENGTH ); 51 52 52 53 // get cluster and local pointer on reference process -
trunk/kernel/syscalls/sys_signal.c
r406 r407 45 45 this->process->sig_mgr.sigactions[sig_id] = handler; 46 46 47 signal_dmsg("\n[D MSG] %s : handler @%x has been registred for signal %d\n",47 signal_dmsg("\n[DBG] %s : handler @%x has been registred for signal %d\n", 48 48 __FUNCTION__ , handler , sig_id ); 49 49 -
trunk/kernel/syscalls/sys_stat.c
r124 r407 32 32 #include <process.h> 33 33 34 ///////////////////////////////////// /////35 int sys_stat( uint32_t file_id,36 struct vfs_stat_s *stat )34 ///////////////////////////////////// 35 int sys_stat( char * pathname, 36 struct stat * u_stat ) 37 37 { 38 error_t error; 39 paddr_t paddr; 40 struct vfs_stat_s k_stat; 41 xptr_t file_xp; 38 error_t error; 39 paddr_t paddr; 40 struct stat k_stat; // kernel space 41 xptr_t file_xp; 42 char kbuf[CONFIG_VFS_MAX_PATH_LENGTH]; 42 43 43 44 thread_t * this = CURRENT_THREAD; … … 45 46 46 47 // check stat structure in user space 47 error = vmm_v2p_translate( false , stat , &paddr );48 error = vmm_v2p_translate( false , u_stat , &paddr ); 48 49 49 50 if( error ) … … 55 56 } 56 57 57 // get extended pointer on remote file descriptor 58 file_xp = process_fd_get_xptr( process , file_id ); 59 60 if( file_xp == XPTR_NULL ) 58 // check pathname length 59 if( hal_strlen_from_uspace( pathname ) >= CONFIG_VFS_MAX_PATH_LENGTH ) 61 60 { 62 printk("\n[ERROR] in %s : undefined file descriptor for thread %x in process %x\n", 63 __FUNCTION__ , this->trdid , process->pid ); 64 this->errno = EBADFD; 61 printk("\n[ERROR] in %s : pathname too long\n", __FUNCTION__ ); 62 this->errno = ENFILE; 65 63 return -1; 66 64 } 67 65 68 // call the relevant VFS function 66 // copy pathname in kernel space 67 hal_strcpy_from_uspace( kbuf , pathname , CONFIG_VFS_MAX_PATH_LENGTH ); 68 69 // get cluster and local pointer on reference process 70 xptr_t ref_xp = process->ref_xp; 71 process_t * ref_ptr = (process_t *)GET_PTR( ref_xp ); 72 cxy_t ref_cxy = GET_CXY( ref_xp ); 73 74 // get extended pointer on cwd inode 75 xptr_t cwd_xp = hal_remote_lwd( XPTR( ref_cxy , &ref_ptr->vfs_cwd_xp ) ); 76 77 // get the cwd lock in read mode from reference process 78 remote_rwlock_rd_lock( XPTR( ref_cxy , &ref_ptr->cwd_lock ) ); 79 80 // get extended pointer on remote file descriptor 81 error = vfs_lookup( cwd_xp, 82 pathname, 83 0, 84 &file_xp ); 85 86 // release the cwd lock 87 remote_rwlock_rd_unlock( XPTR( ref_cxy , &ref_ptr->cwd_lock ) ); 88 89 if( error ) 90 { 91 printk("\n[ERROR] in %s : cannot found file <%s> for thread %x in process %x\n", 92 __FUNCTION__ , pathname , this->trdid , process->pid ); 93 this->errno = error; 94 return -1; 95 } 96 97 // call VFS function to get stat info 69 98 error = vfs_stat( file_xp, 70 99 &k_stat ); 71 100 if( error ) 72 101 { 73 printk("\n[ERROR] in %s : cannot access file %d for thread %x in process %x\n",74 __FUNCTION__ , file_id , this->trdid , process->pid);102 printk("\n[ERROR] in %s : cannot get stats for file %s\n", 103 __FUNCTION__ , pathname ); 75 104 this->errno = error; 76 105 return -1; 77 106 } 78 107 79 // copy stat to user space80 hal_copy_to_uspace( stat , &k_stat , sizeof(struct vfs_stat_s) );108 // copy k_stat to u_stat 109 hal_copy_to_uspace( u_stat , &k_stat , sizeof(struct stat) ); 81 110 82 111 hal_fence(); -
trunk/kernel/syscalls/sys_thread_create.c
r406 r407 40 40 41 41 42 ////////////////////////////////////////////////////////////////////////////////////////// 43 // This function implements the pthread_create system call 44 ////////////////////////////////////////////////////////////////////////////////////////// 45 int sys_thread_create ( thread_t * new_thread, // [out] argument 46 pthread_attr_t * user_attr, // [in] argument 47 void * start_func, // [in] argument 48 void * start_arg ) // [in] argument 42 /////////////////////////////////////////////////// 43 int sys_thread_create ( pthread_t * trdid_ptr, 44 pthread_attr_t * user_attr, 45 void * start_func, 46 void * start_arg ) 49 47 { 50 pthread_attr_t k _attr;// copy of pthread attributes in kernel space48 pthread_attr_t kern_attr; // copy of pthread attributes in kernel space 51 49 thread_t * parent; // pointer on thread executing the pthread_create 52 50 xptr_t parent_xp; // extended pointer on created thread … … 56 54 process_t * process; // pointer on local process descriptor 57 55 paddr_t paddr; // unused, required by vmm_v2p_translate() 56 cxy_t target_cxy; // target cluster identifier 58 57 error_t error; 59 58 … … 63 62 tm_start = hal_get_cycles(); 64 63 65 // get parent thead pointer, extended pointer, and process pointer64 // get parent thead pointer, extended pointer, and process 66 65 parent = CURRENT_THREAD; 67 66 parent_xp = XPTR( local_cxy , parent ); 68 67 process = parent->process; 69 68 70 // check user_attr in user space 71 error = vmm_v2p_translate( false , user_attr , &paddr ); 69 // check user_attr in user space & copy to kernel space 70 if( user_attr != NULL ) 71 { 72 error = vmm_v2p_translate( false , user_attr , &paddr ); 72 73 73 if( error ) 74 { 75 printk("\n[ERROR] in %s : user_attr unmapped\n", __FUNCTION__ ); 76 parent->errno = EINVAL; 77 return -1; 78 } 74 if( error ) 75 { 76 printk("\n[ERROR] in %s : user_attr unmapped\n", __FUNCTION__ ); 77 parent->errno = EINVAL; 78 return -1; 79 } 80 81 hal_copy_from_uspace( &kern_attr , user_attr , sizeof(pthread_attr_t) ); 82 } 79 83 80 84 // check start_func in user space … … 98 102 } 99 103 100 // copy user_attr structure from user space to kernel space 101 hal_copy_from_uspace( &k_attr , user_attr , sizeof(pthread_attr_t) ); 102 103 // check/set "cxy" attribute 104 if( k_attr.attributes & PT_ATTR_CLUSTER_DEFINED ) 104 // check / define attributes an target_cxy 105 if( user_attr != NULL ) // user defined attributes 106 { 107 // check / get target_cxy 108 if( kern_attr.attributes & PT_ATTR_CLUSTER_DEFINED ) 109 { 110 if( cluster_is_undefined( kern_attr.cxy ) ) 111 { 112 printk("\n[ERROR] in %s : illegal target cluster = %x\n", 113 __FUNCTION__ , kern_attr.cxy ); 114 parent->errno = EINVAL; 115 return -1; 116 } 117 target_cxy = kern_attr.cxy; 118 } 119 else 120 { 121 target_cxy = dqdt_get_cluster_for_process(); 122 } 123 } 124 else // set default attributes 105 125 { 106 if( cluster_is_undefined( k_attr.cxy ) ) 107 { 108 printk("\n[ERROR] in %s : illegal target cluster attribute = %x\n", 109 __FUNCTION__ , k_attr.cxy ); 110 parent->errno = EINVAL; 111 return -1; 112 } 113 } 114 else 115 { 116 k_attr.cxy = dqdt_get_cluster_for_process(); 126 kern_attr.attributes = PT_ATTR_DETACH | PT_ATTR_CLUSTER_DEFINED; 127 target_cxy = dqdt_get_cluster_for_process(); 117 128 } 118 129 119 130 // create the thread, using a RPC if required 120 // this returns "error", "child ", and "child_xp"131 // this returns "error", "child_ptr", and "child_xp" 121 132 122 if( k_attr.cxy == local_cxy ) // target cluster is local133 if( target_cxy == local_cxy ) // target cluster is local 123 134 { 124 135 // create thread in local cluster … … 126 137 start_func, 127 138 start_arg, 128 &k _attr,139 &kern_attr, 129 140 &child_ptr ); 130 141 … … 133 144 else // target cluster is remote 134 145 { 135 rpc_thread_user_create_client( k_attr.cxy,146 rpc_thread_user_create_client( target_cxy, 136 147 process->pid, 137 148 start_func, 138 149 start_arg, 139 &k _attr,150 &kern_attr, 140 151 &child_xp, 141 152 &error ); … … 152 163 153 164 // returns trdid to user space 154 trdid = hal_remote_lw( XPTR( k_attr.cxy , &child_ptr->trdid ) );155 hal_copy_to_uspace( new_thread, &trdid , sizeof(pthread_t) );165 trdid = hal_remote_lw( XPTR( target_cxy , &child_ptr->trdid ) ); 166 hal_copy_to_uspace( trdid_ptr , &trdid , sizeof(pthread_t) ); 156 167 157 // register new-thread in parent-thread children list if required 158 if( (k_attr.attributes & PT_ATTR_DETACH) == 0 ) 159 thread_child_parent_link( parent_xp , child_xp ); 168 // register child in parent if required 169 if( user_attr != NULL ) 170 { 171 if( (kern_attr.attributes & PT_ATTR_DETACH) == 0 ) 172 thread_child_parent_link( parent_xp , child_xp ); 173 } 174 175 // activate new thread 176 thread_unblock( child_xp , THREAD_BLOCKED_GLOBAL ); 177 178 hal_fence(); 160 179 161 180 tm_end = hal_get_cycles(); 162 181 163 thread_dmsg("\n[DMSG] %s created thread %x for process %x in cluster %x\n" 164 " start_cycle = %d / end_cycle = %d\n", 165 trdid , process->pid , k_attr.cxy , tm_start , tm_end ); 182 syscall_dmsg("\n[DBG] %s : core[%x,%d] created thread %x for process %x / cycle %d\n" 183 " cluster %x / cost = %d cycles\n", 184 __FUNCTION__ , local_cxy , parent->core->lid , trdid , process->pid , tm_end , 185 target_cxy , tm_end - tm_start ); 186 166 187 return 0; 167 }168 188 189 } // end sys_thread_create() 190 -
trunk/kernel/syscalls/sys_thread_exit.c
r296 r407 38 38 reg_t irq_state; 39 39 40 // register the exit_value in thread descriptor40 // register the exit_value pointer in thread descriptor 41 41 this->exit_value = exit_value; 42 42 43 // we enter the join loop to wait the join 44 // only if thread is joinable 43 // enter the join loop to wait the join if thread is joinable 45 44 if( (this->flags & THREAD_FLAG_DETACHED) == 0 ) 46 45 { … … 74 73 75 74 // deschedule 76 sched_yield( NULL);75 sched_yield(); 77 76 } 78 77 } -
trunk/kernel/syscalls/sys_thread_join.c
r296 r407 138 138 139 139 // deschedule 140 sched_yield( NULL);140 sched_yield(); 141 141 } 142 142 } -
trunk/kernel/syscalls/sys_thread_sleep.c
r406 r407 32 32 thread_t * this = CURRENT_THREAD; 33 33 34 thread_dmsg("\n[D MSG] %s : thread %x in process %x goes to sleep at cycle %d\n",34 thread_dmsg("\n[DBG] %s : thread %x in process %x goes to sleep at cycle %d\n", 35 35 __FUNCTION__, this->trdid, this->process->pid, hal_get_cycles() ); 36 36 37 37 thread_block( this , THREAD_BLOCKED_GLOBAL ); 38 sched_yield( NULL);38 sched_yield(); 39 39 40 thread_dmsg("\n[D MSG] %s : thread %x in process %x resume at cycle\n",40 thread_dmsg("\n[DBG] %s : thread %x in process %x resume at cycle\n", 41 41 __FUNCTION__, this->trdid, this->process->pid, hal_get_cycles() ); 42 42 -
trunk/kernel/syscalls/sys_thread_yield.c
r296 r407 27 27 int sys_thread_yield() 28 28 { 29 sched_yield( NULL);29 sched_yield(); 30 30 return 0; 31 31 } -
trunk/kernel/syscalls/sys_timeofday.c
r124 r407 30 30 #include <vmm.h> 31 31 #include <core.h> 32 #include < time.h>32 #include <shared_syscalls.h> 33 33 34 34 //////////////////////////////////////// -
trunk/kernel/syscalls/sys_trace.c
r406 r407 49 49 // desactivate thread trace TODO 50 50 51 printk("\n[D MSG] %s : trace OFF for thread %x in process %x\n",51 printk("\n[DBG] %s : trace OFF for thread %x in process %x\n", 52 52 __FUNCTION__ , trdid , pid ); 53 53 } … … 56 56 // activate thread trace TODO 57 57 58 printk("\n[D MSG] %s : trace ON for thread %x in process %x\n",58 printk("\n[DBG] %s : trace ON for thread %x in process %x\n", 59 59 __FUNCTION__ , trdid , pid ); 60 60 } -
trunk/kernel/syscalls/sys_unlink.c
r305 r407 37 37 process_t * process = this->process; 38 38 39 // get pathname copy in kernel space 40 error = hal_strcpy_from_uspace( kbuf , pathname , CONFIG_VFS_MAX_PATH_LENGTH ); 41 42 if( error ) 39 // check pathname length 40 if( hal_strlen_from_uspace( pathname ) >= CONFIG_VFS_MAX_PATH_LENGTH ) 43 41 { 44 42 printk("\n[ERROR] in %s : pathname too long\n", __FUNCTION__ ); … … 46 44 return -1; 47 45 } 46 47 // copy pathname in kernel space 48 hal_strcpy_from_uspace( kbuf , pathname , CONFIG_VFS_MAX_PATH_LENGTH ); 48 49 49 50 // get cluster and local pointer on reference process -
trunk/kernel/syscalls/sys_write.c
r315 r407 32 32 #include <process.h> 33 33 34 /* TODO: user page(s) need to be locked[AG] */34 /* TODO: concurrent user page(s) unmap need to be handled [AG] */ 35 35 36 36 ////////////////////////////////// 37 37 int sys_write( uint32_t file_id, 38 void * buf,38 void * vaddr, 39 39 uint32_t count ) 40 40 { 41 41 error_t error; 42 paddr_t paddr; // required for user space checking42 paddr_t paddr; // unused, but required for user space checking 43 43 xptr_t file_xp; // remote file extended pointer 44 uint32_t nbytes; // number of bytes actually written 45 46 uint32_t tm_start; 47 uint32_t tm_end; 48 49 tm_start = hal_get_cycles(); 44 50 45 51 thread_t * this = CURRENT_THREAD; … … 55 61 56 62 // check user buffer in user space 57 error = vmm_v2p_translate( false , buf, &paddr );63 error = vmm_v2p_translate( false , vaddr , &paddr ); 58 64 59 65 if ( error ) 60 66 { 61 67 printk("\n[ERROR] in %s : user buffer unmapped = %x\n", 62 __FUNCTION__ , (intptr_t)buf);68 __FUNCTION__ , (intptr_t)vaddr ); 63 69 this->errno = EINVAL; 64 70 return -1; … … 70 76 if( file_xp == XPTR_NULL ) 71 77 { 72 printk("\n[ERROR] in %s : undefined file descriptor index = %d \n",73 __FUNCTION__ , file_id );78 printk("\n[ERROR] in %s : undefined file descriptor index = %d in process %x\n", 79 __FUNCTION__ , file_id , process->pid ); 74 80 this->errno = EBADFD; 75 81 return -1; … … 84 90 if( (attr & FD_ATTR_WRITE_ENABLE) == 0 ) 85 91 { 86 printk("\n[ERROR] in %s : file %d not writable \n",87 __FUNCTION__ , file_id );92 printk("\n[ERROR] in %s : file %d not writable in process %x\n", 93 __FUNCTION__ , file_id , process->pid ); 88 94 this->errno = EBADFD; 89 95 return -1; 90 96 } 91 97 92 // transfer count bytes directly from user buffer to mapper 93 error = vfs_user_move( false, // from buffer 94 file_xp, 95 buf , 96 count ); 98 // get file type 99 vfs_inode_type_t type = hal_remote_lw( XPTR( file_cxy , &file_ptr->type ) ); 97 100 98 if( error ) 101 // action depend on file type 102 if( type == INODE_TYPE_FILE ) // transfer count bytes to file mapper 99 103 { 100 printk("\n[ERROR] in %s cannot read data from file %d\n", 101 __FUNCTION__ , file_id ); 104 nbytes = vfs_user_move( false, // from buffer to mapper 105 file_xp, 106 vaddr, 107 count ); 108 } 109 else if( type == INODE_TYPE_DEV ) // transfer count bytes to device 110 { 111 nbytes = devfs_user_move( false, // from buffer to device 112 file_xp, 113 vaddr, 114 count ); 115 } 116 else 117 { 118 nbytes = 0; 119 panic("file type %d non supported", type ); 120 } 121 122 if( nbytes != count ) 123 { 124 printk("\n[ERROR] in %s cannot write data to file %d in process %x\n", 125 __FUNCTION__ , file_id , process->pid ); 102 126 this->errno = error; 103 127 return -1; … … 106 130 hal_fence(); 107 131 108 return 0; 132 tm_end = hal_get_cycles(); 133 134 syscall_dmsg("\n[DBG] %s : core[%x,%d] / thread %x / nbytes = %d / cycle %d\n" 135 " first byte = %c / file_id = %d / cost = %d\n", 136 __FUNCTION__ , local_cxy , this->core->lid , this->trdid , nbytes , tm_start , 137 *((char *)(intptr_t)paddr) , file_id , tm_end - tm_start ); 138 139 return nbytes; 109 140 110 141 } // end sys_write() -
trunk/kernel/syscalls/syscalls.h
r279 r407 1 1 /* 2 * syscalls.h - kernel services definition2 * syscalls.h - Kernel side services for syscall handling. 3 3 * 4 4 * Author Alain Greiner (2016,2017) … … 26 26 27 27 #include <hal_types.h> 28 #include < time.h>29 30 /** ***Forward declarations *****/28 #include <shared_syscalls.h> 29 30 /** Forward declarations *****/ 31 31 32 32 struct thread_s; // defined in thread.h … … 36 36 struct mmap_attr_s; // defined in vmm.h 37 37 38 /****************************************************************************************** 39 * This enum defines the mnemonics for the syscall indexes. 40 * It must be kept consistent with the array defined in do_syscalls.c 41 *****************************************************************************************/ 42 enum 43 { 44 SYS_THREAD_EXIT = 0, 45 SYS_MMAP = 1, 46 SYS_THREAD_CREATE = 2, 47 SYS_THREAD_JOIN = 3, 48 SYS_THREAD_DETACH = 4, 49 SYS_THREAD_YIELD = 5, 50 SYS_SEM = 6, 51 SYS_CONDVAR = 7, 52 SYS_BARRIER = 8, 53 SYS_MUTEX = 9, 54 55 SYS_SLEEP = 10, 56 SYS_WAKEUP = 11, 57 SYS_OPEN = 12, 58 SYS_CREAT = 13, 59 SYS_READ = 14, 60 SYS_WRITE = 15, 61 SYS_LSEEK = 16, 62 SYS_CLOSE = 17, 63 SYS_UNLINK = 18, 64 SYS_PIPE = 19, 65 66 SYS_CHDIR = 20, 67 SYS_MKDIR = 21, 68 SYS_MKFIFO = 22, 69 SYS_OPENDIR = 23, 70 SYS_READDIR = 24, 71 SYS_CLOSEDIR = 25, 72 SYS_GETCWD = 26, 73 SYS_CLOCK = 27, 74 SYS_ALARM = 28, 75 SYS_RMDIR = 29, 76 77 SYS_UTLS = 30, 78 SYS_CHMOD = 31, 79 SYS_SIGNAL = 32, 80 SYS_TIMEOFDAY = 33, 81 SYS_KILL = 34, 82 SYS_GETPID = 35, 83 SYS_FORK = 36, 84 SYS_EXEC = 37, 85 SYS_STAT = 38, 86 SYS_TRACE = 39, 87 88 SYSCALLS_NR = 40, 89 }; 90 91 92 /********************************************************************************************/ 93 /******************** system calls ****************************************************/ 94 /********************************************************************************************/ 95 96 /********************************************************************************************* 97 * [0] This function terminates the execution of the calling user thread value, 38 /****************************************************************************************** 39 * [0] This function terminates the execution of the calling user thread, 98 40 * and makes the exit_value pointer available to any successful pthread_join() with the 99 41 * terminating thread. 100 ****************************************************************************************** ***101 * @ exit_vallue : [out] pointer to to the parrent thread ifattached.102 * @ return 0 if success / return -1 if failure. 103 ***************************************************************************************** ***/42 ****************************************************************************************** 43 * @ exit_vallue : pointer to be returned to parent thread if thead is attached. 44 * @ return 0 if success / return -1 if failure. 45 *****************************************************************************************/ 104 46 int sys_thread_exit( void * exit_value ); 105 47 106 /****************************************************************************************** ***107 * [1] This function map physical memory (or a file) in the calling thread virtual space.108 * The <attr> argument is a pointer on a structure containing arguments, defined in vmm.h.109 * TODO not implemented yet...110 * ********************************************************************************************111 * @ attr : pointer on attributes structure.112 * @ return 0 if success / return -1 if failure.113 ***************************************************************************************** ***/114 int sys_ mmap( struct mmap_attr_s * attr);115 116 /****************************************************************************************** ***48 /****************************************************************************************** 49 * [1] This function calls the scheduler for the core running the calling thread. 50 ****************************************************************************************** 51 * @ x_size : [out] number of clusters in a row. 52 * @ y_size : [out] number of clusters in a column. 53 * @ ncores : [out] number of cores per cluster. 54 * @ return always 0. 55 *****************************************************************************************/ 56 int sys_thread_yield(); 57 58 /****************************************************************************************** 117 59 * [2] This function creates a new user thread. The <user_attr> argument is a pointer 118 60 * on astructure containing the thread attributes, defined in thread.h file. 119 ****************************************************************************************** ***61 ****************************************************************************************** 120 62 * @ new_thread : [out] local pointer on created thread descriptor. 121 63 * @ user_attr : [in] pointer on thread attributes structure. … … 123 65 * @ start_args : [in] pointer on start function arguments. 124 66 * @ return 0 if success / return -1 if failure. 125 ***************************************************************************************** ***/67 *****************************************************************************************/ 126 68 int sys_thread_create( struct thread_s * new_thread, 127 69 struct pthread_attr_s * user_attr, … … 129 71 void * start_args ); 130 72 131 /****************************************************************************************** ***73 /****************************************************************************************** 132 74 * [3] This blocking function suspend execution of the calling thread until completion 133 75 * of another target thread identified by the <trdid> argument. 134 76 * If the <exit_value> argument is not NULL, the value passed to pthread_exit() by the 135 77 * target thread is stored in the location referenced by exit_value. 136 ****************************************************************************************** ***78 ****************************************************************************************** 137 79 * @ trdid : [in] target thread identifier. 138 80 * @ thread : [out] buffer for exit_value returned by target thread. 139 81 * @ return 0 if success / return -1 if failure. 140 ***************************************************************************************** ***/82 *****************************************************************************************/ 141 83 int sys_thread_join( trdid_t trdid, 142 84 void ** exit_value ); 143 85 144 /****************************************************************************************** ***86 /****************************************************************************************** 145 87 * [4] This function detach a joinable thread. 146 ****************************************************************************************** ***147 * @ trdid : thread identifier. 148 * @ return 0 if success / return -1 if failure. 149 ***************************************************************************************** ***/88 ****************************************************************************************** 89 * @ trdid : thread identifier.i 90 * @ return 0 if success / return -1 if failure. 91 *****************************************************************************************/ 150 92 int sys_thread_detach( trdid_t trdid ); 151 93 152 /********************************************************************************************* 153 * [5] This function calls the scheduler for the core running the calling thread. 154 ********************************************************************************************* 155 * @ return always 0. 156 ********************************************************************************************/ 157 int sys_thread_yield(); 158 159 /********************************************************************************************* 94 /****************************************************************************************** 95 * [5] This slot is not used. 96 *****************************************************************************************/ 97 98 /****************************************************************************************** 160 99 * [6] This function implement all operations on a POSIX unnamed semaphore, 161 100 * that can be shared by threads running in different clusters. 162 101 * The kernel structure representing a remote semaphore is in the remote_sem.h file, 163 102 * and the code implementing the operations is in the remore_sem.c file. 164 ****************************************************************************************** ***103 ****************************************************************************************** 165 104 * @ vaddr : semaphore virtual address in user space == identifier. 166 105 * @ operation : SEM_INIT / SEM_DESTROY / SEM_GETVALUE / SEM_POST / SEM_WAIT. 167 106 * @ value : pointer on in/out argument in user space. 168 107 * @ return 0 if success / return -1 if failure. 169 ***************************************************************************************** ***/108 *****************************************************************************************/ 170 109 int sys_sem( void * vaddr, 171 110 uint32_t operation, 172 111 uint32_t * value ); 173 112 174 typedef enum 175 { 176 SEM_INIT, 177 SEM_DESTROY, 178 SEM_GETVALUE, 179 SEM_WAIT, 180 SEM_POST, 181 } 182 sem_operation_t; 183 184 /********************************************************************************************* 113 /****************************************************************************************** 185 114 * [7] This function implement all operations on a POSIX condition variable. 186 115 * The kernel structure representing a cond_var is defined in the remote_cv.h file, 187 116 * The code implementing the operations is defined in the remote_cv.c file. 188 ****************************************************************************************** ***117 ****************************************************************************************** 189 118 * @ vaddr : condvar virtual address in user space == identifier. 190 119 * @ operation : operation type (see below). 191 120 * @ attr : mutex virtual address in user space == identifier. 192 121 * @ return 0 if success / return -1 if failure. 193 ***************************************************************************************** ***/122 *****************************************************************************************/ 194 123 int sys_condvar( void * condvar, 195 124 uint32_t operation, 196 125 void * mutex ); 197 126 198 typedef enum 199 { 200 CONDVAR_INIT, 201 CONDVAR_DESTROY, 202 CONDVAR_WAIT, 203 CONDVAR_SIGNAL, 204 CONDVAR_BROADCAST, 205 } 206 condvar_operation_t; 207 208 /********************************************************************************************* 127 /****************************************************************************************** 209 128 * [8] This function implement all operations on a POSIX barrier. 210 129 * The kernel structure representing a barrier is defined in the remote_barrier.h file. 211 130 * The code implementting the operations is defined in the remote_barrier.c file. 212 ****************************************************************************************** ***131 ****************************************************************************************** 213 132 * @ vaddr : barrier virtual address in user space == identifier. 214 133 * @ operation : BARRIER_INIT / BARRIER_DESTROY / BARRIER_WAIT. 215 134 * @ count : number of expected threads (only used by BARRIER_INIT operation). 216 135 * @ return 0 if success / return -1 if failure. 217 ***************************************************************************************** ***/136 *****************************************************************************************/ 218 137 int sys_barrier( void * vaddr, 219 138 uint32_t operation, 220 139 uint32_t count ); 221 140 222 typedef enum 223 { 224 BARRIER_INIT, 225 BARRIER_DESTROY, 226 BARRIER_WAIT, 227 } 228 barrier_operation_t; 229 230 /********************************************************************************************* 141 /****************************************************************************************** 231 142 * [9] This function implement all operations on a POSIX mutex. 232 143 * The kernel structure representing a barrier is defined in the remote_barrier.h file. 233 144 * The code implementting the operations is defined in the remote_barrier.c file. 234 ****************************************************************************************** ***145 ****************************************************************************************** 235 146 * @ vaddr : mutex virtual address in user space == identifier. 236 147 * @ operation : MUTEX_INIT / MUTEX_DESTROY / MUTEX_LOCK / MUTEX_UNLOCK 237 148 * @ attr : mutex attributes (non supported yet => must be 0). 238 149 * @ return 0 if success / return -1 if failure. 239 ***************************************************************************************** ***/150 *****************************************************************************************/ 240 151 int sys_mutex( void * vaddr, 241 152 uint32_t operation, 242 153 uint32_t count ); 243 154 244 typedef enum 245 { 246 MUTEX_INIT, 247 MUTEX_DESTROY, 248 MUTEX_LOCK, 249 MUTEX_UNLOCK, 250 } 251 mutex_operation_t; 252 253 /********************************************************************************************* 254 * [10] This function block the calling thread on the THREAD_BLOCKED_GLOBAL condition, 255 * and deschedule. 256 ********************************************************************************************* 257 * @ return 0 if success / returns -1 if failure. 258 ********************************************************************************************/ 259 int sys_thread_sleep(); 260 261 /********************************************************************************************* 262 * [11] This function unblock the thread identified by its <trdid> from the 263 * THREAD_BLOCKED_GLOBAL condition. 264 ********************************************************************************************* 265 * @ trdid : target thread identifier. 266 * @ return 0 if success / return -1 if failure. 267 ********************************************************************************************/ 268 int sys_thread_wakeup(); 269 270 /********************************************************************************************* 271 * [12] This function open or create a file. 272 ********************************************************************************************* 155 /****************************************************************************************** 156 * [10] This slot not allocated yet 157 ****************************************************************************************** 158 * @ return 0 if success / returns -1 if failure. 159 *****************************************************************************************/ 160 161 /****************************************************************************************** 162 * [11] This function rmove an existing mapping defined by the <addr> and <size> 163 * arguments in user space. 164 ****************************************************************************************** 165 * @ addr : base address in user space. 166 * # size : number of bytes. 167 * @ return 0 if success / return -1 if failure. 168 *****************************************************************************************/ 169 int sys_munmap( void * addr, 170 uint32_t size ); 171 172 /****************************************************************************************** 173 * [12] This function open or create an open file descriptor. 174 ****************************************************************************************** 273 175 * @ pathname : pathname (can be relative or absolute). 274 176 * @ flags : bit vector attributes (see below). 275 177 * @ mode : access rights. 276 178 * @ return file descriptor index in fd_array if success / return -1 if failure. 277 ***************************************************************************************** ***/179 *****************************************************************************************/ 278 180 int sys_open( char * pathname, 279 181 uint32_t flags, 280 182 uint32_t mode ); 281 183 282 typedef enum 283 { 284 O_RDONLY = 0x0010000, /*! open file in read-only mode */ 285 O_WRONLY = 0x0020000, /*! open file in write-only mode */ 286 O_RDWR = 0x0030000, /*! open file in read/write mode */ 287 O_NONBLOCK = 0x0040000, /*! do not block if data non available */ 288 O_APPEND = 0x0080000, /*! append on each write */ 289 O_CREAT = 0x0100000, /*! create file if it does not exist */ 290 O_TRUNC = 0x0200000, /*! file length is forced to 0 */ 291 O_EXCL = 0x0400000, /*! error if VFS_O_CREAT and file exist */ 292 O_SYNC = 0x0800000, /*! synchronize File System on each write */ 293 O_CLOEXEC = 0x1000000, /*! set the close-on-exec flag in file descriptor */ 294 O_DIR = 0x2000000, /*! new file descriptor is for a directory */ 295 } 296 open_attributes_t; 297 298 /********************************************************************************************* 299 * [13] This function creates a new file as specified by the arguments. 300 * This function is obsolete, you should use open() with 0_CREATE. 301 ********************************************************************************************* 302 * @ pathname : pathname (can be relative or absolute). 303 * @ mode : access rights. 304 ********************************************************************************************/ 305 int sys_creat( char * pathname, 306 uint32_t mode ); 307 308 /********************************************************************************************* 184 /****************************************************************************************** 185 * [13] This function map physical memory (or a file) in the calling thread virtual space. 186 * The <attr> argument is a pointer on a structure for arguments (see shared_syscalls.h). 187 ****************************************************************************************** 188 * @ attr : pointer on attributes structure. 189 * @ return 0 if success / return -1 if failure. 190 *****************************************************************************************/ 191 int sys_mmap( mmap_attr_t * attr ); 192 193 /****************************************************************************************** 309 194 * [14] This function read bytes from an open file identified by its file descriptor. 310 * Th isfile can be a regular file or character oriented device.311 ****************************************************************************************** ***195 * The file can be a regular file or character oriented device. 196 ****************************************************************************************** 312 197 * @ file_id : open file index in fd_array. 313 198 * @ buf : buffer virtual address in user space. 314 199 * @ count : number of bytes. 315 200 * @ return number of bytes actually read if success / returns -1 if failure. 316 ***************************************************************************************** ***/201 *****************************************************************************************/ 317 202 int sys_read( uint32_t file_id, 318 203 void * buf, 319 204 uint32_t count ); 320 205 321 /****************************************************************************************** ***206 /****************************************************************************************** 322 207 * [15] This function writes bytes to an open file identified by its file descriptor. 323 * Th isfile can be a regular file or character oriented device.324 ****************************************************************************************** ***208 * The file can be a regular file or character oriented device. 209 ****************************************************************************************** 325 210 * @ file_id : open file index in fd_array. 326 211 * @ buf : buffer virtual address in user space. 327 212 * @ count : number of bytes. 328 213 * @ return number of bytes actually written if success / returns -1 if failure. 329 ***************************************************************************************** ***/214 *****************************************************************************************/ 330 215 int sys_write( uint32_t file_id, 331 216 void * buf, 332 217 uint32_t count ); 333 218 334 /****************************************************************************************** ***335 * [16] This function epositions the offset of the file descriptor identified by <file_id>,336 * according to the operation type defined by the <whence> a nd <offset> arguments.337 ****************************************************************************************** ***219 /****************************************************************************************** 220 * [16] This function repositions the offset of the file descriptor identified by <file_id>, 221 * according to the operation type defined by the <whence> argument. 222 ****************************************************************************************** 338 223 * @ file_id : open file index in fd_array. 339 * @ offset : buffer virtual address in user space.224 * @ offset : used to compute new offset value. 340 225 * @ whence : operation type (see below). 341 226 * @ return 0 if success / returns -1 if failure. 342 ***************************************************************************************** ***/227 *****************************************************************************************/ 343 228 int sys_lseek( xptr_t file_id, 344 229 uint32_t offset, 345 230 uint32_t whence ); 346 231 347 typedef enum 348 { 349 SEEK_SET = 0, /*! new_offset <= offset */ 350 SEEK_CUR = 1, /*! new_offset <= current_offset + offset */ 351 SEEK_END = 2, /*! new_iffset <= current_size + offset */ 352 } 353 lseek_operation_t; 354 355 /********************************************************************************************* 232 /****************************************************************************************** 356 233 * [17] This function release the memory allocated for the file descriptor identified by 357 234 * the <file_id> argument, and remove the fd array_entry in all copies of the process 358 235 * descriptor. 359 ****************************************************************************************** ***236 ****************************************************************************************** 360 237 file_id : file descriptor index in fd_array. 361 238 * @ return 0 if success / returns -1 if failure. 362 ***************************************************************************************** ***/239 *****************************************************************************************/ 363 240 int sys_close( uint32_t file_id ); 364 241 365 /****************************************************************************************** ***366 * [18] This function removes a directory entry identified by the <pathname> from its242 /****************************************************************************************** 243 * [18] This function removes a directory entry identified by the <pathname> from the 367 244 * directory, and decrement the link count of the file referenced by the link. 368 245 * If the link count reduces to zero, and no process has the file open, then all resources … … 370 247 * the last link is removed, the link is removed, but the removal of the file is delayed 371 248 * until all references to it have been closed. 372 ****************************************************************************************** ***373 * @ pathname : pathname (can be relative or absolute). 374 * @ return 0 if success / returns -1 if failure. 375 ***************************************************************************************** ***/249 ****************************************************************************************** 250 * @ pathname : pathname (can be relative or absolute). 251 * @ return 0 if success / returns -1 if failure. 252 *****************************************************************************************/ 376 253 int sys_unlink( char * pathname ); 377 254 378 /****************************************************************************************** ***255 /****************************************************************************************** 379 256 * [19] This function creates in the calling thread cluster an unnamed pipe, and two 380 257 * (read and write) file descriptors. 381 ********************************************************************************************* 258 * TODO not implemented yet... 259 ****************************************************************************************** 382 260 * @ file_id[0] : [out] read only file descriptor index. 383 261 * @ file_id[1] : [out] write only file descriptor index. 384 262 * @ return 0 if success / return -1 if failure. 385 ***************************************************************************************** ***/263 *****************************************************************************************/ 386 264 int sys_pipe( uint32_t file_id[2] ); 387 265 388 /****************************************************************************************** ***266 /****************************************************************************************** 389 267 * [20] This function change the current working directory in reference process descriptor. 390 ****************************************************************************************** ***391 * @ pathname : pathname (can be relative or absolute). 392 * @ return 0 if success / returns -1 if failure. 393 ***************************************************************************************** ***/268 ****************************************************************************************** 269 * @ pathname : pathname (can be relative or absolute). 270 * @ return 0 if success / returns -1 if failure. 271 *****************************************************************************************/ 394 272 int sys_chdir( char * pathname ); 395 273 396 /****************************************************************************************** ***274 /****************************************************************************************** 397 275 * [21] This function creates a new directory in file system. 398 ****************************************************************************************** ***276 ****************************************************************************************** 399 277 * @ pathname : pathname (can be relative or absolute). 400 278 * @ mode : access rights (as defined in chmod). 401 279 * @ return 0 if success / returns -1 if failure. 402 ***************************************************************************************** ***/280 *****************************************************************************************/ 403 281 int sys_mkdir( char * pathname, 404 282 uint32_t mode ); 405 283 406 /****************************************************************************************** ***284 /****************************************************************************************** 407 285 * [22] This function creates a named FIFO file in the calling thread cluster. 408 286 * The associated read and write file descriptors mut be be explicitely created 409 * using the sy _open() function.410 ****************************************************************************************** ***287 * using the sys_open() function. 288 ****************************************************************************************** 411 289 * @ pathname : pathname (can be relative or absolute). 412 290 * @ mode : access rights (as defined in chmod). 413 291 * @ return 0 if success / returns -1 if failure. 414 ***************************************************************************************** ***/292 *****************************************************************************************/ 415 293 int sys_mkfifo( char * pathname, 416 294 uint32_t mode ); 417 295 418 /********************************************************************************************* 419 * [23] This function open a directory, that must exist in the file system. 420 ********************************************************************************************* 421 * @ pathname : pathname (can be relative or absolute). 422 * @ return file descriptor index in fd_array if success / return -1 if failure. 423 ********************************************************************************************/ 424 int sys_opendir( char * pathname ); 425 426 /********************************************************************************************* 427 * [24] This function returns in the structure pointed by the <dirent> argument various 428 * information about an entry of the directory identified by the <file_id> argument. 429 ********************************************************************************************* 430 * @ file_id : file descriptor index of the searched directory. 431 * @ dirent : pointer on a dirent structure in user space. 432 * @ return 0 if success / returns -1 if failure. 433 ********************************************************************************************/ 434 int sys_readdir( uint32_t file_id, 435 struct vfs_dirent_s * dirent ); 436 437 /********************************************************************************************* 438 * [25] This function close the file descriptor previouly open by the opendir() function. 439 ********************************************************************************************* 440 * @ file_id : file descriptor index of the searched directory. 441 * @ return 0 if success / returns -1 if failure. 442 ********************************************************************************************/ 443 int sys_closedir( uint32_t file_id ); 444 445 /********************************************************************************************* 296 /****************************************************************************************** 297 * [23] This function open a directory, that must exist in the file system, returning 298 * a DIR pointer on the directory in user space. 299 ****************************************************************************************** 300 * @ pathname : pathname (can be relative or absolute). 301 * @ dirp : [out] buffer for pointer on user directory (DIR). 302 * @ return 0 if success / returns -1 if failure. 303 *****************************************************************************************/ 304 int sys_opendir( char * pathname, 305 DIR ** dirp ); 306 307 /****************************************************************************************** 308 * [24] This function returns an user pointer on the dirent structure describing the 309 * next directory entry in the directory identified by the <dirp> argument. 310 ****************************************************************************************** 311 * @ dirp : user pointer identifying the searched directory. 312 * @ dentp : [out] buffer for pointer on user direntory entry (dirent). 313 * @ return O if success / returns -1 if failure. 314 *****************************************************************************************/ 315 int sys_readdir( DIR * dirp, 316 struct dirent ** dentp ); 317 318 /****************************************************************************************** 319 * [25] This function closes the directory identified by the <dirp> argument, and releases 320 * all structures associated with the <dirp> pointer. 321 ****************************************************************************************** 322 * @ dirp : user pointer identifying the directory. 323 * @ return 0 if success / returns -1 if failure. 324 *****************************************************************************************/ 325 int sys_closedir( DIR * dirp ); 326 327 /****************************************************************************************** 446 328 * [26] This function returns the pathname of the current working directory. 447 ****************************************************************************************** ***329 ****************************************************************************************** 448 330 * buf : buffer addres in user space. 449 331 * nbytes : user buffer size in bytes. 450 332 * @ return 0 if success / returns -1 if failure. 451 ***************************************************************************************** ***/333 *****************************************************************************************/ 452 334 int sys_getcwd( char * buf, 453 335 uint32_t nbytes ); 454 336 455 /********************************************************************************************* 456 * [27] This function returns in a 64 bits user buffer the calling core cycles count. 457 * It uses both the hardware register and the core descriptor cycles count tos take 458 * into account a possible harware register overflow in 32 bits architectures. 459 ********************************************************************************************* 460 * cyles : [out] address of buffer in user space. 461 ********************************************************************************************/ 462 int sys_clock( uint64_t * cycles ); 463 464 /********************************************************************************************* 337 /****************************************************************************************** 338 * [27] This slot is not used. 339 *****************************************************************************************/ 340 341 /****************************************************************************************** 465 342 * [28] This function forces the calling thread to sleep, for a fixed number of cycles. 466 ****************************************************************************************** ***343 ****************************************************************************************** 467 344 * cycles : number of cycles. 468 ***************************************************************************************** ***/345 *****************************************************************************************/ 469 346 int sys_alarm( uint32_t cycles ); 470 347 471 /********************************************************************************************* 472 * [29] This undefined function does nothing. 473 ********************************************************************************************* 474 * @ pathname : pathname (can be relative or absolute). 475 * @ return 0 if success / returns -1 if failure. 476 ********************************************************************************************/ 348 /****************************************************************************************** 349 * [29] This function removes a directory file whose name is given by <pathname>. 350 * The directory must not have any entries other than `.' and `..'. 351 ****************************************************************************************** 352 * @ pathname : pathname (can be relative or absolute). 353 * @ return 0 if success / returns -1 if failure. 354 *****************************************************************************************/ 477 355 int sys_rmdir( char * pathname ); 478 356 479 /****************************************************************************************** ***357 /****************************************************************************************** 480 358 * [30] This function implement the operations related to User Thread Local Storage. 481 359 * It is actually implemented as an uint32_t variable in the thread descriptor. 482 ****************************************************************************************** ***360 ****************************************************************************************** 483 361 * @ operation : UTLS operation type as defined below. 484 362 * @ value : argument value for the UTLS_SET operation. 485 363 * @ return value for the UTLS_GET and UTLS_GET_ERRNO / return -1 if failure. 486 ***************************************************************************************** ***/364 *****************************************************************************************/ 487 365 int sys_utls( uint32_t operation, 488 366 uint32_t value ); 489 367 490 typedef enum 491 { 492 UTLS_SET = 1, 493 UTLS_GET = 2, 494 UTLS_GET_ERRNO = 3, 495 } 496 utls_operation_t; 497 498 /********************************************************************************************* 368 /****************************************************************************************** 499 369 * [31] This function change the acces rights for the file/dir identified by the 500 370 * pathname argument. 501 ****************************************************************************************** ***371 ****************************************************************************************** 502 372 * @ pathname : pathname (can be relative or absolute). 503 373 * @ rights : acces rights. 504 374 * @ return 0 if success / returns -1 if failure. 505 ***************************************************************************************** ***/375 *****************************************************************************************/ 506 376 int sys_chmod( char * pathname, 507 377 uint32_t rights ); 508 378 509 /****************************************************************************************** ***379 /****************************************************************************************** 510 380 * [32] This function associate a specific signal handler to a given signal type. 511 381 * Tee handlers for the SIGKILL and SIGSTOP signals cannot be redefined. 512 ****************************************************************************************** ***382 ****************************************************************************************** 513 383 * @ sig_id : index defining signal type (from 1 to 31). 514 384 * @ handler : pointer on fonction implementing the specific handler. 515 385 * @ return 0 if success / returns -1 if failure. 516 ***************************************************************************************** ***/386 *****************************************************************************************/ 517 387 int sys_signal( uint32_t sig_id, 518 388 void * handler ); 519 389 520 /****************************************************************************************** ***390 /****************************************************************************************** 521 391 * [33] This function returns in the structure <tv>, defined in the time.h file, 522 392 * the current time (in seconds & micro-seconds). 523 393 * It is computed from the calling core descriptor. 524 394 * The timezone is not supported. 525 ****************************************************************************************** ***395 ****************************************************************************************** 526 396 * @ tv : pointer on the timeval structure. 527 397 * @ tz : pointer on the timezone structure : must be NULL. 528 398 * @ return 0 if success / returns -1 if failure. 529 ***************************************************************************************** ***/399 *****************************************************************************************/ 530 400 int sys_timeofday( struct timeval * tv, 531 401 struct timezone * tz ); 532 402 533 /****************************************************************************************** ***403 /****************************************************************************************** 534 404 * [34] This function implements the "kill" system call. 535 405 * It register the signal defined by the <sig_id> argument in all thread descriptors … … 537 407 * containing threads for the target process. 538 408 * It can be executed by any thread running in any cluster, as this function uses 539 * remote access to traverse the list of process copies in the owner cluster,409 * remote access to traverse the list of process copies stored in the owner cluster, 540 410 * and the RPC_SIGNAL_RISE to signal the remote threads. 541 ****************************************************************************************** ***411 ****************************************************************************************** 542 412 * @ pid : target process identifier. 543 413 * @ sig_id : index defining the signal type (from 1 to 31). 544 414 * @ return 0 if success / returns -1 if failure. 545 ***************************************************************************************** ***/415 *****************************************************************************************/ 546 416 int sys_kill( pid_t pid, 547 417 uint32_t sig_id ); 548 418 549 /****************************************************************************************** ***419 /****************************************************************************************** 550 420 * [35] This function implements the "getpid" system call. 551 ****************************************************************************************** ***552 * @ returns the PID for the calling thread.553 ***************************************************************************************** ***/421 ****************************************************************************************** 422 * @ returns the process PID for the calling thread. 423 *****************************************************************************************/ 554 424 int sys_getpid(); 555 425 556 /****************************************************************************************** ***426 /****************************************************************************************** 557 427 * [36] This function implement the "fork" system call. 558 428 * The calling process descriptor (parent process), and the associated thread descriptor are … … 560 430 * is registered in another target cluster, that is the new process owner. 561 431 * The child process and the associated main thread will be migrated to the target cluster 562 * later, when the child process makes an "exec" or any other system call. 432 * later, when the child process makes an "exec" or any other system call... TODO [AG] 563 433 * The target cluster depends on the "fork_user" flag and "fork_cxy" variable that can be 564 434 * stored in the calling thread descriptor by the specific fork_place() system call. 565 435 * If not, the sys_fork() function makes a query to the DQDT to select the target cluster. 566 ********************************************************************************************* 567 * @ returns child process PID if success / returns -1 if failure 568 ********************************************************************************************/ 436 ****************************************************************************************** 437 * @ if success, returns child process PID to parent, and return O to child. 438 * @ if failure, returns -1 to parent / no child process is created. 439 *****************************************************************************************/ 569 440 int sys_fork(); 570 441 571 /********************************************************************************************* 572 * [37] This function implement the "exec" system call. 573 * It is executed in the client cluster, but the new process descriptor and main thread 574 * must be created in a server cluster, that is generally another cluster. 575 * - if the server_cluster is the client cluster, call directly the process_make_exec() 442 /****************************************************************************************** 443 * [37] This function implement the "exec" system call, that creates a new process 444 * descriptor. 445 * It is executed in the client cluster, but the new process descriptor and the main 446 * thread are created in a server cluster, that is generally another cluster. 447 * - if the server_cluster is the client cluster, it calls directly the process_make_exec() 576 448 * function to create a new process, and launch a new thread in local cluster. 577 * - if the target_cluster is remote, call rpc_process_exec_client() to execute the578 * process_ make_exec() on the remote cluster.449 * - if the target_cluster is remote, it calls the rpc_process_exec_client() to execute 450 * process_signedmake_exec() on the remote cluster. 579 451 * In both case this function build an exec_info_t structure containing all informations 580 452 * required to build the new process descriptor and the associated thread. 581 453 * Finally, the calling process and thread are deleted. 582 ****************************************************************************************** ***583 * @ filename : string pointer on .elf filename ( virtualpointer in user space)584 * @ argv : array of strings on process arguments ( virtualpointers in user space)585 * @ envp : array of strings on Renvironment variables (virtualpointers in user space)454 ****************************************************************************************** 455 * @ filename : string pointer on .elf filename (pointer in user space) 456 * @ argv : array of strings on process arguments (pointers in user space) 457 * @ envp : array of strings on environment variables (pointers in user space) 586 458 * @ returns O if success / returns -1 if failure. 587 ***************************************************************************************** ***/459 *****************************************************************************************/ 588 460 int sys_exec( char * filename, 589 461 char ** argv, 590 462 char ** envp ); 591 463 592 /****************************************************************************************** ***593 * [38] This function returns in the <stat> structure, defined in the vfs.h file,594 * various informations on the file/directory identified by the <file_id> argument.595 ****************************************************************************************** ***596 * @ file_id : file descriptor index in fd_array.597 * @ stat : pointer on the stat structure.464 /****************************************************************************************** 465 * [38] This function returns in the <stat> structure, defined in the "shared_syscalls.h" 466 * file, various informations on the file/directory identified by the <pathname> argument. 467 ****************************************************************************************** 468 * @ pathname : user pointer on file pathname. 469 * @ stat : user pointer on the stat structure. 598 470 * @ returns O if success / returns -1 if failure. 599 ***************************************************************************************** ***/600 int sys_stat( uint32_t file_id,601 struct vfs_stat_s* stat );602 603 /****************************************************************************************** ***604 * [39] This function is used to activate / desactivate Rthe trace for a thread471 *****************************************************************************************/ 472 int sys_stat( const char * pathname, 473 struct stat * stat ); 474 475 /****************************************************************************************** 476 * [39] This non-standard function is used to activate / desactivate the trace for a thread 605 477 * identified by the <trdid> and <pid> arguments. 606 * It can be called by any other thread .607 ****************************************************************************************** ***478 * It can be called by any other thread in the same process. 479 ****************************************************************************************** 608 480 * @ operation : operation type as defined below. 609 481 * @ pid : process identifier. 610 482 * @ trdid : thread identifier. 611 483 * @ returns O if success / returns -1 if failure. 612 ***************************************************************************************** ***/484 *****************************************************************************************/ 613 485 int sys_trace( uint32_t operation, 614 486 pid_t pid, 615 487 uint32_t trdid ); 616 488 617 typedef enum 618 { 619 TRACE_ON = 0, 620 TRACE_OFF = 1, 621 } 622 trace_operation_t; 489 /****************************************************************************************** 490 * [40] This function returns the hardware platform parameters. 491 ****************************************************************************************** 492 * @ x_size : [out] number of clusters in a row. 493 * @ y_size : [out] number of clusters in a column. 494 * @ ncores : [out] number of cores per cluster. 495 * @ return 0 if success / return -1 if illegal arguments 496 *****************************************************************************************/ 497 int sys_get_config( uint32_t * x_size, 498 uint32_t * y_size, 499 uint32_t * ncores ); 500 501 /****************************************************************************************** 502 * [41] This function returns the calling core cluster and local index. 503 ****************************************************************************************** 504 * @ cxy : [out] cluster identifier (fixed format) 505 * @ lid : [out] core local index in cluster. 506 * @ return 0 if success / return -1 if illegal arguments 507 *****************************************************************************************/ 508 int sys_get_core( uint32_t * cxy, 509 uint32_t * lid ); 510 511 /****************************************************************************************** 512 * [42] This function returns in a 64 bits user buffer the calling core cycles count. 513 * It uses both the hardware register and the core descriptor cycles count to take 514 * into account a possible harware register overflow in 32 bits architectures. 515 ****************************************************************************************** 516 * cycle : [out] address of buffer in user space. 517 * @ return 0 if success / return -1 if illegal arguments 518 *****************************************************************************************/ 519 int sys_get_cycle( uint64_t * cycle ); 520 521 /****************************************************************************************** 522 * [43] This debug function displays on the kernel terminal the current state of a 523 * scheduler identified by the <cxy> and <lid> arguments. 524 ****************************************************************************************** 525 * cxy : [in] target cluster identifier. 526 * lid : [in] target core local index. 527 * @ return 0 if success / return -1 if illegal arguments 528 *****************************************************************************************/ 529 int sys_get_sched( uint32_t cxy, 530 uint32_t lid ); 531 532 /****************************************************************************************** 533 * [44] This debug function requires the kernel to display on the kernel terminal a message 534 * containing the thread / process / core identifiers, and the cause of panic, 535 * as defined by the <string> argument. 536 ****************************************************************************************** 537 * string : [in] message to be displayed. 538 * @ return always 0. 539 *****************************************************************************************/ 540 int sys_panic( char * string ); 541 542 /****************************************************************************************** 543 * [45] This function block the calling thread on the THREAD_BLOCKED_GLOBAL condition, 544 * and deschedule. 545 ****************************************************************************************** 546 * @ return 0 if success / returns -1 if failure. 547 *****************************************************************************************/ 548 int sys_thread_sleep(); 549 550 /****************************************************************************************** 551 * [46] This function unblock the thread identified by its <trdid> from the 552 * THREAD_BLOCKED_GLOBAL condition. 553 ****************************************************************************************** 554 * @ trdid : target thread identifier. 555 * @ return 0 if success / return -1 if failure. 556 *****************************************************************************************/ 557 int sys_thread_wakeup(); 623 558 624 559
Note: See TracChangeset
for help on using the changeset viewer.