Changeset 204 for trunk/kernel/libk
- Timestamp:
- Jul 17, 2017, 8:42:59 AM (7 years ago)
- Location:
- trunk/kernel/libk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/libk/bits.h
r23 r204 30 30 31 31 /********************************************************************************************* 32 * These macros are NOT used by the bitma t, but can be useful in other contexts... [AG]32 * These macros are NOT used by the bitmap, but can be useful in other contexts... [AG] 33 33 *********************************************************************************************/ 34 34 -
trunk/kernel/libk/elf.c
r157 r204 75 75 /////////////////////////////////////////////////////////////////////////////////////// 76 76 // This function loads the .elf header in the buffer allocated by the caller. 77 /////////////////////////////////////////////////////////////////////////////////////// 77 78 // @ file : extended pointer on the remote file descriptor. 78 79 // @ buffer : pointer on buffer allocated by the caller. 79 80 // @ size : number of bytes to read. 80 81 /////////////////////////////////////////////////////////////////////////////////////// 81 static error_t elf_header_ read( xptr_t file_xp,82 static error_t elf_header_load( xptr_t file_xp, 82 83 void * buffer, 83 84 uint32_t size ) … … 114 115 } 115 116 return 0; 116 } 117 118 } // end elf_header_load() 117 119 118 120 /////////////////////////////////////////////////////////////////////////////////////// 119 121 // This function registers in the process VMM the CODE and DATA segments. 122 /////////////////////////////////////////////////////////////////////////////////////// 120 123 // @ file : extended pointer on the remote file descriptor. 121 124 // @ segs_base : local pointer on buffer containing the segments descriptors array … … 212 215 213 216 return 0; 214 } 217 218 } // end elf_segments_load() 215 219 216 220 /////////////////////////////////////////////// … … 218 222 process_t * process) 219 223 { 220 char path_copy[CONFIG_VFS_MAX_PATH_LENGTH];221 224 kmem_req_t req; // kmem request for program header 222 uint32_t length; // actual path length223 225 Elf32_Ehdr header; // local buffer for .elf header 224 226 void * segs_base; // pointer on buffer for segment descriptors array … … 229 231 error_t error; 230 232 231 // get path length from user space 232 length = hal_strlen_from_uspace( pathname ); 233 234 if( length >= CONFIG_VFS_MAX_PATH_LENGTH ) 235 { 236 printk("\n[ERROR] in %s : pathname length too long\n", __FUNCTION__ ); 237 return -1; 238 } 239 240 // make a local copy for pathname 241 hal_copy_from_uspace( path_copy , pathname , length+1 ); 233 elf_dmsg("\n[INFO] %s : enter for %s\n", __FUNCTION__ , pathname ); 234 235 // avoid GCC warning 236 file_xp = XPTR_NULL; 237 file_id = -1; 242 238 243 239 // open file 244 file_xp = XPTR_NULL; // avoid GCC warning245 file_id = -1;246 247 240 error = vfs_open( process->vfs_cwd_xp, 248 path _copy,241 pathname, 249 242 O_RDONLY, 250 243 0, … … 253 246 if( error ) 254 247 { 255 printk("\n[ERROR] in %s : failed to open executable file %s\n", 256 __FUNCTION__ , path_copy ); 257 return -1; 258 } 248 printk("\n[ERROR] in %s : failed to open file %s\n", __FUNCTION__ , pathname ); 249 return -1; 250 } 251 252 elf_dmsg("\n[INFO] %s : file %s open\n", __FUNCTION__ , pathname ); 259 253 260 254 // load header in local buffer 261 error = elf_header_ read( file_xp ,255 error = elf_header_load( file_xp , 262 256 &header, 263 257 sizeof(Elf32_Ehdr) ); 264 258 if( error ) 265 259 { 266 vfs_close( file_xp , file_id ); 267 return -1; 268 } 269 270 elf_dmsg("\n[INFO] %s loaded elf header for %s\n", __FUNCTION__ , path_copy ); 260 printk("\n[ERROR] in %s : cannot get header file %s\n", __FUNCTION__ , pathname ); 261 vfs_close( file_xp , file_id ); 262 return -1; 263 } 264 265 elf_dmsg("\n[INFO] %s : loaded elf header for %s\n", __FUNCTION__ , pathname ); 271 266 272 267 if( header.e_phnum == 0 ) … … 320 315 } 321 316 322 elf_dmsg("\n[INFO] %s loaded segments descriptors for %s \n", __FUNCTION__ , path _copy);317 elf_dmsg("\n[INFO] %s loaded segments descriptors for %s \n", __FUNCTION__ , pathname ); 323 318 324 319 // register loadable segments in process VMM … … 346 341 347 342 elf_dmsg("\n[INFO] %s successfully completed / entry point = %x for %s]\n", 348 __FUNCTION__, (uint32_t) header.e_entry , path _copy);343 __FUNCTION__, (uint32_t) header.e_entry , pathname ); 349 344 350 345 return 0; 351 } 352 346 347 } // end elf_load_process() 348 -
trunk/kernel/libk/elf.h
r158 r204 182 182 * It also registers the process entry point in VMM. 183 183 **************************************************************************************** 184 * @ pathname : .elf file pathname (in user space => must use hal_uspace API).184 * @ pathname : local pointer on .elf file pathname (in kernel space). 185 185 * @ process : local pointer on target process descriptor. 186 186 ***************************************************************************************/ -
trunk/kernel/libk/xhtab.c
r188 r204 76 76 // returns true if given name matches directory entry name. 77 77 //////////////////////////////////////////////////////////////////////////////////////////// 78 static bool_t xhtab_dentry_item_match_key( xptr_t item_xp,78 static bool_t xhtab_dentry_item_match_key( xptr_t item_xp, 79 79 void * key ) 80 80 { 81 vfs_dentry_t * dentry_ptr; 82 cxy_t dentry_cxy; 83 84 char name[CONFIG_VFS_MAX_NAME_LENGTH]; 81 char name[CONFIG_VFS_MAX_NAME_LENGTH]; 85 82 86 83 // get dentry cluster and local pointer 87 dentry_cxy = GET_CXY( item_xp );88 dentry_ptr = (vfs_dentry_t *)GET_PTR( item_xp );84 cxy_t dentry_cxy = GET_CXY( item_xp ); 85 vfs_dentry_t * dentry_ptr = (vfs_dentry_t *)GET_PTR( item_xp ); 89 86 90 87 // make a local copy of directory entry name … … 94 91 return( strcmp( name , (char*)key ) == 0 ); 95 92 } 96 93 94 //////////////////////////////////////////////////////////////////////////////////////////// 95 // This function print the item key, that is the name for a vfs_entry_t, 96 //////////////////////////////////////////////////////////////////////////////////////////// 97 // @ item_xp : extended pointer on item. 98 //////////////////////////////////////////////////////////////////////////////////////////// 99 static void xhtab_dentry_item_print_key( xptr_t item_xp ) 100 { 101 char name[CONFIG_VFS_MAX_NAME_LENGTH]; 102 103 // get dentry cluster and local pointer 104 cxy_t dentry_cxy = GET_CXY( item_xp ); 105 vfs_dentry_t * dentry_ptr = (vfs_dentry_t *)GET_PTR( item_xp ); 106 107 // make a local copy of directory entry name 108 hal_remote_strcpy( XPTR( local_cxy , name ) , 109 XPTR( dentry_cxy , &dentry_ptr->name ) ); 110 111 // print dentry name 112 printk("%s , ", name ); 113 } 114 97 115 //////////////////////////////////////////////////////////////////////////////////////// 98 116 // Generic access functions … … 108 126 remote_rwlock_init( XPTR( local_cxy , &xhtab->lock) ); 109 127 110 xhtab->items = 0; 128 xhtab->items = 0; 129 xhtab->current_index = 0; 130 xhtab->current_xlist_xp = XPTR_NULL; 111 131 112 132 if( type == XHTAB_DENTRY_TYPE ) … … 115 135 xhtab->index_from_key = &xhtab_dentry_index_from_key; 116 136 xhtab->item_from_xlist = &xhtab_dentry_item_from_xlist; 137 xhtab->item_print_key = &xhtab_dentry_item_print_key; 117 138 } 118 139 else … … 134 155 void * key ) 135 156 { 136 xptr_t xlist_xp; // xlist_entry_t (iterator) 137 xptr_t item_xp; // associated item 138 xhtab_t * xhtab_ptr; // hash table local pointer 139 cxy_t xhtab_cxy; // hash table cluster 157 xptr_t xlist_xp; // xlist_entry_t (iterator) 158 xptr_t item_xp; // associated item 159 xhtab_t * xhtab_ptr; // hash table local pointer 160 cxy_t xhtab_cxy; // hash table cluster 161 item_from_xlist_t * item_from_xlist; // function pointer 162 item_match_key_t * item_match_key; // function pointer 140 163 141 164 // get hash table cluster and local pointer 142 165 xhtab_cxy = GET_CXY( xhtab_xp ); 143 166 xhtab_ptr = (xhtab_t *)GET_PTR( xhtab_xp ); 167 168 // get pointer on "item_from_xlist" function 169 item_from_xlist = (item_from_xlist_t *)hal_remote_lpt( XPTR( xhtab_cxy , 170 &xhtab_ptr->item_from_xlist ) ); 171 // get pointer on "item_match_key" function 172 item_match_key = (item_match_key_t *)hal_remote_lpt( XPTR( xhtab_cxy , 173 &xhtab_ptr->item_match_key ) ); 144 174 145 175 // scan sub-list[index] … … 147 177 { 148 178 // get extended pointer on item containing the xlist entry 149 item_xp = xhtab_ptr->item_from_xlist( xlist_xp );179 item_xp = item_from_xlist( xlist_xp ); 150 180 151 181 // check matching 152 if( xhtab_ptr->item_match_key( item_xp , key ) ) return item_xp;182 if( item_match_key( item_xp , key ) ) return item_xp; 153 183 } 154 184 155 185 // No matching item found 156 186 return XPTR_NULL; 157 } 187 188 } // end xhtab_scan() 158 189 159 190 /////////////////////////////////////// … … 162 193 xptr_t xlist_xp ) 163 194 { 164 // get xhtab cluster and local pointer 165 cxy_t xhtab_cxy = GET_CXY( xhtab_xp ); 166 xhtab_t * xhtab_ptr = (xhtab_t *)GET_PTR( xhtab_xp ); 167 195 xptr_t item_xp; 196 uint32_t index; 197 cxy_t xhtab_cxy; 198 xhtab_t * xhtab_ptr; 199 index_from_key_t * index_from_key; // function pointer 200 201 // get xhtab cluster and local pointer 202 xhtab_cxy = GET_CXY( xhtab_xp ); 203 xhtab_ptr = (xhtab_t *)GET_PTR( xhtab_xp ); 204 205 // get pointer on "index_from_key" function 206 index_from_key = (index_from_key_t *)hal_remote_lpt( XPTR( xhtab_cxy , 207 &xhtab_ptr->index_from_key ) ); 168 208 // compute index from key 169 uint32_t index = xhtab_ptr->index_from_key( key );209 index = index_from_key( key ); 170 210 171 211 // take the lock protecting hash table … … 173 213 174 214 // search a matching item 175 xptr_titem_xp = xhtab_scan( xhtab_xp , index , key );215 item_xp = xhtab_scan( xhtab_xp , index , key ); 176 216 177 217 if( item_xp != XPTR_NULL ) // error if found … … 202 242 xptr_t xlist_entry_xp ) 203 243 { 204 // get xhtab cluster and local pointer 205 cxy_t xhtab_cxy = GET_CXY( xhtab_xp ); 206 xhtab_t * xhtab_ptr = (xhtab_t *)GET_PTR( xhtab_xp ); 207 244 xptr_t item_xp; 245 uint32_t index; 246 cxy_t xhtab_cxy; 247 xhtab_t * xhtab_ptr; 248 index_from_key_t * index_from_key; // function pointer 249 250 // get xhtab cluster and local pointer 251 xhtab_cxy = GET_CXY( xhtab_xp ); 252 xhtab_ptr = (xhtab_t *)GET_PTR( xhtab_xp ); 253 254 // get pointer on "index_from_key" function 255 index_from_key = (index_from_key_t *)hal_remote_lpt( XPTR( xhtab_cxy , 256 &xhtab_ptr->index_from_key ) ); 208 257 // compute index from key 209 uint32_t index = xhtab_ptr->index_from_key( key );258 index = index_from_key( key ); 210 259 211 260 // take the lock protecting hash table … … 213 262 214 263 // get extended pointer on item to remove 215 xptr_titem_xp = xhtab_scan( xhtab_xp , index , key );264 item_xp = xhtab_scan( xhtab_xp , index , key ); 216 265 217 266 if( item_xp == XPTR_NULL ) // error if not found … … 241 290 void * key ) 242 291 { 243 xptr_t item_xp; 244 245 // get xhtab cluster and local pointer 246 cxy_t xhtab_cxy = GET_CXY( xhtab_xp ); 247 xhtab_t * xhtab_ptr = (xhtab_t *)GET_PTR( xhtab_xp ); 248 292 xptr_t item_xp; 293 uint32_t index; 294 cxy_t xhtab_cxy; 295 xhtab_t * xhtab_ptr; 296 index_from_key_t * index_from_key; // function pointer 297 298 // get xhtab cluster and local pointer 299 xhtab_cxy = GET_CXY( xhtab_xp ); 300 xhtab_ptr = (xhtab_t *)GET_PTR( xhtab_xp ); 301 302 // get pointer on "index_from_key" function 303 index_from_key = (index_from_key_t *)hal_remote_lpt( XPTR( xhtab_cxy , 304 &xhtab_ptr->index_from_key ) ); 249 305 // compute index from key 250 uint32_t index = xhtab_ptr->index_from_key( key );306 index = index_from_key( key ); 251 307 252 308 // take the lock protecting hash table … … 288 344 xptr_t xhtab_get_first( xptr_t xhtab_xp ) 289 345 { 290 uint32_t index; 291 xptr_t xlist_xp; 292 xptr_t item_xp; 293 xptr_t root_xp; 294 295 // get xhtab cluster and local pointer 296 cxy_t xhtab_cxy = GET_CXY( xhtab_xp ); 297 xhtab_t * xhtab_ptr = (xhtab_t *)GET_PTR( xhtab_xp ); 298 346 uint32_t index; 347 cxy_t xhtab_cxy; 348 xhtab_t * xhtab_ptr; 349 xptr_t xlist_xp; 350 xptr_t item_xp; 351 xptr_t root_xp; 352 item_from_xlist_t * item_from_xlist; // function pointer 353 354 // get xhtab cluster and local pointer 355 xhtab_cxy = GET_CXY( xhtab_xp ); 356 xhtab_ptr = (xhtab_t *)GET_PTR( xhtab_xp ); 357 358 // get pointer on "item_from_xlist" function 359 item_from_xlist = (item_from_xlist_t *)hal_remote_lpt( XPTR( xhtab_cxy , 360 &xhtab_ptr->item_from_xlist ) ); 299 361 //loop on subsets 300 362 for( index = 0 ; index < XHASHTAB_SIZE ; index++ ) … … 309 371 { 310 372 // get extended pointer on item containing the xlist entry 311 item_xp = xhtab_ptr->item_from_xlist( xlist_xp );373 item_xp = item_from_xlist( xlist_xp ); 312 374 313 375 // register item in hash table header … … 327 389 xptr_t xhtab_get_next( xptr_t xhtab_xp ) 328 390 { 329 uint32_t index; 330 xptr_t xlist_xp; 331 xptr_t item_xp; 332 xptr_t root_xp; 391 uint32_t index; 392 cxy_t xhtab_cxy; 393 xhtab_t * xhtab_ptr; 394 xptr_t xlist_xp; 395 xptr_t item_xp; 396 xptr_t root_xp; 397 item_from_xlist_t * item_from_xlist; // function pointer 333 398 334 399 uint32_t current_index; … … 336 401 337 402 // get xhtab cluster and local pointer 338 cxy_txhtab_cxy = GET_CXY( xhtab_xp );339 xhtab_ t * xhtab_ptr = (xhtab_t *)GET_PTR( xhtab_xp );403 xhtab_cxy = GET_CXY( xhtab_xp ); 404 xhtab_ptr = (xhtab_t *)GET_PTR( xhtab_xp ); 340 405 341 406 // get current item pointers … … 343 408 current_xlist_xp = hal_remote_lwd( XPTR( xhtab_cxy , &xhtab_ptr->current_xlist_xp ) ); 344 409 410 // get pointer on "item_from_xlist" function 411 item_from_xlist = (item_from_xlist_t *)hal_remote_lpt( XPTR( xhtab_cxy , 412 &xhtab_ptr->item_from_xlist ) ); 345 413 //loop on subsets 346 414 for( index = current_index ; index < XHASHTAB_SIZE ; index++ ) … … 350 418 351 419 // get next item 352 xlist_xp = xlist_next( root_xp , current_xlist_xp ); 420 if( index == current_index ) xlist_xp = xlist_next( root_xp , current_xlist_xp ); 421 else xlist_xp = xlist_next( root_xp , root_xp ); 353 422 354 423 if( xlist_xp != XPTR_NULL ) // next item found 355 424 { 356 425 // get extended pointer on item containing the xlist entry 357 item_xp = xhtab_ptr->item_from_xlist( xlist_xp );426 item_xp = item_from_xlist( xlist_xp ); 358 427 359 428 // register item in hash table header … … 370 439 } // end xhtab_get_next() 371 440 372 441 ///////////////////////////////////// 442 void xhtab_display( xptr_t xhtab_xp ) 443 { 444 uint32_t index; 445 cxy_t xhtab_cxy; 446 xhtab_t * xhtab_ptr; 447 xptr_t root_xp; 448 xptr_t iter_xp; 449 xptr_t item_xp; 450 item_from_xlist_t * item_from_xlist; // function pointer 451 item_print_key_t * item_print_key; // function pointer 452 453 // get xhtab cluster and local pointer 454 xhtab_cxy = GET_CXY( xhtab_xp ); 455 xhtab_ptr = (xhtab_t *)GET_PTR( xhtab_xp ); 456 457 // get pointer on "item_from_xlist" function 458 item_from_xlist = (item_from_xlist_t *)hal_remote_lpt( XPTR( xhtab_cxy , 459 &xhtab_ptr->item_from_xlist ) ); 460 // get pointer on "item_print_key" function 461 item_print_key = (item_print_key_t *)hal_remote_lpt( XPTR( xhtab_cxy , 462 &xhtab_ptr->item_print_key ) ); 463 //loop on subsets 464 for( index = 0 ; index < XHASHTAB_SIZE ; index++ ) 465 { 466 printk(" index = %d : ", index ); 467 468 // get root of subset 469 root_xp = XPTR( xhtab_cxy , &xhtab_ptr->roots[index] ); 470 471 // loop on xlist 472 XLIST_FOREACH( root_xp , iter_xp ) 473 { 474 // get item from xlist 475 item_xp = item_from_xlist( iter_xp ); 476 477 // print item identifier 478 item_print_key( item_xp ); 479 } 480 481 printk("\n"); 482 } 483 } // end xhtab_display() -
trunk/kernel/libk/xhtab.h
r188 r204 36 36 // It can be accessed by any thread, running in any cluster. 37 37 // It is generic as it can be used to register various types of items. 38 // The main goal is to speedup search by key fora large number of items of same type.38 // The main goal is to speedup search by key in a large number of items of same type. 39 39 // For this purpose the set of all registered items is split in several subsets. 40 40 // Each subset is organised as an embedded double linked lists. 41 41 // - an item is uniquely identified by a <key>, that is a single uint32_t value. 42 // - From the <key> value, the hash table uses an item type specific xhtab_index() function,43 // to compute an <index> value, defining a subset of registered items.42 // - From the <key> value, the hash table uses an item type specific xhtab_index() 43 // function, to compute an <index> value, defining a subset of registered items. 44 44 // - to discriminate between items that have the same <index>, the hash table makes 45 // an associative search in subset.45 // an associative search on the key in subset. 46 46 // - Each registered item is a structure, that must contain an embedded xlist_entry, 47 47 // that is part of the xlist implementing the subset. 48 48 // 49 // A total order is defined for all registered itemsby the increasing index values,50 // and for each index value by the position in the partial xlist.49 // For all registered items, a total order is defined by the increasing index values, 50 // and for each index value, by the position in the partial xlist. 51 51 // This order is used by the two functions xhtab_get_first() and xhtab_get_next(), that 52 52 // are used to scan all registered items. The two "current_index" and "current_xlist_xp" … … 54 54 // 55 55 // Implementation Note: 56 // For each supported item type ***, you must define the threeitem-type-specific56 // For each supported item type ***, you must define four item-type-specific 57 57 // functions specified below, and you must update the xhtab_init() function 58 58 // and the xhtab_item_type_t. 59 59 /////////////////////////////////////////////////////////////////////////////////////////// 60 60 61 #define XHASHTAB_SIZE 64// number of subsets61 #define XHASHTAB_SIZE 8 // number of subsets 62 62 63 63 /****************************************************************************************** 64 * This define the three item type specific function prototypes. 64 * This define the four item_type_specific function prototypes that must be defined 65 * for each item type. 65 66 *****************************************************************************************/ 66 67 67 typedef bool_t xhtab_match_t ( xptr_t item_xp , void * key ); 68 typedef xptr_t xhtab_item_t ( xptr_t xlist_xp ); 69 typedef uint32_t xhtab_index_t ( void * key ); 68 typedef bool_t (item_match_key_t) ( xptr_t item_xp , void * key ); 69 typedef xptr_t (item_from_xlist_t) ( xptr_t xlist_xp ); 70 typedef uint32_t (index_from_key_t) ( void * key ); 71 typedef void (item_print_key_t) ( xptr_t item_xp ); 70 72 71 73 /****************************************************************************************** … … 85 87 typedef struct xhtab_s 86 88 { 87 xlist_entry_t roots[XHASHTAB_SIZE]; /*! array of roots of xlist */ 88 xhtab_index_t * index_from_key; /*! item specific function */ 89 xhtab_match_t * item_match_key; /*! item specific function */ 90 xhtab_item_t * item_from_xlist; /*! item specific function */ 91 uint32_t items; /*! number of registered items */ 92 remote_rwlock_t lock; /*! lock protecting hash table accesses */ 93 uint32_t current_index; /*! current item subset index */ 94 xptr_t * current_xlist_xp; /*! xptr on current item xlist entry */ 89 xlist_entry_t roots[XHASHTAB_SIZE]; /*! array of roots of xlist */ 90 index_from_key_t * index_from_key; /*! item specific function pointer */ 91 item_match_key_t * item_match_key; /*! item specific function pointer */ 92 item_from_xlist_t * item_from_xlist; /*! item specific function pointer */ 93 item_print_key_t * item_print_key; /*! item specific function pointer */ 94 uint32_t items; /*! number of registered items */ 95 remote_rwlock_t lock; /*! lock protecting hash table accesses */ 96 uint32_t current_index; /*! current item subset index */ 97 xptr_t current_xlist_xp; /*! xptr on current item xlist entry */ 95 98 } 96 99 xhtab_t; … … 100 103 * The initialisation must be done by a thread running in cluster containing the table. 101 104 ****************************************************************************************** 102 * @ xhtab : local pointer on local xhtab to be initialized.103 * @ type : item type (see above).105 * @ xhtab : local pointer on local xhtab to be initialized. 106 * @ type : item type (see above). 104 107 *****************************************************************************************/ 105 108 void xhtab_init( xhtab_t * xhtab, … … 176 179 xptr_t xhtab_get_next( xptr_t xhtab_xp ); 177 180 178 181 /****************************************************************************************** 182 * This function displays the full content of an xhtab. 183 ****************************************************************************************** 184 * @ xhtab_xp : extended pointer on hash table. 185 *****************************************************************************************/ 186 void xhtab_display( xptr_t xhtab_xp ); 179 187 180 188 #endif /* _XHTAB_H_ */
Note: See TracChangeset
for help on using the changeset viewer.