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/concttome.c

    r874381a readaeae8  
    4242static int request_process(call_t *call, answerbox_t *box)
    4343{
    44         cap_handle_t phone_handle;
     44        cap_phone_handle_t phone_handle;
    4545        kobject_t *phone_obj;
    4646        errno_t rc = phone_alloc(TASK, false, &phone_handle, &phone_obj);
    4747        call->priv = (sysarg_t) phone_obj;
    48         IPC_SET_ARG5(call->data, (rc == EOK) ? phone_handle : -1);
     48        IPC_SET_ARG5(call->data,
     49            (rc == EOK) ? CAP_HANDLE_RAW(phone_handle) : CAP_NIL);
    4950        return 0;
    5051}
     
    5253static errno_t answer_cleanup(call_t *answer, ipc_data_t *olddata)
    5354{
    54         cap_handle_t phone_handle = (cap_handle_t) IPC_GET_ARG5(*olddata);
     55        cap_phone_handle_t phone_handle = (cap_handle_t) IPC_GET_ARG5(*olddata);
    5556        kobject_t *phone_obj = (kobject_t *) answer->priv;
    5657
    57         if (phone_handle >= 0) {
     58        if (CAP_HANDLE_VALID(phone_handle)) {
    5859                kobject_put(phone_obj);
    5960                cap_free(TASK, phone_handle);
     
    6566static errno_t answer_preprocess(call_t *answer, ipc_data_t *olddata)
    6667{
    67         cap_handle_t phone_handle = (cap_handle_t) IPC_GET_ARG5(*olddata);
     68        cap_phone_handle_t phone_handle = (cap_handle_t) IPC_GET_ARG5(*olddata);
    6869        kobject_t *phone_obj = (kobject_t *) answer->priv;
    6970
     
    7172                /* The connection was not accepted */
    7273                answer_cleanup(answer, olddata);
    73         } else if (phone_handle >= 0) {
     74        } else if (CAP_HANDLE_VALID(phone_handle)) {
    7475                /*
    7576                 * The connection was accepted
Note: See TracChangeset for help on using the changeset viewer.