Changeset db4d6de in mainline for kernel/generic/src


Ignore:
Timestamp:
2009-11-28T16:30:43Z (16 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
c4702804
Parents:
ba8f8cb (diff), 67392fa (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes.

Location:
kernel/generic/src
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/console/cmd.c

    rba8f8cb rdb4d6de  
    409409};
    410410
     411/* Data and methods for 'kill' command */
     412static int cmd_kill(cmd_arg_t *argv);
     413static cmd_arg_t kill_argv = {
     414        .type = ARG_TYPE_INT,
     415};
     416static cmd_info_t kill_info = {
     417        .name = "kill",
     418        .description = "kill <taskid> Kill a task.",
     419        .func = cmd_kill,
     420        .argc = 1,
     421        .argv = &kill_argv
     422};
     423
    411424/* Data and methods for 'zone' command */
    412425static int cmd_zone(cmd_arg_t *argv);
     
    459472        &help_info,
    460473        &ipc_info,
     474        &kill_info,
    461475        &set4_info,
    462476        &slabs_info,
     
    848862 * @return Always 1
    849863 */
    850 int cmd_slabs(cmd_arg_t * argv) {
     864int cmd_slabs(cmd_arg_t * argv)
     865{
    851866        slab_print_list();
    852867        return 1;
     
    860875 * @return Always 1
    861876 */
    862 int cmd_threads(cmd_arg_t * argv) {
     877int cmd_threads(cmd_arg_t * argv)
     878{
    863879        thread_print_list();
    864880        return 1;
     
    871887 * @return Always 1
    872888 */
    873 int cmd_tasks(cmd_arg_t * argv) {
     889int cmd_tasks(cmd_arg_t * argv)
     890{
    874891        task_print_list();
    875892        return 1;
     
    882899 * @return Always 1
    883900 */
    884 int cmd_sched(cmd_arg_t * argv) {
     901int cmd_sched(cmd_arg_t * argv)
     902{
    885903        sched_print_list();
    886904        return 1;
     
    893911 * return Always 1
    894912 */
    895 int cmd_zones(cmd_arg_t * argv) {
     913int cmd_zones(cmd_arg_t * argv)
     914{
    896915        zone_print_list();
    897916        return 1;
     
    904923 * return Always 1
    905924 */
    906 int cmd_zone(cmd_arg_t * argv) {
     925int cmd_zone(cmd_arg_t * argv)
     926{
    907927        zone_print_one(argv[0].intval);
    908928        return 1;
     
    915935 * return Always 1
    916936 */
    917 int cmd_ipc(cmd_arg_t * argv) {
     937int cmd_ipc(cmd_arg_t * argv)
     938{
    918939        ipc_print_task(argv[0].intval);
    919940        return 1;
    920941}
    921942
     943/** Command for killing a task
     944 *
     945 * @param argv Integer argument from cmdline expected
     946 *
     947 * return 0 on failure, 1 on success.
     948 */
     949int cmd_kill(cmd_arg_t * argv)
     950{
     951        if (task_kill(argv[0].intval) != EOK)
     952                return 0;
     953
     954        return 1;
     955}
    922956
    923957/** Command for listing processors.
  • kernel/generic/src/console/console.c

    rba8f8cb rdb4d6de  
    319319       
    320320        if (size > PAGE_SIZE)
    321                 return ELIMIT;
     321                return (unative_t) ELIMIT;
    322322       
    323323        if (size > 0) {
    324324                data = (char *) malloc(size + 1, 0);
    325325                if (!data)
    326                         return ENOMEM;
     326                        return (unative_t) ENOMEM;
    327327               
    328328                rc = copy_from_uspace(data, buf, size);
    329329                if (rc) {
    330330                        free(data);
    331                         return rc;
     331                        return (unative_t) rc;
    332332                }
    333333                data[size] = 0;
  • kernel/generic/src/ipc/ipc.c

    rba8f8cb rdb4d6de  
    6262
    6363static slab_cache_t *ipc_call_slab;
     64static slab_cache_t *ipc_answerbox_slab;
    6465
    6566/** Initialize a call structure.
     
    9697}
    9798
    98 /** Initialize a statically allocated call structure.
    99  *
    100  * @param call          Statically allocated kernel call structure to be
    101  *                      initialized.
    102  */
    103 void ipc_call_static_init(call_t *call)
    104 {
    105         _ipc_call_init(call);
    106         call->flags |= IPC_CALL_STATIC_ALLOC;
    107 }
    108 
    10999/** Deallocate a call structure.
    110100 *
     
    113103void ipc_call_free(call_t *call)
    114104{
    115         ASSERT(!(call->flags & IPC_CALL_STATIC_ALLOC));
    116105        /* Check to see if we have data in the IPC_M_DATA_SEND buffer. */
    117106        if (call->buffer)
     
    130119        spinlock_initialize(&box->irq_lock, "ipc_box_irqlock");
    131120        waitq_initialize(&box->wq);
     121        link_initialize(&box->sync_box_link);
    132122        list_initialize(&box->connected_phones);
    133123        list_initialize(&box->calls);
     
    179169int ipc_call_sync(phone_t *phone, call_t *request)
    180170{
    181         answerbox_t sync_box;
    182 
    183         ipc_answerbox_init(&sync_box, TASK);
     171        answerbox_t *sync_box;
     172        ipl_t ipl;
     173
     174        sync_box = slab_alloc(ipc_answerbox_slab, 0);
     175        ipc_answerbox_init(sync_box, TASK);
     176
     177        /*
     178         * Put the answerbox on the TASK's list of synchronous answerboxes so
     179         * that it can be cleaned up if the call is interrupted.
     180         */
     181        ipl = interrupts_disable();
     182        spinlock_lock(&TASK->lock);
     183        list_append(&sync_box->sync_box_link, &TASK->sync_box_head);
     184        spinlock_unlock(&TASK->lock);
     185        interrupts_restore(ipl);
    184186
    185187        /* We will receive data in a special box. */
    186         request->callerbox = &sync_box;
     188        request->callerbox = sync_box;
    187189
    188190        ipc_call(phone, request);
    189         if (!ipc_wait_for_call(&sync_box, SYNCH_NO_TIMEOUT,
    190             SYNCH_FLAGS_INTERRUPTIBLE))
     191        if (!ipc_wait_for_call(sync_box, SYNCH_NO_TIMEOUT,
     192            SYNCH_FLAGS_INTERRUPTIBLE)) {
     193                /* The answerbox and the call will be freed by ipc_cleanup(). */
    191194                return EINTR;
     195        }
     196
     197        /*
     198         * The answer arrived without interruption so we can remove the
     199         * answerbox from the TASK's list of synchronous answerboxes.
     200         */
     201        (void) interrupts_disable();
     202        spinlock_lock(&TASK->lock);
     203        list_remove(&sync_box->sync_box_link);
     204        spinlock_unlock(&TASK->lock);
     205        interrupts_restore(ipl);
     206
     207        slab_free(ipc_answerbox_slab, sync_box);
    192208        return EOK;
    193209}
     
    520536        int i;
    521537        call_t *call;
     538        ipl_t ipl;
    522539
    523540        /* Disconnect all our phones ('ipc_phone_hangup') */
     
    545562        spinlock_unlock(&TASK->answerbox.lock);
    546563       
    547         /* Wait for all async answers to arrive */
     564        /* Wait for all answers to interrupted synchronous calls to arrive */
     565        ipl = interrupts_disable();
     566        while (!list_empty(&TASK->sync_box_head)) {
     567                answerbox_t *box = list_get_instance(TASK->sync_box_head.next,
     568                    answerbox_t, sync_box_link);
     569
     570                list_remove(&box->sync_box_link);
     571                call = ipc_wait_for_call(box, SYNCH_NO_TIMEOUT,
     572                    SYNCH_FLAGS_NONE);
     573                ipc_call_free(call);
     574                slab_free(ipc_answerbox_slab, box);
     575        }
     576        interrupts_restore(ipl);
     577
     578        /* Wait for all answers to asynchronous calls to arrive */
    548579        while (1) {
    549580                /* Go through all phones, until all are FREE... */
     
    552583                for (i = 0; i < IPC_MAX_PHONES; i++) {
    553584                        if (TASK->phones[i].state == IPC_PHONE_HUNGUP &&
    554                             atomic_get(&TASK->phones[i].active_calls) == 0)
     585                            atomic_get(&TASK->phones[i].active_calls) == 0) {
    555586                                TASK->phones[i].state = IPC_PHONE_FREE;
     587                                TASK->phones[i].callee = NULL;
     588                        }
    556589                       
    557590                        /* Just for sure, we might have had some
     
    574607                ASSERT((call->flags & IPC_CALL_ANSWERED) ||
    575608                    (call->flags & IPC_CALL_NOTIF));
    576                 ASSERT(!(call->flags & IPC_CALL_STATIC_ALLOC));
    577609               
    578610                /*
     
    593625        ipc_call_slab = slab_cache_create("ipc_call", sizeof(call_t), 0, NULL,
    594626            NULL, 0);
     627        ipc_answerbox_slab = slab_cache_create("ipc_answerbox",
     628            sizeof(answerbox_t), 0, NULL, NULL, 0);
    595629}
    596630
  • kernel/generic/src/ipc/irq.c

    rba8f8cb rdb4d6de  
    418418                case CMD_ACCEPT:
    419419                        return IRQ_ACCEPT;
    420                         break;
    421420                case CMD_DECLINE:
    422421                default:
  • kernel/generic/src/ipc/kbox.c

    rba8f8cb rdb4d6de  
    137137                /* Only detach kbox thread unless already terminating. */
    138138                mutex_lock(&TASK->kb.cleanup_lock);
    139                 if (&TASK->kb.finished == false) {
     139                if (TASK->kb.finished == false) {
    140140                        /* Detach kbox thread so it gets freed from memory. */
    141141                        thread_detach(TASK->kb.thread);
  • kernel/generic/src/ipc/sysipc.c

    rba8f8cb rdb4d6de  
    6161{ \
    6262        if (phoneid > IPC_MAX_PHONES) { \
    63                 err; \
     63                err \
    6464        } \
    6565        phone = &TASK->phones[phoneid]; \
     
    122122        case IPC_M_DATA_READ:
    123123                return 1;
    124                 break;
    125124        default:
    126125                return 0;
     
    376375                phone_t *cloned_phone;
    377376                GET_CHECK_PHONE(cloned_phone, IPC_GET_ARG1(call->data),
    378                     return ENOENT);
     377                    return ENOENT;);
    379378                phones_lock(cloned_phone, phone);
    380379                if ((cloned_phone->state != IPC_PHONE_CONNECTED) ||
     
    531530    unative_t arg1, unative_t arg2, unative_t arg3, ipc_data_t *data)
    532531{
    533         call_t call;
     532        call_t *call;
    534533        phone_t *phone;
    535534        int res;
    536535        int rc;
    537536       
    538         GET_CHECK_PHONE(phone, phoneid, return ENOENT);
    539 
    540         ipc_call_static_init(&call);
    541         IPC_SET_METHOD(call.data, method);
    542         IPC_SET_ARG1(call.data, arg1);
    543         IPC_SET_ARG2(call.data, arg2);
    544         IPC_SET_ARG3(call.data, arg3);
     537        GET_CHECK_PHONE(phone, phoneid, return ENOENT;);
     538
     539        call = ipc_call_alloc(0);
     540        IPC_SET_METHOD(call->data, method);
     541        IPC_SET_ARG1(call->data, arg1);
     542        IPC_SET_ARG2(call->data, arg2);
     543        IPC_SET_ARG3(call->data, arg3);
    545544        /*
    546545         * To achieve deterministic behavior, zero out arguments that are beyond
    547546         * the limits of the fast version.
    548547         */
    549         IPC_SET_ARG4(call.data, 0);
    550         IPC_SET_ARG5(call.data, 0);
    551 
    552         if (!(res = request_preprocess(&call, phone))) {
     548        IPC_SET_ARG4(call->data, 0);
     549        IPC_SET_ARG5(call->data, 0);
     550
     551        if (!(res = request_preprocess(call, phone))) {
    553552#ifdef CONFIG_UDEBUG
    554553                udebug_stoppable_begin();
    555554#endif
    556                 rc = ipc_call_sync(phone, &call);
     555                rc = ipc_call_sync(phone, call);
    557556#ifdef CONFIG_UDEBUG
    558557                udebug_stoppable_end();
    559558#endif
    560                 if (rc != EOK)
     559                if (rc != EOK) {
     560                        /* The call will be freed by ipc_cleanup(). */
    561561                        return rc;
    562                 process_answer(&call);
     562                }
     563                process_answer(call);
    563564
    564565        } else {
    565                 IPC_SET_RETVAL(call.data, res);
    566         }
    567         rc = STRUCT_TO_USPACE(&data->args, &call.data.args);
     566                IPC_SET_RETVAL(call->data, res);
     567        }
     568        rc = STRUCT_TO_USPACE(&data->args, &call->data.args);
     569        ipc_call_free(call);
    568570        if (rc != 0)
    569571                return rc;
     
    584586    ipc_data_t *reply)
    585587{
    586         call_t call;
     588        call_t *call;
    587589        phone_t *phone;
    588590        int res;
    589591        int rc;
    590592
    591         ipc_call_static_init(&call);
    592         rc = copy_from_uspace(&call.data.args, &question->args,
    593             sizeof(call.data.args));
    594         if (rc != 0)
     593        GET_CHECK_PHONE(phone, phoneid, return ENOENT;);
     594
     595        call = ipc_call_alloc(0);
     596        rc = copy_from_uspace(&call->data.args, &question->args,
     597            sizeof(call->data.args));
     598        if (rc != 0) {
     599                ipc_call_free(call);
    595600                return (unative_t) rc;
    596 
    597         GET_CHECK_PHONE(phone, phoneid, return ENOENT);
    598 
    599         if (!(res = request_preprocess(&call, phone))) {
     601        }
     602
     603
     604        if (!(res = request_preprocess(call, phone))) {
    600605#ifdef CONFIG_UDEBUG
    601606                udebug_stoppable_begin();
    602607#endif
    603                 rc = ipc_call_sync(phone, &call);
     608                rc = ipc_call_sync(phone, call);
    604609#ifdef CONFIG_UDEBUG
    605610                udebug_stoppable_end();
    606611#endif
    607                 if (rc != EOK)
     612                if (rc != EOK) {
     613                        /* The call will be freed by ipc_cleanup(). */
    608614                        return rc;
    609                 process_answer(&call);
     615                }
     616                process_answer(call);
    610617        } else
    611                 IPC_SET_RETVAL(call.data, res);
    612 
    613         rc = STRUCT_TO_USPACE(&reply->args, &call.data.args);
     618                IPC_SET_RETVAL(call->data, res);
     619
     620        rc = STRUCT_TO_USPACE(&reply->args, &call->data.args);
     621        ipc_call_free(call);
    614622        if (rc != 0)
    615623                return rc;
     
    658666                return IPC_CALLRET_TEMPORARY;
    659667
    660         GET_CHECK_PHONE(phone, phoneid, return IPC_CALLRET_FATAL);
     668        GET_CHECK_PHONE(phone, phoneid, return IPC_CALLRET_FATAL;);
    661669
    662670        call = ipc_call_alloc(0);
     
    697705                return IPC_CALLRET_TEMPORARY;
    698706
    699         GET_CHECK_PHONE(phone, phoneid, return IPC_CALLRET_FATAL);
     707        GET_CHECK_PHONE(phone, phoneid, return IPC_CALLRET_FATAL;);
    700708
    701709        call = ipc_call_alloc(0);
     
    747755        call->flags |= IPC_CALL_FORWARDED;
    748756
    749         GET_CHECK_PHONE(phone, phoneid, { 
     757        GET_CHECK_PHONE(phone, phoneid, {
    750758                IPC_SET_RETVAL(call->data, EFORWARD);
    751759                ipc_answer(&TASK->answerbox, call);
     
    952960        phone_t *phone;
    953961
    954         GET_CHECK_PHONE(phone, phoneid, return ENOENT);
     962        GET_CHECK_PHONE(phone, phoneid, return ENOENT;);
    955963
    956964        if (ipc_phone_hangup(phone))
     
    991999
    9921000        if (call->flags & IPC_CALL_NOTIF) {
    993                 ASSERT(! (call->flags & IPC_CALL_STATIC_ALLOC));
    994 
    9951001                /* Set in_phone_hash to the interrupt counter */
    9961002                call->data.phone = (void *) call->priv;
     
    10051011        if (call->flags & IPC_CALL_ANSWERED) {
    10061012                process_answer(call);
    1007 
    1008                 ASSERT(! (call->flags & IPC_CALL_STATIC_ALLOC));
    10091013
    10101014                if (call->flags & IPC_CALL_DISCARD_ANSWER) {
  • kernel/generic/src/lib/elf.c

    rba8f8cb rdb4d6de  
    163163        case PT_LOAD:
    164164                return load_segment(entry, elf, as);
    165                 break;
    166165        case PT_DYNAMIC:
    167166        case PT_INTERP:
     
    182181        default:
    183182                return EE_UNSUPPORTED;
    184                 break;
    185183        }
    186184        return EE_OK;
  • kernel/generic/src/proc/task.c

    rba8f8cb rdb4d6de  
    7575static task_id_t task_counter = 0;
    7676
     77static slab_cache_t *task_slab;
     78
    7779/* Forward declarations. */
    7880static void task_kill_internal(task_t *);
     81static int tsk_constructor(void *, int);
    7982
    8083/** Initialize kernel tasks support. */
     
    8386        TASK = NULL;
    8487        avltree_create(&tasks_tree);
     88        task_slab = slab_cache_create("task_slab", sizeof(task_t), 0,
     89            tsk_constructor, NULL, 0);
    8590}
    8691
     
    128133}
    129134
     135int tsk_constructor(void *obj, int kmflags)
     136{
     137        task_t *ta = obj;
     138        int i;
     139
     140        atomic_set(&ta->refcount, 0);
     141        atomic_set(&ta->lifecount, 0);
     142        atomic_set(&ta->active_calls, 0);
     143
     144        spinlock_initialize(&ta->lock, "task_ta_lock");
     145        mutex_initialize(&ta->futexes_lock, MUTEX_PASSIVE);
     146
     147        list_initialize(&ta->th_head);
     148        list_initialize(&ta->sync_box_head);
     149
     150        ipc_answerbox_init(&ta->answerbox, ta);
     151        for (i = 0; i < IPC_MAX_PHONES; i++)
     152                ipc_phone_init(&ta->phones[i]);
     153
     154#ifdef CONFIG_UDEBUG
     155        /* Init kbox stuff */
     156        ta->kb.thread = NULL;
     157        ipc_answerbox_init(&ta->kb.box, ta);
     158        mutex_initialize(&ta->kb.cleanup_lock, MUTEX_PASSIVE);
     159#endif
     160
     161        return 0;
     162}
     163
    130164/** Create new task with no threads.
    131165 *
     
    140174        ipl_t ipl;
    141175        task_t *ta;
    142         int i;
    143        
    144         ta = (task_t *) malloc(sizeof(task_t), 0);
    145 
     176       
     177        ta = (task_t *) slab_alloc(task_slab, 0);
    146178        task_create_arch(ta);
    147 
    148         spinlock_initialize(&ta->lock, "task_ta_lock");
    149         list_initialize(&ta->th_head);
    150179        ta->as = as;
    151 
    152180        memcpy(ta->name, name, TASK_NAME_BUFLEN);
    153181        ta->name[TASK_NAME_BUFLEN - 1] = 0;
    154182
    155         atomic_set(&ta->refcount, 0);
    156         atomic_set(&ta->lifecount, 0);
    157183        ta->context = CONTEXT;
    158 
    159184        ta->capabilities = 0;
    160185        ta->cycles = 0;
     
    165190
    166191        /* Init kbox stuff */
    167         ipc_answerbox_init(&ta->kb.box, ta);
    168         ta->kb.thread = NULL;
    169         mutex_initialize(&ta->kb.cleanup_lock, MUTEX_PASSIVE);
    170192        ta->kb.finished = false;
    171193#endif
    172194
    173         ipc_answerbox_init(&ta->answerbox, ta);
    174         for (i = 0; i < IPC_MAX_PHONES; i++)
    175                 ipc_phone_init(&ta->phones[i]);
    176         if ((ipc_phone_0) && (context_check(ipc_phone_0->task->context,
    177             ta->context)))
     195        if ((ipc_phone_0) &&
     196            (context_check(ipc_phone_0->task->context, ta->context)))
    178197                ipc_phone_connect(&ta->phones[0], ipc_phone_0);
    179         atomic_set(&ta->active_calls, 0);
    180 
    181         mutex_initialize(&ta->futexes_lock, MUTEX_PASSIVE);
     198
    182199        btree_create(&ta->futexes);
    183200       
    184201        ipl = interrupts_disable();
    185 
    186         /*
    187          * Increment address space reference count.
    188          */
    189202        atomic_inc(&as->refcount);
    190 
    191203        spinlock_lock(&tasks_lock);
    192204        ta->taskid = ++task_counter;
     
    229241                as_destroy(t->as);
    230242       
    231         free(t);
     243        slab_free(task_slab, t);
    232244        TASK = NULL;
    233245}
Note: See TracChangeset for help on using the changeset viewer.