/* -*- c -*-
 *
 * This is a list of system calls we invoke "directly".  These
 * are generated into syscall stubs in their own files, so the
 * linker can do its job properly.
 *
 * The full description of a line is:
 * [<[?][!]arch,...>] type [sysname,...][@systype][::funcname](args);
 *
 * ? means only instantiate this system call if present in asm/unistd.h
 */

#include <asm/unistd.h>
#include <klibc/sysconfig.h>
#include <bitsize.h>

/*
 * Process-related syscalls
 */
void _exit,exit::_exit(int);
#ifdef __NR_fork
<!sparc,sparc64> pid_t fork();
<sparc,sparc64> pid_t fork@forkish();
#else
/*
 * The clone() parameter order varies between architectures.  However,
 * the first 2 are always clone_flags and newsp, except on s390/s390x
 * where we have fork() and do not use clone().
 */
pid_t clone::__clone(unsigned long, void *);
#endif
#if _KLIBC_REAL_VFORK
/*
 * A lot of architectures need architecture-specific vfork
 * stubs, due to the no-stack requirement.  These are the
 * architectures which do not.
 */
<alpha,ppc,ppc64,sh,s390,s390x> pid_t vfork();
<sparc,sparc64> pid_t vfork@forkish();
#endif
<!alpha> pid_t getpid();
<alpha> pid_t getxpid@dual0::getpid();
int setpgid(pid_t, pid_t);
pid_t getpgid(pid_t);
<!alpha> pid_t getppid();
<alpha> pid_t getxpid@dual1::getppid();
pid_t setsid();
pid_t getsid(pid_t);
pid_t wait4(pid_t, int *, int, struct rusage *);
int execve(const char *, char * const *, char * const *);
<?> int nice(int);
<alpha> int getpriority(int, int);
<!alpha> int getpriority::__getpriority(int, int);
int setpriority(int, int, int);
int getrusage(int, struct rusage *);
int sched_setscheduler(pid_t, int, const struct sched_param *);
int sched_setaffinity(pid_t, unsigned int, unsigned long *);
int sched_getaffinity(pid_t, unsigned int, unsigned long *);
int sched_yield();
<i386> int prctl@varadic(int, unsigned long, unsigned long, unsigned long, unsigned long);
<!i386> int prctl(int, unsigned long, unsigned long, unsigned long, unsigned long);

/*
 * User and group IDs
 */
int setuid32,setuid::setuid(uid_t);
int setgid32,setgid::setgid(gid_t);
<!alpha> uid_t getuid32,getuid::getuid();
<alpha>  uid_t getxuid@dual0::getuid();
<!alpha> gid_t getgid32,getgid::getgid();
<alpha> gid_t getxgid@dual0::getgid();
<!alpha> uid_t geteuid32,geteuid::geteuid();
<alpha> uid_t getxuid@dual1::geteuid();
<!alpha> gid_t getegid32,getegid::getegid();
<alpha> gid_t getxgid@dual1::getegid();
int getgroups32,getgroups::getgroups(int, gid_t *);
int setgroups32,setgroups::setgroups(size_t, const gid_t *);
int setreuid32,setreuid::setreuid(uid_t, uid_t);
int setregid32,setregid::setregid(gid_t, gid_t);
int setfsuid32,setfsuid::setfsuid(uid_t);
int setfsgid32,setfsgid::setfsgid(gid_t);
int setresuid32,setresuid::setresuid(int, uid_t, uid_t, uid_t);

/*
 * POSIX Capabilities
 */
int capget(cap_user_header_t, cap_user_data_t);
int capset(cap_user_header_t, cap_user_data_t);

/*
 * Filesystem-related system calls
 */
int mount(const char *, const char *, const char *, unsigned long, const void *);
<!alpha> int umount2(const char *, int);
<alpha> int umount::umount2(const char *, int);
int pivot_root(const char *, const char *);
int sync();
#ifdef __NR_statfs64
int statfs64::__statfs64(const char *, size_t, struct statfs *);
#else
int statfs(const char *, struct statfs *);
#endif
#ifdef __NR_fstatfs64
int fstatfs64::__fstatfs64(int, size_t, struct statfs *);
#else
int fstatfs(int, struct statfs *);
#endif
int swapon(const char *, int);
int swapoff(const char *);

