diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2017-06-27 06:44:32 +0000 |
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2017-06-27 06:44:32 +0000 |
| commit | a3604b95ed1b025e84c6b948b9939cf63fc9f9ce (patch) | |
| tree | 6998e1bc3c80f5ac90fcd7497da4a1d547a8452e /lib/libc/sys | |
| parent | edd7eaddc8e5730ca33436568f6fcb8409984d13 (diff) | |
| parent | f21680fd983784341c88dbe1015548f65c79868d (diff) | |
Notes
Diffstat (limited to 'lib/libc/sys')
| -rw-r--r-- | lib/libc/sys/Makefile.inc | 11 | ||||
| -rw-r--r-- | lib/libc/sys/Symbol.map | 2 | ||||
| -rw-r--r-- | lib/libc/sys/compat-ino64.h | 102 | ||||
| -rw-r--r-- | lib/libc/sys/fstat.c | 54 | ||||
| -rw-r--r-- | lib/libc/sys/fstatat.c | 50 | ||||
| -rw-r--r-- | lib/libc/sys/fstatfs.c | 54 | ||||
| -rw-r--r-- | lib/libc/sys/getdents.c | 7 | ||||
| -rw-r--r-- | lib/libc/sys/getdirentries.c | 117 | ||||
| -rw-r--r-- | lib/libc/sys/getfsstat.c | 65 | ||||
| -rw-r--r-- | lib/libc/sys/kqueue.2 | 74 | ||||
| -rw-r--r-- | lib/libc/sys/lstat.c | 14 | ||||
| -rw-r--r-- | lib/libc/sys/mmap.2 | 47 | ||||
| -rw-r--r-- | lib/libc/sys/munmap.2 | 4 | ||||
| -rw-r--r-- | lib/libc/sys/pdfork.2 | 21 | ||||
| -rw-r--r-- | lib/libc/sys/stat.2 | 44 | ||||
| -rw-r--r-- | lib/libc/sys/stat.c | 14 | ||||
| -rw-r--r-- | lib/libc/sys/statfs.c | 50 | ||||
| -rw-r--r-- | lib/libc/sys/wait.2 | 6 |
18 files changed, 644 insertions, 92 deletions
diff --git a/lib/libc/sys/Makefile.inc b/lib/libc/sys/Makefile.inc index 9b9f718dbe2f..a5e7e04597d0 100644 --- a/lib/libc/sys/Makefile.inc +++ b/lib/libc/sys/Makefile.inc @@ -37,6 +37,14 @@ SRCS+= \ SRCS+= getdents.c lstat.c mknod.c stat.c +SRCS+= fstat.c fstatat.c fstatfs.c getfsstat.c statfs.c +NOASM+= fstat.o fstatat.o fstatfs.o getfsstat.o statfs.o +PSEUDO+= _fstat.o _fstatat.o _fstatfs.o _getfsstat.o _statfs.o + +SRCS+= getdirentries.c +NOASM+= getdirentries.o +PSEUDO+= _getdirentries.o + SRCS+= pipe.c INTERPOSED = \ @@ -421,8 +429,7 @@ MLINKS+=open.2 openat.2 MLINKS+=pathconf.2 fpathconf.2 MLINKS+=pathconf.2 lpathconf.2 MLINKS+=pdfork.2 pdgetpid.2\ - pdfork.2 pdkill.2 \ - pdfork.2 pdwait4.2 + pdfork.2 pdkill.2 MLINKS+=pipe.2 pipe2.2 MLINKS+=poll.2 ppoll.2 MLINKS+=rctl_add_rule.2 rctl_get_limits.2 \ diff --git a/lib/libc/sys/Symbol.map b/lib/libc/sys/Symbol.map index feccda6f6bf4..4411cfe968cd 100644 --- a/lib/libc/sys/Symbol.map +++ b/lib/libc/sys/Symbol.map @@ -121,7 +121,6 @@ FBSD_1.0 { jail; jail_attach; kenv; - kevent; kill; kldfind; kldfirstmod; @@ -393,6 +392,7 @@ FBSD_1.5 { getdents; getdirentries; getfsstat; + kevent; lstat; mknod; mknodat; diff --git a/lib/libc/sys/compat-ino64.h b/lib/libc/sys/compat-ino64.h new file mode 100644 index 000000000000..dde741e4f089 --- /dev/null +++ b/lib/libc/sys/compat-ino64.h @@ -0,0 +1,102 @@ +/*- + * Copyright (c) 2017 M. Warner Losh <imp@FreeBSD.org> + * 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. + * + * $FreeBSD$ + */ + +/* + * Forward compatibility shim to convert old stat buffer to + * new so we can call the old system call, but return data in + * the new system call's format. + */ +#define _WANT_FREEBSD11_STATFS +#include <sys/fcntl.h> +#include <sys/mount.h> + +#define _WANT_FREEBSD11_STAT +#include <sys/stat.h> + +#include <string.h> + +#define INO64_FIRST 1200031 + +static __inline void +__stat11_to_stat(const struct freebsd11_stat *sb11, struct stat *sb) +{ + + sb->st_dev = sb11->st_dev; + sb->st_ino = sb11->st_ino; + sb->st_nlink = sb11->st_nlink; + sb->st_mode = sb11->st_mode; + sb->st_uid = sb11->st_uid; + sb->st_gid = sb11->st_gid; + sb->st_rdev = sb11->st_rdev; + sb->st_atim = sb11->st_atim; + sb->st_mtim = sb11->st_mtim; + sb->st_ctim = sb11->st_ctim; +#ifdef __STAT_TIME_T_EXT + sb->st_atim_ext = 0; + sb->st_mtim_ext = 0; + sb->st_ctim_ext = 0; + sb->st_btim_ext = 0; +#endif + sb->st_birthtim = sb11->st_birthtim; + sb->st_size = sb11->st_size; + sb->st_blocks = sb11->st_blocks; + sb->st_blksize = sb11->st_blksize; + sb->st_flags = sb11->st_flags; + sb->st_gen = sb11->st_gen; + sb->st_padding0 = 0; + sb->st_padding1 = 0; + memset(sb->st_spare, 0, sizeof(sb->st_spare)); +} + +static __inline void +__statfs11_to_statfs(const struct freebsd11_statfs *sf11, struct statfs *sf) +{ + + sf->f_version = STATFS_VERSION; + sf->f_type = sf11->f_type; + sf->f_flags = sf11->f_flags; + sf->f_bsize = sf11->f_bsize; + sf->f_iosize = sf11->f_iosize; + sf->f_blocks = sf11->f_blocks; + sf->f_bfree = sf11->f_bfree; + sf->f_bavail = sf11->f_bavail; + sf->f_files = sf11->f_files; + sf->f_ffree = sf11->f_ffree; + sf->f_syncwrites = sf11->f_syncwrites; + sf->f_asyncwrites = sf11->f_asyncwrites; + sf->f_syncreads = sf11->f_syncreads; + sf->f_asyncreads = sf11->f_asyncreads; + sf->f_namemax = sf11->f_namemax; + sf->f_owner = sf11->f_owner; + sf->f_fsid = sf11->f_fsid; + memset(sf->f_spare, 0, sizeof(sf->f_spare)); + memset(sf->f_charspare, 0, sizeof(sf->f_charspare)); + strlcpy(sf->f_fstypename, sf11->f_fstypename, sizeof(sf->f_fstypename)); + strlcpy(sf->f_mntfromname, sf11->f_mntfromname, sizeof(sf->f_mntfromname)); + strlcpy(sf->f_mntonname, sf11->f_mntonname, sizeof(sf->f_mntonname)); +} diff --git a/lib/libc/sys/fstat.c b/lib/libc/sys/fstat.c new file mode 100644 index 000000000000..a57a8aad52a2 --- /dev/null +++ b/lib/libc/sys/fstat.c @@ -0,0 +1,54 @@ +/*- + * Copyright (c) 2017 M. Warner Losh <imp@FreeBSD.org> + * 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 "namespace.h" +#include <sys/param.h> +#include <sys/syscall.h> +#include "compat-ino64.h" +#include <unistd.h> + +#include "libc_private.h" + +#undef fstat +__weak_reference(_fstat, fstat); + +#pragma weak _fstat +int +_fstat(int fd, struct stat *sb) +{ + struct freebsd11_stat stat11; + int rv; + + if (__getosreldate() >= INO64_FIRST) + return (__sys_fstat(fd, sb)); + rv = syscall(SYS_freebsd11_fstat, fd, &stat11); + if (rv == 0) + __stat11_to_stat(&stat11, sb); + return (rv); +} diff --git a/lib/libc/sys/fstatat.c b/lib/libc/sys/fstatat.c new file mode 100644 index 000000000000..5e6edccdb97d --- /dev/null +++ b/lib/libc/sys/fstatat.c @@ -0,0 +1,50 @@ +/*- + * Copyright (c) 2017 M. Warner Losh <imp@FreeBSD.org> + * 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 "namespace.h" +#include <sys/param.h> +#include <sys/syscall.h> +#include "compat-ino64.h" +#include <unistd.h> + +#include "libc_private.h" + +int +fstatat(int fd, const char *path, struct stat *sb, int flag) +{ + struct freebsd11_stat stat11; + int rv; + + if (__getosreldate() >= INO64_FIRST) + return (__sys_fstatat(fd, path, sb, flag)); + rv = syscall(SYS_freebsd11_fstatat, fd, path, &stat11, flag); + if (rv == 0) + __stat11_to_stat(&stat11, sb); + return (rv); +} diff --git a/lib/libc/sys/fstatfs.c b/lib/libc/sys/fstatfs.c new file mode 100644 index 000000000000..71ee12dc0bfb --- /dev/null +++ b/lib/libc/sys/fstatfs.c @@ -0,0 +1,54 @@ +/*- + * Copyright (c) 2017 M. Warner Losh <imp@FreeBSD.org> + * 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 "namespace.h" +#include <sys/param.h> +#include <sys/syscall.h> +#include "compat-ino64.h" +#include <unistd.h> + +#include "libc_private.h" + +#undef fstatfs +__weak_reference(_fstatfs, fstatfs); + +#pragma weak _fstatfs +int +_fstatfs(int fd, struct statfs *buf) +{ + struct freebsd11_statfs statfs11; + int rv; + + if (__getosreldate() >= INO64_FIRST) + return (__sys_fstatfs(fd, buf)); + rv = syscall(SYS_freebsd11_fstatfs, fd, &statfs11); + if (rv == 0) + __statfs11_to_statfs(&statfs11, buf); + return (rv); +} diff --git a/lib/libc/sys/getdents.c b/lib/libc/sys/getdents.c index c8a2878c972f..480fbf265fb9 100644 --- a/lib/libc/sys/getdents.c +++ b/lib/libc/sys/getdents.c @@ -36,6 +36,11 @@ __FBSDID("$FreeBSD$"); ssize_t getdents(int fd, char *buf, size_t nbytes) { + /* + * _getdirentries knows how to call the right thing and + * return it in the new format. It assumes that the entire + * libc expecting the new format. + */ - return (__sys_getdirentries(fd, buf, nbytes, NULL)); + return (_getdirentries(fd, buf, nbytes, NULL)); } diff --git a/lib/libc/sys/getdirentries.c b/lib/libc/sys/getdirentries.c new file mode 100644 index 000000000000..469e6d26d790 --- /dev/null +++ b/lib/libc/sys/getdirentries.c @@ -0,0 +1,117 @@ +/*- + * Copyright (c) 2017 M. Warner Losh <imp@FreeBSD.org> + * 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$"); + +#define _WANT_FREEBSD11_DIRENT + +#include "namespace.h" +#include <sys/param.h> +#include <sys/syscall.h> +#include "compat-ino64.h" +#include <dirent.h> +#include <errno.h> +#include <stddef.h> +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <unistd.h> +#include "libc_private.h" + +static ssize_t +__cvt_dirents_from11(const char *de11, ssize_t len11, char *de, ssize_t len) +{ + struct dirent *dst; + const struct freebsd11_dirent *src; + const char *edst, *esrc; + ssize_t rlen; + + src = (const struct freebsd11_dirent *)de11; + dst = (struct dirent *)de; + esrc = de11 + len11; + edst = de + len; + while ((const char *)src < esrc && (const char *)dst < edst) { + rlen = roundup(offsetof(struct dirent, d_name) + src->d_namlen + 1, 8); + if ((const char *)dst + rlen >= edst) + break; + dst->d_fileno = src->d_fileno; + dst->d_off = 0; /* nothing uses it yet, so safe for now */ + dst->d_reclen = rlen; + dst->d_type = src->d_type; + dst->d_pad0 = 0; + dst->d_namlen = src->d_namlen; + dst->d_pad1 = 0; + memset(dst->d_name, 0, roundup(src->d_namlen + 1, 8)); + memcpy(dst->d_name, src->d_name, src->d_namlen); + dst = (struct dirent *)((char *)dst + rlen); + src = (const struct freebsd11_dirent *)((const char *)src + src->d_reclen); + } + return ((char *)dst - de); +} + +#undef getdirentries +__weak_reference(_getdirentries, getdirentries); + +#pragma weak _getdirentries +ssize_t +_getdirentries(int fd, char *buf, size_t nbytes, off_t *basep) +{ + char *oldbuf; + size_t len; + ssize_t rv; + + if (__getosreldate() >= INO64_FIRST) + return (__sys_getdirentries(fd, buf, nbytes, basep)); + + /* + * Because the old system call returns entries that are smaller than the + * new, we could wind up in a situation where we have too many to fit in + * the buffer with the new encoding. So sacrifice a small bit of + * efficiency to ensure that never happens. We pick 1/4 the size round + * up to the next DIRBLKSIZ. This will guarnatee enough room exists in + * the dst buffer due to changes in efficiency in packing dirent + * entries. We don't check against minimum block size to avoid a lot of + * stat calls, we'll see if that's wise or not. + * TBD: Will this difference matter to lseek? + */ + len = roundup(nbytes / 4, DIRBLKSIZ); + oldbuf = malloc(len); + if (oldbuf == NULL) { + errno = EINVAL; /* ENOMEM not in possible list */ + return (-1); + } + rv = syscall(SYS_freebsd11_getdirentries, fd, oldbuf, len, basep); + if (rv == -1) { + free(oldbuf); + return (rv); + } + if (rv > 0) + rv = __cvt_dirents_from11(oldbuf, rv, buf, nbytes); + free(oldbuf); + + return (rv); +} diff --git a/lib/libc/sys/getfsstat.c b/lib/libc/sys/getfsstat.c new file mode 100644 index 000000000000..ca81f3e9fd52 --- /dev/null +++ b/lib/libc/sys/getfsstat.c @@ -0,0 +1,65 @@ +/*- + * Copyright (c) 2017 M. Warner Losh <imp@FreeBSD.org> + * 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 "namespace.h" +#include <sys/param.h> +#include "compat-ino64.h" +#include <sys/errno.h> +#include <sys/syscall.h> +#include <stdlib.h> +#include <unistd.h> + +#include "libc_private.h" + +int +getfsstat(struct statfs *buf, long bufsize, int flags) +{ + struct freebsd11_statfs *statfs11 = NULL; + ssize_t len = 0; + int rv, i; + + if (__getosreldate() >= INO64_FIRST) + return (__sys_getfsstat(buf, bufsize, flags)); + if (buf != NULL) { + len = sizeof(struct freebsd11_statfs) * /* Round down on purpose to avoid */ + (bufsize / sizeof(struct statfs)); /* overflow on translation. */ + statfs11 = malloc(len); + if (statfs11 == NULL) { + errno = ENOMEM; + return (-1); + } + } + rv = syscall(SYS_freebsd11_getfsstat, statfs11, len, flags); + if (rv != -1 && buf != NULL) { + for (i = 0; i < rv; i++) + __statfs11_to_statfs(&statfs11[i], &buf[i]); + } + free(statfs11); + return (rv); +} diff --git a/lib/libc/sys/kqueue.2 b/lib/libc/sys/kqueue.2 index e7bca7231690..6630ae3db688 100644 --- a/lib/libc/sys/kqueue.2 +++ b/lib/libc/sys/kqueue.2 @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd April 18, 2017 +.Dd June 22, 2017 .Dt KQUEUE 2 .Os .Sh NAME @@ -148,12 +148,13 @@ The structure is defined as: .Bd -literal struct kevent { - uintptr_t ident; /* identifier for this event */ + uintptr_t ident; /* identifier for this event */ short filter; /* filter for event */ u_short flags; /* action flags for kqueue */ u_int fflags; /* filter flag value */ - intptr_t data; /* filter data value */ + int64_t data; /* filter data value */ void *udata; /* opaque user data identifier */ + uint64_t ext[4]; /* extentions */ }; .Ed .Pp @@ -177,6 +178,20 @@ Filter-specific flags. Filter-specific data value. .It Fa udata Opaque user-defined value passed through the kernel unchanged. +.It Fa ext +Extended data passed to and from kernel. +The +.Fa ext[0] +and +.Fa ext[1] +members use is defined by the filter. +If the filter does not use them, the members are copied unchanged. +The +.Fa ext[2] +and +.Fa ext[3] +members are always passed throught the kernel as-is, +making additional context available to application. .El .Pp The @@ -336,33 +351,18 @@ case. Takes a descriptor as the identifier, and returns whenever there is no remaining data in the write buffer. .It Dv EVFILT_AIO -The sigevent portion of the AIO request is filled in, with -.Va sigev_notify_kqueue -containing the descriptor of the kqueue that the event should -be attached to, -.Va sigev_notify_kevent_flags -containing the kevent flags which should be -.Dv EV_ONESHOT , -.Dv EV_CLEAR -or -.Dv EV_DISPATCH , -.Va sigev_value -containing the udata value, and -.Va sigev_notify -set to -.Dv SIGEV_KEVENT . -When the -.Fn aio_* -system call is made, the event will be registered -with the specified kqueue, and the -.Va ident -argument set to the -.Fa struct aiocb -returned by the -.Fn aio_* -system call. +Events for this filter are not registered with +.Fn kevent +directly but are registered via the +.Va aio_sigevent +member of an asychronous I/O request when it is scheduled via an asychronous I/O +system call such as +.Fn aio_read . The filter returns under the same conditions as .Fn aio_error . +For more details on this filter see +.Xr sigevent 3 and +.Xr aio 4 . .It Dv EVFILT_VNODE Takes a file descriptor as the identifier and the events to watch for in .Va fflags , @@ -515,16 +515,26 @@ Establishes an arbitrary timer identified by .Va ident . When adding a timer, .Va data -specifies the timeout period. +specifies the moment to fire the timer (for +.Dv NOTE_ABSTIME ) +or the timeout period. The timer will be periodic unless .Dv EV_ONESHOT +or +.Dv NOTE_ABSTIME is specified. On return, .Va data contains the number of times the timeout has expired since the last call to .Fn kevent . -This filter automatically sets the EV_CLEAR flag internally. -.Bl -tag -width "Dv NOTE_USECONDS" +For non-monotonic timers, this filter automatically sets the +.Dv EV_CLEAR +flag internally. +.Pp +The filter accepts the following flags in the +.Va fflags +argument: +.Bl -tag -width "Dv NOTE_MSECONDS" .It Dv NOTE_SECONDS .Va data is in seconds. @@ -537,6 +547,8 @@ is in microseconds. .It Dv NOTE_NSECONDS .Va data is in nanoseconds. +.It Dv NOTE_ABSTIME +The specified expiration time is absolute. .El .Pp If diff --git a/lib/libc/sys/lstat.c b/lib/libc/sys/lstat.c index ccc73e3d3d06..d639a42d3dd0 100644 --- a/lib/libc/sys/lstat.c +++ b/lib/libc/sys/lstat.c @@ -1,4 +1,5 @@ /*- + * Copyright (c) 2017 M. Warner Losh <imp@FreeBSD.org> * Copyright (c) 2012 Gleb Kurtsou <gleb@FreeBSD.org> * All rights reserved. * @@ -29,15 +30,22 @@ __FBSDID("$FreeBSD$"); #include "namespace.h" #include <sys/param.h> -#include <sys/fcntl.h> #include <sys/syscall.h> -#include <sys/stat.h> +#include "compat-ino64.h" #include <unistd.h> + #include "libc_private.h" int lstat(const char *path, struct stat *sb) { + struct freebsd11_stat stat11; + int rv; - return (__sys_fstatat(AT_FDCWD, path, sb, AT_SYMLINK_NOFOLLOW)); + if (__getosreldate() >= INO64_FIRST) + return (__sys_fstatat(AT_FDCWD, path, sb, AT_SYMLINK_NOFOLLOW)); + rv = syscall(SYS_freebsd11_lstat, path, &stat11); + if (rv == 0) + __stat11_to_stat(&stat11, sb); + return (rv); } diff --git a/lib/libc/sys/mmap.2 b/lib/libc/sys/mmap.2 index e36f804c587b..b7704a2351c0 100644 --- a/lib/libc/sys/mmap.2 +++ b/lib/libc/sys/mmap.2 @@ -28,7 +28,7 @@ .\" @(#)mmap.2 8.4 (Berkeley) 5/11/95 .\" $FreeBSD$ .\" -.Dd February 4, 2017 +.Dd June 22, 2017 .Dt MMAP 2 .Os .Sh NAME @@ -69,7 +69,7 @@ current) offsets in the object. In particular, the .Fa offset value cannot be negative. -If the object is truncated and the process later accesses a pages that +If the object is truncated and the process later accesses a page that is wholly within the truncated region, the access is aborted and a .Dv SIGBUS signal is delivered to the process. @@ -199,9 +199,21 @@ In contrast, if .Dv MAP_EXCL is specified, the request will fail if a mapping already exists within the range. -.It Dv MAP_HASSEMAPHORE -Notify the kernel that the region may contain semaphores and that special -handling may be necessary. +.It Dv MAP_GUARD +Instead of a mapping, create a guard of the specified size. +Guards allow a process to create reservations in its address space, +which can later be replaced by actual mappings. +.Pp +.Fa mmap +will not create mappings in the address range of a guard unless +the request specifies +.Dv MAP_FIXED . +Guards can be destroyed with +.Xr munmap 2 . +Any memory access by a thread to the guarded range results +in the delivery of a +.Dv SIGSEGV +signal to that thread. .It Dv MAP_NOCORE Region is not included in a core file. .It Dv MAP_NOSYNC @@ -306,6 +318,7 @@ must include at least .Dv PROT_READ and .Dv PROT_WRITE . +.Pp This option creates a memory region that grows to at most .Fa len @@ -316,6 +329,10 @@ stack top is the starting address returned by the call, plus bytes. The bottom of the stack at maximum growth is the starting address returned by the call. +The system uses guards to prevent the inadvertent use of +regions into which stacks created with +.Dv MAP_STACK +will automatically grow, without mapping the whole stack in advance. .El .Pp The @@ -409,6 +426,7 @@ were specified. .It Bq Er EINVAL None of .Dv MAP_ANON , +.Dv MAP_GUARD , .Dv MAP_PRIVATE , .Dv MAP_SHARED , or @@ -458,6 +476,25 @@ were specified, but the requested region is already used by a mapping. was specified, but .Dv MAP_FIXED was not. +.It Bq Er EINVAL +.Dv MAP_GUARD +was specified, but the +.Fa offset +argument was not zero, the +.Fa fd +argument was not -1, or the +.Fa prot +argument was not +.Dv PROT_NONE . +.It Bq Er EINVAL +.Dv MAP_GUARD +was specified together with one of the flags +.Dv MAP_ANON , +.Dv MAP_PREFAULT , +.Dv MAP_PREFAULT_READ , +.Dv MAP_PRIVATE , +.Dv MAP_SHARED , +.Dv MAP_STACK . .It Bq Er ENODEV .Dv MAP_ANON has not been specified and diff --git a/lib/libc/sys/munmap.2 b/lib/libc/sys/munmap.2 index 8fa539550fbe..d050db0f3fac 100644 --- a/lib/libc/sys/munmap.2 +++ b/lib/libc/sys/munmap.2 @@ -28,7 +28,7 @@ .\" @(#)munmap.2 8.3 (Berkeley) 5/27/94 .\" $FreeBSD$ .\" -.Dd May 27, 1994 +.Dd June 22, 2017 .Dt MUNMAP 2 .Os .Sh NAME @@ -44,7 +44,7 @@ The .Fn munmap system call -deletes the mappings for the specified address range, +deletes the mappings and guards for the specified address range, and causes further references to addresses within the range to generate invalid memory references. .Sh RETURN VALUES diff --git a/lib/libc/sys/pdfork.2 b/lib/libc/sys/pdfork.2 index 5f1a86e3b961..ab1a73dc9ce1 100644 --- a/lib/libc/sys/pdfork.2 +++ b/lib/libc/sys/pdfork.2 @@ -32,14 +32,13 @@ .\" .\" $FreeBSD$ .\" -.Dd June 8, 2016 +.Dd June 17, 2017 .Dt PDFORK 2 .Os .Sh NAME .Nm pdfork , .Nm pdgetpid , -.Nm pdkill , -.Nm pdwait4 +.Nm pdkill .Nd System calls to manage process descriptors .Sh LIBRARY .Lb libc @@ -51,8 +50,6 @@ .Fn pdgetpid "int fd" "pid_t *pidp" .Ft int .Fn pdkill "int fd" "int signum" -.Ft int -.Fn pdwait4 "int fd" "int *status" "int options" "struct rusage *rusage" .Sh DESCRIPTION Process descriptors are special file descriptors that represent processes, and are created using @@ -96,11 +93,6 @@ except that it accepts a process descriptor, .Fa fd , rather than a PID. .Pp -.Fn pdwait4 -behaves identically to -.Xr wait4 2 , -but operates with respect to a process descriptor argument rather than a PID. -.Pp The following system calls also have effects specific to process descriptors: .Pp .Xr fstat 2 @@ -146,9 +138,6 @@ does. and .Fn pdkill return 0 on success and -1 on failure. -.Pp -.Fn pdwait4 -returns a PID on success and -1 on failure. .Sh ERRORS These functions may return the same error numbers as their PID-based equivalents (e.g. @@ -180,9 +169,8 @@ for The .Fn pdfork , .Fn pdgetpid , -.Fn pdkill and -.Fn pdwait4 +.Fn pdkill system calls first appeared in .Fx 9.0 . .Pp @@ -197,6 +185,3 @@ and .An Jonathan Anderson Aq Mt jonathan@FreeBSD.org at the University of Cambridge Computer Laboratory with support from a grant from Google, Inc. -.Sh BUGS -.Fn pdwait4 -has not yet been implemented. diff --git a/lib/libc/sys/stat.2 b/lib/libc/sys/stat.2 index e706a408275d..8256ebc23cd0 100644 --- a/lib/libc/sys/stat.2 +++ b/lib/libc/sys/stat.2 @@ -28,7 +28,7 @@ .\" @(#)stat.2 8.4 (Berkeley) 5/1/95 .\" $FreeBSD$ .\" -.Dd January 14, 2016 +.Dd June 23, 2017 .Dt STAT 2 .Os .Sh NAME @@ -62,7 +62,7 @@ The .Fn lstat system call is like .Fn stat -except in the case where the named file is a symbolic link, +except when the named file is a symbolic link, in which case .Fn lstat returns information about the link, @@ -82,7 +82,7 @@ system call is equivalent to .Fn stat and .Fn lstat -except in the case where the +except when the .Fa path specifies a relative path. In this case the status is retrieved from a file relative to @@ -92,7 +92,7 @@ instead of the current working directory. .Pp The values for the .Fa flag -are constructed by a bitwise-inclusive OR of flags from the following list, +are constructed by a bitwise-inclusive OR of flags from this list, defined in .In fcntl.h : .Bl -tag -width indent @@ -129,16 +129,16 @@ and into which information is placed concerning the file. .Pp The fields of .Vt "struct stat" -related to the file system are as follows: +related to the file system are: .Bl -tag -width ".Va st_nlink" .It Va st_dev -The numeric ID of the device containing the file. +Numeric ID of the device containing the file. .It Va st_ino The file's inode number. .It Va st_nlink -The number of hard links to the file. +Number of hard links to the file. .It Va st_flags -The flags enabled for the file. +Flags enabled for the file. See .Xr chflags 2 for the list of flags and their description. @@ -152,10 +152,10 @@ fields together identify the file uniquely within the system. .Pp The time-related fields of .Vt "struct stat" -are as follows: +are: .Bl -tag -width ".Va st_birthtim" .It Va st_atim -Time when file data last accessed. +Time when file data was last accessed. Changed by the .Xr mknod 2 , .Xr utimes 2 , @@ -164,7 +164,7 @@ and .Xr readv 2 system calls. .It Va st_mtim -Time when file data last modified. +Time when file data was last modified. Changed by the .Xr mkdir 2 , .Xr mkfifo 2 , @@ -199,7 +199,7 @@ system calls. Time when the inode was created. .El .Pp -The following time-related macros are defined for compatibility: +These time-related macros are defined for compatibility: .Bd -literal #define st_atime st_atim.tv_sec #define st_mtime st_mtim.tv_sec @@ -216,35 +216,35 @@ The following time-related macros are defined for compatibility: #endif .Ed .Pp -The size-related fields of the +Size-related fields of the .Vt "struct stat" -are as follows: +are: .Bl -tag -width ".Va st_blksize" .It Va st_size -The file size in bytes. +File size in bytes. .It Va st_blksize -The optimal I/O block size for the file. +Optimal I/O block size for the file. .It Va st_blocks -The actual number of blocks allocated for the file in 512-byte units. +Actual number of blocks allocated for the file in 512-byte units. As short symbolic links are stored in the inode, this number may be zero. .El .Pp The access-related fields of .Vt "struct stat" -are as follows: +are: .Bl -tag -width ".Va st_mode" .It Va st_uid -The user ID of the file's owner. +User ID of the file's owner. .It Va st_gid -The group ID of the file. +Group ID of the file. .It Va st_mode Status of the file (see below). .El .Pp The status information word .Fa st_mode -has the following bits: +has these bits: .Bd -literal #define S_IFMT 0170000 /* type of file mask */ #define S_IFIFO 0010000 /* named pipe (fifo) */ @@ -277,7 +277,7 @@ For a list of access modes, see .Xr access 2 and .Xr chmod 2 . -The following macros are available to test whether a +These macros are available to test whether a .Va st_mode value passed in the .Fa m diff --git a/lib/libc/sys/stat.c b/lib/libc/sys/stat.c index 6b58daa9e515..a7ed7baf5c2f 100644 --- a/lib/libc/sys/stat.c +++ b/lib/libc/sys/stat.c @@ -1,4 +1,5 @@ /*- + * Copyright (c) 2017 M. Warner Losh <imp@FreeBSD.org> * Copyright (c) 2012 Gleb Kurtsou <gleb@FreeBSD.org> * All rights reserved. * @@ -29,15 +30,22 @@ __FBSDID("$FreeBSD$"); #include "namespace.h" #include <sys/param.h> -#include <sys/fcntl.h> #include <sys/syscall.h> -#include <sys/stat.h> +#include "compat-ino64.h" #include <unistd.h> + #include "libc_private.h" int stat(const char *path, struct stat *sb) { + struct freebsd11_stat stat11; + int rv; - return (__sys_fstatat(AT_FDCWD, path, sb, 0)); + if (__getosreldate() >= INO64_FIRST) + return (__sys_fstatat(AT_FDCWD, path, sb, 0)); + rv = syscall(SYS_freebsd11_stat, path, &stat11); + if (rv == 0) + __stat11_to_stat(&stat11, sb); + return (rv); } diff --git a/lib/libc/sys/statfs.c b/lib/libc/sys/statfs.c new file mode 100644 index 000000000000..63774e999d92 --- /dev/null +++ b/lib/libc/sys/statfs.c @@ -0,0 +1,50 @@ +/*- + * Copyright (c) 2017 M. Warner Losh <imp@FreeBSD.org> + * 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 "namespace.h" +#include <sys/param.h> +#include <sys/syscall.h> +#include "compat-ino64.h" +#include <unistd.h> + +#include "libc_private.h" + +int +statfs(const char *path, struct statfs *buf) +{ + struct freebsd11_statfs statfs11; + int rv; + + if (__getosreldate() >= INO64_FIRST) + return (__sys_statfs(path, buf)); + rv = syscall(SYS_freebsd11_statfs, path, &statfs11); + if (rv == 0) + __statfs11_to_statfs(&statfs11, buf); + return (rv); +} diff --git a/lib/libc/sys/wait.2 b/lib/libc/sys/wait.2 index c34743290451..49cbc269d326 100644 --- a/lib/libc/sys/wait.2 +++ b/lib/libc/sys/wait.2 @@ -28,7 +28,7 @@ .\" @(#)wait.2 8.2 (Berkeley) 4/19/94 .\" $FreeBSD$ .\" -.Dd June 1, 2016 +.Dd June 17, 2017 .Dt WAIT 2 .Os .Sh NAME @@ -601,9 +601,7 @@ must be checked against zero to determine if a process reported status. called with -1 to wait for any child process will ignore a child that is referenced by a process descriptor (see .Xr pdfork 2 ) . -Specific processes can still be waited on by specifying the process ID -or descriptor (see -.Xr pdwait 4 ) . +Specific processes can still be waited on by specifying the process ID. .Sh ERRORS The .Fn wait |
