Index: uspace/lib/c/include/setjmp.h
===================================================================
--- uspace/lib/c/include/setjmp.h	(revision 860a7bb68c0de53fb36b554589d46522e847b95e)
+++ uspace/lib/c/include/setjmp.h	(revision 91e22dcf5c44d908b24ae2bcd292787f0a7b8d96)
@@ -31,5 +31,8 @@
  * @{
  */
-/** @file
+/** @file Long jump implementation.
+ *
+ * Implementation inspired by Jiri Zarevucky's code from
+ * http://bazaar.launchpad.net/~zarevucky-jiri/helenos/stdc/revision/1544/uspace/lib/posix/setjmp.h
  */
 
@@ -37,12 +40,33 @@
 #define LIBC_SETJMP_H_
 
+#include <libarch/fibril.h>
+
+struct jmp_buf_interal {
+	context_t context;
+	int return_value;
+};
+typedef struct jmp_buf_interal jmp_buf[1];
+
 /*
- * We hide the structure to allow smooth inclusion from libposix
- * as no other types are necessary (and thus no includes are needed).
+ * Specified as extern to minimize number of included headers
+ * because this file is used as is in libposix too.
  */
-struct jmp_buf_interal;
-typedef struct jmp_buf_interal *jmp_buf;
+extern int context_save(context_t *ctx) __attribute__((returns_twice));
 
-extern int setjmp(jmp_buf env);
+/**
+ * Save current environment (registers).
+ *
+ * This function may return twice.
+ *
+ * @param env Variable where to save the environment (of type jmp_buf).
+ * @return Whether the call returned after longjmp.
+ * @retval 0 Environment was saved, normal execution.
+ * @retval other longjmp was executed and returned here.
+ */
+#define setjmp(env) \
+	((env)[0].return_value = 0, \
+	context_save(&(env)[0].context), \
+	(env)[0].return_value)
+
 extern void longjmp(jmp_buf env, int val) __attribute__((noreturn));
 
