diff options
author | Jerry Jelinek <jerry.jelinek@joyent.com> | 2018-08-17 12:26:02 +0000 |
---|---|---|
committer | Jerry Jelinek <jerry.jelinek@joyent.com> | 2018-08-17 12:26:02 +0000 |
commit | b024317c8de8fc6aa55e87767b0e084ba5941ce7 (patch) | |
tree | 2fb250f1cfd1ef0a78b9db6c2b2553a1140ef198 /usr/src/lib | |
parent | 48810110f815c605fe76c7da807dcfc9f4962485 (diff) | |
parent | e5ecfaa0ff00b00d0b97e8638701ff77caeeab1d (diff) | |
download | illumos-joyent-b024317c8de8fc6aa55e87767b0e084ba5941ce7.tar.gz |
[illumos-gate merge]
commit e5ecfaa0ff00b00d0b97e8638701ff77caeeab1d
9726 getent could list the attr databases
commit 70ee30a511f4abfd1b9cdf25495a219fe131829a
9719 uts/i86pc: add way to set bootrd_debug
commit ca876c1c4225b51f8e1c2763b28e8466add83a0b
9717 libstand: build with -Wall only
commit 64a170cf91c8d267e7707c00ac13639160db85cd
9703 loader: stage1 should not probe floppies for zfs
commit 843ead088f87e5e766084646370e981f176eb323
9418 iwn: rate array in struct iwn_ks_txpower should have size IWN_RIDX_MAX+1
commit 8e5dcf3a637ec78130ed00945993c8c991997a44
9728 3secdb man pages need some tlc
commit 00efb5e1437d3912284689f1b0c13190e634e788
8548 want memset_s(3C)
commit 3b5ccf6b95a705120c7f7fa193afabfd40dc7342
9242 st: this statement may fall through
Conflicts:
usr/src/test/libc-tests/runfiles/default.run
Diffstat (limited to 'usr/src/lib')
-rw-r--r-- | usr/src/lib/libc/amd64/Makefile | 2 | ||||
-rw-r--r-- | usr/src/lib/libc/i386/Makefile.com | 2 | ||||
-rw-r--r-- | usr/src/lib/libc/inc/libc.h | 10 | ||||
-rw-r--r-- | usr/src/lib/libc/port/gen/memset_s.c | 76 | ||||
-rw-r--r-- | usr/src/lib/libc/port/gen/set_constraint_handler_s.c | 107 | ||||
-rw-r--r-- | usr/src/lib/libc/port/mapfile-vers | 8 | ||||
-rw-r--r-- | usr/src/lib/libc/port/threads/assfail.c | 2 | ||||
-rw-r--r-- | usr/src/lib/libc/sparc/Makefile.com | 2 | ||||
-rw-r--r-- | usr/src/lib/libc/sparcv9/Makefile.com | 2 |
9 files changed, 210 insertions, 1 deletions
diff --git a/usr/src/lib/libc/amd64/Makefile b/usr/src/lib/libc/amd64/Makefile index 550ece08fd..9b57d2517e 100644 --- a/usr/src/lib/libc/amd64/Makefile +++ b/usr/src/lib/libc/amd64/Makefile @@ -467,6 +467,7 @@ PORTGEN= \ malloc.o \ memalign.o \ memmem.o \ + memset_s.o \ mkdev.o \ mkdtemp.o \ mkfifo.o \ @@ -524,6 +525,7 @@ PORTGEN= \ scandir.o \ seekdir.o \ select.o \ + set_constraint_handler_s.o \ setlabel.o \ setpriority.o \ settimeofday.o \ diff --git a/usr/src/lib/libc/i386/Makefile.com b/usr/src/lib/libc/i386/Makefile.com index 255622629c..dd647b2811 100644 --- a/usr/src/lib/libc/i386/Makefile.com +++ b/usr/src/lib/libc/i386/Makefile.com @@ -504,6 +504,7 @@ PORTGEN= \ malloc.o \ memalign.o \ memmem.o \ + memset_s.o \ mkdev.o \ mkdtemp.o \ mkfifo.o \ @@ -561,6 +562,7 @@ PORTGEN= \ scandir.o \ seekdir.o \ select.o \ + set_constraint_handler_s.o \ setlabel.o \ setpriority.o \ settimeofday.o \ diff --git a/usr/src/lib/libc/inc/libc.h b/usr/src/lib/libc/inc/libc.h index 86d894b3de..3d440ab2e2 100644 --- a/usr/src/lib/libc/inc/libc.h +++ b/usr/src/lib/libc/inc/libc.h @@ -316,6 +316,16 @@ extern wint_t __ungetwc_xpg5(wint_t, FILE *); */ extern char *current_locale(locale_t, int); +/* + * defined in set_constraint_handler_s.c. + */ +extern void __throw_constraint_handler_s(const char *_RESTRICT_KYWD, int); + +/* + * defined in assfail.c. + */ +extern void common_panic(const char *, const char *); + #ifdef __cplusplus } #endif diff --git a/usr/src/lib/libc/port/gen/memset_s.c b/usr/src/lib/libc/port/gen/memset_s.c new file mode 100644 index 0000000000..9f3fcf8ec0 --- /dev/null +++ b/usr/src/lib/libc/port/gen/memset_s.c @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2017 Juniper Networks. 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 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. + */ + +/* + * Copyright 2018 Nexenta Systems, Inc. + */ + +#include "lint.h" + +#include <errno.h> +#include <stddef.h> +#include <stdint.h> +#include <string.h> + +#include "libc.h" + +/* __memset_vp is a volatile pointer to memset() function */ +static void *(*const volatile __memset_vp)(void *, int, size_t) = (memset); + +/* ISO/IEC 9899:2011 K.3.7.4.1 */ +errno_t +memset_s(void *s, rsize_t smax, int c, rsize_t n) +{ + errno_t ret; + rsize_t lim; + unsigned char v; + + ret = EINVAL; + lim = n < smax ? n : smax; + v = (unsigned char)c; + if (s == NULL) { + __throw_constraint_handler_s("memset_s: s is NULL", ret); + } else if (smax > RSIZE_MAX) { + __throw_constraint_handler_s("memset_s: smax > RSIZE_MAX", + ret); + } else { + /* + * Both s and smax are valid, fill the memory buffer using + * memset() called through a volatile pointer to guarantee + * it will not be optimized away. + */ + (*__memset_vp)(s, v, lim); + + if (n > RSIZE_MAX) { + __throw_constraint_handler_s("memset_s: n > RSIZE_MAX", + ret); + } else if (n > smax) { + __throw_constraint_handler_s("memset_s: n > smax", ret); + } else { + ret = 0; + } + } + return (ret); +} diff --git a/usr/src/lib/libc/port/gen/set_constraint_handler_s.c b/usr/src/lib/libc/port/gen/set_constraint_handler_s.c new file mode 100644 index 0000000000..3466b8a1d0 --- /dev/null +++ b/usr/src/lib/libc/port/gen/set_constraint_handler_s.c @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2017 Juniper Networks. 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 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. + */ + +/* + * Copyright 2018 Nexenta Systems, Inc. + */ + +#include "lint.h" + +#include <sys/types.h> +#include <errno.h> +#include <stddef.h> +#include <stdlib.h> +#include <string.h> +#include <synch.h> +#include <thread.h> +#include <unistd.h> + +#include "libc.h" + +/* + * Rationale recommends allocating new memory each time. + */ +static constraint_handler_t *_ch = NULL; +static mutex_t ch_lock = ERRORCHECKMUTEX; + +constraint_handler_t +set_constraint_handler_s(constraint_handler_t handler) +{ + constraint_handler_t *new, *old, ret; + + new = malloc(sizeof (constraint_handler_t)); + if (new == NULL) + return (NULL); + *new = handler; + mutex_enter(&ch_lock); + old = _ch; + _ch = new; + mutex_exit(&ch_lock); + if (old == NULL) { + ret = NULL; + } else { + ret = *old; + free(old); + } + return (ret); +} + +/*ARGSUSED*/ +void +abort_handler_s(const char *_RESTRICT_KYWD msg, + void *_RESTRICT_KYWD ptr, errno_t error) +{ + common_panic("abort_handler_s: ", msg); +} + +/*ARGSUSED*/ +void +ignore_handler_s(const char *_RESTRICT_KYWD msg, + void *_RESTRICT_KYWD ptr, errno_t error) +{ +} + +void +__throw_constraint_handler_s(const char *_RESTRICT_KYWD msg, errno_t error) +{ + constraint_handler_t ch; + + mutex_enter(&ch_lock); + ch = (_ch != NULL) ? *_ch : NULL; + mutex_exit(&ch_lock); + if (ch != NULL) { + ch(msg, NULL, error); + } else { + /* + * If current handler is NULL (there were no calls to + * set_constraint_handler_s(), or it was called with NULL + * pointer handler argument), call default constraint handler + * per K.3.6.1.1 points 4 and 5. + * + * This implementation defines abort_handler_s() as default. + */ + abort_handler_s(msg, NULL, error); + } +} diff --git a/usr/src/lib/libc/port/mapfile-vers b/usr/src/lib/libc/port/mapfile-vers index d184c2e68c..812c0c94d5 100644 --- a/usr/src/lib/libc/port/mapfile-vers +++ b/usr/src/lib/libc/port/mapfile-vers @@ -77,6 +77,14 @@ $if _x86 && _ELF64 $add amd64 $endif +SYMBOL_VERSION ILLUMOS_0.27 { # memset_s(3C) and set_constraint_handler_s(3C) + protected: + abort_handler_s; + ignore_handler_s; + memset_s; + set_constraint_handler_s; +} ILLUMOS_0.26; + SYMBOL_VERSION ILLUMOS_0.26 { # fts(3) LFS $if lf64 protected: diff --git a/usr/src/lib/libc/port/threads/assfail.c b/usr/src/lib/libc/port/threads/assfail.c index b40e6dc029..1c032d8ea7 100644 --- a/usr/src/lib/libc/port/threads/assfail.c +++ b/usr/src/lib/libc/port/threads/assfail.c @@ -95,7 +95,7 @@ Abort(const char *msg) * Write a panic message w/o grabbing any locks other than assert_lock. * We have no idea what locks are held at this point. */ -static void +void common_panic(const char *head, const char *why) { char msg[400]; /* no panic() message in the library is this long */ diff --git a/usr/src/lib/libc/sparc/Makefile.com b/usr/src/lib/libc/sparc/Makefile.com index cf62c4d6d4..20a4e0fd4e 100644 --- a/usr/src/lib/libc/sparc/Makefile.com +++ b/usr/src/lib/libc/sparc/Makefile.com @@ -530,6 +530,7 @@ PORTGEN= \ malloc.o \ memalign.o \ memmem.o \ + memset_s.o \ mkdev.o \ mkdtemp.o \ mkfifo.o \ @@ -587,6 +588,7 @@ PORTGEN= \ scandir.o \ seekdir.o \ select.o \ + set_constraint_handler_s.o \ setlabel.o \ setpriority.o \ settimeofday.o \ diff --git a/usr/src/lib/libc/sparcv9/Makefile.com b/usr/src/lib/libc/sparcv9/Makefile.com index 14b5711beb..8e8fc96f16 100644 --- a/usr/src/lib/libc/sparcv9/Makefile.com +++ b/usr/src/lib/libc/sparcv9/Makefile.com @@ -487,6 +487,7 @@ PORTGEN= \ malloc.o \ memalign.o \ memmem.o \ + memset_s.o \ mkdev.o \ mkdtemp.o \ mkfifo.o \ @@ -544,6 +545,7 @@ PORTGEN= \ scandir.o \ seekdir.o \ select.o \ + set_constraint_handler_s.o \ setlabel.o \ setpriority.o \ settimeofday.o \ |