Ignore:
File:
1 edited

Legend:

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

    ra35a3d8 re0a4686  
    11/*
    22 * Copyright (c) 2013 Vojtech Horky
    3  * Copyright (c) 2018 CZ.NIC, z.s.p.o.
    43 * All rights reserved.
    54 *
     
    3130 * @{
    3231 */
     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 */
    3337
    3438#include <setjmp.h>
    3539#include <context.h>
    3640
    37 /** Standard function implementation. */
    38 void longjmp(jmp_buf env, int val)
    39 {
    40         /* __longjmp defined in assembly doesn't "correct" the value. */
    41         __longjmp(env, val == 0 ? 1 : val);
     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 */
     55void longjmp(jmp_buf env, int val) {
     56        env[0].return_value = (val == 0) ? 1 : val;
     57        context_restore(&env[0].context);
    4258}
    4359
Note: See TracChangeset for help on using the changeset viewer.