Changeset eadaeae8 in mainline for uspace/lib/c/generic/ipc.c


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
  • uspace/lib/c/generic/ipc.c

    r874381a readaeae8  
    129129 * @param callback  Answer or error callback.
    130130 */
    131 void ipc_call_async_fast(cap_handle_t phandle, sysarg_t imethod, sysarg_t arg1,
    132     sysarg_t arg2, sysarg_t arg3, void *private, ipc_async_callback_t callback)
     131void ipc_call_async_fast(cap_phone_handle_t phandle, sysarg_t imethod,
     132    sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, void *private,
     133    ipc_async_callback_t callback)
    133134{
    134135        async_call_t *call = ipc_prepare_async(private, callback);
     
    136137                return;
    137138
    138         errno_t rc = (errno_t) __SYSCALL6(SYS_IPC_CALL_ASYNC_FAST, phandle, imethod, arg1,
    139             arg2, arg3, (sysarg_t) call);
     139        errno_t rc = (errno_t) __SYSCALL6(SYS_IPC_CALL_ASYNC_FAST,
     140            CAP_HANDLE_RAW(phandle), imethod, arg1, arg2, arg3,
     141            (sysarg_t) call);
    140142
    141143        ipc_finish_async(rc, call);
     
    160162 * @param callback  Answer or error callback.
    161163 */
    162 void ipc_call_async_slow(int phandle, sysarg_t imethod, sysarg_t arg1,
    163     sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t arg5, void *private,
    164     ipc_async_callback_t callback)
     164void ipc_call_async_slow(cap_phone_handle_t phandle, sysarg_t imethod,
     165    sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t arg5,
     166    void *private, ipc_async_callback_t callback)
    165167{
    166168        async_call_t *call = ipc_prepare_async(private, callback);
     
    175177        IPC_SET_ARG5(call->msg.data, arg5);
    176178
    177         errno_t rc = (errno_t) __SYSCALL3(SYS_IPC_CALL_ASYNC_SLOW, phandle,
    178             (sysarg_t) &call->msg.data, (sysarg_t) call);
     179        errno_t rc = (errno_t) __SYSCALL3(SYS_IPC_CALL_ASYNC_SLOW,
     180            CAP_HANDLE_RAW(phandle), (sysarg_t) &call->msg.data,
     181            (sysarg_t) call);
    179182
    180183        ipc_finish_async(rc, call);
     
    197200 *
    198201 */
    199 errno_t ipc_answer_fast(cap_handle_t chandle, errno_t retval, sysarg_t arg1,
    200     sysarg_t arg2, sysarg_t arg3, sysarg_t arg4)
    201 {
    202         return (errno_t) __SYSCALL6(SYS_IPC_ANSWER_FAST, chandle, (sysarg_t) retval, arg1, arg2,
    203             arg3, arg4);
     202errno_t ipc_answer_fast(cap_call_handle_t chandle, errno_t retval,
     203    sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, sysarg_t arg4)
     204{
     205        return (errno_t) __SYSCALL6(SYS_IPC_ANSWER_FAST,
     206            CAP_HANDLE_RAW(chandle), (sysarg_t) retval, arg1, arg2, arg3, arg4);
    204207}
    205208
     
    218221 *
    219222 */
    220 errno_t ipc_answer_slow(cap_handle_t chandle, errno_t retval, sysarg_t arg1,
    221     sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t arg5)
     223errno_t ipc_answer_slow(cap_call_handle_t chandle, errno_t retval,
     224    sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t arg5)
    222225{
    223226        ipc_call_t data;
     
    230233        IPC_SET_ARG5(data, arg5);
    231234
    232         return (errno_t) __SYSCALL2(SYS_IPC_ANSWER_SLOW, chandle, (sysarg_t) &data);
     235        return (errno_t) __SYSCALL2(SYS_IPC_ANSWER_SLOW,
     236            CAP_HANDLE_RAW(chandle), (sysarg_t) &data);
    233237}
    234238
     
    251255/** Wait for first IPC call to come.
    252256 *
    253  * @param call   Incoming call storage.
    254  * @param usec   Timeout in microseconds
    255  * @param flags  Flags passed to SYS_IPC_WAIT (blocking, nonblocking).
    256  * @param[out] out_handle  Call handle.
     257 * @param[out] call   Storage for the received call.
     258 * @param[in]  usec   Timeout in microseconds
     259 * @param[in[  flags  Flags passed to SYS_IPC_WAIT (blocking, nonblocking).
    257260 *
    258261 * @return  Error code.
     
    260263errno_t ipc_wait_cycle(ipc_call_t *call, sysarg_t usec, unsigned int flags)
    261264{
    262         errno_t rc = (errno_t) __SYSCALL3(SYS_IPC_WAIT, (sysarg_t) call, usec, flags);
     265        errno_t rc = (errno_t) __SYSCALL3(SYS_IPC_WAIT, (sysarg_t) call, usec,
     266            flags);
    263267
    264268        /* Handle received answers */
     
    295299        do {
    296300                rc = ipc_wait_cycle(call, usec, SYNCH_FLAGS_NONE);
    297         } while ((rc == EOK) && (call->cap_handle == CAP_NIL) && (call->flags & IPC_CALL_ANSWERED));
     301        } while ((rc == EOK) && (call->cap_handle == CAP_NIL) &&
     302            (call->flags & IPC_CALL_ANSWERED));
    298303
    299304        return rc;
     
    316321                rc = ipc_wait_cycle(call, SYNCH_NO_TIMEOUT,
    317322                    SYNCH_FLAGS_NON_BLOCKING);
    318         } while ((rc == EOK) && (call->cap_handle == CAP_NIL) && (call->flags & IPC_CALL_ANSWERED));
     323        } while ((rc == EOK) && (call->cap_handle == CAP_NIL) &&
     324            (call->flags & IPC_CALL_ANSWERED));
    319325
    320326        return rc;
     
    328334 *
    329335 */
    330 errno_t ipc_hangup(cap_handle_t phandle)
    331 {
    332         return (errno_t) __SYSCALL1(SYS_IPC_HANGUP, phandle);
     336errno_t ipc_hangup(cap_phone_handle_t phandle)
     337{
     338        return (errno_t) __SYSCALL1(SYS_IPC_HANGUP, CAP_HANDLE_RAW(phandle));
    333339}
    334340
     
    350356 *
    351357 */
    352 errno_t ipc_forward_fast(cap_handle_t chandle, cap_handle_t phandle,
     358errno_t ipc_forward_fast(cap_call_handle_t chandle, cap_phone_handle_t phandle,
    353359    sysarg_t imethod, sysarg_t arg1, sysarg_t arg2, unsigned int mode)
    354360{
    355         return (errno_t) __SYSCALL6(SYS_IPC_FORWARD_FAST, chandle, phandle, imethod, arg1,
     361        return (errno_t) __SYSCALL6(SYS_IPC_FORWARD_FAST,
     362            CAP_HANDLE_RAW(chandle), CAP_HANDLE_RAW(phandle), imethod, arg1,
    356363            arg2, mode);
    357364}
    358365
    359 errno_t ipc_forward_slow(cap_handle_t chandle, cap_handle_t phandle,
     366errno_t ipc_forward_slow(cap_call_handle_t chandle, cap_phone_handle_t phandle,
    360367    sysarg_t imethod, sysarg_t arg1, sysarg_t arg2, sysarg_t arg3,
    361368    sysarg_t arg4, sysarg_t arg5, unsigned int mode)
     
    370377        IPC_SET_ARG5(data, arg5);
    371378
    372         return (errno_t) __SYSCALL4(SYS_IPC_FORWARD_SLOW, chandle, phandle,
    373             (sysarg_t) &data, mode);
     379        return (errno_t) __SYSCALL4(SYS_IPC_FORWARD_SLOW,
     380            CAP_HANDLE_RAW(chandle), CAP_HANDLE_RAW(phandle), (sysarg_t) &data,
     381            mode);
    374382}
    375383
     
    377385 *
    378386 */
    379 errno_t ipc_connect_kbox(task_id_t id, cap_handle_t *phone)
     387errno_t ipc_connect_kbox(task_id_t id, cap_phone_handle_t *phone)
    380388{
    381389        return (errno_t) __SYSCALL2(SYS_IPC_CONNECT_KBOX, (sysarg_t) &id, (sysarg_t) phone);
Note: See TracChangeset for help on using the changeset viewer.