move_pages: just use calloc
[trinity.git] / syscalls / open.c
blobd6d1406025217745a7bf3b2ba309df40a5627767
1 #include <sys/types.h>
2 #include <sys/stat.h>
3 #include <fcntl.h>
4 #include <stdlib.h>
5 #include "files.h"
6 #include "sanitise.h"
7 #include "shm.h"
8 #include "utils.h"
9 #include "compat.h"
11 static const unsigned long o_flags[] = {
12 O_EXCL, O_NOCTTY, O_TRUNC, O_APPEND,
13 O_NONBLOCK, O_SYNC, O_ASYNC, O_DIRECTORY,
14 O_NOFOLLOW, O_CLOEXEC, O_DIRECT, O_NOATIME,
15 O_PATH, O_DSYNC, O_LARGEFILE, O_TMPFILE,
19 * Choose a random number of file flags to OR into the mask.
20 * also used in files.c:open_file()
22 unsigned long get_o_flags(void)
24 unsigned long mask;
26 mask = set_rand_bitmask(ARRAY_SIZE(o_flags), o_flags);
28 return mask;
32 * SYSCALL_DEFINE3(open, const char __user *, filename, int, flags, int, mode)
34 static void sanitise_open(int childno);
36 struct syscallentry syscall_open = {
37 .name = "open",
38 .num_args = 3,
39 .arg1name = "filename",
40 .arg1type = ARG_PATHNAME,
41 .arg2name = "flags",
42 .arg2type = ARG_OP,
43 .arg2list = {
44 .num = 4,
45 .values = { O_RDONLY, O_WRONLY, O_RDWR, O_CREAT, },
47 .arg3name = "mode",
48 .arg3type = ARG_MODE_T,
49 .sanitise = sanitise_open,
52 static void sanitise_open(int childno)
54 unsigned long flags;
56 flags = get_o_flags();
58 shm->syscall[childno].a2 |= flags;
62 * SYSCALL_DEFINE4(openat, int, dfd, const char __user *, filename, int, flags, int, mode)
64 static void sanitise_openat(int childno);
66 struct syscallentry syscall_openat = {
67 .name = "openat",
68 .num_args = 4,
69 .arg1name = "dfd",
70 .arg1type = ARG_FD,
71 .arg2name = "filename",
72 .arg2type = ARG_PATHNAME,
73 .arg3name = "flags",
74 .arg3type = ARG_OP,
75 .arg3list = {
76 .num = 4,
77 .values = { O_RDONLY, O_WRONLY, O_RDWR, O_CREAT, },
79 .arg4name = "mode",
80 .arg4type = ARG_MODE_T,
81 .flags = NEED_ALARM,
82 .sanitise = sanitise_openat,
85 static void sanitise_openat(int childno)
87 unsigned long flags;
89 flags = get_o_flags();
91 shm->syscall[childno].a3 |= flags;
95 * SYSCALL_DEFINE3(open_by_handle_at, int, mountdirfd,
96 * struct file_handle __user *, handle,
97 * int, flags)
99 struct syscallentry syscall_open_by_handle_at = {
100 .name = "open_by_handle_at",
101 .num_args = 3,
102 .arg1name = "mountdirfd",
103 .arg1type = ARG_FD,
104 .arg2name = "handle",
105 .arg2type = ARG_ADDRESS,
106 .arg3name = "flags",
107 .arg3type = ARG_OP,
108 .arg3list = {
109 .num = 4,
110 .values = { O_RDONLY, O_WRONLY, O_RDWR, O_CREAT, },
112 .flags = NEED_ALARM,
113 .sanitise = sanitise_openat, // For now we only sanitise .flags, which is also arg3