Changeset eadaeae8 in mainline for kernel/generic/src/ipc/sysipc.c


Ignore:
Timestamp:
2018-03-21T20:58:49Z (6 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/sysipc.c

    r874381a readaeae8  
    271271 *
    272272 */
    273 errno_t ipc_req_internal(cap_handle_t handle, ipc_data_t *data, sysarg_t priv)
     273errno_t
     274ipc_req_internal(cap_phone_handle_t handle, ipc_data_t *data, sysarg_t priv)
    274275{
    275276        kobject_t *kobj = kobject_get(TASK, handle, KOBJECT_TYPE_PHONE);
     
    362363 *
    363364 */
    364 sys_errno_t sys_ipc_call_async_fast(sysarg_t handle, sysarg_t imethod,
     365sys_errno_t sys_ipc_call_async_fast(cap_phone_handle_t handle, sysarg_t imethod,
    365366    sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, sysarg_t label)
    366367{
     
    409410 *
    410411 */
    411 sys_errno_t sys_ipc_call_async_slow(sysarg_t handle, ipc_data_t *data,
     412sys_errno_t sys_ipc_call_async_slow(cap_phone_handle_t handle, ipc_data_t *data,
    412413    sysarg_t label)
    413414{
     
    466467 *
    467468 */
    468 static sys_errno_t sys_ipc_forward_common(sysarg_t chandle, sysarg_t phandle,
    469     sysarg_t imethod, sysarg_t arg1, sysarg_t arg2, sysarg_t arg3,
    470     sysarg_t arg4, sysarg_t arg5, unsigned int mode, bool slow)
     469static sys_errno_t sys_ipc_forward_common(cap_call_handle_t chandle,
     470    cap_phone_handle_t phandle, sysarg_t imethod, sysarg_t arg1, sysarg_t arg2,
     471    sysarg_t arg3, sysarg_t arg4, sysarg_t arg5, unsigned int mode, bool slow)
    471472{
    472473        kobject_t *ckobj = cap_unpublish(TASK, chandle, KOBJECT_TYPE_CALL);
     
    506507                if (method_is_system(IPC_GET_IMETHOD(call->data))) {
    507508                        if (IPC_GET_IMETHOD(call->data) == IPC_M_CONNECT_TO_ME)
    508                                 phone_dealloc(IPC_GET_ARG5(call->data));
     509                                phone_dealloc((cap_phone_handle_t)
     510                                    IPC_GET_ARG5(call->data));
    509511
    510512                        IPC_SET_ARG1(call->data, imethod);
     
    577579 *
    578580 */
    579 sys_errno_t sys_ipc_forward_fast(sysarg_t chandle, sysarg_t phandle,
    580     sysarg_t imethod, sysarg_t arg1, sysarg_t arg2, unsigned int mode)
     581sys_errno_t sys_ipc_forward_fast(cap_call_handle_t chandle,
     582    cap_phone_handle_t phandle, sysarg_t imethod, sysarg_t arg1, sysarg_t arg2,
     583    unsigned int mode)
    581584{
    582585        return sys_ipc_forward_common(chandle, phandle, imethod, arg1, arg2, 0,
     
    601604 *
    602605 */
    603 sys_errno_t sys_ipc_forward_slow(sysarg_t chandle, sysarg_t phandle,
    604     ipc_data_t *data, unsigned int mode)
     606sys_errno_t sys_ipc_forward_slow(cap_call_handle_t chandle,
     607    cap_phone_handle_t phandle, ipc_data_t *data, unsigned int mode)
    605608{
    606609        ipc_data_t newdata;
     
    631634 *
    632635 */
    633 sys_errno_t sys_ipc_answer_fast(sysarg_t chandle, sysarg_t retval, sysarg_t arg1,
    634     sysarg_t arg2, sysarg_t arg3, sysarg_t arg4)
     636sys_errno_t sys_ipc_answer_fast(cap_call_handle_t chandle, sysarg_t retval,
     637    sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, sysarg_t arg4)
    635638{
    636639        kobject_t *kobj = cap_unpublish(TASK, chandle, KOBJECT_TYPE_CALL);
     
    678681 *
    679682 */
    680 sys_errno_t sys_ipc_answer_slow(sysarg_t chandle, ipc_data_t *data)
     683sys_errno_t sys_ipc_answer_slow(cap_call_handle_t chandle, ipc_data_t *data)
    681684{
    682685        kobject_t *kobj = cap_unpublish(TASK, chandle, KOBJECT_TYPE_CALL);
     
    722725 *
    723726 */
    724 sys_errno_t sys_ipc_hangup(sysarg_t handle)
     727sys_errno_t sys_ipc_hangup(cap_phone_handle_t handle)
    725728{
    726729        kobject_t *kobj = cap_unpublish(TASK, handle, KOBJECT_TYPE_PHONE);
     
    800803                goto restart;
    801804
    802         cap_handle_t handle;
     805        cap_handle_t handle = CAP_NIL;
    803806        errno_t rc = cap_alloc(TASK, &handle);
    804807        if (rc != EOK) {
     
    821824
    822825error:
    823         if (handle >= 0)
     826        if (CAP_HANDLE_VALID(handle))
    824827                cap_free(TASK, handle);
    825828
     
    861864 * @param ucode   Uspace pointer to the top-half pseudocode.
    862865 *
    863  * @param[out] uspace_handle  Uspace pointer to IRQ kernel object capability
     866 * @param[out] uspace_handle  Uspace pointer to IRQ capability handle
    864867 *
    865868 * @return EPERM
     
    867870 *
    868871 */
    869 sys_errno_t sys_ipc_irq_subscribe(inr_t inr, sysarg_t imethod, irq_code_t *ucode,
    870         cap_handle_t *uspace_handle)
     872sys_errno_t sys_ipc_irq_subscribe(inr_t inr, sysarg_t imethod,
     873    irq_code_t *ucode, cap_irq_handle_t *uspace_handle)
    871874{
    872875        if (!(perm_get(TASK) & PERM_IRQ_REG))
     
    878881/** Disconnect an IRQ handler from a task.
    879882 *
    880  * @param inr   IRQ number.
    881  * @param devno Device number.
     883 * @param handle  IRQ capability handle.
    882884 *
    883885 * @return Zero on success or EPERM on error.
    884886 *
    885887 */
    886 sys_errno_t sys_ipc_irq_unsubscribe(sysarg_t cap)
     888sys_errno_t sys_ipc_irq_unsubscribe(cap_irq_handle_t handle)
    887889{
    888890        if (!(perm_get(TASK) & PERM_IRQ_REG))
    889891                return EPERM;
    890892
    891         ipc_irq_unsubscribe(&TASK->answerbox, cap);
     893        ipc_irq_unsubscribe(&TASK->answerbox, handle);
    892894
    893895        return 0;
     
    899901 *
    900902 */
    901 sys_errno_t sys_ipc_connect_kbox(task_id_t *uspace_taskid, cap_handle_t *uspace_phone)
     903sys_errno_t sys_ipc_connect_kbox(task_id_t *uspace_taskid,
     904    cap_phone_handle_t *uspace_phone)
    902905{
    903906#ifdef CONFIG_UDEBUG
    904907        task_id_t taskid;
    905         cap_handle_t phone;
     908        cap_phone_handle_t phone;
    906909
    907910        errno_t rc = copy_from_uspace(&taskid, uspace_taskid, sizeof(task_id_t));
Note: See TracChangeset for help on using the changeset viewer.