Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/include/setjmp.h

    ra35a3d8 r91e22dc  
    11/*
    2  * Copyright (c) 2018 CZ.NIC, z.s.p.o.
     2 * Copyright (c) 2008 Josef Cejka
     3 * Copyright (c) 2013 Vojtech Horky
    34 * All rights reserved.
    45 *
     
    3031 * @{
    3132 */
     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 */
    3238
    3339#ifndef LIBC_SETJMP_H_
    3440#define LIBC_SETJMP_H_
    3541
    36 #include <libarch/fibril_context.h>
     42#include <libarch/fibril.h>
    3743
    38 typedef context_t jmp_buf[1];
     44struct jmp_buf_interal {
     45        context_t context;
     46        int return_value;
     47};
     48typedef struct jmp_buf_interal jmp_buf[1];
    3949
    40 extern int __setjmp(jmp_buf) __attribute__((returns_twice));
    41 extern _Noreturn void __longjmp(jmp_buf, int);
     50/*
     51 * Specified as extern to minimize number of included headers
     52 * because this file is used as is in libposix too.
     53 */
     54extern int context_save(context_t *ctx) __attribute__((returns_twice));
    4255
    43 #define setjmp __setjmp
    44 extern _Noreturn void longjmp(jmp_buf, int);
     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
     71extern void longjmp(jmp_buf env, int val) __attribute__((noreturn));
    4572
    4673#endif
Note: See TracChangeset for help on using the changeset viewer.