Changeset 91e22dc in mainline for uspace/lib/c/generic/setjmp.c


Ignore:
Timestamp:
2013-11-15T08:39:36Z (11 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
6a5b999
Parents:
8797bae
Message:

setjmp() shall be a macro according to C standard

As a matter of fact, when it is a function, the context that was
saved may no longer exist. Excerpt from IRC follows:

vhotspur: jermar, hi: what makes you think setjmp needs to be macro
vhotspur: hmmmm, C99 states that setjmp is macro and longjmp is function,

POSIX states that setjmp can be either macro or function

jermar: from what we have learned about context_save over the years
jermar: you basically capture the stack pointer in context_save()
jermar: if it is a function, you immediately deallocate part of that stack
jermar: so later to return to something which has once been a stack,

but is not anymore

jermar: for instance, you could expect to find the return address from

the call to setjmp() on it, but that could have been overwritten
by some further use of the stack

Also fixed bad definition of buffer type.

File:
1 edited

Legend:

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

    r8797bae r91e22dc  
    4040#include <fibril.h>
    4141
    42 struct jmp_buf_interal {
    43         context_t context;
    44         int return_value;
    45 };
    46 
    47 /**
    48  * Save current environment (registers).
    49  *
    50  * This function may return twice.
    51  *
    52  * @param env Variable where to save the environment.
    53  * @return Whether the call returned after longjmp.
    54  * @retval 0 Environment was saved, normal execution.
    55  * @retval other longjmp was executed and returned here.
    56  */
    57 int setjmp(jmp_buf env) {
    58         env->return_value = 0;
    59         context_save(&env[0].context);
    60         return env->return_value;
    61 }
    62 
    6342/**
    6443 * Restore environment previously stored by setjmp.
Note: See TracChangeset for help on using the changeset viewer.