Ignore:
Timestamp:
2018-10-29T17:15:02Z (5 years ago)
Author:
Jakub Jermar <jakub@…>
Children:
eec201d
Parents:
184f2f8a
git-author:
Jakub Jermar <jakub@…> (2018-10-28 12:42:35)
git-committer:
Jakub Jermar <jakub@…> (2018-10-29 17:15:02)
Message:

Use user-defined labels instead of phone hashes

This commit changes the way how the async framework maps incomming calls
to connections. Instead of abusing the kernel addresses of attached
phones as identifiers, the IPC_M_CONNECT_TO_ME and IPC_M_CONNECT_ME_TO
messages allow the server to specify an arbitrary label which is
remembered in the connected phone and consequently imprinted on each
call which is routed through this phone.

The async framework uses the address of the connection structure as the
label. This removes the need for a connection hash table because each
incoming call already remembers the connection in its label.

To disambiguate this new label and the other user-defined label used for
answers, the call structure now has the request_label member for the
former and answer_label member for the latter.

This commit also moves the kernel definition of ipc_data_t to abi/ and
removes the uspace redefinition thereof. Finally, when forwarding the
IPC_M_CONNECT_TO_ME call, the phone capability and the kernel object
allocated in request_process are now correctly disposed of.

File:
1 edited

Legend:

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

    r184f2f8a rf5837524  
    4646         * That will be done once the phone is connected.
    4747         */
    48         cap_phone_handle_t phone_handle;
    49         kobject_t *phone_obj;
    50         errno_t rc = phone_alloc(TASK, false, &phone_handle, &phone_obj);
     48        cap_phone_handle_t phandle;
     49        kobject_t *pobj;
     50        errno_t rc = phone_alloc(TASK, false, &phandle, &pobj);
    5151        if (rc != EOK) {
    52                 call->priv = -1;
     52                call->priv = 0;
    5353                return rc;
    5454        }
    5555
    56         /* Hand over phone_obj's reference to ARG5 */
    57         IPC_SET_ARG5(call->data, (sysarg_t) phone_obj->phone);
     56        /* Move pobj's reference to call->priv */
     57        call->priv = (sysarg_t) pobj;
     58        pobj = NULL;
    5859
    5960        /* Remember the handle */
    60         call->priv = CAP_HANDLE_RAW(phone_handle);
     61        IPC_SET_ARG5(call->data, (sysarg_t) phandle);
    6162
    6263        return EOK;
     
    6566static errno_t request_forget(call_t *call)
    6667{
    67         cap_phone_handle_t phone_handle = (cap_handle_t) call->priv;
     68        cap_phone_handle_t phandle = (cap_handle_t) IPC_GET_ARG5(call->data);
    6869
    69         if (CAP_HANDLE_RAW(phone_handle) < 0)
     70        if (CAP_HANDLE_RAW(phandle) < 0)
    7071                return EOK;
    7172
    72         /* Hand over reference from ARG5 to phone->kobject */
    73         phone_t *phone = (phone_t *) IPC_GET_ARG5(call->data);
    74         /* Drop phone->kobject's reference */
    75         kobject_put(phone->kobject);
    76         cap_free(TASK, phone_handle);
     73        /* Move reference from call->priv to pobj */
     74        kobject_t *pobj = (kobject_t *) call->priv;
     75        call->priv = 0;
     76        /* Drop pobj's reference */
     77        kobject_put(pobj);
     78        cap_free(TASK, phandle);
    7779
    7880        return EOK;
     
    8183static errno_t answer_preprocess(call_t *answer, ipc_data_t *olddata)
    8284{
    83         /* Hand over reference from ARG5 to phone */
    84         phone_t *phone = (phone_t *) IPC_GET_ARG5(*olddata);
     85        /* Get an extra reference for phone */
     86        kobject_t *pobj = (kobject_t *) answer->priv;
     87        kobject_add_ref(pobj);
    8588
    86         /*
    87          * Get an extra reference and pass it in the answer data.
    88          */
    89         kobject_add_ref(phone->kobject);
    90         IPC_SET_ARG5(answer->data, (sysarg_t) phone);
     89        /* Set the recipient-assigned label */
     90        pobj->phone->label = IPC_GET_ARG5(answer->data);
     91
     92        /* Restore phone handle in answer's ARG5 */
     93        IPC_SET_ARG5(answer->data, IPC_GET_ARG5(*olddata));
    9194
    9295        /* If the user accepted the call, connect */
    9396        if (IPC_GET_RETVAL(answer->data) == EOK) {
    94                 /* Hand over reference from phone to the answerbox */
    95                 (void) ipc_phone_connect(phone, &TASK->answerbox);
     97                /* Hand over reference from pobj to the answerbox */
     98                (void) ipc_phone_connect(pobj->phone, &TASK->answerbox);
    9699        } else {
    97                 kobject_put(phone->kobject);
     100                /* Drop the extra reference */
     101                kobject_put(pobj);
    98102        }
    99103
     
    103107static errno_t answer_process(call_t *answer)
    104108{
    105         cap_phone_handle_t phone_handle = (cap_handle_t) answer->priv;
    106         phone_t *phone = (phone_t *) IPC_GET_ARG5(answer->data);
     109        cap_phone_handle_t phandle = (cap_handle_t) IPC_GET_ARG5(answer->data);
     110        /* Move the reference from answer->priv to pobj */
     111        kobject_t *pobj = (kobject_t *) answer->priv;
     112        answer->priv = 0;
    107113
    108114        if (IPC_GET_RETVAL(answer->data)) {
    109                 if (CAP_HANDLE_RAW(phone_handle) >= 0) {
     115                if (CAP_HANDLE_RAW(phandle) >= 0) {
    110116                        /*
    111117                         * Cleanup the unpublished capability and drop
    112118                         * phone->kobject's reference.
    113119                         */
    114                         kobject_put(phone->kobject);
    115                         cap_free(TASK, phone_handle);
     120                        kobject_put(pobj);
     121                        cap_free(TASK, phandle);
    116122                }
    117123        } else {
     
    121127                 * capability for each phone that wasn't hung up by the user.
    122128                 */
    123                 cap_publish(TASK, phone_handle, phone->kobject);
    124 
    125                 IPC_SET_ARG5(answer->data, CAP_HANDLE_RAW(phone_handle));
     129                cap_publish(TASK, phandle, pobj);
    126130        }
    127131
Note: See TracChangeset for help on using the changeset viewer.