Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/ipc/sysipc.c

    raddbce4 ra53ed3a  
    155155 * @param olddata Saved data of the request.
    156156 *
    157  * @return Return EOK on success or a negative error code.
    158  *
    159  */
    160 int answer_preprocess(call_t *answer, ipc_data_t *olddata)
    161 {
    162         int rc = EOK;
     157 * @return Return EOK on success or an error code.
     158 *
     159 */
     160errno_t answer_preprocess(call_t *answer, ipc_data_t *olddata)
     161{
     162        errno_t rc = EOK;
    163163
    164164        spinlock_lock(&answer->forget_lock);
     
    194194        spinlock_unlock(&answer->forget_lock);
    195195
    196         if ((native_t) IPC_GET_RETVAL(answer->data) == EHANGUP) {
     196        if ((errno_t) IPC_GET_RETVAL(answer->data) == EHANGUP) {
    197197                phone_t *phone = answer->caller_phone;
    198198                mutex_lock(&phone->lock);
     
    222222 *
    223223 */
    224 static int request_preprocess(call_t *call, phone_t *phone)
     224static errno_t request_preprocess(call_t *call, phone_t *phone)
    225225{
    226226        call->request_method = IPC_GET_IMETHOD(call->data);
     
    239239static void process_answer(call_t *call)
    240240{
    241         if (((native_t) IPC_GET_RETVAL(call->data) == EHANGUP) &&
     241        if (((errno_t) IPC_GET_RETVAL(call->data) == EHANGUP) &&
    242242            (call->flags & IPC_CALL_FORWARDED))
    243243                IPC_SET_RETVAL(call->data, EFORWARD);
     
    271271 *
    272272 */
    273 int ipc_req_internal(cap_handle_t handle, ipc_data_t *data, sysarg_t priv)
     273errno_t ipc_req_internal(cap_handle_t handle, ipc_data_t *data, sysarg_t priv)
    274274{
    275275        kobject_t *kobj = kobject_get(TASK, handle, KOBJECT_TYPE_PHONE);
     
    281281        memcpy(call->data.args, data->args, sizeof(data->args));
    282282       
    283         int rc = request_preprocess(call, kobj->phone);
     283        errno_t rc = request_preprocess(call, kobj->phone);
    284284        if (!rc) {
    285285#ifdef CONFIG_UDEBUG
     
    359359 *
    360360 * @return EOK on success.
    361  * @return Negative error code on error.
    362  *
    363  */
    364 sysarg_t sys_ipc_call_async_fast(sysarg_t handle, sysarg_t imethod,
     361 * @return An error code on error.
     362 *
     363 */
     364sys_errno_t sys_ipc_call_async_fast(sysarg_t handle, sysarg_t imethod,
    365365    sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, sysarg_t label)
    366366{
     
    389389        call->data.label = label;
    390390       
    391         int res = request_preprocess(call, kobj->phone);
     391        errno_t res = request_preprocess(call, kobj->phone);
    392392       
    393393        if (!res)
     
    409409 *
    410410 */
    411 sysarg_t sys_ipc_call_async_slow(sysarg_t handle, ipc_data_t *data,
     411sys_errno_t sys_ipc_call_async_slow(sysarg_t handle, ipc_data_t *data,
    412412    sysarg_t label)
    413413{
     
    422422
    423423        call_t *call = ipc_call_alloc(0);
    424         int rc = copy_from_uspace(&call->data.args, &data->args,
     424        errno_t rc = copy_from_uspace(&call->data.args, &data->args,
    425425            sizeof(call->data.args));
    426         if (rc != 0) {
     426        if (rc != EOK) {
    427427                kobject_put(call->kobject);
    428428                kobject_put(kobj);
    429                 return (sysarg_t) rc;
     429                return (sys_errno_t) rc;
    430430        }
    431431
     
    433433        call->data.label = label;
    434434       
    435         int res = request_preprocess(call, kobj->phone);
     435        errno_t res = request_preprocess(call, kobj->phone);
    436436       
    437437        if (!res)
     
    466466 *
    467467 */
    468 static sysarg_t sys_ipc_forward_common(sysarg_t chandle, sysarg_t phandle,
     468static sys_errno_t sys_ipc_forward_common(sysarg_t chandle, sysarg_t phandle,
    469469    sysarg_t imethod, sysarg_t arg1, sysarg_t arg2, sysarg_t arg3,
    470470    sysarg_t arg4, sysarg_t arg5, unsigned int mode, bool slow)
     
    482482       
    483483        bool after_forward = false;
    484         int rc;
     484        errno_t rc;
    485485
    486486        kobject_t *pkobj = kobject_get(TASK, phandle, KOBJECT_TYPE_PHONE);
     
    577577 *
    578578 */
    579 sysarg_t sys_ipc_forward_fast(sysarg_t chandle, sysarg_t phandle,
     579sys_errno_t sys_ipc_forward_fast(sysarg_t chandle, sysarg_t phandle,
    580580    sysarg_t imethod, sysarg_t arg1, sysarg_t arg2, unsigned int mode)
    581581{
     
    601601 *
    602602 */
    603 sysarg_t sys_ipc_forward_slow(sysarg_t chandle, sysarg_t phandle,
     603sys_errno_t sys_ipc_forward_slow(sysarg_t chandle, sysarg_t phandle,
    604604    ipc_data_t *data, unsigned int mode)
    605605{
    606606        ipc_data_t newdata;
    607         int rc = copy_from_uspace(&newdata.args, &data->args,
     607        errno_t rc = copy_from_uspace(&newdata.args, &data->args,
    608608            sizeof(newdata.args));
    609         if (rc != 0)
    610                 return (sysarg_t) rc;
     609        if (rc != EOK)
     610                return (sys_errno_t) rc;
    611611       
    612612        return sys_ipc_forward_common(chandle, phandle,
     
    631631 *
    632632 */
    633 sysarg_t sys_ipc_answer_fast(sysarg_t chandle, sysarg_t retval, sysarg_t arg1,
     633sys_errno_t sys_ipc_answer_fast(sysarg_t chandle, sysarg_t retval, sysarg_t arg1,
    634634    sysarg_t arg2, sysarg_t arg3, sysarg_t arg4)
    635635{
     
    660660         */
    661661        IPC_SET_ARG5(call->data, 0);
    662         int rc = answer_preprocess(call, saved ? &saved_data : NULL);
     662        errno_t rc = answer_preprocess(call, saved ? &saved_data : NULL);
    663663       
    664664        ipc_answer(&TASK->answerbox, call);
     
    678678 *
    679679 */
    680 sysarg_t sys_ipc_answer_slow(sysarg_t chandle, ipc_data_t *data)
     680sys_errno_t sys_ipc_answer_slow(sysarg_t chandle, ipc_data_t *data)
    681681{
    682682        kobject_t *kobj = cap_unpublish(TASK, chandle, KOBJECT_TYPE_CALL);
     
    695695                saved = false;
    696696       
    697         int rc = copy_from_uspace(&call->data.args, &data->args,
     697        errno_t rc = copy_from_uspace(&call->data.args, &data->args,
    698698            sizeof(call->data.args));
    699         if (rc != 0) {
     699        if (rc != EOK) {
    700700                /*
    701701                 * Republish the capability so that the call does not get lost.
     
    722722 *
    723723 */
    724 sysarg_t sys_ipc_hangup(sysarg_t handle)
     724sys_errno_t sys_ipc_hangup(sysarg_t handle)
    725725{
    726726        kobject_t *kobj = kobject_get(TASK, handle, KOBJECT_TYPE_PHONE);
     
    728728                return ENOENT;
    729729       
    730         if (ipc_phone_hangup(kobj->phone)) {
    731                 kobject_put(kobj);
    732                 return -1;
    733         }
    734        
     730        errno_t rc = ipc_phone_hangup(kobj->phone);
    735731        kobject_put(kobj);
    736         return 0;
     732        return rc;
    737733}
    738734
     
    744740 *                 for explanation.
    745741 *
    746  * @return Capability handle of the received request.
    747  * @return CAP_NIL for answers, notifications and when there is no call.
    748  * @return Negative error code on error.
    749  */
    750 sysarg_t sys_ipc_wait_for_call(ipc_data_t *calldata, uint32_t usec,
     742 * @return An error code on error.
     743 */
     744sys_errno_t sys_ipc_wait_for_call(ipc_data_t *calldata, uint32_t usec,
    751745    unsigned int flags)
    752746{
     
    767761
    768762        if (!call) {
    769                 STRUCT_TO_USPACE(calldata, &(ipc_data_t){});
    770                 return CAP_NIL;
    771         }
    772        
     763                ipc_data_t data = {};
     764                data.cap_handle = CAP_NIL;
     765                STRUCT_TO_USPACE(calldata, &data);
     766                return EOK;
     767        }
     768       
     769        call->data.flags = call->flags;
    773770        if (call->flags & IPC_CALL_NOTIF) {
    774771                /* Set in_phone_hash to the interrupt counter */
    775772                call->data.phone = (void *) call->priv;
    776773               
    777                 call->data.flags = IPC_CALL_NOTIF;
     774                call->data.cap_handle = CAP_NIL;
    778775
    779776                STRUCT_TO_USPACE(calldata, &call->data);
    780777                kobject_put(call->kobject);
    781778               
    782                 return CAP_NIL;
     779                return EOK;
    783780        }
    784781       
     
    791788                }
    792789
    793                 call->data.flags = IPC_CALL_ANSWERED;
     790                call->data.cap_handle = CAP_NIL;
    794791               
    795792                STRUCT_TO_USPACE(calldata, &call->data);
    796793                kobject_put(call->kobject);
    797794               
    798                 return CAP_NIL;
     795                return EOK;
    799796        }
    800797       
     
    802799                goto restart;
    803800       
    804         int rc;
    805         cap_handle_t handle = cap_alloc(TASK);
    806         if (handle < 0) {
    807                 rc = handle;
     801        cap_handle_t handle;
     802        errno_t rc = cap_alloc(TASK, &handle);
     803        if (rc != EOK) {
    808804                goto error;
    809805        }
    810806       
     807        call->data.cap_handle = handle;
     808
    811809        /*
    812810         * Include phone hash of the caller in the request, copy the whole
     
    819817        kobject_add_ref(call->kobject);
    820818        cap_publish(TASK, handle, call->kobject);
    821         return handle;
     819        return EOK;
    822820
    823821error:
     
    827825        /*
    828826         * The callee will not receive this call and no one else has a chance to
    829          * answer it. Reply with the EPARTY error code.
     827         * answer it. Set the IPC_CALL_AUTO_REPLY flag and return the EPARTY
     828         * error code.
    830829         */
    831830        ipc_data_t saved_data;
     
    840839        IPC_SET_RETVAL(call->data, EPARTY);
    841840        (void) answer_preprocess(call, saved ? &saved_data : NULL);
     841        call->flags |= IPC_CALL_AUTO_REPLY;
    842842        ipc_answer(&TASK->answerbox, call);
    843843
     
    848848 *
    849849 */
    850 sysarg_t sys_ipc_poke(void)
     850sys_errno_t sys_ipc_poke(void)
    851851{
    852852        waitq_unsleep(&TASK->answerbox.wq);
     
    860860 * @param ucode   Uspace pointer to the top-half pseudocode.
    861861 *
    862  * @return IRQ kernel object capability
     862 * @param[out] uspace_handle  Uspace pointer to IRQ kernel object capability
     863 *
    863864 * @return EPERM
    864865 * @return Error code returned by ipc_irq_subscribe().
    865866 *
    866867 */
    867 sysarg_t sys_ipc_irq_subscribe(inr_t inr, sysarg_t imethod, irq_code_t *ucode)
     868sys_errno_t sys_ipc_irq_subscribe(inr_t inr, sysarg_t imethod, irq_code_t *ucode,
     869        cap_handle_t *uspace_handle)
    868870{
    869871        if (!(perm_get(TASK) & PERM_IRQ_REG))
    870872                return EPERM;
    871873       
    872         return ipc_irq_subscribe(&TASK->answerbox, inr, imethod, ucode);
     874        return ipc_irq_subscribe(&TASK->answerbox, inr, imethod, ucode, uspace_handle);
    873875}
    874876
     
    881883 *
    882884 */
    883 sysarg_t sys_ipc_irq_unsubscribe(sysarg_t cap)
     885sys_errno_t sys_ipc_irq_unsubscribe(sysarg_t cap)
    884886{
    885887        if (!(perm_get(TASK) & PERM_IRQ_REG))
     
    891893}
    892894
    893 #ifdef __32_BITS__
    894 
    895 /** Syscall connect to a task by ID (32 bits)
    896  *
    897  * @return Phone id on success, or negative error code.
    898  *
    899  */
    900 sysarg_t sys_ipc_connect_kbox(sysarg64_t *uspace_taskid)
     895/** Syscall connect to a task by ID
     896 *
     897 * @return Error code.
     898 *
     899 */
     900sys_errno_t sys_ipc_connect_kbox(task_id_t *uspace_taskid, cap_handle_t *uspace_phone)
    901901{
    902902#ifdef CONFIG_UDEBUG
    903         sysarg64_t taskid;
    904         int rc = copy_from_uspace(&taskid, uspace_taskid, sizeof(sysarg64_t));
    905         if (rc != 0)
    906                 return (sysarg_t) rc;
    907        
    908         return ipc_connect_kbox((task_id_t) taskid);
     903        task_id_t taskid;
     904        cap_handle_t phone;
     905       
     906        errno_t rc = copy_from_uspace(&taskid, uspace_taskid, sizeof(task_id_t));
     907        if (rc == EOK) {
     908                rc = ipc_connect_kbox((task_id_t) taskid, &phone);
     909        }
     910       
     911        if (rc == EOK) {
     912                rc = copy_to_uspace(uspace_phone, &phone, sizeof(cap_handle_t));
     913                if (rc != EOK) {
     914                        // Clean up the phone on failure.
     915                        sys_ipc_hangup(phone);
     916                }
     917        }
     918       
     919        return (sys_errno_t) rc;
    909920#else
    910         return (sysarg_t) ENOTSUP;
     921        return (sys_errno_t) ENOTSUP;
    911922#endif
    912923}
    913924
    914 #endif  /* __32_BITS__ */
    915 
    916 #ifdef __64_BITS__
    917 
    918 /** Syscall connect to a task by ID (64 bits)
    919  *
    920  * @return Phone id on success, or negative error code.
    921  *
    922  */
    923 sysarg_t sys_ipc_connect_kbox(sysarg_t taskid)
    924 {
    925 #ifdef CONFIG_UDEBUG
    926         return ipc_connect_kbox((task_id_t) taskid);
    927 #else
    928         return (sysarg_t) ENOTSUP;
    929 #endif
    930 }
    931 
    932 #endif  /* __64_BITS__ */
    933 
    934925/** @}
    935926 */
Note: See TracChangeset for help on using the changeset viewer.