Changeset de9460e in mainline


Ignore:
Timestamp:
2009-11-21T10:38:16Z (14 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
01607604
Parents:
4e739652 (diff), fd1210a (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 fix for #138 (Sync call answer may refer to a non-existent answerbox.)

Location:
kernel/generic
Files:
5 edited

Legend:

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

    r4e739652 rde9460e  
    5151/** This is answer to a call */
    5252#define IPC_CALL_ANSWERED       (1 << 0)
    53 /** This call will not be freed on error */
    54 #define IPC_CALL_STATIC_ALLOC   (1 << 1)
    5553/** Answer will not be passed to userspace, will be discarded */
    56 #define IPC_CALL_DISCARD_ANSWER (1 << 2)
     54#define IPC_CALL_DISCARD_ANSWER (1 << 1)
    5755/** Call was forwarded */
    58 #define IPC_CALL_FORWARDED      (1 << 3)
     56#define IPC_CALL_FORWARDED      (1 << 2)
    5957/** Identify connect_me_to answer */
    60 #define IPC_CALL_CONN_ME_TO     (1 << 4)
     58#define IPC_CALL_CONN_ME_TO     (1 << 3)
    6159/** Interrupt notification */
    62 #define IPC_CALL_NOTIF          (1 << 5)
     60#define IPC_CALL_NOTIF          (1 << 4)
    6361
    6462/*
     
    267265        waitq_t wq;
    268266
     267        /** Linkage for the list of task's synchronous answerboxes. */
     268        link_t sync_box_link;
     269
    269270        /** Phones connected to this answerbox. */
    270271        link_t connected_phones;
     
    316317} call_t;
    317318
     319
     320extern answerbox_t *ipc_phone_0;
     321
     322
    318323extern void ipc_init(void);
    319 extern call_t * ipc_wait_for_call(answerbox_t *, uint32_t, int);
    320 extern void ipc_answer(answerbox_t *, call_t *);
     324
     325extern call_t * ipc_call_alloc(int);
     326extern void ipc_call_free(call_t *);
     327
    321328extern int ipc_call(phone_t *, call_t *);
    322329extern int ipc_call_sync(phone_t *, call_t *);
     330extern call_t * ipc_wait_for_call(answerbox_t *, uint32_t, int);
     331extern int ipc_forward(call_t *, phone_t *, answerbox_t *, int);
     332extern void ipc_answer(answerbox_t *, call_t *);
     333
    323334extern void ipc_phone_init(phone_t *);
    324335extern void ipc_phone_connect(phone_t *, answerbox_t *);
    325 extern void ipc_call_free(call_t *);
    326 extern call_t * ipc_call_alloc(int);
     336extern int ipc_phone_hangup(phone_t *);
     337
    327338extern void ipc_answerbox_init(answerbox_t *, struct task *);
    328 extern void ipc_call_static_init(call_t *);
    329 extern void task_print_list(void);
    330 extern int ipc_forward(call_t *, phone_t *, answerbox_t *, int);
     339
    331340extern void ipc_cleanup(void);
    332 extern int ipc_phone_hangup(phone_t *);
    333341extern void ipc_backsend_err(phone_t *, call_t *, unative_t);
    334 extern void ipc_print_task(task_id_t);
    335342extern void ipc_answerbox_slam_phones(answerbox_t *, bool);
    336343extern void ipc_cleanup_call_list(link_t *);
    337344
    338 extern answerbox_t *ipc_phone_0;
     345extern void ipc_print_task(task_id_t);
    339346
    340347#endif
  • kernel/generic/include/proc/task.h

    r4e739652 rde9460e  
    9898         */
    9999        atomic_t active_calls;
     100        /** List of synchronous answerboxes. */
     101        link_t sync_box_head;
    100102
    101103#ifdef CONFIG_UDEBUG
     
    132134extern int task_kill(task_id_t id);
    133135extern uint64_t task_get_accounting(task_t *t);
     136extern void task_print_list(void);
    134137
    135138extern void cap_set(task_t *t, cap_t caps);
  • kernel/generic/src/ipc/ipc.c

    r4e739652 rde9460e  
    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... */
     
    574605                ASSERT((call->flags & IPC_CALL_ANSWERED) ||
    575606                    (call->flags & IPC_CALL_NOTIF));
    576                 ASSERT(!(call->flags & IPC_CALL_STATIC_ALLOC));
    577607               
    578608                /*
     
    593623        ipc_call_slab = slab_cache_create("ipc_call", sizeof(call_t), 0, NULL,
    594624            NULL, 0);
     625        ipc_answerbox_slab = slab_cache_create("ipc_answerbox",
     626            sizeof(answerbox_t), 0, NULL, NULL, 0);
    595627}
    596628
  • kernel/generic/src/ipc/sysipc.c

    r4e739652 rde9460e  
    531531    unative_t arg1, unative_t arg2, unative_t arg3, ipc_data_t *data)
    532532{
    533         call_t call;
     533        call_t *call;
    534534        phone_t *phone;
    535535        int res;
     
    538538        GET_CHECK_PHONE(phone, phoneid, return ENOENT);
    539539
    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);
     540        call = ipc_call_alloc(0);
     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);
    545545        /*
    546546         * To achieve deterministic behavior, zero out arguments that are beyond
    547547         * the limits of the fast version.
    548548         */
    549         IPC_SET_ARG4(call.data, 0);
    550         IPC_SET_ARG5(call.data, 0);
    551 
    552         if (!(res = request_preprocess(&call, phone))) {
     549        IPC_SET_ARG4(call->data, 0);
     550        IPC_SET_ARG5(call->data, 0);
     551
     552        if (!(res = request_preprocess(call, phone))) {
    553553#ifdef CONFIG_UDEBUG
    554554                udebug_stoppable_begin();
    555555#endif
    556                 rc = ipc_call_sync(phone, &call);
     556                rc = ipc_call_sync(phone, call);
    557557#ifdef CONFIG_UDEBUG
    558558                udebug_stoppable_end();
    559559#endif
    560                 if (rc != EOK)
     560                if (rc != EOK) {
     561                        /* The call will be freed by ipc_cleanup(). */
    561562                        return rc;
    562                 process_answer(&call);
     563                }
     564                process_answer(call);
    563565
    564566        } else {
    565                 IPC_SET_RETVAL(call.data, res);
    566         }
    567         rc = STRUCT_TO_USPACE(&data->args, &call.data.args);
     567                IPC_SET_RETVAL(call->data, res);
     568        }
     569        rc = STRUCT_TO_USPACE(&data->args, &call->data.args);
     570        ipc_call_free(call);
    568571        if (rc != 0)
    569572                return rc;
     
    584587    ipc_data_t *reply)
    585588{
    586         call_t call;
     589        call_t *call;
    587590        phone_t *phone;
    588591        int res;
    589592        int rc;
    590593
    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)
     594        GET_CHECK_PHONE(phone, phoneid, return ENOENT);
     595
     596        call = ipc_call_alloc(0);
     597        rc = copy_from_uspace(&call->data.args, &question->args,
     598            sizeof(call->data.args));
     599        if (rc != 0) {
     600                ipc_call_free(call);
    595601                return (unative_t) rc;
    596 
    597         GET_CHECK_PHONE(phone, phoneid, return ENOENT);
    598 
    599         if (!(res = request_preprocess(&call, phone))) {
     602        }
     603
     604
     605        if (!(res = request_preprocess(call, phone))) {
    600606#ifdef CONFIG_UDEBUG
    601607                udebug_stoppable_begin();
    602608#endif
    603                 rc = ipc_call_sync(phone, &call);
     609                rc = ipc_call_sync(phone, call);
    604610#ifdef CONFIG_UDEBUG
    605611                udebug_stoppable_end();
    606612#endif
    607                 if (rc != EOK)
     613                if (rc != EOK) {
     614                        /* The call will be freed by ipc_cleanup(). */
    608615                        return rc;
    609                 process_answer(&call);
     616                }
     617                process_answer(call);
    610618        } else
    611                 IPC_SET_RETVAL(call.data, res);
    612 
    613         rc = STRUCT_TO_USPACE(&reply->args, &call.data.args);
     619                IPC_SET_RETVAL(call->data, res);
     620
     621        rc = STRUCT_TO_USPACE(&reply->args, &call->data.args);
     622        ipc_call_free(call);
    614623        if (rc != 0)
    615624                return rc;
     
    9911000
    9921001        if (call->flags & IPC_CALL_NOTIF) {
    993                 ASSERT(! (call->flags & IPC_CALL_STATIC_ALLOC));
    994 
    9951002                /* Set in_phone_hash to the interrupt counter */
    9961003                call->data.phone = (void *) call->priv;
     
    10051012        if (call->flags & IPC_CALL_ANSWERED) {
    10061013                process_answer(call);
    1007 
    1008                 ASSERT(! (call->flags & IPC_CALL_STATIC_ALLOC));
    10091014
    10101015                if (call->flags & IPC_CALL_DISCARD_ANSWER) {
  • kernel/generic/src/proc/task.c

    r4e739652 rde9460e  
    178178                ipc_phone_connect(&ta->phones[0], ipc_phone_0);
    179179        atomic_set(&ta->active_calls, 0);
     180        list_initialize(&ta->sync_box_head);
    180181
    181182        mutex_initialize(&ta->futexes_lock, MUTEX_PASSIVE);
Note: See TracChangeset for help on using the changeset viewer.