/*
 * Inode-related system calls
 */
<?> int access(const char *, int);
int faccessat(int, const char *, int, int);
<?> int link(const char *, const char *);
int linkat(int, const char *, int, const char *, int);
<?> int unlink(const char *);
int unlinkat(int, const char *, int);
int chdir(const char *);
int fchdir(int);
<?> int rename(const char *, const char *);
<?> int renameat(int, const char *, int, const char *);
int renameat2(int, const char *, int, const char *, unsigned int);
<?> int mknod(const char *, mode_t, dev_t);
int mknodat(int, const char *, mode_t, dev_t);
<?> int chmod(const char *, mode_t);
int fchmod(int, mode_t);
int fchmodat(int, const char *, mode_t, int);
<?> int mkdir(const char *, mode_t);
int mkdirat(int, const char *, mode_t);
<?> int rmdir(const char *);
<?!alpha,mips,mips64,sh,sparc,sparc64> int pipe(int *);
int pipe2(int *, int);
mode_t umask(mode_t);
int chroot(const char *);
<?> int symlink(const char *, const char *);
int symlinkat(const char *, int, const char *);
<?> int readlink(const char *, char *, size_t);
int readlinkat(int, const char *, char *, int);
int statx(int, const char *, int, unsigned int, struct statx *);
int getdents64,getdents::getdents(unsigned int, struct dirent *, unsigned int);
<?> int chown32,chown::chown(const char *, uid_t, gid_t);
int fchown32,fchown::fchown(int, uid_t, gid_t);
int fchownat(int, const char *, uid_t, gid_t, int);
<?> int lchown32,lchown::lchown(const char *, uid_t, gid_t);
int getcwd::__getcwd(char *, size_t);
<32> int utimensat_time64::utimensat(int, const char *, const struct timespec *, int);
<64> int utimensat(int, const char *, const struct timespec *, int);
<?> int inotify_init();
int inotify_init1(int);
int inotify_add_watch(int, const char *, __u32);
int inotify_rm_watch(int, __u32);

/*
 * I/O operations
 */
<!i386,m68k,64> int open::__open(const char *, int, mode_t);
<!i386,m68k,64> int openat::__openat(int, const char *, int, mode_t);
<?64> int open(const char *, int, mode_t);
<64> int openat(int, const char *, int, mode_t);
ssize_t read(int, void *, size_t);
ssize_t write(int, const void *, size_t);
int close(int);
<64> off_t lseek(int, off_t, int);
<32> int _llseek::__llseek(int, unsigned long, unsigned long, off_t *, int);
int dup(int);
<?> int dup2(int, int);
int dup3(int, int, int);
<i386> int fcntl64@varadic::fcntl(int, int, unsigned long);
<ppc64> int fcntl(int, int, unsigned long);
<!i386,ppc64> int fcntl64,fcntl::fcntl(int, int, unsigned long);
int ioctl(int, int, void *);
int flock(int, int);
<32> int pselect6_time64::__pselect6(int, fd_set *, fd_set *, fd_set *, struct timespec *, const struct __pselect6 *);
<64> int pselect6::__pselect6(int, fd_set *, fd_set *, fd_set *, struct timespec *, const struct __pselect6 *);
<?> int poll(struct pollfd *, nfds_t, long);
<32> int ppoll_time64::__ppoll(struct pollfd *, nfds_t, struct timespec *, const sigset_t *, size_t);
<64> int ppoll::__ppoll(struct pollfd *, nfds_t, struct timespec *, const sigset_t *, size_t);
int fsync(int);
int fdatasync,fsync::fdatasync(int);
int readv(int, const struct iovec *, int);
int writev(int, const struct iovec *, int);
int ftruncate64,ftruncate::ftruncate(int, off_t);
<parisc> ssize_t pread64,pread::__pread(int, void *, size_t, off_t);
<parisc> ssize_t pwrite64,pwrite::__pwrite(int, void *, size_t, off_t);
<!parisc> ssize_t pread64,pread::pread(int, void *, size_t, off_t);
<!parisc> ssize_t pwrite64,pwrite::pwrite(int, void *, size_t, off_t);
int sync_file_range,fdatasync,fsync::sync_file_range(int, off_t, off_t, unsigned int);
int splice(int, off_t *, int, off_t *, size_t, unsigned int);
int tee(int, int, size_t, unsigned int);
ssize_t sendfile64,sendfile::sendfile(int, int, off_t *, size_t, off_t);

