Changes in / [74a165cc:accdf882] in mainline
- Location:
- kernel/generic
- Files:
-
- 19 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/include/cap/cap.h
r74a165cc raccdf882 37 37 38 38 #include <abi/cap.h> 39 #include <typedefs.h> 40 #include <adt/list.h> 41 #include <adt/hash.h> 39 42 #include <adt/hash_table.h> 40 #include < adt/hash.h>41 #include < adt/list.h>43 #include <lib/ra.h> 44 #include <synch/mutex.h> 42 45 #include <atomic.h> 43 #include <lib/ra.h>44 #include <lib/refcount.h>45 #include <synch/mutex.h>46 #include <typedefs.h>47 46 48 47 typedef enum { … … 60 59 } kobject_type_t; 61 60 62 struct kobject; 61 struct task; 62 63 struct call; 64 struct irq; 65 struct phone; 66 struct waitq; 63 67 64 68 typedef struct kobject_ops { 65 void (*destroy)( struct kobject*);69 void (*destroy)(void *); 66 70 } kobject_ops_t; 67 71 … … 72 76 /* 73 77 * Everything in kobject_t except for the atomic reference count, the capability 74 * list and its lock is im mutable.78 * list and its lock is imutable. 75 79 */ 76 80 typedef struct kobject { 77 81 kobject_type_t type; 78 atomic_ refcount_t refcnt;82 atomic_size_t refcnt; 79 83 80 84 /** Mutex protecting caps_list */ … … 82 86 /** List of published capabilities associated with the kobject */ 83 87 list_t caps_list; 88 89 union { 90 void *raw; 91 struct call *call; 92 struct irq *irq; 93 struct phone *phone; 94 struct waitq *waitq; 95 }; 84 96 } kobject_t; 85 97 … … 117 129 extern errno_t caps_task_alloc(struct task *); 118 130 extern void caps_task_free(struct task *); 119 extern void caps_task_clear(struct task *task); 120 extern errno_t caps_task_init(struct task *); 131 extern void caps_task_init(struct task *); 121 132 extern bool caps_apply_to_kobject_type(struct task *, kobject_type_t, 122 133 bool (*)(cap_t *, void *), void *); … … 128 139 extern void cap_free(struct task *, cap_handle_t); 129 140 130 extern void kobject_initialize(kobject_t *, kobject_type_t); 141 extern kobject_t *kobject_alloc(unsigned int); 142 extern void kobject_free(kobject_t *); 143 extern void kobject_initialize(kobject_t *, kobject_type_t, void *); 131 144 extern kobject_t *kobject_get(struct task *, cap_handle_t, kobject_type_t); 132 145 extern void kobject_add_ref(kobject_t *); -
kernel/generic/include/ddi/irq.h
r74a165cc raccdf882 132 132 extern hash_table_t irq_uspace_hash_table; 133 133 134 extern slab_cache_t *irq_cache; 135 134 136 extern inr_t last_inr; 135 137 -
kernel/generic/include/ipc/ipc.h
r74a165cc raccdf882 74 74 /** User-defined label */ 75 75 sysarg_t label; 76 kobject_t kobject;76 kobject_t *kobject; 77 77 } phone_t; 78 78 … … 108 108 109 109 typedef struct call { 110 kobject_t kobject;110 kobject_t *kobject; 111 111 112 112 /** … … 169 169 170 170 extern slab_cache_t *phone_cache; 171 extern slab_cache_t *irq_cache;172 171 173 172 extern answerbox_t *ipc_box_0; 174 173 175 174 extern kobject_ops_t call_kobject_ops; 176 177 static inline phone_t *phone_from_kobject(kobject_t *kobject)178 {179 if (kobject)180 return ((void *) kobject) - offsetof(phone_t, kobject);181 else182 return NULL;183 }184 185 static inline call_t *call_from_kobject(kobject_t *kobject)186 {187 if (kobject)188 return ((void *) kobject) - offsetof(call_t, kobject);189 else190 return NULL;191 }192 175 193 176 extern void ipc_init(void); -
kernel/generic/include/ipc/irq.h
r74a165cc raccdf882 50 50 extern kobject_ops_t irq_kobject_ops; 51 51 52 typedef struct {53 kobject_t kobject;54 irq_t irq;55 } irq_kobject_t;56 57 static inline irq_t *irq_from_kobject(kobject_t *kobject)58 {59 if (kobject) {60 return &((irq_kobject_t *) kobject)->irq;61 } else {62 return NULL;63 }64 }65 66 52 extern irq_ownership_t ipc_irq_top_half_claim(irq_t *); 67 53 extern void ipc_irq_top_half_handler(irq_t *); -
kernel/generic/include/synch/syswaitq.h
r74a165cc raccdf882 44 44 extern void sys_waitq_init(void); 45 45 46 extern void sys_waitq_task_cleanup(void); 47 46 48 extern sys_errno_t sys_waitq_create(uspace_ptr_cap_waitq_handle_t); 47 49 extern sys_errno_t sys_waitq_sleep(cap_waitq_handle_t, uint32_t, unsigned int); -
kernel/generic/src/cap/cap.c
r74a165cc raccdf882 93 93 94 94 #define CAPS_START ((intptr_t) CAP_NIL + 1) 95 #define CAPS_ LAST ((intptr_t) INT_MAX - 1)96 #define CAPS_ SIZE (CAPS_LAST - CAPS_START +1)95 #define CAPS_SIZE (INT_MAX - (int) CAPS_START) 96 #define CAPS_LAST (CAPS_SIZE - 1) 97 97 98 98 static slab_cache_t *cap_cache; 99 static slab_cache_t *kobject_cache; 99 100 100 101 kobject_ops_t *kobject_ops[KOBJECT_TYPE_MAX] = { … … 124 125 } 125 126 126 static void caps_remove_callback(ht_link_t *item)127 {128 cap_t *cap = hash_table_get_inst(item, cap_t, caps_link);129 130 if (cap->kobject) {131 kobject_t *kobj = cap->kobject;132 133 mutex_lock(&kobj->caps_list_lock);134 cap->kobject = NULL;135 list_remove(&cap->kobj_link);136 mutex_unlock(&kobj->caps_list_lock);137 138 kobject_put(kobj);139 }140 141 list_remove(&cap->type_link);142 143 slab_free(cap_cache, cap);144 }145 146 127 static const hash_table_ops_t caps_ops = { 147 128 .hash = caps_hash, 148 129 .key_hash = caps_key_hash, 149 .key_equal = caps_key_equal, 150 .remove_callback = caps_remove_callback, 130 .key_equal = caps_key_equal 151 131 }; 152 132 … … 155 135 cap_cache = slab_cache_create("cap_t", sizeof(cap_t), 0, NULL, 156 136 NULL, 0); 137 kobject_cache = slab_cache_create("kobject_t", sizeof(kobject_t), 0, 138 NULL, NULL, 0); 157 139 } 158 140 … … 166 148 if (!task->cap_info) 167 149 return ENOMEM; 168 169 if (!hash_table_create(&task->cap_info->caps, 0, 0, &caps_ops)) { 170 free(task->cap_info); 171 return ENOMEM; 172 } 173 150 task->cap_info->handles = ra_arena_create(); 151 if (!task->cap_info->handles) 152 goto error_handles; 153 if (!ra_span_add(task->cap_info->handles, CAPS_START, CAPS_SIZE)) 154 goto error_span; 155 if (!hash_table_create(&task->cap_info->caps, 0, 0, &caps_ops)) 156 goto error_span; 157 return EOK; 158 159 error_span: 160 ra_arena_destroy(task->cap_info->handles); 161 error_handles: 162 free(task->cap_info); 163 return ENOMEM; 164 } 165 166 /** Initialize the capability info structure 167 * 168 * @param task Task for which to initialize the info structure. 169 */ 170 void caps_task_init(task_t *task) 171 { 174 172 mutex_initialize(&task->cap_info->lock, MUTEX_RECURSIVE); 175 176 task->cap_info->handles = NULL;177 173 178 174 for (kobject_type_t t = 0; t < KOBJECT_TYPE_MAX; t++) 179 175 list_initialize(&task->cap_info->type_list[t]); 180 181 return EOK;182 }183 184 /** Initialize the capability info structure185 *186 * @param task Task for which to initialize the info structure.187 */188 errno_t caps_task_init(task_t *task)189 {190 assert(task->cap_info);191 assert(!task->cap_info->handles);192 193 task->cap_info->handles = ra_arena_create();194 if (!task->cap_info->handles)195 return ENOMEM;196 197 if (!ra_span_add(task->cap_info->handles, CAPS_START, CAPS_SIZE)) {198 ra_arena_destroy(task->cap_info->handles);199 return ENOMEM;200 }201 202 return EOK;203 }204 205 void caps_task_clear(task_t *task)206 {207 mutex_lock(&task->cap_info->lock);208 209 hash_table_clear(&task->cap_info->caps);210 211 if (task->cap_info->handles) {212 ra_arena_destroy(task->cap_info->handles);213 task->cap_info->handles = NULL;214 }215 216 for (kobject_type_t t = 0; t < KOBJECT_TYPE_MAX; t++)217 list_initialize(&task->cap_info->type_list[t]);218 219 mutex_unlock(&task->cap_info->lock);220 176 } 221 177 … … 227 183 { 228 184 hash_table_destroy(&task->cap_info->caps); 229 230 if (task->cap_info->handles) 231 ra_arena_destroy(task->cap_info->handles); 232 185 ra_arena_destroy(task->cap_info->handles); 233 186 free(task->cap_info); 234 187 } … … 347 300 cap_publish(task_t *task, cap_handle_t handle, kobject_t *kobj) 348 301 { 349 mutex_lock(&task->cap_info->lock);350 302 mutex_lock(&kobj->caps_list_lock); 303 mutex_lock(&task->cap_info->lock); 351 304 cap_t *cap = cap_get(task, handle, CAP_STATE_ALLOCATED); 352 305 assert(cap); … … 356 309 list_append(&cap->kobj_link, &kobj->caps_list); 357 310 list_append(&cap->type_link, &task->cap_info->type_list[kobj->type]); 311 mutex_unlock(&task->cap_info->lock); 358 312 mutex_unlock(&kobj->caps_list_lock); 359 mutex_unlock(&task->cap_info->lock);360 313 } 361 314 … … 387 340 kobject_t *kobj = NULL; 388 341 342 restart: 389 343 mutex_lock(&task->cap_info->lock); 390 344 cap_t *cap = cap_get(task, handle, CAP_STATE_PUBLISHED); … … 393 347 /* Hand over cap's reference to kobj */ 394 348 kobj = cap->kobject; 395 396 mutex_lock(&kobj->caps_list_lock); 349 if (mutex_trylock(&kobj->caps_list_lock) != EOK) { 350 mutex_unlock(&task->cap_info->lock); 351 kobj = NULL; 352 goto restart; 353 } 397 354 cap_unpublish_unsafe(cap); 398 355 mutex_unlock(&kobj->caps_list_lock); … … 419 376 { 420 377 mutex_lock(&kobj->caps_list_lock); 421 422 while (!list_empty(&kobj->caps_list)) { 423 cap_t *cap = list_get_instance(list_first(&kobj->caps_list), cap_t, kobj_link); 424 425 /* We're trying to acquire the two locks in reverse order. */ 426 if (mutex_trylock(&cap->task->cap_info->lock) != EOK) { 427 mutex_unlock(&kobj->caps_list_lock); 428 mutex_lock(&kobj->caps_list_lock); 429 continue; 430 } 431 378 list_foreach_safe(kobj->caps_list, cur, hlp) { 379 cap_t *cap = list_get_instance(cur, cap_t, kobj_link); 380 mutex_lock(&cap->task->cap_info->lock); 432 381 cap_unpublish_unsafe(cap); 433 382 /* Drop the reference for the unpublished capability */ 434 383 kobject_put(kobj); 435 436 384 mutex_unlock(&cap->task->cap_info->lock); 437 385 } 438 439 386 mutex_unlock(&kobj->caps_list_lock); 440 387 } … … 457 404 hash_table_remove_item(&task->cap_info->caps, &cap->caps_link); 458 405 ra_free(task->cap_info->handles, cap_handle_raw(handle), 1); 459 mutex_unlock(&task->cap_info->lock); 406 slab_free(cap_cache, cap); 407 mutex_unlock(&task->cap_info->lock); 408 } 409 410 kobject_t *kobject_alloc(unsigned int flags) 411 { 412 return slab_alloc(kobject_cache, flags); 413 } 414 415 void kobject_free(kobject_t *kobj) 416 { 417 slab_free(kobject_cache, kobj); 460 418 } 461 419 … … 464 422 * @param kobj Kernel object to initialize. 465 423 * @param type Type of the kernel object. 466 */ 467 void kobject_initialize(kobject_t *kobj, kobject_type_t type) 468 { 469 refcount_init(&kobj->refcnt); 424 * @param raw Raw pointer to the encapsulated object. 425 */ 426 void kobject_initialize(kobject_t *kobj, kobject_type_t type, void *raw) 427 { 428 atomic_store(&kobj->refcnt, 1); 470 429 471 430 mutex_initialize(&kobj->caps_list_lock, MUTEX_PASSIVE); … … 473 432 474 433 kobj->type = type; 434 kobj->raw = raw; 475 435 } 476 436 … … 495 455 if (cap->kobject->type == type) { 496 456 kobj = cap->kobject; 497 refcount_up(&kobj->refcnt);457 atomic_inc(&kobj->refcnt); 498 458 } 499 459 } … … 509 469 void kobject_add_ref(kobject_t *kobj) 510 470 { 511 refcount_up(&kobj->refcnt);471 atomic_inc(&kobj->refcnt); 512 472 } 513 473 … … 521 481 void kobject_put(kobject_t *kobj) 522 482 { 523 if (refcount_down(&kobj->refcnt)) { 524 KOBJECT_OP(kobj)->destroy(kobj); 483 if (atomic_postdec(&kobj->refcnt) == 1) { 484 KOBJECT_OP(kobj)->destroy(kobj->raw); 485 kobject_free(kobj); 525 486 } 526 487 } -
kernel/generic/src/ddi/irq.c
r74a165cc raccdf882 50 50 #include <arch.h> 51 51 52 slab_cache_t *irq_cache = NULL; 53 52 54 /** Spinlock protecting the kernel IRQ hash table 53 55 * … … 94 96 { 95 97 last_inr = inrs - 1; 98 99 irq_cache = slab_cache_create("irq_t", sizeof(irq_t), 0, NULL, NULL, 100 FRAME_ATOMIC); 101 assert(irq_cache); 96 102 97 103 hash_table_create(&irq_uspace_hash_table, chains, 0, &irq_ht_ops); -
kernel/generic/src/ipc/ipc.c
r74a165cc raccdf882 71 71 static slab_cache_t *answerbox_cache; 72 72 73 slab_cache_t *irq_cache = NULL;74 73 slab_cache_t *phone_cache = NULL; 75 74 … … 88 87 call->callerbox = NULL; 89 88 call->buffer = NULL; 90 kobject_initialize(&call->kobject, KOBJECT_TYPE_CALL); 91 } 92 93 static void call_destroy(kobject_t *arg) 94 { 95 call_t *call = call_from_kobject(arg); 89 } 90 91 static void call_destroy(void *arg) 92 { 93 call_t *call = (call_t *) arg; 96 94 97 95 if (call->buffer) 98 96 free(call->buffer); 99 97 if (call->caller_phone) 100 kobject_put( &call->caller_phone->kobject);98 kobject_put(call->caller_phone->kobject); 101 99 slab_free(call_cache, call); 102 100 } … … 116 114 call_t *ipc_call_alloc(void) 117 115 { 116 // TODO: Allocate call and kobject in single allocation 117 118 118 call_t *call = slab_alloc(call_cache, FRAME_ATOMIC); 119 119 if (!call) 120 120 return NULL; 121 121 122 kobject_t *kobj = kobject_alloc(0); 123 if (!kobj) { 124 slab_free(call_cache, call); 125 return NULL; 126 } 127 122 128 _ipc_call_init(call); 129 kobject_initialize(kobj, KOBJECT_TYPE_CALL, call); 130 call->kobject = kobj; 123 131 124 132 return call; … … 173 181 if (!connected) { 174 182 /* We still have phone->kobject's reference; drop it */ 175 kobject_put( &phone->kobject);183 kobject_put(phone->kobject); 176 184 } 177 185 … … 193 201 atomic_store(&phone->active_calls, 0); 194 202 phone->label = 0; 195 kobject_initialize(&phone->kobject, KOBJECT_TYPE_PHONE);203 phone->kobject = NULL; 196 204 } 197 205 … … 286 294 /* This is a forgotten call and call->sender is not valid. */ 287 295 spinlock_unlock(&call->forget_lock); 288 kobject_put( &call->kobject);296 kobject_put(call->kobject); 289 297 return; 290 298 } else { … … 344 352 345 353 call->caller_phone = phone; 346 kobject_add_ref( &phone->kobject);354 kobject_add_ref(phone->kobject); 347 355 348 356 if (preforget) { … … 354 362 else 355 363 atomic_inc(&caller->answerbox.active_calls); 356 kobject_add_ref( &phone->kobject);364 kobject_add_ref(phone->kobject); 357 365 call->sender = caller; 358 366 call->active = true; … … 471 479 472 480 /* Drop the answerbox reference */ 473 kobject_put( &phone->kobject);481 kobject_put(phone->kobject); 474 482 475 483 call_t *call = phone->hangup_call; … … 573 581 atomic_dec(&request->caller_phone->active_calls); 574 582 atomic_dec(&box->active_calls); 575 kobject_put( &request->caller_phone->kobject);583 kobject_put(request->caller_phone->kobject); 576 584 } else if (!list_empty(&box->calls)) { 577 585 /* Count received call */ … … 689 697 task_release(phone->caller); 690 698 691 kobject_put( &phone->kobject);699 kobject_put(phone->kobject); 692 700 693 701 /* Must start again */ … … 696 704 697 705 mutex_unlock(&phone->lock); 698 kobject_put( &phone->kobject);706 kobject_put(phone->kobject); 699 707 } 700 708 … … 720 728 * must hold a reference to it. 721 729 */ 722 kobject_add_ref( &call->kobject);730 kobject_add_ref(call->kobject); 723 731 724 732 spinlock_unlock(&call->forget_lock); … … 727 735 atomic_dec(&call->caller_phone->active_calls); 728 736 atomic_dec(&TASK->answerbox.active_calls); 729 kobject_put( &call->caller_phone->kobject);737 kobject_put(call->caller_phone->kobject); 730 738 731 739 SYSIPC_OP(request_forget, call); 732 740 733 kobject_put( &call->kobject);741 kobject_put(call->kobject); 734 742 } 735 743 … … 769 777 static bool phone_cap_cleanup_cb(cap_t *cap, void *arg) 770 778 { 771 ipc_phone_hangup( phone_from_kobject(cap->kobject));779 ipc_phone_hangup(cap->kobject->phone); 772 780 kobject_t *kobj = cap_unpublish(cap->task, cap->handle, 773 781 KOBJECT_TYPE_PHONE); … … 790 798 SYSIPC_OP(answer_process, call); 791 799 792 kobject_put( &call->kobject);800 kobject_put(call->kobject); 793 801 794 802 /* … … 884 892 answerbox_cache = slab_cache_create("answerbox_t", sizeof(answerbox_t), 885 893 0, NULL, NULL, 0); 886 irq_cache = slab_cache_create("irq_t", sizeof(irq_kobject_t),887 0, NULL, NULL, 0);888 894 } 889 895 … … 921 927 static bool print_task_phone_cb(cap_t *cap, void *arg) 922 928 { 923 phone_t *phone = phone_from_kobject(cap->kobject);929 phone_t *phone = cap->kobject->phone; 924 930 925 931 mutex_lock(&phone->lock); -
kernel/generic/src/ipc/ipcrsc.c
r74a165cc raccdf882 44 44 #include <stdlib.h> 45 45 46 static void phone_destroy( kobject_t*arg)46 static void phone_destroy(void *arg) 47 47 { 48 phone_t *phone = phone_from_kobject(arg);48 phone_t *phone = (phone_t *) arg; 49 49 if (phone->hangup_call) 50 kobject_put( &phone->hangup_call->kobject);50 kobject_put(phone->hangup_call->kobject); 51 51 slab_free(phone_cache, phone); 52 52 } … … 76 76 return ENOMEM; 77 77 } 78 78 kobject_t *kobj = kobject_alloc(FRAME_ATOMIC); 79 if (!kobj) { 80 cap_free(TASK, handle); 81 slab_free(phone_cache, phone); 82 return ENOMEM; 83 } 79 84 call_t *hcall = ipc_call_alloc(); 80 85 if (!hcall) { 81 86 cap_free(TASK, handle); 82 87 slab_free(phone_cache, phone); 88 free(kobj); 83 89 return ENOMEM; 84 90 } … … 88 94 phone->hangup_call = hcall; 89 95 96 kobject_initialize(kobj, KOBJECT_TYPE_PHONE, phone); 97 phone->kobject = kobj; 98 90 99 if (publish) 91 cap_publish(task, handle, &phone->kobject);100 cap_publish(task, handle, kobj); 92 101 93 102 *phandle = handle; 94 103 if (kobject) 95 *kobject = &phone->kobject;104 *kobject = kobj; 96 105 } 97 106 return rc; -
kernel/generic/src/ipc/irq.c
r74a165cc raccdf882 295 295 } 296 296 297 static void irq_destroy( kobject_t*arg)298 { 299 irq_ kobject_t *kobj = (irq_kobject_t *) arg;300 301 irq_hash_out( &kobj->irq);297 static void irq_destroy(void *arg) 298 { 299 irq_t *irq = (irq_t *) arg; 300 301 irq_hash_out(irq); 302 302 303 303 /* Free up the IRQ code and associated structures. */ 304 code_free( kobj->irq.notif_cfg.code);305 slab_free(irq_cache, kobj);304 code_free(irq->notif_cfg.code); 305 slab_free(irq_cache, irq); 306 306 } 307 307 … … 350 350 } 351 351 352 irq_ kobject_t *kobj =slab_alloc(irq_cache, FRAME_ATOMIC);353 if (! kobj) {352 irq_t *irq = (irq_t *) slab_alloc(irq_cache, FRAME_ATOMIC); 353 if (!irq) { 354 354 cap_free(TASK, handle); 355 355 return ENOMEM; 356 356 } 357 357 358 kobject_initialize(&kobj->kobject, KOBJECT_TYPE_IRQ); 359 360 irq_t *irq = &kobj->irq; 358 kobject_t *kobject = kobject_alloc(FRAME_ATOMIC); 359 if (!kobject) { 360 cap_free(TASK, handle); 361 slab_free(irq_cache, irq); 362 return ENOMEM; 363 } 361 364 362 365 irq_initialize(irq); … … 382 385 irq_spinlock_unlock(&irq_uspace_hash_table_lock, true); 383 386 384 cap_publish(TASK, handle, &kobj->kobject); 387 kobject_initialize(kobject, KOBJECT_TYPE_IRQ, irq); 388 cap_publish(TASK, handle, kobject); 385 389 386 390 return EOK; … … 401 405 return ENOENT; 402 406 403 assert( irq_from_kobject(kobj)->notif_cfg.answerbox == box);404 405 irq_hash_out( irq_from_kobject(kobj));407 assert(kobj->irq->notif_cfg.answerbox == box); 408 409 irq_hash_out(kobj->irq); 406 410 407 411 kobject_put(kobj); -
kernel/generic/src/ipc/kbox.c
r74a165cc raccdf882 242 242 } 243 243 244 phone_t *phone = phone_from_kobject(245 kobject_get(TASK, phone_handle, KOBJECT_TYPE_PHONE));244 kobject_t *phone_obj = kobject_get(TASK, phone_handle, 245 KOBJECT_TYPE_PHONE); 246 246 /* Connect the newly allocated phone to the kbox */ 247 247 /* Hand over phone_obj's reference to ipc_phone_connect() */ 248 (void) ipc_phone_connect(phone , &task->kb.box);248 (void) ipc_phone_connect(phone_obj->phone, &task->kb.box); 249 249 250 250 mutex_unlock(&task->kb.cleanup_lock); -
kernel/generic/src/ipc/ops/conctmeto.c
r74a165cc raccdf882 88 88 89 89 /* Set the recipient-assigned label */ 90 p hone_from_kobject(pobj)->label = ipc_get_arg5(&answer->data);90 pobj->phone->label = ipc_get_arg5(&answer->data); 91 91 92 92 /* Restore phone handle in answer's ARG5 */ … … 96 96 if (ipc_get_retval(&answer->data) == EOK) { 97 97 /* Hand over reference from pobj to the answerbox */ 98 (void) ipc_phone_connect(p hone_from_kobject(pobj), &TASK->answerbox);98 (void) ipc_phone_connect(pobj->phone, &TASK->answerbox); 99 99 } else { 100 100 /* Drop the extra reference */ -
kernel/generic/src/ipc/ops/concttome.c
r74a165cc raccdf882 49 49 * Set the sender-assigned label to the new phone. 50 50 */ 51 p hone_from_kobject(pobj)->label = ipc_get_arg5(&call->data);51 pobj->phone->label = ipc_get_arg5(&call->data); 52 52 } 53 53 call->priv = (sysarg_t) pobj; … … 88 88 kobject_add_ref(pobj); 89 89 90 if (ipc_phone_connect(p hone_from_kobject(pobj),90 if (ipc_phone_connect(pobj->phone, 91 91 &answer->sender->answerbox)) { 92 92 /* Pass the reference to the capability */ -
kernel/generic/src/ipc/ops/stchngath.c
r74a165cc raccdf882 45 45 task_t *other_task_s; 46 46 47 phone_t *sender_phone = phone_from_kobject(kobject_get(TASK,48 (cap_handle_t) ipc_get_arg5(&call->data), KOBJECT_TYPE_PHONE) );49 if (!sender_ phone)47 kobject_t *sender_obj = kobject_get(TASK, 48 (cap_handle_t) ipc_get_arg5(&call->data), KOBJECT_TYPE_PHONE); 49 if (!sender_obj) 50 50 return ENOENT; 51 51 52 mutex_lock(&sender_ phone->lock);53 if (sender_ phone->state != IPC_PHONE_CONNECTED) {54 mutex_unlock(&sender_ phone->lock);55 kobject_put( &sender_phone->kobject);52 mutex_lock(&sender_obj->phone->lock); 53 if (sender_obj->phone->state != IPC_PHONE_CONNECTED) { 54 mutex_unlock(&sender_obj->phone->lock); 55 kobject_put(sender_obj); 56 56 return EINVAL; 57 57 } 58 58 59 other_task_s = sender_ phone->callee->task;59 other_task_s = sender_obj->phone->callee->task; 60 60 61 mutex_unlock(&sender_ phone->lock);61 mutex_unlock(&sender_obj->phone->lock); 62 62 63 63 /* Remember the third party task hash. */ 64 64 ipc_set_arg5(&call->data, (sysarg_t) other_task_s); 65 65 66 kobject_put( &sender_phone->kobject);66 kobject_put(sender_obj); 67 67 return EOK; 68 68 } … … 77 77 task_t *other_task_r; 78 78 79 phone_t *recipient_phone = phone_from_kobject(kobject_get(TASK,79 kobject_t *recipient_obj = kobject_get(TASK, 80 80 (cap_handle_t) ipc_get_arg1(&answer->data), 81 KOBJECT_TYPE_PHONE) );82 if (!recipient_ phone) {81 KOBJECT_TYPE_PHONE); 82 if (!recipient_obj) { 83 83 ipc_set_retval(&answer->data, ENOENT); 84 84 return ENOENT; 85 85 } 86 86 87 mutex_lock(&recipient_ phone->lock);88 if (recipient_ phone->state != IPC_PHONE_CONNECTED) {89 mutex_unlock(&recipient_ phone->lock);87 mutex_lock(&recipient_obj->phone->lock); 88 if (recipient_obj->phone->state != IPC_PHONE_CONNECTED) { 89 mutex_unlock(&recipient_obj->phone->lock); 90 90 ipc_set_retval(&answer->data, EINVAL); 91 kobject_put( &recipient_phone->kobject);91 kobject_put(recipient_obj); 92 92 return EINVAL; 93 93 } 94 94 95 other_task_r = recipient_ phone->callee->task;95 other_task_r = recipient_obj->phone->callee->task; 96 96 other_task_s = (task_t *) ipc_get_arg5(olddata); 97 97 … … 114 114 } 115 115 116 mutex_unlock(&recipient_ phone->lock);117 kobject_put( &recipient_phone->kobject);116 mutex_unlock(&recipient_obj->phone->lock); 117 kobject_put(recipient_obj); 118 118 } 119 119 -
kernel/generic/src/ipc/sysipc.c
r74a165cc raccdf882 199 199 list_remove(&phone->link); 200 200 /* Drop callee->connected_phones reference */ 201 kobject_put( &phone->kobject);201 kobject_put(phone->kobject); 202 202 phone->state = IPC_PHONE_SLAMMED; 203 203 phone->label = 0; … … 273 273 ipc_req_internal(cap_phone_handle_t handle, ipc_data_t *data, sysarg_t priv) 274 274 { 275 phone_t *phone = phone_from_kobject( 276 kobject_get(TASK, handle, KOBJECT_TYPE_PHONE)); 277 if (!phone) 275 kobject_t *kobj = kobject_get(TASK, handle, KOBJECT_TYPE_PHONE); 276 if (!kobj->phone) 278 277 return ENOENT; 279 278 280 279 call_t *call = ipc_call_alloc(); 281 280 if (!call) { 282 kobject_put( &phone->kobject);281 kobject_put(kobj); 283 282 return ENOMEM; 284 283 } … … 287 286 memcpy(call->data.args, data->args, sizeof(data->args)); 288 287 289 errno_t rc = request_preprocess(call, phone);288 errno_t rc = request_preprocess(call, kobj->phone); 290 289 if (!rc) { 291 290 #ifdef CONFIG_UDEBUG … … 293 292 #endif 294 293 295 kobject_add_ref( &call->kobject);296 rc = ipc_call_sync( phone, call);294 kobject_add_ref(call->kobject); 295 rc = ipc_call_sync(kobj->phone, call); 297 296 spinlock_lock(&call->forget_lock); 298 297 bool forgotten = call->forget; 299 298 spinlock_unlock(&call->forget_lock); 300 kobject_put( &call->kobject);299 kobject_put(call->kobject); 301 300 302 301 #ifdef CONFIG_UDEBUG … … 313 312 * deallocation. 314 313 */ 315 kobject_put( &call->kobject);314 kobject_put(call->kobject); 316 315 } else { 317 316 /* … … 321 320 assert(rc == EINTR); 322 321 } 323 kobject_put( &phone->kobject);322 kobject_put(kobj); 324 323 return rc; 325 324 } … … 330 329 331 330 memcpy(data->args, call->data.args, sizeof(data->args)); 332 kobject_put( &call->kobject);333 kobject_put( &phone->kobject);331 kobject_put(call->kobject); 332 kobject_put(kobj); 334 333 335 334 return EOK; … … 371 370 sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, sysarg_t label) 372 371 { 373 phone_t *phone = phone_from_kobject( 374 kobject_get(TASK, handle, KOBJECT_TYPE_PHONE)); 375 376 if (!phone) 372 kobject_t *kobj = kobject_get(TASK, handle, KOBJECT_TYPE_PHONE); 373 if (!kobj) 377 374 return ENOENT; 378 375 379 if (check_call_limit( phone)) {380 kobject_put( &phone->kobject);376 if (check_call_limit(kobj->phone)) { 377 kobject_put(kobj); 381 378 return ELIMIT; 382 379 } … … 384 381 call_t *call = ipc_call_alloc(); 385 382 if (!call) { 386 kobject_put( &phone->kobject);383 kobject_put(kobj); 387 384 return ENOMEM; 388 385 } … … 402 399 call->data.answer_label = label; 403 400 404 errno_t res = request_preprocess(call, phone);401 errno_t res = request_preprocess(call, kobj->phone); 405 402 406 403 if (!res) 407 ipc_call( phone, call);404 ipc_call(kobj->phone, call); 408 405 else 409 ipc_backsend_err( phone, call, res);410 411 kobject_put( &phone->kobject);406 ipc_backsend_err(kobj->phone, call, res); 407 408 kobject_put(kobj); 412 409 return EOK; 413 410 } … … 425 422 sysarg_t label) 426 423 { 427 phone_t *phone = phone_from_kobject( 428 kobject_get(TASK, handle, KOBJECT_TYPE_PHONE)); 429 if (!phone) 424 kobject_t *kobj = kobject_get(TASK, handle, KOBJECT_TYPE_PHONE); 425 if (!kobj) 430 426 return ENOENT; 431 427 432 if (check_call_limit( phone)) {433 kobject_put( &phone->kobject);428 if (check_call_limit(kobj->phone)) { 429 kobject_put(kobj); 434 430 return ELIMIT; 435 431 } … … 437 433 call_t *call = ipc_call_alloc(); 438 434 if (!call) { 439 kobject_put( &phone->kobject);435 kobject_put(kobj); 440 436 return ENOMEM; 441 437 } … … 444 440 sizeof(call->data.args)); 445 441 if (rc != EOK) { 446 kobject_put( &call->kobject);447 kobject_put( &phone->kobject);442 kobject_put(call->kobject); 443 kobject_put(kobj); 448 444 return (sys_errno_t) rc; 449 445 } … … 452 448 call->data.answer_label = label; 453 449 454 errno_t res = request_preprocess(call, phone);450 errno_t res = request_preprocess(call, kobj->phone); 455 451 456 452 if (!res) 457 ipc_call( phone, call);453 ipc_call(kobj->phone, call); 458 454 else 459 ipc_backsend_err( phone, call, res);460 461 kobject_put( &phone->kobject);455 ipc_backsend_err(kobj->phone, call, res); 456 457 kobject_put(kobj); 462 458 return EOK; 463 459 } … … 493 489 return ENOENT; 494 490 495 call_t *call = c all_from_kobject(ckobj);491 call_t *call = ckobj->call; 496 492 497 493 ipc_data_t old; … … 555 551 } 556 552 557 rc = ipc_forward(call, p hone_from_kobject(pkobj), &TASK->answerbox, mode);553 rc = ipc_forward(call, pkobj->phone, &TASK->answerbox, mode); 558 554 if (rc != EOK) { 559 555 after_forward = true; … … 663 659 return ENOENT; 664 660 665 call_t *call = call_from_kobject(kobj);661 call_t *call = kobj->call; 666 662 assert(!(call->flags & IPC_CALL_ANSWERED)); 667 663 … … 710 706 return ENOENT; 711 707 712 call_t *call = call_from_kobject(kobj);708 call_t *call = kobj->call; 713 709 assert(!(call->flags & IPC_CALL_ANSWERED)); 714 710 … … 755 751 return ENOENT; 756 752 757 errno_t rc = ipc_phone_hangup( phone_from_kobject(kobj));753 errno_t rc = ipc_phone_hangup(kobj->phone); 758 754 kobject_put(kobj); 759 755 cap_free(TASK, handle); … … 801 797 802 798 STRUCT_TO_USPACE(calldata, &call->data); 803 kobject_put( &call->kobject);799 kobject_put(call->kobject); 804 800 805 801 return EOK; … … 810 806 811 807 if (call->flags & IPC_CALL_DISCARD_ANSWER) { 812 kobject_put( &call->kobject);808 kobject_put(call->kobject); 813 809 goto restart; 814 810 } … … 817 813 818 814 STRUCT_TO_USPACE(calldata, &call->data); 819 kobject_put( &call->kobject);815 kobject_put(call->kobject); 820 816 821 817 return EOK; … … 840 836 goto error; 841 837 842 kobject_add_ref( &call->kobject);843 cap_publish(TASK, handle, &call->kobject);838 kobject_add_ref(call->kobject); 839 cap_publish(TASK, handle, call->kobject); 844 840 return EOK; 845 841 -
kernel/generic/src/proc/task.c
r74a165cc raccdf882 201 201 return NULL; 202 202 203 if (caps_task_init(task) != EOK) {204 slab_free(task_cache, task);205 return NULL;206 }207 208 203 refcount_init(&task->refcount); 209 204 … … 217 212 task->ucycles = 0; 218 213 task->kcycles = 0; 214 215 caps_task_init(task); 219 216 220 217 task->ipc_info.call_sent = 0; … … 251 248 } 252 249 253 phone_t *phone = phone_from_kobject(254 kobject_get(task, phone_handle, KOBJECT_TYPE_PHONE));255 (void) ipc_phone_connect(phone , ipc_box_0);250 kobject_t *phone_obj = kobject_get(task, phone_handle, 251 KOBJECT_TYPE_PHONE); 252 (void) ipc_phone_connect(phone_obj->phone, ipc_box_0); 256 253 } 257 254 … … 290 287 */ 291 288 as_release(task->as); 292 293 caps_task_clear(task);294 289 295 290 slab_free(task_cache, task); -
kernel/generic/src/proc/thread.c
r74a165cc raccdf882 444 444 */ 445 445 ipc_cleanup(); 446 caps_task_clear(TASK);446 sys_waitq_task_cleanup(); 447 447 LOG("Cleanup of task %" PRIu64 " completed.", TASK->taskid); 448 448 } -
kernel/generic/src/synch/syswaitq.c
r74a165cc raccdf882 48 48 static slab_cache_t *waitq_cache; 49 49 50 typedef struct { 51 kobject_t kobject; 52 waitq_t waitq; 53 } waitq_kobject_t; 54 55 static void waitq_destroy(kobject_t *arg) 50 static void waitq_destroy(void *arg) 56 51 { 57 waitq_ kobject_t *wq = (waitq_kobject_t *) arg;52 waitq_t *wq = (waitq_t *) arg; 58 53 slab_free(waitq_cache, wq); 59 54 } 60 55 61 56 kobject_ops_t waitq_kobject_ops = { 62 .destroy = waitq_destroy ,57 .destroy = waitq_destroy 63 58 }; 59 60 static bool waitq_cap_cleanup_cb(cap_t *cap, void *arg) 61 { 62 kobject_t *kobj = cap_unpublish(cap->task, cap->handle, 63 KOBJECT_TYPE_WAITQ); 64 kobject_put(kobj); 65 cap_free(cap->task, cap->handle); 66 return true; 67 } 64 68 65 69 /** Initialize the user waitq subsystem */ 66 70 void sys_waitq_init(void) 67 71 { 68 waitq_cache = slab_cache_create("syswaitq_t", sizeof(waitq_kobject_t), 69 0, NULL, NULL, 0); 72 waitq_cache = slab_cache_create("waitq_t", sizeof(waitq_t), 0, NULL, 73 NULL, 0); 74 } 75 76 /** Clean-up all waitq capabilities held by the exiting task */ 77 void sys_waitq_task_cleanup(void) 78 { 79 caps_apply_to_kobject_type(TASK, KOBJECT_TYPE_WAITQ, 80 waitq_cap_cleanup_cb, NULL); 70 81 } 71 82 … … 79 90 sys_errno_t sys_waitq_create(uspace_ptr_cap_waitq_handle_t whandle) 80 91 { 81 waitq_ kobject_t *kobj= slab_alloc(waitq_cache, FRAME_ATOMIC);82 if (! kobj)92 waitq_t *wq = slab_alloc(waitq_cache, FRAME_ATOMIC); 93 if (!wq) 83 94 return (sys_errno_t) ENOMEM; 95 waitq_initialize(wq); 84 96 85 kobject_initialize(&kobj->kobject, KOBJECT_TYPE_WAITQ); 86 waitq_initialize(&kobj->waitq); 97 kobject_t *kobj = kobject_alloc(0); 98 if (!kobj) { 99 slab_free(waitq_cache, wq); 100 return (sys_errno_t) ENOMEM; 101 } 102 kobject_initialize(kobj, KOBJECT_TYPE_WAITQ, wq); 87 103 88 104 cap_handle_t handle; 89 105 errno_t rc = cap_alloc(TASK, &handle); 90 106 if (rc != EOK) { 91 slab_free(waitq_cache, kobj); 107 slab_free(waitq_cache, wq); 108 kobject_free(kobj); 92 109 return (sys_errno_t) rc; 93 110 } … … 96 113 if (rc != EOK) { 97 114 cap_free(TASK, handle); 98 slab_free(waitq_cache, kobj); 115 kobject_free(kobj); 116 slab_free(waitq_cache, wq); 99 117 return (sys_errno_t) rc; 100 118 } 101 119 102 cap_publish(TASK, handle, &kobj->kobject);120 cap_publish(TASK, handle, kobj); 103 121 104 122 return (sys_errno_t) EOK; … … 133 151 unsigned int flags) 134 152 { 135 waitq_kobject_t *kobj = 136 (waitq_kobject_t *) kobject_get(TASK, whandle, KOBJECT_TYPE_WAITQ); 153 kobject_t *kobj = kobject_get(TASK, whandle, KOBJECT_TYPE_WAITQ); 137 154 if (!kobj) 138 155 return (sys_errno_t) ENOENT; … … 142 159 #endif 143 160 144 errno_t rc = _waitq_sleep_timeout( &kobj->waitq, timeout,161 errno_t rc = _waitq_sleep_timeout(kobj->waitq, timeout, 145 162 SYNCH_FLAGS_INTERRUPTIBLE | flags); 146 163 … … 149 166 #endif 150 167 151 kobject_put( &kobj->kobject);168 kobject_put(kobj); 152 169 153 170 return (sys_errno_t) rc; … … 162 179 sys_errno_t sys_waitq_wakeup(cap_waitq_handle_t whandle) 163 180 { 164 waitq_kobject_t *kobj = 165 (waitq_kobject_t *) kobject_get(TASK, whandle, KOBJECT_TYPE_WAITQ); 181 kobject_t *kobj = kobject_get(TASK, whandle, KOBJECT_TYPE_WAITQ); 166 182 if (!kobj) 167 183 return (sys_errno_t) ENOENT; 168 184 169 waitq_wake_one( &kobj->waitq);185 waitq_wake_one(kobj->waitq); 170 186 171 kobject_put( &kobj->kobject);187 kobject_put(kobj); 172 188 return (sys_errno_t) EOK; 173 189 } -
kernel/generic/src/sysinfo/stats.c
r74a165cc raccdf882 384 384 static bool produce_stats_ipcc_cb(cap_t *cap, void *arg) 385 385 { 386 phone_t *phone = (phone_t *) cap->kobject;386 phone_t *phone = cap->kobject->phone; 387 387 ipccs_state_t *state = (ipccs_state_t *) arg; 388 388
Note:
See TracChangeset
for help on using the changeset viewer.