Changeset a35a3d8 in mainline for uspace/lib/c/generic/setjmp.c


Ignore:
Timestamp:
2018-03-12T17:13:46Z (7 years ago)
Author:
GitHub <noreply@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
b127e4af
Parents:
f3d47c97
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2018-03-12 17:13:46)
git-committer:
GitHub <noreply@…> (2018-03-12 17:13:46)
Message:

Turn context_save/context_restore into standard setjmp/longjmp. (#24)

Turn context_save()/context_restore() into semi-standard __setjmp()/__longjmp().

The original context_* functions are similar to setjmp()/longjmp(), except that the return value is more restricted for the former, and with inverted meaning. This commit adopts the standard return value semantics and acknowledges that these functions are "standard setjmp()/longjmp() with additional implementation-specific properties" by changing the name. The only divergence from the standard is that __longjmp() causes __setjmp() to return its value unchanged, even if it is zero. This is just to avoid extra assembly, and longjmp() checks this in C.

Note that the original use of context_save()/context_restore() to implement context switching in fibril implementation has already been delegated to context_create()/context_swap(), which provide more natural control flow.

File:
1 edited

Legend:

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

    rf3d47c97 ra35a3d8  
    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.