diff options
Diffstat (limited to 'lib/libc')
-rw-r--r-- | lib/libc/gen/Makefile.inc | 3 | ||||
-rw-r--r-- | lib/libc/gen/__getosreldate.c | 61 | ||||
-rw-r--r-- | lib/libc/include/libc_private.h | 23 | ||||
-rw-r--r-- | lib/libc/sys/ftruncate.c | 6 | ||||
-rw-r--r-- | lib/libc/sys/lseek.c | 7 | ||||
-rw-r--r-- | lib/libc/sys/mmap.c | 8 | ||||
-rw-r--r-- | lib/libc/sys/pread.c | 7 | ||||
-rw-r--r-- | lib/libc/sys/pwrite.c | 6 | ||||
-rw-r--r-- | lib/libc/sys/truncate.c | 7 |
9 files changed, 119 insertions, 9 deletions
diff --git a/lib/libc/gen/Makefile.inc b/lib/libc/gen/Makefile.inc index 8881d80..c3f3940 100644 --- a/lib/libc/gen/Makefile.inc +++ b/lib/libc/gen/Makefile.inc @@ -4,7 +4,8 @@ # machine-independent gen sources .PATH: ${.CURDIR}/${MACHINE_ARCH}/gen ${.CURDIR}/gen -SRCS+= __xuname.c _pthread_stubs.c _rand48.c _spinlock_stub.c _thread_init.c \ +SRCS+= __getosreldate.c __xuname.c \ + _pthread_stubs.c _rand48.c _spinlock_stub.c _thread_init.c \ alarm.c arc4random.c assert.c basename.c check_utility_compat.c \ clock.c closedir.c confstr.c \ crypt.c ctermid.c daemon.c devname.c dirname.c disklabel.c \ diff --git a/lib/libc/gen/__getosreldate.c b/lib/libc/gen/__getosreldate.c new file mode 100644 index 0000000..69aac07 --- /dev/null +++ b/lib/libc/gen/__getosreldate.c @@ -0,0 +1,61 @@ +/*- + * Copyright (c) 2007 Peter Wemm + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <sys/param.h> +#include <sys/sysctl.h> + +/* + * This is private to libc. It is intended for wrapping syscall stubs in order + * to avoid having to put SIGSYS signal handlers in place to test for presence + * of new syscalls. This caches the result in order to be as quick as possible. + * + * Use getosreldate(3) for public use as it respects the $OSVERSION environment + * variable. + */ + +int +__getosreldate(void) +{ + static int osreldate; + size_t len; + int oid[2]; + int error, osrel; + + if (osreldate != 0) + return (osreldate); + + oid[0] = CTL_KERN; + oid[1] = KERN_OSRELDATE; + osrel = 0; + len = sizeof(osrel); + error = sysctl(oid, 2, &osrel, &len, NULL, 0); + if (error == 0 && osrel > 0 && len == sizeof(osrel)) + osreldate = osrel; + return (osreldate); +} diff --git a/lib/libc/include/libc_private.h b/lib/libc/include/libc_private.h index a8b53fe..de4bbe4 100644 --- a/lib/libc/include/libc_private.h +++ b/lib/libc/include/libc_private.h @@ -169,4 +169,27 @@ void _malloc_postfork(void); */ extern void (*__cleanup)(void); +/* + * Get kern.osreldate to detect ABI revisions. Explicitly + * ignores value of $OSVERSION and caches result. Prototypes + * for the wrapped "new" pad-less syscalls are here for now. + */ +extern int __getosreldate(void); +#include <sys/_types.h> +/* Without pad */ +extern __off_t __sys_lseek(int, __off_t, int); +extern int __sys_ftruncate(int, __off_t); +extern int __sys_truncate(const char *, __off_t); +extern __ssize_t __sys_pread(int, void *, __size_t, __off_t); +extern __ssize_t __sys_pwrite(int, const void *, __size_t, __off_t); +extern void * __sys_mmap(void *, __size_t, int, int, int, __off_t); + +/* With pad */ +extern __off_t __sys_freebsd6_lseek(int, int, __off_t, int); +extern int __sys_freebsd6_ftruncate(int, int, __off_t); +extern int __sys_freebsd6_truncate(const char *, int, __off_t); +extern __ssize_t __sys_freebsd6_pread(int, void *, __size_t, int, __off_t); +extern __ssize_t __sys_freebsd6_pwrite(int, const void *, __size_t, int, __off_t); +extern void * __sys_freebsd6_mmap(void *, __size_t, int, int, int, int, __off_t); + #endif /* _LIBC_PRIVATE_H_ */ diff --git a/lib/libc/sys/ftruncate.c b/lib/libc/sys/ftruncate.c index fcd2ef8..78b5a36 100644 --- a/lib/libc/sys/ftruncate.c +++ b/lib/libc/sys/ftruncate.c @@ -36,6 +36,7 @@ __FBSDID("$FreeBSD$"); #include <sys/types.h> #include <sys/syscall.h> #include <unistd.h> +#include "libc_private.h" /* * This function provides 64-bit offset padding that @@ -47,5 +48,8 @@ ftruncate(fd, length) off_t length; { - return(__syscall((quad_t)SYS_ftruncate, fd, 0, length)); + if (__getosreldate() >= 700051) + return(__sys_ftruncate(fd, length)); + else + return(__sys_freebsd6_ftruncate(fd, 0, length)); } diff --git a/lib/libc/sys/lseek.c b/lib/libc/sys/lseek.c index 8613678..a086be1 100644 --- a/lib/libc/sys/lseek.c +++ b/lib/libc/sys/lseek.c @@ -36,6 +36,7 @@ __FBSDID("$FreeBSD$"); #include <sys/types.h> #include <sys/syscall.h> #include <unistd.h> +#include "libc_private.h" /* * This function provides 64-bit offset padding that @@ -47,5 +48,9 @@ lseek(fd, offset, whence) off_t offset; int whence; { - return(__syscall((quad_t)SYS_lseek, fd, 0, offset, whence)); + + if (__getosreldate() >= 700051) + return(__sys_lseek(fd, offset, whence)); + else + return(__sys_freebsd6_lseek(fd, 0, offset, whence)); } diff --git a/lib/libc/sys/mmap.c b/lib/libc/sys/mmap.c index 8b22147..cfdb944 100644 --- a/lib/libc/sys/mmap.c +++ b/lib/libc/sys/mmap.c @@ -37,6 +37,7 @@ __FBSDID("$FreeBSD$"); #include <sys/mman.h> #include <sys/syscall.h> #include <unistd.h> +#include "libc_private.h" /* * This function provides 64-bit offset padding that @@ -52,6 +53,9 @@ mmap(addr, len, prot, flags, fd, offset) off_t offset; { - return ((void *)(intptr_t)__syscall((quad_t)SYS_mmap, addr, len, prot, - flags, fd, 0, offset)); + if (__getosreldate() >= 700051) + return (__sys_mmap(addr, len, prot, flags, fd, offset)); + else + + return (__sys_freebsd6_mmap(addr, len, prot, flags, fd, 0, offset)); } diff --git a/lib/libc/sys/pread.c b/lib/libc/sys/pread.c index 1d2fee6..7566566 100644 --- a/lib/libc/sys/pread.c +++ b/lib/libc/sys/pread.c @@ -36,6 +36,7 @@ __FBSDID("$FreeBSD$"); #include <sys/types.h> #include <sys/syscall.h> #include <unistd.h> +#include "libc_private.h" /* * This function provides 64-bit offset padding that @@ -48,5 +49,9 @@ pread(fd, buf, nbyte, offset) size_t nbyte; off_t offset; { - return ((ssize_t)__syscall((quad_t)SYS_pread, fd, buf, nbyte, 0, offset)); + + if (__getosreldate() >= 700051) + return (__sys_pread(fd, buf, nbyte, offset)); + else + return (__sys_freebsd6_pread(fd, buf, nbyte, 0, offset)); } diff --git a/lib/libc/sys/pwrite.c b/lib/libc/sys/pwrite.c index ebbb1ec..d17ed29 100644 --- a/lib/libc/sys/pwrite.c +++ b/lib/libc/sys/pwrite.c @@ -36,6 +36,7 @@ __FBSDID("$FreeBSD$"); #include <sys/types.h> #include <sys/syscall.h> #include <unistd.h> +#include "libc_private.h" /* * This function provides 64-bit offset padding that @@ -48,5 +49,8 @@ pwrite(fd, buf, nbyte, offset) size_t nbyte; off_t offset; { - return ((ssize_t)__syscall((quad_t)SYS_pwrite, fd, buf, nbyte, 0, offset)); + if (__getosreldate() >= 700051) + return (__sys_pwrite(fd, buf, nbyte, offset)); + else + return (__sys_freebsd6_pwrite(fd, buf, nbyte, 0, offset)); } diff --git a/lib/libc/sys/truncate.c b/lib/libc/sys/truncate.c index e26f3f5..375c9d9 100644 --- a/lib/libc/sys/truncate.c +++ b/lib/libc/sys/truncate.c @@ -35,8 +35,8 @@ __FBSDID("$FreeBSD$"); #include <sys/types.h> #include <sys/syscall.h> - #include <unistd.h> +#include "libc_private.h" /* * This function provides 64-bit offset padding that @@ -48,5 +48,8 @@ truncate(path, length) off_t length; { - return(__syscall((quad_t)SYS_truncate, path, 0, length)); + if (__getosreldate() >= 700051) + return(__sys_truncate(path, length)); + else + return(__sys_freebsd6_truncate(path, 0, length)); } |