Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 09d01f2 in mainline


Ignore:
Timestamp:
2017-12-18T17:40:52Z (4 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
lfn, master
Children:
2024096, 23d4515
Parents:
6a32cc5f
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2017-12-18 15:39:01)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2017-12-18 17:40:52)
Message:

Return phones/capabilities separately from error codes.

Location:
kernel/generic
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/include/cap/cap.h

    r6a32cc5f r09d01f2  
    121121    bool (*)(cap_t *, void *), void *);
    122122
    123 extern cap_handle_t cap_alloc(struct task *);
     123extern int cap_alloc(struct task *, cap_handle_t *);
    124124extern void cap_publish(struct task *, cap_handle_t, kobject_t *);
    125125extern kobject_t *cap_unpublish(struct task *, cap_handle_t, kobject_type_t);
  • kernel/generic/include/ipc/ipcrsc.h

    r6a32cc5f r09d01f2  
    4040#include <cap/cap.h>
    4141
    42 extern cap_handle_t phone_alloc(task_t *);
     42extern int phone_alloc(task_t *, cap_handle_t *);
    4343extern bool phone_connect(cap_handle_t, answerbox_t *);
    4444extern void phone_dealloc(cap_handle_t);
  • kernel/generic/src/cap/cap.c

    r6a32cc5f r09d01f2  
    257257 * @param task  Task for which to allocate the new capability.
    258258 *
    259  * @return New capability handle on success.
     259 * @param[out] handle  New capability handle on success.
     260 *
    260261 * @return Negative error code in case of error.
    261262 */
    262 cap_handle_t cap_alloc(task_t *task)
     263int cap_alloc(task_t *task, cap_handle_t *handle)
    263264{
    264265        cap_t *cap = NULL;
    265         cap_handle_t handle;
    266266
    267267        /*
     
    293293
    294294        cap->state = CAP_STATE_ALLOCATED;
    295         handle = cap->handle;
    296         mutex_unlock(&task->cap_info->lock);
    297 
    298         return handle;
     295        *handle = cap->handle;
     296        mutex_unlock(&task->cap_info->lock);
     297
     298        return EOK;
    299299}
    300300
  • kernel/generic/src/ipc/ipcrsc.c

    r6a32cc5f r09d01f2  
    166166 * @param task  Task for which to allocate a new phone.
    167167 *
    168  * @return  New phone capability handle.
     168 * @param[out] out_handle  New phone capability handle.
     169 *
    169170 * @return  Negative error code if a new capability cannot be allocated.
    170171 */
    171 cap_handle_t phone_alloc(task_t *task)
    172 {
    173         cap_handle_t handle = cap_alloc(task);
    174         if (handle >= 0) {
     172int phone_alloc(task_t *task, cap_handle_t *out_handle)
     173{
     174        cap_handle_t handle;
     175        int rc = cap_alloc(task, &handle);
     176        if (rc == EOK) {
    175177                phone_t *phone = slab_alloc(phone_cache, FRAME_ATOMIC);
    176178                if (!phone) {
     
    193195               
    194196                cap_publish(task, handle, kobject);
     197
     198                *out_handle = handle;
    195199        }
    196        
    197         return handle;
     200        return rc;
    198201}
    199202
  • kernel/generic/src/ipc/irq.c

    r6a32cc5f r09d01f2  
    330330         * Allocate and populate the IRQ kernel object.
    331331         */
    332         cap_handle_t handle = cap_alloc(TASK);
    333         if (handle < 0)
    334                 return handle;
    335        
    336         int rc = copy_to_uspace(uspace_handle, &handle, sizeof(cap_handle_t));
     332        cap_handle_t handle;
     333        int rc = cap_alloc(TASK, &handle);
     334        if (rc != EOK)
     335                return rc;
     336       
     337        rc = copy_to_uspace(uspace_handle, &handle, sizeof(cap_handle_t));
    337338        if (rc != EOK) {
    338339                cap_free(TASK, handle);
  • kernel/generic/src/ipc/kbox.c

    r6a32cc5f r09d01f2  
    252252       
    253253        /* Allocate a new phone. */
    254         cap_handle_t phone_handle = phone_alloc(TASK);
    255         if (phone_handle < 0) {
     254        cap_handle_t phone_handle;
     255        int rc = phone_alloc(TASK, &phone_handle);
     256        if (rc != EOK) {
    256257                mutex_unlock(&task->kb.cleanup_lock);
    257                 return phone_handle;
     258                return rc;
    258259        }
    259260       
  • kernel/generic/src/ipc/ops/conctmeto.c

    r6a32cc5f r09d01f2  
    4242static int request_preprocess(call_t *call, phone_t *phone)
    4343{
    44         cap_handle_t phone_handle = phone_alloc(TASK);
     44        cap_handle_t phone_handle;
     45        int rc = phone_alloc(TASK, &phone_handle);
    4546
    46         /* Remember the phone capability or the error. */
    47         call->priv = phone_handle;
    48         if (phone_handle < 0)
    49                 return phone_handle;
     47        /* Remember the phone capability or that an error occured. */
     48        call->priv = (rc == EOK) ? phone_handle : -1;
     49
     50        if (rc != EOK) {
     51                return rc;
     52        }
    5053
    5154        /* Set arg5 for server */
     
    6164{
    6265        cap_handle_t phone_handle = (cap_handle_t) call->priv;
     66
     67        if (phone_handle < 0) {
     68                return EOK;
     69        }
     70
    6371        phone_dealloc(phone_handle);
    6472        /* Hand over reference from ARG5 to phone->kobject */
  • kernel/generic/src/ipc/ops/concttome.c

    r6a32cc5f r09d01f2  
    4242static int request_process(call_t *call, answerbox_t *box)
    4343{
    44         cap_handle_t phone_handle = phone_alloc(TASK);
    45 
    46         IPC_SET_ARG5(call->data, phone_handle);
    47        
    48         return EOK;
     44        cap_handle_t phone_handle;
     45        int rc = phone_alloc(TASK, &phone_handle);
     46        IPC_SET_ARG5(call->data, (rc == EOK) ? phone_handle : -1);
     47        return 0;
    4948}
    5049
  • kernel/generic/src/ipc/sysipc.c

    r6a32cc5f r09d01f2  
    804804                goto restart;
    805805       
    806         int rc;
    807         cap_handle_t handle = cap_alloc(TASK);
    808         if (handle < 0) {
    809                 rc = handle;
     806        cap_handle_t handle;
     807        int rc = cap_alloc(TASK, &handle);
     808        if (rc != EOK) {
    810809                goto error;
    811810        }
  • kernel/generic/src/proc/task.c

    r6a32cc5f r09d01f2  
    245245        if ((ipc_phone_0) &&
    246246            (container_check(ipc_phone_0->task->container, task->container))) {
    247                 cap_handle_t phone_handle = phone_alloc(task);
    248                 if (phone_handle < 0) {
     247                cap_handle_t phone_handle;
     248                int rc = phone_alloc(task, &phone_handle);
     249                if (rc != EOK) {
    249250                        task->as = NULL;
    250251                        task_destroy_arch(task);
Note: See TracChangeset for help on using the changeset viewer.