Changeset a35a3d8 in mainline for uspace/lib/c/include/setjmp.h


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/include/setjmp.h

    rf3d47c97 ra35a3d8  
    11/*
    2  * Copyright (c) 2008 Josef Cejka
    3  * Copyright (c) 2013 Vojtech Horky
     2 * Copyright (c) 2018 CZ.NIC, z.s.p.o.
    43 * All rights reserved.
    54 *
     
    3130 * @{
    3231 */
    33 /** @file Long jump implementation.
    34  *
    35  * Implementation inspired by Jiri Zarevucky's code from
    36  * http://bazaar.launchpad.net/~zarevucky-jiri/helenos/stdc/revision/1544/uspace/lib/posix/setjmp.h
    37  */
    3832
    3933#ifndef LIBC_SETJMP_H_
    4034#define LIBC_SETJMP_H_
    4135
    42 #include <libarch/fibril.h>
     36#include <libarch/fibril_context.h>
    4337
    44 struct jmp_buf_interal {
    45         context_t context;
    46         int return_value;
    47 };
    48 typedef struct jmp_buf_interal jmp_buf[1];
     38typedef context_t jmp_buf[1];
    4939
    50 /*
    51  * Specified as extern to minimize number of included headers
    52  * because this file is used as is in libposix too.
    53  */
    54 extern int context_save(context_t *ctx) __attribute__((returns_twice));
     40extern int __setjmp(jmp_buf) __attribute__((returns_twice));
     41extern _Noreturn void __longjmp(jmp_buf, int);
    5542
    56 /**
    57  * Save current environment (registers).
    58  *
    59  * This function may return twice.
    60  *
    61  * @param env Variable where to save the environment (of type jmp_buf).
    62  * @return Whether the call returned after longjmp.
    63  * @retval 0 Environment was saved, normal execution.
    64  * @retval other longjmp was executed and returned here.
    65  */
    66 #define setjmp(env) \
    67         ((env)[0].return_value = 0, \
    68         context_save(&(env)[0].context), \
    69         (env)[0].return_value)
    70 
    71 extern void longjmp(jmp_buf env, int val) __attribute__((noreturn));
     43#define setjmp __setjmp
     44extern _Noreturn void longjmp(jmp_buf, int);
    7245
    7346#endif
Note: See TracChangeset for help on using the changeset viewer.