Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/proc/task.c

    r5bcf1f9 rbe06914  
    151151        atomic_set(&task->refcount, 0);
    152152        atomic_set(&task->lifecount, 0);
     153        atomic_set(&task->active_calls, 0);
    153154       
    154155        irq_spinlock_initialize(&task->lock, "task_t_lock");
     
    290291}
    291292
    292 #ifdef __32_BITS__
    293 
    294 /** Syscall for reading task ID from userspace (32 bits)
    295  *
    296  * @param uspace_taskid Pointer to user-space buffer
    297  *                      where to store current task ID.
     293/** Syscall for reading task ID from userspace.
     294 *
     295 * @param uspace_task_id Userspace address of 8-byte buffer
     296 *                       where to store current task ID.
    298297 *
    299298 * @return Zero on success or an error code from @ref errno.h.
    300299 *
    301300 */
    302 sysarg_t sys_task_get_id(sysarg64_t *uspace_taskid)
     301unative_t sys_task_get_id(task_id_t *uspace_task_id)
    303302{
    304303        /*
     
    306305         * the lifespan of the task.
    307306         */
    308         return (sysarg_t) copy_to_uspace(uspace_taskid, &TASK->taskid,
     307        return (unative_t) copy_to_uspace(uspace_task_id, &TASK->taskid,
    309308            sizeof(TASK->taskid));
    310309}
    311 
    312 #endif  /* __32_BITS__ */
    313 
    314 #ifdef __64_BITS__
    315 
    316 /** Syscall for reading task ID from userspace (64 bits)
    317  *
    318  * @return Current task ID.
    319  *
    320  */
    321 sysarg_t sys_task_get_id(void)
    322 {
    323         /*
    324          * No need to acquire lock on TASK because taskid remains constant for
    325          * the lifespan of the task.
    326          */
    327         return TASK->taskid;
    328 }
    329 
    330 #endif  /* __64_BITS__ */
    331310
    332311/** Syscall for setting the task name.
     
    340319 *
    341320 */
    342 sysarg_t sys_task_set_name(const char *uspace_name, size_t name_len)
    343 {
     321unative_t sys_task_set_name(const char *uspace_name, size_t name_len)
     322{
     323        int rc;
    344324        char namebuf[TASK_NAME_BUFLEN];
    345325       
    346326        /* Cap length of name and copy it from userspace. */
     327       
    347328        if (name_len > TASK_NAME_BUFLEN - 1)
    348329                name_len = TASK_NAME_BUFLEN - 1;
    349330       
    350         int rc = copy_from_uspace(namebuf, uspace_name, name_len);
     331        rc = copy_from_uspace(namebuf, uspace_name, name_len);
    351332        if (rc != 0)
    352                 return (sysarg_t) rc;
     333                return (unative_t) rc;
    353334       
    354335        namebuf[name_len] = '\0';
    355        
    356         /*
    357          * As the task name is referenced also from the
    358          * threads, lock the threads' lock for the course
    359          * of the update.
    360          */
    361        
    362         irq_spinlock_lock(&tasks_lock, true);
    363         irq_spinlock_lock(&TASK->lock, false);
    364         irq_spinlock_lock(&threads_lock, false);
    365        
    366         /* Set task name */
    367336        str_cpy(TASK->name, TASK_NAME_BUFLEN, namebuf);
    368337       
    369         irq_spinlock_unlock(&threads_lock, false);
    370         irq_spinlock_unlock(&TASK->lock, false);
    371         irq_spinlock_unlock(&tasks_lock, true);
    372        
    373338        return EOK;
    374 }
    375 
    376 /** Syscall to forcefully terminate a task
    377  *
    378  * @param uspace_taskid Pointer to task ID in user space.
    379  *
    380  * @return 0 on success or an error code from @ref errno.h.
    381  *
    382  */
    383 sysarg_t sys_task_kill(task_id_t *uspace_taskid)
    384 {
    385         task_id_t taskid;
    386         int rc = copy_from_uspace(&taskid, uspace_taskid, sizeof(taskid));
    387         if (rc != 0)
    388                 return (sysarg_t) rc;
    389        
    390         return (sysarg_t) task_kill(taskid);
    391339}
    392340
     
    461409static void task_kill_internal(task_t *task)
    462410{
     411        link_t *cur;
     412       
     413        /*
     414         * Interrupt all threads.
     415         */
    463416        irq_spinlock_lock(&task->lock, false);
    464         irq_spinlock_lock(&threads_lock, false);
    465        
    466         /*
    467          * Interrupt all threads.
    468          */
    469        
    470         link_t *cur;
    471417        for (cur = task->th_head.next; cur != &task->th_head; cur = cur->next) {
    472418                thread_t *thread = list_get_instance(cur, thread_t, th_link);
     
    485431        }
    486432       
    487         irq_spinlock_unlock(&threads_lock, false);
    488433        irq_spinlock_unlock(&task->lock, false);
    489434}
     
    515460        irq_spinlock_unlock(&tasks_lock, true);
    516461       
    517         return EOK;
    518 }
    519 
    520 /** Kill the currently running task.
    521  *
    522  * @param notify Send out fault notifications.
    523  *
    524  * @return Zero on success or an error code from errno.h.
    525  *
    526  */
    527 void task_kill_self(bool notify)
    528 {
    529         /*
    530          * User space can subscribe for FAULT events to take action
    531          * whenever a task faults (to take a dump, run a debugger, etc.).
    532          * The notification is always available, but unless udebug is enabled,
    533          * that's all you get.
    534         */
    535         if (notify) {
    536                 if (event_is_subscribed(EVENT_FAULT)) {
    537                         /* Notify the subscriber that a fault occurred. */
    538                         event_notify_3(EVENT_FAULT, LOWER32(TASK->taskid),
    539                             UPPER32(TASK->taskid), (sysarg_t) THREAD);
    540                
    541 #ifdef CONFIG_UDEBUG
    542                         /* Wait for a debugging session. */
    543                         udebug_thread_fault();
    544 #endif
    545                 }
    546         }
    547        
    548         irq_spinlock_lock(&tasks_lock, true);
    549         task_kill_internal(TASK);
    550         irq_spinlock_unlock(&tasks_lock, true);
    551        
    552         thread_exit();
    553 }
    554 
    555 /** Process syscall to terminate the current task.
    556  *
    557  * @param notify Send out fault notifications.
    558  *
    559  */
    560 sysarg_t sys_task_exit(sysarg_t notify)
    561 {
    562         task_kill_self(notify);
    563        
    564         /* Unreachable */
    565462        return EOK;
    566463}
     
    581478#ifdef __32_BITS__
    582479        if (*additional)
    583                 printf("%-8" PRIu64 " %9" PRIua, task->taskid,
    584                     atomic_get(&task->refcount));
     480                printf("%-8" PRIu64 " %9lu %7lu", task->taskid,
     481                    atomic_get(&task->refcount), atomic_get(&task->active_calls));
    585482        else
    586483                printf("%-8" PRIu64 " %-14s %-5" PRIu32 " %10p %10p"
     
    592489#ifdef __64_BITS__
    593490        if (*additional)
    594                 printf("%-8" PRIu64 " %9" PRIu64 "%c %9" PRIu64 "%c "
    595                     "%9" PRIua, task->taskid, ucycles, usuffix, kcycles,
    596                     ksuffix, atomic_get(&task->refcount));
     491                printf("%-8" PRIu64 " %9" PRIu64 "%c %9" PRIu64 "%c %9lu %7lu",
     492                    task->taskid, ucycles, usuffix, kcycles, ksuffix,
     493                    atomic_get(&task->refcount), atomic_get(&task->active_calls));
    597494        else
    598495                printf("%-8" PRIu64 " %-14s %-5" PRIu32 " %18p %18p\n",
     
    604501                for (i = 0; i < IPC_MAX_PHONES; i++) {
    605502                        if (task->phones[i].callee)
    606                                 printf(" %zu:%p", i, task->phones[i].callee);
     503                                printf(" %" PRIs ":%p", i, task->phones[i].callee);
    607504                }
    608505                printf("\n");
Note: See TracChangeset for help on using the changeset viewer.