/*
 * Signal operations
 */
<!sparc,sparc64,alpha> int rt_sigaction::__rt_sigaction(int, const struct sigaction *, struct sigaction *, size_t);
<sparc,sparc64> int rt_sigaction::____rt_sigaction(int, const struct sigaction *, struct sigaction *, void *, size_t);
<alpha> int rt_sigaction::____rt_sigaction(int, const struct sigaction *, struct sigaction *, size_t, void *);
int rt_sigsuspend::__rt_sigsuspend(const sigset_t *, size_t);
int rt_sigpending::__rt_sigpending(sigset_t *, size_t);
int rt_sigprocmask::__rt_sigprocmask(int, const sigset_t *, sigset_t *, size_t);
<s390,s390x,sparc,sparc64> void rt_sigreturn::__sigreturn();
int kill(pid_t, int);
<?> unsigned int alarm(unsigned int);
int getitimer(int, struct itimerval *);
int setitimer(int, const struct itimerval *, struct itimerval *);

/*
 * Time-related system calls
 */
clock_t times(struct tms *);
int gettimeofday::__gettimeofday(void *, struct timezone *);
int settimeofday::__settimeofday(const void *, const struct timezone *);
<32> int clock_gettime64::clock_gettime(clockid_t, struct timespec *);
<64> int clock_gettime(clockid_t, struct timespec *);
<32> int clock_settime64::clock_settime(clockid_t, const struct timespec *);
<64> int clock_settime(clockid_t, const struct timespec *);
<32> int clock_nanosleep_time64::__clock_nanosleep(clockid_t, int, const struct timespec *, struct timespec *);
<64> int clock_nanosleep::__clock_nanosleep(clockid_t, int, const struct timespec *, struct timespec *);
<?> int pause();

/*
 * Memory
 */
void * brk::__brk(void *);
int munmap(void *, size_t);
void * mremap(void *, size_t, size_t, unsigned long);
int msync(const void *, size_t, int);
int mprotect(const void *, size_t, int);
#if _KLIBC_USE_MMAP2
<!s390> void * mmap2::__mmap2(void *, size_t, int, int, int, long);
#else
<!s390x> void * mmap(void *, size_t, int, int, int, long);
#endif
int mlockall(int);
int munlockall();
int mlock(const void *, size_t);
int munlock(const void *, size_t);

/*
 * System stuff
 */
int uname(struct utsname *);
int setdomainname(const char *, size_t);
int sethostname(const char *, size_t);
long init_module(void *, unsigned long, const char *);
long finit_module(int, const char *, int);
long delete_module(const char *, unsigned int);
int reboot::__reboot(int, int, int, void *);
int syslog::klogctl(int, char *, int);
int sysinfo(struct sysinfo *);
long kexec_load(void *, unsigned long, struct kexec_segment *, unsigned long);

/*
 * Low-level I/O (generally architecture-specific);
 */
<i386,x86_64> int iopl(int);
<i386,x86_64> int ioperm(unsigned long, unsigned long, int);
<i386> int vm86(struct vm86_struct *);

/*
 * Socket interfaces.
 */
int socket(int, int, int);
int bind(int, const struct sockaddr *, int);
int connect(int, const struct sockaddr *, socklen_t);
int listen(int, int);
<?> int accept(int, struct sockaddr *, socklen_t *);
int accept4(int, struct sockaddr *, socklen_t *, int);
int getsockname(int, struct sockaddr *, socklen_t *);
int getpeername(int, struct sockaddr *, socklen_t *);
int socketpair(int, int, int, int *);
int sendto(int, const void *, size_t, int, const struct sockaddr *, socklen_t);
int recvfrom(int, void *, size_t, unsigned int, struct sockaddr *, socklen_t *);
int shutdown(int, int);
int setsockopt(int, int, int, const void *, socklen_t);
int getsockopt(int, int, int, void *, socklen_t *);
int sendmsg(int, const struct msghdr *, unsigned int);
int recvmsg(int, struct msghdr *, unsigned int);
