xref: /freebsd/sys/sys/syscallsubr.h (revision d0b2dbfa)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 2002 Ian Dowse.  All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  */
27 
28 #ifndef _SYS_SYSCALLSUBR_H_
29 #define _SYS_SYSCALLSUBR_H_
30 
31 #include <sys/signal.h>
32 #include <sys/socket.h>
33 #include <sys/mac.h>
34 #include <sys/mount.h>
35 #include <sys/_cpuset.h>
36 #include <sys/_domainset.h>
37 #include <sys/_uio.h>
38 
39 struct __wrusage;
40 struct cpuset_copy_cb;
41 struct file;
42 struct filecaps;
43 enum idtype;
44 struct itimerval;
45 struct image_args;
46 struct jail;
47 struct kevent;
48 struct kevent_copyops;
49 struct kld_file_stat;
50 struct ksiginfo;
51 struct mbuf;
52 struct msghdr;
53 struct msqid_ds;
54 struct pollfd;
55 struct ogetdirentries_args;
56 struct rlimit;
57 struct rusage;
58 struct sched_param;
59 struct sembuf;
60 union semun;
61 struct sockaddr;
62 struct spacectl_range;
63 struct stat;
64 struct thr_param;
65 struct timex;
66 struct uio;
67 struct vm_map;
68 struct vmspace;
69 
70 typedef int (*mmap_check_fp_fn)(struct file *, int, int, int);
71 
72 struct mmap_req {
73 	vm_offset_t		mr_hint;
74 	vm_size_t		mr_len;
75 	int			mr_prot;
76 	int			mr_flags;
77 	int			mr_fd;
78 	off_t			mr_pos;
79 	mmap_check_fp_fn	mr_check_fp_fn;
80 };
81 
82 uint64_t at2cnpflags(u_int at_flags, u_int mask);
83 int	kern___getcwd(struct thread *td, char *buf, enum uio_seg bufseg,
84 	    size_t buflen, size_t path_max);
85 int	kern_abort2(struct thread *td, const char *why, int nargs,
86 	    void **uargs);
87 int	kern_accept(struct thread *td, int s, struct sockaddr **name,
88 	    socklen_t *namelen, struct file **fp);
89 int	kern_accept4(struct thread *td, int s, struct sockaddr **name,
90 	    socklen_t *namelen, int flags, struct file **fp);
91 int	kern_accessat(struct thread *td, int fd, const char *path,
92 	    enum uio_seg pathseg, int flags, int mode);
93 int	kern_adjtime(struct thread *td, struct timeval *delta,
94 	    struct timeval *olddelta);
95 int	kern_bindat(struct thread *td, int dirfd, int fd, struct sockaddr *sa);
96 int	kern_break(struct thread *td, uintptr_t *addr);
97 int	kern_cap_ioctls_limit(struct thread *td, int fd, u_long *cmds,
98 	    size_t ncmds);
99 int	kern_cap_rights_limit(struct thread *td, int fd, cap_rights_t *rights);
100 int	kern_chdir(struct thread *td, const char *path, enum uio_seg pathseg);
101 int	kern_clock_getcpuclockid2(struct thread *td, id_t id, int which,
102 	    clockid_t *clk_id);
103 int	kern_clock_getres(struct thread *td, clockid_t clock_id,
104 	    struct timespec *ts);
105 int	kern_clock_gettime(struct thread *td, clockid_t clock_id,
106 	    struct timespec *ats);
107 int	kern_clock_nanosleep(struct thread *td, clockid_t clock_id, int flags,
108 	    const struct timespec *rqtp, struct timespec *rmtp);
109 int	kern_clock_settime(struct thread *td, clockid_t clock_id,
110 	    struct timespec *ats);
111 void	kern_thread_cputime(struct thread *targettd, struct timespec *ats);
112 void	kern_process_cputime(struct proc *targetp, struct timespec *ats);
113 int	kern_close_range(struct thread *td, int flags, u_int lowfd, u_int highfd);
114 int	kern_close(struct thread *td, int fd);
115 int	kern_connectat(struct thread *td, int dirfd, int fd,
116 	    struct sockaddr *sa);
117 int	kern_copy_file_range(struct thread *td, int infd, off_t *inoffp,
118 	    int outfd, off_t *outoffp, size_t len, unsigned int flags);
119 int	user_cpuset_getaffinity(struct thread *td, cpulevel_t level,
120 	    cpuwhich_t which, id_t id, size_t cpusetsize, cpuset_t *maskp,
121 	    const struct cpuset_copy_cb *cb);
122 int	kern_cpuset_getaffinity(struct thread *td, cpulevel_t level,
123 	    cpuwhich_t which, id_t id, size_t cpusetsize, cpuset_t *mask);
124 int	kern_cpuset_setaffinity(struct thread *td, cpulevel_t level,
125 	    cpuwhich_t which, id_t id, cpuset_t *maskp);
126 int	user_cpuset_setaffinity(struct thread *td, cpulevel_t level,
127 	    cpuwhich_t which, id_t id, size_t cpusetsize,
128 	    const cpuset_t *maskp, const struct cpuset_copy_cb *cb);
129 int	kern_cpuset_getdomain(struct thread *td, cpulevel_t level,
130 	    cpuwhich_t which, id_t id, size_t domainsetsize,
131 	    domainset_t *maskp, int *policyp, const struct cpuset_copy_cb *cb);
132 int	kern_cpuset_setdomain(struct thread *td, cpulevel_t level,
133 	    cpuwhich_t which, id_t id, size_t domainsetsize,
134 	    const domainset_t *maskp, int policy, const struct cpuset_copy_cb *cb);
135 int	kern_cpuset_getid(struct thread *td, cpulevel_t level,
136 	    cpuwhich_t which, id_t id, cpusetid_t *setid);
137 int	kern_cpuset_setid(struct thread *td, cpuwhich_t which,
138 	    id_t id, cpusetid_t setid);
139 int	kern_dup(struct thread *td, u_int mode, int flags, int old, int new);
140 int	kern_execve(struct thread *td, struct image_args *args,
141 	    struct mac *mac_p, struct vmspace *oldvmspace);
142 int	kern_fchmodat(struct thread *td, int fd, const char *path,
143 	    enum uio_seg pathseg, mode_t mode, int flag);
144 int	kern_fchownat(struct thread *td, int fd, const char *path,
145 	    enum uio_seg pathseg, int uid, int gid, int flag);
146 int	kern_fcntl(struct thread *td, int fd, int cmd, intptr_t arg);
147 int	kern_fcntl_freebsd(struct thread *td, int fd, int cmd, long arg);
148 int	kern_fhopen(struct thread *td, const struct fhandle *u_fhp, int flags);
149 int	kern_fhstat(struct thread *td, fhandle_t fh, struct stat *buf);
150 int	kern_fhstatfs(struct thread *td, fhandle_t fh, struct statfs *buf);
151 int	kern_fpathconf(struct thread *td, int fd, int name, long *valuep);
152 int	kern_freebsd11_getfsstat(struct thread *td,
153 	    struct freebsd11_statfs *ubuf, long bufsize, int mode);
154 int	kern_fstat(struct thread *td, int fd, struct stat *sbp);
155 int	kern_fstatfs(struct thread *td, int fd, struct statfs *buf);
156 int	kern_fsync(struct thread *td, int fd, bool fullsync);
157 int	kern_ftruncate(struct thread *td, int fd, off_t length);
158 int	kern_futimes(struct thread *td, int fd, const struct timeval *tptr,
159 	    enum uio_seg tptrseg);
160 int	kern_futimens(struct thread *td, int fd, const struct timespec *tptr,
161 	    enum uio_seg tptrseg);
162 int	kern_getdirentries(struct thread *td, int fd, char *buf, size_t count,
163 	    off_t *basep, ssize_t *residp, enum uio_seg bufseg);
164 int	kern_getfhat(struct thread *td, int flags, int fd, const char *path,
165 	    enum uio_seg pathseg, fhandle_t *fhp, enum uio_seg fhseg);
166 int	kern_getfsstat(struct thread *td, struct statfs **buf, size_t bufsize,
167 	    size_t *countp, enum uio_seg bufseg, int mode);
168 int	kern_getitimer(struct thread *, u_int, struct itimerval *);
169 int	kern_getppid(struct thread *);
170 int	kern_getpeername(struct thread *td, int fd, struct sockaddr **sa,
171 	    socklen_t *alen);
172 int	kern_getpriority(struct thread *td, int which, int who);
173 int	kern_getrusage(struct thread *td, int who, struct rusage *rup);
174 int	kern_getsid(struct thread *td, pid_t pid);
175 int	kern_getsockname(struct thread *td, int fd, struct sockaddr **sa,
176 	    socklen_t *alen);
177 int	kern_getsockopt(struct thread *td, int s, int level, int name,
178 	    void *optval, enum uio_seg valseg, socklen_t *valsize);
179 int	kern_ioctl(struct thread *td, int fd, u_long com, caddr_t data);
180 int	kern_jail(struct thread *td, struct jail *j);
181 int	kern_jail_get(struct thread *td, struct uio *options, int flags);
182 int	kern_jail_set(struct thread *td, struct uio *options, int flags);
183 int	kern_kevent(struct thread *td, int fd, int nchanges, int nevents,
184 	    struct kevent_copyops *k_ops, const struct timespec *timeout);
185 int	kern_kevent_anonymous(struct thread *td, int nevents,
186 	    struct kevent_copyops *k_ops);
187 int	kern_kevent_fp(struct thread *td, struct file *fp, int nchanges,
188 	    int nevents, struct kevent_copyops *k_ops,
189 	    const struct timespec *timeout);
190 int	kern_kill(struct thread *td, pid_t pid, int signum);
191 int	kern_kqueue(struct thread *td, int flags, struct filecaps *fcaps);
192 int	kern_kldload(struct thread *td, const char *file, int *fileid);
193 int	kern_kldstat(struct thread *td, int fileid, struct kld_file_stat *stat);
194 int	kern_kldunload(struct thread *td, int fileid, int flags);
195 int	kern_linkat(struct thread *td, int fd1, int fd2, const char *path1,
196 	    const char *path2, enum uio_seg segflg, int flag);
197 int	kern_listen(struct thread *td, int s, int backlog);
198 int	kern_lseek(struct thread *td, int fd, off_t offset, int whence);
199 int	kern_lutimes(struct thread *td, const char *path, enum uio_seg pathseg,
200 	    const struct timeval *tptr, enum uio_seg tptrseg);
201 int	kern_madvise(struct thread *td, uintptr_t addr, size_t len, int behav);
202 int	kern_mincore(struct thread *td, uintptr_t addr, size_t len, char *vec);
203 int	kern_minherit(struct thread *td, uintptr_t addr, size_t len,
204 	    int inherit);
205 int	kern_mkdirat(struct thread *td, int fd, const char *path,
206 	    enum uio_seg segflg, int mode);
207 int	kern_mkfifoat(struct thread *td, int fd, const char *path,
208 	    enum uio_seg pathseg, int mode);
209 int	kern_mknodat(struct thread *td, int fd, const char *path,
210 	    enum uio_seg pathseg, int mode, dev_t dev);
211 int	kern_mlock(struct proc *proc, struct ucred *cred, uintptr_t addr,
212 	    size_t len);
213 int	kern_mmap(struct thread *td, const struct mmap_req *mrp);
214 int	kern_mmap_racct_check(struct thread *td, struct vm_map *map,
215 	    vm_size_t size);
216 int	kern_mmap_maxprot(struct proc *p, int prot);
217 int	kern_mprotect(struct thread *td, uintptr_t addr, size_t size,
218 	    int prot, int flags);
219 int	kern_msgctl(struct thread *, int, int, struct msqid_ds *);
220 int	kern_msgrcv(struct thread *, int, void *, size_t, long, int, long *);
221 int	kern_msgsnd(struct thread *, int, const void *, size_t, int, long);
222 int	kern_msync(struct thread *td, uintptr_t addr, size_t size, int flags);
223 int	kern_munlock(struct thread *td, uintptr_t addr, size_t size);
224 int	kern_munmap(struct thread *td, uintptr_t addr, size_t size);
225 int     kern_nanosleep(struct thread *td, struct timespec *rqt,
226 	    struct timespec *rmt);
227 int	kern_ntp_adjtime(struct thread *td, struct timex *ntv, int *retvalp);
228 int	kern_ogetdirentries(struct thread *td, struct ogetdirentries_args *uap,
229 	    long *ploff);
230 int	kern_ommap(struct thread *td, uintptr_t hint, int len, int oprot,
231 	    int oflags, int fd, long pos);
232 int	kern_openat(struct thread *td, int fd, const char *path,
233 	    enum uio_seg pathseg, int flags, int mode);
234 int	kern_pathconf(struct thread *td, const char *path,
235 	    enum uio_seg pathseg, int name, u_long flags, long *valuep);
236 int	kern_pipe(struct thread *td, int fildes[2], int flags,
237 	    struct filecaps *fcaps1, struct filecaps *fcaps2);
238 int	kern_poll(struct thread *td, struct pollfd *fds, u_int nfds,
239 	    struct timespec *tsp, sigset_t *uset);
240 int	kern_poll_kfds(struct thread *td, struct pollfd *fds, u_int nfds,
241 	    struct timespec *tsp, sigset_t *uset);
242 bool	kern_poll_maxfds(u_int nfds);
243 int	kern_posix_error(struct thread *td, int error);
244 int	kern_posix_fadvise(struct thread *td, int fd, off_t offset, off_t len,
245 	    int advice);
246 int	kern_posix_fallocate(struct thread *td, int fd, off_t offset,
247 	    off_t len);
248 int	kern_fspacectl(struct thread *td, int fd, int cmd,
249 	    const struct spacectl_range *, int flags, struct spacectl_range *);
250 int	kern_procctl(struct thread *td, enum idtype idtype, id_t id, int com,
251 	    void *data);
252 int	kern_pread(struct thread *td, int fd, void *buf, size_t nbyte,
253 	    off_t offset);
254 int	kern_preadv(struct thread *td, int fd, struct uio *auio, off_t offset);
255 int	kern_pselect(struct thread *td, int nd, fd_set *in, fd_set *ou,
256 	    fd_set *ex, struct timeval *tvp, sigset_t *uset, int abi_nfdbits);
257 int	kern_ptrace(struct thread *td, int req, pid_t pid, void *addr,
258 	    int data);
259 int	kern_pwrite(struct thread *td, int fd, const void *buf, size_t nbyte,
260 	    off_t offset);
261 int	kern_pwritev(struct thread *td, int fd, struct uio *auio, off_t offset);
262 int	kern_readlinkat(struct thread *td, int fd, const char *path,
263 	    enum uio_seg pathseg, char *buf, enum uio_seg bufseg, size_t count);
264 int	kern_readv(struct thread *td, int fd, struct uio *auio);
265 int	kern_recvit(struct thread *td, int s, struct msghdr *mp,
266 	    enum uio_seg fromseg, struct mbuf **controlp);
267 int	kern_renameat(struct thread *td, int oldfd, const char *old, int newfd,
268 	    const char *new, enum uio_seg pathseg);
269 int	kern_frmdirat(struct thread *td, int dfd, const char *path, int fd,
270 	    enum uio_seg pathseg, int flag);
271 int	kern_sched_getparam(struct thread *td, struct thread *targettd,
272 	    struct sched_param *param);
273 int	kern_sched_getscheduler(struct thread *td, struct thread *targettd,
274 	    int *policy);
275 int	kern_sched_setparam(struct thread *td, struct thread *targettd,
276 	    struct sched_param *param);
277 int	kern_sched_setscheduler(struct thread *td, struct thread *targettd,
278 	    int policy, struct sched_param *param);
279 int	kern_sched_rr_get_interval(struct thread *td, pid_t pid,
280 	    struct timespec *ts);
281 int	kern_sched_rr_get_interval_td(struct thread *td, struct thread *targettd,
282 	    struct timespec *ts);
283 int	kern_semctl(struct thread *td, int semid, int semnum, int cmd,
284 	    union semun *arg, register_t *rval);
285 int	kern_select(struct thread *td, int nd, fd_set *fd_in, fd_set *fd_ou,
286 	    fd_set *fd_ex, struct timeval *tvp, int abi_nfdbits);
287 int	kern_sendit(struct thread *td, int s, struct msghdr *mp, int flags,
288 	    struct mbuf *control, enum uio_seg segflg);
289 int	kern_setgroups(struct thread *td, u_int ngrp, gid_t *groups);
290 int	kern_setitimer(struct thread *, u_int, struct itimerval *,
291 	    struct itimerval *);
292 int	kern_setpriority(struct thread *td, int which, int who, int prio);
293 int	kern_setrlimit(struct thread *, u_int, struct rlimit *);
294 int	kern_setsockopt(struct thread *td, int s, int level, int name,
295 	    const void *optval, enum uio_seg valseg, socklen_t valsize);
296 int	kern_settimeofday(struct thread *td, struct timeval *tv,
297 	    struct timezone *tzp);
298 int	kern_shm_open(struct thread *td, const char *userpath, int flags,
299 	    mode_t mode, struct filecaps *fcaps);
300 int	kern_shm_open2(struct thread *td, const char *path, int flags,
301 	    mode_t mode, int shmflags, struct filecaps *fcaps,
302 	    const char *name);
303 int	kern_shmat(struct thread *td, int shmid, const void *shmaddr,
304 	    int shmflg);
305 int	kern_shmctl(struct thread *td, int shmid, int cmd, void *buf,
306 	    size_t *bufsz);
307 int	kern_shutdown(struct thread *td, int s, int how);
308 int	kern_sigaction(struct thread *td, int sig, const struct sigaction *act,
309 	    struct sigaction *oact, int flags);
310 int	kern_sigaltstack(struct thread *td, stack_t *ss, stack_t *oss);
311 int	kern_sigprocmask(struct thread *td, int how,
312 	    sigset_t *set, sigset_t *oset, int flags);
313 int	kern_sigsuspend(struct thread *td, sigset_t mask);
314 int	kern_sigtimedwait(struct thread *td, sigset_t waitset,
315 	    struct ksiginfo *ksi, struct timespec *timeout);
316 int	kern_sigqueue(struct thread *td, pid_t pid, int signum,
317 	    union sigval *value);
318 int	kern_socket(struct thread *td, int domain, int type, int protocol);
319 int	kern_statat(struct thread *td, int flag, int fd, const char *path,
320 	    enum uio_seg pathseg, struct stat *sbp);
321 int	kern_specialfd(struct thread *td, int type, void *arg);
322 int	kern_statfs(struct thread *td, const char *path, enum uio_seg pathseg,
323 	    struct statfs *buf);
324 int	kern_symlinkat(struct thread *td, const char *path1, int fd,
325 	    const char *path2, enum uio_seg segflg);
326 int	kern_sync(struct thread *td);
327 int	kern_ktimer_create(struct thread *td, clockid_t clock_id,
328 	    struct sigevent *evp, int *timerid, int preset_id);
329 int	kern_ktimer_delete(struct thread *, int);
330 int	kern_ktimer_settime(struct thread *td, int timer_id, int flags,
331 	    struct itimerspec *val, struct itimerspec *oval);
332 int	kern_ktimer_gettime(struct thread *td, int timer_id,
333 	    struct itimerspec *val);
334 int	kern_ktimer_getoverrun(struct thread *td, int timer_id);
335 int	kern_semop(struct thread *td, int usemid, struct sembuf *usops,
336 	    size_t nsops, struct timespec *timeout);
337 int	kern_thr_alloc(struct proc *, int pages, struct thread **);
338 int	kern_thr_exit(struct thread *td);
339 int	kern_thr_new(struct thread *td, struct thr_param *param);
340 int	kern_thr_suspend(struct thread *td, struct timespec *tsp);
341 int	kern_truncate(struct thread *td, const char *path,
342 	    enum uio_seg pathseg, off_t length);
343 int	kern_funlinkat(struct thread *td, int dfd, const char *path, int fd,
344 	    enum uio_seg pathseg, int flag, ino_t oldinum);
345 int	kern_utimesat(struct thread *td, int fd, const char *path,
346 	    enum uio_seg pathseg, const struct timeval *tptr,
347 	    enum uio_seg tptrseg);
348 int	kern_utimensat(struct thread *td, int fd, const char *path,
349 	    enum uio_seg pathseg, const struct timespec *tptr,
350 	    enum uio_seg tptrseg, int flag);
351 int	kern_wait(struct thread *td, pid_t pid, int *status, int options,
352 	    struct rusage *rup);
353 int	kern_wait6(struct thread *td, enum idtype idtype, id_t id, int *status,
354 	    int options, struct __wrusage *wrup, siginfo_t *sip);
355 int	kern_writev(struct thread *td, int fd, struct uio *auio);
356 int	kern_socketpair(struct thread *td, int domain, int type, int protocol,
357 	    int *rsv);
358 int	kern_unmount(struct thread *td, const char *path, int flags);
359 
360 /* flags for kern_sigaction */
361 #define	KSA_OSIGSET	0x0001	/* uses osigact_t */
362 #define	KSA_FREEBSD4	0x0002	/* uses ucontext4 */
363 
364 struct freebsd11_dirent;
365 
366 int	freebsd11_kern_getdirentries(struct thread *td, int fd, char *ubuf, u_int
367 	    count, long *basep, void (*func)(struct freebsd11_dirent *));
368 
369 #endif /* !_SYS_SYSCALLSUBR_H_ */
370