2 * Copyright (C) 2017 Francis Deslauriers <francis.deslauriers@efficios.com>
4 * SPDX-License-Identifier: LGPL-2.1-only
10 #include <sys/syscall.h>
12 #include <common/error.h>
13 #include <common/align.h>
20 * The LTTng system call tracing facilities can't handle page faults at the
21 * moment. If a fault would occur while reading a syscall argument, the
22 * tracer will report an empty string (""). Since the proper execution of the
23 * tests which use this generator depends on some syscall string arguments being
24 * present, this util allows us to mitigate the page-fault risk.
26 * This isn't a proper fix; it is simply the best we can do for now.
27 * See bug #1261 for more context.
30 void prefault_string(const char *p
)
32 const char * const end
= p
+ strlen(p
) + 1;
36 * Trigger a read attempt on *p, faulting-in the pages
39 asm volatile("" : : "m"(*p
));
40 p
+= sysconf(_SC_PAGE_SIZE
);
45 int open_read_close(const char *path
)
51 * Start generating syscalls. We use syscall(2) to prevent libc from
52 * changing the underlying syscall (e.g. calling openat(2) instead of
55 prefault_string(path
);
56 fd
= syscall(SYS_openat
, AT_FDCWD
, path
, O_RDONLY
);
58 PERROR_NO_LOGGER("Failed to open file with openat(): path = '%s'", path
);
63 ret
= syscall(SYS_read
, fd
, buf
, MAX_LEN
);
65 PERROR_NO_LOGGER("Failed to read file: path = '%s', fd = %d, length = %d",
71 ret
= syscall(SYS_close
, fd
);
73 PERROR_NO_LOGGER("Failed to close file: path = '%s', fd = %d", path
, fd
);
83 * The process waits for the creation of a file passed as argument from an
84 * external processes to execute a syscall and exiting. This is useful for tests
85 * in combinaison with LTTng's PID tracker feature where we can trace the kernel
86 * events generated by our test process only.
88 int main(int argc
, char **argv
)
91 const char *start_file
, *path1
, *path2
;
94 fprintf(stderr
, "Error: Missing argument\n");
95 fprintf(stderr
, "USAGE: %s PATH_WAIT_FILE PATH1_TO_OPEN PATH2_TO_OPEN\n", argv
[0]);
100 start_file
= argv
[1];
105 * Wait for the start_file to be created by an external process
106 * (typically the test script) before executing the syscalls.
108 ret
= wait_on_file(start_file
);
114 * Start generating syscalls. We use syscall(2) to prevent libc to change
115 * the underlying syscall. e.g. calling openat(2) instead of open(2).
117 ret
= open_read_close(path1
);
123 ret
= open_read_close(path2
);
This page took 0.033147 seconds and 5 git commands to generate.