[go: up one dir, main page]

File: s-ucontext.c

package info (click to toggle)
uftrace 0.9.0-1
  • links: PTS
  • area: main
  • in suites: buster
  • size: 3,896 kB
  • sloc: ansic: 41,425; python: 7,369; makefile: 698; asm: 488; cpp: 461; sh: 349
file content (42 lines) | stat: -rw-r--r-- 575 bytes parent folder | download
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 <ucontext.h>
#include <unistd.h>
#include <stdlib.h>

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

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

int baz(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);
}