Ben Hutchings
2024-Oct-02 01:13 UTC
[klibc] [PATCH klibc 0/7] Clean up and harmonise system call definitions
This series cleans up the system call definitions somewhat, and fixes some cases where system call wrappers were missing on some architectures. It also removes the unused no-MMU support. Ben. Ben Hutchings (7): [klibc] Remove unused no-MMU support [klibc] syscalls: Define mlock() etc. on all architectures [klibc] syscalls: Clean up the fork() and clone() definitions [klibc] syscalls: Make more system calls non-optional [klibc] syscalls: Remove _KLIBC_SYS_SOCKETCALL config macro [klibc] syscalls: Remove support for socketcall() [klibc] syscalls: Support for inotify_init1() usr/include/arch/arm64/klibc/archconfig.h | 1 - .../arch/loongarch64/klibc/archconfig.h | 3 - usr/include/arch/riscv64/klibc/archconfig.h | 3 - usr/include/arch/sparc/klibc/archconfig.h | 2 - usr/include/arch/sparc64/klibc/archconfig.h | 1 - usr/include/klibc/sysconfig.h | 27 ------ usr/include/sys/inotify.h | 1 + usr/kinit/nfsmount/main.c | 5 -- usr/klibc/Kbuild | 3 +- usr/klibc/SOCKETCALLS.def | 22 ----- usr/klibc/SYSCALLS.def | 78 +++++++++++------- usr/klibc/accept.c | 2 +- usr/klibc/arch/README.klibc.arch | 2 - usr/klibc/brk.c | 4 - usr/klibc/fork.c | 8 +- usr/klibc/inotify_init.c | 18 ++++ usr/klibc/openat.c | 2 +- usr/klibc/sbrk.c | 4 - usr/klibc/socketcalls.pl | 82 ------------------- usr/klibc/socketcalls/.gitignore | 4 - usr/klibc/socketcalls/Kbuild | 52 ------------ usr/klibc/socketcalls/socketcommon.h | 15 ---- usr/klibc/vfork.c | 2 +- 23 files changed, 75 insertions(+), 266 deletions(-) delete mode 100644 usr/klibc/SOCKETCALLS.def create mode 100644 usr/klibc/inotify_init.c delete mode 100644 usr/klibc/socketcalls.pl delete mode 100644 usr/klibc/socketcalls/.gitignore delete mode 100644 usr/klibc/socketcalls/Kbuild delete mode 100644 usr/klibc/socketcalls/socketcommon.h -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: <https://lists.zytor.com/archives/klibc/attachments/20241002/04904c3d/attachment.sig>
Ben Hutchings
2024-Oct-02 01:15 UTC
[klibc] [PATCH klibc 1/7] Remove unused no-MMU support
There is some conditional logic to handle no-MMU architectures, but no such architectures are defined. We are now having to override the automatic detection for each new architecture because it only checks for fork() and not clone(). Since this is currently unused and therefore untested, it's probably broken. Remove it. Signed-off-by: Ben Hutchings <ben at decadent.org.uk> --- usr/include/arch/arm64/klibc/archconfig.h | 1 - usr/include/arch/loongarch64/klibc/archconfig.h | 3 --- usr/include/arch/riscv64/klibc/archconfig.h | 3 --- usr/include/klibc/sysconfig.h | 16 ---------------- usr/kinit/nfsmount/main.c | 5 ----- usr/klibc/SYSCALLS.def | 4 +--- usr/klibc/arch/README.klibc.arch | 2 -- usr/klibc/brk.c | 4 ---- usr/klibc/fork.c | 4 ++-- usr/klibc/sbrk.c | 4 ---- usr/klibc/vfork.c | 2 +- 11 files changed, 4 insertions(+), 44 deletions(-) diff --git a/usr/include/arch/arm64/klibc/archconfig.h b/usr/include/arch/arm64/klibc/archconfig.h index d094c28d..6792fd47 100644 --- a/usr/include/arch/arm64/klibc/archconfig.h +++ b/usr/include/arch/arm64/klibc/archconfig.h @@ -9,7 +9,6 @@ #ifndef _KLIBC_ARCHCONFIG_H #define _KLIBC_ARCHCONFIG_H -#define _KLIBC_NO_MMU 0 #define _KLIBC_REAL_VFORK 1 #endif /* _KLIBC_ARCHCONFIG_H */ diff --git a/usr/include/arch/loongarch64/klibc/archconfig.h b/usr/include/arch/loongarch64/klibc/archconfig.h index 7a47b915..667b94e7 100644 --- a/usr/include/arch/loongarch64/klibc/archconfig.h +++ b/usr/include/arch/loongarch64/klibc/archconfig.h @@ -9,7 +9,4 @@ #ifndef _KLIBC_ARCHCONFIG_H #define _KLIBC_ARCHCONFIG_H -/* We have an MMU but no fork() syscall */ -#define _KLIBC_NO_MMU 0 - #endif /* _KLIBC_ARCHCONFIG_H */ diff --git a/usr/include/arch/riscv64/klibc/archconfig.h b/usr/include/arch/riscv64/klibc/archconfig.h index e85a69c0..20d9b185 100644 --- a/usr/include/arch/riscv64/klibc/archconfig.h +++ b/usr/include/arch/riscv64/klibc/archconfig.h @@ -9,7 +9,4 @@ #ifndef _KLIBC_ARCHCONFIG_H #define _KLIBC_ARCHCONFIG_H -/* We have an MMU but no fork() syscall */ -#define _KLIBC_NO_MMU 0 - #endif /* _KLIBC_ARCHCONFIG_H */ diff --git a/usr/include/klibc/sysconfig.h b/usr/include/klibc/sysconfig.h index 5d16f612..636c3c08 100644 --- a/usr/include/klibc/sysconfig.h +++ b/usr/include/klibc/sysconfig.h @@ -19,22 +19,6 @@ */ -/* - * _KLIBC_NO_MMU: - * - * Indicates this architecture doesn't have an MMU, and therefore - * does not have the sys_fork and sys_brk system calls. - */ -/* Default to having an MMU if we can find the fork system call */ -#ifndef _KLIBC_NO_MMU -# if defined(__NR_fork) -# define _KLIBC_NO_MMU 0 -# else -# define _KLIBC_NO_MMU 1 -# endif -#endif - - /* * _KLIBC_REAL_VFORK: * diff --git a/usr/kinit/nfsmount/main.c b/usr/kinit/nfsmount/main.c index 66969f42..f6b5b4c1 100644 --- a/usr/kinit/nfsmount/main.c +++ b/usr/kinit/nfsmount/main.c @@ -10,7 +10,6 @@ #include <setjmp.h> #include <sys/wait.h> #include <unistd.h> -#include <klibc/sysconfig.h> /* For _KLIBC_NO_MMU */ #include <linux/nfs_mount.h> @@ -257,9 +256,6 @@ int nfsmount_main(int argc, char *argv[]) check_path(path); -#if !_KLIBC_NO_MMU - /* Note: uClinux can't fork(), so the spoof portmapper is not - available on uClinux. */ if (portmap_file) spoof_portmap = start_dummy_portmap(portmap_file); @@ -267,7 +263,6 @@ int nfsmount_main(int argc, char *argv[]) free(rem_name); return 1; } -#endif ret = 0; if (nfs_mount(rem_name, hostname, server, rem_path, path, diff --git a/usr/klibc/SYSCALLS.def b/usr/klibc/SYSCALLS.def index 7fd8164c..ff32b2ed 100644 --- a/usr/klibc/SYSCALLS.def +++ b/usr/klibc/SYSCALLS.def @@ -19,10 +19,8 @@ */ void _exit,exit::_exit(int); <?> pid_t clone::__clone(unsigned long, void *); -# if ! _KLIBC_NO_MMU <!sparc,sparc64,arm64,riscv64,loongarch64> pid_t fork(); <sparc,sparc64> pid_t fork at forkish(); -#endif #if _KLIBC_REAL_VFORK /* * A lot of architectures need architecture-specific vfork @@ -216,7 +214,7 @@ int settimeofday::__settimeofday(const void *, const struct timezone *); /* * Memory */ -<?> void * brk::__brk(void *); +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); diff --git a/usr/klibc/arch/README.klibc.arch b/usr/klibc/arch/README.klibc.arch index 662b9d3f..c50144d0 100644 --- a/usr/klibc/arch/README.klibc.arch +++ b/usr/klibc/arch/README.klibc.arch @@ -77,5 +77,3 @@ e) Any support functions needed by gcc, *unless* they are in libgcc f) A link location for the shared klibc. This should be specified in SHAREDFLAGS in klibc/arch/*/MCONFIG. - - This is not applicable to no-MMU architectures. diff --git a/usr/klibc/brk.c b/usr/klibc/brk.c index df0bb7bd..cb87324d 100644 --- a/usr/klibc/brk.c +++ b/usr/klibc/brk.c @@ -7,8 +7,6 @@ #include <sys/types.h> #include "malloc.h" -#if !_KLIBC_NO_MMU /* uClinux doesn't have brk() */ - char *__current_brk; /* @@ -25,5 +23,3 @@ int brk(void *end_data_segment) __current_brk = new_brk; return 0; } - -#endif diff --git a/usr/klibc/fork.c b/usr/klibc/fork.c index b07486e9..f5c5d753 100644 --- a/usr/klibc/fork.c +++ b/usr/klibc/fork.c @@ -11,11 +11,11 @@ #include <sched.h> #include <klibc/sysconfig.h> -#if !_KLIBC_NO_MMU && !defined(__NR_fork) +#ifndef __NR_fork pid_t fork(void) { return __clone(SIGCHLD, 0); } -#endif /* __NR_fork */ +#endif diff --git a/usr/klibc/sbrk.c b/usr/klibc/sbrk.c index 4896ce0b..07597428 100644 --- a/usr/klibc/sbrk.c +++ b/usr/klibc/sbrk.c @@ -9,8 +9,6 @@ #include <errno.h> #include "malloc.h" -#if !_KLIBC_NO_MMU /* uClinux doesn't have brk() */ - char *__current_brk; /* Common with brk.c */ /* p is an address, a is alignment; must be a power of 2 */ @@ -41,5 +39,3 @@ void *sbrk(ptrdiff_t increment) __current_brk = new_brk; return start; } - -#endif /* !_KLIBC_NO_MMU */ diff --git a/usr/klibc/vfork.c b/usr/klibc/vfork.c index f2b1a85c..58c089b6 100644 --- a/usr/klibc/vfork.c +++ b/usr/klibc/vfork.c @@ -8,7 +8,7 @@ #include <klibc/compiler.h> #include <klibc/sysconfig.h> -#if !_KLIBC_NO_MMU && !_KLIBC_REAL_VFORK +#if !_KLIBC_REAL_VFORK int vfork(void) { return fork(); -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: <https://lists.zytor.com/archives/klibc/attachments/20241002/4757a594/attachment.sig>
Ben Hutchings
2024-Oct-02 01:15 UTC
[klibc] [PATCH klibc 2/7] syscalls: Define mlock() etc. on all architectures
Due to an error in editing preprocessor conditionals long ago, the m{,un}lock{,all}() system call wrappers are only generated on architectures where we use mmap() and not mmap2(). Move the #endif to the right place. Signed-off-by: Ben Hutchings <ben at decadent.org.uk> --- usr/klibc/SYSCALLS.def | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/usr/klibc/SYSCALLS.def b/usr/klibc/SYSCALLS.def index ff32b2ed..65cf1c2e 100644 --- a/usr/klibc/SYSCALLS.def +++ b/usr/klibc/SYSCALLS.def @@ -219,15 +219,15 @@ 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 +#if _KLIBC_USE_MMAP2 <!s390> void * mmap2::__mmap2(void *, size_t, int, int, int, long); -# else +#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); -#endif /* * System stuff -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: <https://lists.zytor.com/archives/klibc/attachments/20241002/e88ba654/attachment.sig>
Ben Hutchings
2024-Oct-02 01:15 UTC
[klibc] [PATCH klibc 3/7] syscalls: Clean up the fork() and clone() definitions
Currently we're defining __clone() on all architectures, but it's only needed where fork() is missing and it's broken on s390 and s390x where the parameter order is incompatible. We're also building a list of new architectures which don't implement fork(), when we could automatically detect that. To fix these problems: - If __NR_fork is defined, generate a fork() system call wrapper, with only sparc and sparc64 as special cases. - Otherwise, generate __clone() as a clone() system call wrapper. Comment why this works despite the architecture differences. Signed-off-by: Ben Hutchings <ben at decadent.org.uk> --- usr/klibc/SYSCALLS.def | 12 ++++++++++-- usr/klibc/fork.c | 4 ++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/usr/klibc/SYSCALLS.def b/usr/klibc/SYSCALLS.def index 65cf1c2e..e0f8895b 100644 --- a/usr/klibc/SYSCALLS.def +++ b/usr/klibc/SYSCALLS.def @@ -18,9 +18,17 @@ * Process-related syscalls */ void _exit,exit::_exit(int); -<?> pid_t clone::__clone(unsigned long, void *); -<!sparc,sparc64,arm64,riscv64,loongarch64> pid_t fork(); +#ifdef __NR_fork +<!sparc,sparc64> pid_t fork(); <sparc,sparc64> pid_t fork at 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 diff --git a/usr/klibc/fork.c b/usr/klibc/fork.c index f5c5d753..bc0f3755 100644 --- a/usr/klibc/fork.c +++ b/usr/klibc/fork.c @@ -1,8 +1,8 @@ /* * fork.c * - * This is normally just a syscall stub, but at least one system - * doesn't have sys_fork, only sys_clone... + * This is normally just a syscall stub, but new architectures only + * implement clone(). */ #include <sys/syscall.h> -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: <https://lists.zytor.com/archives/klibc/attachments/20241002/c24e7401/attachment.sig>
Ben Hutchings
2024-Oct-02 01:15 UTC
[klibc] [PATCH klibc 4/7] syscalls: Make more system calls non-optional
Currently many system calls are marked as optional in SYSCALLS.def, but should be defined on all architectures. Make them non-optional. Signed-off-by: Ben Hutchings <ben at decadent.org.uk> --- usr/klibc/SYSCALLS.def | 34 +++++++++++++++++----------------- usr/klibc/openat.c | 2 +- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/usr/klibc/SYSCALLS.def b/usr/klibc/SYSCALLS.def index e0f8895b..bbf39c0e 100644 --- a/usr/klibc/SYSCALLS.def +++ b/usr/klibc/SYSCALLS.def @@ -54,8 +54,8 @@ int execve(const char *, char * const *, char * const *); 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_setaffinity(pid_t, unsigned int, unsigned long *); +int sched_getaffinity(pid_t, unsigned int, unsigned long *); int sched_yield(); <i386> int prctl at varadic(int, unsigned long, unsigned long, unsigned long, unsigned long); <!i386> int prctl(int, unsigned long, unsigned long, unsigned long, unsigned long); @@ -93,7 +93,7 @@ int capset(cap_user_header_t, cap_user_data_t); 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 pivot_root(const char *, const char *); int sync(); #ifdef __NR_statfs64 int statfs64::__statfs64(const char *, size_t, struct statfs *); @@ -114,48 +114,48 @@ int swapoff(const char *); <?> 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 linkat(int, const char *, int, const char *, int); <?> int unlink(const char *); -<?> int unlinkat(int, const char *, int); +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 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 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 fchmodat(int, const char *, mode_t, int); <?> int mkdir(const char *, mode_t); -<?> int mkdirat(int, 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 symlinkat(const char *, int, const char *); <?> int readlink(const char *, char *, size_t); -<?> int readlinkat(int, const char *, char *, int); +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 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_add_watch(int, const char *, __u32); -<?> int inotify_rm_watch(int, __u32); +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); +<!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); @@ -186,8 +186,8 @@ 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); 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); +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); /* diff --git a/usr/klibc/openat.c b/usr/klibc/openat.c index 8e5baa0c..59161ac7 100644 --- a/usr/klibc/openat.c +++ b/usr/klibc/openat.c @@ -10,7 +10,7 @@ #include <fcntl.h> #include <bitsize.h> -#if _BITSIZE == 32 && !defined(__i386__) && !defined(__m68k__) && defined(__NR_openat) +#if _BITSIZE == 32 && !defined(__i386__) && !defined(__m68k__) extern int __openat(int, const char *, int, mode_t); -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: <https://lists.zytor.com/archives/klibc/attachments/20241002/a1775953/attachment-0001.sig>
Ben Hutchings
2024-Oct-02 01:16 UTC
[klibc] [PATCH klibc 5/7] syscalls: Remove _KLIBC_SYS_SOCKETCALL config macro
From Linux 1.3.44 to 2.6.25, the sparc port implemented separate system calls for socket(), connect(), etc. in its SunOS personality. The system call numbers were defined in <asm/unistd.h> header even though they were not implemented for native Linux programs. As a workaround for this, commit 8594ecec842d ("[klibc] sparc, sparc64 use sys_socketcall unconditionally") added a macro to override automatic detection of these system calls and defined that on these architectures. No other architecture ever needed this, and since Linux 4.20 all of those system calls are now implemented. We can therefore remove the use of this macro. Signed-off-by: Ben Hutchings <ben at decadent.org.uk> --- usr/include/arch/sparc/klibc/archconfig.h | 2 -- usr/include/arch/sparc64/klibc/archconfig.h | 1 - usr/include/klibc/sysconfig.h | 11 ----------- usr/klibc/SYSCALLS.def | 2 -- usr/klibc/accept.c | 2 +- usr/klibc/socketcalls.pl | 8 ++------ 6 files changed, 3 insertions(+), 23 deletions(-) diff --git a/usr/include/arch/sparc/klibc/archconfig.h b/usr/include/arch/sparc/klibc/archconfig.h index bdc8b1e4..e84a02b2 100644 --- a/usr/include/arch/sparc/klibc/archconfig.h +++ b/usr/include/arch/sparc/klibc/archconfig.h @@ -9,8 +9,6 @@ #ifndef _KLIBC_ARCHCONFIG_H #define _KLIBC_ARCHCONFIG_H -#define _KLIBC_SYS_SOCKETCALL 1 /* Use sys_socketcall unconditionally */ - /* So that we can avoid stack trampolines */ #define _KLIBC_NEEDS_SA_RESTORER 1 /* Our restorer will call rt_sigreturn() */ diff --git a/usr/include/arch/sparc64/klibc/archconfig.h b/usr/include/arch/sparc64/klibc/archconfig.h index df5c8064..c469e87f 100644 --- a/usr/include/arch/sparc64/klibc/archconfig.h +++ b/usr/include/arch/sparc64/klibc/archconfig.h @@ -10,6 +10,5 @@ #define _KLIBC_ARCHCONFIG_H #define _KLIBC_NEEDS_SA_RESTORER 1 /* Need a restorer function */ -#define _KLIBC_SYS_SOCKETCALL 1 /* Use sys_socketcall unconditionally */ #endif /* _KLIBC_ARCHCONFIG_H */ diff --git a/usr/include/klibc/sysconfig.h b/usr/include/klibc/sysconfig.h index 636c3c08..c65ac94a 100644 --- a/usr/include/klibc/sysconfig.h +++ b/usr/include/klibc/sysconfig.h @@ -187,17 +187,6 @@ #endif -/* - * _KLIBC_SYS_SOCKETCALL - * - * This architecture (e.g. SPARC) advertises socket-related - * system calls, which are not actually implemented. Use - * socketcalls unconditionally instead. - */ -#ifndef _KLIBC_SYS_SOCKETCALL -# define _KLIBC_SYS_SOCKETCALL 0 -#endif - /* * _KLIBC_ARM_USE_BX * diff --git a/usr/klibc/SYSCALLS.def b/usr/klibc/SYSCALLS.def index bbf39c0e..b3b269ca 100644 --- a/usr/klibc/SYSCALLS.def +++ b/usr/klibc/SYSCALLS.def @@ -263,6 +263,4 @@ long kexec_load(void *, unsigned long, struct kexec_segment *, unsigned long); * system calls. */ <?!i386> long socketcall::__socketcall(int, const unsigned long *); -#if ! _KLIBC_SYS_SOCKETCALL #include "SOCKETCALLS.def" -#endif diff --git a/usr/klibc/accept.c b/usr/klibc/accept.c index 60575446..443c2fe9 100644 --- a/usr/klibc/accept.c +++ b/usr/klibc/accept.c @@ -6,7 +6,7 @@ #include <sys/socket.h> -#if !_KLIBC_SYS_SOCKETCALL && defined(__NR_accept4) && !defined(__NR_accept) +#if defined(__NR_accept4) && !defined(__NR_accept) int accept(int socket, struct sockaddr *address, socklen_t *addr_len) { diff --git a/usr/klibc/socketcalls.pl b/usr/klibc/socketcalls.pl index 70ded0b0..8e4fe9fc 100644 --- a/usr/klibc/socketcalls.pl +++ b/usr/klibc/socketcalls.pl @@ -47,15 +47,11 @@ while ( defined($line = <FILE>) ) { print OUT "#include \"socketcommon.h\"\n"; print OUT "\n"; - print OUT "#if _KLIBC_SYS_SOCKETCALL\n"; - print OUT "# define DO_THIS_SOCKETCALL\n"; - print OUT "#else\n"; - print OUT "# if !defined(__NR_${name})"; + print OUT "#if !defined(__NR_${name})"; if ($name eq 'accept') { print OUT " && !defined(__NR_accept4)"; } - print OUT "\n# define DO_THIS_SOCKETCALL\n"; - print OUT "# endif\n"; + print OUT "\n# define DO_THIS_SOCKETCALL\n"; print OUT "#endif\n\n"; print OUT "#if defined(DO_THIS_SOCKETCALL) && defined(SYS_\U${name}\E)\n\n"; -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: <https://lists.zytor.com/archives/klibc/attachments/20241002/61646dbf/attachment.sig>
Ben Hutchings
2024-Oct-02 01:16 UTC
[klibc] [PATCH klibc 6/7] syscalls: Remove support for socketcall()
All architectures that implement socketcall() now also have separate system calls: - arm: added in 2.6.12 - i386: added in 4.3 - m68k: added in 4.3 - mips, mips64: added in 2.1.44 - parisc: always had both - ppc, ppc64: added in 2.6.37 - s390, s390x: added in 4.3 - sh: added in 2.6.37 - sparc, sparc64: added in 4.4 and 4.20 We can therefore unconditionally use the separate system calls, except for accept() which may need to be a wrapper for accept4(). Remove support for socketcall(), and move the socket system call definitions into SYSCALLS.def. Signed-off-by: Ben Hutchings <ben at decadent.org.uk> --- usr/klibc/Kbuild | 2 - usr/klibc/SOCKETCALLS.def | 22 -------- usr/klibc/SYSCALLS.def | 21 ++++++-- usr/klibc/accept.c | 2 +- usr/klibc/socketcalls.pl | 78 ---------------------------- usr/klibc/socketcalls/.gitignore | 4 -- usr/klibc/socketcalls/Kbuild | 52 ------------------- usr/klibc/socketcalls/socketcommon.h | 15 ------ 8 files changed, 18 insertions(+), 178 deletions(-) delete mode 100644 usr/klibc/SOCKETCALLS.def delete mode 100644 usr/klibc/socketcalls.pl delete mode 100644 usr/klibc/socketcalls/.gitignore delete mode 100644 usr/klibc/socketcalls/Kbuild delete mode 100644 usr/klibc/socketcalls/socketcommon.h diff --git a/usr/klibc/Kbuild b/usr/klibc/Kbuild index 8b132190..b2a122aa 100644 --- a/usr/klibc/Kbuild +++ b/usr/klibc/Kbuild @@ -7,8 +7,6 @@ export klibc-build := y # Generate syscall stubs klib-y += syscalls/ -# Generate socket calls stubs -klib-y += socketcalls/ # zlib, if configured klib-$(CONFIG_KLIBC_ZLIB) += zlib/ # arch specific .o files diff --git a/usr/klibc/SOCKETCALLS.def b/usr/klibc/SOCKETCALLS.def deleted file mode 100644 index 97413dec..00000000 --- a/usr/klibc/SOCKETCALLS.def +++ /dev/null @@ -1,22 +0,0 @@ -/* -*- c -*- - * - * These are calls that are invoked via the socketcall mechanism - * Note that on most architectures this is simply #included into - * SYSCALLS.def. - */ -<?> 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); diff --git a/usr/klibc/SYSCALLS.def b/usr/klibc/SYSCALLS.def index b3b269ca..d4a593af 100644 --- a/usr/klibc/SYSCALLS.def +++ b/usr/klibc/SYSCALLS.def @@ -259,8 +259,21 @@ long kexec_load(void *, unsigned long, struct kexec_segment *, unsigned long); <i386> int vm86(struct vm86_struct *); /* - * Most architectures have the socket interfaces using regular - * system calls. + * Socket interfaces. */ -<?!i386> long socketcall::__socketcall(int, const unsigned long *); -#include "SOCKETCALLS.def" +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); diff --git a/usr/klibc/accept.c b/usr/klibc/accept.c index 443c2fe9..18c2d6ca 100644 --- a/usr/klibc/accept.c +++ b/usr/klibc/accept.c @@ -6,7 +6,7 @@ #include <sys/socket.h> -#if defined(__NR_accept4) && !defined(__NR_accept) +#ifndef __NR_accept int accept(int socket, struct sockaddr *address, socklen_t *addr_len) { diff --git a/usr/klibc/socketcalls.pl b/usr/klibc/socketcalls.pl deleted file mode 100644 index 8e4fe9fc..00000000 --- a/usr/klibc/socketcalls.pl +++ /dev/null @@ -1,78 +0,0 @@ -#!/usr/bin/perl - -$v = $ENV{'KBUILD_VERBOSE'}; -$quiet = defined($v) ? !$v : 0; - - at args = (); -for $arg ( @ARGV ) { - if ( $arg =~ /^-/ ) { - if ( $arg eq '-q' ) { - $quiet = 1; - } else { - die "$0: Unknown option: $arg\n"; - } - } else { - push(@args, $arg); - } -} -($file, $arch, $outputdir) = @args; - -if (!open(FILE, "< $file")) { - die "$file: $!\n"; -} - -print "socketcall-objs := "; -while ( defined($line = <FILE>) ) { - chomp $line; - $line =~ s/\s*(|\#.*|\/\/.*)$//; # Strip comments and trailing blanks - next unless $line; - - if ( $line =~ /^\s*\<\?\>\s*(.*)\s+([_a-zA-Z][_a-zA-Z0-9]+)\s*\((.*)\)\s*\;$/ ) { - $type = $1; - $name = $2; - $argv = $3; - - @args = split(/\s*\,\s*/, $argv); - @cargs = (); - - $i = 0; - for $arg ( @args ) { - push(@cargs, "$arg a".$i++); - } - $nargs = $i; - print " \\\n\t${name}.o"; - - open(OUT, "> ${outputdir}/${name}.c") - or die "$0: Cannot open ${outputdir}/${name}.c\n"; - - print OUT "#include \"socketcommon.h\"\n"; - print OUT "\n"; - print OUT "#if !defined(__NR_${name})"; - if ($name eq 'accept') { - print OUT " && !defined(__NR_accept4)"; - } - print OUT "\n# define DO_THIS_SOCKETCALL\n"; - print OUT "#endif\n\n"; - - print OUT "#if defined(DO_THIS_SOCKETCALL) && defined(SYS_\U${name}\E)\n\n"; - - print OUT "extern long __socketcall(int, const unsigned long *);\n\n"; - - print OUT "$type ${name}(", join(', ', @cargs), ")\n"; - print OUT "{\n"; - print OUT " unsigned long args[$nargs];\n"; - for ( $i = 0 ; $i < $nargs ; $i++ ) { - print OUT " args[$i] = (unsigned long)a$i;\n"; - } - print OUT " return ($type) __socketcall(SYS_\U${name}\E, args);\n"; - print OUT "}\n\n"; - - print OUT "#endif\n"; - - close(OUT); - } else { - die "$file:$.: Could not parse input\n"; - } -} - -print "\n"; diff --git a/usr/klibc/socketcalls/.gitignore b/usr/klibc/socketcalls/.gitignore deleted file mode 100644 index 67da0d1f..00000000 --- a/usr/klibc/socketcalls/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -*.S -*.c -SOCKETCALLS.i -socketcalls.mk diff --git a/usr/klibc/socketcalls/Kbuild b/usr/klibc/socketcalls/Kbuild deleted file mode 100644 index a974a889..00000000 --- a/usr/klibc/socketcalls/Kbuild +++ /dev/null @@ -1,52 +0,0 @@ -# -# Generate socket calls based on SOCKETCALLS.def -# - -# Include automatically generated Makefile fragment. -# It contains definition of socketcall-objs specifying name of all .o files -ifeq ($(clean),) --include $(obj)/socketcalls.mk -endif - -# Listing of all .o files -always := klib.list - -##### -# Generate socket calls stubs -# Based on input from SOCKETCALLS.def generate socket call stubs -targets := klib.list -targets += socketcalls.mk -targets += SOCKETCALLS.i -targets += $(socketcall-objs) -clean-files += *.S *.c *.o *.list - -EXTRA_KLIBCCFLAGS := -I$(srctree)/$(src) - -quiet_cmd_makelist = LIST $@ - cmd_makelist = echo '$(filter-out FORCE,$^)' > $@ - -# Create list of all files -$(obj)/klib.list: $(call objectify,$(socketcall-objs)) FORCE - $(call if_changed,makelist) - -# Generate assembler file (.i) -# We pass -ansi to keep cpp from define e.g. "i386" as well as "__i386__" -quiet_cmd_socketcall.i = GEN $@ - cmd_socketcall.i = $(KLIBCCC) $(klibccflags) -D__ASSEMBLY__ \ - -ansi -x c -E -o $@ $< -$(obj)/SOCKETCALLS.i: $(KLIBCSRC)/SOCKETCALLS.def FORCE - $(call if_changed_dep,socketcall.i) - -# Generate socketcall stubs -quiet_cmd_socketcalls = GEN $@ - cmd_socketcalls = $(PERL) $(srctree)/$(KLIBCSRC)/socketcalls.pl \ - $(obj)/SOCKETCALLS.i \ - $(KLIBCARCH) $(obj) > $@ \ - || ( rm -f $@ ; exit 1 ) - -$(obj)/socketcalls.mk: $(srctree)/$(KLIBCSRC)/socketcalls.pl \ - $(obj)/SOCKETCALLS.i \ - $(src)/socketcommon.h - $(call cmd,socketcalls) - -PHONY += FORCE diff --git a/usr/klibc/socketcalls/socketcommon.h b/usr/klibc/socketcalls/socketcommon.h deleted file mode 100644 index 7fdd5470..00000000 --- a/usr/klibc/socketcalls/socketcommon.h +++ /dev/null @@ -1,15 +0,0 @@ -/* - * socketcommon.h - * - * Common header file for socketcall stubs - */ - -#define __IN_SYS_COMMON -#include <errno.h> -#include <signal.h> -#include <sys/types.h> -#include <sys/syscall.h> -#include <sys/stat.h> -#include <sys/time.h> -#include <sys/socket.h> -#include <linux/net.h> -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: <https://lists.zytor.com/archives/klibc/attachments/20241002/3b6658d7/attachment.sig>
Ben Hutchings
2024-Oct-02 01:16 UTC
[klibc] [PATCH klibc 7/7] syscalls: Support for inotify_init1()
Linux 2.6.27 added the inotify_init1() system call, a variant of inotify_init() with a flags parameter added. Generate a wrapper for this system call. Newer architectures support only inotify_init1(), so also add a inotify_init() implementation for them. Signed-off-by: Ben Hutchings <ben at decadent.org.uk> --- usr/include/sys/inotify.h | 1 + usr/klibc/Kbuild | 1 + usr/klibc/SYSCALLS.def | 1 + usr/klibc/inotify_init.c | 18 ++++++++++++++++++ 4 files changed, 21 insertions(+) create mode 100644 usr/klibc/inotify_init.c diff --git a/usr/include/sys/inotify.h b/usr/include/sys/inotify.h index e08cb055..256aa56e 100644 --- a/usr/include/sys/inotify.h +++ b/usr/include/sys/inotify.h @@ -10,6 +10,7 @@ #include <klibc/extern.h> __extern int inotify_init(void); +__extern int inotify_init1(int); __extern int inotify_add_watch(int, const char *, __u32); __extern int inotify_rm_watch(int, __u32); diff --git a/usr/klibc/Kbuild b/usr/klibc/Kbuild index b2a122aa..1add6a12 100644 --- a/usr/klibc/Kbuild +++ b/usr/klibc/Kbuild @@ -64,6 +64,7 @@ klib-y += vsnprintf.o snprintf.o vsprintf.o sprintf.o \ fstat.o fstatat.o lstat.o stat.o \ lchown.o link.o rmdir.o unlink.o mkdir.o \ readlink.o realpath.o select.o symlink.o pipe.o \ + inotify_init.o \ ctype/isalnum.o ctype/isalpha.o ctype/isascii.o \ ctype/isblank.o ctype/iscntrl.o ctype/isdigit.o \ ctype/isgraph.o ctype/islower.o ctype/isprint.o \ diff --git a/usr/klibc/SYSCALLS.def b/usr/klibc/SYSCALLS.def index d4a593af..ef29a8f8 100644 --- a/usr/klibc/SYSCALLS.def +++ b/usr/klibc/SYSCALLS.def @@ -148,6 +148,7 @@ 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); diff --git a/usr/klibc/inotify_init.c b/usr/klibc/inotify_init.c new file mode 100644 index 00000000..d9129bbb --- /dev/null +++ b/usr/klibc/inotify_init.c @@ -0,0 +1,18 @@ +/* + * inotify_init.c + * + * Some architectures need to wrap the system call + */ + +#include <unistd.h> +#include <sys/inotify.h> +#include <sys/syscall.h> + +#ifndef __NR_inotify_init + +int inotify_init(void) +{ + return inotify_init1(0); +} + +#endif -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: <https://lists.zytor.com/archives/klibc/attachments/20241002/865e9051/attachment.sig>