Changeset 2569ec90 in mainline


Ignore:
Timestamp:
2006-06-05T18:15:30Z (18 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
b65caba1
Parents:
31e8ddd
Message:

In task_kill(), remove the task from the tasks_btree before proceeding.
Thus, when the kernel finds the task in the tasks_btree and locks it before
releasing tasks_lock, it is guaranteed that the task will not be destroyed
until the lock is held. If the kernel needs to unlock the task, do some operation
and lock it again, it should increase its refcount before doing so. In that case,
when releasing the lock, it must decrement the refcount and if it reaches
zero, it must call task_destroy().

Location:
generic/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • generic/src/ddi/ddi.c

    r31e8ddd r2569ec90  
    136136        }
    137137
    138         /*
    139          * TODO: We are currently lacking support for task destroying.
    140          * Once it is added to the kernel, we must take care to
    141          * synchronize in a way that prevents race conditions here.
    142          */
    143        
    144138        /* Lock the task and release the lock protecting tasks_btree. */
    145139        spinlock_lock(&t->lock);
  • generic/src/proc/task.c

    r31e8ddd r2569ec90  
    141141void task_destroy(task_t *t)
    142142{
    143         spinlock_lock(&tasks_lock);
    144         btree_remove(&tasks_btree, t->taskid, NULL);
    145         spinlock_unlock(&tasks_lock);
    146 
    147143        task_destroy_arch(t);
    148144        btree_destroy(&t->futexes);
     
    275271                return ENOENT;
    276272        }
    277        
     273
    278274        spinlock_lock(&ta->lock);
    279275        ta->refcount++;
    280276        spinlock_unlock(&ta->lock);
    281277
     278        btree_remove(&tasks_btree, ta->taskid, NULL);
    282279        spinlock_unlock(&tasks_lock);
    283280       
  • generic/src/security/cap.c

    r31e8ddd r2569ec90  
    113113                return (__native) ENOENT;
    114114        }
     115       
     116        spinlock_lock(&t->lock);
     117        cap_set(t, cap_get(t) | caps);
     118        spinlock_unlock(&t->lock);
     119       
    115120        spinlock_unlock(&tasks_lock);
    116121       
    117         cap_set(t, cap_get(t) | caps);
     122
    118123       
    119124        interrupts_restore(ipl);       
     
    150155                return (__native) ENOENT;
    151156        }
    152         spinlock_unlock(&tasks_lock);
    153157
    154158        /*
     
    158162         */
    159163        if (!(cap_get(TASK) & CAP_CAP) || !(t == TASK)) {
     164                spinlock_unlock(&tasks_lock);
    160165                interrupts_restore(ipl);
    161166                return (__native) EPERM;
    162167        }
     168       
     169        spinlock_lock(&t->lock);
     170        cap_set(t, cap_get(t) & ~caps);
     171        spinlock_unlock(&t->lock);
    163172
    164         cap_set(t, cap_get(t) & ~caps);
    165        
     173        spinlock_unlock(&tasks_lock);
     174
    166175        interrupts_restore(ipl);
    167176        return 0;
Note: See TracChangeset for help on using the changeset viewer.