diff options
| author | Baptiste Daroussin <bapt@FreeBSD.org> | 2015-09-12 12:03:02 +0000 |
|---|---|---|
| committer | Baptiste Daroussin <bapt@FreeBSD.org> | 2015-09-12 12:03:02 +0000 |
| commit | f94594b37a145b9b3e9ff31af2cd1dc3de8aa4d4 (patch) | |
| tree | 38501bd60c958b3b5474368fc0834fe6d09c307a /lib | |
| parent | b779ff2b9c12b92001cff75c2047f6a32c0beb48 (diff) | |
| parent | d36c6176161e31d945d8adbb2aae1ccffb632bd7 (diff) | |
Notes
Diffstat (limited to 'lib')
112 files changed, 2327 insertions, 899 deletions
diff --git a/lib/Makefile b/lib/Makefile index d17cb5d25cd17..031c1b46bde69 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -182,7 +182,7 @@ _clang= clang _cuse= libcuse .endif -.if ${MK_ELFTOOLCHAIN_TOOLS} != "no" +.if ${MK_TOOLCHAIN} != "no" _libelftc= libelftc .endif diff --git a/lib/libarchive/test/Makefile b/lib/libarchive/test/Makefile index 80d6dd4a03ff5..e57c5ff29e692 100644 --- a/lib/libarchive/test/Makefile +++ b/lib/libarchive/test/Makefile @@ -120,6 +120,7 @@ TESTS= \ test_read_format_gtar_gz.c \ test_read_format_gtar_lzma.c \ test_read_format_gtar_sparse.c \ + test_read_format_gtar_sparse_skip_entry.c \ test_read_format_iso_Z.c \ test_read_format_iso_multi_extent.c \ test_read_format_iso_xorriso.c \ diff --git a/lib/libc/Makefile b/lib/libc/Makefile index b6d3f9f96a3b8..2f8865c16a059 100644 --- a/lib/libc/Makefile +++ b/lib/libc/Makefile @@ -95,6 +95,7 @@ NOASM= .include "${LIBC_SRCTOP}/stdtime/Makefile.inc" .include "${LIBC_SRCTOP}/string/Makefile.inc" .include "${LIBC_SRCTOP}/sys/Makefile.inc" +.include "${LIBC_SRCTOP}/secure/Makefile.inc" .include "${LIBC_SRCTOP}/rpc/Makefile.inc" .include "${LIBC_SRCTOP}/uuid/Makefile.inc" .include "${LIBC_SRCTOP}/xdr/Makefile.inc" diff --git a/lib/libc/aarch64/Symbol.map b/lib/libc/aarch64/Symbol.map index e47056a9d7a34..84c38d8dac680 100644 --- a/lib/libc/aarch64/Symbol.map +++ b/lib/libc/aarch64/Symbol.map @@ -17,6 +17,8 @@ FBSD_1.0 { __flt_rounds; fpgetmask; fpsetmask; + __infinity; + __nan; setjmp; longjmp; sigsetjmp; diff --git a/lib/libc/aarch64/gen/Makefile.inc b/lib/libc/aarch64/gen/Makefile.inc index 2ccc8340abb2c..f13800829d7fc 100644 --- a/lib/libc/aarch64/gen/Makefile.inc +++ b/lib/libc/aarch64/gen/Makefile.inc @@ -5,6 +5,7 @@ SRCS+= _ctx_start.S \ flt_rounds.c \ fpgetmask.c \ fpsetmask.c \ + infinity.c \ ldexp.c \ makecontext.c \ _setjmp.S \ diff --git a/lib/libc/aarch64/gen/infinity.c b/lib/libc/aarch64/gen/infinity.c new file mode 100644 index 0000000000000..c96045e581b6b --- /dev/null +++ b/lib/libc/aarch64/gen/infinity.c @@ -0,0 +1,14 @@ +/* + * infinity.c + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <math.h> + +/* bytes for +Infinity on aarch64 */ +const union __infinity_un __infinity = { { 0, 0, 0, 0, 0, 0, 0xf0, 0x7f } }; + +/* bytes for NaN */ +const union __nan_un __nan = { { 0, 0, 0xc0, 0xff } }; diff --git a/lib/libc/amd64/gen/setjmp.S b/lib/libc/amd64/gen/setjmp.S index c26f52f5b70bc..826220e8bb55f 100644 --- a/lib/libc/amd64/gen/setjmp.S +++ b/lib/libc/amd64/gen/setjmp.S @@ -55,7 +55,7 @@ ENTRY(setjmp) movq $0,%rsi /* (sigset_t*)set */ leaq 72(%rcx),%rdx /* 9,10; (sigset_t*)oset */ /* stack is 16-byte aligned */ - call PIC_PLT(CNAME(_sigprocmask)) + call __libc_sigprocmask popq %rdi movq %rdi,%rcx movq 0(%rsp),%rdx /* retval */ @@ -82,7 +82,7 @@ ENTRY(__longjmp) leaq 72(%rdx),%rsi /* (sigset_t*)set */ movq $0,%rdx /* (sigset_t*)oset */ subq $0x8,%rsp /* make the stack 16-byte aligned */ - call PIC_PLT(CNAME(_sigprocmask)) + call __libc_sigprocmask addq $0x8,%rsp popq %rsi popq %rdi /* jmpbuf */ diff --git a/lib/libc/amd64/gen/sigsetjmp.S b/lib/libc/amd64/gen/sigsetjmp.S index 9a205567c3b74..1e8e77cbde3b1 100644 --- a/lib/libc/amd64/gen/sigsetjmp.S +++ b/lib/libc/amd64/gen/sigsetjmp.S @@ -63,7 +63,7 @@ ENTRY(sigsetjmp) movq $0,%rsi /* (sigset_t*)set */ leaq 72(%rcx),%rdx /* 9,10 (sigset_t*)oset */ /* stack is 16-byte aligned */ - call PIC_PLT(CNAME(_sigprocmask)) + call __libc_sigprocmask popq %rdi 2: movq %rdi,%rcx movq 0(%rsp),%rdx /* retval */ @@ -91,7 +91,7 @@ ENTRY(__siglongjmp) leaq 72(%rdx),%rsi /* (sigset_t*)set */ movq $0,%rdx /* (sigset_t*)oset */ subq $0x8,%rsp /* make the stack 16-byte aligned */ - call PIC_PLT(CNAME(_sigprocmask)) + call __libc_sigprocmask addq $0x8,%rsp popq %rsi popq %rdi /* jmpbuf */ diff --git a/lib/libc/amd64/sys/__vdso_gettc.c b/lib/libc/amd64/sys/__vdso_gettc.c index c6f2dfb3556a5..1899b213e2f6e 100644 --- a/lib/libc/amd64/sys/__vdso_gettc.c +++ b/lib/libc/amd64/sys/__vdso_gettc.c @@ -36,19 +36,29 @@ __FBSDID("$FreeBSD$"); static u_int __vdso_gettc_low(const struct vdso_timehands *th) { - uint32_t rv; + u_int rv; - __asm __volatile("rdtsc; shrd %%cl, %%edx, %0" + __asm __volatile("lfence; rdtsc; shrd %%cl, %%edx, %0" : "=a" (rv) : "c" (th->th_x86_shift) : "edx"); return (rv); } +static u_int +__vdso_rdtsc32(void) +{ + u_int rv; + + __asm __volatile("lfence;rdtsc" : "=a" (rv) : : "edx"); + return (rv); +} + #pragma weak __vdso_gettc u_int __vdso_gettc(const struct vdso_timehands *th) { - return (th->th_x86_shift > 0 ? __vdso_gettc_low(th) : rdtsc32()); + return (th->th_x86_shift > 0 ? __vdso_gettc_low(th) : + __vdso_rdtsc32()); } #pragma weak __vdso_gettimekeep diff --git a/lib/libc/compat-43/sigcompat.c b/lib/libc/compat-43/sigcompat.c index 199846fd272a5..a8cef1c1421e0 100644 --- a/lib/libc/compat-43/sigcompat.c +++ b/lib/libc/compat-43/sigcompat.c @@ -59,7 +59,7 @@ sigvec(signo, sv, osv) } else sap = NULL; osap = osv != NULL ? &osa : NULL; - ret = _sigaction(signo, sap, osap); + ret = __libc_sigaction(signo, sap, osap); if (ret == 0 && osv != NULL) { osv->sv_handler = osa.sa_handler; osv->sv_flags = osa.sa_flags ^ SV_INTERRUPT; @@ -77,7 +77,7 @@ sigsetmask(mask) sigemptyset(&set); set.__bits[0] = mask; - n = _sigprocmask(SIG_SETMASK, &set, &oset); + n = __libc_sigprocmask(SIG_SETMASK, &set, &oset); if (n) return (n); return (oset.__bits[0]); @@ -92,7 +92,7 @@ sigblock(mask) sigemptyset(&set); set.__bits[0] = mask; - n = _sigprocmask(SIG_BLOCK, &set, &oset); + n = __libc_sigprocmask(SIG_BLOCK, &set, &oset); if (n) return (n); return (oset.__bits[0]); @@ -105,7 +105,7 @@ sigpause(int mask) sigemptyset(&set); set.__bits[0] = mask; - return (_sigsuspend(&set)); + return (__libc_sigsuspend(&set)); } int @@ -113,11 +113,11 @@ xsi_sigpause(int sig) { sigset_t set; - if (_sigprocmask(SIG_BLOCK, NULL, &set) == -1) + if (__libc_sigprocmask(SIG_BLOCK, NULL, &set) == -1) return (-1); if (sigdelset(&set, sig) == -1) return (-1); - return (_sigsuspend(&set)); + return (__libc_sigsuspend(&set)); } int @@ -128,7 +128,7 @@ sighold(int sig) sigemptyset(&set); if (sigaddset(&set, sig) == -1) return (-1); - return (_sigprocmask(SIG_BLOCK, &set, NULL)); + return (__libc_sigprocmask(SIG_BLOCK, &set, NULL)); } int @@ -138,7 +138,7 @@ sigignore(int sig) bzero(&sa, sizeof(sa)); sa.sa_handler = SIG_IGN; - return (_sigaction(sig, &sa, NULL)); + return (__libc_sigaction(sig, &sa, NULL)); } int @@ -149,7 +149,7 @@ sigrelse(int sig) sigemptyset(&set); if (sigaddset(&set, sig) == -1) return (-1); - return (_sigprocmask(SIG_UNBLOCK, &set, NULL)); + return (__libc_sigprocmask(SIG_UNBLOCK, &set, NULL)); } void @@ -161,26 +161,26 @@ void sigemptyset(&set); if (sigaddset(&set, sig) == -1) return (SIG_ERR); - if (_sigprocmask(SIG_BLOCK, NULL, &pset) == -1) + if (__libc_sigprocmask(SIG_BLOCK, NULL, &pset) == -1) return (SIG_ERR); if ((__sighandler_t *)disp == SIG_HOLD) { - if (_sigprocmask(SIG_BLOCK, &set, &pset) == -1) + if (__libc_sigprocmask(SIG_BLOCK, &set, &pset) == -1) return (SIG_ERR); if (sigismember(&pset, sig)) return (SIG_HOLD); else { - if (_sigaction(sig, NULL, &psa) == -1) + if (__libc_sigaction(sig, NULL, &psa) == -1) return (SIG_ERR); return (psa.sa_handler); } } else { - if (_sigprocmask(SIG_UNBLOCK, &set, &pset) == -1) + if (__libc_sigprocmask(SIG_UNBLOCK, &set, &pset) == -1) return (SIG_ERR); } bzero(&sa, sizeof(sa)); sa.sa_handler = disp; - if (_sigaction(sig, &sa, &psa) == -1) + if (__libc_sigaction(sig, &sa, &psa) == -1) return (SIG_ERR); if (sigismember(&pset, sig)) return (SIG_HOLD); diff --git a/lib/libc/db/btree/bt_open.c b/lib/libc/db/btree/bt_open.c index 94ba014ed3af7..051fc28e93f6b 100644 --- a/lib/libc/db/btree/bt_open.c +++ b/lib/libc/db/btree/bt_open.c @@ -57,6 +57,7 @@ __FBSDID("$FreeBSD$"); #include <string.h> #include <unistd.h> #include "un-namespace.h" +#include "libc_private.h" #include <db.h> #include "btree.h" @@ -401,10 +402,10 @@ tmp(void) } (void)sigfillset(&set); - (void)_sigprocmask(SIG_BLOCK, &set, &oset); + (void)__libc_sigprocmask(SIG_BLOCK, &set, &oset); if ((fd = mkostemp(path, O_CLOEXEC)) != -1) (void)unlink(path); - (void)_sigprocmask(SIG_SETMASK, &oset, NULL); + (void)__libc_sigprocmask(SIG_SETMASK, &oset, NULL); return(fd); } diff --git a/lib/libc/db/hash/hash_page.c b/lib/libc/db/hash/hash_page.c index d319d988c165d..8040419f728ed 100644 --- a/lib/libc/db/hash/hash_page.c +++ b/lib/libc/db/hash/hash_page.c @@ -66,6 +66,7 @@ __FBSDID("$FreeBSD$"); #include <assert.h> #endif #include "un-namespace.h" +#include "libc_private.h" #include <db.h> #include "hash.h" @@ -861,10 +862,10 @@ open_temp(HTAB *hashp) /* Block signals; make sure file goes away at process exit. */ (void)sigfillset(&set); - (void)_sigprocmask(SIG_BLOCK, &set, &oset); + (void)__libc_sigprocmask(SIG_BLOCK, &set, &oset); if ((hashp->fp = mkostemp(path, O_CLOEXEC)) != -1) (void)unlink(path); - (void)_sigprocmask(SIG_SETMASK, &oset, (sigset_t *)NULL); + (void)__libc_sigprocmask(SIG_SETMASK, &oset, (sigset_t *)NULL); return (hashp->fp != -1 ? 0 : -1); } diff --git a/lib/libc/gen/daemon.c b/lib/libc/gen/daemon.c index b359a87aa6436..15c6f4af7583c 100644 --- a/lib/libc/gen/daemon.c +++ b/lib/libc/gen/daemon.c @@ -41,10 +41,10 @@ __FBSDID("$FreeBSD$"); #include <signal.h> #include <unistd.h> #include "un-namespace.h" +#include "libc_private.h" int -daemon(nochdir, noclose) - int nochdir, noclose; +daemon(int nochdir, int noclose) { struct sigaction osa, sa; int fd; @@ -56,7 +56,7 @@ daemon(nochdir, noclose) sigemptyset(&sa.sa_mask); sa.sa_handler = SIG_IGN; sa.sa_flags = 0; - osa_ok = _sigaction(SIGHUP, &sa, &osa); + osa_ok = __libc_sigaction(SIGHUP, &sa, &osa); switch (fork()) { case -1: @@ -74,7 +74,7 @@ daemon(nochdir, noclose) newgrp = setsid(); oerrno = errno; if (osa_ok != -1) - _sigaction(SIGHUP, &osa, NULL); + __libc_sigaction(SIGHUP, &osa, NULL); if (newgrp == -1) { errno = oerrno; diff --git a/lib/libc/gen/devname.c b/lib/libc/gen/devname.c index da0b923573ade..bf9564589eb51 100644 --- a/lib/libc/gen/devname.c +++ b/lib/libc/gen/devname.c @@ -38,6 +38,7 @@ __FBSDID("$FreeBSD$"); #include <stdio.h> #include <stdint.h> +#include <stdlib.h> #include <string.h> #include <sys/param.h> #include <sys/stat.h> diff --git a/lib/libc/gen/posix_spawn.c b/lib/libc/gen/posix_spawn.c index e3124b2e24ba5..c65a730875d2f 100644 --- a/lib/libc/gen/posix_spawn.c +++ b/lib/libc/gen/posix_spawn.c @@ -118,15 +118,18 @@ process_spawnattr(const posix_spawnattr_t sa) return (errno); } - /* Set signal masks/defaults */ + /* + * Set signal masks/defaults. + * Use unwrapped syscall, libthr is in undefined state after vfork(). + */ if (sa->sa_flags & POSIX_SPAWN_SETSIGMASK) { - _sigprocmask(SIG_SETMASK, &sa->sa_sigmask, NULL); + __sys_sigprocmask(SIG_SETMASK, &sa->sa_sigmask, NULL); } if (sa->sa_flags & POSIX_SPAWN_SETSIGDEF) { for (i = 1; i <= _SIG_MAXSIG; i++) { if (sigismember(&sa->sa_sigdefault, i)) - if (_sigaction(i, &sigact, NULL) != 0) + if (__sys_sigaction(i, &sigact, NULL) != 0) return (errno); } } diff --git a/lib/libc/gen/readpassphrase.c b/lib/libc/gen/readpassphrase.c index 95ae725e040c4..60051a189e576 100644 --- a/lib/libc/gen/readpassphrase.c +++ b/lib/libc/gen/readpassphrase.c @@ -36,6 +36,7 @@ __FBSDID("$FreeBSD$"); #include <unistd.h> #include <readpassphrase.h> #include "un-namespace.h" +#include "libc_private.h" static volatile sig_atomic_t signo[NSIG]; @@ -104,15 +105,15 @@ restart: sigemptyset(&sa.sa_mask); sa.sa_flags = 0; /* don't restart system calls */ sa.sa_handler = handler; - (void)_sigaction(SIGALRM, &sa, &savealrm); - (void)_sigaction(SIGHUP, &sa, &savehup); - (void)_sigaction(SIGINT, &sa, &saveint); - (void)_sigaction(SIGPIPE, &sa, &savepipe); - (void)_sigaction(SIGQUIT, &sa, &savequit); - (void)_sigaction(SIGTERM, &sa, &saveterm); - (void)_sigaction(SIGTSTP, &sa, &savetstp); - (void)_sigaction(SIGTTIN, &sa, &savettin); - (void)_sigaction(SIGTTOU, &sa, &savettou); + (void)__libc_sigaction(SIGALRM, &sa, &savealrm); + (void)__libc_sigaction(SIGHUP, &sa, &savehup); + (void)__libc_sigaction(SIGINT, &sa, &saveint); + (void)__libc_sigaction(SIGPIPE, &sa, &savepipe); + (void)__libc_sigaction(SIGQUIT, &sa, &savequit); + (void)__libc_sigaction(SIGTERM, &sa, &saveterm); + (void)__libc_sigaction(SIGTSTP, &sa, &savetstp); + (void)__libc_sigaction(SIGTTIN, &sa, &savettin); + (void)__libc_sigaction(SIGTTOU, &sa, &savettou); if (!(flags & RPP_STDIN)) (void)_write(output, prompt, strlen(prompt)); @@ -142,15 +143,15 @@ restart: errno == EINTR && !signo[SIGTTOU]) continue; } - (void)_sigaction(SIGALRM, &savealrm, NULL); - (void)_sigaction(SIGHUP, &savehup, NULL); - (void)_sigaction(SIGINT, &saveint, NULL); - (void)_sigaction(SIGQUIT, &savequit, NULL); - (void)_sigaction(SIGPIPE, &savepipe, NULL); - (void)_sigaction(SIGTERM, &saveterm, NULL); - (void)_sigaction(SIGTSTP, &savetstp, NULL); - (void)_sigaction(SIGTTIN, &savettin, NULL); - (void)_sigaction(SIGTTOU, &savettou, NULL); + (void)__libc_sigaction(SIGALRM, &savealrm, NULL); + (void)__libc_sigaction(SIGHUP, &savehup, NULL); + (void)__libc_sigaction(SIGINT, &saveint, NULL); + (void)__libc_sigaction(SIGQUIT, &savequit, NULL); + (void)__libc_sigaction(SIGPIPE, &savepipe, NULL); + (void)__libc_sigaction(SIGTERM, &saveterm, NULL); + (void)__libc_sigaction(SIGTSTP, &savetstp, NULL); + (void)__libc_sigaction(SIGTTIN, &savettin, NULL); + (void)__libc_sigaction(SIGTTOU, &savettou, NULL); if (input != STDIN_FILENO) (void)_close(input); diff --git a/lib/libc/gen/setmode.c b/lib/libc/gen/setmode.c index 815cf146ed0ba..7525567bb7921 100644 --- a/lib/libc/gen/setmode.c +++ b/lib/libc/gen/setmode.c @@ -53,6 +53,7 @@ __FBSDID("$FreeBSD$"); #include <stdio.h> #endif #include "un-namespace.h" +#include "libc_private.h" #define SET_LEN 6 /* initial # of bitcmd struct to malloc */ #define SET_LEN_INCR 4 /* # of bitcmd structs to add as needed */ @@ -364,9 +365,9 @@ getumask(void) * handler, protect them as best we can. */ sigfillset(&sigset); - (void)_sigprocmask(SIG_BLOCK, &sigset, &sigoset); + (void)__libc_sigprocmask(SIG_BLOCK, &sigset, &sigoset); (void)umask(mask = umask(0)); - (void)_sigprocmask(SIG_SETMASK, &sigoset, NULL); + (void)__libc_sigprocmask(SIG_SETMASK, &sigoset, NULL); return (mask); } diff --git a/lib/libc/gen/siginterrupt.c b/lib/libc/gen/siginterrupt.c index fde33ca567cea..d99b772337869 100644 --- a/lib/libc/gen/siginterrupt.c +++ b/lib/libc/gen/siginterrupt.c @@ -43,14 +43,13 @@ __FBSDID("$FreeBSD$"); * after an instance of the indicated signal. */ int -siginterrupt(sig, flag) - int sig, flag; +siginterrupt(int sig, int flag) { extern sigset_t _sigintr __hidden; struct sigaction sa; int ret; - if ((ret = _sigaction(sig, (struct sigaction *)0, &sa)) < 0) + if ((ret = __libc_sigaction(sig, (struct sigaction *)0, &sa)) < 0) return (ret); if (flag) { sigaddset(&_sigintr, sig); @@ -59,5 +58,5 @@ siginterrupt(sig, flag) sigdelset(&_sigintr, sig); sa.sa_flags |= SA_RESTART; } - return (_sigaction(sig, &sa, (struct sigaction *)0)); + return (__libc_sigaction(sig, &sa, (struct sigaction *)0)); } diff --git a/lib/libc/gen/signal.c b/lib/libc/gen/signal.c index ee96dcc3c5b62..70e7f1712cea3 100644 --- a/lib/libc/gen/signal.c +++ b/lib/libc/gen/signal.c @@ -44,9 +44,7 @@ __FBSDID("$FreeBSD$"); sigset_t _sigintr __hidden; /* shared with siginterrupt */ sig_t -signal(s, a) - int s; - sig_t a; +signal(int s, sig_t a) { struct sigaction sa, osa; @@ -55,7 +53,7 @@ signal(s, a) sa.sa_flags = 0; if (!sigismember(&_sigintr, s)) sa.sa_flags |= SA_RESTART; - if (_sigaction(s, &sa, &osa) < 0) + if (__libc_sigaction(s, &sa, &osa) < 0) return (SIG_ERR); return (osa.sa_handler); } diff --git a/lib/libc/gen/sysctl.3 b/lib/libc/gen/sysctl.3 index 7d7b90a7442e9..4594d9af9a505 100644 --- a/lib/libc/gen/sysctl.3 +++ b/lib/libc/gen/sysctl.3 @@ -28,7 +28,7 @@ .\" @(#)sysctl.3 8.4 (Berkeley) 5/9/95 .\" $FreeBSD$ .\" -.Dd May 17, 2013 +.Dd September 10, 2015 .Dt SYSCTL 3 .Os .Sh NAME @@ -736,8 +736,6 @@ privilege may change the value. .It "VM_LOADAVG struct loadavg no" .It "VM_TOTAL struct vmtotal no" .It "VM_SWAPPING_ENABLED integer maybe" -.It "VM_V_CACHE_MAX integer yes" -.It "VM_V_CACHE_MIN integer yes" .It "VM_V_FREE_MIN integer yes" .It "VM_V_FREE_RESERVED integer yes" .It "VM_V_FREE_TARGET integer yes" @@ -757,12 +755,6 @@ The returned data consists of a 1 if process swapping is enabled or 0 if disabled. This variable is permanently set to 0 if the kernel was built with swapping disabled. -.It Li VM_V_CACHE_MAX -Maximum desired size of the cache queue. -.It Li VM_V_CACHE_MIN -Minimum desired size of the cache queue. -If the cache queue size -falls very far below this value, the pageout daemon is awakened. .It Li VM_V_FREE_MIN Minimum amount of memory (cache memory plus free memory) required to be available before a process waiting on memory will be diff --git a/lib/libc/gen/tls.c b/lib/libc/gen/tls.c index 58ebb55c00280..73eb9a261939a 100644 --- a/lib/libc/gen/tls.c +++ b/lib/libc/gen/tls.c @@ -40,9 +40,9 @@ #include "libc_private.h" /* Provided by jemalloc to avoid bootstrapping issues. */ -void *__je_a0malloc(size_t size); -void *__je_a0calloc(size_t num, size_t size); -void __je_a0free(void *ptr); +void *__je_bootstrap_malloc(size_t size); +void *__je_bootstrap_calloc(size_t num, size_t size); +void __je_bootstrap_free(void *ptr); __weak_reference(__libc_allocate_tls, _rtld_allocate_tls); __weak_reference(__libc_free_tls, _rtld_free_tls); @@ -125,8 +125,8 @@ __libc_free_tls(void *tcb, size_t tcbsize, size_t tcbalign __unused) tls = (Elf_Addr **)((Elf_Addr)tcb + tcbsize - TLS_TCB_SIZE); dtv = tls[0]; - __je_a0free(dtv); - __je_a0free(tcb); + __je_bootstrap_free(dtv); + __je_bootstrap_free(tcb); } /* @@ -142,18 +142,18 @@ __libc_allocate_tls(void *oldtcb, size_t tcbsize, size_t tcbalign __unused) if (oldtcb != NULL && tcbsize == TLS_TCB_SIZE) return (oldtcb); - tcb = __je_a0calloc(1, tls_static_space + tcbsize - TLS_TCB_SIZE); + tcb = __je_bootstrap_calloc(1, tls_static_space + tcbsize - TLS_TCB_SIZE); tls = (Elf_Addr **)(tcb + tcbsize - TLS_TCB_SIZE); if (oldtcb != NULL) { memcpy(tls, oldtcb, tls_static_space); - __je_a0free(oldtcb); + __je_bootstrap_free(oldtcb); /* Adjust the DTV. */ dtv = tls[0]; dtv[2] = (Elf_Addr)tls + TLS_TCB_SIZE; } else { - dtv = __je_a0malloc(3 * sizeof(Elf_Addr)); + dtv = __je_bootstrap_malloc(3 * sizeof(Elf_Addr)); tls[0] = dtv; dtv[0] = 1; dtv[1] = 1; @@ -194,8 +194,8 @@ __libc_free_tls(void *tcb, size_t tcbsize __unused, size_t tcbalign) dtv = ((Elf_Addr**)tcb)[1]; tlsend = (Elf_Addr) tcb; tlsstart = tlsend - size; - __je_a0free((void*) tlsstart); - __je_a0free(dtv); + __je_bootstrap_free((void*) tlsstart); + __je_bootstrap_free(dtv); } /* @@ -213,8 +213,8 @@ __libc_allocate_tls(void *oldtls, size_t tcbsize, size_t tcbalign) if (tcbsize < 2 * sizeof(Elf_Addr)) tcbsize = 2 * sizeof(Elf_Addr); - tls = __je_a0calloc(1, size + tcbsize); - dtv = __je_a0malloc(3 * sizeof(Elf_Addr)); + tls = __je_bootstrap_calloc(1, size + tcbsize); + dtv = __je_bootstrap_malloc(3 * sizeof(Elf_Addr)); segbase = (Elf_Addr)(tls + size); ((Elf_Addr*)segbase)[0] = segbase; diff --git a/lib/libc/gen/wordexp.3 b/lib/libc/gen/wordexp.3 index 41b0d0c46df4f..2fc20ef81f2bb 100644 --- a/lib/libc/gen/wordexp.3 +++ b/lib/libc/gen/wordexp.3 @@ -25,7 +25,7 @@ .\" .\" $FreeBSD$ .\" -.Dd July 07, 2015 +.Dd August 18, 2015 .Dt WORDEXP 3 .Os .Sh NAME @@ -108,9 +108,8 @@ function frees the memory allocated by .Sh IMPLEMENTATION NOTES The .Fn wordexp -function is implemented as a wrapper around the undocumented -.Ic wordexp -shell built-in command. +function is implemented by executing +.Xr sh 1 . .Sh RETURN VALUES The .Fn wordexp @@ -132,9 +131,10 @@ argument contains one of the following unquoted characters: .Ql { , .Ql } . .It Dv WRDE_BADVAL -An attempt was made to expand an undefined shell variable and +An error after successful parsing, +such as an attempt to expand an undefined shell variable with .Dv WRDE_UNDEF -is set in +set in .Fa flags . .It Dv WRDE_CMDSUB An attempt was made to use command substitution and @@ -142,7 +142,9 @@ An attempt was made to use command substitution and is set in .Fa flags . .It Dv WRDE_NOSPACE -Not enough memory to store the result. +Not enough memory to store the result or +an error during +.Xr fork 2 . .It Dv WRDE_SYNTAX Shell syntax error in .Fa words . diff --git a/lib/libc/gen/wordexp.c b/lib/libc/gen/wordexp.c index c7f4b1d0e9024..859ca50ea6aa0 100644 --- a/lib/libc/gen/wordexp.c +++ b/lib/libc/gen/wordexp.c @@ -38,6 +38,7 @@ #include <unistd.h> #include <wordexp.h> #include "un-namespace.h" +#include "libc_private.h" __FBSDID("$FreeBSD$"); @@ -103,8 +104,7 @@ static int we_askshell(const char *words, wordexp_t *we, int flags) { int pdes[2]; /* Pipe to child */ - char bbuf[9]; /* Buffer for byte count */ - char wbuf[9]; /* Buffer for word count */ + char buf[18]; /* Buffer for byte and word count */ long nwords, nbytes; /* Number of words, bytes from child */ long i; /* Handy integer */ size_t sofs; /* Offset into we->we_strings */ @@ -119,6 +119,7 @@ we_askshell(const char *words, wordexp_t *we, int flags) char **nwv; /* Temporary for realloc() */ sigset_t newsigblock, oldsigblock; const char *ifs; + char save; serrno = errno; ifs = getenv("IFS"); @@ -127,27 +128,29 @@ we_askshell(const char *words, wordexp_t *we, int flags) return (WRDE_NOSPACE); /* XXX */ (void)sigemptyset(&newsigblock); (void)sigaddset(&newsigblock, SIGCHLD); - (void)_sigprocmask(SIG_BLOCK, &newsigblock, &oldsigblock); + (void)__libc_sigprocmask(SIG_BLOCK, &newsigblock, &oldsigblock); if ((pid = fork()) < 0) { serrno = errno; _close(pdes[0]); _close(pdes[1]); - (void)_sigprocmask(SIG_SETMASK, &oldsigblock, NULL); + (void)__libc_sigprocmask(SIG_SETMASK, &oldsigblock, NULL); errno = serrno; return (WRDE_NOSPACE); /* XXX */ } else if (pid == 0) { /* - * We are the child; just get /bin/sh to run the wordexp - * builtin on `words'. + * We are the child; make /bin/sh expand `words'. */ - (void)_sigprocmask(SIG_SETMASK, &oldsigblock, NULL); + (void)__libc_sigprocmask(SIG_SETMASK, &oldsigblock, NULL); if ((pdes[1] != STDOUT_FILENO ? _dup2(pdes[1], STDOUT_FILENO) : _fcntl(pdes[1], F_SETFD, 0)) < 0) _exit(1); execl(_PATH_BSHELL, "sh", flags & WRDE_UNDEF ? "-u" : "+u", - "-c", "IFS=$1;eval \"$2\";eval \"wordexp $3\"", "", + "-c", "IFS=$1;eval \"$2\";eval \"echo;set -- $3\";" + "IFS=;a=\"$*\";printf '%08x' \"$#\" \"${#a}\";" + "printf '%s\\0' \"$@\"", + "", ifs != NULL ? ifs : " \t\n", flags & WRDE_SHOWERR ? "" : "exec 2>/dev/null", words, (char *)NULL); @@ -156,20 +159,30 @@ we_askshell(const char *words, wordexp_t *we, int flags) /* * We are the parent; read the output of the shell wordexp function, - * which is a 32-bit hexadecimal word count, a 32-bit hexadecimal - * byte count (not including terminating null bytes), followed by - * the expanded words separated by nulls. + * which is a byte indicating that the words were parsed successfully, + * a 32-bit hexadecimal word count, a 32-bit hexadecimal byte count + * (not including terminating null bytes), followed by the expanded + * words separated by nulls. */ _close(pdes[1]); - if (we_read_fully(pdes[0], wbuf, 8) != 8 || - we_read_fully(pdes[0], bbuf, 8) != 8) { - error = flags & WRDE_UNDEF ? WRDE_BADVAL : WRDE_SYNTAX; + switch (we_read_fully(pdes[0], buf, 17)) { + case 1: + error = WRDE_BADVAL; + serrno = errno; + goto cleanup; + case 17: + break; + default: + error = WRDE_SYNTAX; serrno = errno; goto cleanup; } - wbuf[8] = bbuf[8] = '\0'; - nwords = strtol(wbuf, NULL, 16); - nbytes = strtol(bbuf, NULL, 16) + nwords; + save = buf[9]; + buf[9] = '\0'; + nwords = strtol(buf + 1, NULL, 16); + buf[9] = save; + buf[17] = '\0'; + nbytes = strtol(buf + 9, NULL, 16) + nwords; /* * Allocate or reallocate (when flags & WRDE_APPEND) the word vector @@ -199,7 +212,7 @@ we_askshell(const char *words, wordexp_t *we, int flags) we->we_strings = nstrings; if (we_read_fully(pdes[0], we->we_strings + sofs, nbytes) != nbytes) { - error = flags & WRDE_UNDEF ? WRDE_BADVAL : WRDE_SYNTAX; + error = WRDE_NOSPACE; /* abort for unknown reason */ serrno = errno; goto cleanup; } @@ -210,13 +223,13 @@ cleanup: do wpid = _waitpid(pid, &status, 0); while (wpid < 0 && errno == EINTR); - (void)_sigprocmask(SIG_SETMASK, &oldsigblock, NULL); + (void)__libc_sigprocmask(SIG_SETMASK, &oldsigblock, NULL); if (error != 0) { errno = serrno; return (error); } if (wpid < 0 || !WIFEXITED(status) || WEXITSTATUS(status) != 0) - return (flags & WRDE_UNDEF ? WRDE_BADVAL : WRDE_SYNTAX); + return (WRDE_NOSPACE); /* abort for unknown reason */ /* * Break the null-terminated expanded word strings out into diff --git a/lib/libc/i386/gen/setjmp.S b/lib/libc/i386/gen/setjmp.S index 6e15868a1901d..eb33e101ea86a 100644 --- a/lib/libc/i386/gen/setjmp.S +++ b/lib/libc/i386/gen/setjmp.S @@ -50,21 +50,12 @@ __FBSDID("$FreeBSD$"); ENTRY(setjmp) movl 4(%esp),%ecx - PIC_PROLOGUE -#ifdef PIC - subl $12,%esp /* make the stack 16-byte aligned */ -#endif leal 28(%ecx), %eax pushl %eax /* (sigset_t*)oset */ pushl $0 /* (sigset_t*)set */ pushl $1 /* SIG_BLOCK */ - call PIC_PLT(CNAME(_sigprocmask)) -#ifdef PIC - addl $24,%esp -#else + call __libc_sigprocmask addl $12,%esp -#endif - PIC_EPILOGUE movl 4(%esp),%ecx movl 0(%esp),%edx movl %edx, 0(%ecx) @@ -81,21 +72,12 @@ END(setjmp) WEAK_REFERENCE(__longjmp, longjmp) ENTRY(__longjmp) movl 4(%esp),%edx - PIC_PROLOGUE -#ifdef PIC - subl $12,%esp /* make the stack 16-byte aligned */ -#endif pushl $0 /* (sigset_t*)oset */ leal 28(%edx), %eax pushl %eax /* (sigset_t*)set */ pushl $3 /* SIG_SETMASK */ - call PIC_PLT(CNAME(_sigprocmask)) -#ifdef PIC - addl $24,%esp -#else + call __libc_sigprocmask addl $12,%esp -#endif - PIC_EPILOGUE movl 4(%esp),%edx movl 8(%esp),%eax movl 0(%edx),%ecx diff --git a/lib/libc/i386/gen/sigsetjmp.S b/lib/libc/i386/gen/sigsetjmp.S index 1c636493c507e..7566d72464095 100644 --- a/lib/libc/i386/gen/sigsetjmp.S +++ b/lib/libc/i386/gen/sigsetjmp.S @@ -59,21 +59,12 @@ ENTRY(sigsetjmp) movl %eax,44(%ecx) testl %eax,%eax jz 2f - PIC_PROLOGUE -#ifdef PIC - subl $12,%esp /* make the stack 16-byte aligned */ -#endif leal 28(%ecx), %eax pushl %eax /* (sigset_t*)oset */ pushl $0 /* (sigset_t*)set */ pushl $1 /* SIG_BLOCK */ - call PIC_PLT(CNAME(_sigprocmask)) -#ifdef PIC - addl $24,%esp -#else + call __libc_sigprocmask addl $12,%esp -#endif - PIC_EPILOGUE movl 4(%esp),%ecx 2: movl 0(%esp),%edx movl %edx, 0(%ecx) @@ -92,21 +83,12 @@ ENTRY(__siglongjmp) movl 4(%esp),%edx cmpl $0,44(%edx) jz 2f - PIC_PROLOGUE -#ifdef PIC - subl $12,%esp /* make the stack 16-byte aligned */ -#endif pushl $0 /* (sigset_t*)oset */ leal 28(%edx), %eax pushl %eax /* (sigset_t*)set */ pushl $3 /* SIG_SETMASK */ - call PIC_PLT(CNAME(_sigprocmask)) -#ifdef PIC - addl $24,%esp -#else + call __libc_sigprocmask addl $12,%esp -#endif - PIC_EPILOGUE movl 4(%esp),%edx 2: movl 8(%esp),%eax movl 0(%edx),%ecx diff --git a/lib/libc/i386/sys/__vdso_gettc.c b/lib/libc/i386/sys/__vdso_gettc.c index c6f2dfb3556a5..1454f16699d27 100644 --- a/lib/libc/i386/sys/__vdso_gettc.c +++ b/lib/libc/i386/sys/__vdso_gettc.c @@ -31,24 +31,78 @@ __FBSDID("$FreeBSD$"); #include <sys/time.h> #include <sys/vdso.h> #include <machine/cpufunc.h> +#include <machine/specialreg.h> #include "libc_private.h" +static int lfence_works = -1; + +static int +get_lfence_usage(void) +{ + u_int cpuid_supported, p[4]; + + if (lfence_works == -1) { + __asm __volatile( + " pushfl\n" + " popl %%eax\n" + " movl %%eax,%%ecx\n" + " xorl $0x200000,%%eax\n" + " pushl %%eax\n" + " popfl\n" + " pushfl\n" + " popl %%eax\n" + " xorl %%eax,%%ecx\n" + " je 1f\n" + " movl $1,%0\n" + " jmp 2f\n" + "1: movl $0,%0\n" + "2:\n" + : "=r" (cpuid_supported) : : "eax", "ecx"); + if (cpuid_supported) { + __asm __volatile( + " pushl %%ebx\n" + " cpuid\n" + " movl %%ebx,%1\n" + " popl %%ebx\n" + : "=a" (p[0]), "=r" (p[1]), "=c" (p[2]), "=d" (p[3]) + : "0" (0x1)); + lfence_works = (p[3] & CPUID_SSE2) != 0; + } else + lfence_works = 0; + } + return (lfence_works); +} + static u_int __vdso_gettc_low(const struct vdso_timehands *th) { - uint32_t rv; + u_int rv; + if (get_lfence_usage() == 1) + lfence(); __asm __volatile("rdtsc; shrd %%cl, %%edx, %0" : "=a" (rv) : "c" (th->th_x86_shift) : "edx"); return (rv); } +static u_int +__vdso_rdtsc32(void) +{ + u_int rv; + + if (get_lfence_usage() == 1) + lfence(); + rv = rdtsc32(); + return (rv); +} + #pragma weak __vdso_gettc u_int __vdso_gettc(const struct vdso_timehands *th) { - return (th->th_x86_shift > 0 ? __vdso_gettc_low(th) : rdtsc32()); + return (th->th_x86_shift > 0 ? __vdso_gettc_low(th) : + __vdso_rdtsc32()); } #pragma weak __vdso_gettimekeep diff --git a/lib/libc/include/libc_private.h b/lib/libc/include/libc_private.h index a670d63e08543..5caf9a362550e 100644 --- a/lib/libc/include/libc_private.h +++ b/lib/libc/include/libc_private.h @@ -359,6 +359,11 @@ __pid_t __sys_wait6(enum idtype, __id_t, int *, int, __ssize_t __sys_write(int, const void *, __size_t); __ssize_t __sys_writev(int, const struct iovec *, int); +int __libc_sigaction(int, const struct sigaction *, + struct sigaction *) __hidden; +int __libc_sigprocmask(int, const __sigset_t *, __sigset_t *) + __hidden; +int __libc_sigsuspend(const __sigset_t *) __hidden; int __libc_sigwait(const __sigset_t * __restrict, int * restrict sig); int __libc_system(const char *); diff --git a/lib/libc/locale/utf8.c b/lib/libc/locale/utf8.c index ce49279cb2d75..8ccfdb1aa3b3c 100644 --- a/lib/libc/locale/utf8.c +++ b/lib/libc/locale/utf8.c @@ -145,14 +145,6 @@ _UTF8_mbrtowc(wchar_t * __restrict pwc, const char * __restrict s, size_t n, mask = 0x07; want = 4; lbound = 0x10000; - } else if ((ch & 0xfc) == 0xf8) { - mask = 0x03; - want = 5; - lbound = 0x200000; - } else if ((ch & 0xfe) == 0xfc) { - mask = 0x01; - want = 6; - lbound = 0x4000000; } else { /* * Malformed input; input is not UTF-8. @@ -199,7 +191,7 @@ _UTF8_mbrtowc(wchar_t * __restrict pwc, const char * __restrict s, size_t n, errno = EILSEQ; return ((size_t)-1); } - if (wch >= 0xd800 && wch <= 0xdfff) { + if ((wch >= 0xd800 && wch <= 0xdfff) || wch > 0x10ffff) { /* * Malformed input; invalid code points. */ @@ -326,17 +318,15 @@ _UTF8_wcrtomb(char * __restrict s, wchar_t wc, mbstate_t * __restrict ps) lead = 0xc0; len = 2; } else if ((wc & ~0xffff) == 0) { + if (wc >= 0xd800 && wc <= 0xdfff) { + errno = EILSEQ; + return ((size_t)-1); + } lead = 0xe0; len = 3; - } else if ((wc & ~0x1fffff) == 0) { + } else if (wc >= 0 && wc <= 0x10ffff) { lead = 0xf0; len = 4; - } else if ((wc & ~0x3ffffff) == 0) { - lead = 0xf8; - len = 5; - } else if ((wc & ~0x7fffffff) == 0) { - lead = 0xfc; - len = 6; } else { errno = EILSEQ; return ((size_t)-1); diff --git a/lib/libc/net/getnameinfo.c b/lib/libc/net/getnameinfo.c index 005b8773bfc15..d7e7971ea647c 100644 --- a/lib/libc/net/getnameinfo.c +++ b/lib/libc/net/getnameinfo.c @@ -78,6 +78,8 @@ getnameinfo(const struct sockaddr *sa, socklen_t salen, char *host, size_t hostlen, char *serv, size_t servlen, int flags) { + if (sa == NULL) + return (EAI_FAIL); switch (sa->sa_family) { case AF_INET: @@ -124,25 +126,19 @@ getnameinfo_inet(const struct sockaddr *sa, socklen_t salen, struct servent *sp; struct hostent *hp; u_short port; - int family, i; const char *addr; u_int32_t v4a; int h_error; char numserv[512]; char numaddr[512]; - if (sa == NULL) - return EAI_FAIL; - - family = sa->sa_family; - for (i = 0; afdl[i].a_af; i++) - if (afdl[i].a_af == family) { - afd = &afdl[i]; - goto found; - } - return EAI_FAMILY; + for (afd = &afdl[0]; afd->a_af > 0; afd++) { + if (afd->a_af == sa->sa_family) + break; + } + if (afd->a_af == 0) + return (EAI_FAMILY); - found: if (salen != afd->a_socklen) return EAI_FAIL; @@ -394,11 +390,22 @@ getnameinfo_link(const struct sockaddr *sa, socklen_t salen, if (sdl->sdl_nlen == 0 && sdl->sdl_alen == 0 && sdl->sdl_slen == 0) { n = snprintf(host, hostlen, "link#%d", sdl->sdl_index); - if (n > hostlen) { + if (n >= hostlen) { *host = '\0'; - return EAI_MEMORY; + return (EAI_MEMORY); + } + return (0); + } + + if (sdl->sdl_nlen > 0 && sdl->sdl_alen == 0) { + n = sdl->sdl_nlen; + if (n >= hostlen) { + *host = '\0'; + return (EAI_MEMORY); } - return 0; + memcpy(host, sdl->sdl_data, sdl->sdl_nlen); + host[n] = '\0'; + return (0); } switch (sdl->sdl_type) { @@ -440,10 +447,7 @@ getnameinfo_link(const struct sockaddr *sa, socklen_t salen, } static int -hexname(cp, len, host, hostlen) - const u_int8_t *cp; - char *host; - size_t len, hostlen; +hexname(const u_int8_t *cp, size_t len, char *host, size_t hostlen) { int i, n; char *outp = host; diff --git a/lib/libc/net/if_nametoindex.c b/lib/libc/net/if_nametoindex.c index 8f04921760ebb..debf3fabc6af6 100644 --- a/lib/libc/net/if_nametoindex.c +++ b/lib/libc/net/if_nametoindex.c @@ -70,9 +70,7 @@ if_nametoindex(const char *ifname) s = _socket(AF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0); if (s != -1) { -#ifdef PURIFY memset(&ifr, 0, sizeof(ifr)); -#endif strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); if (_ioctl(s, SIOCGIFINDEX, &ifr) != -1) { _close(s); diff --git a/lib/libc/net/rcmd.c b/lib/libc/net/rcmd.c index 2885dc331e087..1ba98888ea8cd 100644 --- a/lib/libc/net/rcmd.c +++ b/lib/libc/net/rcmd.c @@ -58,6 +58,7 @@ __FBSDID("$FreeBSD$"); #endif #include <arpa/nameser.h> #include "un-namespace.h" +#include "libc_private.h" extern int innetgr( const char *, const char *, const char *, const char * ); @@ -148,7 +149,7 @@ rcmd_af(ahost, rport, locuser, remuser, cmd, fd2p, af) refused = 0; sigemptyset(&newmask); sigaddset(&newmask, SIGURG); - _sigprocmask(SIG_BLOCK, (const sigset_t *)&newmask, &oldmask); + __libc_sigprocmask(SIG_BLOCK, (const sigset_t *)&newmask, &oldmask); for (timo = 1, lport = IPPORT_RESERVED - 1;;) { s = rresvport_af(&lport, ai->ai_family); if (s < 0) { @@ -163,7 +164,7 @@ rcmd_af(ahost, rport, locuser, remuser, cmd, fd2p, af) (void)fprintf(stderr, "rcmd: socket: %s\n", strerror(errno)); freeaddrinfo(res); - _sigprocmask(SIG_SETMASK, (const sigset_t *)&oldmask, + __libc_sigprocmask(SIG_SETMASK, (const sigset_t *)&oldmask, NULL); return (-1); } @@ -181,7 +182,7 @@ rcmd_af(ahost, rport, locuser, remuser, cmd, fd2p, af) (void)fprintf(stderr, "%s: %s\n", *ahost, strerror(errno)); freeaddrinfo(res); - _sigprocmask(SIG_SETMASK, (const sigset_t *)&oldmask, + __libc_sigprocmask(SIG_SETMASK, (const sigset_t *)&oldmask, NULL); return (-1); } @@ -306,7 +307,7 @@ again: } goto bad2; } - _sigprocmask(SIG_SETMASK, (const sigset_t *)&oldmask, NULL); + __libc_sigprocmask(SIG_SETMASK, (const sigset_t *)&oldmask, NULL); freeaddrinfo(res); return (s); bad2: @@ -314,7 +315,7 @@ bad2: (void)_close(*fd2p); bad: (void)_close(s); - _sigprocmask(SIG_SETMASK, (const sigset_t *)&oldmask, NULL); + __libc_sigprocmask(SIG_SETMASK, (const sigset_t *)&oldmask, NULL); freeaddrinfo(res); return (-1); } diff --git a/lib/libc/net/rcmdsh.c b/lib/libc/net/rcmdsh.c index bc4e87af9faff..f30ad1434bb5d 100644 --- a/lib/libc/net/rcmdsh.c +++ b/lib/libc/net/rcmdsh.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rcmdsh.c,v 1.5 1998/04/25 16:23:58 millert Exp $ */ +/* $OpenBSD: rcmdsh.c,v 1.7 2002/03/12 00:05:44 millert Exp $ */ /* * Copyright (c) 2001, MagniComp @@ -49,23 +49,18 @@ __FBSDID("$FreeBSD$"); #include <string.h> #include <unistd.h> -#ifndef _PATH_RSH -#define _PATH_RSH "/usr/bin/rsh" -#endif - /* * This is a replacement rcmd() function that uses the rsh(1) * program in place of a direct rcmd(3) function call so as to * avoid having to be root. Note that rport is ignored. */ int -rcmdsh(ahost, rport, locuser, remuser, cmd, rshprog) - char **ahost; - int rport; - const char *locuser, *remuser, *cmd, *rshprog; +rcmdsh(char **ahost, int rport, const char *locuser, const char *remuser, + const char *cmd, const char *rshprog) { struct addrinfo hints, *res; - int cpid, sp[2], error; + int sp[2], error; + pid_t cpid; char *p; struct passwd *pw; char num[8]; diff --git a/lib/libc/posix1e/acl_add_flag_np.3 b/lib/libc/posix1e/acl_add_flag_np.3 index db8e565a72d92..22048268706a8 100644 --- a/lib/libc/posix1e/acl_add_flag_np.3 +++ b/lib/libc/posix1e/acl_add_flag_np.3 @@ -25,7 +25,7 @@ .\" .\" $FreeBSD$ .\" -.Dd October 30, 2014 +.Dd September 4, 2015 .Dt ACL_ADD_FLAG_NP 3 .Os .Sh NAME @@ -56,6 +56,7 @@ Valid values are: .It ACL_ENTRY_DIRECTORY_INHERIT Ta "Will be inherited by directories." .It ACL_ENTRY_NO_PROPAGATE_INHERIT Ta "Will not propagate." .It ACL_ENTRY_INHERIT_ONLY Ta "Inherit-only." +.It ACL_ENTRY_INHERITED Ta "Inherited from parent" .El .Sh RETURN VALUES .Rv -std acl_add_flag_np diff --git a/lib/libc/posix1e/acl_entry.c b/lib/libc/posix1e/acl_entry.c index 3f8ca62c8b00e..2cffaa33d54cc 100644 --- a/lib/libc/posix1e/acl_entry.c +++ b/lib/libc/posix1e/acl_entry.c @@ -91,7 +91,7 @@ acl_create_entry_np(acl_t *acl_p, acl_entry_t *entry_p, int offset) return (-1); } - if (offset < 0 || offset >= acl_int->acl_cnt) { + if (offset < 0 || offset > acl_int->acl_cnt) { errno = EINVAL; return (-1); } diff --git a/lib/libc/posix1e/acl_flag.c b/lib/libc/posix1e/acl_flag.c index 39e258da67896..8ad10c52d9d8a 100644 --- a/lib/libc/posix1e/acl_flag.c +++ b/lib/libc/posix1e/acl_flag.c @@ -71,7 +71,7 @@ acl_clear_flags_np(acl_flagset_t flagset_d) return (-1); } - *flagset_d |= 0; + *flagset_d = 0; return (0); } diff --git a/lib/libc/posix1e/acl_init.c b/lib/libc/posix1e/acl_init.c index 4fe403777ddb5..88a1fc5aaf1c3 100644 --- a/lib/libc/posix1e/acl_init.c +++ b/lib/libc/posix1e/acl_init.c @@ -67,8 +67,10 @@ acl_init(int count) error = posix_memalign((void *)&acl, 1 << _ACL_T_ALIGNMENT_BITS, sizeof(struct acl_t_struct)); - if (error) + if (error) { + errno = error; return (NULL); + } bzero(acl, sizeof(struct acl_t_struct)); acl->ats_brand = ACL_BRAND_UNKNOWN; diff --git a/lib/libc/posix1e/acl_strip.c b/lib/libc/posix1e/acl_strip.c index 85dfb4721a3c2..24fda84806468 100644 --- a/lib/libc/posix1e/acl_strip.c +++ b/lib/libc/posix1e/acl_strip.c @@ -107,13 +107,13 @@ _posix1e_acl_strip_np(const acl_t aclp, int recalculate_mask) if (acl_get_permset(entry, &perm) == -1) goto fail; if (acl_create_entry(&acl_new, &entry_new) == -1) - return (NULL); + goto fail; if (acl_set_tag_type(entry_new, tag) == -1) - return (NULL); + goto fail; if (acl_set_permset(entry_new, perm) == -1) - return (NULL); + goto fail; if (acl_copy_entry(entry_new, entry) == -1) - return (NULL); + goto fail; assert(_entry_brand(entry_new) == ACL_BRAND_POSIX); break; case ACL_MASK: @@ -122,20 +122,22 @@ _posix1e_acl_strip_np(const acl_t aclp, int recalculate_mask) default: break; } -fail: - acl_free(acl_new); - acl_free(acl_old); - return (NULL); } assert(_acl_brand(acl_new) == ACL_BRAND_POSIX); if (have_mask_entry && recalculate_mask) { if (acl_calc_mask(&acl_new) == -1) - return (NULL); + goto fail; } return (acl_new); + +fail: + acl_free(acl_new); + acl_free(acl_old); + + return (NULL); } acl_t diff --git a/lib/libc/posix1e/acl_support_nfs4.c b/lib/libc/posix1e/acl_support_nfs4.c index 4878b4387a8ec..1eece989ad3f2 100644 --- a/lib/libc/posix1e/acl_support_nfs4.c +++ b/lib/libc/posix1e/acl_support_nfs4.c @@ -48,6 +48,7 @@ struct flagnames_struct a_flags[] = { ACL_ENTRY_NO_PROPAGATE_INHERIT, "no_propagate", 'n'}, { ACL_ENTRY_SUCCESSFUL_ACCESS, "successfull_access", 'S'}, { ACL_ENTRY_FAILED_ACCESS, "failed_access", 'F'}, + { ACL_ENTRY_INHERITED, "inherited", 'I' }, /* * There is no ACE_IDENTIFIER_GROUP here - SunOS does not show it * in the "flags" field. There is no ACE_OWNER, ACE_GROUP or diff --git a/lib/libc/posix1e/mac.3 b/lib/libc/posix1e/mac.3 index af162f8a5a467..5d2d5c4f49dfa 100644 --- a/lib/libc/posix1e/mac.3 +++ b/lib/libc/posix1e/mac.3 @@ -31,7 +31,7 @@ .\" .\" $FreeBSD$ .\" -.Dd August 7, 2009 +.Dd July 25, 2015 .Dt MAC 3 .Os .Sh NAME @@ -163,14 +163,3 @@ Support for Mandatory Access Control was introduced in as part of the .Tn TrustedBSD Project. -.Sh BUGS -The -.Tn TrustedBSD -MAC Framework and associated policies, interfaces, and -applications are considered to be an experimental feature in -.Fx . -Sites considering production deployment should keep the experimental -status of these services in mind during any deployment process. -See also -.Xr mac 9 -for related considerations regarding the kernel framework. diff --git a/lib/libc/posix1e/mac.conf.5 b/lib/libc/posix1e/mac.conf.5 index a8dfba214393e..3946be18db166 100644 --- a/lib/libc/posix1e/mac.conf.5 +++ b/lib/libc/posix1e/mac.conf.5 @@ -29,7 +29,7 @@ .\" .\" $FreeBSD$ .\" -.Dd April 19, 2003 +.Dd July 25, 2015 .Dt MAC.CONF 5 .Os .Sh NAME @@ -110,14 +110,3 @@ Support for Mandatory Access Control was introduced in as part of the .Tn TrustedBSD Project. -.Sh BUGS -The -.Tn TrustedBSD -MAC Framework and associated policies, interfaces, and -applications are considered to be an experimental feature in -.Fx . -Sites considering production deployment should keep the experimental -status of these services in mind during any deployment process. -See also -.Xr mac 9 -for related considerations regarding the kernel framework. diff --git a/lib/libc/rpc/auth_des.c b/lib/libc/rpc/auth_des.c index 1bc26615b5d40..5435e7749fdf5 100644 --- a/lib/libc/rpc/auth_des.c +++ b/lib/libc/rpc/auth_des.c @@ -69,7 +69,7 @@ __FBSDID("$FreeBSD$"); extern bool_t xdr_authdes_cred( XDR *, struct authdes_cred *); extern bool_t xdr_authdes_verf( XDR *, struct authdes_verf *); -extern int key_encryptsession_pk(); +extern int key_encryptsession_pk(char *, netobj *, des_block *); extern bool_t __rpc_get_time_offset(struct timeval *, nis_server *, char *, char **, char **); @@ -259,7 +259,7 @@ failed: */ /*ARGSUSED*/ static void -authdes_nextverf(AUTH *auth) +authdes_nextverf(AUTH *auth __unused) { /* what the heck am I supposed to do??? */ } @@ -420,7 +420,7 @@ authdes_validate(AUTH *auth, struct opaque_auth *rverf) */ /*ARGSUSED*/ static bool_t -authdes_refresh(AUTH *auth, void *dummy) +authdes_refresh(AUTH *auth, void *dummy __unused) { /* LINTED pointer alignment */ struct ad_private *ad = AUTH_PRIVATE(auth); diff --git a/lib/libc/rpc/auth_none.c b/lib/libc/rpc/auth_none.c index 311fa5581bb69..0b846ebc9b180 100644 --- a/lib/libc/rpc/auth_none.c +++ b/lib/libc/rpc/auth_none.c @@ -65,9 +65,9 @@ static bool_t authnone_validate (AUTH *, struct opaque_auth *); static bool_t authnone_refresh (AUTH *, void *); static void authnone_destroy (AUTH *); -extern bool_t xdr_opaque_auth(); +extern bool_t xdr_opaque_auth(XDR *, struct opaque_auth *); -static struct auth_ops *authnone_ops(); +static struct auth_ops *authnone_ops(void); static struct authnone_private { AUTH no_client; @@ -76,7 +76,7 @@ static struct authnone_private { } *authnone_private; AUTH * -authnone_create() +authnone_create(void) { struct authnone_private *ap = authnone_private; XDR xdr_stream; @@ -156,7 +156,7 @@ authnone_destroy(AUTH *client) } static struct auth_ops * -authnone_ops() +authnone_ops(void) { static struct auth_ops ops; diff --git a/lib/libc/rpc/auth_time.c b/lib/libc/rpc/auth_time.c index 7aea23268a571..4b714468b92e2 100644 --- a/lib/libc/rpc/auth_time.c +++ b/lib/libc/rpc/auth_time.c @@ -61,8 +61,7 @@ extern int _rpc_dtablesize( void ); static int saw_alarm = 0; static void -alarm_hndler(s) - int s; +alarm_hndler(int s) { saw_alarm = 1; return; @@ -83,12 +82,7 @@ alarm_hndler(s) * Turn a 'universal address' into a struct sockaddr_in. * Bletch. */ -static int uaddr_to_sockaddr(uaddr, sin) -#ifdef foo - endpoint *endpt; -#endif - char *uaddr; - struct sockaddr_in *sin; +static int uaddr_to_sockaddr(char *uaddr, struct sockaddr_in *sin) { unsigned char p_bytes[2]; int i; @@ -118,9 +112,7 @@ static int uaddr_to_sockaddr(uaddr, sin) * Free the strings that were strduped into the eps structure. */ static void -free_eps(eps, num) - endpoint eps[]; - int num; +free_eps(endpoint eps[], int num) { int i; @@ -142,14 +134,15 @@ free_eps(eps, num) * fact that gethostbyname() could do an NIS search. Ideally, the * NIS+ server will call __rpc_get_time_offset() with the nis_server * structure already populated. + * + * host - name of the time host + * srv - nis_server struct to use. + * eps[] - array of endpoints + * maxep - max array size */ static nis_server * -get_server(sin, host, srv, eps, maxep) - struct sockaddr_in *sin; - char *host; /* name of the time host */ - nis_server *srv; /* nis_server struct to use. */ - endpoint eps[]; /* array of endpoints */ - int maxep; /* max array size */ +get_server(struct sockaddr_in *sin, char *host, nis_server *srv, + endpoint eps[], int maxep) { char hname[256]; int num_ep = 0, i; @@ -236,14 +229,16 @@ get_server(sin, host, srv, eps, maxep) * structure and to then contact the machine for the time. * * td = "server" - "client" + * + * td - Time difference + * srv - NIS Server description + * thost - if no server, this is the timehost + * uaddr - known universal address + * netid - known network identifier */ int -__rpc_get_time_offset(td, srv, thost, uaddr, netid) - struct timeval *td; /* Time difference */ - nis_server *srv; /* NIS Server description */ - char *thost; /* if no server, this is the timehost */ - char **uaddr; /* known universal address */ - struct sockaddr_in *netid; /* known network identifier */ +__rpc_get_time_offset(struct timeval *td, nis_server *srv, char *thost, + char **uaddr, struct sockaddr_in *netid) { CLIENT *clnt; /* Client handle */ endpoint *ep, /* useful endpoints */ @@ -260,7 +255,7 @@ __rpc_get_time_offset(td, srv, thost, uaddr, netid) char ut[64], ipuaddr[64]; endpoint teps[32]; nis_server tsrv; - void (*oldsig)() = NULL; /* old alarm handler */ + void (*oldsig)(int) = NULL; /* old alarm handler */ struct sockaddr_in sin; socklen_t len; int s = RPC_ANYSOCK; @@ -429,7 +424,7 @@ __rpc_get_time_offset(td, srv, thost, uaddr, netid) } else { int res; - oldsig = (void (*)())signal(SIGALRM, alarm_hndler); + oldsig = (void (*)(int))signal(SIGALRM, alarm_hndler); saw_alarm = 0; /* global tracking the alarm */ alarm(20); /* only wait 20 seconds */ res = _connect(s, (struct sockaddr *)&sin, sizeof(sin)); diff --git a/lib/libc/rpc/clnt_bcast.c b/lib/libc/rpc/clnt_bcast.c index 6ee1f909270c2..63d3becae5036 100644 --- a/lib/libc/rpc/clnt_bcast.c +++ b/lib/libc/rpc/clnt_bcast.c @@ -251,7 +251,7 @@ rpc_broadcast_exp(prog, vers, proc, xargs, argsp, xresults, resultsp, int inlen; u_int maxbufsize = 0; AUTH *sys_auth = authunix_create_default(); - int i; + u_int i; void *handle; char uaddress[1024]; /* A self imposed limit */ char *uaddrp = uaddress; diff --git a/lib/libc/rpc/clnt_dg.c b/lib/libc/rpc/clnt_dg.c index cebbaf9e344f0..274a255ea2fc7 100644 --- a/lib/libc/rpc/clnt_dg.c +++ b/lib/libc/rpc/clnt_dg.c @@ -153,15 +153,17 @@ struct cu_data { * If they are 0, use the transport default. * * If svcaddr is NULL, returns NULL. + * + * fd - open file descriptor + * svcaddr - servers address + * program - program number + * version - version number + * sendsz - buffer recv size + * recvsz - buffer send size */ CLIENT * -clnt_dg_create(fd, svcaddr, program, version, sendsz, recvsz) - int fd; /* open file descriptor */ - const struct netbuf *svcaddr; /* servers address */ - rpcprog_t program; /* program number */ - rpcvers_t version; /* version number */ - u_int sendsz; /* buffer recv size */ - u_int recvsz; /* buffer send size */ +clnt_dg_create(int fd, const struct netbuf *svcaddr, rpcprog_t program, + rpcvers_t version, u_int sendsz, u_int recvsz) { CLIENT *cl = NULL; /* client handle */ struct cu_data *cu = NULL; /* private data */ @@ -301,15 +303,18 @@ err2: return (NULL); } +/* + * cl - client handle + * proc - procedure number + * xargs - xdr routine for args + * argsp - pointer to args + * xresults - xdr routine for results + * resultsp - pointer to results + * utimeout - seconds to wait before giving up + */ static enum clnt_stat -clnt_dg_call(cl, proc, xargs, argsp, xresults, resultsp, utimeout) - CLIENT *cl; /* client handle */ - rpcproc_t proc; /* procedure number */ - xdrproc_t xargs; /* xdr routine for args */ - void *argsp; /* pointer to args */ - xdrproc_t xresults; /* xdr routine for results */ - void *resultsp; /* pointer to results */ - struct timeval utimeout; /* seconds to wait before giving up */ +clnt_dg_call(CLIENT *cl, rpcproc_t proc, xdrproc_t xargs, void *argsp, + xdrproc_t xresults, void *resultsp, struct timeval utimeout) { struct cu_data *cu = (struct cu_data *)cl->cl_private; XDR *xdrs; @@ -602,9 +607,7 @@ out: } static void -clnt_dg_geterr(cl, errp) - CLIENT *cl; - struct rpc_err *errp; +clnt_dg_geterr(CLIENT *cl, struct rpc_err *errp) { struct cu_data *cu = (struct cu_data *)cl->cl_private; @@ -612,10 +615,7 @@ clnt_dg_geterr(cl, errp) } static bool_t -clnt_dg_freeres(cl, xdr_res, res_ptr) - CLIENT *cl; - xdrproc_t xdr_res; - void *res_ptr; +clnt_dg_freeres(CLIENT *cl, xdrproc_t xdr_res, void *res_ptr) { struct cu_data *cu = (struct cu_data *)cl->cl_private; XDR *xdrs = &(cu->cu_outxdrs); @@ -638,16 +638,12 @@ clnt_dg_freeres(cl, xdr_res, res_ptr) /*ARGSUSED*/ static void -clnt_dg_abort(h) - CLIENT *h; +clnt_dg_abort(CLIENT *h) { } static bool_t -clnt_dg_control(cl, request, info) - CLIENT *cl; - u_int request; - void *info; +clnt_dg_control(CLIENT *cl, u_int request, void *info) { struct cu_data *cu = (struct cu_data *)cl->cl_private; struct netbuf *addr; @@ -790,8 +786,7 @@ clnt_dg_control(cl, request, info) } static void -clnt_dg_destroy(cl) - CLIENT *cl; +clnt_dg_destroy(CLIENT *cl) { struct cu_data *cu = (struct cu_data *)cl->cl_private; int cu_fd = cu->cu_fd; @@ -820,7 +815,7 @@ clnt_dg_destroy(cl) } static struct clnt_ops * -clnt_dg_ops() +clnt_dg_ops(void) { static struct clnt_ops ops; sigset_t mask; @@ -848,8 +843,7 @@ clnt_dg_ops() * Make sure that the time is not garbage. -1 value is allowed. */ static bool_t -time_not_ok(t) - struct timeval *t; +time_not_ok(struct timeval *t) { return (t->tv_sec < -1 || t->tv_sec > 100000000 || t->tv_usec < -1 || t->tv_usec > 1000000); diff --git a/lib/libc/rpc/crypt_client.c b/lib/libc/rpc/crypt_client.c index 5290021a3341b..b7f0d1fff48c8 100644 --- a/lib/libc/rpc/crypt_client.c +++ b/lib/libc/rpc/crypt_client.c @@ -43,10 +43,7 @@ __FBSDID("$FreeBSD$"); #include "un-namespace.h" int -_des_crypt_call(buf, len, dparms) - char *buf; - int len; - struct desparams *dparms; +_des_crypt_call(char *buf, int len, struct desparams *dparms) { CLIENT *clnt; desresp *result_1; diff --git a/lib/libc/rpc/des_crypt.c b/lib/libc/rpc/des_crypt.c index ace8ed6ce129a..b54af4f981e8a 100644 --- a/lib/libc/rpc/des_crypt.c +++ b/lib/libc/rpc/des_crypt.c @@ -70,12 +70,7 @@ extern int _des_crypt_call(char *, int, struct desparams *); * CBC mode encryption */ int -cbc_crypt(key, buf, len, mode, ivec) - char *key; - char *buf; - unsigned len; - unsigned mode; - char *ivec; +cbc_crypt(char *key, char *buf, unsigned len, unsigned mode, char *ivec) { int err; struct desparams dp; @@ -97,11 +92,7 @@ cbc_crypt(key, buf, len, mode, ivec) * ECB mode encryption */ int -ecb_crypt(key, buf, len, mode) - char *key; - char *buf; - unsigned len; - unsigned mode; +ecb_crypt(char *key, char *buf, unsigned len, unsigned mode) { struct desparams dp; @@ -120,12 +111,8 @@ ecb_crypt(key, buf, len, mode) * Common code to cbc_crypt() & ecb_crypt() */ static int -common_crypt(key, buf, len, mode, desp) - char *key; - char *buf; - unsigned len; - unsigned mode; - struct desparams *desp; +common_crypt(char *key, char *buf, unsigned len, unsigned mode, + struct desparams *desp) { int desdev; diff --git a/lib/libc/rpc/des_soft.c b/lib/libc/rpc/des_soft.c index 80d8c5241a011..5eb99151c0e03 100644 --- a/lib/libc/rpc/des_soft.c +++ b/lib/libc/rpc/des_soft.c @@ -58,8 +58,7 @@ static char partab[128] = { * Add odd parity to low bit of 8 byte key */ void -des_setparity(p) - char *p; +des_setparity(char *p) { int i; diff --git a/lib/libc/rpc/getpublickey.c b/lib/libc/rpc/getpublickey.c index 143c0fcaeb04e..74ed98394ad5f 100644 --- a/lib/libc/rpc/getpublickey.c +++ b/lib/libc/rpc/getpublickey.c @@ -62,9 +62,7 @@ int (*__getpublickey_LOCAL)() = 0; * Get somebody's public key */ static int -__getpublickey_real(netname, publickey) - const char *netname; - char *publickey; +__getpublickey_real(const char *netname, char *publickey) { char lookup[3 * HEXKEYBYTES]; char *p; @@ -89,9 +87,7 @@ __getpublickey_real(netname, publickey) */ int -getpublicandprivatekey(key, ret) - const char *key; - char *ret; +getpublicandprivatekey(const char *key, char *ret) { char buf[1024]; /* big enough */ char *res; @@ -166,9 +162,7 @@ getpublicandprivatekey(key, ret) } } -int getpublickey(netname, publickey) - const char *netname; - char *publickey; +int getpublickey(const char *netname, char *publickey) { if (__getpublickey_LOCAL != NULL) return(__getpublickey_LOCAL(netname, publickey)); diff --git a/lib/libc/rpc/key_call.c b/lib/libc/rpc/key_call.c index 3864061c68b9d..664ddfd67668c 100644 --- a/lib/libc/rpc/key_call.c +++ b/lib/libc/rpc/key_call.c @@ -88,8 +88,7 @@ des_block *(*__key_gendes_LOCAL)() = 0; static int key_call( u_long, xdrproc_t, void *, xdrproc_t, void *); int -key_setsecret(secretkey) - const char *secretkey; +key_setsecret(const char *secretkey) { keystatus status; @@ -131,10 +130,7 @@ key_secretkey_is_set(void) } int -key_encryptsession_pk(remotename, remotekey, deskey) - char *remotename; - netobj *remotekey; - des_block *deskey; +key_encryptsession_pk(char *remotename, netobj *remotekey, des_block *deskey) { cryptkeyarg2 arg; cryptkeyres res; @@ -155,10 +151,7 @@ key_encryptsession_pk(remotename, remotekey, deskey) } int -key_decryptsession_pk(remotename, remotekey, deskey) - char *remotename; - netobj *remotekey; - des_block *deskey; +key_decryptsession_pk(char *remotename, netobj *remotekey, des_block *deskey) { cryptkeyarg2 arg; cryptkeyres res; @@ -179,9 +172,7 @@ key_decryptsession_pk(remotename, remotekey, deskey) } int -key_encryptsession(remotename, deskey) - const char *remotename; - des_block *deskey; +key_encryptsession(const char *remotename, des_block *deskey) { cryptkeyarg arg; cryptkeyres res; @@ -201,9 +192,7 @@ key_encryptsession(remotename, deskey) } int -key_decryptsession(remotename, deskey) - const char *remotename; - des_block *deskey; +key_decryptsession(const char *remotename, des_block *deskey) { cryptkeyarg arg; cryptkeyres res; @@ -223,8 +212,7 @@ key_decryptsession(remotename, deskey) } int -key_gendes(key) - des_block *key; +key_gendes(des_block *key) { if (!key_call((u_long)KEY_GEN, (xdrproc_t)xdr_void, NULL, (xdrproc_t)xdr_des_block, key)) { @@ -234,8 +222,7 @@ key_gendes(key) } int -key_setnet(arg) -struct key_netstarg *arg; +key_setnet(struct key_netstarg *arg) { keystatus status; @@ -254,9 +241,7 @@ struct key_netstarg *arg; int -key_get_conv(pkey, deskey) - char *pkey; - des_block *deskey; +key_get_conv(char *pkey, des_block *deskey) { cryptkeyres res; @@ -305,8 +290,7 @@ key_call_init(void) * Keep the handle cached. This call may be made quite often. */ static CLIENT * -getkeyserv_handle(vers) -int vers; +getkeyserv_handle(int vers) { void *localhandle; struct netconfig *nconf; @@ -429,12 +413,8 @@ int vers; /* returns 0 on failure, 1 on success */ static int -key_call(proc, xdr_arg, arg, xdr_rslt, rslt) - u_long proc; - xdrproc_t xdr_arg; - void *arg; - xdrproc_t xdr_rslt; - void *rslt; +key_call(u_long proc, xdrproc_t xdr_arg, void *arg, xdrproc_t xdr_rslt, + void *rslt) { CLIENT *clnt; struct timeval wait_time; diff --git a/lib/libc/rpc/rpc_prot.c b/lib/libc/rpc/rpc_prot.c index 20dc8fa3484cd..d4fdd90d84286 100644 --- a/lib/libc/rpc/rpc_prot.c +++ b/lib/libc/rpc/rpc_prot.c @@ -68,9 +68,7 @@ extern struct opaque_auth _null_auth; * (see auth.h) */ bool_t -xdr_opaque_auth(xdrs, ap) - XDR *xdrs; - struct opaque_auth *ap; +xdr_opaque_auth(XDR *xdrs, struct opaque_auth *ap) { assert(xdrs != NULL); @@ -86,9 +84,7 @@ xdr_opaque_auth(xdrs, ap) * XDR a DES block */ bool_t -xdr_des_block(xdrs, blkp) - XDR *xdrs; - des_block *blkp; +xdr_des_block(XDR *xdrs, des_block *blkp) { assert(xdrs != NULL); @@ -103,9 +99,7 @@ xdr_des_block(xdrs, blkp) * XDR the MSG_ACCEPTED part of a reply message union */ bool_t -xdr_accepted_reply(xdrs, ar) - XDR *xdrs; - struct accepted_reply *ar; +xdr_accepted_reply(XDR *xdrs, struct accepted_reply *ar) { enum accept_stat *par_stat; @@ -142,9 +136,7 @@ xdr_accepted_reply(xdrs, ar) * XDR the MSG_DENIED part of a reply message union */ bool_t -xdr_rejected_reply(xdrs, rr) - XDR *xdrs; - struct rejected_reply *rr; +xdr_rejected_reply(XDR *xdrs, struct rejected_reply *rr) { enum reject_stat *prj_stat; enum auth_stat *prj_why; @@ -182,9 +174,7 @@ static const struct xdr_discrim reply_dscrm[3] = { * XDR a reply message */ bool_t -xdr_replymsg(xdrs, rmsg) - XDR *xdrs; - struct rpc_msg *rmsg; +xdr_replymsg(XDR *xdrs, struct rpc_msg *rmsg) { enum msg_type *prm_direction; enum reply_stat *prp_stat; @@ -212,9 +202,7 @@ xdr_replymsg(xdrs, rmsg) * The rm_xid is not really static, but the user can easily munge on the fly. */ bool_t -xdr_callhdr(xdrs, cmsg) - XDR *xdrs; - struct rpc_msg *cmsg; +xdr_callhdr(XDR *xdrs, struct rpc_msg *cmsg) { enum msg_type *prm_direction; @@ -238,9 +226,7 @@ xdr_callhdr(xdrs, cmsg) /* ************************** Client utility routine ************* */ static void -accepted(acpt_stat, error) - enum accept_stat acpt_stat; - struct rpc_err *error; +accepted(enum accept_stat acpt_stat, struct rpc_err *error) { assert(error != NULL); diff --git a/lib/libc/rpc/rpc_soc.c b/lib/libc/rpc/rpc_soc.c index febc597c5d943..b7f6651d1a295 100644 --- a/lib/libc/rpc/rpc_soc.c +++ b/lib/libc/rpc/rpc_soc.c @@ -88,14 +88,8 @@ static bool_t rpc_wrap_bcast(char *, struct netbuf *, struct netconfig *); * A common clnt create routine */ static CLIENT * -clnt_com_create(raddr, prog, vers, sockp, sendsz, recvsz, tp) - struct sockaddr_in *raddr; - rpcprog_t prog; - rpcvers_t vers; - int *sockp; - u_int sendsz; - u_int recvsz; - char *tp; +clnt_com_create(struct sockaddr_in *raddr, rpcprog_t prog, rpcvers_t vers, int *sockp, + u_int sendsz, u_int recvsz, char *tp) { CLIENT *cl; int madefd = FALSE; @@ -164,14 +158,8 @@ err: if (madefd == TRUE) } CLIENT * -clntudp_bufcreate(raddr, prog, vers, wait, sockp, sendsz, recvsz) - struct sockaddr_in *raddr; - u_long prog; - u_long vers; - struct timeval wait; - int *sockp; - u_int sendsz; - u_int recvsz; +clntudp_bufcreate(struct sockaddr_in *raddr, u_long prog, u_long vers, + struct timeval wait, int *sockp, u_int sendsz, u_int recvsz) { CLIENT *cl; @@ -185,12 +173,8 @@ clntudp_bufcreate(raddr, prog, vers, wait, sockp, sendsz, recvsz) } CLIENT * -clntudp_create(raddr, program, version, wait, sockp) - struct sockaddr_in *raddr; - u_long program; - u_long version; - struct timeval wait; - int *sockp; +clntudp_create(struct sockaddr_in *raddr, u_long program, u_long version, + struct timeval wait, int *sockp) { return clntudp_bufcreate(raddr, program, version, wait, sockp, @@ -198,13 +182,8 @@ clntudp_create(raddr, program, version, wait, sockp) } CLIENT * -clnttcp_create(raddr, prog, vers, sockp, sendsz, recvsz) - struct sockaddr_in *raddr; - u_long prog; - u_long vers; - int *sockp; - u_int sendsz; - u_int recvsz; +clnttcp_create(struct sockaddr_in *raddr, u_long prog, u_long vers, int *sockp, + u_int sendsz, u_int recvsz) { return clnt_com_create(raddr, (rpcprog_t)prog, (rpcvers_t)vers, sockp, @@ -212,9 +191,7 @@ clnttcp_create(raddr, prog, vers, sockp, sendsz, recvsz) } CLIENT * -clntraw_create(prog, vers) - u_long prog; - u_long vers; +clntraw_create(u_long prog, u_long vers) { return clnt_raw_create((rpcprog_t)prog, (rpcvers_t)vers); @@ -224,11 +201,7 @@ clntraw_create(prog, vers) * A common server create routine */ static SVCXPRT * -svc_com_create(fd, sendsize, recvsize, netid) - int fd; - u_int sendsize; - u_int recvsize; - char *netid; +svc_com_create(int fd, u_int sendsize, u_int recvsize, char *netid) { struct netconfig *nconf; SVCXPRT *svc; @@ -268,29 +241,21 @@ svc_com_create(fd, sendsize, recvsize, netid) } SVCXPRT * -svctcp_create(fd, sendsize, recvsize) - int fd; - u_int sendsize; - u_int recvsize; +svctcp_create(int fd, u_int sendsize, u_int recvsize) { return svc_com_create(fd, sendsize, recvsize, "tcp"); } SVCXPRT * -svcudp_bufcreate(fd, sendsz, recvsz) - int fd; - u_int sendsz, recvsz; +svcudp_bufcreate(int fd, u_int sendsz, u_int recvsz) { return svc_com_create(fd, sendsz, recvsz, "udp"); } SVCXPRT * -svcfd_create(fd, sendsize, recvsize) - int fd; - u_int sendsize; - u_int recvsize; +svcfd_create(int fd, u_int sendsize, u_int recvsize) { return svc_fd_create(fd, sendsize, recvsize); @@ -298,8 +263,7 @@ svcfd_create(fd, sendsize, recvsize) SVCXPRT * -svcudp_create(fd) - int fd; +svcudp_create(int fd) { return svc_com_create(fd, UDPMSGSIZE, UDPMSGSIZE, "udp"); @@ -313,8 +277,7 @@ svcraw_create() } int -get_myaddress(addr) - struct sockaddr_in *addr; +get_myaddress(struct sockaddr_in *addr) { memset((void *) addr, 0, sizeof(*addr)); @@ -328,11 +291,8 @@ get_myaddress(addr) * For connectionless "udp" transport. Obsoleted by rpc_call(). */ int -callrpc(host, prognum, versnum, procnum, inproc, in, outproc, out) - const char *host; - int prognum, versnum, procnum; - xdrproc_t inproc, outproc; - void *in, *out; +callrpc(const char *host, int prognum, int versnum, int procnum, + xdrproc_t inproc, void *in, xdrproc_t outproc, void *out) { return (int)rpc_call(host, (rpcprog_t)prognum, (rpcvers_t)versnum, @@ -343,10 +303,9 @@ callrpc(host, prognum, versnum, procnum, inproc, in, outproc, out) * For connectionless kind of transport. Obsoleted by rpc_reg() */ int -registerrpc(prognum, versnum, procnum, progname, inproc, outproc) - int prognum, versnum, procnum; - char *(*progname)(char [UDPMSGSIZE]); - xdrproc_t inproc, outproc; +registerrpc(int prognum, int versnum, int procnum, + char *(*progname)(char [UDPMSGSIZE]), + xdrproc_t inproc, xdrproc_t outproc) { return rpc_reg((rpcprog_t)prognum, (rpcvers_t)versnum, @@ -374,10 +333,12 @@ clnt_broadcast_key_init(void) */ /* ARGSUSED */ static bool_t -rpc_wrap_bcast(resultp, addr, nconf) - char *resultp; /* results of the call */ - struct netbuf *addr; /* address of the guy who responded */ - struct netconfig *nconf; /* Netconf of the transport */ +rpc_wrap_bcast(char *resultp, struct netbuf *addr, struct netconfig *nconf) +/* + * char *resultp; // results of the call + * struct netbuf *addr; // address of the guy who responded + * struct netconfig *nconf; // Netconf of the transport + */ { resultproc_t clnt_broadcast_result; @@ -395,15 +356,18 @@ rpc_wrap_bcast(resultp, addr, nconf) * Broadcasts on UDP transport. Obsoleted by rpc_broadcast(). */ enum clnt_stat -clnt_broadcast(prog, vers, proc, xargs, argsp, xresults, resultsp, eachresult) - u_long prog; /* program number */ - u_long vers; /* version number */ - u_long proc; /* procedure number */ - xdrproc_t xargs; /* xdr routine for args */ - void *argsp; /* pointer to args */ - xdrproc_t xresults; /* xdr routine for results */ - void *resultsp; /* pointer to results */ - resultproc_t eachresult; /* call with each result obtained */ +clnt_broadcast(u_long prog, u_long vers, u_long proc, xdrproc_t xargs, + void *argsp, xdrproc_t xresults, void *resultsp, resultproc_t eachresult) +/* + * u_long prog; // program number + * u_long vers; // version number + * u_long proc; // procedure number + * xdrproc_t xargs; // xdr routine for args + * void *argsp; // pointer to args + * xdrproc_t xresults; // xdr routine for results + * void *resultsp; // pointer to results + * resultproc_t eachresult; // call with each result obtained + */ { if (thr_main()) @@ -422,11 +386,14 @@ clnt_broadcast(prog, vers, proc, xargs, argsp, xresults, resultsp, eachresult) * authdes_seccreate(). */ AUTH * -authdes_create(servername, window, syncaddr, ckey) - char *servername; /* network name of server */ - u_int window; /* time to live */ - struct sockaddr *syncaddr; /* optional hostaddr to sync with */ - des_block *ckey; /* optional conversation key to use */ +authdes_create(char *servername, u_int window, struct sockaddr *syncaddr, + des_block *ckey) +/* + * char *servername; // network name of server + * u_int window; // time to live + * struct sockaddr *syncaddr; // optional hostaddr to sync with + * des_block *ckey; // optional conversation key to use + */ { AUTH *dummy; AUTH *nauth; @@ -453,13 +420,8 @@ fallback: * Create a client handle for a unix connection. Obsoleted by clnt_vc_create() */ CLIENT * -clntunix_create(raddr, prog, vers, sockp, sendsz, recvsz) - struct sockaddr_un *raddr; - u_long prog; - u_long vers; - int *sockp; - u_int sendsz; - u_int recvsz; +clntunix_create(struct sockaddr_un *raddr, u_long prog, u_long vers, int *sockp, + u_int sendsz, u_int recvsz) { struct netbuf *svcaddr; CLIENT *cl; @@ -504,11 +466,7 @@ done: * Obsoleted by svc_vc_create(). */ SVCXPRT * -svcunix_create(sock, sendsize, recvsize, path) - int sock; - u_int sendsize; - u_int recvsize; - char *path; +svcunix_create(int sock, u_int sendsize, u_int recvsize, char *path) { struct netconfig *nconf; void *localhandle; @@ -568,10 +526,7 @@ done: * descriptor as its first input. Obsoleted by svc_fd_create(); */ SVCXPRT * -svcunixfd_create(fd, sendsize, recvsize) - int fd; - u_int sendsize; - u_int recvsize; +svcunixfd_create(int fd, u_int sendsize, u_int recvsize) { return (svc_fd_create(fd, sendsize, recvsize)); } diff --git a/lib/libc/rpc/rpcb_clnt.c b/lib/libc/rpc/rpcb_clnt.c index a0d840e65f4e1..c0c8c03474ec9 100644 --- a/lib/libc/rpc/rpcb_clnt.c +++ b/lib/libc/rpc/rpcb_clnt.c @@ -109,9 +109,7 @@ static struct netbuf *got_entry(rpcb_entry_list_ptr, const struct netconfig *); * These are private routines that may not be provided in future releases. */ bool_t -__rpc_control(request, info) - int request; - void *info; +__rpc_control(int request, void *info) { switch (request) { case CLCR_GET_RPCB_TIMEOUT: @@ -150,8 +148,7 @@ __rpc_control(request, info) */ static struct address_cache * -check_cache(host, netid) - const char *host, *netid; +check_cache(const char *host, const char *netid) { struct address_cache *cptr; @@ -171,8 +168,7 @@ check_cache(host, netid) } static void -delete_cache(addr) - struct netbuf *addr; +delete_cache(struct netbuf *addr) { struct address_cache *cptr, *prevptr = NULL; @@ -286,10 +282,7 @@ out: * On error, returns NULL and free's everything. */ static CLIENT * -getclnthandle(host, nconf, targaddr) - const char *host; - const struct netconfig *nconf; - char **targaddr; +getclnthandle(const char *host, const struct netconfig *nconf, char **targaddr) { CLIENT *client; struct netbuf *addr, taddr; @@ -531,13 +524,13 @@ try_nconf: /* * Set a mapping between program, version and address. * Calls the rpcbind service to do the mapping. + * + * nconf - Network structure of transport + * address - Services netconfig address */ bool_t -rpcb_set(program, version, nconf, address) - rpcprog_t program; - rpcvers_t version; - const struct netconfig *nconf; /* Network structure of transport */ - const struct netbuf *address; /* Services netconfig address */ +rpcb_set(rpcprog_t program, rpcvers_t version, const struct netconfig *nconf, + const struct netbuf *address) { CLIENT *client; bool_t rslt = FALSE; @@ -594,10 +587,7 @@ rpcb_set(program, version, nconf, address) * only for the given transport. */ bool_t -rpcb_unset(program, version, nconf) - rpcprog_t program; - rpcvers_t version; - const struct netconfig *nconf; +rpcb_unset(rpcprog_t program, rpcvers_t version, const struct netconfig *nconf) { CLIENT *client; bool_t rslt = FALSE; @@ -634,9 +624,7 @@ rpcb_unset(program, version, nconf) * From the merged list, find the appropriate entry */ static struct netbuf * -got_entry(relp, nconf) - rpcb_entry_list_ptr relp; - const struct netconfig *nconf; +got_entry(rpcb_entry_list_ptr relp, const struct netconfig *nconf) { struct netbuf *na = NULL; rpcb_entry_list_ptr sp; @@ -667,7 +655,7 @@ got_entry(relp, nconf) * local transport. */ static bool_t -__rpcbind_is_up() +__rpcbind_is_up(void) { struct netconfig *nconf; struct sockaddr_un sun; @@ -722,13 +710,9 @@ __rpcbind_is_up() * starts working properly. Also look under clnt_vc.c. */ struct netbuf * -__rpcb_findaddr_timed(program, version, nconf, host, clpp, tp) - rpcprog_t program; - rpcvers_t version; - const struct netconfig *nconf; - const char *host; - CLIENT **clpp; - struct timeval *tp; +__rpcb_findaddr_timed(rpcprog_t program, rpcvers_t version, + const struct netconfig *nconf, const char *host, + CLIENT **clpp, struct timeval *tp) { static bool_t check_rpcbind = TRUE; CLIENT *client = NULL; @@ -1037,12 +1021,8 @@ done: * Assuming that the address is all properly allocated */ int -rpcb_getaddr(program, version, nconf, address, host) - rpcprog_t program; - rpcvers_t version; - const struct netconfig *nconf; - struct netbuf *address; - const char *host; +rpcb_getaddr(rpcprog_t program, rpcvers_t version, const struct netconfig *nconf, + struct netbuf *address, const char *host) { struct netbuf *na; @@ -1073,9 +1053,7 @@ rpcb_getaddr(program, version, nconf, address, host) * It returns NULL on failure. */ rpcblist * -rpcb_getmaps(nconf, host) - const struct netconfig *nconf; - const char *host; +rpcb_getmaps(const struct netconfig *nconf, const char *host) { rpcblist_ptr head = NULL; CLIENT *client; @@ -1206,9 +1184,7 @@ error: * Returns 1 if succeeds else 0. */ bool_t -rpcb_gettime(host, timep) - const char *host; - time_t *timep; +rpcb_gettime(const char *host, time_t *timep) { CLIENT *client = NULL; void *handle; @@ -1267,9 +1243,7 @@ rpcb_gettime(host, timep) * really be called because local n2a libraries are always provided. */ char * -rpcb_taddr2uaddr(nconf, taddr) - struct netconfig *nconf; - struct netbuf *taddr; +rpcb_taddr2uaddr(struct netconfig *nconf, struct netbuf *taddr) { CLIENT *client; char *uaddr = NULL; @@ -1301,9 +1275,7 @@ rpcb_taddr2uaddr(nconf, taddr) * really be called because local n2a libraries are always provided. */ struct netbuf * -rpcb_uaddr2taddr(nconf, uaddr) - struct netconfig *nconf; - char *uaddr; +rpcb_uaddr2taddr(struct netconfig *nconf, char *uaddr) { CLIENT *client; struct netbuf *taddr; diff --git a/lib/libc/rpc/rpcdname.c b/lib/libc/rpc/rpcdname.c index d6a21c9a9461b..f214b2122d5df 100644 --- a/lib/libc/rpc/rpcdname.c +++ b/lib/libc/rpc/rpcdname.c @@ -46,7 +46,7 @@ __FBSDID("$FreeBSD$"); static char *default_domain = 0; static char * -get_default_domain() +get_default_domain(void) { char temp[256]; @@ -71,8 +71,7 @@ get_default_domain() * get rejected elsewhere in the NIS client package. */ int -__rpc_get_default_domain(domain) - char **domain; +__rpc_get_default_domain(char **domain) { if ((*domain = get_default_domain()) != 0) return (0); diff --git a/lib/libc/rpc/rtime.c b/lib/libc/rpc/rtime.c index 807b14c7240ce..37bc9a38faab9 100644 --- a/lib/libc/rpc/rtime.c +++ b/lib/libc/rpc/rtime.c @@ -67,10 +67,8 @@ extern int _rpc_dtablesize( void ); static void do_close( int ); int -rtime(addrp, timep, timeout) - struct sockaddr_in *addrp; - struct timeval *timep; - struct timeval *timeout; +rtime(struct sockaddr_in *addrp, struct timeval *timep, + struct timeval *timeout) { int s; fd_set readfds; @@ -148,8 +146,7 @@ rtime(addrp, timep, timeout) } static void -do_close(s) - int s; +do_close(int s) { int save; diff --git a/lib/libc/rpc/svc_auth.c b/lib/libc/rpc/svc_auth.c index 20685298474ab..6fe5bec2162a8 100644 --- a/lib/libc/rpc/svc_auth.c +++ b/lib/libc/rpc/svc_auth.c @@ -151,11 +151,7 @@ _authenticate(rqst, msg) * that don't need to inspect or modify the message body. */ static bool_t -svcauth_null_wrap(auth, xdrs, xdr_func, xdr_ptr) - SVCAUTH *auth; - XDR *xdrs; - xdrproc_t xdr_func; - caddr_t xdr_ptr; +svcauth_null_wrap(SVCAUTH *auth, XDR *xdrs, xdrproc_t xdr_func, caddr_t xdr_ptr) { return (xdr_func(xdrs, xdr_ptr)); @@ -168,9 +164,7 @@ struct svc_auth_ops svc_auth_null_ops = { /*ARGSUSED*/ enum auth_stat -_svcauth_null(rqst, msg) - struct svc_req *rqst; - struct rpc_msg *msg; +_svcauth_null(struct svc_req *rqst, struct rpc_msg *msg) { return (AUTH_OK); } @@ -190,9 +184,8 @@ _svcauth_null(rqst, msg) */ int -svc_auth_reg(cred_flavor, handler) - int cred_flavor; - enum auth_stat (*handler)(struct svc_req *, struct rpc_msg *); +svc_auth_reg(int cred_flavor, + enum auth_stat (*handler)(struct svc_req *, struct rpc_msg *)) { struct authsvc *asp; diff --git a/lib/libc/rpc/svc_auth_des.c b/lib/libc/rpc/svc_auth_des.c index d6fb6afa60d49..7a24c06e34e01 100644 --- a/lib/libc/rpc/svc_auth_des.c +++ b/lib/libc/rpc/svc_auth_des.c @@ -90,11 +90,11 @@ struct cache_entry { static struct cache_entry *authdes_cache/* [AUTHDES_CACHESZ] */; static short *authdes_lru/* [AUTHDES_CACHESZ] */; -static void cache_init(); /* initialize the cache */ -static short cache_spot(); /* find an entry in the cache */ -static void cache_ref(/*short sid*/); /* note that sid was ref'd */ +static void cache_init(void); /* initialize the cache */ +static short cache_spot(des_block *, char *, struct timeval *); /* find an entry in the cache */ +static void cache_ref(short sid); /* note that sid was ref'd */ -static void invalidate(); /* invalidate entry in cache */ +static void invalidate(char *); /* invalidate entry in cache */ /* * cache statistics @@ -109,9 +109,7 @@ static struct { * Service side authenticator for AUTH_DES */ enum auth_stat -_svcauth_des(rqst, msg) - struct svc_req *rqst; - struct rpc_msg *msg; +_svcauth_des(struct svc_req *rqst, struct rpc_msg *msg) { long *ixdr; @@ -355,7 +353,7 @@ _svcauth_des(rqst, msg) * Initialize the cache */ static void -cache_init() +cache_init(void) { int i; @@ -378,7 +376,7 @@ cache_init() * Find the lru victim */ static short -cache_victim() +cache_victim(void) { return (authdes_lru[AUTHDES_CACHESZ-1]); } @@ -387,8 +385,7 @@ cache_victim() * Note that sid was referenced */ static void -cache_ref(sid) - short sid; +cache_ref(short sid) { int i; short curr; @@ -410,10 +407,7 @@ cache_ref(sid) * return the spot in the cache. */ static short -cache_spot(key, name, timestamp) - des_block *key; - char *name; - struct timeval *timestamp; +cache_spot(des_block *key, char *name, struct timeval *timestamp) { struct cache_entry *cp; int i; @@ -461,12 +455,8 @@ struct bsdcred { * the credential. */ int -authdes_getucred(adc, uid, gid, grouplen, groups) - struct authdes_cred *adc; - uid_t *uid; - gid_t *gid; - int *grouplen; - gid_t *groups; +authdes_getucred(struct authdes_cred *adc, uid_t *uid, gid_t *gid, + int *grouplen, gid_t *groups) { unsigned sid; int i; @@ -525,8 +515,7 @@ authdes_getucred(adc, uid, gid, grouplen, groups) } static void -invalidate(cred) - char *cred; +invalidate(char *cred) { if (cred == NULL) { return; diff --git a/lib/libc/rpc/svc_dg.c b/lib/libc/rpc/svc_dg.c index 980e39f1b894a..1957d64b4ea3f 100644 --- a/lib/libc/rpc/svc_dg.c +++ b/lib/libc/rpc/svc_dg.c @@ -102,10 +102,7 @@ static const char svc_dg_err4[] = "cannot set IP_RECVDSTADDR"; static const char __no_mem_str[] = "out of memory"; SVCXPRT * -svc_dg_create(fd, sendsize, recvsize) - int fd; - u_int sendsize; - u_int recvsize; +svc_dg_create(int fd, u_int sendsize, u_int recvsize) { SVCXPRT *xprt; struct svc_dg_data *su = NULL; @@ -188,8 +185,7 @@ freedata_nowarn: /*ARGSUSED*/ static enum xprt_stat -svc_dg_stat(xprt) - SVCXPRT *xprt; +svc_dg_stat(SVCXPRT *xprt) { return (XPRT_IDLE); } @@ -250,9 +246,7 @@ svc_dg_recvfrom(int fd, char *buf, int buflen, } static bool_t -svc_dg_recv(xprt, msg) - SVCXPRT *xprt; - struct rpc_msg *msg; +svc_dg_recv(SVCXPRT *xprt, struct rpc_msg *msg) { struct svc_dg_data *su = su_data(xprt); XDR *xdrs = &(su->su_xdrs); @@ -335,9 +329,7 @@ svc_dg_sendto(int fd, char *buf, int buflen, } static bool_t -svc_dg_reply(xprt, msg) - SVCXPRT *xprt; - struct rpc_msg *msg; +svc_dg_reply(SVCXPRT *xprt, struct rpc_msg *msg) { struct svc_dg_data *su = su_data(xprt); XDR *xdrs = &(su->su_xdrs); @@ -378,10 +370,7 @@ svc_dg_reply(xprt, msg) } static bool_t -svc_dg_getargs(xprt, xdr_args, args_ptr) - SVCXPRT *xprt; - xdrproc_t xdr_args; - void *args_ptr; +svc_dg_getargs(SVCXPRT *xprt, xdrproc_t xdr_args, void *args_ptr) { struct svc_dg_data *su; @@ -392,10 +381,7 @@ svc_dg_getargs(xprt, xdr_args, args_ptr) } static bool_t -svc_dg_freeargs(xprt, xdr_args, args_ptr) - SVCXPRT *xprt; - xdrproc_t xdr_args; - void *args_ptr; +svc_dg_freeargs(SVCXPRT *xprt, xdrproc_t xdr_args, void *args_ptr) { XDR *xdrs = &(su_data(xprt)->su_xdrs); @@ -404,8 +390,7 @@ svc_dg_freeargs(xprt, xdr_args, args_ptr) } static void -svc_dg_destroy(xprt) - SVCXPRT *xprt; +svc_dg_destroy(SVCXPRT *xprt) { struct svc_dg_data *su = su_data(xprt); @@ -428,17 +413,13 @@ svc_dg_destroy(xprt) static bool_t /*ARGSUSED*/ -svc_dg_control(xprt, rq, in) - SVCXPRT *xprt; - const u_int rq; - void *in; +svc_dg_control(SVCXPRT *xprt, const u_int rq, void *in) { return (FALSE); } static void -svc_dg_ops(xprt) - SVCXPRT *xprt; +svc_dg_ops(SVCXPRT *xprt) { static struct xp_ops ops; static struct xp_ops2 ops2; @@ -536,9 +517,7 @@ static const char alloc_err[] = "could not allocate cache "; static const char enable_err[] = "cache already enabled"; int -svc_dg_enablecache(transp, size) - SVCXPRT *transp; - u_int size; +svc_dg_enablecache(SVCXPRT *transp, u_int size) { struct svc_dg_data *su = su_data(transp); struct cl_cache *uc; @@ -593,9 +572,7 @@ static const char cache_set_err2[] = "victim alloc failed"; static const char cache_set_err3[] = "could not allocate new rpc buffer"; static void -cache_set(xprt, replylen) - SVCXPRT *xprt; - size_t replylen; +cache_set(SVCXPRT *xprt, size_t replylen) { cache_ptr victim; cache_ptr *vicp; @@ -683,11 +660,7 @@ cache_set(xprt, replylen) * return 1 if found, 0 if not found and set the stage for cache_set() */ static int -cache_get(xprt, msg, replyp, replylenp) - SVCXPRT *xprt; - struct rpc_msg *msg; - char **replyp; - size_t *replylenp; +cache_get(SVCXPRT *xprt, struct rpc_msg *msg, char **replyp, size_t *replylenp) { u_int loc; cache_ptr ent; diff --git a/lib/libc/rpc/svc_vc.c b/lib/libc/rpc/svc_vc.c index aa45396667898..ca4b93e4fbf7c 100644 --- a/lib/libc/rpc/svc_vc.c +++ b/lib/libc/rpc/svc_vc.c @@ -123,10 +123,7 @@ struct cf_conn { /* kept in xprt->xp_p1 for actual connection */ * 0 => use the system default. */ SVCXPRT * -svc_vc_create(fd, sendsize, recvsize) - int fd; - u_int sendsize; - u_int recvsize; +svc_vc_create(int fd, u_int sendsize, u_int recvsize) { SVCXPRT *xprt = NULL; struct cf_rendezvous *r = NULL; @@ -186,10 +183,7 @@ cleanup_svc_vc_create: * descriptor as its first input. */ SVCXPRT * -svc_fd_create(fd, sendsize, recvsize) - int fd; - u_int sendsize; - u_int recvsize; +svc_fd_create(int fd, u_int sendsize, u_int recvsize) { struct sockaddr_storage ss; socklen_t slen; @@ -243,10 +237,7 @@ freedata: } static SVCXPRT * -makefd_xprt(fd, sendsize, recvsize) - int fd; - u_int sendsize; - u_int recvsize; +makefd_xprt(int fd, u_int sendsize, u_int recvsize) { SVCXPRT *xprt; struct cf_conn *cd; @@ -285,9 +276,7 @@ done: /*ARGSUSED*/ static bool_t -rendezvous_request(xprt, msg) - SVCXPRT *xprt; - struct rpc_msg *msg; +rendezvous_request(SVCXPRT *xprt, struct rpc_msg *msg) { int sock, flags; struct cf_rendezvous *r; @@ -366,16 +355,14 @@ again: /*ARGSUSED*/ static enum xprt_stat -rendezvous_stat(xprt) - SVCXPRT *xprt; +rendezvous_stat(SVCXPRT *xprt) { return (XPRT_IDLE); } static void -svc_vc_destroy(xprt) - SVCXPRT *xprt; +svc_vc_destroy(SVCXPRT *xprt) { assert(xprt != NULL); @@ -384,8 +371,7 @@ svc_vc_destroy(xprt) } static void -__svc_vc_dodestroy(xprt) - SVCXPRT *xprt; +__svc_vc_dodestroy(SVCXPRT *xprt) { struct cf_conn *cd; struct cf_rendezvous *r; @@ -417,19 +403,13 @@ __svc_vc_dodestroy(xprt) /*ARGSUSED*/ static bool_t -svc_vc_control(xprt, rq, in) - SVCXPRT *xprt; - const u_int rq; - void *in; +svc_vc_control(SVCXPRT *xprt, const u_int rq, void *in) { return (FALSE); } static bool_t -svc_vc_rendezvous_control(xprt, rq, in) - SVCXPRT *xprt; - const u_int rq; - void *in; +svc_vc_rendezvous_control(SVCXPRT *xprt, const u_int rq, void *in) { struct cf_rendezvous *cfp; @@ -457,10 +437,7 @@ svc_vc_rendezvous_control(xprt, rq, in) * fatal for the connection. */ static int -read_vc(xprtp, buf, len) - void *xprtp; - void *buf; - int len; +read_vc(void *xprtp, void *buf, int len) { SVCXPRT *xprt; int sock; @@ -520,10 +497,7 @@ fatal_err: * Any error is fatal and the connection is closed. */ static int -write_vc(xprtp, buf, len) - void *xprtp; - void *buf; - int len; +write_vc(void *xprtp, void *buf, int len) { SVCXPRT *xprt; int i, cnt; @@ -567,8 +541,7 @@ write_vc(xprtp, buf, len) } static enum xprt_stat -svc_vc_stat(xprt) - SVCXPRT *xprt; +svc_vc_stat(SVCXPRT *xprt) { struct cf_conn *cd; @@ -584,9 +557,7 @@ svc_vc_stat(xprt) } static bool_t -svc_vc_recv(xprt, msg) - SVCXPRT *xprt; - struct rpc_msg *msg; +svc_vc_recv(SVCXPRT *xprt, struct rpc_msg *msg) { struct cf_conn *cd; XDR *xdrs; @@ -614,10 +585,7 @@ svc_vc_recv(xprt, msg) } static bool_t -svc_vc_getargs(xprt, xdr_args, args_ptr) - SVCXPRT *xprt; - xdrproc_t xdr_args; - void *args_ptr; +svc_vc_getargs(SVCXPRT *xprt, xdrproc_t xdr_args, void *args_ptr) { struct cf_conn *cd; @@ -628,10 +596,7 @@ svc_vc_getargs(xprt, xdr_args, args_ptr) } static bool_t -svc_vc_freeargs(xprt, xdr_args, args_ptr) - SVCXPRT *xprt; - xdrproc_t xdr_args; - void *args_ptr; +svc_vc_freeargs(SVCXPRT *xprt, xdrproc_t xdr_args, void *args_ptr) { XDR *xdrs; @@ -645,9 +610,7 @@ svc_vc_freeargs(xprt, xdr_args, args_ptr) } static bool_t -svc_vc_reply(xprt, msg) - SVCXPRT *xprt; - struct rpc_msg *msg; +svc_vc_reply(SVCXPRT *xprt, struct rpc_msg *msg) { struct cf_conn *cd; XDR *xdrs; @@ -689,8 +652,7 @@ svc_vc_reply(xprt, msg) } static void -svc_vc_ops(xprt) - SVCXPRT *xprt; +svc_vc_ops(SVCXPRT *xprt) { static struct xp_ops ops; static struct xp_ops2 ops2; @@ -713,8 +675,7 @@ svc_vc_ops(xprt) } static void -svc_vc_rendezvous_ops(xprt) - SVCXPRT *xprt; +svc_vc_rendezvous_ops(SVCXPRT *xprt) { static struct xp_ops ops; static struct xp_ops2 ops2; diff --git a/lib/libc/secure/Makefile.inc b/lib/libc/secure/Makefile.inc new file mode 100644 index 0000000000000..6f18bded1ff5c --- /dev/null +++ b/lib/libc/secure/Makefile.inc @@ -0,0 +1,12 @@ +# $FreeBSD$ +# +# libc sources related to security + +.PATH: ${LIBC_SRCTOP}/secure + +# Sources common to both syscall interfaces: +SRCS+= \ + stack_protector.c \ + stack_protector_compat.c + +SYM_MAPS+= ${LIBC_SRCTOP}/secure/Symbol.map diff --git a/lib/libc/secure/Symbol.map b/lib/libc/secure/Symbol.map new file mode 100644 index 0000000000000..aaa76c17291a1 --- /dev/null +++ b/lib/libc/secure/Symbol.map @@ -0,0 +1,9 @@ +/* + * $FreeBSD$ + */ + +FBSD_1.0 { + __chk_fail; + __stack_chk_fail; + __stack_chk_guard; +}; diff --git a/lib/libc/sys/stack_protector.c b/lib/libc/secure/stack_protector.c index cd5f166e92866..cd5f166e92866 100644 --- a/lib/libc/sys/stack_protector.c +++ b/lib/libc/secure/stack_protector.c diff --git a/lib/libc/sys/stack_protector_compat.c b/lib/libc/secure/stack_protector_compat.c index cacb863e75e6e..cacb863e75e6e 100644 --- a/lib/libc/sys/stack_protector_compat.c +++ b/lib/libc/secure/stack_protector_compat.c diff --git a/lib/libc/stdio/open_memstream.3 b/lib/libc/stdio/open_memstream.3 index e01952bc4941a..1a0cb0753abaf 100644 --- a/lib/libc/stdio/open_memstream.3 +++ b/lib/libc/stdio/open_memstream.3 @@ -25,7 +25,7 @@ .\" .\" $FreeBSD$ .\" -.Dd October 28, 2014 +.Dd August 1, 2015 .Dt OPEN_MEMSTREAM 3 .Os .Sh NAME @@ -86,13 +86,13 @@ will contain the start of the memory buffer and the variable referenced by will contain the smaller of the current position and the current buffer length. .Pp After a successful call to -.Xr fflush 3, +.Xr fflush 3 , the pointer referenced by .Fa bufp and the variable referenced by .Fa sizep are only valid until the next write operation or a call to -.Xr fclose 3. +.Xr fclose 3 . .Pp Once a stream is closed, the allocated buffer referenced by diff --git a/lib/libc/stdio/tmpfile.c b/lib/libc/stdio/tmpfile.c index c67d1e456a343..e5a2be1d97be9 100644 --- a/lib/libc/stdio/tmpfile.c +++ b/lib/libc/stdio/tmpfile.c @@ -46,9 +46,10 @@ __FBSDID("$FreeBSD$"); #include <string.h> #include <paths.h> #include "un-namespace.h" +#include "libc_private.h" FILE * -tmpfile() +tmpfile(void) { sigset_t set, oset; FILE *fp; @@ -69,7 +70,7 @@ tmpfile() return (NULL); sigfillset(&set); - (void)_sigprocmask(SIG_BLOCK, &set, &oset); + (void)__libc_sigprocmask(SIG_BLOCK, &set, &oset); fd = mkstemp(buf); if (fd != -1) @@ -77,7 +78,7 @@ tmpfile() free(buf); - (void)_sigprocmask(SIG_SETMASK, &oset, NULL); + (void)__libc_sigprocmask(SIG_SETMASK, &oset, NULL); if (fd == -1) return (NULL); diff --git a/lib/libc/stdlib/abort.c b/lib/libc/stdlib/abort.c index b137e490eb2f7..022c6aa99a72d 100644 --- a/lib/libc/stdlib/abort.c +++ b/lib/libc/stdlib/abort.c @@ -61,7 +61,7 @@ abort() * any errors -- ISO C doesn't allow abort to return anyway. */ sigdelset(&act.sa_mask, SIGABRT); - (void)_sigprocmask(SIG_SETMASK, &act.sa_mask, NULL); + (void)__libc_sigprocmask(SIG_SETMASK, &act.sa_mask, NULL); (void)raise(SIGABRT); /* @@ -71,9 +71,9 @@ abort() act.sa_handler = SIG_DFL; act.sa_flags = 0; sigfillset(&act.sa_mask); - (void)_sigaction(SIGABRT, &act, NULL); + (void)__libc_sigaction(SIGABRT, &act, NULL); sigdelset(&act.sa_mask, SIGABRT); - (void)_sigprocmask(SIG_SETMASK, &act.sa_mask, NULL); + (void)__libc_sigprocmask(SIG_SETMASK, &act.sa_mask, NULL); (void)raise(SIGABRT); exit(1); } diff --git a/lib/libc/stdlib/jemalloc/Makefile.inc b/lib/libc/stdlib/jemalloc/Makefile.inc index 4f5fa58670a6c..46006eeaad140 100644 --- a/lib/libc/stdlib/jemalloc/Makefile.inc +++ b/lib/libc/stdlib/jemalloc/Makefile.inc @@ -4,7 +4,8 @@ JEMALLOCSRCS:= jemalloc.c arena.c atomic.c base.c bitmap.c chunk.c \ chunk_dss.c chunk_mmap.c ckh.c ctl.c extent.c hash.c huge.c mb.c \ - mutex.c prof.c quarantine.c rtree.c stats.c tcache.c tsd.c util.c + mutex.c pages.c prof.c quarantine.c rtree.c stats.c tcache.c tsd.c \ + util.c SYM_MAPS+=${LIBC_SRCTOP}/stdlib/jemalloc/Symbol.map @@ -39,12 +40,8 @@ MLINKS+= \ jemalloc.3 xallocx.3 \ jemalloc.3 sallocx.3 \ jemalloc.3 dallocx.3 \ + jemalloc.3 sdallocx.3 \ jemalloc.3 nallocx.3 \ - jemalloc.3 allocm.3 \ - jemalloc.3 rallocm.3 \ - jemalloc.3 sallocm.3 \ - jemalloc.3 dallocm.3 \ - jemalloc.3 nallocm.3 \ jemalloc.3 malloc.conf.5 .if defined(MALLOC_PRODUCTION) diff --git a/lib/libc/stdlib/jemalloc/Symbol.map b/lib/libc/stdlib/jemalloc/Symbol.map index 132664a7bd690..c07306839dc66 100644 --- a/lib/libc/stdlib/jemalloc/Symbol.map +++ b/lib/libc/stdlib/jemalloc/Symbol.map @@ -51,6 +51,11 @@ FBSD_1.3 { __nallocm; }; +FBSD_1.4 { + sdallocx; + __sdallocx; +}; + FBSDprivate_1.0 { _malloc_thread_cleanup; _malloc_prefork; diff --git a/lib/libc/stdlib/system.c b/lib/libc/stdlib/system.c index bd9ea5a30fdc8..2b298e45a6d63 100644 --- a/lib/libc/stdlib/system.c +++ b/lib/libc/stdlib/system.c @@ -70,16 +70,20 @@ __libc_system(const char *command) (void)sigaddset(&newsigblock, SIGCHLD); (void)sigaddset(&newsigblock, SIGINT); (void)sigaddset(&newsigblock, SIGQUIT); - (void)_sigprocmask(SIG_BLOCK, &newsigblock, &oldsigblock); + (void)__libc_sigprocmask(SIG_BLOCK, &newsigblock, &oldsigblock); switch(pid = vfork()) { + /* + * In the child, use unwrapped syscalls. libthr is in + * undefined state after vfork(). + */ case -1: /* error */ - (void)_sigprocmask(SIG_SETMASK, &oldsigblock, NULL); + (void)__libc_sigprocmask(SIG_SETMASK, &oldsigblock, NULL); return (-1); case 0: /* child */ /* * Restore original signal dispositions and exec the command. */ - (void)_sigprocmask(SIG_SETMASK, &oldsigblock, NULL); + (void)__sys_sigprocmask(SIG_SETMASK, &oldsigblock, NULL); execl(_PATH_BSHELL, "sh", "-c", command, (char *)NULL); _exit(127); } @@ -92,16 +96,16 @@ __libc_system(const char *command) memset(&ign, 0, sizeof(ign)); ign.sa_handler = SIG_IGN; (void)sigemptyset(&ign.sa_mask); - (void)_sigaction(SIGINT, &ign, &intact); - (void)_sigaction(SIGQUIT, &ign, &quitact); + (void)__libc_sigaction(SIGINT, &ign, &intact); + (void)__libc_sigaction(SIGQUIT, &ign, &quitact); savedpid = pid; do { pid = _wait4(savedpid, &pstat, 0, (struct rusage *)0); } while (pid == -1 && errno == EINTR); - (void)_sigaction(SIGINT, &intact, NULL); - (void)_sigaction(SIGQUIT, &quitact, NULL); - (void)_sigprocmask(SIG_SETMASK, &oldsigblock, NULL); - return(pid == -1 ? -1 : pstat); + (void)__libc_sigaction(SIGINT, &intact, NULL); + (void)__libc_sigaction(SIGQUIT, &quitact, NULL); + (void)__libc_sigprocmask(SIG_SETMASK, &oldsigblock, NULL); + return (pid == -1 ? -1 : pstat); } __weak_reference(__libc_system, __system); diff --git a/lib/libc/string/bcopy.3 b/lib/libc/string/bcopy.3 index 1608fad2d79f2..ac480f8ca9663 100644 --- a/lib/libc/string/bcopy.3 +++ b/lib/libc/string/bcopy.3 @@ -31,7 +31,7 @@ .\" @(#)bcopy.3 8.1 (Berkeley) 6/4/93 .\" $FreeBSD$ .\" -.Dd June 4, 1993 +.Dd August 24, 2015 .Dt BCOPY 3 .Os .Sh NAME @@ -75,3 +75,24 @@ before it was moved to for .St -p1003.1-2001 compliance. +.Pp +.St -p1003.1-2008 +removes the specification of +.Fn bcopy +and it is marked as LEGACY in +.St -p1003.1-2004 . +New programs should use +.Xr memmove 3 . +If the input and output buffer do not overlap, then +.Xr memcpy 3 +is more efficient. +Note that +.Fn bcopy +takes +.Ar src +and +.Ar dst +in the opposite order from +.Fn memmove +and +.Fn memcpy . diff --git a/lib/libc/string/bzero.3 b/lib/libc/string/bzero.3 index 5af1bcfcf7727..130a652fe8494 100644 --- a/lib/libc/string/bzero.3 +++ b/lib/libc/string/bzero.3 @@ -31,7 +31,7 @@ .\" @(#)bzero.3 8.1 (Berkeley) 6/4/93 .\" $FreeBSD$ .\" -.Dd October 6, 2014 +.Dd August 24, 2015 .Dt BZERO 3 .Os .Sh NAME @@ -88,3 +88,11 @@ function first appeared in .Ox 5.5 and .Fx 11.0 . +.Pp +.St -p1003.1-2008 +removes the specification of +.Fn bzero +and it is marked as LEGACY in +.St -p1003.1-2004 . +For portability with other systems new programs should use +.Xr memset 3 . diff --git a/lib/libc/string/strndup.c b/lib/libc/string/strndup.c index 2897e933193c8..bee944db167a2 100644 --- a/lib/libc/string/strndup.c +++ b/lib/libc/string/strndup.c @@ -1,32 +1,19 @@ -/* $NetBSD: strndup.c,v 1.3 2007/01/14 23:41:24 cbiere Exp $ */ +/* $OpenBSD: strndup.c,v 1.1 2010/05/18 22:24:55 tedu Exp $ */ /* - * Copyright (c) 1988, 1993 - * The Regents of the University of California. All rights reserved. + * Copyright (c) 2010 Todd C. Miller <Todd.Miller@courtesan.com> * - * 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. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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. + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include <sys/cdefs.h> @@ -37,15 +24,17 @@ __FBSDID("$FreeBSD$"); #include <string.h> char * -strndup(const char *str, size_t n) +strndup(const char *str, size_t maxlen) { - size_t len; char *copy; + size_t len; + + len = strnlen(str, maxlen); + copy = malloc(len + 1); + if (copy != NULL) { + (void)memcpy(copy, str, len); + copy[len] = '\0'; + } - len = strnlen(str, n); - if ((copy = malloc(len + 1)) == NULL) - return (NULL); - memcpy(copy, str, len); - copy[len] = '\0'; - return (copy); + return copy; } diff --git a/lib/libc/sys/Makefile.inc b/lib/libc/sys/Makefile.inc index e672b69e7a432..fad970c22f5ea 100644 --- a/lib/libc/sys/Makefile.inc +++ b/lib/libc/sys/Makefile.inc @@ -21,8 +21,6 @@ PSEUDO+= _clock_gettime.o _gettimeofday.o # Sources common to both syscall interfaces: SRCS+= \ - stack_protector.c \ - stack_protector_compat.c \ __error.c \ interposing_table.c diff --git a/lib/libc/sys/Symbol.map b/lib/libc/sys/Symbol.map index a3a613e24a443..7b3257c6a8128 100644 --- a/lib/libc/sys/Symbol.map +++ b/lib/libc/sys/Symbol.map @@ -3,8 +3,8 @@ */ /* - * It'd be nice to have this automatically generated, but we don't - * know to what version they will eventually belong, so for now + * It'd be nice to automatically generate the syscall symbols, but we + * don't know to what version they will eventually belong to, so for now * it has to be manual. */ FBSD_1.0 { @@ -56,7 +56,6 @@ FBSD_1.0 { bind; chdir; chflags; - __chk_fail; chmod; chown; chroot; @@ -281,8 +280,6 @@ FBSD_1.0 { sigwaitinfo; socket; socketpair; - __stack_chk_fail; - __stack_chk_guard; stat; statfs; swapoff; diff --git a/lib/libc/sys/__vdso_gettimeofday.c b/lib/libc/sys/__vdso_gettimeofday.c index a305173b3ed8c..b3527fa4de533 100644 --- a/lib/libc/sys/__vdso_gettimeofday.c +++ b/lib/libc/sys/__vdso_gettimeofday.c @@ -42,6 +42,15 @@ tc_delta(const struct vdso_timehands *th) th->th_counter_mask); } +/* + * Calculate the absolute or boot-relative time from the + * machine-specific fast timecounter and the published timehands + * structure read from the shared page. + * + * The lockless reading scheme is similar to the one used to read the + * in-kernel timehands, see sys/kern/kern_tc.c:binuptime(). This code + * is based on the kernel implementation. + */ static int binuptime(struct bintime *bt, struct vdso_timekeep *tk, int abs) { @@ -52,27 +61,21 @@ binuptime(struct bintime *bt, struct vdso_timekeep *tk, int abs) if (!tk->tk_enabled) return (ENOSYS); - /* - * XXXKIB. The load of tk->tk_current should use - * atomic_load_acq_32 to provide load barrier. But - * since tk points to r/o mapped page, x86 - * implementation of atomic_load_acq faults. - */ - curr = tk->tk_current; - rmb(); + curr = atomic_load_acq_32(&tk->tk_current); th = &tk->tk_th[curr]; if (th->th_algo != VDSO_TH_ALGO_1) return (ENOSYS); - gen = th->th_gen; + gen = atomic_load_acq_32(&th->th_gen); *bt = th->th_offset; bintime_addx(bt, th->th_scale * tc_delta(th)); if (abs) bintime_add(bt, &th->th_boottime); /* - * Barrier for load of both tk->tk_current and th->th_gen. + * Ensure that the load of th_offset is completed + * before the load of th_gen. */ - rmb(); + atomic_thread_fence_acq(); } while (curr != tk->tk_current || gen == 0 || gen != th->th_gen); return (0); } diff --git a/lib/libc/sys/getrlimit.2 b/lib/libc/sys/getrlimit.2 index 5fdd58bf86138..1fc3656a6366c 100644 --- a/lib/libc/sys/getrlimit.2 +++ b/lib/libc/sys/getrlimit.2 @@ -28,7 +28,7 @@ .\" @(#)getrlimit.2 8.1 (Berkeley) 6/4/93 .\" $FreeBSD$ .\" -.Dd August 20, 2008 +.Dd August 19, 2015 .Dt GETRLIMIT 2 .Os .Sh NAME @@ -74,6 +74,8 @@ this defines how far a program may extend its break with the function. .It Dv RLIMIT_FSIZE The largest size (in bytes) file that may be created. +.It Dv RLIMIT_KQUEUES +The maximum number of kqueues this user id is allowed to create. .It Dv RLIMIT_MEMLOCK The maximum size (in bytes) which a process may lock into memory using the @@ -83,12 +85,25 @@ system call. The maximum number of open files for this process. .It Dv RLIMIT_NPROC The maximum number of simultaneous processes for this user id. +.It Dv RLIMIT_NPTS +The maximum number of pseudo-terminals this user id is allowed to create. .It Dv RLIMIT_RSS -The maximum size (in bytes) to which a process's resident set size may -grow. -This imposes a limit on the amount of physical memory to be given to -a process; if memory is tight, the system will prefer to take memory -from processes that are exceeding their declared resident set size. +When there is memory pressure and swap is available, prioritize eviction of +a process' resident pages beyond this amount (in bytes). +When memory is not under pressure, this rlimit is effectively ignored. +Even when there is memory pressure, the amount of available swap space and some +sysctl settings like +.Xr vm.swap_enabled +and +.Xr vm.swap_idle_enabled +can affect what happens to processes that have exceeded this size. +.Pp +Processes that exceed their set +.Dv RLIMIT_RSS +are not signalled or halted. +The limit is merely a hint to the VM daemon to prefer to deactivate pages from +processes that have exceeded their set +.Dv RLIMIT_RSS . .It Dv RLIMIT_SBSIZE The maximum size (in bytes) of socket buffer usage for this user. This limits the amount of network memory, and hence the amount of @@ -106,18 +121,20 @@ sysctl is set. Please see .Xr tuning 7 for a complete description of this sysctl. -.It Dv RLIMIT_NPTS -The maximum number of pseudo-terminals created by this user id. -.It Dv RLIMIT_KQUEUES -The maximum number of kqueues created by this user id. +.It Dv RLIMIT_VMEM +An alias for +.Dv RLIMIT_AS . .El .Pp A resource limit is specified as a soft limit and a hard limit. -When a -soft limit is exceeded a process may receive a signal (for example, if -the cpu time or file size is exceeded), but it will be allowed to -continue execution until it reaches the hard limit (or modifies -its resource limit). +When a soft limit is exceeded, a process might or might not receive a signal. +For example, signals are generated when the cpu time or file size is exceeded, +but not if the address space or RSS limit is exceeded. +A program that exceeds the soft limit is allowed to continue execution until it +reaches the hard limit, or modifies its own resource limit. +Even reaching the hard limit does not necessarily halt a process. +For example, if the RSS hard limit is exceeded, nothing happens. +.Pp The .Vt rlimit structure is used to specify the hard and soft limits on a resource, @@ -170,6 +187,20 @@ the soft cpu time limit is exceeded, a signal .Dv SIGXCPU is sent to the offending process. +.Pp +When most operations would allocate more virtual memory than allowed by the +soft limit of +.Dv RLIMIT_AS , +the operation fails with +.Dv ENOMEM +and no signal is raised. +A notable exception is stack extension, described above. +If stack extension would allocate more virtual memory than allowed by the soft +limit of +.Dv RLIMIT_AS , +the signal SIGSEGV will be delivered. +The caller is free to raise the soft address space limit up to the hard limit +and retry the allocation. .Sh RETURN VALUES .Rv -std .Sh ERRORS diff --git a/lib/libc/sys/kqueue.2 b/lib/libc/sys/kqueue.2 index c5e8cafd5579e..ca94852cba29c 100644 --- a/lib/libc/sys/kqueue.2 +++ b/lib/libc/sys/kqueue.2 @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd March 29, 2015 +.Dd August 4, 2015 .Dt KQUEUE 2 .Os .Sh NAME @@ -288,6 +288,14 @@ Returns when the file pointer is not at the end of file. .Va data contains the offset from current position to end of file, and may be negative. +.Pp +This behavior is different from +.Xr poll 2 , +where read events are triggered for regular files unconditionally. +This event can be triggered unconditionally by setting the +.Dv NOTE_FILE_POLL +flag in +.Va fflags . .It "Fifos, Pipes" Returns when the there is data to read; .Va data diff --git a/lib/libc/sys/procctl.2 b/lib/libc/sys/procctl.2 index 76a3cef1bfb46..88dcfd3d405bb 100644 --- a/lib/libc/sys/procctl.2 +++ b/lib/libc/sys/procctl.2 @@ -29,7 +29,7 @@ .\" .\" $FreeBSD$ .\" -.Dd December 29, 2014 +.Dd August 21, 2015 .Dt PROCCTL 2 .Os .Sh NAME @@ -71,11 +71,11 @@ The control request to perform is specified by the .Fa cmd argument. The following commands are supported: -.Bl -tag -width "Dv PROC_REAP_GETPIDS" +.Bl -tag -width "PROC_REAP_GETPIDS" .It Dv PROC_SPROTECT Set process protection state. This is used to mark a process as protected from being killed if the system -exhausts available memory and swap. +exhausts the available memory and swap. The .Fa arg parameter must point to an integer containing an operation and zero or more @@ -89,7 +89,7 @@ Clear the protected state of selected processes. .El .Pp The following optional flags are supported: -.Bl -tag -width "Dv PPROT_DESCE" +.Bl -tag -width "Dv PPROT_DESCEND" .It Dv PPROT_DESCEND Apply the requested operation to all child processes of each selected process in addition to each selected process. @@ -101,18 +101,18 @@ Future child processes will also mark all of their future child processes. .El .It Dv PROC_REAP_ACQUIRE Acquires the reaper status for the current process. -The status means that children orphaned by the reaper's descendants -that were forked after the acquisition of the status are reparented to the -reaper. -After the system initialization, +Reaper status means that children orphaned by the reaper's descendants +that were forked after the acquisition of reaper status are reparented to the +reaper process. +After system initialization, .Xr init 8 is the default reaper. .It Dv PROC_REAP_RELEASE -Releases the reaper state for the current process. +Release the reaper state for the current process. The reaper of the current process becomes the new reaper of the current process's descendants. .It Dv PROC_REAP_STATUS -Provides the information about the reaper of the specified process, +Provides information about the reaper of the specified process, or the process itself when it is a reaper. The .Fa data @@ -133,7 +133,7 @@ The may have the following flags returned: .Bl -tag -width "Dv REAPER_STATUS_REALINIT" .It Dv REAPER_STATUS_OWNED -The specified process has acquired the reaper status and has not +The specified process has acquired reaper status and has not released it. When the flag is returned, the specified process .Fa id , @@ -142,13 +142,17 @@ pid, identifies the reaper, otherwise the field of the structure is set to the pid of the reaper for the specified process id. .It Dv REAPER_STATUS_REALINIT -The specified process is the root of the reaper tree, i.e. +The specified process is the root of the reaper tree, i.e., .Xr init 8 . .El .Pp The .Fa rs_children -field returns the number of children of the reaper. +field returns the number of children of the reaper among the descendants. +It is possible to have a child whose reaper is not the specified process, +since the reaper for any existing children is not reset on the +.Dv PROC_REAP_ACQUIRE +operation. The .Fa rs_descendants field returns the total number of descendants of the reaper(s), @@ -242,7 +246,7 @@ struct procctl_reaper_kill { The .Fa rk_sig field specifies the signal to be delivered. -Zero is not a valid signal number, unlike +Zero is not a valid signal number, unlike for .Xr kill 2 . The .Fa rk_flags @@ -271,20 +275,20 @@ field identifies the number of processes signalled. The .Fa rk_fpid field is set to the pid of the first process for which signal -delivery failed, e.g. due to the permission problems. -If no such process exist, the +delivery failed, e.g., due to permission problems. +If no such process exists, the .Fa rk_fpid field is set to -1. .It Dv PROC_TRACE_CTL Enable or disable tracing of the specified process(es), according to the value of the integer argument. -Tracing includes attachment to the process using +Tracing includes attachment to the process using the .Xr ptrace 2 and .Xr ktrace 2 , debugging sysctls, .Xr hwpmc 4 , -.Xr dtrace 1 +.Xr dtrace 1 , and core dumping. Possible values for the .Fa data @@ -297,7 +301,7 @@ Only allowed for self. .It Dv PROC_TRACE_CTL_DISABLE Disable tracing for the specified process. Tracing is re-enabled when the process changes the executing -program with +program with the .Xr execve 2 syscall. A child inherits the trace settings from the parent on @@ -305,7 +309,7 @@ A child inherits the trace settings from the parent on .It Dv PROC_TRACE_CTL_DISABLE_EXEC Same as .Dv PROC_TRACE_CTL_DISABLE , -but the setting persist for the process even after +but the setting persists for the process even after .Xr execve 2 . .El .It Dv PROC_TRACE_STATUS @@ -315,7 +319,7 @@ the integer variable pointed to by If tracing is disabled, .Fa data is set to -1. -If tracing is enabled, but no debugger is attached by +If tracing is enabled, but no debugger is attached by the .Xr ptrace 2 syscall, .Fa data @@ -328,7 +332,7 @@ is set to the pid of the debugger process. Disabling tracing on a process should not be considered a security feature, as it is bypassable both by the kernel and privileged processes, and via other system mechanisms. -As such, it should not be relied on to reliably protect cryptographic +As such, it should not be utilized to reliably protect cryptographic keying material or other confidential data. .Sh RETURN VALUES If an error occurs, a value of -1 is returned and @@ -404,9 +408,9 @@ request was issued for a process already being traced. .It Bq Er EPERM The .Dv PROC_TRACE_CTL -request to re-enable tracing of the process ( -.Dv PROC_TRACE_CTL_ENABLE ) , -or to disable persistence of the +request to re-enable tracing of the process +.Po Dv PROC_TRACE_CTL_ENABLE Pc , +or to disable persistence of .Dv PROC_TRACE_CTL_DISABLE on .Xr execve 2 diff --git a/lib/libc/sys/shutdown.2 b/lib/libc/sys/shutdown.2 index e8a434b239554..35c464e9fe2e7 100644 --- a/lib/libc/sys/shutdown.2 +++ b/lib/libc/sys/shutdown.2 @@ -29,7 +29,7 @@ .\" @(#)shutdown.2 8.1 (Berkeley) 6/4/93 .\" $FreeBSD$ .\" -.Dd March 5, 2007 +.Dd July 27, 2015 .Dt SHUTDOWN 2 .Os .Sh NAME @@ -79,40 +79,26 @@ The following protocol specific actions apply to the use of based on the properties of the socket associated with the file descriptor .Fa s . .Bl -column ".Dv PF_INET6" ".Dv SOCK_STREAM" ".Dv IPPROTO_SCTP" -.It Sy Domain Ta Sy Type Ta Sy Protocol Ta Sy Return value and action +.It Sy Domain Ta Sy Type Ta Sy Protocol Ta Sy Action .It Dv PF_INET Ta Dv SOCK_DGRAM Ta Dv IPPROTO_SCTP Ta -Return \-1. -The global variable -.Va errno -will be set to -.Er EOPNOTSUPP . +Failure, +as socket is not connected. .It Dv PF_INET Ta Dv SOCK_DGRAM Ta Dv IPPROTO_UDP Ta -Return 0. -ICMP messages will -.Em not -be generated. +Failure, +as socket is not connected. .It Dv PF_INET Ta Dv SOCK_STREAM Ta Dv IPPROTO_SCTP Ta -Return 0. Send queued data and tear down association. .It Dv PF_INET Ta Dv SOCK_STREAM Ta Dv IPPROTO_TCP Ta -Return 0. Send queued data, wait for ACK, then send FIN. .It Dv PF_INET6 Ta Dv SOCK_DGRAM Ta Dv IPPROTO_SCTP Ta -Return \-1. -The global variable -.Va errno -will be set to -.Er EOPNOTSUPP . +Failure, +as socket is not connected. .It Dv PF_INET6 Ta Dv SOCK_DGRAM Ta Dv IPPROTO_UDP Ta -Return 0. -ICMP messages will -.Em not -be generated. +Failure, +as socket is not connected. .It Dv PF_INET6 Ta Dv SOCK_STREAM Ta Dv IPPROTO_SCTP Ta -Return 0. Send queued data and tear down association. .It Dv PF_INET6 Ta Dv SOCK_STREAM Ta Dv IPPROTO_TCP Ta -Return 0. Send queued data, wait for ACK, then send FIN. .El .\" @@ -131,16 +117,10 @@ argument is not a valid file descriptor. The .Fa how argument is invalid. -.It Bq Er EOPNOTSUPP -The socket associated with the file descriptor -.Fa s -does not support this operation. .It Bq Er ENOTCONN The .Fa s -argument specifies a -.Dv SOCK_STREAM -socket which is not connected. +argument specifies a socket which is not connected. .It Bq Er ENOTSOCK The .Fa s diff --git a/lib/libc/sys/sigaction.c b/lib/libc/sys/sigaction.c index 7645538cf3b99..b4d65639b816e 100644 --- a/lib/libc/sys/sigaction.c +++ b/lib/libc/sys/sigaction.c @@ -38,6 +38,7 @@ __FBSDID("$FreeBSD$"); #include "libc_private.h" __weak_reference(__sys_sigaction, __sigaction); +__weak_reference(sigaction, __libc_sigaction); #pragma weak sigaction int diff --git a/lib/libc/sys/sigprocmask.c b/lib/libc/sys/sigprocmask.c index 40dba95563be7..d24bb89c1f790 100644 --- a/lib/libc/sys/sigprocmask.c +++ b/lib/libc/sys/sigprocmask.c @@ -38,6 +38,7 @@ __FBSDID("$FreeBSD$"); #include "libc_private.h" __weak_reference(__sys_sigprocmask, __sigprocmask); +__weak_reference(sigprocmask, __libc_sigprocmask); #pragma weak sigprocmask int diff --git a/lib/libc/sys/sigsuspend.c b/lib/libc/sys/sigsuspend.c index 6e47368c49c3d..1f980a117a1bb 100644 --- a/lib/libc/sys/sigsuspend.c +++ b/lib/libc/sys/sigsuspend.c @@ -38,6 +38,7 @@ __FBSDID("$FreeBSD$"); #include "libc_private.h" __weak_reference(__sys_sigsuspend, __sigsuspend); +__weak_reference(sigsuspend, __libc_sigsuspend); #pragma weak sigsuspend int diff --git a/lib/libc/sys/unlink.2 b/lib/libc/sys/unlink.2 index 406c77c24752d..e59ecf8b2a93a 100644 --- a/lib/libc/sys/unlink.2 +++ b/lib/libc/sys/unlink.2 @@ -28,7 +28,7 @@ .\" @(#)unlink.2 8.1 (Berkeley) 6/4/93 .\" $FreeBSD$ .\" -.Dd April 25, 2010 +.Dd July 28, 2015 .Dt UNLINK 2 .Os .Sh NAME @@ -151,6 +151,9 @@ The .Fa path argument points outside the process's allocated address space. +.It Bq Er ENOSPC +On file systems supporting copy-on-write or snapshots, there was not enough +free space to record metadata for the delete operation of the file. .El .Pp In addition to the errors returned by the diff --git a/lib/libc/tests/gen/posix_spawn/Makefile b/lib/libc/tests/gen/posix_spawn/Makefile index a1c9b9e7cd1e3..d2dfa5489d968 100644 --- a/lib/libc/tests/gen/posix_spawn/Makefile +++ b/lib/libc/tests/gen/posix_spawn/Makefile @@ -10,9 +10,9 @@ TESTSDIR= ${TESTSBASE}/lib/libc/gen/posix_spawn BINDIR= ${TESTSDIR} -# TODO: t_spawnattr (fix from pho@ needs additional review) NETBSD_ATF_TESTS_C= fileactions_test NETBSD_ATF_TESTS_C+= spawn_test +NETBSD_ATF_TESTS_C+= spawnattr_test PROGS= h_fileactions PROGS+= h_spawn diff --git a/lib/libgeom/geom_xml2tree.c b/lib/libgeom/geom_xml2tree.c index 2c23361b16667..2a373d7f31d54 100644 --- a/lib/libgeom/geom_xml2tree.c +++ b/lib/libgeom/geom_xml2tree.c @@ -275,18 +275,20 @@ EndElement(void *userData, const char *name) XML_StopParser(mt->parser, 0); warn("Cannot allocate memory during processing of '%s' " "element", name); + free(p); return; } gc->lg_name = strdup(name); if (gc->lg_name == NULL) { - free(gc); mt->error = errno; XML_StopParser(mt->parser, 0); warn("Cannot allocate memory during processing of '%s' " "element", name); + free(gc); + free(p); return; } - gc->lg_val = p ? p : strdup("1"); + gc->lg_val = p; LIST_INSERT_HEAD(c, gc, lg_config); return; } diff --git a/lib/libiconv_modules/BIG5/Makefile b/lib/libiconv_modules/BIG5/Makefile index cdaf9ddf18898..34ff9ebaa220f 100644 --- a/lib/libiconv_modules/BIG5/Makefile +++ b/lib/libiconv_modules/BIG5/Makefile @@ -2,6 +2,6 @@ SHLIB= BIG5 SRCS+= citrus_big5.c -CFLAGS.gcc+= --param max-inline-insns-single=32 +CFLAGS.gcc+= --param max-inline-insns-single=64 .include <bsd.lib.mk> diff --git a/lib/libiconv_modules/EUC/Makefile b/lib/libiconv_modules/EUC/Makefile index aeceff40d2301..b2f02ee3b920c 100644 --- a/lib/libiconv_modules/EUC/Makefile +++ b/lib/libiconv_modules/EUC/Makefile @@ -2,6 +2,6 @@ SHLIB= EUC SRCS+= citrus_euc.c -CFLAGS.gcc+= --param max-inline-insns-single=32 +CFLAGS.gcc+= --param max-inline-insns-single=64 .include <bsd.lib.mk> diff --git a/lib/libiconv_modules/EUCTW/Makefile b/lib/libiconv_modules/EUCTW/Makefile index 4808ca3ac58b4..c719a1aa1f8c7 100644 --- a/lib/libiconv_modules/EUCTW/Makefile +++ b/lib/libiconv_modules/EUCTW/Makefile @@ -2,6 +2,6 @@ SHLIB= EUCTW SRCS+= citrus_euctw.c -CFLAGS.gcc+= --param max-inline-insns-single=32 +CFLAGS.gcc+= --param max-inline-insns-single=64 .include <bsd.lib.mk> diff --git a/lib/libiconv_modules/UTF1632/Makefile b/lib/libiconv_modules/UTF1632/Makefile index 485d0702b40d4..b42e58c7d15fb 100644 --- a/lib/libiconv_modules/UTF1632/Makefile +++ b/lib/libiconv_modules/UTF1632/Makefile @@ -2,6 +2,6 @@ SHLIB= UTF1632 SRCS+= citrus_utf1632.c -CFLAGS.gcc+= --param max-inline-insns-single=32 +CFLAGS.gcc+= --param max-inline-insns-single=64 .include <bsd.lib.mk> diff --git a/lib/libiconv_modules/UTF7/Makefile b/lib/libiconv_modules/UTF7/Makefile index 733cb26e3d434..e191fb9afd303 100644 --- a/lib/libiconv_modules/UTF7/Makefile +++ b/lib/libiconv_modules/UTF7/Makefile @@ -2,6 +2,6 @@ SHLIB= UTF7 SRCS+= citrus_utf7.c -CFLAGS.gcc+= --param max-inline-insns-single=32 +CFLAGS.gcc+= --param max-inline-insns-single=64 .include <bsd.lib.mk> diff --git a/lib/libiconv_modules/iconv_std/Makefile b/lib/libiconv_modules/iconv_std/Makefile index 88d68aafc77b2..f6eeb76d20cbe 100644 --- a/lib/libiconv_modules/iconv_std/Makefile +++ b/lib/libiconv_modules/iconv_std/Makefile @@ -2,6 +2,6 @@ SHLIB= iconv_std SRCS+= citrus_iconv_std.c -CFLAGS.gcc+= --param max-inline-insns-single=32 +CFLAGS.gcc+= --param max-inline-insns-single=64 .include <bsd.lib.mk> diff --git a/lib/libkvm/kvm_aarch64.c b/lib/libkvm/kvm_aarch64.c index f98ef36318865..40b050b105255 100644 --- a/lib/libkvm/kvm_aarch64.c +++ b/lib/libkvm/kvm_aarch64.c @@ -1,5 +1,6 @@ /*- - * Copyright (c) 2014 The FreeBSD Foundation + * Copyright (C) 2006 Bruce M. Simpson. + * Copyright (c) 2015 The FreeBSD Foundation * All rights reserved. * * This software was developed by Andrew Turner under @@ -27,38 +28,78 @@ * SUCH DAMAGE. */ +/* + * arm64 (AArch64) machine dependent routines for kvm. + */ + #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); #include <sys/param.h> +#include <sys/mman.h> + +#include <vm/vm.h> +#include <vm/vm_param.h> +#include <vm/pmap.h> + +#include <machine/pmap.h> #include <limits.h> #include <kvm.h> -#include <stdio.h> #include <stdlib.h> +#include <string.h> +#include <unistd.h> #include "kvm_private.h" +/* minidump must be the first item! */ +struct vmstate { + int minidump; /* 1 = minidump mode */ + void *mmapbase; + size_t mmapsize; +}; + void _kvm_freevtop(kvm_t *kd) { - printf("_kvm_freevtop\n"); - abort(); + if (kd->vmst != 0) { + if (kd->vmst->minidump) + return (_kvm_minidump_freevtop(kd)); + if (kd->vmst->mmapbase != NULL) + munmap(kd->vmst->mmapbase, kd->vmst->mmapsize); + free(kd->vmst); + kd->vmst = NULL; + } } int _kvm_initvtop(kvm_t *kd) { + char minihdr[8]; + + if (!kd->rawdump) { + if (pread(kd->pmfd, &minihdr, 8, 0) == 8) { + if (memcmp(&minihdr, "minidump", 8) == 0) + return (_kvm_minidump_initvtop(kd)); + } else { + _kvm_err(kd, kd->program, "cannot read header"); + return (-1); + } + } - printf("_kvm_initvtop\n"); - abort(); + _kvm_err(kd, 0, "_kvm_initvtop: Unsupported image type"); + return (-1); } int _kvm_kvatop(kvm_t *kd, u_long va, off_t *pa) { - printf("_kvm_kvatop\n"); - abort(); + if (kd->vmst->minidump) + return _kvm_minidump_kvatop(kd, va, pa); + + + _kvm_err(kd, 0, "_kvm_kvatop: Unsupported image type"); + return (0); } diff --git a/lib/libkvm/kvm_minidump_aarch64.c b/lib/libkvm/kvm_minidump_aarch64.c new file mode 100644 index 0000000000000..5a4990ef98eca --- /dev/null +++ b/lib/libkvm/kvm_minidump_aarch64.c @@ -0,0 +1,269 @@ +/*- + * Copyright (c) 2006 Peter Wemm + * + * 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. + * + * From: FreeBSD: src/lib/libkvm/kvm_minidump_amd64.c r261799 + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +/* + * ARM64 (AArch64) machine dependent routines for kvm and minidumps. + */ + +#include <sys/param.h> +#include <sys/user.h> +#include <sys/proc.h> +#include <sys/stat.h> +#include <sys/mman.h> +#include <sys/fnv_hash.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <nlist.h> +#include <kvm.h> + +#include <vm/vm.h> +#include <vm/vm_param.h> + +#include <machine/elf.h> +#include <machine/cpufunc.h> +#include <machine/pte.h> +#include <machine/minidump.h> + +#include <limits.h> +#include <stdint.h> + +#include "kvm_private.h" + +struct hpte { + struct hpte *next; + vm_paddr_t pa; + int64_t off; +}; + +#define HPT_SIZE 1024 + +/* minidump must be the first item! */ +struct vmstate { + int minidump; /* 1 = minidump mode */ + struct minidumphdr hdr; + void *hpt_head[HPT_SIZE]; + uint64_t *bitmap; + uint64_t *page_map; +}; + +static void +hpt_insert(kvm_t *kd, vm_paddr_t pa, int64_t off) +{ + struct hpte *hpte; + uint32_t fnv = FNV1_32_INIT; + + fnv = fnv_32_buf(&pa, sizeof(pa), fnv); + fnv &= (HPT_SIZE - 1); + hpte = malloc(sizeof(*hpte)); + hpte->pa = pa; + hpte->off = off; + hpte->next = kd->vmst->hpt_head[fnv]; + kd->vmst->hpt_head[fnv] = hpte; +} + +static int64_t +hpt_find(kvm_t *kd, vm_paddr_t pa) +{ + struct hpte *hpte; + uint32_t fnv = FNV1_32_INIT; + + fnv = fnv_32_buf(&pa, sizeof(pa), fnv); + fnv &= (HPT_SIZE - 1); + for (hpte = kd->vmst->hpt_head[fnv]; hpte != NULL; hpte = hpte->next) { + if (pa == hpte->pa) + return (hpte->off); + } + return (-1); +} + +static int +inithash(kvm_t *kd, uint64_t *base, int len, off_t off) +{ + uint64_t idx; + uint64_t bit, bits; + vm_paddr_t pa; + + for (idx = 0; idx < len / sizeof(*base); idx++) { + bits = base[idx]; + while (bits) { + bit = ffsl(bits) - 1; + bits &= ~(1ul << bit); + pa = (idx * sizeof(*base) * NBBY + bit) * PAGE_SIZE; + hpt_insert(kd, pa, off); + off += PAGE_SIZE; + } + } + return (off); +} + +void +_kvm_minidump_freevtop(kvm_t *kd) +{ + struct vmstate *vm = kd->vmst; + + free(vm->bitmap); + free(vm->page_map); + free(vm); + kd->vmst = NULL; +} + +int +_kvm_minidump_initvtop(kvm_t *kd) +{ + struct vmstate *vmst; + off_t off; + + vmst = _kvm_malloc(kd, sizeof(*vmst)); + if (vmst == 0) { + _kvm_err(kd, kd->program, "cannot allocate vm"); + return (-1); + } + kd->vmst = vmst; + vmst->minidump = 1; + if (pread(kd->pmfd, &vmst->hdr, sizeof(vmst->hdr), 0) != + sizeof(vmst->hdr)) { + _kvm_err(kd, kd->program, "cannot read dump header"); + return (-1); + } + if (strncmp(MINIDUMP_MAGIC, vmst->hdr.magic, + sizeof(vmst->hdr.magic)) != 0) { + _kvm_err(kd, kd->program, "not a minidump for this platform"); + return (-1); + } + + if (vmst->hdr.version != MINIDUMP_VERSION && vmst->hdr.version != 1) { + _kvm_err(kd, kd->program, "wrong minidump version. " + "Expected %d got %d", MINIDUMP_VERSION, vmst->hdr.version); + return (-1); + } + + /* Skip header and msgbuf */ + off = PAGE_SIZE + round_page(vmst->hdr.msgbufsize); + + vmst->bitmap = _kvm_malloc(kd, vmst->hdr.bitmapsize); + if (vmst->bitmap == NULL) { + _kvm_err(kd, kd->program, + "cannot allocate %d bytes for bitmap", + vmst->hdr.bitmapsize); + return (-1); + } + if (pread(kd->pmfd, vmst->bitmap, vmst->hdr.bitmapsize, off) != + vmst->hdr.bitmapsize) { + _kvm_err(kd, kd->program, + "cannot read %d bytes for page bitmap", + vmst->hdr.bitmapsize); + return (-1); + } + off += round_page(vmst->hdr.bitmapsize); + + vmst->page_map = _kvm_malloc(kd, vmst->hdr.pmapsize); + if (vmst->page_map == NULL) { + _kvm_err(kd, kd->program, + "cannot allocate %d bytes for page_map", + vmst->hdr.pmapsize); + return (-1); + } + /* This is the end of the dump, savecore may have truncated it. */ + if (pread(kd->pmfd, vmst->page_map, vmst->hdr.pmapsize, off) < + PAGE_SIZE) { + _kvm_err(kd, kd->program, "cannot read %d bytes for page_map", + vmst->hdr.pmapsize); + } + off += vmst->hdr.pmapsize; + + /* build physical address hash table for sparse pages */ + inithash(kd, vmst->bitmap, vmst->hdr.bitmapsize, off); + + return (0); +} + +static int +_kvm_minidump_vatop(kvm_t *kd, u_long va, off_t *pa) +{ + struct vmstate *vm; + u_long offset; + pt_entry_t l3; + u_long l3_index; + u_long a; + off_t ofs; + + vm = kd->vmst; + offset = va & PAGE_MASK; + + if (va >= vm->hdr.dmapbase && va < vm->hdr.dmapend) { + a = (va - vm->hdr.dmapbase + vm->hdr.dmapphys) & ~PAGE_MASK; + ofs = hpt_find(kd, a); + if (ofs == -1) { + _kvm_err(kd, kd->program, "_kvm_vatop: " + "direct map address 0x%lx not in minidump", va); + goto invalid; + } + *pa = ofs + offset; + return (PAGE_SIZE - offset); + } else if (va >= vm->hdr.kernbase) { + l3_index = (va - vm->hdr.kernbase) >> L3_SHIFT; + if (l3_index >= vm->hdr.pmapsize / sizeof(*vm->page_map)) + goto invalid; + l3 = vm->page_map[l3_index]; + if ((l3 & ATTR_DESCR_MASK) != L3_PAGE) { + _kvm_err(kd, kd->program, "_kvm_vatop: pde not valid"); + goto invalid; + } + a = l3 & ~ATTR_MASK; + ofs = hpt_find(kd, a); + if (ofs == -1) { + _kvm_err(kd, kd->program, "_kvm_vatop: " + "physical address 0x%lx not in minidump", a); + goto invalid; + } + *pa = ofs + offset; + return (PAGE_SIZE - offset); + } else { + _kvm_err(kd, kd->program, + "_kvm_vatop: virtual address 0x%lx not minidumped", va); + goto invalid; + } + +invalid: + _kvm_err(kd, 0, "invalid address (0x%lx)", va); + return (0); +} + +int +_kvm_minidump_kvatop(kvm_t *kd, u_long va, off_t *pa) +{ + + if (ISALIVE(kd)) { + _kvm_err(kd, 0, "kvm_kvatop called in live kernel!"); + return (0); + } + return (_kvm_minidump_vatop(kd, va, pa)); +} diff --git a/lib/libkvm/kvm_private.h b/lib/libkvm/kvm_private.h index b3eeea7ad3fc9..4829046f22391 100644 --- a/lib/libkvm/kvm_private.h +++ b/lib/libkvm/kvm_private.h @@ -104,8 +104,8 @@ uintptr_t _kvm_vnet_validaddr(kvm_t *, uintptr_t); int _kvm_dpcpu_initialized(kvm_t *, int); uintptr_t _kvm_dpcpu_validaddr(kvm_t *, uintptr_t); -#if defined(__amd64__) || defined(__i386__) || defined(__arm__) || \ - defined(__mips__) +#if defined(__aarch64__) || defined(__amd64__) || defined(__arm__) || \ + defined(__i386__) || defined(__mips__) void _kvm_minidump_freevtop(kvm_t *); int _kvm_minidump_initvtop(kvm_t *); int _kvm_minidump_kvatop(kvm_t *, u_long, off_t *); diff --git a/lib/libmagic/config.h b/lib/libmagic/config.h index 956b0400c1856..f7057d1e11f9c 100644 --- a/lib/libmagic/config.h +++ b/lib/libmagic/config.h @@ -290,7 +290,7 @@ #define PACKAGE_NAME "file" /* Define to the full name and version of this package. */ -#define PACKAGE_STRING "file 5.23" +#define PACKAGE_STRING "file 5.24" /* Define to the one symbol short name of this package. */ #define PACKAGE_TARNAME "file" @@ -299,7 +299,7 @@ #define PACKAGE_URL "" /* Define to the version of this package. */ -#define PACKAGE_VERSION "5.23" +#define PACKAGE_VERSION "5.24" /* Define to 1 if you have the ANSI C header files. */ #define STDC_HEADERS 1 @@ -330,7 +330,7 @@ /* Version number of package */ -#define VERSION "5.23" +#define VERSION "5.24" /* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most significant byte first (like Motorola and SPARC, unlike Intel). */ diff --git a/lib/libnv/tests/Makefile b/lib/libnv/tests/Makefile index 7fc8d918c9c0a..38e7f13219a65 100644 --- a/lib/libnv/tests/Makefile +++ b/lib/libnv/tests/Makefile @@ -4,6 +4,7 @@ TESTSDIR= ${TESTSBASE}/lib/libnv ATF_TESTS_CXX= \ dnv_tests \ + nv_array_tests \ nv_tests \ TAP_TESTS_C+= nvlist_add_test diff --git a/lib/libnv/tests/nv_array_tests.cc b/lib/libnv/tests/nv_array_tests.cc new file mode 100644 index 0000000000000..3de0ee877a2fb --- /dev/null +++ b/lib/libnv/tests/nv_array_tests.cc @@ -0,0 +1,1191 @@ +/*- + * Copyright (c) 2015 Mariusz Zaborski <oshogbo@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 <sys/nv.h> +#include <sys/types.h> +#include <sys/socket.h> + +#include <atf-c++.hpp> + +#include <cstdio> +#include <errno.h> +#include <fcntl.h> +#include <limits> +#include <set> +#include <sstream> +#include <string> + +#define fd_is_valid(fd) (fcntl((fd), F_GETFL) != -1 || errno != EBADF) + +ATF_TEST_CASE_WITHOUT_HEAD(nvlist_bool_array__basic); +ATF_TEST_CASE_BODY(nvlist_bool_array__basic) +{ + bool testbool[16]; + const bool *const_result; + bool *result; + nvlist_t *nvl; + size_t nitems; + unsigned int i; + const char *key; + + key = "nvl/bool"; + nvl = nvlist_create(0); + ATF_REQUIRE(nvl != NULL); + ATF_REQUIRE(nvlist_empty(nvl)); + ATF_REQUIRE(!nvlist_exists_string_array(nvl, key)); + + for (i = 0; i < 16; i++) + testbool[i] = (i % 2 == 0); + + nvlist_add_bool_array(nvl, key, testbool, 16); + ATF_REQUIRE_EQ(nvlist_error(nvl), 0); + ATF_REQUIRE(!nvlist_empty(nvl)); + ATF_REQUIRE(nvlist_exists_bool_array(nvl, key)); + ATF_REQUIRE(nvlist_exists_bool_array(nvl, "nvl/bool")); + + const_result = nvlist_get_bool_array(nvl, key, &nitems); + ATF_REQUIRE_EQ(nitems, 16); + ATF_REQUIRE(const_result != NULL); + for (i = 0; i < nitems; i++) + ATF_REQUIRE_EQ(const_result[i], testbool[i]); + + result = nvlist_take_bool_array(nvl, key, &nitems); + ATF_REQUIRE_EQ(nitems, 16); + ATF_REQUIRE(const_result != NULL); + for (i = 0; i < nitems; i++) + ATF_REQUIRE_EQ(result[i], testbool[i]); + + ATF_REQUIRE(!nvlist_exists_bool_array(nvl, key)); + ATF_REQUIRE(nvlist_empty(nvl)); + ATF_REQUIRE_EQ(nvlist_error(nvl), 0); + + free(result); + nvlist_destroy(nvl); +} + +ATF_TEST_CASE_WITHOUT_HEAD(nvlist_string_array__basic); +ATF_TEST_CASE_BODY(nvlist_string_array__basic) +{ + const char * const *const_result; + char **result; + nvlist_t *nvl; + size_t nitems; + unsigned int i; + const char *key; + const char *string[8] = { "a", "b", "kot", "foo", + "tests", "nice test", "", "abcdef" }; + + key = "nvl/string"; + nvl = nvlist_create(0); + ATF_REQUIRE(nvl != NULL); + ATF_REQUIRE(nvlist_empty(nvl)); + ATF_REQUIRE(!nvlist_exists_string_array(nvl, key)); + + nvlist_add_string_array(nvl, key, string, 8); + ATF_REQUIRE_EQ(nvlist_error(nvl), 0); + ATF_REQUIRE(!nvlist_empty(nvl)); + ATF_REQUIRE(nvlist_exists_string_array(nvl, key)); + ATF_REQUIRE(nvlist_exists_string_array(nvl, "nvl/string")); + + const_result = nvlist_get_string_array(nvl, key, &nitems); + ATF_REQUIRE(!nvlist_empty(nvl)); + ATF_REQUIRE(const_result != NULL); + ATF_REQUIRE(nitems == 8); + for (i = 0; i < nitems; i++) { + if (string[i] != NULL) { + ATF_REQUIRE(strcmp(const_result[i], string[i]) == 0); + } else { + ATF_REQUIRE(const_result[i] == string[i]); + } + } + + result = nvlist_take_string_array(nvl, key, &nitems); + ATF_REQUIRE(result != NULL); + ATF_REQUIRE_EQ(nitems, 8); + for (i = 0; i < nitems; i++) { + if (string[i] != NULL) { + ATF_REQUIRE_EQ(strcmp(result[i], string[i]), 0); + } else { + ATF_REQUIRE_EQ(result[i], string[i]); + } + } + + ATF_REQUIRE(!nvlist_exists_string_array(nvl, key)); + ATF_REQUIRE(nvlist_empty(nvl)); + ATF_REQUIRE_EQ(nvlist_error(nvl), 0); + + for (i = 0; i < 8; i++) + free(result[i]); + free(result); + nvlist_destroy(nvl); +} + +ATF_TEST_CASE_WITHOUT_HEAD(nvlist_descriptor_array__basic); +ATF_TEST_CASE_BODY(nvlist_descriptor_array__basic) +{ + int fd[32], *result; + const int *const_result; + nvlist_t *nvl; + size_t nitems; + unsigned int i; + const char *key; + + for (i = 0; i < 32; i++) { + fd[i] = dup(STDERR_FILENO); + ATF_REQUIRE(fd_is_valid(fd[i])); + } + + key = "nvl/descriptor"; + nvl = nvlist_create(0); + ATF_REQUIRE(nvl != NULL); + ATF_REQUIRE(nvlist_empty(nvl)); + ATF_REQUIRE(!nvlist_exists_descriptor_array(nvl, key)); + + nvlist_add_descriptor_array(nvl, key, fd, 32); + ATF_REQUIRE_EQ(nvlist_error(nvl), 0); + ATF_REQUIRE(!nvlist_empty(nvl)); + ATF_REQUIRE(nvlist_exists_descriptor_array(nvl, key)); + ATF_REQUIRE(nvlist_exists_descriptor_array(nvl, "nvl/descriptor")); + + const_result = nvlist_get_descriptor_array(nvl, key, &nitems); + ATF_REQUIRE(!nvlist_empty(nvl)); + ATF_REQUIRE(const_result != NULL); + ATF_REQUIRE(nitems == 32); + for (i = 0; i < nitems; i++) { + ATF_REQUIRE(fd_is_valid(const_result[i])); + if (i > 0) + ATF_REQUIRE(const_result[i] != const_result[i - 1]); + } + + result = nvlist_take_descriptor_array(nvl, key, &nitems); + ATF_REQUIRE(result != NULL); + ATF_REQUIRE_EQ(nitems, 32); + for (i = 0; i < nitems; i++) { + ATF_REQUIRE(fd_is_valid(result[i])); + if (i > 0) + ATF_REQUIRE(const_result[i] != const_result[i - 1]); + } + + ATF_REQUIRE(!nvlist_exists_string_array(nvl, key)); + ATF_REQUIRE(nvlist_empty(nvl)); + ATF_REQUIRE_EQ(nvlist_error(nvl), 0); + + for (i = 0; i < nitems; i++) { + close(result[i]); + close(fd[i]); + } + free(result); + nvlist_destroy(nvl); +} + +ATF_TEST_CASE_WITHOUT_HEAD(nvlist_number_array__basic); +ATF_TEST_CASE_BODY(nvlist_number_array__basic) +{ + const uint64_t *const_result; + uint64_t *result; + nvlist_t *nvl; + size_t nitems; + unsigned int i; + const char *key; + const uint64_t number[8] = { 0, UINT_MAX, 7, 123, 90, + 100000, 8, 1 }; + + key = "nvl/number"; + nvl = nvlist_create(0); + ATF_REQUIRE(nvl != NULL); + ATF_REQUIRE(nvlist_empty(nvl)); + ATF_REQUIRE(!nvlist_exists_string_array(nvl, key)); + + nvlist_add_number_array(nvl, key, number, 8); + ATF_REQUIRE_EQ(nvlist_error(nvl), 0); + ATF_REQUIRE(!nvlist_empty(nvl)); + ATF_REQUIRE(nvlist_exists_number_array(nvl, key)); + ATF_REQUIRE(nvlist_exists_number_array(nvl, "nvl/number")); + + const_result = nvlist_get_number_array(nvl, key, &nitems); + ATF_REQUIRE(!nvlist_empty(nvl)); + ATF_REQUIRE(const_result != NULL); + ATF_REQUIRE(nitems == 8); + for (i = 0; i < nitems; i++) + ATF_REQUIRE_EQ(const_result[i], number[i]); + + result = nvlist_take_number_array(nvl, key, &nitems); + ATF_REQUIRE(result != NULL); + ATF_REQUIRE_EQ(nitems, 8); + for (i = 0; i < nitems; i++) + ATF_REQUIRE_EQ(result[i], number[i]); + + ATF_REQUIRE(!nvlist_exists_string_array(nvl, key)); + ATF_REQUIRE(nvlist_empty(nvl)); + ATF_REQUIRE_EQ(nvlist_error(nvl), 0); + + free(result); + nvlist_destroy(nvl); +} + +ATF_TEST_CASE_WITHOUT_HEAD(nvlist_nvlist_array__basic); +ATF_TEST_CASE_BODY(nvlist_nvlist_array__basic) +{ + nvlist_t *testnvl[8]; + const nvlist_t * const *const_result; + nvlist_t **result; + nvlist_t *nvl; + size_t nitems; + unsigned int i; + const char *somestr[8] = { "a", "b", "c", "d", "e", "f", "g", "h" }; + const char *key; + + for (i = 0; i < 8; i++) { + testnvl[i] = nvlist_create(0); + ATF_REQUIRE(testnvl[i] != NULL); + ATF_REQUIRE_EQ(nvlist_error(testnvl[i]), 0); + nvlist_add_string(testnvl[i], "nvl/string", somestr[i]); + ATF_REQUIRE_EQ(nvlist_error(testnvl[i]), 0); + ATF_REQUIRE(nvlist_exists_string(testnvl[i], "nvl/string")); + } + + key = "nvl/nvlist"; + nvl = nvlist_create(0); + ATF_REQUIRE(nvl != NULL); + ATF_REQUIRE(nvlist_empty(nvl)); + ATF_REQUIRE(!nvlist_exists_string_array(nvl, key)); + + nvlist_add_nvlist_array(nvl, key, (const nvlist_t * const *)testnvl, 8); + ATF_REQUIRE_EQ(nvlist_error(nvl), 0); + ATF_REQUIRE(!nvlist_empty(nvl)); + ATF_REQUIRE(nvlist_exists_nvlist_array(nvl, key)); + ATF_REQUIRE(nvlist_exists_nvlist_array(nvl, "nvl/nvlist")); + + const_result = nvlist_get_nvlist_array(nvl, key, &nitems); + ATF_REQUIRE(!nvlist_empty(nvl)); + ATF_REQUIRE(const_result != NULL); + ATF_REQUIRE(nitems == 8); + + for (i = 0; i < nitems; i++) { + ATF_REQUIRE_EQ(nvlist_error(const_result[i]), 0); + if (i < nitems - 1) { + ATF_REQUIRE(nvlist_get_array_next(const_result[i]) == + const_result[i + 1]); + } else { + ATF_REQUIRE(nvlist_get_array_next(const_result[i]) == + NULL); + } + ATF_REQUIRE(nvlist_get_parent(const_result[i], NULL) == nvl); + ATF_REQUIRE(nvlist_in_array(const_result[i])); + ATF_REQUIRE(nvlist_exists_string(const_result[i], + "nvl/string")); + ATF_REQUIRE(strcmp(nvlist_get_string(const_result[i], + "nvl/string"), somestr[i]) == 0); + } + + result = nvlist_take_nvlist_array(nvl, key, &nitems); + ATF_REQUIRE(result != NULL); + ATF_REQUIRE_EQ(nitems, 8); + for (i = 0; i < nitems; i++) { + ATF_REQUIRE_EQ(nvlist_error(result[i]), 0); + ATF_REQUIRE(nvlist_get_array_next(result[i]) == NULL); + ATF_REQUIRE(nvlist_get_array_next(const_result[i]) == NULL); + ATF_REQUIRE(!nvlist_in_array(const_result[i])); + } + + ATF_REQUIRE(!nvlist_exists_string_array(nvl, key)); + ATF_REQUIRE(nvlist_empty(nvl)); + ATF_REQUIRE_EQ(nvlist_error(nvl), 0); + + for (i = 0; i < 8; i++) { + nvlist_destroy(result[i]); + nvlist_destroy(testnvl[i]); + } + + free(result); + nvlist_destroy(nvl); +} + +ATF_TEST_CASE_WITHOUT_HEAD(nvlist_clone_array); +ATF_TEST_CASE_BODY(nvlist_clone_array) +{ + nvlist_t *testnvl[8]; + nvlist_t *src, *dst; + const nvlist_t *nvl; + bool testbool[16]; + int testfd[16]; + size_t i, nitems; + const char *string[8] = { "a", "b", "kot", "foo", + "tests", "nice test", "", "abcdef" }; + const char *somestr[8] = { "a", "b", "c", "d", "e", "f", "g", "h" }; + const uint64_t number[8] = { 0, UINT_MAX, 7, 123, 90, + 100000, 8, 1 }; + + for (i = 0; i < 16; i++) { + testbool[i] = (i % 2 == 0); + testfd[i] = dup(STDERR_FILENO); + ATF_REQUIRE(fd_is_valid(testfd[i])); + } + for (i = 0; i < 8; i++) { + testnvl[i] = nvlist_create(0); + ATF_REQUIRE(nvlist_error(testnvl[i]) == 0); + nvlist_add_string(testnvl[i], "nvl/nvl/teststr", somestr[i]); + ATF_REQUIRE(nvlist_error(testnvl[i]) == 0); + } + + src = nvlist_create(0); + ATF_REQUIRE(nvlist_error(src) == 0); + + ATF_REQUIRE(!nvlist_exists_bool_array(src, "nvl/bool")); + nvlist_add_bool_array(src, "nvl/bool", testbool, 16); + ATF_REQUIRE_EQ(nvlist_error(src), 0); + ATF_REQUIRE(nvlist_exists_bool_array(src, "nvl/bool")); + + ATF_REQUIRE(!nvlist_exists_string_array(src, "nvl/string")); + nvlist_add_string_array(src, "nvl/string", string, 8); + ATF_REQUIRE_EQ(nvlist_error(src), 0); + ATF_REQUIRE(nvlist_exists_string_array(src, "nvl/string")); + + ATF_REQUIRE(!nvlist_exists_descriptor_array(src, "nvl/fd")); + nvlist_add_descriptor_array(src, "nvl/fd", testfd, 16); + ATF_REQUIRE_EQ(nvlist_error(src), 0); + ATF_REQUIRE(nvlist_exists_descriptor_array(src, "nvl/fd")); + + ATF_REQUIRE(!nvlist_exists_number_array(src, "nvl/number")); + nvlist_add_number_array(src, "nvl/number", number, 8); + ATF_REQUIRE_EQ(nvlist_error(src), 0); + ATF_REQUIRE(nvlist_exists_number_array(src, "nvl/number")); + + ATF_REQUIRE(!nvlist_exists_nvlist_array(src, "nvl/array")); + nvlist_add_nvlist_array(src, "nvl/array", + (const nvlist_t * const *)testnvl, 8); + ATF_REQUIRE_EQ(nvlist_error(src), 0); + ATF_REQUIRE(nvlist_exists_nvlist_array(src, "nvl/array")); + + dst = nvlist_clone(src); + ATF_REQUIRE(dst != NULL); + + ATF_REQUIRE(nvlist_exists_bool_array(dst, "nvl/bool")); + (void) nvlist_get_bool_array(dst, "nvl/bool", &nitems); + ATF_REQUIRE_EQ(nitems, 16); + for (i = 0; i < nitems; i++) { + ATF_REQUIRE( + nvlist_get_bool_array(dst, "nvl/bool", &nitems)[i] == + nvlist_get_bool_array(src, "nvl/bool", &nitems)[i]); + } + + ATF_REQUIRE(nvlist_exists_string_array(dst, "nvl/string")); + (void) nvlist_get_string_array(dst, "nvl/string", &nitems); + ATF_REQUIRE_EQ(nitems, 8); + for (i = 0; i < nitems; i++) { + if (nvlist_get_string_array(dst, "nvl/string", + &nitems)[i] == NULL) { + ATF_REQUIRE(nvlist_get_string_array(dst, "nvl/string", + &nitems)[i] == nvlist_get_string_array(src, + "nvl/string", &nitems)[i]); + } else { + ATF_REQUIRE(strcmp(nvlist_get_string_array(dst, + "nvl/string", &nitems)[i], nvlist_get_string_array( + src, "nvl/string", &nitems)[i]) == 0); + } + } + + ATF_REQUIRE(nvlist_exists_descriptor_array(dst, "nvl/fd")); + (void) nvlist_get_descriptor_array(dst, "nvl/fd", &nitems); + ATF_REQUIRE_EQ(nitems, 16); + for (i = 0; i < nitems; i++) { + ATF_REQUIRE(fd_is_valid( + nvlist_get_descriptor_array(dst, "nvl/fd", &nitems)[i])); + } + ATF_REQUIRE(nvlist_exists_number_array(dst, "nvl/number")); + (void) nvlist_get_number_array(dst, "nvl/number", &nitems); + ATF_REQUIRE_EQ(nitems, 8); + + for (i = 0; i < nitems; i++) { + ATF_REQUIRE( + nvlist_get_number_array(dst, "nvl/number", &nitems)[i] == + nvlist_get_number_array(src, "nvl/number", &nitems)[i]); + } + + ATF_REQUIRE(nvlist_exists_nvlist_array(dst, "nvl/array")); + (void) nvlist_get_nvlist_array(dst, "nvl/array", &nitems); + ATF_REQUIRE_EQ(nitems, 8); + for (i = 0; i < nitems; i++) { + nvl = nvlist_get_nvlist_array(dst, "nvl/array", &nitems)[i]; + ATF_REQUIRE(nvlist_exists_string(nvl, "nvl/nvl/teststr")); + ATF_REQUIRE(strcmp(nvlist_get_string(nvl, "nvl/nvl/teststr"), + somestr[i]) == 0); + } + + for (i = 0; i < 16; i++) { + close(testfd[i]); + if (i < 8) { + nvlist_destroy(testnvl[i]); + } + } + nvlist_destroy(src); + nvlist_destroy(dst); +} + +ATF_TEST_CASE_WITHOUT_HEAD(nvlist_bool_array__move); +ATF_TEST_CASE_BODY(nvlist_bool_array__move) +{ + bool *testbool; + const bool *const_result; + nvlist_t *nvl; + size_t nitems, count; + unsigned int i; + const char *key; + + key = "nvl/bool"; + nvl = nvlist_create(0); + ATF_REQUIRE(nvl != NULL); + ATF_REQUIRE(nvlist_empty(nvl)); + ATF_REQUIRE(!nvlist_exists_string_array(nvl, key)); + + count = 16; + testbool = (bool*)malloc(sizeof(*testbool) * count); + ATF_REQUIRE(testbool != NULL); + for (i = 0; i < count; i++) + testbool[i] = (i % 2 == 0); + + nvlist_move_bool_array(nvl, key, testbool, count); + ATF_REQUIRE_EQ(nvlist_error(nvl), 0); + ATF_REQUIRE(!nvlist_empty(nvl)); + ATF_REQUIRE(nvlist_exists_bool_array(nvl, key)); + + const_result = nvlist_get_bool_array(nvl, key, &nitems); + ATF_REQUIRE_EQ(nitems, count); + ATF_REQUIRE(const_result != NULL); + ATF_REQUIRE(const_result == testbool); + for (i = 0; i < nitems; i++) + ATF_REQUIRE_EQ(const_result[i], (i % 2 == 0)); + + nvlist_destroy(nvl); +} + +ATF_TEST_CASE_WITHOUT_HEAD(nvlist_string_array__move); +ATF_TEST_CASE_BODY(nvlist_string_array__move) +{ + char **teststr; + const char * const *const_result; + nvlist_t *nvl; + size_t nitems, count; + unsigned int i; + const char *key; + + key = "nvl/string"; + nvl = nvlist_create(0); + ATF_REQUIRE(nvl != NULL); + ATF_REQUIRE(nvlist_empty(nvl)); + ATF_REQUIRE(!nvlist_exists_string_array(nvl, key)); + + count = 26; + teststr = (char**)malloc(sizeof(*teststr) * count); + ATF_REQUIRE(teststr != NULL); + for (i = 0; i < count; i++) { + teststr[i] = (char*)malloc(sizeof(**teststr) * 2); + ATF_REQUIRE(teststr[i] != NULL); + teststr[i][0] = 'a' + i; + teststr[i][1] = '\0'; + } + + nvlist_move_string_array(nvl, key, teststr, count); + ATF_REQUIRE_EQ(nvlist_error(nvl), 0); + ATF_REQUIRE(!nvlist_empty(nvl)); + ATF_REQUIRE(nvlist_exists_string_array(nvl, key)); + + const_result = nvlist_get_string_array(nvl, key, &nitems); + ATF_REQUIRE_EQ(nitems, count); + ATF_REQUIRE(const_result != NULL); + ATF_REQUIRE((intptr_t)const_result == (intptr_t)teststr); + for (i = 0; i < nitems; i++) { + ATF_REQUIRE_EQ(const_result[i][0], (char)('a' + i)); + ATF_REQUIRE_EQ(const_result[i][1], '\0'); + } + + nvlist_destroy(nvl); +} + +ATF_TEST_CASE_WITHOUT_HEAD(nvlist_nvlist_array__move); +ATF_TEST_CASE_BODY(nvlist_nvlist_array__move) +{ + nvlist **testnv; + const nvlist * const *const_result; + nvlist_t *nvl; + size_t nitems, count; + unsigned int i; + const char *key; + + key = "nvl/nvlist"; + nvl = nvlist_create(0); + ATF_REQUIRE(nvl != NULL); + ATF_REQUIRE(nvlist_empty(nvl)); + ATF_REQUIRE(!nvlist_exists_nvlist_array(nvl, key)); + + count = 26; + testnv = (nvlist**)malloc(sizeof(*testnv) * count); + ATF_REQUIRE(testnv != NULL); + for (i = 0; i < count; i++) { + testnv[i] = nvlist_create(0); + ATF_REQUIRE(testnv[i] != NULL); + } + + nvlist_move_nvlist_array(nvl, key, testnv, count); + ATF_REQUIRE_EQ(nvlist_error(nvl), 0); + ATF_REQUIRE(!nvlist_empty(nvl)); + ATF_REQUIRE(nvlist_exists_nvlist_array(nvl, key)); + + const_result = nvlist_get_nvlist_array(nvl, key, &nitems); + ATF_REQUIRE_EQ(nitems, count); + ATF_REQUIRE(const_result != NULL); + ATF_REQUIRE((intptr_t)const_result == (intptr_t)testnv); + for (i = 0; i < nitems; i++) { + ATF_REQUIRE_EQ(nvlist_error(const_result[i]), 0); + ATF_REQUIRE(nvlist_empty(const_result[i])); + if (i < nitems - 1) { + ATF_REQUIRE(nvlist_get_array_next(const_result[i]) == + const_result[i + 1]); + } else { + ATF_REQUIRE(nvlist_get_array_next(const_result[i]) == + NULL); + } + ATF_REQUIRE(nvlist_get_parent(const_result[i], NULL) == nvl); + ATF_REQUIRE(nvlist_in_array(const_result[i])); + } + + nvlist_destroy(nvl); +} + +ATF_TEST_CASE_WITHOUT_HEAD(nvlist_number_array__move); +ATF_TEST_CASE_BODY(nvlist_number_array__move) +{ + uint64_t *testnumber; + const uint64_t *const_result; + nvlist_t *nvl; + size_t nitems, count; + unsigned int i; + const char *key; + + key = "nvl/number"; + nvl = nvlist_create(0); + ATF_REQUIRE(nvl != NULL); + ATF_REQUIRE(nvlist_empty(nvl)); + ATF_REQUIRE(!nvlist_exists_string_array(nvl, key)); + + count = 1000; + testnumber = (uint64_t*)malloc(sizeof(*testnumber) * count); + ATF_REQUIRE(testnumber != NULL); + for (i = 0; i < count; i++) + testnumber[i] = i; + + nvlist_move_number_array(nvl, key, testnumber, count); + ATF_REQUIRE_EQ(nvlist_error(nvl), 0); + ATF_REQUIRE(!nvlist_empty(nvl)); + ATF_REQUIRE(nvlist_exists_number_array(nvl, key)); + + const_result = nvlist_get_number_array(nvl, key, &nitems); + ATF_REQUIRE_EQ(nitems, count); + ATF_REQUIRE(const_result != NULL); + ATF_REQUIRE(const_result == testnumber); + for (i = 0; i < nitems; i++) + ATF_REQUIRE_EQ(const_result[i], i); + + nvlist_destroy(nvl); +} + +ATF_TEST_CASE_WITHOUT_HEAD(nvlist_descriptor_array__move); +ATF_TEST_CASE_BODY(nvlist_descriptor_array__move) +{ + int *testfd; + const int *const_result; + nvlist_t *nvl; + size_t nitems, count; + unsigned int i; + const char *key; + + key = "nvl/fd"; + nvl = nvlist_create(0); + ATF_REQUIRE(nvl != NULL); + ATF_REQUIRE(nvlist_empty(nvl)); + ATF_REQUIRE(!nvlist_exists_string_array(nvl, key)); + + count = 50; + testfd = (int*)malloc(sizeof(*testfd) * count); + ATF_REQUIRE(testfd != NULL); + for (i = 0; i < count; i++) { + testfd[i] = dup(STDERR_FILENO); + ATF_REQUIRE(fd_is_valid(testfd[i])); + } + + nvlist_move_descriptor_array(nvl, key, testfd, count); + ATF_REQUIRE_EQ(nvlist_error(nvl), 0); + ATF_REQUIRE(!nvlist_empty(nvl)); + ATF_REQUIRE(nvlist_exists_descriptor_array(nvl, key)); + + const_result = nvlist_get_descriptor_array(nvl, key, &nitems); + ATF_REQUIRE_EQ(nitems, count); + ATF_REQUIRE(const_result != NULL); + ATF_REQUIRE(const_result == testfd); + for (i = 0; i < nitems; i++) + ATF_REQUIRE(fd_is_valid(const_result[i])); + + nvlist_destroy(nvl); +} + +ATF_TEST_CASE_WITHOUT_HEAD(nvlist_arrays__error_null); +ATF_TEST_CASE_BODY(nvlist_arrays__error_null) +{ + nvlist_t *nvl; + + nvl = nvlist_create(0); + ATF_REQUIRE(nvl != NULL); + nvlist_add_number_array(nvl, "nvl/number", NULL, 0); + ATF_REQUIRE(nvlist_error(nvl) != 0); + nvlist_destroy(nvl); + + nvl = nvlist_create(0); + ATF_REQUIRE(nvl != NULL); + nvlist_move_number_array(nvl, "nvl/number", NULL, 0); + ATF_REQUIRE(nvlist_error(nvl) != 0); + nvlist_destroy(nvl); + + nvl = nvlist_create(0); + ATF_REQUIRE(nvl != NULL); + nvlist_add_descriptor_array(nvl, "nvl/fd", NULL, 0); + ATF_REQUIRE(nvlist_error(nvl) != 0); + nvlist_destroy(nvl); + + nvl = nvlist_create(0); + ATF_REQUIRE(nvl != NULL); + nvlist_move_descriptor_array(nvl, "nvl/fd", NULL, 0); + ATF_REQUIRE(nvlist_error(nvl) != 0); + nvlist_destroy(nvl); + + nvl = nvlist_create(0); + ATF_REQUIRE(nvl != NULL); + nvlist_add_string_array(nvl, "nvl/string", NULL, 0); + ATF_REQUIRE(nvlist_error(nvl) != 0); + nvlist_destroy(nvl); + + nvl = nvlist_create(0); + ATF_REQUIRE(nvl != NULL); + nvlist_move_string_array(nvl, "nvl/string", NULL, 0); + ATF_REQUIRE(nvlist_error(nvl) != 0); + nvlist_destroy(nvl); + + nvl = nvlist_create(0); + ATF_REQUIRE(nvl != NULL); + nvlist_add_nvlist_array(nvl, "nvl/nvlist", NULL, 0); + ATF_REQUIRE(nvlist_error(nvl) != 0); + nvlist_destroy(nvl); + + nvl = nvlist_create(0); + ATF_REQUIRE(nvl != NULL); + nvlist_move_nvlist_array(nvl, "nvl/nvlist", NULL, 0); + ATF_REQUIRE(nvlist_error(nvl) != 0); + nvlist_destroy(nvl); + + nvl = nvlist_create(0); + ATF_REQUIRE(nvl != NULL); + nvlist_add_bool_array(nvl, "nvl/bool", NULL, 0); + ATF_REQUIRE(nvlist_error(nvl) != 0); + nvlist_destroy(nvl); + + nvl = nvlist_create(0); + ATF_REQUIRE(nvl != NULL); + nvlist_move_bool_array(nvl, "nvl/bool", NULL, 0); + ATF_REQUIRE(nvlist_error(nvl) != 0); + nvlist_destroy(nvl); +} + +ATF_TEST_CASE_WITHOUT_HEAD(nvlist_arrays__bad_value); +ATF_TEST_CASE_BODY(nvlist_arrays__bad_value) +{ + nvlist_t *nvl, *nvladd[1], **nvlmove; + int fdadd[1], *fdmove; + + nvladd[0] = NULL; + nvl = nvlist_create(0); + ATF_REQUIRE(nvl != NULL); + nvlist_add_nvlist_array(nvl, "nvl/nvlist", nvladd, 1); + ATF_REQUIRE(nvlist_error(nvl) != 0); + nvlist_destroy(nvl); + + nvlmove = (nvlist_t**)malloc(sizeof(*nvlmove)); + ATF_REQUIRE(nvlmove != NULL); + nvlmove[0] = NULL; + nvl = nvlist_create(0); + ATF_REQUIRE(nvl != NULL); + nvlist_move_nvlist_array(nvl, "nvl/nvlist", nvlmove, 1); + ATF_REQUIRE(nvlist_error(nvl) != 0); + nvlist_destroy(nvl); + + fdadd[0] = -2; + nvl = nvlist_create(0); + ATF_REQUIRE(nvl != NULL); + nvlist_add_descriptor_array(nvl, "nvl/fd", fdadd, 1); + ATF_REQUIRE(nvlist_error(nvl) != 0); + nvlist_destroy(nvl); + + fdmove = (int*)malloc(sizeof(*fdmove)); + ATF_REQUIRE(fdmove != NULL); + fdmove[0] = -2; + nvl = nvlist_create(0); + ATF_REQUIRE(nvl != NULL); + nvlist_move_descriptor_array(nvl, "nvl/fd", fdmove, 1); + ATF_REQUIRE(nvlist_error(nvl) != 0); + nvlist_destroy(nvl); +} + +ATF_TEST_CASE_WITHOUT_HEAD(nvlist_nvlist_array__travel); +ATF_TEST_CASE_BODY(nvlist_nvlist_array__travel) +{ + nvlist_t *nvl, *test[5], *nasted; + const nvlist_t *travel; + void *cookie; + int index, i, type; + const char *name; + + for (i = 0; i < 5; i++) { + test[i] = nvlist_create(0); + ATF_REQUIRE(test[i] != NULL); + nvlist_add_number(test[i], "nvl/number", i); + ATF_REQUIRE(nvlist_error(test[i]) == 0); + } + nvl = nvlist_create(0); + ATF_REQUIRE(nvl != NULL); + nvlist_add_nvlist_array(nvl, "nvl/nvlist_array", test, 5); + ATF_REQUIRE(nvlist_error(nvl) == 0); + nasted = nvlist_create(0); + ATF_REQUIRE(nasted != NULL); + nvlist_add_nvlist_array(nasted, "nvl/nvl/nvlist_array", test, 5); + ATF_REQUIRE(nvlist_error(nasted) == 0); + nvlist_move_nvlist(nvl, "nvl/nvl", nasted); + ATF_REQUIRE(nvlist_error(nvl) == 0); + nvlist_add_string(nvl, "nvl/string", "END"); + ATF_REQUIRE(nvlist_error(nvl) == 0); + + cookie = NULL; + index = 0; + travel = nvl; + do { + while ((name = nvlist_next(travel, &type, &cookie)) != NULL) { + if (index == 0) { + ATF_REQUIRE(type == NV_TYPE_NVLIST_ARRAY); + } else if (index >= 1 && index <= 5) { + ATF_REQUIRE(type == NV_TYPE_NUMBER); + } else if (index == 6) { + ATF_REQUIRE(type == NV_TYPE_NVLIST); + } else if (index == 7) { + ATF_REQUIRE(type == NV_TYPE_NVLIST_ARRAY); + } else if (index >= 8 && index <= 12) { + ATF_REQUIRE(type == NV_TYPE_NUMBER); + } else if (index == 13) { + ATF_REQUIRE(type == NV_TYPE_STRING); + } + + if (type == NV_TYPE_NVLIST) { + travel = nvlist_get_nvlist(travel, name); + cookie = NULL; + } else if (type == NV_TYPE_NVLIST_ARRAY) { + travel = nvlist_get_nvlist_array(travel, name, + NULL)[0]; + cookie = NULL; + } + index ++; + } + } while ((travel = nvlist_get_pararr(travel, &cookie)) != NULL); + + for (i = 0; i < 5; i++) + nvlist_destroy(test[i]); + + nvlist_destroy(nvl); +} + +ATF_TEST_CASE_WITHOUT_HEAD(nvlist_nvlist_array__travel_alternative); +ATF_TEST_CASE_BODY(nvlist_nvlist_array__travel_alternative) +{ + nvlist_t *nvl, *test[5], *nasted; + const nvlist_t *travel, *tmp; + void *cookie; + int index, i, type; + const char *name; + + for (i = 0; i < 5; i++) { + test[i] = nvlist_create(0); + ATF_REQUIRE(test[i] != NULL); + nvlist_add_number(test[i], "nvl/number", i); + ATF_REQUIRE(nvlist_error(test[i]) == 0); + } + nvl = nvlist_create(0); + ATF_REQUIRE(nvl != NULL); + nvlist_add_nvlist_array(nvl, "nvl/nvlist_array", test, 5); + ATF_REQUIRE(nvlist_error(nvl) == 0); + nasted = nvlist_create(0); + ATF_REQUIRE(nasted != NULL); + nvlist_add_nvlist_array(nasted, "nvl/nvl/nvlist_array", test, 5); + ATF_REQUIRE(nvlist_error(nasted) == 0); + nvlist_move_nvlist(nvl, "nvl/nvl", nasted); + ATF_REQUIRE(nvlist_error(nvl) == 0); + nvlist_add_string(nvl, "nvl/string", "END"); + ATF_REQUIRE(nvlist_error(nvl) == 0); + + cookie = NULL; + index = 0; + tmp = travel = nvl; + do { + do { + travel = tmp; + while ((name = nvlist_next(travel, &type, &cookie)) != + NULL) { + if (index == 0) { + ATF_REQUIRE(type == + NV_TYPE_NVLIST_ARRAY); + } else if (index >= 1 && index <= 5) { + ATF_REQUIRE(type == NV_TYPE_NUMBER); + } else if (index == 6) { + ATF_REQUIRE(type == NV_TYPE_NVLIST); + } else if (index == 7) { + ATF_REQUIRE(type == + NV_TYPE_NVLIST_ARRAY); + } else if (index >= 8 && index <= 12) { + ATF_REQUIRE(type == NV_TYPE_NUMBER); + } else if (index == 13) { + ATF_REQUIRE(type == NV_TYPE_STRING); + } + + if (type == NV_TYPE_NVLIST) { + travel = nvlist_get_nvlist(travel, + name); + cookie = NULL; + } else if (type == NV_TYPE_NVLIST_ARRAY) { + travel = nvlist_get_nvlist_array(travel, + name, NULL)[0]; + cookie = NULL; + } + index ++; + } + cookie = NULL; + } while ((tmp = nvlist_get_array_next(travel)) != NULL); + } while ((tmp = nvlist_get_parent(travel, &cookie)) != NULL); + + for (i = 0; i < 5; i++) + nvlist_destroy(test[i]); + + nvlist_destroy(nvl); +} + +ATF_TEST_CASE_WITHOUT_HEAD(nvlist_bool_array__pack); +ATF_TEST_CASE_BODY(nvlist_bool_array__pack) +{ + nvlist_t *nvl, *unpacked; + const char *key; + size_t packed_size, count; + void *packed; + unsigned int i; + const bool *const_result; + bool testbool[16]; + + for (i = 0; i < 16; i++) + testbool[i] = (i % 2 == 0); + + key = "nvl/bool"; + nvl = nvlist_create(0); + ATF_REQUIRE(nvl != NULL); + ATF_REQUIRE(nvlist_empty(nvl)); + ATF_REQUIRE(!nvlist_exists_string_array(nvl, key)); + + nvlist_add_bool_array(nvl, key, testbool, 16); + ATF_REQUIRE_EQ(nvlist_error(nvl), 0); + ATF_REQUIRE(!nvlist_empty(nvl)); + ATF_REQUIRE(nvlist_exists_bool_array(nvl, key)); + + packed = nvlist_pack(nvl, &packed_size); + ATF_REQUIRE(packed != NULL); + + unpacked = nvlist_unpack(packed, packed_size, 0); + ATF_REQUIRE(unpacked != NULL); + ATF_REQUIRE_EQ(nvlist_error(unpacked), 0); + ATF_REQUIRE(nvlist_exists_bool_array(unpacked, key)); + + const_result = nvlist_get_bool_array(unpacked, key, &count); + ATF_REQUIRE_EQ(count, 16); + for (i = 0; i < count; i++) { + ATF_REQUIRE_EQ(testbool[i], const_result[i]); + } + + nvlist_destroy(nvl); + nvlist_destroy(unpacked); + free(packed); +} + +ATF_TEST_CASE_WITHOUT_HEAD(nvlist_number_array__pack); +ATF_TEST_CASE_BODY(nvlist_number_array__pack) +{ + nvlist_t *nvl, *unpacked; + const char *key; + size_t packed_size, count; + void *packed; + unsigned int i; + const uint64_t *const_result; + const uint64_t number[8] = { 0, UINT_MAX, 7, 123, 90, + 100000, 8, 1 }; + + key = "nvl/number"; + nvl = nvlist_create(0); + ATF_REQUIRE(nvl != NULL); + ATF_REQUIRE(nvlist_empty(nvl)); + ATF_REQUIRE(!nvlist_exists_string_array(nvl, key)); + + nvlist_add_number_array(nvl, key, number, 8); + ATF_REQUIRE_EQ(nvlist_error(nvl), 0); + ATF_REQUIRE(!nvlist_empty(nvl)); + ATF_REQUIRE(nvlist_exists_number_array(nvl, key)); + + packed = nvlist_pack(nvl, &packed_size); + ATF_REQUIRE(packed != NULL); + + unpacked = nvlist_unpack(packed, packed_size, 0); + ATF_REQUIRE(unpacked != NULL); + ATF_REQUIRE_EQ(nvlist_error(unpacked), 0); + ATF_REQUIRE(nvlist_exists_number_array(unpacked, key)); + + const_result = nvlist_get_number_array(unpacked, key, &count); + ATF_REQUIRE_EQ(count, 8); + for (i = 0; i < count; i++) { + ATF_REQUIRE_EQ(number[i], const_result[i]); + } + + nvlist_destroy(nvl); + nvlist_destroy(unpacked); + free(packed); +} + +ATF_TEST_CASE_WITHOUT_HEAD(nvlist_descriptor_array__pack); +ATF_TEST_CASE_BODY(nvlist_descriptor_array__pack) +{ + nvlist_t *nvl; + const char *key; + size_t nitems; + unsigned int i; + const int *const_result; + int desc[32], fd, socks[2]; + pid_t pid; + + key = "nvl/descriptor"; + + ATF_REQUIRE_EQ(socketpair(PF_UNIX, SOCK_STREAM, 0, socks), 0); + + pid = atf::utils::fork(); + ATF_REQUIRE(pid >= 0); + if (pid == 0) { + /* Child. */ + fd = socks[0]; + close(socks[1]); + for (i = 0; i < 32; i++) { + desc[i] = dup(STDERR_FILENO); + ATF_REQUIRE(fd_is_valid(desc[i])); + } + + nvl = nvlist_create(0); + ATF_REQUIRE(nvl != NULL); + ATF_REQUIRE(nvlist_empty(nvl)); + ATF_REQUIRE(!nvlist_exists_descriptor_array(nvl, key)); + + nvlist_add_descriptor_array(nvl, key, desc, 32); + ATF_REQUIRE_EQ(nvlist_error(nvl), 0); + ATF_REQUIRE(!nvlist_empty(nvl)); + ATF_REQUIRE(nvlist_exists_descriptor_array(nvl, key)); + + ATF_REQUIRE(nvlist_send(fd, nvl) >= 0); + + for (i = 0; i < nitems; i++) + close(desc[i]); + } else { + /* Parent */ + fd = socks[1]; + close(socks[0]); + + errno = 0; + nvl = nvlist_recv(fd, 0); + ATF_REQUIRE(nvl != NULL); + ATF_REQUIRE_EQ(nvlist_error(nvl), 0); + ATF_REQUIRE(nvlist_exists_descriptor_array(nvl, key)); + + const_result = nvlist_get_descriptor_array(nvl, key, &nitems); + ATF_REQUIRE(const_result != NULL); + ATF_REQUIRE_EQ(nitems, 32); + for (i = 0; i < nitems; i++) + ATF_REQUIRE(fd_is_valid(const_result[i])); + + atf::utils::wait(pid, 0, "", ""); + } + + nvlist_destroy(nvl); + close(fd); +} + +ATF_TEST_CASE_WITHOUT_HEAD(nvlist_string_array__pack); +ATF_TEST_CASE_BODY(nvlist_string_array__pack) +{ + nvlist_t *nvl, *unpacked; + const char *key; + size_t packed_size, count; + void *packed; + unsigned int i; + const char * const *const_result; + const char *string[8] = { "a", "b", "kot", "foo", + "tests", "nice test", "", "abcdef" }; + + key = "nvl/string"; + nvl = nvlist_create(0); + ATF_REQUIRE(nvl != NULL); + ATF_REQUIRE(nvlist_empty(nvl)); + ATF_REQUIRE(!nvlist_exists_string_array(nvl, key)); + + nvlist_add_string_array(nvl, key, string, 8); + ATF_REQUIRE_EQ(nvlist_error(nvl), 0); + ATF_REQUIRE(!nvlist_empty(nvl)); + ATF_REQUIRE(nvlist_exists_string_array(nvl, key)); + + packed = nvlist_pack(nvl, &packed_size); + ATF_REQUIRE(packed != NULL); + + unpacked = nvlist_unpack(packed, packed_size, 0); + ATF_REQUIRE(unpacked != NULL); + ATF_REQUIRE_EQ(nvlist_error(unpacked), 0); + ATF_REQUIRE(nvlist_exists_string_array(unpacked, key)); + + const_result = nvlist_get_string_array(unpacked, key, &count); + ATF_REQUIRE_EQ(count, 8); + for (i = 0; i < count; i++) { + ATF_REQUIRE_EQ(strcmp(string[i], const_result[i]), 0); + } + + nvlist_destroy(nvl); + nvlist_destroy(unpacked); + free(packed); +} + +ATF_TEST_CASE_WITHOUT_HEAD(nvlist_nvlist_array__pack); +ATF_TEST_CASE_BODY(nvlist_nvlist_array__pack) +{ + nvlist_t *testnvl[8], *unpacked; + const nvlist_t * const *const_result; + nvlist_t **result; + nvlist_t *nvl; + size_t nitems, packed_size; + unsigned int i; + void *packed; + const char *somestr[8] = { "a", "b", "c", "d", "e", "f", "g", "h" }; + const char *key; + + for (i = 0; i < 8; i++) { + testnvl[i] = nvlist_create(0); + ATF_REQUIRE(testnvl[i] != NULL); + ATF_REQUIRE_EQ(nvlist_error(testnvl[i]), 0); + nvlist_add_string(testnvl[i], "nvl/string", somestr[i]); + ATF_REQUIRE_EQ(nvlist_error(testnvl[i]), 0); + ATF_REQUIRE(nvlist_exists_string(testnvl[i], "nvl/string")); + } + + key = "nvl/nvlist"; + nvl = nvlist_create(0); + ATF_REQUIRE(nvl != NULL); + ATF_REQUIRE(nvlist_empty(nvl)); + ATF_REQUIRE(!nvlist_exists_string_array(nvl, key)); + + nvlist_add_nvlist_array(nvl, key, (const nvlist_t * const *)testnvl, 8); + ATF_REQUIRE_EQ(nvlist_error(nvl), 0); + ATF_REQUIRE(!nvlist_empty(nvl)); + ATF_REQUIRE(nvlist_exists_nvlist_array(nvl, key)); + ATF_REQUIRE(nvlist_exists_nvlist_array(nvl, "nvl/nvlist")); + packed = nvlist_pack(nvl, &packed_size); + ATF_REQUIRE(packed != NULL); + + unpacked = nvlist_unpack(packed, packed_size, 0); + ATF_REQUIRE(unpacked != NULL); + ATF_REQUIRE_EQ(nvlist_error(unpacked), 0); + ATF_REQUIRE(nvlist_exists_nvlist_array(unpacked, key)); + + const_result = nvlist_get_nvlist_array(unpacked, key, &nitems); + ATF_REQUIRE(const_result != NULL); + ATF_REQUIRE_EQ(nitems, 8); + for (i = 0; i < nitems; i++) { + ATF_REQUIRE_EQ(nvlist_error(const_result[i]), 0); + if (i < nitems - 1) { + ATF_REQUIRE(nvlist_get_array_next(const_result[i]) == + const_result[i + 1]); + } else { + ATF_REQUIRE(nvlist_get_array_next(const_result[i]) == + NULL); + } + ATF_REQUIRE(nvlist_get_parent(const_result[i], NULL) == unpacked); + ATF_REQUIRE(nvlist_in_array(const_result[i])); + ATF_REQUIRE(nvlist_exists_string(const_result[i], + "nvl/string")); + ATF_REQUIRE(strcmp(nvlist_get_string(const_result[i], + "nvl/string"), somestr[i]) == 0); + } + + for (i = 0; i < 8; i++) + nvlist_destroy(testnvl[i]); + free(result); + nvlist_destroy(nvl); + nvlist_destroy(unpacked); + free(packed); +} + +ATF_INIT_TEST_CASES(tp) +{ + + ATF_ADD_TEST_CASE(tp, nvlist_bool_array__basic); + ATF_ADD_TEST_CASE(tp, nvlist_string_array__basic); + ATF_ADD_TEST_CASE(tp, nvlist_descriptor_array__basic); + ATF_ADD_TEST_CASE(tp, nvlist_number_array__basic); + ATF_ADD_TEST_CASE(tp, nvlist_nvlist_array__basic) + + ATF_ADD_TEST_CASE(tp, nvlist_clone_array) + + ATF_ADD_TEST_CASE(tp, nvlist_bool_array__move); + ATF_ADD_TEST_CASE(tp, nvlist_string_array__move); + ATF_ADD_TEST_CASE(tp, nvlist_nvlist_array__move); + ATF_ADD_TEST_CASE(tp, nvlist_number_array__move); + ATF_ADD_TEST_CASE(tp, nvlist_descriptor_array__move); + + ATF_ADD_TEST_CASE(tp, nvlist_arrays__error_null); + + ATF_ADD_TEST_CASE(tp, nvlist_arrays__bad_value) + + ATF_ADD_TEST_CASE(tp, nvlist_nvlist_array__travel) + ATF_ADD_TEST_CASE(tp, nvlist_nvlist_array__travel_alternative) + + ATF_ADD_TEST_CASE(tp, nvlist_bool_array__pack) + ATF_ADD_TEST_CASE(tp, nvlist_number_array__pack) + ATF_ADD_TEST_CASE(tp, nvlist_descriptor_array__pack) + ATF_ADD_TEST_CASE(tp, nvlist_string_array__pack) + ATF_ADD_TEST_CASE(tp, nvlist_nvlist_array__pack) +} + diff --git a/lib/libproc/proc_bkpt.c b/lib/libproc/proc_bkpt.c index 50d8a9d67908a..f0ff5c5d77012 100644 --- a/lib/libproc/proc_bkpt.c +++ b/lib/libproc/proc_bkpt.c @@ -51,6 +51,7 @@ __FBSDID("$FreeBSD$"); #elif defined(__amd64__) || defined(__i386__) #define BREAKPOINT_INSTR 0xcc /* int 0x3 */ #define BREAKPOINT_INSTR_SZ 1 +#define BREAKPOINT_ADJUST_SZ BREAKPOINT_INSTR_SZ #elif defined(__arm__) #define BREAKPOINT_INSTR 0xe7ffffff /* bkpt */ #define BREAKPOINT_INSTR_SZ 4 @@ -195,11 +196,19 @@ proc_bkptdel(struct proc_handle *phdl, uintptr_t address, /* * Decrement pc so that we delete the breakpoint at the correct * address, i.e. at the BREAKPOINT_INSTR address. + * + * This is only needed on some architectures where the pc value + * when reading registers points at the instruction after the + * breakpoint, e.g. x86. */ void proc_bkptregadj(unsigned long *pc) { - *pc = *pc - BREAKPOINT_INSTR_SZ; + + (void)pc; +#ifdef BREAKPOINT_ADJUST_SZ + *pc = *pc - BREAKPOINT_ADJUST_SZ; +#endif } /* diff --git a/lib/libprocstat/libprocstat.c b/lib/libprocstat/libprocstat.c index c292d5dae14d9..932b5a0f83afc 100644 --- a/lib/libprocstat/libprocstat.c +++ b/lib/libprocstat/libprocstat.c @@ -767,6 +767,8 @@ kinfo_getfile_core(struct procstat_core *core, int *cntp) eb = buf + len; while (bp < eb) { kf = (struct kinfo_file *)(uintptr_t)bp; + if (kf->kf_structsize == 0) + break; bp += kf->kf_structsize; cnt++; } @@ -782,6 +784,8 @@ kinfo_getfile_core(struct procstat_core *core, int *cntp) /* Pass 2: unpack */ while (bp < eb) { kf = (struct kinfo_file *)(uintptr_t)bp; + if (kf->kf_structsize == 0) + break; /* Copy/expand into pre-zeroed buffer */ memcpy(kp, kf, kf->kf_structsize); /* Advance to next packed record */ diff --git a/lib/libsqlite3/Makefile b/lib/libsqlite3/Makefile index 2db85fb39708a..d446151628783 100644 --- a/lib/libsqlite3/Makefile +++ b/lib/libsqlite3/Makefile @@ -12,10 +12,10 @@ SQLITE= ${.CURDIR}/../../contrib/sqlite3 WARNS= 3 CFLAGS+= -I${SQLITE} \ + -DUSE_PREAD=1 \ -DSTDC_HEADERS=1 \ -DHAVE_SYS_TYPES_H=1 \ -DHAVE_SYS_STAT_H=1 \ - -DUSE_PREAD=1 \ -DHAVE_STDLIB_H=1 \ -DHAVE_STRING_H=1 \ -DHAVE_MEMORY_H=1 \ diff --git a/lib/libstand/Makefile b/lib/libstand/Makefile index 2ee29212f2cf9..a038087dfa44b 100644 --- a/lib/libstand/Makefile +++ b/lib/libstand/Makefile @@ -21,34 +21,8 @@ MAN= libstand.3 WARNS?= 0 -CFLAGS+= -ffreestanding -Wformat CFLAGS+= -I${LIBSTAND_SRC} -.if ${MACHINE_CPUARCH} == "i386" || ${MACHINE_CPUARCH} == "amd64" -CFLAGS+= -mno-mmx -mno-3dnow -mno-sse -mno-sse2 -mno-sse3 -msoft-float -.endif -.if ${MACHINE_CPUARCH} == "i386" -CFLAGS.gcc+= -mpreferred-stack-boundary=2 -.endif -.if ${MACHINE_CPUARCH} == "amd64" -CFLAGS+= -fPIC -mno-red-zone -.endif -.if ${MACHINE} == "pc98" -CFLAGS+= -Os -.endif -.if ${MACHINE_CPUARCH} == "powerpc" -CFLAGS+= -msoft-float -D_STANDALONE -DNETIF_DEBUG -.endif -.if ${MACHINE_CPUARCH} == "arm" -CFLAGS+= -msoft-float -D_STANDALONE -.endif -.if ${MACHINE_CPUARCH} == "aarch64" -CFLAGS+= -D_STANDALONE -mgeneral-regs-only -.endif -.if ${MACHINE_CPUARCH} == "mips" -CFLAGS+= -G0 -fno-pic -mno-abicalls -.endif - # standalone components and stuff we have modified locally SRCS+= gzguts.h zutil.h __main.c assert.c bcd.c bswap.c environment.c getopt.c gets.c \ globals.c pager.c printf.c strdup.c strerror.c strtol.c strtoul.c random.c \ @@ -168,4 +142,5 @@ SRCS+= pkgfs.c SRCS+= nandfs.c .endif +.include <bsd.stand.mk> .include <bsd.lib.mk> diff --git a/lib/libthr/arch/amd64/Makefile.inc b/lib/libthr/arch/amd64/Makefile.inc index 797618d4183a2..43f6e839ff103 100644 --- a/lib/libthr/arch/amd64/Makefile.inc +++ b/lib/libthr/arch/amd64/Makefile.inc @@ -1,3 +1,9 @@ #$FreeBSD$ SRCS+= _umtx_op_err.S + +# With the current compiler and libthr code, using SSE in libthr +# does not provide enough performance improvement to outweigh +# the extra context switch cost. This can measurably impact +# performance when the application also does not use enough SSE. +CFLAGS+=${CFLAGS_NO_SIMD} diff --git a/lib/libthr/arch/i386/Makefile.inc b/lib/libthr/arch/i386/Makefile.inc index bdab0bc90fe6f..23a95498f4438 100644 --- a/lib/libthr/arch/i386/Makefile.inc +++ b/lib/libthr/arch/i386/Makefile.inc @@ -1,3 +1,9 @@ # $FreeBSD$ SRCS+= _umtx_op_err.S + +# With the current compiler and libthr code, using SSE in libthr +# does not provide enough performance improvement to outweigh +# the extra context switch cost. This can measurably impact +# performance when the application also does not use enough SSE. +CFLAGS+=${CFLAGS_NO_SIMD} diff --git a/lib/libthr/thread/thr_once.c b/lib/libthr/thread/thr_once.c index 4f7037416c259..208b703ff4322 100644 --- a/lib/libthr/thread/thr_once.c +++ b/lib/libthr/thread/thr_once.c @@ -50,9 +50,11 @@ __weak_reference(_pthread_once, pthread_once); static void once_cancel_handler(void *arg) { - pthread_once_t *once_control = arg; + pthread_once_t *once_control; - if (atomic_cmpset_rel_int(&once_control->state, ONCE_IN_PROGRESS, ONCE_NEVER_DONE)) + once_control = arg; + if (atomic_cmpset_rel_int(&once_control->state, ONCE_IN_PROGRESS, + ONCE_NEVER_DONE)) return; atomic_store_rel_int(&once_control->state, ONCE_NEVER_DONE); _thr_umtx_wake(&once_control->state, INT_MAX, 0); @@ -68,16 +70,22 @@ _pthread_once(pthread_once_t *once_control, void (*init_routine) (void)) for (;;) { state = once_control->state; - if (state == ONCE_DONE) + if (state == ONCE_DONE) { + atomic_thread_fence_acq(); return (0); + } if (state == ONCE_NEVER_DONE) { - if (atomic_cmpset_acq_int(&once_control->state, state, ONCE_IN_PROGRESS)) + if (atomic_cmpset_int(&once_control->state, state, + ONCE_IN_PROGRESS)) break; } else if (state == ONCE_IN_PROGRESS) { - if (atomic_cmpset_acq_int(&once_control->state, state, ONCE_WAIT)) - _thr_umtx_wait_uint(&once_control->state, ONCE_WAIT, NULL, 0); + if (atomic_cmpset_int(&once_control->state, state, + ONCE_WAIT)) + _thr_umtx_wait_uint(&once_control->state, + ONCE_WAIT, NULL, 0); } else if (state == ONCE_WAIT) { - _thr_umtx_wait_uint(&once_control->state, state, NULL, 0); + _thr_umtx_wait_uint(&once_control->state, state, + NULL, 0); } else return (EINVAL); } @@ -86,7 +94,8 @@ _pthread_once(pthread_once_t *once_control, void (*init_routine) (void)) THR_CLEANUP_PUSH(curthread, once_cancel_handler, once_control); init_routine(); THR_CLEANUP_POP(curthread, 0); - if (atomic_cmpset_rel_int(&once_control->state, ONCE_IN_PROGRESS, ONCE_DONE)) + if (atomic_cmpset_rel_int(&once_control->state, ONCE_IN_PROGRESS, + ONCE_DONE)) return (0); atomic_store_rel_int(&once_control->state, ONCE_DONE); _thr_umtx_wake(&once_control->state, INT_MAX, 0); @@ -94,6 +103,6 @@ _pthread_once(pthread_once_t *once_control, void (*init_routine) (void)) } void -_thr_once_init() +_thr_once_init(void) { } diff --git a/lib/libthr/thread/thr_rtld.c b/lib/libthr/thread/thr_rtld.c index 5d899880d1c59..cb200980cb26a 100644 --- a/lib/libthr/thread/thr_rtld.c +++ b/lib/libthr/thread/thr_rtld.c @@ -185,7 +185,9 @@ _thr_rtld_init(void) { struct RtldLockInfo li; struct pthread *curthread; + ucontext_t *uc; long dummy = -1; + int uc_len; curthread = _get_curthread(); @@ -231,4 +233,9 @@ _thr_rtld_init(void) _thr_signal_block(curthread); _rtld_thread_init(&li); _thr_signal_unblock(curthread); + + uc_len = __getcontextx_size(); + uc = alloca(uc_len); + getcontext(uc); + __fillcontextx2((char *)uc); } diff --git a/lib/libthr/thread/thr_sig.c b/lib/libthr/thread/thr_sig.c index a6d021fed31db..ebb6c58a4bb67 100644 --- a/lib/libthr/thread/thr_sig.c +++ b/lib/libthr/thread/thr_sig.c @@ -30,6 +30,7 @@ #include <sys/param.h> #include <sys/types.h> #include <sys/signalvar.h> +#include <sys/syscall.h> #include <signal.h> #include <errno.h> #include <stdlib.h> @@ -257,7 +258,7 @@ handle_signal(struct sigaction *actp, int sig, siginfo_t *info, ucontext_t *ucp) /* reschedule cancellation */ check_cancel(curthread, &uc2); errno = err; - __sys_sigreturn(&uc2); + syscall(SYS_sigreturn, &uc2); } void diff --git a/lib/libusb/Makefile b/lib/libusb/Makefile index 24d97fd63aacd..6560f8f0b231d 100644 --- a/lib/libusb/Makefile +++ b/lib/libusb/Makefile @@ -70,8 +70,6 @@ CFLAGS+= -DUSB_GLOBAL_INCLUDE_FILE=\"${LIBUSB_GLOBAL_INCLUDE_FILE}\" CFLAGS+= -I ../../sys .endif -.include <bsd.lib.mk> - # LibUSB v1.0 MLINKS += libusb.3 libusb_init.3 MLINKS += libusb.3 libusb_exit.3 @@ -259,3 +257,5 @@ MLINKS += libusb20.3 libusb20_me_decode.3 MLINKS += libusb20.3 libusb20_desc_foreach.3 MLINKS += libusb20.3 libusb20_strerror.3 MLINKS += libusb20.3 libusb20_error_name.3 + +.include <bsd.lib.mk> diff --git a/lib/libutil/kinfo_getfile.c b/lib/libutil/kinfo_getfile.c index 84b64db202043..8a5477f406549 100644 --- a/lib/libutil/kinfo_getfile.c +++ b/lib/libutil/kinfo_getfile.c @@ -44,6 +44,8 @@ kinfo_getfile(pid_t pid, int *cntp) eb = buf + len; while (bp < eb) { kf = (struct kinfo_file *)(uintptr_t)bp; + if (kf->kf_structsize == 0) + break; bp += kf->kf_structsize; cnt++; } @@ -59,6 +61,8 @@ kinfo_getfile(pid_t pid, int *cntp) /* Pass 2: unpack */ while (bp < eb) { kf = (struct kinfo_file *)(uintptr_t)bp; + if (kf->kf_structsize == 0) + break; /* Copy/expand into pre-zeroed buffer */ memcpy(kp, kf, kf->kf_structsize); /* Advance to next packed record */ diff --git a/lib/libutil/tests/Makefile b/lib/libutil/tests/Makefile index 36eb2ae55d370..4a675b0cc18ff 100644 --- a/lib/libutil/tests/Makefile +++ b/lib/libutil/tests/Makefile @@ -5,7 +5,9 @@ TESTSDIR= ${TESTSBASE}/lib/libutil TAP_TESTS_C+= flopen_test TAP_TESTS_C+= grp_test TAP_TESTS_C+= humanize_number_test +.if ${MACHINE_CPUARCH} != "aarch64" # PR202304: pidfile_test hangs on arm64 TAP_TESTS_C+= pidfile_test +.endif TAP_TESTS_C+= trimdomain_test TAP_TESTS_C+= trimdomain-nodomain_test diff --git a/lib/libxo/Makefile b/lib/libxo/Makefile index 62fface44dfa5..8ca129221eb89 100644 --- a/lib/libxo/Makefile +++ b/lib/libxo/Makefile @@ -9,33 +9,40 @@ SHLIB_MAJOR=0 SHLIBDIR?= /lib -SRCS= libxo.c +SRCS= libxo.c xo_encoder.c xo_syslog.c CFLAGS+=-I${LIBXO}/libxo +CFLAGS+=-DXO_ENCODERDIR=\"/usr/lib/libxo/encoder\" -INCS= xo.h +INCS= xo.h xo_encoder.h INCSDIR=${INCLUDEDIR}/libxo +WARNS?= 5 + MAN+= libxo.3 MAN+= xo_attr.3 \ xo_create.3 \ xo_emit.3 \ + xo_emit_err.3 \ xo_err.3 \ xo_error.3 \ xo_finish.3 \ xo_flush.3 \ + xo_message.3 \ xo_no_setlocale.3 \ xo_open_container.3 \ - xo_open_marker.3 \ xo_open_list.3 \ + xo_open_marker.3 \ xo_parse_args.3 \ xo_set_allocator.3 \ xo_set_flags.3 \ xo_set_info.3 \ xo_set_options.3 \ xo_set_style.3 \ + xo_set_syslog_enterprise_id.3 \ xo_set_version.3 \ - xo_set_writer.3 + xo_set_writer.3 \ + xo_syslog.3 MAN+= xo_format.5 MLINKS= xo_attr.3 xo_attr_h.3 \ @@ -44,18 +51,23 @@ MLINKS= xo_attr.3 xo_attr_h.3 \ xo_create.3 xo_destroy.3 \ xo_emit.3 xo_emit_h.3 \ xo_emit.3 xo_emit_hv.3 \ + xo_emit_err.3 xo_emit_errc.3 \ + xo_emit_err.3 xo_emit_errx.3 \ + xo_emit_err.3 xo_emit_warn.3 \ + xo_emit_err.3 xo_emit_warnx.3 \ + xo_emit_err.3 xo_emit_warn_c.3 \ + xo_emit_err.3 xo_emit_warn_hc.3 \ + xo_err.3 xo_errc.3 \ + xo_err.3 xo_errx.3 \ xo_err.3 xo_warn.3 \ xo_err.3 xo_warnx.3 \ xo_err.3 xo_warn_c.3 \ xo_err.3 xo_warn_hc.3 \ - xo_err.3 xo_errc.3 \ - xo_err.3 xo_errx.3 \ - xo_err.3 xo_message.3 \ - xo_err.3 xo_message_c.3 \ - xo_err.3 xo_message_hc.3 \ - xo_err.3 xo_message_hcv.3 \ xo_finish.3 xo_finish_h.3 \ xo_flush.3 xo_flush_h.3 \ + xo_message.3 xo_message_c.3 \ + xo_message.3 xo_message_hc.3 \ + xo_message.3 xo_message_hcv.3 \ xo_open_container.3 xo_open_container_h.3 \ xo_open_container.3 xo_open_container_hd.3 \ xo_open_container.3 xo_open_container_d.3 \ @@ -78,7 +90,16 @@ MLINKS= xo_attr.3 xo_attr_h.3 \ xo_open_list.3 xo_close_list_h.3 \ xo_open_list.3 xo_close_list_hd.3 \ xo_open_list.3 xo_close_list_d.3 \ + xo_open_marker.3 xo_open_marker_h.3 \ + xo_open_marker.3 xo_close_marker.3 \ + xo_open_marker.3 xo_close_marker_h.3 \ + xo_parse_args.3 xo_set_program.3 \ xo_set_flags.3 xo_clear_flags.3 \ - xo_set_style.3 xo_set_style_name.3 + xo_set_style.3 xo_set_style_name.3 \ + xo_set_version.3 xo_set_version_h.3 \ + xo_syslog.3 xo_close_log.3 \ + xo_syslog.3 xo_open_log.3 \ + xo_syslog.3 xo_set_logmask.3 \ + xo_syslog.3 xo_vsyslog.3 .include <bsd.lib.mk> diff --git a/lib/libz/inflate.c b/lib/libz/inflate.c index 870f89bb4d364..b51a8a50ad89c 100644 --- a/lib/libz/inflate.c +++ b/lib/libz/inflate.c @@ -1504,7 +1504,7 @@ z_streamp strm; { struct inflate_state FAR *state; - if (strm == Z_NULL || strm->state == Z_NULL) return -1L << 16; + if (strm == Z_NULL || strm->state == Z_NULL) return -(1L << 16); state = (struct inflate_state FAR *)strm->state; return ((long)(state->back) << 16) + (state->mode == COPY ? state->length : diff --git a/lib/msun/src/s_exp2.c b/lib/msun/src/s_exp2.c index fde11c27d63e7..5cf2e15bd259e 100644 --- a/lib/msun/src/s_exp2.c +++ b/lib/msun/src/s_exp2.c @@ -376,14 +376,14 @@ exp2(double x) /* Compute r = exp2(y) = exp2t[i0] * p(z - eps[i]). */ t = tbl[i0]; /* exp2t[i0] */ z -= tbl[i0 + 1]; /* eps[i0] */ - if (k >= -1021 << 20) + if (k >= -(1021 << 20)) INSERT_WORDS(twopk, 0x3ff00000 + k, 0); else INSERT_WORDS(twopkp1000, 0x3ff00000 + k + (1000 << 20), 0); r = t + t * z * (P1 + z * (P2 + z * (P3 + z * (P4 + z * P5)))); /* Scale by 2**(k>>20). */ - if(k >= -1021 << 20) { + if(k >= -(1021 << 20)) { if (k == 1024 << 20) return (r * 2.0 * 0x1p1023); return (r * twopk); |
