Skip to content

Instantly share code, notes, and snippets.

@avagin
Last active August 29, 2015 14:14
Show Gist options
  • Save avagin/4c494d528923f16511f1 to your computer and use it in GitHub Desktop.
Save avagin/4c494d528923f16511f1 to your computer and use it in GitHub Desktop.
*** longjmp causes uninitialized stack frame ***: nsenter-exec terminated
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <setjmp.h>
#include <sched.h>
#include <signal.h>
struct cr_clone_arg {
char stack[4096] __attribute__((aligned (8)));
char stack_ptr[0];
jmp_buf env;
};
static int child_func(void *_arg)
{
struct cr_clone_arg *arg = (struct cr_clone_arg *) _arg;
longjmp(arg->env, 1);
}
int main()
{
int child;
struct cr_clone_arg ca;
if (setjmp(ca.env) == 1) {
printf("Ok\n");
return 0;
}
child = clone(child_func, ca.stack_ptr, CLONE_PARENT | SIGCHLD, &ca);
if (child < 0) {
fprintf(stderr, "Unable to fork: %m");
exit(1);
}
printf("Done\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment