On Thu, Feb 01, 2007 at 02:45:09PM +0100, Bernhard Fischer wrote: >On Thu, Feb 01, 2007 at 01:31:18PM +0100, Joakim Tjernlund wrote: >>O >>> Well, do we -ENOSYS if something isn't available? >>> If so, then we should rather >>> #ifdef __NR_readahead >>> [snip current code] >>> #else >>> ssize_t readahead(int fd, off_t offset, size_t count) >>> { >>> __set_errno(ENOSYS); >>> return -1; >>> } >>> link_warning(readahead,"not available") >>> #endif >>> >>> Wondering if there should be a generic internal helper stub for >>> the ENOSYS;ret -1 case.. >> >>This can make cross compiling painful since you can't tell if >>readahead is present or not. >>On the other hand, a well behaved app will handle this dynamically ... > >Either way, behaviour should imho be consistent, and it is not, from a >quick grep for ENOSYS. Didn't really look, admittedly. > >Not stubbing unsupported functions out sounds smaller. Deciding what >route to take, either to stub them out or making them not available >isn't my call, though.
[replying to this old thread] So.. what do people think should be done in this respect? I'm attaching a proposal that allows for conveniently adding stubs by doing this: --- 8< --- #include <bits/syscall-stub.h> #define __SYSCALL_STUB __NR_pivot_root #include <sys/syscall.h> int pivot_root(const char *new_root, const char *put_old); _syscall2(int, pivot_root, const char *, new_root, const char *, put_old); --- 8< --- instead of manually providing a __set_errno(ENOSYS);return -1; stub It converts a few conditional syscalls to this proposed scheme as an example. This way we could even have a config-option that decides if there should be any stubs or none (not talking about alternative impls, they are of no interrest for now). Opinions?
Index: include/sys/syscall.h =================================================================== --- include/sys/syscall.h (revision 22022) +++ include/sys/syscall.h (working copy) @@ -31,6 +31,11 @@ #include <features.h> #include <bits/sysnum.h> #if defined _LIBC && (defined IS_IN_libc || defined NOT_IN_libc) +# if defined __SYSCALL_STUB && __SYSCALL_STUB + /* Syscall exists, no stub needed. */ +# undef __SYSCALL_STUB +# endif + # include <bits/syscalls.h> #endif Index: libc/sysdeps/linux/common/access.c =================================================================== --- libc/sysdeps/linux/common/access.c (revision 22022) +++ libc/sysdeps/linux/common/access.c (working copy) @@ -7,6 +7,8 @@ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. */ +#include <bits/syscall-stub.h> +#define __SYSCALL_STUB __NR_access #include <sys/syscall.h> #include <unistd.h> _syscall2(int, access, const char *, pathname, int, mode); Index: libc/sysdeps/linux/common/bdflush.c =================================================================== --- libc/sysdeps/linux/common/bdflush.c (revision 22022) +++ libc/sysdeps/linux/common/bdflush.c (working copy) @@ -7,15 +7,9 @@ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. */ +#include <bits/syscall-stub.h> +#define __SYSCALL_STUB __NR_bdflush #include <sys/syscall.h> #include <sys/kdaemon.h> -#ifdef __NR_bdflush _syscall2(int, bdflush, int, __func, long int, __data); -#else -int bdflush(int __func, long int __data) -{ - __set_errno(ENOSYS); - return -1; -} -#endif Index: libc/sysdeps/linux/common/capget.c =================================================================== --- libc/sysdeps/linux/common/capget.c (revision 22022) +++ libc/sysdeps/linux/common/capget.c (working copy) @@ -6,15 +6,9 @@ * * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. */ - +#include <bits/syscall-stub.h> +#define __SYSCALL_STUB __NR_capget #include <sys/syscall.h> + int capget(void *header, void *data); -#ifdef __NR_capget _syscall2(int, capget, void *, header, void *, data); -#else -int capget(void *header, void *data) -{ - __set_errno(ENOSYS); - return -1; -} -#endif Index: libc/sysdeps/linux/common/adjtimex.c =================================================================== --- libc/sysdeps/linux/common/adjtimex.c (revision 22022) +++ libc/sysdeps/linux/common/adjtimex.c (working copy) @@ -7,6 +7,8 @@ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. */ +#include <bits/syscall-stub.h> +#define __SYSCALL_STUB __NR_adjtimex #include <sys/syscall.h> #include <sys/timex.h> Index: libc/sysdeps/linux/common/capset.c =================================================================== --- libc/sysdeps/linux/common/capset.c (revision 22022) +++ libc/sysdeps/linux/common/capset.c (working copy) @@ -6,15 +6,9 @@ * * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. */ - +#include <bits/syscall-stub.h> +#define __SYSCALL_STUB __NR_capset #include <sys/syscall.h> + int capset(void *header, const void *data); -#ifdef __NR_capset _syscall2(int, capset, void *, header, const void *, data); -#else -int capset(void *header, const void *data) -{ - __set_errno(ENOSYS); - return -1; -} -#endif Index: libc/sysdeps/linux/common/delete_module.c =================================================================== --- libc/sysdeps/linux/common/delete_module.c (revision 22022) +++ libc/sysdeps/linux/common/delete_module.c (working copy) @@ -6,14 +6,9 @@ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. */ +#include <bits/syscall-stub.h> +#define __SYSCALL_STUB __NR_delete_module #include <sys/syscall.h> + int delete_module(const char *name); -#ifdef __NR_delete_module _syscall1(int, delete_module, const char *, name); -#else -int delete_module(const char *name) -{ - __set_errno(ENOSYS); - return -1; -} -#endif Index: libc/sysdeps/linux/common/pivot_root.c =================================================================== --- libc/sysdeps/linux/common/pivot_root.c (revision 22022) +++ libc/sysdeps/linux/common/pivot_root.c (working copy) @@ -7,15 +7,9 @@ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. */ +#include <bits/syscall-stub.h> +#define __SYSCALL_STUB __NR_pivot_root #include <sys/syscall.h> int pivot_root(const char *new_root, const char *put_old); -#ifdef __NR_pivot_root _syscall2(int, pivot_root, const char *, new_root, const char *, put_old); -#else -int pivot_root(const char *new_root, const char *put_old) -{ - __set_errno(ENOSYS); - return -1; -} -#endif Index: libc/sysdeps/linux/i386/bits/syscalls.h =================================================================== --- libc/sysdeps/linux/i386/bits/syscalls.h (revision 22022) +++ libc/sysdeps/linux/i386/bits/syscalls.h (working copy) @@ -12,8 +12,7 @@ #ifndef __ASSEMBLER__ #include <errno.h> - -#define SYS_ify(syscall_name) (__NR_##syscall_name) +#include <bits/syscall-stub.h> #define INTERNAL_SYSCALL_DECL(err) do { } while (0) @@ -106,35 +105,40 @@ __asm__ (".L__X'%ebx = 1\n\t" #define _syscall0(type,name) \ type name(void) \ { \ -return (type) (INLINE_SYSCALL(name, 0)); \ +EMIT_INLINE_SYSCALL(type) (INLINE_SYSCALL(name, 0)); \ } #undef _syscall1 #define _syscall1(type,name,type1,arg1) \ type name(type1 arg1) \ { \ -return (type) (INLINE_SYSCALL(name, 1, arg1)); \ +EMIT_INLINE_SYSCALL(type) (INLINE_SYSCALL(name, 1, arg1)); \ } + #undef _syscall2 +#define INLINE_SYSCALL2(name, arg1, arg2) \ +EMIT_INLINE_SYSCALL(type) (INLINE_SYSCALL(name, 2, arg1, arg2)); + #define _syscall2(type,name,type1,arg1,type2,arg2) \ type name(type1 arg1,type2 arg2) \ { \ -return (type) (INLINE_SYSCALL(name, 2, arg1, arg2)); \ +EMIT_INLINE_SYSCALL(type) (INLINE_SYSCALL(name, 2, arg1, arg2)); \ } + #undef _syscall3 #define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \ type name(type1 arg1,type2 arg2,type3 arg3) \ { \ -return (type) (INLINE_SYSCALL(name, 3, arg1, arg2, arg3)); \ +EMIT_INLINE_SYSCALL(type) (INLINE_SYSCALL(name, 3, arg1, arg2, arg3)); \ } #undef _syscall4 #define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \ type name (type1 arg1, type2 arg2, type3 arg3, type4 arg4) \ { \ -return (type) (INLINE_SYSCALL(name, 4, arg1, arg2, arg3, arg4)); \ +EMIT_INLINE_SYSCALL(type) (INLINE_SYSCALL(name, 4, arg1, arg2, arg3, arg4)); \ } #undef _syscall5 @@ -142,7 +146,7 @@ return (type) (INLINE_SYSCALL(name, 4, a type5,arg5) \ type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5) \ { \ -return (type) (INLINE_SYSCALL(name, 5, arg1, arg2, arg3, arg4, arg5)); \ +EMIT_INLINE_SYSCALL(type) (INLINE_SYSCALL(name, 5, arg1, arg2, arg3, arg4, arg5)); \ } #undef _syscall6 @@ -150,9 +154,13 @@ return (type) (INLINE_SYSCALL(name, 5, a type5,arg5,type6,arg6) \ type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5, type6 arg6) \ { \ -return (type) (INLINE_SYSCALL(name, 6, arg1, arg2, arg3, arg4, arg5, arg6)); \ +EMIT_INLINE_SYSCALL(type) (INLINE_SYSCALL(name, 6, arg1, arg2, arg3, arg4, arg5, arg6)); \ } - #define INLINE_SYSCALL(name, nr, args...) \ + +#if !defined __SYSCALL_STUB +#warning NO STUB +#define EMIT_INLINE_SYSCALL(type) return (type) +#define INLINE_SYSCALL(name, nr, args...) \ ({ \ unsigned int _resultvar = INTERNAL_SYSCALL (name, , nr, args); \ if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (_resultvar, ), 0)) \ @@ -161,6 +169,15 @@ return (type) (INLINE_SYSCALL(name, 6, a _resultvar = 0xffffffff; \ } \ (int) _resultvar; }) +#else +#warning do STUB +#define EMIT_INLINE_SYSCALL(type) +#define INLINE_SYSCALL(name, nr, args...) \ + ({ \ + __set_errno(ENOSYS); \ + return -1; \ + }) +#endif #define INTERNAL_SYSCALL(name, err, nr, args...) \ ({ \ Index: libc/sysdeps/linux/i386/bits/syscall-stub.h =================================================================== --- libc/sysdeps/linux/i386/bits/syscall-stub.h (revision 0) +++ libc/sysdeps/linux/i386/bits/syscall-stub.h (revision 0) @@ -0,0 +1,17 @@ +#ifndef __SYSCALL_STUB_H__ +#define __SYSCALL_STUB_H__ 1 + +#define SYS_ify(syscall_name) (__NR_##syscall_name) + +/* XXX: drop this! */ +#ifndef _SYSCALL_H +#define _SYSCALL_H 42 +#endif + +#include <bits/sysnum.h> + +#if _SYSCALL_H == 42 +#undef _SYSCALL_H +#endif + +#endif /* __SYSCALL_STUB_H__ */
_______________________________________________ uClibc mailing list uClibc@uclibc.org http://busybox.net/cgi-bin/mailman/listinfo/uclibc