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