2 * Copyright © 2018 Alexey Dobriyan <adobriyan@gmail.com>
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 // Test that /proc/thread-self gives correct TGID/PID.
29 char buf1
[64], buf2
[64];
35 snprintf(buf1
, sizeof(buf1
), "%u/task/%u", pid
, tid
);
37 rv
= readlink("/proc/thread-self", buf2
, sizeof(buf2
));
38 assert(rv
== strlen(buf1
));
40 assert(streq(buf1
, buf2
));
49 const int PAGE_SIZE
= sysconf(_SC_PAGESIZE
);
56 stack
= mmap(NULL
, 2 * PAGE_SIZE
, PROT_READ
|PROT_WRITE
, MAP_PRIVATE
|MAP_ANONYMOUS
, -1, 0);
57 assert(stack
!= MAP_FAILED
);
59 pid
= clone(f
, stack
+ PAGE_SIZE
, CLONE_THREAD
|CLONE_SIGHAND
|CLONE_VM
, (void *)1);