Changeset 48bcf49 in mainline for kernel/generic/src/ipc/ops


Ignore:
Timestamp:
2017-09-28T22:08:15Z (8 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
6636fb19
Parents:
dd20cbb
Message:

Introduce reference-counted kobjects

Capabilities are thus reduced to task-local names for references to kobjects.

Location:
kernel/generic/src/ipc/ops
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/ipc/ops/conctmeto.c

    rdd20cbb r48bcf49  
    11/*
    22 * Copyright (c) 2006 Ondrej Palkovsky
    3  * Copyright (c) 2012 Jakub Jermar 
     3 * Copyright (c) 2012 Jakub Jermar
    44 * All rights reserved.
    55 *
     
    4242static int request_preprocess(call_t *call, phone_t *phone)
    4343{
    44         int cap = phone_alloc(TASK);
     44        cap_handle_t phone_handle = phone_alloc(TASK);
    4545
    4646        /* Remember the phone capability or the error. */
    47         call->priv = cap;
    48         if (cap < 0)
    49                 return ELIMIT;
    50                
     47        call->priv = phone_handle;
     48        if (phone_handle < 0)
     49                return phone_handle;
     50
    5151        /* Set arg5 for server */
    52         IPC_SET_ARG5(call->data, (sysarg_t) phone_get_current(cap));
     52        kobject_t *phone_obj = kobject_get(TASK, phone_handle,
     53            KOBJECT_TYPE_PHONE);
     54        /* Hand over phone_obj's reference to ARG5 */
     55        IPC_SET_ARG5(call->data, (sysarg_t) phone_obj->phone);
    5356
    5457        return EOK;
     
    5760static int request_forget(call_t *call)
    5861{
    59         phone_dealloc(call->priv);
     62        cap_handle_t phone_handle = (cap_handle_t) call->priv;
     63        phone_dealloc(phone_handle);
     64        /* Hand over reference from ARG5 to phone->kobject */
     65        phone_t *phone = (phone_t *) IPC_GET_ARG5(call->data);
     66        /* Drop phone_obj's reference */
     67        kobject_put(phone->kobject);
    6068        return EOK;
    6169}
     
    6371static int answer_preprocess(call_t *answer, ipc_data_t *olddata)
    6472{
     73        /* Hand over reference from ARG5 to phone */
    6574        phone_t *phone = (phone_t *) IPC_GET_ARG5(*olddata);
    6675
    6776        /* If the user accepted call, connect */
    68         if (IPC_GET_RETVAL(answer->data) == EOK)
     77        if (IPC_GET_RETVAL(answer->data) == EOK) {
     78                /* Hand over reference from phone to the answerbox */
    6979                (void) ipc_phone_connect(phone, &TASK->answerbox);
     80        } else {
     81                kobject_put(phone->kobject);
     82        }
    7083
    7184        return EOK;
     
    7487static int answer_process(call_t *answer)
    7588{
    76         int cap = (int) answer->priv;
     89        cap_handle_t phone_handle = (cap_handle_t) answer->priv;
    7790
    7891        if (IPC_GET_RETVAL(answer->data)) {
    79                 if (cap >= 0) {
     92                if (phone_handle >= 0) {
    8093                        /*
    8194                         * The phone was indeed allocated and now needs
    8295                         * to be deallocated.
    8396                         */
    84                         phone_dealloc(cap);
     97                        phone_dealloc(phone_handle);
    8598                }
    8699        } else {
    87                 IPC_SET_ARG5(answer->data, cap);
     100                IPC_SET_ARG5(answer->data, phone_handle);
    88101        }
    89102       
  • kernel/generic/src/ipc/ops/concttome.c

    rdd20cbb r48bcf49  
    11/*
    22 * Copyright (c) 2006 Ondrej Palkovsky
    3  * Copyright (c) 2012 Jakub Jermar 
     3 * Copyright (c) 2012 Jakub Jermar
    44 * All rights reserved.
    55 *
     
    4242static int request_process(call_t *call, answerbox_t *box)
    4343{
    44         int cap = phone_alloc(TASK);
     44        cap_handle_t phone_handle = phone_alloc(TASK);
    4545
    46         IPC_SET_ARG5(call->data, cap);
     46        IPC_SET_ARG5(call->data, phone_handle);
    4747       
    4848        return EOK;
     
    5151static int answer_cleanup(call_t *answer, ipc_data_t *olddata)
    5252{
    53         int cap = (int) IPC_GET_ARG5(*olddata);
     53        cap_handle_t phone_handle = (cap_handle_t) IPC_GET_ARG5(*olddata);
    5454
    55         if (cap >= 0)
    56                 phone_dealloc(cap);
     55        if (phone_handle >= 0)
     56                phone_dealloc(phone_handle);
    5757
    5858        return EOK;
     
    6161static int answer_preprocess(call_t *answer, ipc_data_t *olddata)
    6262{
    63         int cap = (int) IPC_GET_ARG5(*olddata);
     63        cap_handle_t phone_handle = (cap_handle_t) IPC_GET_ARG5(*olddata);
    6464
    6565        if (IPC_GET_RETVAL(answer->data) != EOK) {
    6666                /* The connection was not accepted */
    6767                answer_cleanup(answer, olddata);
    68         } else if (cap >= 0) {
     68        } else if (phone_handle >= 0) {
    6969                /* The connection was accepted */
    70                 if (phone_connect(cap, &answer->sender->answerbox)) {
    71                         /* Set 'phone hash' as arg5 of response */
     70                if (phone_connect(phone_handle, &answer->sender->answerbox)) {
     71                        /* Set 'phone hash' as ARG5 of response */
     72                        kobject_t *phone_obj = kobject_get(TASK, phone_handle,
     73                            KOBJECT_TYPE_PHONE);
    7274                        IPC_SET_ARG5(answer->data,
    73                             (sysarg_t) phone_get_current(cap));
     75                            (sysarg_t) phone_obj->phone);
     76                        kobject_put(phone_obj);
    7477                } else {
    7578                        /* The answerbox is shutting down. */
  • kernel/generic/src/ipc/ops/stchngath.c

    rdd20cbb r48bcf49  
    4545        task_t *other_task_s;
    4646
    47         phone_t *sender_phone = phone_get_current(IPC_GET_ARG5(call->data));
    48         if (!sender_phone)
     47        kobject_t *sender_obj = kobject_get(TASK, IPC_GET_ARG5(call->data),
     48            KOBJECT_TYPE_PHONE);
     49        if (!sender_obj)
    4950                return ENOENT;
    5051
    51         mutex_lock(&sender_phone->lock);
    52         if (sender_phone->state != IPC_PHONE_CONNECTED) {
    53                 mutex_unlock(&sender_phone->lock);
     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);
    5456                return EINVAL;
    5557        }
    5658
    57         other_task_s = sender_phone->callee->task;
     59        other_task_s = sender_obj->phone->callee->task;
    5860
    59         mutex_unlock(&sender_phone->lock);
     61        mutex_unlock(&sender_obj->phone->lock);
    6062
    6163        /* Remember the third party task hash. */
    6264        IPC_SET_ARG5(call->data, (sysarg_t) other_task_s);
    6365
     66        kobject_put(sender_obj);
    6467        return EOK;
    6568}
     
    7174        if (!IPC_GET_RETVAL(answer->data)) {
    7275                /* The recipient authorized the change of state. */
    73                 phone_t *recipient_phone;
    7476                task_t *other_task_s;
    7577                task_t *other_task_r;
    7678
    77                 recipient_phone = phone_get_current(IPC_GET_ARG1(answer->data));
    78                 if (!recipient_phone) {
     79                kobject_t *recipient_obj = kobject_get(TASK,
     80                    IPC_GET_ARG1(answer->data), KOBJECT_TYPE_PHONE);
     81                if (!recipient_obj) {
    7982                        IPC_SET_RETVAL(answer->data, ENOENT);
    8083                        return ENOENT;
    8184                }
    8285
    83                 mutex_lock(&recipient_phone->lock);
    84                 if (recipient_phone->state != IPC_PHONE_CONNECTED) {
    85                         mutex_unlock(&recipient_phone->lock);
     86                mutex_lock(&recipient_obj->phone->lock);
     87                if (recipient_obj->phone->state != IPC_PHONE_CONNECTED) {
     88                        mutex_unlock(&recipient_obj->phone->lock);
    8689                        IPC_SET_RETVAL(answer->data, EINVAL);
     90                        kobject_put(recipient_obj);
    8791                        return EINVAL;
    8892                }
    8993
    90                 other_task_r = recipient_phone->callee->task;
     94                other_task_r = recipient_obj->phone->callee->task;
    9195                other_task_s = (task_t *) IPC_GET_ARG5(*olddata);
    9296
     
    109113                }
    110114
    111                 mutex_unlock(&recipient_phone->lock);
     115                mutex_unlock(&recipient_obj->phone->lock);
     116                kobject_put(recipient_obj);
    112117        }
    113118
Note: See TracChangeset for help on using the changeset viewer.