summaryrefslogtreecommitdiff
path: root/usr/src/lib/libc
diff options
context:
space:
mode:
authorYuri Pankov <yuri.pankov@nexenta.com>2017-07-28 14:44:18 +0300
committerRobert Mustacchi <rm@joyent.com>2017-07-29 22:55:08 +0000
commitf1cdbd3731f01314c1d46f05280ad63f1770fdc6 (patch)
treec5a25b595ef96005afa9734a6347a7e910c5b9b2 /usr/src/lib/libc
parent0b905b49d460a57773d88d714cd880ffe0182b7c (diff)
downloadillumos-gate-f1cdbd3731f01314c1d46f05280ad63f1770fdc6.tar.gz
8546 want recallocarray(3C) and freezero(3C)
Reviewed by: Toomas Soome <tsoome@me.com> Reviewed by: Igor Kozhukhov <igor@dilos.org> Reviewed by: Andy Stormont <astormont@racktopsystems.com> Approved by: Robert Mustacchi <rm@joyent.com>
Diffstat (limited to 'usr/src/lib/libc')
-rw-r--r--usr/src/lib/libc/amd64/Makefile2
-rw-r--r--usr/src/lib/libc/i386/Makefile.com2
-rw-r--r--usr/src/lib/libc/port/gen/freezero.c27
-rw-r--r--usr/src/lib/libc/port/gen/reallocarray.c8
-rw-r--r--usr/src/lib/libc/port/gen/recallocarray.c80
-rw-r--r--usr/src/lib/libc/port/llib-lc6
-rw-r--r--usr/src/lib/libc/port/mapfile-vers13
-rw-r--r--usr/src/lib/libc/sparc/Makefile.com2
-rw-r--r--usr/src/lib/libc/sparcv9/Makefile.com2
9 files changed, 134 insertions, 8 deletions
diff --git a/usr/src/lib/libc/amd64/Makefile b/usr/src/lib/libc/amd64/Makefile
index 8cee9dee02..2fe0b7bafe 100644
--- a/usr/src/lib/libc/amd64/Makefile
+++ b/usr/src/lib/libc/amd64/Makefile
@@ -395,6 +395,7 @@ PORTGEN= \
flock.o \
fls.o \
fmtmsg.o \
+ freezero.o \
ftime.o \
ftok.o \
fts.o \
@@ -513,6 +514,7 @@ PORTGEN= \
readdir.o \
readdir_r.o \
reallocarray.o \
+ recallocarray.o \
realpath.o \
reboot.o \
regexpr.o \
diff --git a/usr/src/lib/libc/i386/Makefile.com b/usr/src/lib/libc/i386/Makefile.com
index 0a879e1508..3edbed15e0 100644
--- a/usr/src/lib/libc/i386/Makefile.com
+++ b/usr/src/lib/libc/i386/Makefile.com
@@ -431,6 +431,7 @@ PORTGEN= \
flock.o \
fls.o \
fmtmsg.o \
+ freezero.o \
ftime.o \
ftok.o \
fts.o \
@@ -549,6 +550,7 @@ PORTGEN= \
readdir.o \
readdir_r.o \
reallocarray.o \
+ recallocarray.o \
realpath.o \
reboot.o \
regexpr.o \
diff --git a/usr/src/lib/libc/port/gen/freezero.c b/usr/src/lib/libc/port/gen/freezero.c
new file mode 100644
index 0000000000..9280590aa6
--- /dev/null
+++ b/usr/src/lib/libc/port/gen/freezero.c
@@ -0,0 +1,27 @@
+/*
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source. A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ */
+
+/*
+ * Copyright 2017 Nexenta Systems, Inc.
+ */
+
+#include <stdlib.h>
+#include <strings.h>
+
+void
+freezero(void *ptr, size_t size)
+{
+ if (ptr == NULL)
+ return;
+
+ explicit_bzero(ptr, size);
+ free(ptr);
+}
diff --git a/usr/src/lib/libc/port/gen/reallocarray.c b/usr/src/lib/libc/port/gen/reallocarray.c
index ecc4d25fa9..ba1f028c42 100644
--- a/usr/src/lib/libc/port/gen/reallocarray.c
+++ b/usr/src/lib/libc/port/gen/reallocarray.c
@@ -26,12 +26,12 @@
#define MUL_NO_OVERFLOW ((size_t)1 << (sizeof (size_t) * 4))
void *
-reallocarray(void *optr, size_t nmemb, size_t size)
+reallocarray(void *ptr, size_t nelem, size_t elsize)
{
- if ((nmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) &&
- nmemb > 0 && SIZE_MAX / nmemb < size) {
+ if ((nelem >= MUL_NO_OVERFLOW || elsize >= MUL_NO_OVERFLOW) &&
+ nelem > 0 && SIZE_MAX / nelem < elsize) {
errno = ENOMEM;
return (NULL);
}
- return (realloc(optr, size * nmemb));
+ return (realloc(ptr, elsize * nelem));
}
diff --git a/usr/src/lib/libc/port/gen/recallocarray.c b/usr/src/lib/libc/port/gen/recallocarray.c
new file mode 100644
index 0000000000..1edcbef960
--- /dev/null
+++ b/usr/src/lib/libc/port/gen/recallocarray.c
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 2008, 2017 Otto Moerbeek <otto@drijf.net>
+ *
+ * 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.
+ *
+ * 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 <errno.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <string.h>
+#include <unistd.h>
+
+/*
+ * This is sqrt(SIZE_MAX+1), as s1*s2 <= SIZE_MAX
+ * if both s1 < MUL_NO_OVERFLOW and s2 < MUL_NO_OVERFLOW
+ */
+#define MUL_NO_OVERFLOW ((size_t)1 << (sizeof (size_t) * 4))
+
+void *
+recallocarray(void *ptr, size_t oldnelem, size_t newnelem, size_t elsize)
+{
+ size_t oldsize, newsize;
+ void *newptr;
+
+ if (ptr == NULL)
+ return (calloc(newnelem, elsize));
+
+ if ((newnelem >= MUL_NO_OVERFLOW || elsize >= MUL_NO_OVERFLOW) &&
+ newnelem > 0 && SIZE_MAX / newnelem < elsize) {
+ errno = ENOMEM;
+ return (NULL);
+ }
+ newsize = newnelem * elsize;
+
+ if ((oldnelem >= MUL_NO_OVERFLOW || elsize >= MUL_NO_OVERFLOW) &&
+ oldnelem > 0 && SIZE_MAX / oldnelem < elsize) {
+ errno = EINVAL;
+ return (NULL);
+ }
+ oldsize = oldnelem * elsize;
+
+ /*
+ * Don't bother too much if we're shrinking just a bit,
+ * we do not shrink for series of small steps, oh well.
+ */
+ if (newsize <= oldsize) {
+ size_t d = oldsize - newsize;
+
+ if (d < oldsize / 2 && d < getpagesize()) {
+ (void) memset((char *)ptr + newsize, 0, d);
+ return (ptr);
+ }
+ }
+
+ newptr = malloc(newsize);
+ if (newptr == NULL)
+ return (NULL);
+
+ if (newsize > oldsize) {
+ (void) memcpy(newptr, ptr, oldsize);
+ (void) memset((char *)newptr + oldsize, 0, newsize - oldsize);
+ } else {
+ (void) memcpy(newptr, ptr, newsize);
+ }
+
+ explicit_bzero(ptr, oldsize);
+ free(ptr);
+
+ return (newptr);
+}
diff --git a/usr/src/lib/libc/port/llib-lc b/usr/src/lib/libc/port/llib-lc
index db73a140f9..f547dd44da 100644
--- a/usr/src/lib/libc/port/llib-lc
+++ b/usr/src/lib/libc/port/llib-lc
@@ -438,6 +438,9 @@ int addseverity(int value, const char *string);
int fmtmsg(long class, const char *label, int severity, const char *text,
const char *action, const char *tag);
+/* freezero.c */
+void freezero(void *, size_t);
+
/* ftime.c */
int ftime(struct timeb *tp);
@@ -831,6 +834,9 @@ struct dirent *readdir(DIR *dirp);
/* reallocarray.c */
void *reallocarray(void *, size_t, size_t);
+/* recallocarray.c */
+void *recallocarray(void *, size_t, size_t, size_t);
+
/* realpath.c */
char *realpath(const char *_RESTRICT_KYWD raw, char *_RESTRICT_KYWD canon);
diff --git a/usr/src/lib/libc/port/mapfile-vers b/usr/src/lib/libc/port/mapfile-vers
index c9e03580e2..905de27667 100644
--- a/usr/src/lib/libc/port/mapfile-vers
+++ b/usr/src/lib/libc/port/mapfile-vers
@@ -18,17 +18,16 @@
#
# CDDL HEADER END
#
+
#
# Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
-#
-# Copyright 2010 Nexenta Systems, Inc. All rights reserved.
-# Use is subject to license terms.
-#
+# Copyright 2017 Nexenta Systems, Inc.
# Copyright (c) 2012 by Delphix. All rights reserved.
# Copyright 2016 Joyent, Inc.
# Copyright (c) 2013, OmniTI Computer Consulting, Inc. All rights reserved.
# Copyright (c) 2013 Gary Mills
# Copyright 2014 Garrett D'Amore <garrett@damore.org>
+#
#
# MAPFILE HEADER START
@@ -93,6 +92,12 @@ $if _x86 && _ELF64
$add amd64
$endif
+SYMBOL_VERSION ILLUMOS_0.24 { # openbsd compat
+ protected:
+ freezero;
+ recallocarray;
+} ILLUMOS_0.23;
+
SYMBOL_VERSION ILLUMOS_0.23 { # openbsd compat
protected:
fts_children;
diff --git a/usr/src/lib/libc/sparc/Makefile.com b/usr/src/lib/libc/sparc/Makefile.com
index b478c61a74..8ad448f56a 100644
--- a/usr/src/lib/libc/sparc/Makefile.com
+++ b/usr/src/lib/libc/sparc/Makefile.com
@@ -456,6 +456,7 @@ PORTGEN= \
flock.o \
fls.o \
fmtmsg.o \
+ freezero.o \
ftime.o \
ftok.o \
fts.o \
@@ -575,6 +576,7 @@ PORTGEN= \
readdir.o \
readdir_r.o \
reallocarray.o \
+ recallocarray.o \
realpath.o \
reboot.o \
regexpr.o \
diff --git a/usr/src/lib/libc/sparcv9/Makefile.com b/usr/src/lib/libc/sparcv9/Makefile.com
index 70d1fdea43..5c131719c9 100644
--- a/usr/src/lib/libc/sparcv9/Makefile.com
+++ b/usr/src/lib/libc/sparcv9/Makefile.com
@@ -414,6 +414,7 @@ PORTGEN= \
flock.o \
fls.o \
fmtmsg.o \
+ freezero.o \
ftime.o \
ftok.o \
fts.o \
@@ -533,6 +534,7 @@ PORTGEN= \
readdir.o \
readdir_r.o \
reallocarray.o \
+ recallocarray.o \
realpath.o \
reboot.o \
regexpr.o \