Changeset 63d8f43 in mainline


Ignore:
Timestamp:
2017-09-04T19:38:28Z (7 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
fa32c9f
Parents:
30c27e9
Message:

Allocate the kobjects referenced by capabilities dynamically

Location:
kernel/generic
Files:
6 edited

Legend:

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

    r30c27e9 r63d8f43  
    3838#include <typedefs.h>
    3939#include <ipc/ipc.h>
    40 #include <ddi/irq.h>
    4140
    4241#define MAX_CAPS  64
     
    6463
    6564        /* The underlying kernel object. */
    66         union {
    67                 phone_t phone;
    68                 irq_t irq;
    69         };
     65        void *kobject;
    7066} cap_t;
    7167
  • kernel/generic/src/cap/cap.c

    r30c27e9 r63d8f43  
    102102        assert(handle >= 0);
    103103        assert(handle < MAX_CAPS);
    104         assert(task->caps[handle].type != CAP_TYPE_INVALID);
     104        assert(task->caps[handle].type == CAP_TYPE_ALLOCATED);
    105105
    106106        irq_spinlock_lock(&task->lock, true);
  • kernel/generic/src/ipc/ipc.c

    r30c27e9 r63d8f43  
    743743        all_clean = true;
    744744        for_each_cap_current(cap, CAP_TYPE_PHONE) {
    745                 phone_t *phone = &cap->phone;
     745                phone_t *phone = (phone_t *) cap->kobject;
    746746
    747747                mutex_lock(&phone->lock);
     
    820820        /* Disconnect all our phones ('ipc_phone_hangup') */
    821821        for_each_cap_current(cap, CAP_TYPE_PHONE) {
    822                 phone_t *phone = &cap->phone;
     822                phone_t *phone = (phone_t *) cap->kobject;
    823823                ipc_phone_hangup(phone);
    824824        }
     
    913913       
    914914        for_each_cap(task, cap, CAP_TYPE_PHONE) {
    915                 phone_t *phone = &cap->phone;
     915                phone_t *phone = (phone_t *) cap->kobject;
    916916       
    917917                if (SYNCH_FAILED(mutex_trylock(&phone->lock))) {
  • kernel/generic/src/ipc/ipcrsc.c

    r30c27e9 r63d8f43  
    135135#include <abi/errno.h>
    136136#include <cap/cap.h>
     137#include <mm/slab.h>
    137138
    138139/** Find call_t * in call table according to callid.
     
    178179                return NULL;
    179180       
    180         return &cap->phone;
     181        return (phone_t *) cap->kobject;
    181182}
    182183
     
    190191        assert(cap->type == CAP_TYPE_PHONE);
    191192
    192         return (cap->phone.state == IPC_PHONE_HUNGUP) &&
    193             (atomic_get(&cap->phone.active_calls) == 0);
     193        phone_t *phone = (phone_t *) cap->kobject;
     194
     195        return (phone->state == IPC_PHONE_HUNGUP) &&
     196            (atomic_get(&phone->active_calls) == 0);
    194197}
    195198
     
    205208        int handle = cap_alloc(task);
    206209        if (handle >= 0) {
     210                phone_t *phone = malloc(sizeof(phone_t), FRAME_ATOMIC);
     211                if (!phone) {
     212                        cap_free(TASK, handle);
     213                        return ENOMEM;
     214                }
     215               
     216                ipc_phone_init(phone, task);
     217                phone->state = IPC_PHONE_CONNECTING;
     218               
    207219                irq_spinlock_lock(&task->lock, true);
    208220                cap_t *cap = cap_get(task, handle, CAP_TYPE_ALLOCATED);
    209                 ipc_phone_init(&cap->phone, task);
    210221                cap->type = CAP_TYPE_PHONE;
     222                cap->kobject = (void *) phone;
    211223                cap->can_reclaim = phone_can_reclaim;
    212                 cap->phone.state = IPC_PHONE_CONNECTING;
    213224                irq_spinlock_unlock(&task->lock, true);
    214225        }
     
    226237void phone_dealloc(int handle)
    227238{
    228         phone_t *phone = phone_get_current(handle);
     239        irq_spinlock_lock(&TASK->lock, true);
     240        cap_t *cap = cap_get_current(handle, CAP_TYPE_PHONE);
     241        assert(cap);
     242        cap->type = CAP_TYPE_ALLOCATED;
     243        irq_spinlock_unlock(&TASK->lock, true);
     244       
     245        phone_t *phone = (phone_t *) cap->kobject;
    229246       
    230247        assert(phone);
    231248        assert(phone->state == IPC_PHONE_CONNECTING);
    232 
     249       
     250        free(phone);
    233251        cap_free(TASK, handle);
    234252}
  • kernel/generic/src/ipc/irq.c

    r30c27e9 r63d8f43  
    307307        if (handle < 0)
    308308                return handle;
     309       
     310        irq_t *irq = (irq_t *) malloc(sizeof(irq_t), FRAME_ATOMIC);
     311        if (!irq) {
     312                cap_free(TASK, handle);
     313                return ENOMEM;
     314        }
     315       
    309316        cap_t *cap = cap_get_current(handle, CAP_TYPE_ALLOCATED);
    310317        assert(cap);
    311318       
    312         irq_t *irq = &cap->irq;
    313319        irq_initialize(irq);
    314320        irq->inr = inr;
     
    321327        irq->notif_cfg.counter = 0;
    322328       
     329        cap->kobject = (void *) irq;
     330       
    323331        /*
    324332         * Insert the IRQ structure into the uspace IRQ hash table and retype
     
    359367        irq_spinlock_unlock(&TASK->lock, true);
    360368       
    361         irq_t *irq = &cap->irq;
     369        irq_t *irq = (irq_t *) cap->kobject;
    362370       
    363371        irq_spinlock_lock(&irq_uspace_hash_table_lock, true);
     
    376384       
    377385        /* Free up the IRQ capability and the underlying kernel object. */
     386        free(cap->kobject);
    378387        cap_free(TASK, handle);
    379388       
  • kernel/generic/src/proc/task.c

    r30c27e9 r63d8f43  
    625625        if (*additional) {
    626626                for_each_cap(task, cap, CAP_TYPE_PHONE) {
    627                         phone_t *phone = &cap->phone;
     627                        phone_t *phone = (void *) &cap->kobject;
    628628                        if (phone->callee)
    629629                                printf(" %d:%p", cap->handle, phone->callee);
Note: See TracChangeset for help on using the changeset viewer.