note a leak that needs fixing eventually
[trinity.git] / syscalls / sync_file_range.c
blobeabaee163292f46486019965e22e3b5e3cca85f9
1 /*
2 * SYSCALL_DEFINE(sync_file_range)(int fd, loff_t offset, loff_t nbytes, unsigned int flags)
3 * SYSCALL_DEFINE(sync_file_range2)(int fd, unsigned int flags, loff_t offset, loff_t nbytes)
4 */
5 #include <linux/fs.h>
6 #include <fcntl.h>
7 #include <string.h>
8 #include <stdlib.h>
9 #include "arch.h"
10 #include "random.h"
11 #include "sanitise.h"
12 #include "shm.h"
13 #include "tables.h"
15 static void sanitise_sync_file_range(int childno)
17 long endbyte;
18 loff_t nbytes;
19 loff_t off;
21 retry:
22 off = rand64() & 0x0fffffffffffffffUL;
23 nbytes = rand64() & 0x0fffffffffffffffUL;
24 endbyte = off + nbytes;
25 if (endbyte < off)
26 goto retry;
28 if (off >= (0x100000000LL << PAGE_SHIFT))
29 goto retry;
31 if (this_syscallname("sync_file_range2", childno) == FALSE) {
32 shm->syscall[childno].a2 = off;
33 shm->syscall[childno].a3 = nbytes;
34 } else {
35 shm->syscall[childno].a3 = off;
36 shm->syscall[childno].a4 = nbytes;
40 struct syscallentry syscall_sync_file_range = {
41 .name = "sync_file_range",
42 .num_args = 4,
43 .sanitise = sanitise_sync_file_range,
44 .arg1name = "fd",
45 .arg1type = ARG_FD,
46 .arg2name = "offset",
47 .arg3name = "nbytes",
48 .arg3type = ARG_LEN,
49 .arg4name = "flags",
50 .arg4type = ARG_LIST,
51 .arg4list = {
52 .num = 3,
53 .values = { SYNC_FILE_RANGE_WAIT_BEFORE, SYNC_FILE_RANGE_WRITE, SYNC_FILE_RANGE_WAIT_AFTER },
55 .flags = NEED_ALARM,
56 .group = GROUP_VFS,
60 * ARM & PowerPC have different argument order.
61 * See edd5cd4a9424f22b0fa08bef5e299d41befd5622 in kernel tree.
63 struct syscallentry syscall_sync_file_range2 = {
64 .name = "sync_file_range2",
65 .num_args = 4,
66 .sanitise = sanitise_sync_file_range,
67 .arg1name = "fd",
68 .arg1type = ARG_FD,
69 .arg2name = "flags",
70 .arg2type = ARG_LIST,
71 .arg2list = {
72 .num = 3,
73 .values = { SYNC_FILE_RANGE_WAIT_BEFORE, SYNC_FILE_RANGE_WRITE, SYNC_FILE_RANGE_WAIT_AFTER },
75 .arg3name = "offset",
76 .arg4name = "nbytes",
77 .arg4type = ARG_LEN,
78 .flags = NEED_ALARM,
79 .group = GROUP_VFS,