Ignore:
File:
1 edited

Legend:

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

    rae66564 r48bcf49  
    3434
    3535#include <arch.h>
     36#include <assert.h>
    3637#include <errno.h>
    37 #include <memstr.h>
     38#include <mem.h>
    3839#include <ipc/ipc.h>
    3940#include <abi/ipc/methods.h>
     
    4849#include <arch/interrupt.h>
    4950#include <syscall/copy.h>
    50 #include <security/cap.h>
     51#include <security/perm.h>
    5152#include <console/console.h>
    5253#include <print.h>
     
    8485{
    8586        switch (imethod) {
    86         case IPC_M_CONNECTION_CLONE:
    87         case IPC_M_CLONE_ESTABLISH:
    8887        case IPC_M_PHONE_HUNGUP:
    8988                /* This message is meant only for the original recipient. */
     
    134133{
    135134        switch (IPC_GET_IMETHOD(call->data)) {
    136         case IPC_M_CONNECTION_CLONE:
    137         case IPC_M_CLONE_ESTABLISH:
    138135        case IPC_M_CONNECT_TO_ME:
    139136        case IPC_M_CONNECT_ME_TO:
     
    174171                return rc;
    175172        } else {
    176                 ASSERT(answer->active);
     173                assert(answer->active);
    177174
    178175                /*
     
    263260/** Make a call over IPC and wait for reply.
    264261 *
    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.
     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.
    268265 *
    269266 * @return EOK on success.
     
    271268 *
    272269 */
    273 int ipc_req_internal(int phoneid, ipc_data_t *data, sysarg_t priv)
    274 {
    275         phone_t *phone;
    276         if (phone_get(phoneid, &phone) != EOK)
     270int 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)
    277274                return ENOENT;
    278275       
     
    281278        memcpy(call->data.args, data->args, sizeof(data->args));
    282279       
    283         int rc = request_preprocess(call, phone);
     280        int rc = request_preprocess(call, kobj->phone);
    284281        if (!rc) {
    285282#ifdef CONFIG_UDEBUG
     
    288285
    289286                ipc_call_hold(call);
    290                 rc = ipc_call_sync(phone, call);
     287                rc = ipc_call_sync(kobj->phone, call);
    291288                spinlock_lock(&call->forget_lock);
    292289                bool forgotten = call->forget;
     
    313310                                 * We are no longer expected to free it.
    314311                                 */
    315                                 ASSERT(rc == EINTR);
     312                                assert(rc == EINTR);
    316313                        }
    317                         return rc;     
     314                        kobject_put(kobj);
     315                        return rc;
    318316                }
    319317
     
    324322        memcpy(data->args, call->data.args, sizeof(data->args));
    325323        ipc_call_free(call);
     324        kobject_put(kobj);
    326325       
    327326        return EOK;
     
    349348 * the generic function sys_ipc_call_async_slow().
    350349 *
    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.
     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.
    357356 *
    358357 * @return Call hash on success.
     
    362361 *
    363362 */
    364 sysarg_t sys_ipc_call_async_fast(sysarg_t phoneid, sysarg_t imethod,
     363sysarg_t sys_ipc_call_async_fast(sysarg_t handle, sysarg_t imethod,
    365364    sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, sysarg_t arg4)
    366365{
    367         phone_t *phone;
    368         if (phone_get(phoneid, &phone) != EOK)
     366        kobject_t *kobj = kobject_get(TASK, handle, KOBJECT_TYPE_PHONE);
     367        if (!kobj)
    369368                return IPC_CALLRET_FATAL;
    370369       
    371         if (check_call_limit(phone))
     370        if (check_call_limit(kobj->phone)) {
     371                kobject_put(kobj);
    372372                return IPC_CALLRET_TEMPORARY;
     373        }
    373374       
    374375        call_t *call = ipc_call_alloc(0);
     
    385386        IPC_SET_ARG5(call->data, 0);
    386387       
    387         int res = request_preprocess(call, phone);
     388        int res = request_preprocess(call, kobj->phone);
    388389       
    389390        if (!res)
    390                 ipc_call(phone, call);
     391                ipc_call(kobj->phone, call);
    391392        else
    392                 ipc_backsend_err(phone, call, res);
    393        
     393                ipc_backsend_err(kobj->phone, call, res);
     394       
     395        kobject_put(kobj);
    394396        return (sysarg_t) call;
    395397}
     
    397399/** Make an asynchronous IPC call allowing to transmit the entire payload.
    398400 *
    399  * @param phoneid Phone handle for the call.
     401 * @param handle  Phone capability for the call.
    400402 * @param data    Userspace address of call data with the request.
    401403 *
     
    403405 *
    404406 */
    405 sysarg_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)
     407sysarg_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)
    409411                return IPC_CALLRET_FATAL;
    410412
    411         if (check_call_limit(phone))
     413        if (check_call_limit(kobj->phone)) {
     414                kobject_put(kobj);
    412415                return IPC_CALLRET_TEMPORARY;
     416        }
    413417
    414418        call_t *call = ipc_call_alloc(0);
     
    417421        if (rc != 0) {
    418422                ipc_call_free(call);
     423                kobject_put(kobj);
    419424                return (sysarg_t) rc;
    420425        }
    421426       
    422         int res = request_preprocess(call, phone);
     427        int res = request_preprocess(call, kobj->phone);
    423428       
    424429        if (!res)
    425                 ipc_call(phone, call);
     430                ipc_call(kobj->phone, call);
    426431        else
    427                 ipc_backsend_err(phone, call, res);
    428        
     432                ipc_backsend_err(kobj->phone, call, res);
     433       
     434        kobject_put(kobj);
    429435        return (sysarg_t) call;
    430436}
     
    434440 * Common code for both the fast and the slow version.
    435441 *
    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.
     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.
    448454 *
    449455 * @return 0 on succes, otherwise an error code.
     
    452458 *
    453459 */
    454 static sysarg_t sys_ipc_forward_common(sysarg_t callid, sysarg_t phoneid,
     460static sysarg_t sys_ipc_forward_common(sysarg_t callid, sysarg_t handle,
    455461    sysarg_t imethod, sysarg_t arg1, sysarg_t arg2, sysarg_t arg3,
    456462    sysarg_t arg4, sysarg_t arg5, unsigned int mode, bool slow)
     
    467473        bool after_forward = false;
    468474        int rc;
    469         phone_t *phone;
    470        
    471         if (phone_get(phoneid, &phone) != EOK) {
     475
     476        kobject_t *kobj = kobject_get(TASK, handle, KOBJECT_TYPE_PHONE);
     477        if (!kobj) {
    472478                rc = ENOENT;
    473479                goto error;
     
    515521        }
    516522       
    517         rc = ipc_forward(call, phone, &TASK->answerbox, mode);
     523        rc = ipc_forward(call, kobj->phone, &TASK->answerbox, mode);
    518524        if (rc != EOK) {
    519525                after_forward = true;
     
    521527        }
    522528
     529        kobject_put(kobj);
    523530        return EOK;
    524531
     
    531538                ipc_answer(&TASK->answerbox, call);
    532539
     540        if (kobj)
     541                kobject_put(kobj);
    533542        return rc;
    534543}
     
    543552 * arguments are not set and these values are ignored.
    544553 *
    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.
     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.
    551560 *
    552561 * @return 0 on succes, otherwise an error code.
    553562 *
    554563 */
    555 sysarg_t sys_ipc_forward_fast(sysarg_t callid, sysarg_t phoneid,
     564sysarg_t sys_ipc_forward_fast(sysarg_t callid, sysarg_t handle,
    556565    sysarg_t imethod, sysarg_t arg1, sysarg_t arg2, unsigned int mode)
    557566{
    558         return sys_ipc_forward_common(callid, phoneid, imethod, arg1, arg2, 0, 0,
     567        return sys_ipc_forward_common(callid, handle, imethod, arg1, arg2, 0, 0,
    559568            0, mode, false);
    560569}
     
    570579 *
    571580 * @param callid  Hash of the call to forward.
    572  * @param phoneid Phone handle to use for forwarding.
     581 * @param handle Phone handle to use for forwarding.
    573582 * @param data    Userspace address of the new IPC data.
    574583 * @param mode    Flags that specify mode of the forward operation.
     
    577586 *
    578587 */
    579 sysarg_t sys_ipc_forward_slow(sysarg_t callid, sysarg_t phoneid,
     588sysarg_t sys_ipc_forward_slow(sysarg_t callid, sysarg_t handle,
    580589    ipc_data_t *data, unsigned int mode)
    581590{
     
    586595                return (sysarg_t) rc;
    587596       
    588         return sys_ipc_forward_common(callid, phoneid,
     597        return sys_ipc_forward_common(callid, handle,
    589598            IPC_GET_IMETHOD(newdata), IPC_GET_ARG1(newdata),
    590599            IPC_GET_ARG2(newdata), IPC_GET_ARG3(newdata),
     
    684693/** Hang up a phone.
    685694 *
    686  * @param Phone handle of the phone to be hung up.
     695 * @param handle  Phone capability handle of the phone to be hung up.
    687696 *
    688697 * @return 0 on success or an error code.
    689698 *
    690699 */
    691 sysarg_t sys_ipc_hangup(sysarg_t phoneid)
    692 {
    693         phone_t *phone;
    694        
    695         if (phone_get(phoneid, &phone) != EOK)
     700sysarg_t sys_ipc_hangup(sysarg_t handle)
     701{
     702        kobject_t *kobj = kobject_get(TASK, handle, KOBJECT_TYPE_PHONE);
     703        if (!kobj)
    696704                return ENOENT;
    697705       
    698         if (ipc_phone_hangup(phone))
     706        if (ipc_phone_hangup(kobj->phone)) {
     707                kobject_put(kobj);
    699708                return -1;
    700        
     709        }
     710       
     711        kobject_put(kobj);
    701712        return 0;
    702713}
     
    801812 *
    802813 * @param inr     IRQ number.
    803  * @param devno   Device number.
    804814 * @param imethod Interface and method to be associated with the notification.
    805815 * @param ucode   Uspace pointer to the top-half pseudocode.
    806816 *
    807  * @return EPERM or a return code returned by ipc_irq_subscribe().
    808  *
    809  */
    810 sysarg_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))
     817 * @return IRQ kernel object capability
     818 * @return EPERM
     819 * @return Error code returned by ipc_irq_subscribe().
     820 *
     821 */
     822sysarg_t sys_ipc_irq_subscribe(inr_t inr, sysarg_t imethod, irq_code_t *ucode)
     823{
     824        if (!(perm_get(TASK) & PERM_IRQ_REG))
    814825                return EPERM;
    815826       
    816         return ipc_irq_subscribe(&TASK->answerbox, inr, devno, imethod, ucode);
     827        return ipc_irq_subscribe(&TASK->answerbox, inr, imethod, ucode);
    817828}
    818829
     
    825836 *
    826837 */
    827 sysarg_t sys_ipc_irq_unsubscribe(inr_t inr, devno_t devno)
    828 {
    829         if (!(cap_get(TASK) & CAP_IRQ_REG))
     838sysarg_t sys_ipc_irq_unsubscribe(sysarg_t cap)
     839{
     840        if (!(perm_get(TASK) & PERM_IRQ_REG))
    830841                return EPERM;
    831842       
    832         ipc_irq_unsubscribe(&TASK->answerbox, inr, devno);
     843        ipc_irq_unsubscribe(&TASK->answerbox, cap);
    833844       
    834845        return 0;
Note: See TracChangeset for help on using the changeset viewer.