Changeset 05ffb41 in mainline
- Timestamp:
- 2017-08-17T19:11:14Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 1c85bae
- Parents:
- 7e3826d9
- Location:
- kernel/generic
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/include/ipc/ipc.h
r7e3826d9 r05ffb41 43 43 #include <typedefs.h> 44 44 45 #define IPC_MAX_PHONES 6446 47 45 struct answerbox; 48 46 struct task; -
kernel/generic/include/ipc/ipcrsc.h
r7e3826d9 r05ffb41 40 40 41 41 extern call_t *get_call(sysarg_t); 42 extern int phone_get(sysarg_t, phone_t **); 42 extern phone_t *phone_get_current(int); 43 extern phone_t *phone_get(task_t *, int); 43 44 extern int phone_alloc(task_t *); 44 45 extern bool phone_connect(int, answerbox_t *); -
kernel/generic/include/kobject/kobject.h
r7e3826d9 r05ffb41 37 37 38 38 #include <typedefs.h> 39 #include <ipc/ipc.h> 39 40 40 41 #define MAX_KERNEL_OBJECTS 64 … … 44 45 typedef enum { 45 46 KOBJECT_TYPE_INVALID, 46 KOBJECT_TYPE_ALLOCATED 47 KOBJECT_TYPE_ALLOCATED, 48 KOBJECT_TYPE_PHONE 47 49 } kobject_type_t; 48 50 49 typedef struct {51 typedef struct kobject { 50 52 kobject_type_t type; 53 bool (* can_reclaim)(struct kobject *); 54 51 55 union { 56 phone_t phone; 52 57 }; 53 58 } kobject_t; 54 59 55 extern kobject_t *kobject_get_local(int, kobject_type_t);60 struct task; 56 61 57 struct task; 62 extern void kobject_init(kobject_t *); 63 extern kobject_t *kobject_get(struct task *, int, kobject_type_t); 64 extern kobject_t *kobject_get_current(int, kobject_type_t); 58 65 extern int kobject_alloc(struct task *); 59 66 extern void kobject_free(struct task *, int); -
kernel/generic/include/proc/task.h
r7e3826d9 r05ffb41 105 105 answerbox_t answerbox; 106 106 107 /** Sending communication endpoints */108 phone_t phones[IPC_MAX_PHONES];109 110 107 /** Spinlock protecting the active_calls list. */ 111 108 SPINLOCK_DECLARE(active_calls_lock); -
kernel/generic/src/ipc/ipc.c
r7e3826d9 r05ffb41 43 43 #include <synch/waitq.h> 44 44 #include <ipc/ipc.h> 45 #include <ipc/ipcrsc.h> 45 46 #include <abi/ipc/methods.h> 46 47 #include <ipc/kbox.h> … … 740 741 * Locking is needed as there may be connection handshakes in progress. 741 742 */ 742 for (i = 0; i < IPC_MAX_PHONES; i++) { 743 phone_t *phone = &TASK->phones[i]; 744 745 mutex_lock(&phone->lock); 743 for (i = 0; i < MAX_KERNEL_OBJECTS; i++) { 744 phone_t *phone = phone_get_current(i); 745 if (!phone) 746 continue; 747 748 mutex_lock(&phone->lock); 746 749 if ((phone->state == IPC_PHONE_HUNGUP) && 747 750 (atomic_get(&phone->active_calls) == 0)) { … … 784 787 785 788 /* Got into cleanup */ 786 if (i == IPC_MAX_PHONES)789 if (i == MAX_KERNEL_OBJECTS) 787 790 return; 788 791 … … 816 819 817 820 /* Disconnect all our phones ('ipc_phone_hangup') */ 818 for (size_t i = 0; i < IPC_MAX_PHONES; i++) 819 ipc_phone_hangup(&TASK->phones[i]); 821 for (int i = 0; i < MAX_KERNEL_OBJECTS; i++) { 822 phone_t *phone = phone_get_current(i); 823 if (!phone) 824 continue; 825 ipc_phone_hangup(phone); 826 } 820 827 821 828 /* Unsubscribe from any event notifications. */ … … 903 910 irq_spinlock_exchange(&tasks_lock, &task->lock); 904 911 905 printf("[phone id] [calls] [state\n");912 printf("[phone cap] [calls] [state\n"); 906 913 907 914 size_t i; 908 for (i = 0; i < IPC_MAX_PHONES; i++) { 909 if (SYNCH_FAILED(mutex_trylock(&task->phones[i].lock))) { 915 for (i = 0; i < MAX_KERNEL_OBJECTS; i++) { 916 phone_t *phone = phone_get(task, i); 917 if (!phone) 918 continue; 919 920 if (SYNCH_FAILED(mutex_trylock(&phone->lock))) { 910 921 printf("%-10zu (mutex busy)\n", i); 911 922 continue; 912 923 } 913 924 914 if ( task->phones[i].state != IPC_PHONE_FREE) {915 printf("%-1 0zu %7" PRIun " ", i,916 atomic_get(& task->phones[i].active_calls));925 if (phone->state != IPC_PHONE_FREE) { 926 printf("%-11zu %7" PRIun " ", i, 927 atomic_get(&phone->active_calls)); 917 928 918 switch ( task->phones[i].state) {929 switch (phone->state) { 919 930 case IPC_PHONE_CONNECTING: 920 931 printf("connecting"); … … 922 933 case IPC_PHONE_CONNECTED: 923 934 printf("connected to %" PRIu64 " (%s)", 924 task->phones[i].callee->task->taskid,925 task->phones[i].callee->task->name);935 phone->callee->task->taskid, 936 phone->callee->task->name); 926 937 break; 927 938 case IPC_PHONE_SLAMMED: 928 printf("slammed by %p", 929 task->phones[i].callee); 939 printf("slammed by %p", phone->callee); 930 940 break; 931 941 case IPC_PHONE_HUNGUP: 932 printf("hung up by %p", 933 task->phones[i].callee); 942 printf("hung up by %p", phone->callee); 934 943 break; 935 944 default: … … 940 949 } 941 950 942 mutex_unlock(& task->phones[i].lock);951 mutex_unlock(&phone->lock); 943 952 } 944 953 -
kernel/generic/src/ipc/ipcrsc.c
r7e3826d9 r05ffb41 162 162 } 163 163 164 /** Get phone from the current task by ID. 165 * 166 * @param phoneid Phone ID. 167 * @param phone Place to store pointer to phone. 168 * 169 * @return EOK on success, EINVAL if ID is invalid. 170 * 171 */ 172 int phone_get(sysarg_t phoneid, phone_t **phone) 173 { 174 if (phoneid >= IPC_MAX_PHONES) 175 return EINVAL; 176 177 *phone = &TASK->phones[phoneid]; 178 return EOK; 179 } 180 181 /** Allocate new phone slot in the specified task. 182 * 183 * @param task Task for which to allocate a new phone. 184 * 185 * @return New phone handle or -1 if the phone handle limit is 186 * exceeded. 187 * 164 /** Get phone from the current task by capability. 165 * 166 * @param cap Phone capability. 167 * @param phone Place to store pointer to phone. 168 * 169 * @return Address of the phone kernel object. 170 * @return NULL if the capability is invalid. 171 * 172 */ 173 phone_t *phone_get(task_t *task, int cap) 174 { 175 kobject_t *kobj = kobject_get(task, cap, KOBJECT_TYPE_PHONE); 176 if (!kobj) 177 return NULL; 178 179 return &kobj->phone; 180 } 181 182 phone_t *phone_get_current(int cap) 183 { 184 return phone_get(TASK, cap); 185 } 186 187 static bool phone_can_reclaim(kobject_t *kobj) 188 { 189 assert(kobj->type == KOBJECT_TYPE_PHONE); 190 191 return (kobj->phone.state == IPC_PHONE_HUNGUP) && 192 (atomic_get(&kobj->phone.active_calls) == 0); 193 } 194 195 /** Allocate new phone in the specified task. 196 * 197 * @param task Task for which to allocate a new phone. 198 * 199 * @return New phone capability. 200 * @return KOBJECT_INVALID_CAP if a new capability cannot be allocated. 188 201 */ 189 202 int phone_alloc(task_t *task) 190 203 { 191 irq_spinlock_lock(&task->lock, true); 192 193 size_t i; 194 for (i = 0; i < IPC_MAX_PHONES; i++) { 195 phone_t *phone = &task->phones[i]; 196 197 if ((phone->state == IPC_PHONE_HUNGUP) && 198 (atomic_get(&phone->active_calls) == 0)) 199 phone->state = IPC_PHONE_FREE; 200 201 if (phone->state == IPC_PHONE_FREE) { 202 phone->state = IPC_PHONE_CONNECTING; 203 break; 204 } 204 int cap = kobject_alloc(task); 205 if (cap != KOBJECT_INVALID_CAP) { 206 irq_spinlock_lock(&task->lock, true); 207 kobject_t *kobj = &task->kobject[cap]; 208 ipc_phone_init(&kobj->phone, task); 209 kobj->type = KOBJECT_TYPE_PHONE; 210 kobj->can_reclaim = phone_can_reclaim; 211 kobj->phone.state = IPC_PHONE_CONNECTING; 212 irq_spinlock_unlock(&task->lock, true); 205 213 } 206 214 207 irq_spinlock_unlock(&task->lock, true);208 209 if (i == IPC_MAX_PHONES) 210 return -1; 211 212 return i; 213 } 214 215 /** Mark a phone structure free. 216 * 217 * @param phone Phone structure to be marked free. 218 * 219 */ 220 static void phone_deallocp(phone_t *phone) 221 { 215 return cap; 216 } 217 218 /** Free slot from a disconnected phone. 219 * 220 * All already sent messages will be correctly processed. 221 * 222 * @param phoneid Phone handle of the phone to be freed. 223 * 224 */ 225 void phone_dealloc(int cap) 226 { 227 phone_t *phone = phone_get_current(cap); 228 229 assert(phone); 222 230 assert(phone->state == IPC_PHONE_CONNECTING); 223 224 /* Atomic operation */ 225 phone->state = IPC_PHONE_FREE; 226 } 227 228 /** Free slot from a disconnected phone. 229 * 230 * All already sent messages will be correctly processed. 231 * 232 * @param phoneid Phone handle of the phone to be freed. 233 * 234 */ 235 void phone_dealloc(int phoneid) 236 { 237 phone_deallocp(&TASK->phones[phoneid]); 231 232 kobject_free(TASK, cap); 238 233 } 239 234 240 235 /** Connect phone to a given answerbox. 241 236 * 242 * @param phoneid Phone handle to be connected. 243 * @param box Answerbox to which to connect the phone handle. 244 * @return True if the phone was connected, false otherwise. 245 * 246 * The procedure _enforces_ that the user first marks the phone 247 * busy (e.g. via phone_alloc) and then connects the phone, otherwise 248 * race condition may appear. 249 * 250 */ 251 bool phone_connect(int phoneid, answerbox_t *box) 252 { 253 phone_t *phone = &TASK->phones[phoneid]; 254 237 * @param cap Phone capability to be connected. 238 * @param box Answerbox to which to connect the phone capability. 239 * @return True if the phone was connected, false otherwise. 240 * 241 * The procedure _enforces_ that the user first marks the phone busy (e.g. via 242 * phone_alloc) and then connects the phone, otherwise race condition may 243 * appear. 244 * 245 */ 246 bool phone_connect(int cap, answerbox_t *box) 247 { 248 phone_t *phone = phone_get_current(cap); 249 250 assert(phone); 255 251 assert(phone->state == IPC_PHONE_CONNECTING); 252 256 253 return ipc_phone_connect(phone, box); 257 254 } -
kernel/generic/src/ipc/kbox.c
r7e3826d9 r05ffb41 206 206 * cleanup code. 207 207 * 208 * @return Phone idon success, or negative error code.208 * @return Phone capability on success, or negative error code. 209 209 * 210 210 */ … … 236 236 } 237 237 238 int newphid= phone_alloc(TASK);239 if ( newphid< 0) {238 int cap = phone_alloc(TASK); 239 if (cap < 0) { 240 240 mutex_unlock(&task->kb.cleanup_lock); 241 241 return ELIMIT; … … 243 243 244 244 /* Connect the newly allocated phone to the kbox */ 245 (void) ipc_phone_connect( &TASK->phones[newphid], &task->kb.box);245 (void) ipc_phone_connect(phone_get_current(cap), &task->kb.box); 246 246 247 247 if (task->kb.thread != NULL) { 248 248 mutex_unlock(&task->kb.cleanup_lock); 249 return newphid;249 return cap; 250 250 } 251 251 … … 263 263 mutex_unlock(&task->kb.cleanup_lock); 264 264 265 return newphid;265 return cap; 266 266 } 267 267 -
kernel/generic/src/ipc/ops/conctmeto.c
r7e3826d9 r05ffb41 42 42 static int request_preprocess(call_t *call, phone_t *phone) 43 43 { 44 int newphid= phone_alloc(TASK);44 int cap = phone_alloc(TASK); 45 45 46 /* Remember the phone idor the error. */47 call->priv = newphid;48 if ( newphid< 0)46 /* Remember the phone capability or the error. */ 47 call->priv = cap; 48 if (cap < 0) 49 49 return ELIMIT; 50 50 51 51 /* Set arg5 for server */ 52 IPC_SET_ARG5(call->data, (sysarg_t) &TASK->phones[newphid]);52 IPC_SET_ARG5(call->data, (sysarg_t) phone_get_current(cap)); 53 53 54 54 return EOK; … … 74 74 static int answer_process(call_t *answer) 75 75 { 76 int newphid= (int) answer->priv;76 int cap = (int) answer->priv; 77 77 78 78 if (IPC_GET_RETVAL(answer->data)) { 79 if ( newphid>= 0) {79 if (cap >= 0) { 80 80 /* 81 81 * The phone was indeed allocated and now needs 82 82 * to be deallocated. 83 83 */ 84 phone_dealloc( newphid);84 phone_dealloc(cap); 85 85 } 86 86 } else { 87 IPC_SET_ARG5(answer->data, newphid);87 IPC_SET_ARG5(answer->data, cap); 88 88 } 89 89 -
kernel/generic/src/ipc/ops/concttome.c
r7e3826d9 r05ffb41 42 42 static int request_process(call_t *call, answerbox_t *box) 43 43 { 44 int phoneid= phone_alloc(TASK);44 int cap = phone_alloc(TASK); 45 45 46 IPC_SET_ARG5(call->data, phoneid);46 IPC_SET_ARG5(call->data, cap); 47 47 48 48 return EOK; … … 51 51 static int answer_cleanup(call_t *answer, ipc_data_t *olddata) 52 52 { 53 int phoneid= (int) IPC_GET_ARG5(*olddata);53 int cap = (int) IPC_GET_ARG5(*olddata); 54 54 55 if ( phoneid>= 0)56 phone_dealloc( phoneid);55 if (cap >= 0) 56 phone_dealloc(cap); 57 57 58 58 return EOK; … … 61 61 static int answer_preprocess(call_t *answer, ipc_data_t *olddata) 62 62 { 63 int phoneid= (int) IPC_GET_ARG5(*olddata);63 int cap = (int) IPC_GET_ARG5(*olddata); 64 64 65 65 if (IPC_GET_RETVAL(answer->data) != EOK) { 66 66 /* The connection was not accepted */ 67 67 answer_cleanup(answer, olddata); 68 } else if ( phoneid>= 0) {68 } else if (cap >= 0) { 69 69 /* The connection was accepted */ 70 if (phone_connect( phoneid, &answer->sender->answerbox)) {70 if (phone_connect(cap, &answer->sender->answerbox)) { 71 71 /* Set 'phone hash' as arg5 of response */ 72 72 IPC_SET_ARG5(answer->data, 73 (sysarg_t) &TASK->phones[phoneid]);73 (sysarg_t) phone_get_current(cap)); 74 74 } else { 75 75 /* The answerbox is shutting down. */ -
kernel/generic/src/ipc/ops/connclone.c
r7e3826d9 r05ffb41 61 61 static int request_preprocess(call_t *call, phone_t *phone) 62 62 { 63 phone_t *cloned_phone; 64 65 if (phone_get(IPC_GET_ARG1(call->data), &cloned_phone) != EOK) 63 phone_t *cloned_phone = phone_get_current(IPC_GET_ARG1(call->data)); 64 if (!cloned_phone) 66 65 return ENOENT; 67 66 68 67 phones_lock(cloned_phone, phone); 69 68 70 69 if ((cloned_phone->state != IPC_PHONE_CONNECTED) || 71 70 phone->state != IPC_PHONE_CONNECTED) { … … 73 72 return EINVAL; 74 73 } 75 74 76 75 /* 77 76 * We can be pretty sure now that both tasks exist and we are … … 81 80 * 82 81 */ 83 int newphid= phone_alloc(phone->callee->task);84 if ( newphid< 0) {82 int cap = phone_alloc(phone->callee->task); 83 if (cap < 0) { 85 84 phones_unlock(cloned_phone, phone); 86 85 return ELIMIT; 87 86 } 88 89 (void) ipc_phone_connect( &phone->callee->task->phones[newphid],87 88 (void) ipc_phone_connect(phone_get(phone->callee->task, cap), 90 89 cloned_phone->callee); 91 90 phones_unlock(cloned_phone, phone); 92 91 93 92 /* Set the new phone for the callee. */ 94 IPC_SET_ARG1(call->data, newphid);93 IPC_SET_ARG1(call->data, cap); 95 94 96 95 return EOK; … … 99 98 static int answer_cleanup(call_t *answer, ipc_data_t *olddata) 100 99 { 101 int phoneid= (int) IPC_GET_ARG1(*olddata);102 phone_t *phone = &TASK->phones[phoneid];100 int cap = (int) IPC_GET_ARG1(*olddata); 101 phone_t *phone = phone_get_current(cap); 103 102 104 103 /* -
kernel/generic/src/ipc/ops/stchngath.c
r7e3826d9 r05ffb41 43 43 static int request_preprocess(call_t *call, phone_t *phone) 44 44 { 45 phone_t *sender_phone;46 45 task_t *other_task_s; 47 46 48 if (phone_get(IPC_GET_ARG5(call->data), &sender_phone) != EOK) 47 phone_t *sender_phone = phone_get_current(IPC_GET_ARG5(call->data)); 48 if (!sender_phone) 49 49 return ENOENT; 50 50 … … 75 75 task_t *other_task_r; 76 76 77 rc = phone_get(IPC_GET_ARG1(answer->data), 78 &recipient_phone); 79 if (rc != EOK) { 77 recipient_phone = phone_get_current(IPC_GET_ARG1(answer->data)); 78 if (!recipient_phone) { 80 79 IPC_SET_RETVAL(answer->data, ENOENT); 81 80 return ENOENT; -
kernel/generic/src/ipc/sysipc.c
r7e3826d9 r05ffb41 264 264 /** Make a call over IPC and wait for reply. 265 265 * 266 * @param phone id Phone handlefor the call.267 * @param data[inout] Structure with request/reply data.268 * @param priv Value to be stored in call->priv.266 * @param phone_cap Phone capability for the call. 267 * @param data[inout] Structure with request/reply data. 268 * @param priv Value to be stored in call->priv. 269 269 * 270 270 * @return EOK on success. … … 272 272 * 273 273 */ 274 int ipc_req_internal(int phone id, ipc_data_t *data, sysarg_t priv)275 { 276 phone_t *phone ;277 if ( phone_get(phoneid, &phone) != EOK)274 int ipc_req_internal(int phone_cap, ipc_data_t *data, sysarg_t priv) 275 { 276 phone_t *phone = phone_get_current(phone_cap); 277 if (!phone) 278 278 return ENOENT; 279 279 … … 350 350 * the generic function sys_ipc_call_async_slow(). 351 351 * 352 * @param phone id Phone handlefor the call.353 * @param imethod Interface and method of the call.354 * @param arg1 Service-defined payload argument.355 * @param arg2 Service-defined payload argument.356 * @param arg3 Service-defined payload argument.357 * @param arg4 Service-defined payload argument.352 * @param phone_cap Phone capability for the call. 353 * @param imethod Interface and method of the call. 354 * @param arg1 Service-defined payload argument. 355 * @param arg2 Service-defined payload argument. 356 * @param arg3 Service-defined payload argument. 357 * @param arg4 Service-defined payload argument. 358 358 * 359 359 * @return Call hash on success. … … 363 363 * 364 364 */ 365 sysarg_t sys_ipc_call_async_fast(sysarg_t phone id, sysarg_t imethod,365 sysarg_t sys_ipc_call_async_fast(sysarg_t phone_cap, sysarg_t imethod, 366 366 sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, sysarg_t arg4) 367 367 { 368 phone_t *phone ;369 if ( phone_get(phoneid, &phone) != EOK)368 phone_t *phone = phone_get_current(phone_cap); 369 if (!phone) 370 370 return IPC_CALLRET_FATAL; 371 371 … … 398 398 /** Make an asynchronous IPC call allowing to transmit the entire payload. 399 399 * 400 * @param phone id Phone handlefor the call.401 * @param data Userspace address of call data with the request.400 * @param phone_cap Phone capability for the call. 401 * @param data Userspace address of call data with the request. 402 402 * 403 403 * @return See sys_ipc_call_async_fast(). 404 404 * 405 405 */ 406 sysarg_t sys_ipc_call_async_slow(sysarg_t phone id, ipc_data_t *data)407 { 408 phone_t *phone ;409 if ( phone_get(phoneid, &phone) != EOK)406 sysarg_t sys_ipc_call_async_slow(sysarg_t phone_cap, ipc_data_t *data) 407 { 408 phone_t *phone = phone_get_current(phone_cap); 409 if (!phone) 410 410 return IPC_CALLRET_FATAL; 411 411 … … 435 435 * Common code for both the fast and the slow version. 436 436 * 437 * @param callid Hash of the call to forward.438 * @param phone id Phone handleto use for forwarding.439 * @param imethod New interface and method to use for the forwarded call.440 * @param arg1 New value of the first argument for the forwarded call.441 * @param arg2 New value of the second argument for the forwarded call.442 * @param arg3 New value of the third argument for the forwarded call.443 * @param arg4 New value of the fourth argument for the forwarded call.444 * @param arg5 New value of the fifth argument for the forwarded call.445 * @param mode Flags that specify mode of the forward operation.446 * @param slow If true, arg3, arg4 and arg5 are considered. Otherwise447 * the function considers only the fast version arguments:448 * i.e. arg1 and arg2.437 * @param callid Hash of the call to forward. 438 * @param phone_cap Phone capability to use for forwarding. 439 * @param imethod New interface and method to use for the forwarded call. 440 * @param arg1 New value of the first argument for the forwarded call. 441 * @param arg2 New value of the second argument for the forwarded call. 442 * @param arg3 New value of the third argument for the forwarded call. 443 * @param arg4 New value of the fourth argument for the forwarded call. 444 * @param arg5 New value of the fifth argument for the forwarded call. 445 * @param mode Flags that specify mode of the forward operation. 446 * @param slow If true, arg3, arg4 and arg5 are considered. Otherwise 447 * the function considers only the fast version arguments: 448 * i.e. arg1 and arg2. 449 449 * 450 450 * @return 0 on succes, otherwise an error code. … … 453 453 * 454 454 */ 455 static sysarg_t sys_ipc_forward_common(sysarg_t callid, sysarg_t phone id,455 static sysarg_t sys_ipc_forward_common(sysarg_t callid, sysarg_t phone_cap, 456 456 sysarg_t imethod, sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, 457 457 sysarg_t arg4, sysarg_t arg5, unsigned int mode, bool slow) … … 468 468 bool after_forward = false; 469 469 int rc; 470 phone_t *phone; 471 472 if ( phone_get(phoneid, &phone) != EOK) {470 471 phone_t *phone = phone_get_current(phone_cap); 472 if (!phone) { 473 473 rc = ENOENT; 474 474 goto error; … … 685 685 /** Hang up a phone. 686 686 * 687 * @param Phone handleof the phone to be hung up.687 * @param phone_cap Phone capability of the phone to be hung up. 688 688 * 689 689 * @return 0 on success or an error code. 690 690 * 691 691 */ 692 sysarg_t sys_ipc_hangup(sysarg_t phoneid) 693 { 694 phone_t *phone; 695 696 if (phone_get(phoneid, &phone) != EOK) 692 sysarg_t sys_ipc_hangup(sysarg_t phone_cap) 693 { 694 phone_t *phone = phone_get_current(phone_cap); 695 if (!phone) 697 696 return ENOENT; 698 697 -
kernel/generic/src/kobject/kobject.c
r7e3826d9 r05ffb41 37 37 #include <synch/spinlock.h> 38 38 39 kobject_t *kobject_get_local(int cap, kobject_type_t type) 39 void kobject_init(kobject_t *kobj) 40 { 41 kobj->type = KOBJECT_TYPE_INVALID; 42 kobj->can_reclaim = NULL; 43 } 44 45 kobject_t *kobject_get(task_t *task, int cap, kobject_type_t type) 40 46 { 41 47 if ((cap < 0) || (cap >= MAX_KERNEL_OBJECTS)) 42 48 return NULL; 43 if ( TASK->kobject[cap].type != type)49 if (task->kobject[cap].type != type) 44 50 return NULL; 45 return &TASK->kobject[cap]; 51 return &task->kobject[cap]; 52 } 53 54 kobject_t *kobject_get_current(int cap, kobject_type_t type) 55 { 56 return kobject_get(TASK, cap, type); 46 57 } 47 58 … … 52 63 irq_spinlock_lock(&task->lock, true); 53 64 for (cap = 0; cap < MAX_KERNEL_OBJECTS; cap++) { 54 if (task->kobject[cap].type == KOBJECT_TYPE_INVALID) { 55 task->kobject[cap].type = KOBJECT_TYPE_ALLOCATED; 65 kobject_t *kobj = &task->kobject[cap]; 66 if (kobj->type > KOBJECT_TYPE_ALLOCATED) { 67 if (kobj->can_reclaim && kobj->can_reclaim(kobj)) 68 kobject_init(kobj); 69 } 70 if (kobj->type == KOBJECT_TYPE_INVALID) { 71 kobj->type = KOBJECT_TYPE_ALLOCATED; 56 72 irq_spinlock_unlock(&task->lock, true); 57 73 return cap; … … 70 86 71 87 irq_spinlock_lock(&task->lock, true); 72 task->kobject[cap].type = KOBJECT_TYPE_INVALID;88 kobject_init(&task->kobject[cap]); 73 89 irq_spinlock_unlock(&task->lock, true); 74 90 } -
kernel/generic/src/proc/task.c
r7e3826d9 r05ffb41 166 166 167 167 list_initialize(&task->threads); 168 169 int cap; 170 for (cap = 0; cap < MAX_KERNEL_OBJECTS; cap++) 171 kobject_init(&task->kobject[cap]); 168 172 169 173 ipc_answerbox_init(&task->answerbox, task); 170 174 171 size_t i;172 for (i = 0; i < IPC_MAX_PHONES; i++)173 ipc_phone_init(&task->phones[i], task);174 175 175 spinlock_initialize(&task->active_calls_lock, "active_calls_lock"); 176 176 list_initialize(&task->active_calls); … … 228 228 229 229 if ((ipc_phone_0) && 230 (container_check(ipc_phone_0->task->container, task->container))) 231 (void) ipc_phone_connect(&task->phones[0], ipc_phone_0); 230 (container_check(ipc_phone_0->task->container, task->container))) { 231 int cap = phone_alloc(task); 232 assert(cap == 0); 233 (void) ipc_phone_connect(phone_get(task, 0), ipc_phone_0); 234 } 232 235 233 236 futex_task_init(task); … … 611 614 612 615 if (*additional) { 613 size_t i; 614 for (i = 0; i < IPC_MAX_PHONES; i++) { 615 if (task->phones[i].callee) 616 printf(" %zu:%p", i, task->phones[i].callee); 616 int i; 617 for (i = 0; i < MAX_KERNEL_OBJECTS; i++) { 618 phone_t *phone = phone_get(task, i); 619 if (phone && phone->callee) 620 printf(" %d:%p", i, phone->callee); 617 621 } 618 622 printf("\n");
Note:
See TracChangeset
for help on using the changeset viewer.