Changeset 615e83d in mainline for uspace/lib/c/generic


Ignore:
Timestamp:
2018-03-08T18:25:31Z (8 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Children:
55f068c
Parents:
e0a4686
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2018-03-08 17:43:06)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2018-03-08 18:25:31)
Message:

Turn context_save/context_restore into standard setjmp/longjmp.

Location:
uspace/lib/c/generic
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/context.c

    re0a4686 r615e83d  
    2828
    2929#include <context.h>
     30#include <setjmp.h>
    3031#include <libarch/tls.h>
    3132#include <libarch/fibril.h>
     
    4243void context_swap(context_t *self, context_t *other)
    4344{
    44         if (context_save(self))
    45                 context_restore(other);
     45        if (!setjmp(self))
     46                __longjmp(other, 1);
    4647}
    4748
    4849void context_create(context_t *context, const context_create_t *arg)
    4950{
    50         context_save(context);
     51        setjmp(context);
    5152        context_set(context, FADDR(arg->fn), arg->stack_base,
    5253            arg->stack_size, arg->tls);
  • uspace/lib/c/generic/setjmp.c

    re0a4686 r615e83d  
    11/*
    22 * Copyright (c) 2013 Vojtech Horky
     3 * Copyright (c) 2018 CZ.NIC, z.s.p.o.
    34 * All rights reserved.
    45 *
     
    3031 * @{
    3132 */
    32 /** @file Long jump implementation.
    33  *
    34  * Implementation inspired by Jiri Zarevucky's code from
    35  * http://bazaar.launchpad.net/~zarevucky-jiri/helenos/stdc/revision/1544/uspace/lib/posix/setjmp.h
    36  */
    3733
    3834#include <setjmp.h>
    3935#include <context.h>
    4036
    41 // TODO: setjmp/longjmp are basically a stronger version of
    42 // context_save/context_restore. It would be preferable to turn
    43 // those two into setjmp/longjmp (all it would need is preserving the
    44 // return value).
    45 
    46 /**
    47  * Restore environment previously stored by setjmp.
    48  *
    49  * This function never returns.
    50  *
    51  * @param env Variable with the environment previously stored by call
    52  * to setjmp.
    53  * @param val Value to fake when returning from setjmp (0 is transformed to 1).
    54  */
    55 void longjmp(jmp_buf env, int val) {
    56         env[0].return_value = (val == 0) ? 1 : val;
    57         context_restore(&env[0].context);
     37/** Standard function implementation. */
     38void longjmp(jmp_buf env, int val)
     39{
     40        /* __longjmp defined in assembly doesn't "correct" the value. */
     41        __longjmp(env, val == 0 ? 1 : val);
    5842}
    5943
Note: See TracChangeset for help on using the changeset viewer.