Ignore:
Timestamp:
2018-03-21T20:58:49Z (7 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
3be9d10
Parents:
874381a
Message:

Make capability handles type-safe

Define distinct pointer types for the handles of the supported
capability types and use them instead of integer handles. This makes it
virtually impossible to pass a non-handle or a handle of different type
instead of the proper handle. Also turn cap_handle_t into an "untyped"
capability handle that can be assigned to and from the "typed" handles.

This commit also fixes a bug in msim-con driver, which wrongly used the
IRQ number instead of the IRQ capability handle to unregister the IRQ.

This commit also fixes the wrong use of the capability handle instead
of error code in libusbhost.

File:
1 edited

Legend:

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

    r874381a readaeae8  
    4646         * That will be done once the phone is connected.
    4747         */
    48         cap_handle_t phone_handle;
     48        cap_phone_handle_t phone_handle;
    4949        kobject_t *phone_obj;
    5050        errno_t rc = phone_alloc(TASK, false, &phone_handle, &phone_obj);
     
    5858
    5959        /* Remember the handle */
    60         call->priv = phone_handle;
     60        call->priv = CAP_HANDLE_RAW(phone_handle);
    6161
    6262        return EOK;
     
    6565static errno_t request_forget(call_t *call)
    6666{
    67         cap_handle_t phone_handle = (cap_handle_t) call->priv;
     67        cap_phone_handle_t phone_handle = (cap_handle_t) call->priv;
    6868
    69         if (phone_handle < 0)
     69        if (CAP_HANDLE_RAW(phone_handle) < 0)
    7070                return EOK;
    7171
     
    103103static errno_t answer_process(call_t *answer)
    104104{
    105         cap_handle_t phone_handle = (cap_handle_t) answer->priv;
     105        cap_phone_handle_t phone_handle = (cap_handle_t) answer->priv;
    106106        phone_t *phone = (phone_t *) IPC_GET_ARG5(answer->data);
    107107
    108108        if (IPC_GET_RETVAL(answer->data)) {
    109                 if (phone_handle >= 0) {
     109                if (CAP_HANDLE_RAW(phone_handle) >= 0) {
    110110                        /*
    111111                         * Cleanup the unpublished capability and drop
     
    123123                cap_publish(TASK, phone_handle, phone->kobject);
    124124
    125                 IPC_SET_ARG5(answer->data, phone_handle);
     125                IPC_SET_ARG5(answer->data, CAP_HANDLE_RAW(phone_handle));
    126126        }
    127127
Note: See TracChangeset for help on using the changeset viewer.