Changeset 594 for trunk/kernel/syscalls/sys_mmap.c
- Timestamp:
- Nov 10, 2018, 2:33:26 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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
Note: See TracChangeset
for help on using the changeset viewer.