Changeset 9e87562 in mainline for kernel/generic/src/ipc/irq.c


Ignore:
Timestamp:
2017-09-18T20:52:12Z (7 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
6abfd250
Parents:
e5f5ce0
Message:

Make all accesses to capabilites exclusive

This commit makes sure that all accesses to the capabilities array and other
metadata are protected by a mutex. This is necessary for future resizing of the
capabilities array.

Group task's capabilities by type so that it is possible to visit all
capabilities of the given type effectively.

Provide cap_publish() and cap_unpublish() to automate steps that make the
capability visible/invisible to userspace and insert/remove the capability from
the respective type list.

File:
1 edited

Legend:

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

    re5f5ce0 r9e87562  
    314314        }
    315315       
    316         cap_t *cap = cap_get_current(handle, CAP_TYPE_ALLOCATED);
    317         assert(cap);
    318        
    319316        irq_initialize(irq);
    320317        irq->inr = inr;
     
    327324        irq->notif_cfg.counter = 0;
    328325       
    329         cap->kobject = (void *) irq;
    330        
    331326        /*
    332          * Insert the IRQ structure into the uspace IRQ hash table and retype
    333          * the capability. By retyping the capability inside the critical
    334          * section, we make sure another thread cannot attempt to unregister the
    335          * IRQ before it is inserted into the hash table.
     327         * Insert the IRQ structure into the uspace IRQ hash table.
    336328         */
    337329        irq_spinlock_lock(&irq_uspace_hash_table_lock, true);
    338330        irq_spinlock_lock(&irq->lock, false);
    339331       
    340         cap->type = CAP_TYPE_IRQ;
    341332        hash_table_insert(&irq_uspace_hash_table, key, &irq->link);
    342333       
    343334        irq_spinlock_unlock(&irq->lock, false);
    344335        irq_spinlock_unlock(&irq_uspace_hash_table_lock, true);
     336
     337        cap_publish(TASK, handle, CAP_TYPE_IRQ, irq);
    345338       
    346339        return handle;
     
    357350int ipc_irq_unsubscribe(answerbox_t *box, int handle)
    358351{
    359         irq_spinlock_lock(&TASK->lock, true);
    360         cap_t *cap = cap_get_current(handle, CAP_TYPE_IRQ);
    361         if (!cap) {
    362                 irq_spinlock_unlock(&TASK->lock, true);
     352        cap_t *cap = cap_unpublish(TASK, handle, CAP_TYPE_IRQ);
     353        if (!cap)
    363354                return ENOENT;
    364         }
    365         /* Make sure only one thread can win the race to unsubscribe. */
    366         cap->type = CAP_TYPE_ALLOCATED;
    367         irq_spinlock_unlock(&TASK->lock, true);
    368355       
    369356        irq_t *irq = (irq_t *) cap->kobject;
Note: See TracChangeset for help on using the changeset viewer.