- Timestamp:
- Nov 10, 2018, 2:33:26 PM (6 years ago)
- Location:
- trunk/kernel/syscalls
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/syscalls/shared_include/shared_mman.h
r445 r594 43 43 MAP_ANON = 0x00000001, /*! map an anonymous vseg in local cluster */ 44 44 MAP_REMOTE = 0x00000002, /*! map an anonymous vseg in remote cluster (cxy == fdid) */ 45 MAP_PRIVATE = 0x00000010, /*! 46 MAP_SHARED = 0x00000020, /*! 47 MAP_FIXED = 0x00000100, /*! non supported 45 MAP_PRIVATE = 0x00000010, /*! modifications are private to the calling process */ 46 MAP_SHARED = 0x00000020, /*! modifications are shared */ 47 MAP_FIXED = 0x00000100, /*! non supported (user defined base address) */ 48 48 } 49 49 mmap_flags_t; -
trunk/kernel/syscalls/shared_include/shared_stat.h
r445 r594 32 32 typedef struct stat 33 33 { 34 unsigned int dev; /*! ID of device containing file*/35 unsigned int inum; /*! inode number*/36 unsigned int mode; /*! protection*/37 unsigned int nlink; /*! number of hard links*/38 unsigned int uid; /*! user ID of owner*/39 unsigned int gid; /*! group ID of owner*/40 unsigned int rdev; /*! device ID (if special file)*/41 unsigned int s ize; /*! total size, in bytes*/42 unsigned int blksize; /*! blocksize for file system I/O*/43 unsigned int blocks; /*! number of 512B blocks allocated*/34 unsigned int st_dev; /*! ID of device containing file */ 35 unsigned int st_ino; /*! inode number */ 36 unsigned int st_mode; /*! bit vector defined below */ 37 unsigned int st_nlink; /*! number of hard links */ 38 unsigned int st_uid; /*! user ID of owner */ 39 unsigned int st_gid; /*! group ID of owner */ 40 unsigned int st_rdev; /*! device ID (if special file) */ 41 unsigned int st_size; /*! total size, in bytes */ 42 unsigned int st_blksize; /*! blocksize for file system I/O */ 43 unsigned int st_blocks; /*! number of allocated blocks */ 44 44 } 45 45 stat_t; 46 46 47 /****************************************************************************************** 48 * The st_mode field contains informations on both access rights and file types. 49 * - access rights (defined by the inode <rights> field) are stored in st_mode[15:0] 50 * - file types (defined by the inode <type> field) are stored in st_mode[19:16] 51 * The following macros can be used to extract file type information. 52 * 53 * WARNING : these macros must be kept consistent with inode types in <vfs.h> file. 54 *****************************************************************************************/ 55 56 #define S_ISREG(x) ((((x)>>16) & 0xF) == 0) /*! it is a regular file */ 57 #define S_ISDIR(x) ((((x)>>16) & 0xF) == 1) /*! it is a directory */ 58 #define S_ISFIFO(x) ((((x)>>16) & 0xF) == 2) /*! it is a named pipe */ 59 #define S_ISPIPE(x) ((((x)>>16) & 0xF) == 3) /*! it is an anonymous pipe */ 60 #define S_ISSOCK(x) ((((x)>>16) & 0xF) == 4) /*! it is a socket */ 61 #define S_ISCHR(x) ((((x)>>16) & 0xF) == 5) /*! it is a character device */ 62 #define S_ISLNK(x) ((((x)>>16) & 0xF) == 6) /*! it is a symbolic link */ 63 47 64 #endif /* _STAT_H_ */ -
trunk/kernel/syscalls/sys_close.c
r506 r594 41 41 process_t * process = this->process; 42 42 43 #if (DEBUG_SYS_CLOSE || CONFIG_INSTRUMENTATION_SYSCALLS) 44 uint64_t tm_start = hal_get_cycles(); 45 #endif 46 43 47 #if DEBUG_SYS_CLOSE 44 uint32_t tm_start;45 uint32_t tm_end;46 tm_start = hal_get_cycles();47 48 if( DEBUG_SYS_CLOSE < tm_start ) 48 printk("\n[ DBG] %s : thread %x in process %xenter / fdid %d / cycle %d\n",49 __FUNCTION__, this->trdid, process->pid, file_id, (uint32_t)tm_start );49 printk("\n[%s] thread[%x,%x] enter / fdid %d / cycle %d\n", 50 __FUNCTION__, process->pid, this->trdid, file_id, (uint32_t)tm_start ); 50 51 #endif 51 52 … … 64 65 if( file_xp == XPTR_NULL ) 65 66 { 66 printk("\n[ERROR] in %s : undefined file descriptor = %d\n", 67 __FUNCTION__ , file_id ); 68 this->errno = EBADFD; 67 68 #if DEBUG_SYSCALLS_ERROR 69 printk("\n[ERROR] in %s : undefined file descriptor %d\n", 70 __FUNCTION__ , file_id ); 71 #endif 72 this->errno = EBADFD; 69 73 return -1; 70 74 } … … 75 79 if( error ) 76 80 { 77 printk("\n[ERROR] in %s : cannot close file descriptor = %d\n", 78 __FUNCTION__ , file_id ); 81 82 #if DEBUG_SYSCALLS_ERROR 83 printk("\n[ERROR] in %s : cannot close file descriptor %d\n", 84 __FUNCTION__ , file_id ); 85 #endif 79 86 this->errno = error; 80 87 return -1; … … 83 90 hal_fence(); 84 91 92 #if (DEBUG_SYS_CLOSE || CONFIG_INSTRUMENTATION_SYSCALLS) 93 uint64_t tm_end = hal_get_cycles(); 94 #endif 95 85 96 #if DEBUG_SYS_CLOSE 86 97 tm_end = hal_get_cycles(); 87 98 if( DEBUG_SYS_CLOSE < tm_start ) 88 printk("\n[ DBG] %s : thread %x in process %x exit / cost %d/ cycle %d\n",89 __FUNCTION__, this->trdid, process->pid, (uint32_t)(tm_end - tm_start), (uint32_t)tm_start);99 printk("\n[%s] thread[%x,%x] exit / cycle %d\n", 100 __FUNCTION__, process->pid, this->trdid, (uint32_t)tm_end ); 90 101 #endif 91 102 103 #if CONFIG_INSTRUMENTATION_SYSCALLS 104 hal_atomic_add( &syscalls_cumul_cost[SYS_CLOSE] , tm_end - tm_start ); 105 hal_atomic_add( &syscalls_occurences[SYS_CLOSE] , 1 ); 106 #endif 107 92 108 return 0; 93 109 } -
trunk/kernel/syscalls/sys_display.c
r584 r594 65 65 process_t * process = this->process; 66 66 67 #if (DEBUG_SYS_DISPLAY || CONFIG_INSTRUMENTATION_SYSCALLS) 68 uint64_t tm_start = hal_get_cycles(); 69 #endif 70 67 71 #if DEBUG_SYS_DISPLAY 68 uint64_t tm_start;69 uint64_t tm_end;70 72 tm_start = hal_get_cycles(); 71 73 if( DEBUG_SYS_DISPLAY < tm_start ) 72 printk("\n[DBG] %s : thread %d enter / process %x/ type %s / cycle = %d\n",73 __FUNCTION__, this, this->process->pid, display_type_str(type), (uint32_t)tm_start );74 printk("\n[DBG] %s : thread[%x,%x] enter / type %s / cycle = %d\n", 75 __FUNCTION__, process->pid, this->trdid, display_type_str(type), (uint32_t)tm_start ); 74 76 #endif 75 77 … … 257 259 else if( type == DISPLAY_BUSYLOCKS ) 258 260 { 259 pid_t pid = ( cxy_t)arg0;261 pid_t pid = (pid_t)arg0; 260 262 trdid_t trdid = (trdid_t)arg1; 261 263 … … 267 269 268 270 #if DEBUG_SYSCALLS_ERROR 269 printk("\n[ERROR] in %s for BUSYLOCKS : thread %x in process %xnot found\n",270 __FUNCTION__ , trdid , pid );271 printk("\n[ERROR] in %s for BUSYLOCKS : thread[%x,%x] not found\n", 272 __FUNCTION__ , pid, trdid ); 271 273 #endif 272 274 this->errno = EINVAL; … … 288 290 } 289 291 292 #if (DEBUG_SYS_DISPLAY || CONFIG_INSTRUMENTATION_SYSCALLS) 293 uint64_t tm_end = hal_get_cycles(); 294 #endif 295 290 296 #if DEBUG_SYS_DISPLAY 291 tm_end = hal_get_cycles();292 297 if( DEBUG_SYS_DISPLAY < tm_end ) 293 printk("\n[DBG] %s : thread %x exit / process %x / cost = %d / cycle %d\n", 294 __FUNCTION__, this, this->process->pid, (uint32_t)(tm_end - tm_start) , (uint32_t)tm_end ); 298 printk("\n[DBG] %s : thread[%x,%x] exit / cycle %d\n", 299 __FUNCTION__, process->pid, this->trdid, (uint32_t)tm_end ); 300 #endif 301 302 #if CONFIG_INSTRUMENTATION_SYSCALLS 303 hal_atomic_add( &syscalls_cumul_cost[SYS_DISPLAY] , tm_end - tm_start ); 304 hal_atomic_add( &syscalls_occurences[SYS_DISPLAY] , 1 ); 295 305 #endif 296 306 -
trunk/kernel/syscalls/sys_fork.c
r584 r594 110 110 #if (DEBUG_SYS_FORK & 1 ) 111 111 if( DEBUG_SYS_FORK < tm_start ) 112 printk("\n[ DBG] %s :thread[%x,%x] selected cluster %x\n",112 printk("\n[%s] thread[%x,%x] selected cluster %x\n", 113 113 __FUNCTION__, parent_pid, parent_thread_ptr->trdid, child_cxy ); 114 114 #endif … … 167 167 #if DEBUG_SYS_FORK 168 168 if( DEBUG_SYS_FORK < tm_end ) 169 printk("\n[ DBG] %s :thread[%x,%x] exit / cycle %d\n",169 printk("\n[%s] thread[%x,%x] exit / cycle %d\n", 170 170 __FUNCTION__, current->process->pid, current->trdid, (uint32_t)tm_end ); 171 171 #endif -
trunk/kernel/syscalls/sys_kill.c
r584 r594 74 74 tm_start = hal_get_cycles(); 75 75 if( DEBUG_SYS_KILL < tm_start ) 76 printk("\n[ DBG] %s :thread[%x,%x] enter / process %x / %s / cycle %d\n",76 printk("\n[%s] thread[%x,%x] enter / process %x / %s / cycle %d\n", 77 77 __FUNCTION__, this->process->pid, this->trdid, pid, 78 78 sig_type_str(sig_id), (uint32_t)tm_start ); … … 86 86 #if (DEBUG_SYS_KILL & 1) 87 87 if( DEBUG_SYS_KILL < tm_start ) 88 printk("\n[ DBG] %s :thread[%x,%x] get owner process %x in cluster %x\n",88 printk("\n[%s] thread[%x,%x] get owner process %x in cluster %x\n", 89 89 __FUNCTION__ , this->process->pid, this->trdid, owner_ptr, owner_cxy ); 90 90 #endif … … 108 108 #if (DEBUG_SYS_KILL & 1) 109 109 if( DEBUG_SYS_KILL < tm_start ) 110 printk("\n[ DBG] %s :thread[%x,%x] get parent process %x in cluster %x\n",110 printk("\n[%x] thread[%x,%x] get parent process %x in cluster %x\n", 111 111 __FUNCTION__ , this->process->pid, this->trdid, parent_ptr, parent_cxy ); 112 112 #endif … … 135 135 thread_unblock( parent_main_xp , THREAD_BLOCKED_WAIT ); 136 136 137 // calling thread deschedules when it is itself a target thread 138 if( this->process->pid == pid ) sched_yield("block itself"); 139 137 140 break; 138 141 } … … 214 217 #if DEBUG_SYS_KILL 215 218 if( DEBUG_SYS_KILL < tm_end ) 216 printk("\n[ DBG] %s :thread[%x,%x] exit / process %x / %s / cost = %d / cycle %d\n",219 printk("\n[%s] thread[%x,%x] exit / process %x / %s / cost = %d / cycle %d\n", 217 220 __FUNCTION__ , this->process->pid, this->trdid, pid, 218 221 sig_type_str(sig_id), (uint32_t)(tm_end - tm_start), (uint32_t)tm_end ); -
trunk/kernel/syscalls/sys_mmap.c
r566 r594 51 51 process_t * process = this->process; 52 52 53 #if (DEBUG_SYS_MMAP || CONFIG_INSTRUMENTATION_SYSCALLS) 54 uint64_t tm_start = hal_get_cycles(); 55 #endif 56 53 57 #if DEBUG_SYS_MMAP 54 uint64_t tm_start;55 uint64_t tm_end;56 58 tm_start = hal_get_cycles(); 57 59 if ( DEBUG_SYS_MMAP < tm_start ) 58 printk("\n[ DBG] %s : thread %x enter / process %x/ cycle %d\n",59 __FUNCTION__, this, process->pid, (uint32_t)tm_start );60 #endif 61 62 // check arguments in user space60 printk("\n[%s] thread[%x,%x] enter / cycle %d\n", 61 __FUNCTION__, process->pid, this->trdid, (uint32_t)tm_start ); 62 #endif 63 64 // check user buffer (containing attributes) is mapped 63 65 error = vmm_get_vseg( process , (intptr_t)attr , &vseg ); 64 66 65 if 66 { 67 68 #if DEBUG_SYSCALLS_ERROR 69 printk("\n[ERROR] in %s : user buffer unmapped %x / thread %x / process%x\n",70 __FUNCTION__ , (intptr_t)attr , this->trdid , process->pid);67 if( error ) 68 { 69 70 #if DEBUG_SYSCALLS_ERROR 71 printk("\n[ERROR] in %s : thread[%x,%x] / mmap attributes unmapped %x\n", 72 __FUNCTION__ , process->pid, this->trdid, (intptr_t)attr ); 71 73 vmm_display( process , false ); 72 74 #endif … … 75 77 } 76 78 77 // copy a rguments from uspace79 // copy attributes from user space to kernel space 78 80 hal_copy_from_uspace( &k_attr , attr , sizeof(mmap_attr_t) ); 79 81 80 // get fdid, offset, and length arguments81 uint32_t fdid = k_attr.fdid;82 uint32_t offset = k_attr.offset;83 uint32_t length = k_attr.length;82 // get addr, fdid, offset, and length attributes 83 uint32_t fdid = k_attr.fdid; 84 uint32_t offset = k_attr.offset; 85 uint32_t length = k_attr.length; 84 86 85 87 // get flags … … 95 97 96 98 #if DEBUG_SYSCALLS_ERROR 97 printk("\n[ERROR] in %s : MAP_FIXED not supported / thread %x / process %x\n",98 __FUNCTION__ , this->trdid , process->pid );99 printk("\n[ERROR] in %s : thread[%x,%x] / MAP_FIXED not supported\n", 100 __FUNCTION__ , process->pid, this->trdid ); 99 101 #endif 100 102 this->errno = EINVAL; … … 106 108 107 109 #if DEBUG_SYSCALLS_ERROR 108 printk("\n[ERROR] in %s : MAP_SHARED == MAP_PRIVATE / thread %x / process %x\n",109 __FUNCTION__ , this->trdid , process->pid );110 printk("\n[ERROR] in %s : thread[%x,%x] / MAP_SHARED == MAP_PRIVATE\n", 111 __FUNCTION__ , process->pid, this->trdid ); 110 112 #endif 111 113 this->errno = EINVAL; … … 115 117 // FIXME handle Copy_On_Write for MAP_PRIVATE... 116 118 117 // get access rigths118 bool_t prot_read = ( (k_attr.prot & PROT_READ ) != 0 );119 bool_t prot_write = ( (k_attr.prot & PROT_WRITE) != 0 );120 121 119 // test mmap type : can be FILE / ANON / REMOTE 122 120 123 121 if( (map_anon == false) && (map_remote == false) ) // FILE 124 122 { 123 124 #if (DEBUG_SYS_MMAP & 1) 125 if ( DEBUG_SYS_MMAP < tm_start ) 126 printk("\n[%s] thread[%x,%x] map file : fdid %d / offset %d / %d bytes\n", 127 __FUNCTION__, process->pid, this->trdid, fdid, offset, length ); 128 #endif 129 125 130 // FIXME: handle concurent delete of file by another thread closing it 126 131 … … 129 134 130 135 #if DEBUG_SYSCALLS_ERROR 131 printk("\n[ERROR] in %s : bad file descriptor %d / thread %x / process %x\n",132 __FUNCTION__ , fdid , this->trdid , process->pid );136 printk("\n[ERROR] in %s : thread[%x,%x] / bad file descriptor %d\n", 137 __FUNCTION__ , process->pid , this->trdid , fdid ); 133 138 #endif 134 139 this->errno = EBADFD; … … 143 148 144 149 #if DEBUG_SYSCALLS_ERROR 145 printk("\n[ERROR] in %s : file %d not found / thread %x / process %x\n",146 __FUNCTION__ , fdid , this->trdid , process->pid );150 printk("\n[ERROR] in %s : thread[%x,%x] / file descriptor %d not found\n", 151 __FUNCTION__ , this->trdid , process->pid , fdid ); 147 152 #endif 148 153 this->errno = EBADFD; … … 154 159 vfs_file_t * file_ptr = (vfs_file_t *)GET_PTR( file_xp ); 155 160 156 // get inode pointer, mapper pointer and file attributes 161 #if (DEBUG_SYS_MMAP & 1) 162 if ( DEBUG_SYS_MMAP < tm_start ) 163 printk("\n[%s] thread[%x,%x] get file pointer %x in cluster %x\n", 164 __FUNCTION__, process->pid, this->trdid, file_ptr, file_cxy ); 165 #endif 166 167 // get inode pointer & mapper pointer 157 168 vfs_inode_t * inode_ptr = hal_remote_lpt(XPTR(file_cxy , &file_ptr->inode )); 158 uint32_t file_attr = hal_remote_l32 (XPTR(file_cxy , &file_ptr->attr ));159 169 mapper_t * mapper_ptr = hal_remote_lpt(XPTR(file_cxy , &file_ptr->mapper)); 160 170 161 171 // get file size 162 172 uint32_t size = hal_remote_l32( XPTR( file_cxy , &inode_ptr->size ) ); 173 174 #if (DEBUG_SYS_MMAP & 1) 175 if ( DEBUG_SYS_MMAP < tm_start ) 176 printk("\n[%s] thread[%x,%x] get file size : %d bytes\n", 177 __FUNCTION__, process->pid, this->trdid, size ); 178 #endif 163 179 164 180 // chek offset and length arguments … … 167 183 168 184 #if DEBUG_SYSCALLS_ERROR 169 printk("\n[ERROR] in %s: offset(%d) + len(%d) >= file's size(%d) / thread %x / process %x\n",170 __FUNCTION__, k_attr.offset, k_attr.length, size, this->trdid, process->pid);185 printk("\n[ERROR] in %s: thread[%x,%x] / offset(%d) + len(%d) >= file's size(%d)\n", 186 __FUNCTION__, process->pid, this->trdid, k_attr.offset, k_attr.length, size ); 171 187 #endif 172 188 this->errno = ERANGE; 173 189 return -1; 174 190 } 191 192 /* TODO 193 // chek access rigths 194 uint32_t file_attr = hal_remote_l32(XPTR(file_cxy , &file_ptr->attr )); 195 bool_t prot_read = ( (k_attr.prot & PROT_READ ) != 0 ); 196 bool_t prot_write = ( (k_attr.prot & PROT_WRITE) != 0 ); 175 197 176 198 // check access rights … … 186 208 return -1; 187 209 } 210 */ 188 211 189 212 // increment file refcount … … 194 217 vseg_cxy = file_cxy; 195 218 } 196 else // ANON or REMOTE 197 { 198 // no mapper for ANON or REMOTE 219 else if ( map_anon ) // MAP_ANON 220 { 199 221 mapper_xp = XPTR_NULL; 200 201 if( map_anon ) 222 vseg_type = VSEG_TYPE_ANON; 223 vseg_cxy = local_cxy; 224 225 #if (DEBUG_SYS_MMAP & 1) 226 if ( DEBUG_SYS_MMAP < tm_start ) 227 printk("\n[%s] thread[%x,%x] map anon / %d bytes / cluster %x\n", 228 __FUNCTION__, process->pid, this->trdid, length, vseg_cxy ); 229 #endif 230 231 } 232 else // MAP_REMOTE 233 { 234 mapper_xp = XPTR_NULL; 235 vseg_type = VSEG_TYPE_REMOTE; 236 vseg_cxy = k_attr.fdid; 237 238 #if (DEBUG_SYS_MMAP & 1) 239 if ( DEBUG_SYS_MMAP < tm_start ) 240 printk("\n[%s] thread[%x,%x] map remote / %d bytes / cluster %x\n", 241 __FUNCTION__, process->pid, this->trdid, length, vseg_cxy ); 242 #endif 243 244 if( cluster_is_undefined( vseg_cxy ) ) 202 245 { 203 vseg_type = VSEG_TYPE_ANON; 204 vseg_cxy = local_cxy; 205 } 206 else 207 { 208 vseg_type = VSEG_TYPE_REMOTE; 209 vseg_cxy = k_attr.fdid; 210 211 if( cluster_is_undefined( vseg_cxy ) ) 212 { 213 214 #if DEBUG_SYSCALLS_ERROR 215 printk("\n[ERROR] in %s : illegal cxy for MAP_REMOTE / thread %x / process %x\n", 216 __FUNCTION__, this->trdid , process->pid ); 217 #endif 218 this->errno = EINVAL; 219 return -1; 220 } 246 247 #if DEBUG_SYSCALLS_ERROR 248 printk("\n[ERROR] in %s : thread[%x,%x] / illegal cxy %x for REMOTE\n", 249 __FUNCTION__, this->trdid , process->pid, vseg_cxy ); 250 #endif 251 this->errno = EINVAL; 252 return -1; 221 253 } 222 254 } … … 228 260 xptr_t ref_xp = process->ref_xp; 229 261 cxy_t ref_cxy = GET_CXY( ref_xp ); 230 process_t * ref_ptr = (process_t *)GET_PTR( ref_xp );262 process_t * ref_ptr = GET_PTR( ref_xp ); 231 263 232 264 // create the vseg in reference cluster … … 235 267 vseg = vmm_create_vseg( process, 236 268 vseg_type, 237 0, // base address unused for mmap()238 length, 239 offset, 240 0, // file_size unused for mmap()269 0, // vseg base (unused for mmap) 270 length, // vseg size 271 offset, // file offset 272 0, // file_size (unused for mmap) 241 273 mapper_xp, 242 274 vseg_cxy ); … … 247 279 ref_ptr, 248 280 vseg_type, 249 0, // base address unused for mmap()250 length, 251 offset, 252 0, // file size unused for mmap()281 0, // vseg base (unused for mmap) 282 length, // vseg size 283 offset, // file offset 284 0, // file size (unused for mmap) 253 285 mapper_xp, 254 286 vseg_cxy, … … 263 295 264 296 #if DEBUG_SYSCALLS_ERROR 265 printk("\n[ERROR] in %s : cannot create vseg / thread %x / process %x\n",266 __FUNCTION__, this->trdid , process->pid );297 printk("\n[ERROR] in %s : thread[%x,%x] / cannot create vseg\n", 298 __FUNCTION__, process->pid, this->trdid ); 267 299 #endif 268 300 this->errno = ENOMEM; … … 275 307 hal_fence(); 276 308 309 #if (DEBUG_SYS_MMAP || CONFIG_INSTRUMENTATION_SYSCALLS) 310 uint64_t tm_end = hal_get_cycles(); 311 #endif 312 277 313 #if DEBUG_SYS_MMAP 278 tm_end = hal_get_cycles(); 279 if ( DEBUG_SYS_MMAP < tm_start ) 280 printk("\n[DBG] %s : thread %x enter / process %x / cycle %d\n" 281 "vseg %s / cluster %x / base %x / size %x / cost %d\n", 282 __FUNCTION__, this, process->pid, (uint32_t)tm_end, 283 vseg_type_str(vseg->type), vseg->cxy, vseg->min, length, (uint32_t)(tm_end - tm_start) ); 314 if ( DEBUG_SYS_MMAP < tm_start ) 315 printk("\n[%s] thread[%x,%x] exit / %s / cxy %x / base %x / size %d / cycle %d\n", 316 __FUNCTION__, process->pid, this->trdid, 317 vseg_type_str(vseg->type), vseg->cxy, vseg->min, length, (uint32_t)tm_end ); 284 318 #endif 285 319 -
trunk/kernel/syscalls/sys_open.c
r566 r594 47 47 process_t * process = this->process; 48 48 49 #if DEBUG_SYS_OPEN 50 uint32_t tm_start; 51 uint32_t tm_end; 52 tm_start = hal_get_cycles(); 49 #if (DEBUG_SYS_OPEN || CONFIG_INSTRUMENTATION_SYSCALLS) 50 uint64_t tm_start = hal_get_cycles(); 53 51 #endif 54 52 55 53 // check fd_array not full 56 54 if( process_fd_array_full() ) … … 81 79 #if DEBUG_SYS_OPEN 82 80 if( DEBUG_SYS_OPEN < tm_start ) 83 printk("\n[ DBG] %s : thread %x in process %x enter / path %s/ flags %x / cycle %d\n",84 __FUNCTION__, this->trdid, process->pid, kbuf, flags, (uint32_t)tm_start );81 printk("\n[%s] thread[%x,%x] enter for <%s> / flags %x / cycle %d\n", 82 __FUNCTION__, process->pid, this->trdid, kbuf, flags, (uint32_t)tm_start ); 85 83 #endif 86 84 … … 112 110 } 113 111 112 hal_fence; 113 114 #if (DEBUG_SYS_OPEN || CONFIG_INSTRUMENTATION_SYSCALLS) 115 uint64_t tm_end = hal_get_cycles(); 116 #endif 117 114 118 #if DEBUG_SYS_OPEN 115 tm_end = hal_get_cycles();116 119 if( DEBUG_SYS_OPEN < tm_start ) 117 printk("\n[ DBG] %s : thread %x in process %x exit / cost %d/ cycle %d\n",118 __FUNCTION__, this->trdid, process->pid, (uint32_t)(tm_end - tm_start), (uint32_t)tm_start);120 printk("\n[%s] thread[%x,%x] exit for <%s> / cycle %d\n", 121 __FUNCTION__, process->pid, this->trdid, kbuf, (uint32_t)tm_end ); 119 122 #endif 120 123 124 #if CONFIG_INSTRUMENTATION_SYSCALLS 125 hal_atomic_add( &syscalls_cumul_cost[SYS_OPEN] , tm_end - tm_start ); 126 hal_atomic_add( &syscalls_occurences[SYS_OPEN] , 1 ); 127 #endif 128 121 129 return file_id; 122 130 } -
trunk/kernel/syscalls/sys_read.c
r584 r594 194 194 195 195 } 196 else 197 { 198 nbytes = 0; 199 assert( false , "file type %d non supported yet\n", type ); 196 else // not FILE and not DEV 197 { 198 199 #if DEBUG_SYSCALLS_ERROR 200 printk("\n[ERROR] in %s : thread[%x,%x] / illegal inode type %\n", 201 __FUNCTION__, vfs_inode_type_str( type ) ); 202 #endif 203 this->errno = EBADFD; 204 return -1; 200 205 } 201 206 … … 207 212 __FUNCTION__, process->pid, this->trdid, file_id ); 208 213 #endif 209 this->errno = error;214 this->errno = EIO; 210 215 return -1; 211 216 } -
trunk/kernel/syscalls/sys_stat.c
r566 r594 39 39 { 40 40 error_t error; 41 vseg_t * vseg; // for user space checking 42 struct stat k_stat; // kernel space 43 xptr_t file_xp; 41 vseg_t * vseg; // for user space checking 42 struct stat k_stat; // in kernel space 43 xptr_t inode_xp; // extended pointer on target inode 44 44 45 char kbuf[CONFIG_VFS_MAX_PATH_LENGTH]; 45 46 46 47 thread_t * this = CURRENT_THREAD; 47 48 process_t * process = this->process; 49 50 #if (DEBUG_SYS_STAT || CONFIG_INSTRUMENTATION_SYSCALLS) 51 uint64_t tm_start = hal_get_cycles(); 52 #endif 48 53 49 54 // check stat structure in user space … … 54 59 55 60 #if DEBUG_SYSCALLS_ERROR 56 printk("\n[ERROR] in %s : stat structure unmapped %x / thread %x / process %x\n",57 __FUNCTION__ , (intptr_t)u_stat , this->trdid , process->pid );61 printk("\n[ERROR] in %s / thread[%x,%x] : stat structure unmapped\n", 62 __FUNCTION__ , process->pid , this->trdid ); 58 63 vmm_display( process , false ); 59 64 #endif … … 65 70 if( hal_strlen_from_uspace( pathname ) >= CONFIG_VFS_MAX_PATH_LENGTH ) 66 71 { 67 printk("\n[ERROR] in %s : pathname too long\n", __FUNCTION__ ); 72 73 #if DEBUG_SYSCALLS_ERROR 74 printk("\n[ERROR] in %s / thread[%x,%x] : pathname too long\n", 75 __FUNCTION__ , process->pid , this->trdid ); 76 #endif 68 77 this->errno = ENFILE; 69 78 return -1; … … 72 81 // copy pathname in kernel space 73 82 hal_strcpy_from_uspace( kbuf , pathname , CONFIG_VFS_MAX_PATH_LENGTH ); 83 84 #if DEBUG_SYS_STAT 85 if( DEBUG_SYS_STAT < tm_start ) 86 printk("\n[%s] thread[%x,%x] enter for file <%s> / cycle %d\n", 87 __FUNCTION__, process->pid, this->trdid, kbuf, (uint32_t)tm_start ); 88 #endif 74 89 75 90 // get cluster and local pointer on reference process … … 86 101 // get extended pointer on remote file descriptor 87 102 error = vfs_lookup( cwd_xp, 88 pathname,103 kbuf, 89 104 0, 90 & file_xp );105 &inode_xp ); 91 106 92 107 // release the cwd lock … … 95 110 if( error ) 96 111 { 97 printk("\n[ERROR] in %s : cannot found file <%s> for thread %x in process %x\n", 98 __FUNCTION__ , pathname , this->trdid , process->pid ); 99 this->errno = error; 112 113 #if DEBUG_SYSCALLS_ERROR 114 printk("\n[ERROR] in %s / thread[%x,%x] : cannot found file <%s>\n", 115 __FUNCTION__ , process->pid , this->trdid , pathname ); 116 #endif 117 this->errno = ENFILE; 100 118 return -1; 101 119 } 102 120 121 #if (DEBUG_SYS_STAT & 1) 122 if( DEBUG_SYS_STAT < tm_start ) 123 printk("\n[%s] thread[%x,%x] got inode %x in cluster %x for <%s>\n", 124 __FUNCTION__, process->pid, this->trdid, GET_PTR(inode_xp), GET_CXY(inode_xp), kbuf ); 125 #endif 126 103 127 // call VFS function to get stat info 104 error = vfs_stat( file_xp,128 error = vfs_stat( inode_xp, 105 129 &k_stat ); 106 130 if( error ) 107 131 { 108 printk("\n[ERROR] in %s : cannot get stats for file %s\n", 109 __FUNCTION__ , pathname ); 110 this->errno = error; 132 133 #if DEBUG_SYSCALLS_ERROR 134 printk("\n[ERROR] in %s / thread[%x,%x] : cannot get stats for inode <%s>\n", 135 __FUNCTION__ , process->pid , this->trdid , pathname ); 136 #endif 137 this->errno = ENFILE; 111 138 return -1; 112 139 } 113 140 141 #if (DEBUG_SYS_STAT & 1) 142 if( DEBUG_SYS_STAT < tm_start ) 143 printk("\n[%s] thread[%x,%x] set kstat : inum %d / size %d / mode %d\n", 144 __FUNCTION__, process->pid, this->trdid, k_stat.st_ino, k_stat.st_size, k_stat.st_mode ); 145 #endif 146 114 147 // copy k_stat to u_stat 115 148 hal_copy_to_uspace( u_stat , &k_stat , sizeof(struct stat) ); … … 117 150 hal_fence(); 118 151 152 #if (DEBUG_SYS_STAT || CONFIG_INSTRUMENTATION_SYSCALLS) 153 uint64_t tm_end = hal_get_cycles(); 154 #endif 155 156 #if DEBUG_SYS_STAT 157 if( DEBUG_SYS_STAT < tm_end ) 158 printk("\n[%s] thread[%x,%x] exit for file <%s> / cycle %d\n", 159 __FUNCTION__, process->pid, this->trdid, kbuf, (uint32_t)tm_end ); 160 #endif 161 162 #if CONFIG_INSTRUMENTATION_SYSCALLS 163 hal_atomic_add( &syscalls_cumul_cost[SYS_STAT] , tm_end - tm_start ); 164 hal_atomic_add( &syscalls_occurences[SYS_STAT] , 1 ); 165 #endif 166 119 167 return 0; 120 168 -
trunk/kernel/syscalls/sys_thread_create.c
r566 r594 62 62 process = parent->process; 63 63 64 #if (DEBUG_SYS_THREAD_CREATE || CONFIG_INSTRUMENTATION_SYSCALLS) 65 uint64_t tm_start = hal_get_cycles(); 66 #endif 67 64 68 #if DEBUG_SYS_THREAD_CREATE 65 uint64_t tm_start;66 uint64_t tm_end;67 69 tm_start = hal_get_cycles(); 68 70 if( DEBUG_SYS_THREAD_CREATE < tm_start ) 69 printk("\n[ DBG] %s : thread %x in process %xenter / cycle %d\n",70 __FUNCTION__, p arent->trdid, process->pid, (uint32_t)tm_start );71 printk("\n[%s] thread[%x,%x] enter / cycle %d\n", 72 __FUNCTION__, process_pid, parent->trdid, (uint32_t)tm_start ); 71 73 #endif 72 74 … … 78 80 79 81 #if DEBUG_SYSCALLS_ERROR 80 printk("\n[ERROR] in %s : thread %x in process %x/ trdid buffer %x unmapped %x\n",81 __FUNCTION__, p arent->trdid, process->pid, (intptr_t)trdid_ptr );82 printk("\n[ERROR] in %s : thread[%x,%x] / trdid buffer %x unmapped %x\n", 83 __FUNCTION__, process->pid, parent->trdid, (intptr_t)trdid_ptr ); 82 84 vmm_display( process , false ); 83 85 #endif … … 95 97 96 98 #if DEBUG_SYSCALLS_ERROR 97 printk("\n[ERROR] in %s : thread %x in process %x/ user_attr buffer unmapped %x\n",98 __FUNCTION__, p arent->trdid, process->pid, (intptr_t)user_attr );99 printk("\n[ERROR] in %s : thread[%x,%x] / user_attr buffer unmapped %x\n", 100 __FUNCTION__, process->pid, parent->trdid, (intptr_t)user_attr ); 99 101 vmm_display( process , false ); 100 102 #endif … … 113 115 114 116 #if DEBUG_SYSCALLS_ERROR 115 printk("\n[ERROR] in %s : thread %x in process %x/ start_func unmapped %x\n",116 __FUNCTION__, p arent->trdid, process->pid, (intptr_t)start_func );117 printk("\n[ERROR] in %s : thread[%x,%x] / start_func unmapped %x\n", 118 __FUNCTION__, process->pid, parent->trdid, (intptr_t)start_func ); 117 119 vmm_display( process , false ); 118 120 #endif … … 130 132 131 133 #if DEBUG_SYSCALLS_ERROR 132 printk("\n[ERROR] in %s : thread %x in process %x/ start_args buffer unmapped %x\n",133 __FUNCTION__, p arent->trdid, process->pid, (intptr_t)start_args );134 printk("\n[ERROR] in %s : thread[%x,%x] / start_args buffer unmapped %x\n", 135 __FUNCTION__, process->pid, parent->trdid, (intptr_t)start_args ); 134 136 vmm_display( process , false ); 135 137 #endif … … 149 151 150 152 #if DEBUG_SYSCALLS_ERROR 151 printk("\n[ERROR] in %s : thread %x in process %x/ illegal target cluster %x\n",152 __FUNCTION__, p arent->trdid, process->pid, kern_attr.cxy );153 printk("\n[ERROR] in %s : thread[%x,%x] / illegal target cluster %x\n", 154 __FUNCTION__, process->pid, parent->trdid, kern_attr.cxy ); 153 155 #endif 154 156 parent->errno = EINVAL; … … 200 202 201 203 #if DEBUG_SYSCALLS_ERROR 202 printk("\n[ERROR] in %s : thread %x in process %xcannot create new thread\n",203 __FUNCTION__ , p arent->trdid, process->pid );204 printk("\n[ERROR] in %s : thread[%x,%x] cannot create new thread\n", 205 __FUNCTION__ , process->pid, parent->trdid ); 204 206 #endif 205 207 parent->errno = ENOMEM; … … 216 218 hal_fence(); 217 219 220 #if (DEBUG_SYS_THREAD_CREATE || CONFIG_INSTRUMENTATION_SYSCALLS) 221 uint64_t tm_end = hal_get_cycles(); 222 #endif 223 218 224 #if DEBUG_SYS_THREAD_CREATE 219 tm_end = hal_get_cycles();220 225 if( DEBUG_SYS_THREAD_CREATE < tm_end ) 221 printk("\n[DBG] %s : thread %x in process %x created thread %x / cycle %d\n", 222 __FUNCTION__, parent->trdid, process->pid, child_ptr->trdid, (uint32_t)tm_end ); 226 printk("\n[%s] thread[%x,%x] created thread %x / cycle %d\n", 227 __FUNCTION__, process->pid, parent->trdid, child_ptr->trdid, (uint32_t)tm_end ); 228 #endif 229 230 #if CONFIG_INSTRUMENTATION_SYSCALLS 231 hal_atomic_add( &syscalls_cumul_cost[SYS_THREAD_CREATE] , tm_end - tm_start ); 232 hal_atomic_add( &syscalls_occurences[SYS_THREAD_CREATE] , 1 ); 223 233 #endif 224 234 -
trunk/kernel/syscalls/sys_write.c
r584 r594 153 153 count ); 154 154 } 155 else if( type == INODE_TYPE_DEV ) // check ownership & write to device 156 { 157 // check user buffer size for TXT_TX 158 if( (type == INODE_TYPE_DEV) && (count >= CONFIG_TXT_KBUF_SIZE) ) 159 { 160 161 #if DEBUG_SYSCALLS_ERROR 162 printk("\n[ERROR] in %s : thread[%x,%x] user buffer size %x too large\n", 163 __FUNCTION__ , process->pid, this->trdid, count ); 164 #endif 165 this->errno = EINVAL; 166 return -1; 167 } 168 155 else if( type == INODE_TYPE_DEV ) // write to TXT device 156 { 169 157 // move count bytes to device 170 158 nbytes = devfs_user_move( false, // from buffer to device … … 175 163 else // not FILE and not DEV 176 164 { 177 nbytes = 0; 178 assert( false , "file type %d non supported\n", type ); 165 166 #if DEBUG_SYSCALLS_ERROR 167 printk("\n[ERROR] in %s : thread[%x,%x] / illegal inode type %\n", 168 __FUNCTION__, vfs_inode_type_str( type ) ); 169 #endif 170 this->errno = EBADFD; 171 return -1; 179 172 } 180 173 … … 186 179 __FUNCTION__ , process->pid, this->trdid, file_id ); 187 180 #endif 188 this->errno = error;181 this->errno = EIO; 189 182 return -1; 190 183 } -
trunk/kernel/syscalls/syscalls.h
r584 r594 208 208 * [13] This function map physical memory (or a file) in the calling thread virtual space. 209 209 * The <attr> argument is a pointer on a structure for arguments (see shared_syscalls.h). 210 * The user defined virtual address (MAP_FIXED flag) is not supported. 211 * TODO : the access rights checking is not implemented yet [AG] 212 * TODO : the Copy on Write for MAP_PRIVATE is not implemented yet [AG] 210 213 ****************************************************************************************** 211 214 * @ attr : pointer on attributes structure. … … 281 284 * [19] This function creates in the calling thread cluster an unnamed pipe, and two 282 285 * (read and write) file descriptors. 283 * TODO not implemented yet ...286 * TODO not implemented yet [AG] 284 287 ****************************************************************************************** 285 288 * @ file_id[0] : [out] read only file descriptor index. … … 497 500 * [38] This function returns in the <stat> structure, defined in the "shared_syscalls.h" 498 501 * file, various informations on the file/directory identified by the <pathname> argument. 502 * TODO only the <st_ino>, <st_mode>,<st_uid>,<st_gid>,<st_size> are set. 499 503 ****************************************************************************************** 500 504 * @ pathname : user pointer on file pathname.
Note: See TracChangeset
for help on using the changeset viewer.