aboutsummaryrefslogtreecommitdiff
path: root/acid/pthread-linux-386
blob: 90d8768604a32e6ba33ab49c2bede777bfb0b618 (plain)
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
43
44
45
46
47
48
49
50
51
52
53
// Linux NPTL 2.3.2
complex list_head {
	'X'	0	next;
	'X'	4	prev;
};
complex nptl_pthread {
	'X'	0	loopback;
	'X'	0x48	tid;
};

// cannot be done at load time -- need shared library symbols
defn guessnptl() {
	if var("nptl_version") then {
		pthreadlibrary = "nptl";
		isnptl = 1;
	} else {
		pthreadlibrary = "linuxclone";
		isnptl = 0;
	}
}

defn pthread2tid(p) {
	guessnptl();
	if p == 0 then
		return 0;
	if isnptl then {
		complex nptl_pthread p;
		if p.loopback != p then
			error("bad pthread "+itoa(p, "%x"));
		return p.tid;
	}else {
		return p\X;
	}
}

defn pthreadlist() {
	local all, p, n, l;

	if isnptl then {
		all = {};
		l = (list_head)stack_used;
		l = (list_head)l.next;
		while l != stack_used do {
			p = l - *_thread_db_pthread_list;
			all = append all, p;
			l = (list_head)l.next;
		}
	} else {
		all = {};
	}
	return all;
}