File: s-ucontext.c

package info (click to toggle)
uftrace 0.19-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,372 kB
  • sloc: ansic: 49,879; python: 11,279; asm: 837; makefile: 769; sh: 637; cpp: 627; javascript: 191
file content (42 lines) | stat: -rw-r--r-- 584 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <stdlib.h>
#include <ucontext.h>
#include <unistd.h>

int foo(ucontext_t *old, ucontext_t *new)
{
	swapcontext(old, new);
}

int bar(int c)
{
	return c + getpid();
}

int baz(volatile int c)
{
	return c % 2;
}

#define STACKSIZE 8192

int main(int argc, char *argv[])
{
	int n = 10;
	char stack[STACKSIZE];
	ucontext_t curr, new;

	if (argc > 1)
		n = atoi(argv[1]);

	getcontext(&new);
	new.uc_link = &curr;
	new.uc_stack.ss_sp = stack;
	new.uc_stack.ss_size = STACKSIZE;

	makecontext(&new, (void (*)(void))bar, 1, n);

	foo(&curr, &new);
	n = baz(n);

	return !(n < 2);
}