11 #define _SDT_HAS_SEMAPHORES 1
14 #define SEC(name) __attribute__((section(name), used))
18 /* defined in urandom_read_aux.c */
19 void urand_read_without_sema(int iter_num, int iter_cnt, int read_sz);
20 /* these are coming from urandom_read_lib{1,2}.c */
21 void urandlib_read_with_sema(int iter_num, int iter_cnt, int read_sz);
22 void urandlib_read_without_sema(int iter_num, int iter_cnt, int read_sz);
24 unsigned short urand_read_with_sema_semaphore SEC(".probes");
26 static __attribute__((noinline))
27 void urandom_read(int fd, int count)
32 for (i = 0; i < count; ++i) {
33 read(fd, buf, BUF_SIZE);
35 /* trigger USDTs defined in executable itself */
36 urand_read_without_sema(i, count, BUF_SIZE);
37 STAP_PROBE3(urand, read_with_sema, i, count, BUF_SIZE);
39 /* trigger USDTs defined in shared lib */
40 urandlib_read_without_sema(i, count, BUF_SIZE);
41 urandlib_read_with_sema(i, count, BUF_SIZE);
45 static volatile bool parent_ready;
47 static void handle_sigpipe(int sig)
52 int main(int argc, char *argv[])
54 int fd = open("/dev/urandom", O_RDONLY);
56 bool report_pid = false;
62 count = atoi(argv[1]);
65 /* install SIGPIPE handler to catch when parent closes their
66 * end of the pipe (on the other side of our stdout)
68 signal(SIGPIPE, handle_sigpipe);
71 /* report PID and wait for parent process to send us "signal" by
75 while (!parent_ready) {
76 fprintf(stdout, "%d\n", getpid());
79 /* at this point stdout is closed, parent process knows our
80 * PID and is ready to trace us
84 urandom_read(fd, count);