Ignore:
File:
1 edited

Legend:

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

    r48bcf49 rae66564  
    3434
    3535#include <arch.h>
    36 #include <assert.h>
    3736#include <errno.h>
    38 #include <mem.h>
     37#include <memstr.h>
    3938#include <ipc/ipc.h>
    4039#include <abi/ipc/methods.h>
     
    4948#include <arch/interrupt.h>
    5049#include <syscall/copy.h>
    51 #include <security/perm.h>
     50#include <security/cap.h>
    5251#include <console/console.h>
    5352#include <print.h>
     
    8584{
    8685        switch (imethod) {
     86        case IPC_M_CONNECTION_CLONE:
     87        case IPC_M_CLONE_ESTABLISH:
    8788        case IPC_M_PHONE_HUNGUP:
    8889                /* This message is meant only for the original recipient. */
     
    133134{
    134135        switch (IPC_GET_IMETHOD(call->data)) {
     136        case IPC_M_CONNECTION_CLONE:
     137        case IPC_M_CLONE_ESTABLISH:
    135138        case IPC_M_CONNECT_TO_ME:
    136139        case IPC_M_CONNECT_ME_TO:
     
    171174                return rc;
    172175        } else {
    173                 assert(answer->active);
     176                ASSERT(answer->active);
    174177
    175178                /*
     
    260263/** Make a call over IPC and wait for reply.
    261264 *
    262  * @param handle       Phone capability handle for the call.
    263  * @param data[inout]  Structure with request/reply data.
    264  * @param priv         Value to be stored in call->priv.
     265 * @param phoneid     Phone handle for the call.
     266 * @param data[inout] Structure with request/reply data.
     267 * @param priv        Value to be stored in call->priv.
    265268 *
    266269 * @return EOK on success.
     
    268271 *
    269272 */
    270 int ipc_req_internal(cap_handle_t handle, ipc_data_t *data, sysarg_t priv)
    271 {
    272         kobject_t *kobj = kobject_get(TASK, handle, KOBJECT_TYPE_PHONE);
    273         if (!kobj->phone)
     273int ipc_req_internal(int phoneid, ipc_data_t *data, sysarg_t priv)
     274{
     275        phone_t *phone;
     276        if (phone_get(phoneid, &phone) != EOK)
    274277                return ENOENT;
    275278       
     
    278281        memcpy(call->data.args, data->args, sizeof(data->args));
    279282       
    280         int rc = request_preprocess(call, kobj->phone);
     283        int rc = request_preprocess(call, phone);
    281284        if (!rc) {
    282285#ifdef CONFIG_UDEBUG
     
    285288
    286289                ipc_call_hold(call);
    287                 rc = ipc_call_sync(kobj->phone, call);
     290                rc = ipc_call_sync(phone, call);
    288291                spinlock_lock(&call->forget_lock);
    289292                bool forgotten = call->forget;
     
    310313                                 * We are no longer expected to free it.
    311314                                 */
    312                                 assert(rc == EINTR);
     315                                ASSERT(rc == EINTR);
    313316                        }
    314                         kobject_put(kobj);
    315                         return rc;
     317                        return rc;     
    316318                }
    317319
     
    322324        memcpy(data->args, call->data.args, sizeof(data->args));
    323325        ipc_call_free(call);
    324         kobject_put(kobj);
    325326       
    326327        return EOK;
     
    348349 * the generic function sys_ipc_call_async_slow().
    349350 *
    350  * @param handle   Phone capability handle for the call.
    351  * @param imethod  Interface and method of the call.
    352  * @param arg1     Service-defined payload argument.
    353  * @param arg2     Service-defined payload argument.
    354  * @param arg3     Service-defined payload argument.
    355  * @param arg4     Service-defined payload argument.
     351 * @param phoneid Phone handle for the call.
     352 * @param imethod Interface and method of the call.
     353 * @param arg1    Service-defined payload argument.
     354 * @param arg2    Service-defined payload argument.
     355 * @param arg3    Service-defined payload argument.
     356 * @param arg4    Service-defined payload argument.
    356357 *
    357358 * @return Call hash on success.
     
    361362 *
    362363 */
    363 sysarg_t sys_ipc_call_async_fast(sysarg_t handle, sysarg_t imethod,
     364sysarg_t sys_ipc_call_async_fast(sysarg_t phoneid, sysarg_t imethod,
    364365    sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, sysarg_t arg4)
    365366{
    366         kobject_t *kobj = kobject_get(TASK, handle, KOBJECT_TYPE_PHONE);
    367         if (!kobj)
     367        phone_t *phone;
     368        if (phone_get(phoneid, &phone) != EOK)
    368369                return IPC_CALLRET_FATAL;
    369370       
    370         if (check_call_limit(kobj->phone)) {
    371                 kobject_put(kobj);
     371        if (check_call_limit(phone))
    372372                return IPC_CALLRET_TEMPORARY;
    373         }
    374373       
    375374        call_t *call = ipc_call_alloc(0);
     
    386385        IPC_SET_ARG5(call->data, 0);
    387386       
    388         int res = request_preprocess(call, kobj->phone);
     387        int res = request_preprocess(call, phone);
    389388       
    390389        if (!res)
    391                 ipc_call(kobj->phone, call);
     390                ipc_call(phone, call);
    392391        else
    393                 ipc_backsend_err(kobj->phone, call, res);
    394        
    395         kobject_put(kobj);
     392                ipc_backsend_err(phone, call, res);
     393       
    396394        return (sysarg_t) call;
    397395}
     
    399397/** Make an asynchronous IPC call allowing to transmit the entire payload.
    400398 *
    401  * @param handle  Phone capability for the call.
     399 * @param phoneid Phone handle for the call.
    402400 * @param data    Userspace address of call data with the request.
    403401 *
     
    405403 *
    406404 */
    407 sysarg_t sys_ipc_call_async_slow(sysarg_t handle, ipc_data_t *data)
    408 {
    409         kobject_t *kobj = kobject_get(TASK, handle, KOBJECT_TYPE_PHONE);
    410         if (!kobj)
     405sysarg_t sys_ipc_call_async_slow(sysarg_t phoneid, ipc_data_t *data)
     406{
     407        phone_t *phone;
     408        if (phone_get(phoneid, &phone) != EOK)
    411409                return IPC_CALLRET_FATAL;
    412410
    413         if (check_call_limit(kobj->phone)) {
    414                 kobject_put(kobj);
     411        if (check_call_limit(phone))
    415412                return IPC_CALLRET_TEMPORARY;
    416         }
    417413
    418414        call_t *call = ipc_call_alloc(0);
     
    421417        if (rc != 0) {
    422418                ipc_call_free(call);
    423                 kobject_put(kobj);
    424419                return (sysarg_t) rc;
    425420        }
    426421       
    427         int res = request_preprocess(call, kobj->phone);
     422        int res = request_preprocess(call, phone);
    428423       
    429424        if (!res)
    430                 ipc_call(kobj->phone, call);
     425                ipc_call(phone, call);
    431426        else
    432                 ipc_backsend_err(kobj->phone, call, res);
    433        
    434         kobject_put(kobj);
     427                ipc_backsend_err(phone, call, res);
     428       
    435429        return (sysarg_t) call;
    436430}
     
    440434 * Common code for both the fast and the slow version.
    441435 *
    442  * @param callid   Hash of the call to forward.
    443  * @param handle   Phone capability to use for forwarding.
    444  * @param imethod  New interface and method to use for the forwarded call.
    445  * @param arg1     New value of the first argument for the forwarded call.
    446  * @param arg2     New value of the second argument for the forwarded call.
    447  * @param arg3     New value of the third argument for the forwarded call.
    448  * @param arg4     New value of the fourth argument for the forwarded call.
    449  * @param arg5     New value of the fifth argument for the forwarded call.
    450  * @param mode     Flags that specify mode of the forward operation.
    451  * @param slow     If true, arg3, arg4 and arg5 are considered. Otherwise
    452  *                 the function considers only the fast version arguments:
    453  *                 i.e. arg1 and arg2.
     436 * @param callid  Hash of the call to forward.
     437 * @param phoneid Phone handle to use for forwarding.
     438 * @param imethod New interface and method to use for the forwarded call.
     439 * @param arg1    New value of the first argument for the forwarded call.
     440 * @param arg2    New value of the second argument for the forwarded call.
     441 * @param arg3    New value of the third argument for the forwarded call.
     442 * @param arg4    New value of the fourth argument for the forwarded call.
     443 * @param arg5    New value of the fifth argument for the forwarded call.
     444 * @param mode    Flags that specify mode of the forward operation.
     445 * @param slow    If true, arg3, arg4 and arg5 are considered. Otherwise
     446 *                the function considers only the fast version arguments:
     447 *                i.e. arg1 and arg2.
    454448 *
    455449 * @return 0 on succes, otherwise an error code.
     
    458452 *
    459453 */
    460 static sysarg_t sys_ipc_forward_common(sysarg_t callid, sysarg_t handle,
     454static sysarg_t sys_ipc_forward_common(sysarg_t callid, sysarg_t phoneid,
    461455    sysarg_t imethod, sysarg_t arg1, sysarg_t arg2, sysarg_t arg3,
    462456    sysarg_t arg4, sysarg_t arg5, unsigned int mode, bool slow)
     
    473467        bool after_forward = false;
    474468        int rc;
    475 
    476         kobject_t *kobj = kobject_get(TASK, handle, KOBJECT_TYPE_PHONE);
    477         if (!kobj) {
     469        phone_t *phone;
     470       
     471        if (phone_get(phoneid, &phone) != EOK) {
    478472                rc = ENOENT;
    479473                goto error;
     
    521515        }
    522516       
    523         rc = ipc_forward(call, kobj->phone, &TASK->answerbox, mode);
     517        rc = ipc_forward(call, phone, &TASK->answerbox, mode);
    524518        if (rc != EOK) {
    525519                after_forward = true;
     
    527521        }
    528522
    529         kobject_put(kobj);
    530523        return EOK;
    531524
     
    538531                ipc_answer(&TASK->answerbox, call);
    539532
    540         if (kobj)
    541                 kobject_put(kobj);
    542533        return rc;
    543534}
     
    552543 * arguments are not set and these values are ignored.
    553544 *
    554  * @param callid   Hash of the call to forward.
    555  * @param handle  Phone handle to use for forwarding.
    556  * @param imethod  New interface and method to use for the forwarded call.
    557  * @param arg1     New value of the first argument for the forwarded call.
    558  * @param arg2     New value of the second argument for the forwarded call.
    559  * @param mode     Flags that specify mode of the forward operation.
     545 * @param callid  Hash of the call to forward.
     546 * @param phoneid Phone handle to use for forwarding.
     547 * @param imethod New interface and method to use for the forwarded call.
     548 * @param arg1    New value of the first argument for the forwarded call.
     549 * @param arg2    New value of the second argument for the forwarded call.
     550 * @param mode    Flags that specify mode of the forward operation.
    560551 *
    561552 * @return 0 on succes, otherwise an error code.
    562553 *
    563554 */
    564 sysarg_t sys_ipc_forward_fast(sysarg_t callid, sysarg_t handle,
     555sysarg_t sys_ipc_forward_fast(sysarg_t callid, sysarg_t phoneid,
    565556    sysarg_t imethod, sysarg_t arg1, sysarg_t arg2, unsigned int mode)
    566557{
    567         return sys_ipc_forward_common(callid, handle, imethod, arg1, arg2, 0, 0,
     558        return sys_ipc_forward_common(callid, phoneid, imethod, arg1, arg2, 0, 0,
    568559            0, mode, false);
    569560}
     
    579570 *
    580571 * @param callid  Hash of the call to forward.
    581  * @param handle Phone handle to use for forwarding.
     572 * @param phoneid Phone handle to use for forwarding.
    582573 * @param data    Userspace address of the new IPC data.
    583574 * @param mode    Flags that specify mode of the forward operation.
     
    586577 *
    587578 */
    588 sysarg_t sys_ipc_forward_slow(sysarg_t callid, sysarg_t handle,
     579sysarg_t sys_ipc_forward_slow(sysarg_t callid, sysarg_t phoneid,
    589580    ipc_data_t *data, unsigned int mode)
    590581{
     
    595586                return (sysarg_t) rc;
    596587       
    597         return sys_ipc_forward_common(callid, handle,
     588        return sys_ipc_forward_common(callid, phoneid,
    598589            IPC_GET_IMETHOD(newdata), IPC_GET_ARG1(newdata),
    599590            IPC_GET_ARG2(newdata), IPC_GET_ARG3(newdata),
     
    693684/** Hang up a phone.
    694685 *
    695  * @param handle  Phone capability handle of the phone to be hung up.
     686 * @param Phone handle of the phone to be hung up.
    696687 *
    697688 * @return 0 on success or an error code.
    698689 *
    699690 */
    700 sysarg_t sys_ipc_hangup(sysarg_t handle)
    701 {
    702         kobject_t *kobj = kobject_get(TASK, handle, KOBJECT_TYPE_PHONE);
    703         if (!kobj)
     691sysarg_t sys_ipc_hangup(sysarg_t phoneid)
     692{
     693        phone_t *phone;
     694       
     695        if (phone_get(phoneid, &phone) != EOK)
    704696                return ENOENT;
    705697       
    706         if (ipc_phone_hangup(kobj->phone)) {
    707                 kobject_put(kobj);
     698        if (ipc_phone_hangup(phone))
    708699                return -1;
    709         }
    710        
    711         kobject_put(kobj);
     700       
    712701        return 0;
    713702}
     
    812801 *
    813802 * @param inr     IRQ number.
     803 * @param devno   Device number.
    814804 * @param imethod Interface and method to be associated with the notification.
    815805 * @param ucode   Uspace pointer to the top-half pseudocode.
    816806 *
    817  * @return IRQ kernel object capability
    818  * @return EPERM
    819  * @return Error code returned by ipc_irq_subscribe().
    820  *
    821  */
    822 sysarg_t sys_ipc_irq_subscribe(inr_t inr, sysarg_t imethod, irq_code_t *ucode)
    823 {
    824         if (!(perm_get(TASK) & PERM_IRQ_REG))
     807 * @return EPERM or a return code returned by ipc_irq_subscribe().
     808 *
     809 */
     810sysarg_t sys_ipc_irq_subscribe(inr_t inr, devno_t devno, sysarg_t imethod,
     811    irq_code_t *ucode)
     812{
     813        if (!(cap_get(TASK) & CAP_IRQ_REG))
    825814                return EPERM;
    826815       
    827         return ipc_irq_subscribe(&TASK->answerbox, inr, imethod, ucode);
     816        return ipc_irq_subscribe(&TASK->answerbox, inr, devno, imethod, ucode);
    828817}
    829818
     
    836825 *
    837826 */
    838 sysarg_t sys_ipc_irq_unsubscribe(sysarg_t cap)
    839 {
    840         if (!(perm_get(TASK) & PERM_IRQ_REG))
     827sysarg_t sys_ipc_irq_unsubscribe(inr_t inr, devno_t devno)
     828{
     829        if (!(cap_get(TASK) & CAP_IRQ_REG))
    841830                return EPERM;
    842831       
    843         ipc_irq_unsubscribe(&TASK->answerbox, cap);
     832        ipc_irq_unsubscribe(&TASK->answerbox, inr, devno);
    844833       
    845834        return 0;
Note: See TracChangeset for help on using the changeset viewer.