726fbc8ed0805e280115ab9e5b31dd6ae4513db4
2 * Copyright (C) 2017 Francis Deslauriers <francis.deslauriers@efficios.com>
4 * SPDX-License-Identifier: LGPL-2.1-only
10 #include <common/align.hpp>
11 #include <common/error.hpp>
15 #include <sys/syscall.h>
21 * The LTTng system call tracing facilities can't handle page faults at the
22 * moment. If a fault would occur while reading a syscall argument, the
23 * tracer will report an empty string (""). Since the proper execution of the
24 * tests which use this generator depends on some syscall string arguments being
25 * present, this util allows us to mitigate the page-fault risk.
27 * This isn't a proper fix; it is simply the best we can do for now.
28 * See bug #1261 for more context.
30 static 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
);
44 static int open_read_close(const char *path
)
50 * Start generating syscalls. We use syscall(2) to prevent libc from
51 * changing the underlying syscall (e.g. calling openat(2) instead of
54 prefault_string(path
);
55 fd
= syscall(SYS_openat
, AT_FDCWD
, path
, O_RDONLY
);
57 PERROR_NO_LOGGER("Failed to open file with openat(): path = '%s'", path
);
62 ret
= syscall(SYS_read
, fd
, buf
, MAX_LEN
);
64 PERROR_NO_LOGGER("Failed to read file: path = '%s', fd = %d, length = %d",
72 ret
= syscall(SYS_close
, fd
);
74 PERROR_NO_LOGGER("Failed to close file: path = '%s', fd = %d", path
, fd
);
84 * The process waits for the creation of a file passed as argument from an
85 * external processes to execute a syscall and exiting. This is useful for tests
86 * in combinaison with LTTng's PID tracker feature where we can trace the kernel
87 * events generated by our test process only.
89 int main(int argc
, char **argv
)
92 const char *start_file
, *path1
, *path2
;
95 fprintf(stderr
, "Error: Missing argument\n");
96 fprintf(stderr
, "USAGE: %s PATH_WAIT_FILE PATH1_TO_OPEN PATH2_TO_OPEN\n", argv
[0]);
101 start_file
= argv
[1];
106 * Wait for the start_file to be created by an external process
107 * (typically the test script) before executing the syscalls.
109 ret
= wait_on_file(start_file
);
115 * Start generating syscalls. We use syscall(2) to prevent libc to change
116 * the underlying syscall. e.g. calling openat(2) instead of open(2).
118 ret
= open_read_close(path1
);
124 ret
= open_read_close(path2
);
This page took 0.033582 seconds and 5 git commands to generate.