summaryrefslogtreecommitdiffstats
path: root/stand/libsa
diff options
context:
space:
mode:
authorkevans <kevans@FreeBSD.org>2018-02-12 17:44:35 +0000
committerkevans <kevans@FreeBSD.org>2018-02-12 17:44:35 +0000
commit03afb65f3947c5fb7be12e5a7ab31bd61a10baf1 (patch)
treedb7e0d0392bd3b86fbdf18ba7bff2a71c4429ce0 /stand/libsa
parent0bf44ac33507723b11556d27f10c9c1d165c4e2a (diff)
downloadFreeBSD-src-03afb65f3947c5fb7be12e5a7ab31bd61a10baf1.zip
FreeBSD-src-03afb65f3947c5fb7be12e5a7ab31bd61a10baf1.tar.gz
MFC Loader Fixes 2017q4p7: r324844,r326089,r326926,r326440,r326484,r326494,
r326588,r326708,r326784,r326914,r327390,r328446,r326090,r326143,r326144, r326182,r326384,r326421,r326440,r326441,r326442,r326443,r326444,r326445, r326446,r326447,r326448,r326484,r326485,r326486,r326487,r326488,r326490, r326491,r326492,r326493,r326494,r326495,r326504,r326507,r326509,r326584, r326585,r326586,r326587,r326588,r326589,r326590,r326591,r326592,r326593, r326594,r326600,r326616,r326671,r326707,r326708,r326709,r326710,r326711, r326712,r326714,r326720,r326768,r326772,r326784,r326792,r326812,r326854, r326855,r326856,r326858,r326886,r326887,r326914,r326926,r326927,r326960, r326961,r326962,r326963,r327351,r327453,r327390,r327523,r327524,r326489, r327880,r328437,r328438,r328439,r328441,r328446,r328448,r328449,r328612, r328613,r328615 While here, undo our libfdt hack of not including <stdlib.h> if we're compiling _STANDALONE. r324844: When building standalone, don't define errno. Let the definition from stand.h override. This is similar to what we do in the kernel. r326089: loader.efi: efipart does not recognize partitionless disks r326090: net_parse_rootpath() has no parameters r326143: Fix theoretical integer overflow issues. If the product here is r326144: Mark the func pointer as __dead2. It looks up loader_main, which r326182: Modify all FreeBSD bootloaders on PowerPC AIM (Book-S) systems r326384: Use const pointers to avoid casting away constness. r326421: loader.efi: efipart should exclude iPXE stub block protocol r326440: Remove stale dependency on ufsread.c r326441: Minor flags cleanup r326442: Cleanup CFALGS usage here r326443: We don't need both _STAND and _STANDALONE, use the latter. r326444: Move geli to common DO32 stuff r326445: Fix random() and srandom() prototypes to match the standard. r326446: Undefine _STANDALONE since this is test code. r326447: Tweaks to the beri boot loader so that it builds w/o warnings. r326448: Fix all warnings related to geli and ZFS support on x86. r326484: Const poison the propname. r326485: Delcare md_load in libofw.h. Make all prototypes match for ofw r326486: Include machine/md_var to pick up __syncicache prototype. r326487: Cast mdp (a vm_offset_t) to void * to match prototype. r326488: e_entry can be smaller than a pointer. Cast it to an intptr_t r326490: Declare our strange brand of main(). r326491: Disconnet ps3 from the build. There's too many warnings to fix. r326492: Cast void * pointer to char * so the arg matches the %s format. r326493: Provide a md_load64 prototype. r326494: Mark two things as unused (since they are only sometimes used) r326495: Now it's safe to bump WARNS to 1. r326504: Switch to proper MK_LOADER_GELI tests. r326507: increase maximum size of zfsboot r326509: loader.efi: add note about iPXE into the efipart.c r326584: When building standalone, include stand.h rather than the kernel r326585: Include ficl.h before anything else r326586: No need to include the userland md5.h, the kernel one is just fine. r326587: Use the kernel relative paths, rather than the userland relative paths r326588: Need to include skein in the include path r326589: Make sure we include the right path for skein.h r326590: Prefer stdint.h to inttypes.h r326591: This isn't NetBSD specific code. Include these for any kernel / r326592: Don't inherit CFLAGS. This a specialized test program. r326593: Stop building with the standard system headers. r326594: Now that we offer a semi-sane standards-ish set of #include files, stop hacking includes with sed. r326600: Since this is contrib code, create an upstreamable version of my r326616: dhcp_try_rfc1048() is not used any more r326671: Avoid setting -Wno-tentative-definition-incomplete-type with gcc. r326707: Add partial support signal.h functioanlity. Pull in machine/signal.h r326708: Remove _KERNEL hack now that errno.h does the right thing when built standalone. r326709: Provide implementations for iscntrl, ispunct and isgraph. r326710: Put the files we're copying over into a few variables and clean hings up. r326711: Const poison a couple of interfaces. r326712: Create interp class. r326714: boot1.c needs EFI_ZFS_BOOT too, so add it globally. r326720: This path belongs in ficl/Makefile, not the common defines for users r326768: Fix a comment to be more accurate r326772: Fix regression with lua import r326784: Revert part of 362772. It was causing problems for includes r326792: Attempt to unbreak buildworld r326812: Revert r326792, r326784, r326772, r326712 r326854: libefi: make efichar.h more usable in stand code r326855: Cargo cut a fix for the regressions r326585 caused. r326856: Fix comments after bump in size. r326858: Revert r326855: Cargo cut a fix for the regressions r326585 caused. r326886: Panic in sbrk if setheap hasn't been called yet. This is preferable o a mysterious crash r326887: Remove the 'mini libstand in libstand' that util.[ch] provided. r326914: Move loader-only defines to loader.mk from defs.mk r326926: Move loader help file definitions to being 100% inside of loader.mk. r326927: libficl is only ever used in a loader (never a boot) program. Move it. r326960: Simplify things a little. The RETURN macro isn't required. r326961: Interact is always called with NULL. Simplify code a little r326962: Hoist btx include stuff to i386/Makefile.inc r326963: No need to use relative paths like this here. r327351: Fix ubldr. uboot/lib uses defines for the loader. r327453: Add a validbcd() routine that uses the bcd2bin_data[] array r327390: Garbage-collect loader.ps3. It is currently disconnected from the build and kboot replaces. r327523: Don't clobber system LDFLAGS for beri boot loaders. r327524: Use 'extern uint8_t' instead of 'extern void' for external symbols. r326489: Allow this file to be used in libsa without warning... r327880: Move getsecs() prototype to stand.h from net.h so it can be used r328437: Split panic routine r328438: Implement abort() as a call to panic. r328439: Provide abs form stdlib.h. r328441: abort() should be marked __dead2 since it won't return. r328446: Now that exit is __dead2, we need to tag ub_exit() as __dead2. r328448: Make exit() never return until host_exit can be written. r328449: Tag unreachable places as such. I left the while (1); in place r328612: Move strtold wrapper from strtol.c to its own strtold.c. r328613: Kill copies of strtol and strtoul. r328615: Update stand.h for changes for strto*l PR: 223969
Diffstat (limited to 'stand/libsa')
-rw-r--r--stand/libsa/Makefile81
-rw-r--r--stand/libsa/abort.c35
-rw-r--r--stand/libsa/bootp.c11
-rw-r--r--stand/libsa/bootp.h2
-rw-r--r--stand/libsa/cd9660.c4
-rw-r--r--stand/libsa/gpt.c2
-rw-r--r--stand/libsa/net.h2
-rw-r--r--stand/libsa/panic.c19
-rw-r--r--stand/libsa/sbrk.c3
-rw-r--r--stand/libsa/stand.h46
-rw-r--r--stand/libsa/strtol.c132
-rw-r--r--stand/libsa/strtoul.c121
-rw-r--r--stand/libsa/util.c182
-rw-r--r--stand/libsa/xlocale_private.h (renamed from stand/libsa/util.h)37
14 files changed, 135 insertions, 542 deletions
diff --git a/stand/libsa/Makefile b/stand/libsa/Makefile
index ea32f3e..ff50dd6 100644
--- a/stand/libsa/Makefile
+++ b/stand/libsa/Makefile
@@ -18,13 +18,10 @@ LIBC_SRC= ${SRCTOP}/lib/libc
LIB?= sa
NO_PIC=
-WARNS?= 0
-
-CFLAGS+= -I${SASRC}
# standalone components and stuff we have modified locally
-SRCS+= gzguts.h zutil.h __main.c assert.c bcd.c environment.c getopt.c gets.c \
- globals.c pager.c panic.c printf.c strdup.c strerror.c strtol.c strtoul.c \
+SRCS+= gzguts.h zutil.h __main.c abort.c assert.c bcd.c environment.c getopt.c gets.c \
+ globals.c pager.c panic.c printf.c strdup.c strerror.c \
random.c sbrk.c twiddle.c zalloc.c zalloc_malloc.c
# private (pruned) versions of libc string functions
@@ -41,6 +38,11 @@ SRCS+= bcmp.c bcopy.c bzero.c ffs.c fls.c \
qdivrem.c strcat.c strchr.c strcmp.c strcpy.c stpcpy.c stpncpy.c \
strcspn.c strlcat.c strlcpy.c strlen.c strncat.c strncmp.c strncpy.c \
strnlen.c strpbrk.c strrchr.c strsep.c strspn.c strstr.c strtok.c swab.c
+
+# stdlib functions from libc
+.PATH: ${LIBC_SRC}/stdlib
+SRCS+= abs.c strtol.c strtoll.c strtoul.c strtoull.c
+
.if ${MACHINE_CPUARCH} == "arm"
.PATH: ${LIBC_SRC}/arm/gen
@@ -90,48 +92,41 @@ SRCS+= _setjmp.S
# loader(8) with LOADER_BZIP2_SUPPORT defined
.PATH: ${SRCTOP}/contrib/bzip2
CFLAGS+= -DBZ_NO_STDIO -DBZ_NO_COMPRESS
-SRCS+= libsa_bzlib_private.h
-.for file in bzlib.c crctable.c decompress.c huffman.c randtable.c
-SRCS+= _${file}
-CLEANFILES+= _${file}
-
-_${file}: ${file}
- sed "s|bzlib_private\.h|libsa_bzlib_private.h|" \
- ${.ALLSRC} > ${.TARGET}
-.endfor
-
-CLEANFILES+= libsa_bzlib_private.h
-libsa_bzlib_private.h: bzlib_private.h
- sed -e 's|<stdlib.h>|"stand.h"|' \
- ${.ALLSRC} > ${.TARGET}
+SRCS+=bzlib.c crctable.c decompress.c huffman.c randtable.c
# decompression functionality from zlib
.PATH: ${SRCTOP}/contrib/zlib
CFLAGS+=-DHAVE_MEMCPY -I${SRCTOP}/contrib/zlib
-SRCS+= adler32.c crc32.c libsa_zutil.h libsa_gzguts.h
-
-.for file in infback.c inffast.c inflate.c inftrees.c zutil.c
-SRCS+= _${file}
-CLEANFILES+= _${file}
-
-_${file}: ${file}
- sed -e "s|zutil\.h|libsa_zutil.h|" \
- -e "s|gzguts\.h|libsa_gzguts.h|" \
- ${.ALLSRC} > ${.TARGET}
-.endfor
-
-# depend on stand.h being able to be included multiple times
-.for file in zutil.h gzguts.h
-CLEANFILES+= libsa_${file}
-libsa_${file}: ${file}
- sed -e 's|<fcntl.h>|"stand.h"|' \
- -e 's|<stddef.h>|"stand.h"|' \
- -e 's|<string.h>|"stand.h"|' \
- -e 's|<stdio.h>|"stand.h"|' \
- -e 's|<stdlib.h>|"stand.h"|' \
- ${.ALLSRC} > ${.TARGET}
-.endfor
+SRCS+= adler32.c crc32.c
+SRCS+= infback.c inffast.c inflate.c inftrees.c zutil.c
+
+# Create a subset of includes that are safe, as well as adjusting those that aren't
+# The lists may drive people nuts, but they are explicitly opt-in
+FAKE_DIRS=xlocale arpa
+SAFE_INCS=a.out.h assert.h elf.h limits.h nlist.h setjmp.h stddef.h stdbool.h string.h strings.h time.h unistd.h uuid.h
+STAND_H_INC=ctype.h fcntl.h signal.h stdio.h stdlib.h
+OTHER_INC=stdarg.h errno.h stdint.h
+
+beforedepend:
+ echo beforedepend; \
+ mkdir -p ${FAKE_DIRS}; \
+ for i in ${SAFE_INCS}; do \
+ ln -sf ${SRCTOP}/include/$$i $$i; \
+ done; \
+ ln -sf ${SYSDIR}/${MACHINE}/include/stdarg.h stdarg.h; \
+ ln -sf ${SYSDIR}/sys/errno.h errno.h; \
+ ln -sf ${SYSDIR}/sys/stdint.h stdint.h; \
+ ln -sf ${SRCTOP}/include/arpa/inet.h arpa/inet.h; \
+ ln -sf ${SRCTOP}/include/arpa/tftp.h arpa/tftp.h; \
+ for i in _time.h _strings.h _string.h; do \
+ [ -f xlocale/$$i ] || cp /dev/null xlocale/$$i; \
+ done; \
+ for i in ${STAND_H_INC}; do \
+ ln -sf ${SASRC}/stand.h $$i; \
+ done
+CLEANDIRS+=${FAKE_DIRS}
+CLEANFILES+= ${SAFE_INCS} ${STAND_H_INC} ${OTHER_INC}
# io routines
SRCS+= closeall.c dev.c ioctl.c nullfs.c stat.c \
@@ -152,6 +147,8 @@ SRCS+= pkgfs.c
SRCS+= nandfs.c
.endif
+CFLAGS.bzipfs.c+= -I${SRCTOP}/contrib/bzip2
+
# explicit_bzero
.PATH: ${SYSDIR}/libkern
SRCS+= explicit_bzero.c
diff --git a/stand/libsa/abort.c b/stand/libsa/abort.c
new file mode 100644
index 0000000..4b3a2c7
--- /dev/null
+++ b/stand/libsa/abort.c
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2018 Netflix. 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 <stand.h>
+
+void
+abort(void)
+{
+ panic("Bootloader aborted by abort");
+}
diff --git a/stand/libsa/bootp.c b/stand/libsa/bootp.c
index 9f08faf..a6d5052 100644
--- a/stand/libsa/bootp.c
+++ b/stand/libsa/bootp.c
@@ -355,17 +355,6 @@ bad:
return (-1);
}
-int
-dhcp_try_rfc1048(u_char *cp, u_int len)
-{
-
- expected_dhcpmsgtype = DHCPACK;
- if (bcmp(vm_rfc1048, cp, sizeof(vm_rfc1048)) == 0) {
- return (vend_rfc1048(cp, len));
- }
- return (-1);
-}
-
static int
vend_rfc1048(u_char *cp, u_int len)
{
diff --git a/stand/libsa/bootp.h b/stand/libsa/bootp.h
index 2e7049b..fd99b77 100644
--- a/stand/libsa/bootp.h
+++ b/stand/libsa/bootp.h
@@ -146,6 +146,4 @@ struct cmu_vend {
extern struct bootp *bootp_response;
extern size_t bootp_response_size;
-int dhcp_try_rfc1048(u_char *cp, u_int len);
-
#endif /* _BOOTP_H_ */
diff --git a/stand/libsa/cd9660.c b/stand/libsa/cd9660.c
index c561883..a1711fb 100644
--- a/stand/libsa/cd9660.c
+++ b/stand/libsa/cd9660.c
@@ -43,8 +43,8 @@ __FBSDID("$FreeBSD$");
#include <sys/param.h>
#include <string.h>
#include <sys/dirent.h>
-#include <isofs/cd9660/iso.h>
-#include <isofs/cd9660/cd9660_rrip.h>
+#include <fs/cd9660/iso.h>
+#include <fs/cd9660/cd9660_rrip.h>
#include "stand.h"
diff --git a/stand/libsa/gpt.c b/stand/libsa/gpt.c
index 7ab3fc6..900f2d5 100644
--- a/stand/libsa/gpt.c
+++ b/stand/libsa/gpt.c
@@ -34,9 +34,9 @@ __FBSDID("$FreeBSD$");
#error gpt.c works only for little endian architectures
#endif
+#include "stand.h"
#include "crc32.h"
#include "drv.h"
-#include "util.h"
#include "gpt.h"
static struct gpt_hdr hdr_primary, hdr_backup, *gpthdr;
diff --git a/stand/libsa/net.h b/stand/libsa/net.h
index f91435c..ac5414f 100644
--- a/stand/libsa/net.h
+++ b/stand/libsa/net.h
@@ -128,6 +128,4 @@ char *inet_ntoa(struct in_addr);
char *intoa(n_long); /* similar to inet_ntoa */
n_long inet_addr(char *);
-/* Machine-dependent functions: */
-time_t getsecs(void);
#endif /* ! _STAND_NET_H */
diff --git a/stand/libsa/panic.c b/stand/libsa/panic.c
index 6e4c76d..bc6e7e2 100644
--- a/stand/libsa/panic.c
+++ b/stand/libsa/panic.c
@@ -39,7 +39,18 @@ __FBSDID("$FreeBSD$");
#include <stand.h>
#include <machine/stdarg.h>
-extern void exit(int) __dead2;
+/*
+ * Boot loaders and other standalone programs that wish to have a
+ * different panic policy can provide their own panic_action rotuine.
+ */
+__weak_symbol void
+panic_action(void)
+{
+ printf("--> Press a key on the console to reboot <--\n");
+ getchar();
+ printf("Rebooting...\n");
+ exit(1);
+}
void
panic(const char *fmt,...)
@@ -51,9 +62,5 @@ panic(const char *fmt,...)
vprintf(fmt, ap);
va_end(ap);
printf("\n");
-
- printf("--> Press a key on the console to reboot <--\n");
- getchar();
- printf("Rebooting...\n");
- exit(1);
+ panic_action();
}
diff --git a/stand/libsa/sbrk.c b/stand/libsa/sbrk.c
index 471e78e..00787fc 100644
--- a/stand/libsa/sbrk.c
+++ b/stand/libsa/sbrk.c
@@ -52,6 +52,9 @@ sbrk(int incr)
{
char *ret;
+ if (heapbase == 0)
+ panic("No heap setup\n");
+
if ((heapsize + incr) <= maxheap) {
ret = (char *)heapbase + heapsize;
bzero(ret, incr);
diff --git a/stand/libsa/stand.h b/stand/libsa/stand.h
index deb6ad8..dd94b48 100644
--- a/stand/libsa/stand.h
+++ b/stand/libsa/stand.h
@@ -72,10 +72,7 @@
#define CHK(fmt, args...) printf("%s(%d): " fmt "\n", __func__, __LINE__ , ##args)
#define PCHK(fmt, args...) {printf("%s(%d): " fmt "\n", __func__, __LINE__ , ##args); getchar();}
-/* Avoid unwanted userlandish components */
-#define _KERNEL
#include <sys/errno.h>
-#undef _KERNEL
/* special stand error codes */
#define EADAPT (ELAST+1) /* bad adaptor */
@@ -88,6 +85,9 @@
#define EOFFSET (ELAST+8) /* relative seek not supported */
#define ESALAST (ELAST+8) /* */
+/* Partial signal emulation for sig_atomic_t */
+#include <machine/signal.h>
+
struct open_file;
/*
@@ -235,6 +235,22 @@ static __inline int isalnum(int c)
return isalpha(c) || isdigit(c);
}
+static __inline int iscntrl(int c)
+{
+ return (c >= 0 && c < ' ') || c == 127;
+}
+
+static __inline int isgraph(int c)
+{
+ return c >= '!' && c <= '~';
+}
+
+static __inline int ispunct(int c)
+{
+ return (c >= '!' && c <= '/') || (c >= ':' && c <= '@') ||
+ (c >= '[' && c <= '`') || (c >= '{' && c <= '~');
+}
+
static __inline int toupper(int c)
{
return islower(c) ? c - 'a' + 'A' : c;
@@ -249,12 +265,6 @@ static __inline int tolower(int c)
extern void setheap(void *base, void *top);
extern char *sbrk(int incr);
-/* Matt Dillon's zalloc/zmalloc */
-extern void *malloc(size_t bytes);
-extern void free(void *ptr);
-/*#define free(p) {CHK("free %p", p); free(p);} */ /* use for catching guard violations */
-extern void *calloc(size_t n1, size_t n2);
-extern void *realloc(void *ptr, size_t size);
extern void *reallocf(void *ptr, size_t size);
extern void mallocstats(void);
@@ -285,8 +295,6 @@ extern void srandom(u_long seed);
extern long random(void);
/* imports from stdlib, locally modified */
-extern long strtol(const char *, char **, int);
-extern unsigned long strtoul(const char *, char **, int);
extern char *optarg; /* getopt(3) external variables */
extern int optind, opterr, optopt, optreset;
extern int getopt(int, char * const [], const char *);
@@ -336,6 +344,14 @@ extern int unsetenv(const char *name);
extern ev_sethook_t env_noset; /* refuse set operation */
extern ev_unsethook_t env_nounset; /* refuse unset operation */
+/* stdlib.h routines */
+extern int abs(int a);
+extern void abort(void) __dead2;
+extern long strtol(const char * __restrict, char ** __restrict, int);
+extern long long strtoll(const char * __restrict, char ** __restrict, int);
+extern unsigned long strtoul(const char * __restrict, char ** __restrict, int);
+extern unsigned long long strtoull(const char * __restrict, char ** __restrict, int);
+
/* BCD conversions (undocumented) */
extern u_char const bcd2bin_data[];
extern u_char const bin2bcd_data[];
@@ -344,6 +360,7 @@ extern char const hex2ascii_data[];
#define bcd2bin(bcd) (bcd2bin_data[bcd])
#define bin2bcd(bin) (bin2bcd_data[bin])
#define hex2ascii(hex) (hex2ascii_data[hex])
+#define validbcd(bcd) (bcd == 0 || (bcd > 0 && bcd <= 0x99 && bcd2bin_data[bcd] != 0))
/* min/max (undocumented) */
static __inline int imax(int a, int b) { return (a > b ? a : b); }
@@ -357,7 +374,6 @@ static __inline quad_t qmin(quad_t a, quad_t b) { return (a < b ? a : b); }
static __inline u_long ulmax(u_long a, u_long b) { return (a > b ? a : b); }
static __inline u_long ulmin(u_long a, u_long b) { return (a < b ? a : b); }
-
/* null functions for device/filesystem switches (undocumented) */
extern int nodev(void);
extern int noioctl(struct open_file *, u_long, void *);
@@ -376,13 +392,15 @@ extern int null_readdir(struct open_file *f, struct dirent *d);
* Machine dependent functions and data, must be provided or stubbed by
* the consumer
*/
-extern void exit(int);
+extern void exit(int) __dead2;
extern int getchar(void);
extern int ischar(void);
extern void putchar(int);
extern int devopen(struct open_file *, const char *, const char **);
extern int devclose(struct open_file *f);
extern void panic(const char *, ...) __dead2 __printflike(1, 2);
+extern void panic_action(void) __weak_symbol __dead2;
+extern time_t getsecs(void);
extern struct fs_ops *file_system[];
extern struct fs_ops *exclusive_file_system;
extern struct devsw *devsw[];
@@ -411,7 +429,7 @@ void *Calloc(size_t, size_t, const char *, int);
void *Realloc(void *, size_t, const char *, int);
void Free(void *, const char *, int);
-#if 1
+#ifdef DEBUG_MALLOC
#define malloc(x) Malloc(x, __FILE__, __LINE__)
#define calloc(x, y) Calloc(x, y, __FILE__, __LINE__)
#define free(x) Free(x, __FILE__, __LINE__)
diff --git a/stand/libsa/strtol.c b/stand/libsa/strtol.c
deleted file mode 100644
index be82fb1..0000000
--- a/stand/libsa/strtol.c
+++ /dev/null
@@ -1,132 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993
- * The Regents of the University of California. 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.
- * 4. 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.
- *
- * 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.
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)strtol.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-
-#include "stand.h"
-#include <limits.h>
-
-/*
- * Convert a string to a long integer.
- *
- * Ignores `locale' stuff. Assumes that the upper and lower case
- * alphabets and digits are each contiguous.
- */
-long
-strtol(nptr, endptr, base)
- const char *nptr;
- char **endptr;
- int base;
-{
- const char *s;
- unsigned long acc;
- unsigned char c;
- unsigned long cutoff;
- int neg = 0, any, cutlim;
-
- /* Be sensible about NULL strings */
- if (nptr == NULL)
- nptr = "";
- s = nptr;
-
- /*
- * Skip white space and pick up leading +/- sign if any.
- * If base is 0, allow 0x for hex and 0 for octal, else
- * assume decimal; if base is already 16, allow 0x.
- */
- do {
- c = *s++;
- } while (isspace(c));
- if (c == '-') {
- neg = 1;
- c = *s++;
- } else if (c == '+')
- c = *s++;
- if ((base == 0 || base == 16) &&
- c == '0' && (*s == 'x' || *s == 'X')) {
- c = s[1];
- s += 2;
- base = 16;
- }
- if (base == 0)
- base = c == '0' ? 8 : 10;
-
- /*
- * Compute the cutoff value between legal numbers and illegal
- * numbers. That is the largest legal value, divided by the
- * base. An input number that is greater than this value, if
- * followed by a legal input character, is too big. One that
- * is equal to this value may be valid or not; the limit
- * between valid and invalid numbers is then based on the last
- * digit. For instance, if the range for longs is
- * [-2147483648..2147483647] and the input base is 10,
- * cutoff will be set to 214748364 and cutlim to either
- * 7 (neg==0) or 8 (neg==1), meaning that if we have accumulated
- * a value > 214748364, or equal but the next digit is > 7 (or 8),
- * the number is too big, and we will return a range error.
- *
- * Set any if any `digits' consumed; make it negative to indicate
- * overflow.
- */
- cutoff = neg ? -(unsigned long)LONG_MIN : LONG_MAX;
- cutlim = cutoff % (unsigned long)base;
- cutoff /= (unsigned long)base;
- for (acc = 0, any = 0;; c = *s++) {
- if (!isascii(c))
- break;
- if (isdigit(c))
- c -= '0';
- else if (isalpha(c))
- c -= isupper(c) ? 'A' - 10 : 'a' - 10;
- else
- break;
- if (c >= base)
- break;
- if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
- any = -1;
- else {
- any = 1;
- acc *= base;
- acc += c;
- }
- }
- if (any < 0) {
- acc = neg ? LONG_MIN : LONG_MAX;
- errno = ERANGE;
- } else if (neg)
- acc = -acc;
- if (endptr != NULL)
- *endptr = (char *)(any ? s - 1 : nptr);
- return (acc);
-}
diff --git a/stand/libsa/strtoul.c b/stand/libsa/strtoul.c
deleted file mode 100644
index 5735d20..0000000
--- a/stand/libsa/strtoul.c
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- * Copyright (c) 1990, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Copyright (c) 2011 The FreeBSD Foundation
- * All rights reserved.
- * Portions of this software were developed by David Chisnall
- * under sponsorship from the FreeBSD Foundation.
- *
- * 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.
- * 4. 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.
- *
- * 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)strtoul.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include "stand.h"
-#include <limits.h>
-
-/*
- * Convert a string to an unsigned long integer.
- *
- * Assumes that the upper and lower case
- * alphabets and digits are each contiguous.
- */
-unsigned long
-strtoul(const char * __restrict nptr, char ** __restrict endptr, int base)
-{
- const char *s;
- unsigned long acc;
- char c;
- unsigned long cutoff;
- int neg, any, cutlim;
-
- /*
- * See strtol for comments as to the logic used.
- */
- s = nptr;
- do {
- c = *s++;
- } while (isspace((unsigned char)c));
- if (c == '-') {
- neg = 1;
- c = *s++;
- } else {
- neg = 0;
- if (c == '+')
- c = *s++;
- }
- if ((base == 0 || base == 16) &&
- c == '0' && (*s == 'x' || *s == 'X') &&
- ((s[1] >= '0' && s[1] <= '9') ||
- (s[1] >= 'A' && s[1] <= 'F') ||
- (s[1] >= 'a' && s[1] <= 'f'))) {
- c = s[1];
- s += 2;
- base = 16;
- }
- if (base == 0)
- base = c == '0' ? 8 : 10;
- acc = any = 0;
- if (base < 2 || base > 36)
- goto noconv;
-
- cutoff = ULONG_MAX / base;
- cutlim = ULONG_MAX % base;
- for ( ; ; c = *s++) {
- if (c >= '0' && c <= '9')
- c -= '0';
- else if (c >= 'A' && c <= 'Z')
- c -= 'A' - 10;
- else if (c >= 'a' && c <= 'z')
- c -= 'a' - 10;
- else
- break;
- if (c >= base)
- break;
- if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
- any = -1;
- else {
- any = 1;
- acc *= base;
- acc += c;
- }
- }
- if (any < 0) {
- acc = ULONG_MAX;
- errno = ERANGE;
- } else if (!any) {
-noconv:
- errno = EINVAL;
- } else if (neg)
- acc = -acc;
- if (endptr != NULL)
- *endptr = (char *)(any ? s - 1 : nptr);
- return (acc);
-}
diff --git a/stand/libsa/util.c b/stand/libsa/util.c
deleted file mode 100644
index 49f42eb..0000000
--- a/stand/libsa/util.c
+++ /dev/null
@@ -1,182 +0,0 @@
-/*-
- * Copyright (c) 1998 Robert Nordier
- * Copyright (c) 2010 Pawel Jakub Dawidek <pjd@FreeBSD.org>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms are freely
- * permitted provided that the above copyright notice and this
- * paragraph and the following disclaimer are duplicated in all
- * such forms.
- *
- * This software is provided "AS IS" and without any express or
- * implied warranties, including, without limitation, the implied
- * warranties of merchantability and fitness for a particular
- * purpose.
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <sys/param.h>
-
-#include <stdarg.h>
-
-#include "cons.h"
-#include "util.h"
-
-void
-memcpy(void *dst, const void *src, int len)
-{
- const char *s = src;
- char *d = dst;
-
- while (len--)
- *d++ = *s++;
-}
-
-void
-memset(void *b, int c, size_t len)
-{
- char *bp = b;
-
- while (len--)
- *bp++ = (unsigned char)c;
-}
-
-int
-memcmp(const void *b1, const void *b2, size_t len)
-{
- const unsigned char *p1, *p2;
-
- for (p1 = b1, p2 = b2; len > 0; len--, p1++, p2++) {
- if (*p1 != *p2)
- return ((*p1) - (*p2));
- }
- return (0);
-}
-
-int
-strcmp(const char *s1, const char *s2)
-{
-
- for (; *s1 == *s2 && *s1 != '\0'; s1++, s2++)
- ;
- return ((unsigned char)*s1 - (unsigned char)*s2);
-}
-
-int
-strncmp(const char *s1, const char *s2, size_t len)
-{
-
- for (; len > 0 && *s1 == *s2 && *s1 != '\0'; len--, s1++, s2++)
- ;
- return (len == 0 ? 0 : (unsigned char)*s1 - (unsigned char)*s2);
-}
-
-void
-strcpy(char *dst, const char *src)
-{
-
- while (*src != '\0')
- *dst++ = *src++;
- *dst = '\0';
-}
-
-void
-strcat(char *dst, const char *src)
-{
-
- while (*dst != '\0')
- dst++;
- while (*src != '\0')
- *dst++ = *src++;
- *dst = '\0';
-}
-
-char *
-strchr(const char *s, char ch)
-{
-
- for (; *s != '\0'; s++) {
- if (*s == ch)
- return ((char *)(uintptr_t)(const void *)s);
- }
- return (NULL);
-}
-
-size_t
-strlen(const char *s)
-{
- size_t len = 0;
-
- while (*s++ != '\0')
- len++;
- return (len);
-}
-
-int
-printf(const char *fmt, ...)
-{
- va_list ap;
- const char *hex = "0123456789abcdef";
- char buf[32], *s;
- uint16_t *S;
- unsigned long long u;
- int c, l;
-
- va_start(ap, fmt);
- while ((c = *fmt++) != '\0') {
- if (c != '%') {
- putchar(c);
- continue;
- }
- l = 0;
-nextfmt:
- c = *fmt++;
- switch (c) {
- case 'l':
- l++;
- goto nextfmt;
- case 'c':
- putchar(va_arg(ap, int));
- break;
- case 's':
- for (s = va_arg(ap, char *); *s != '\0'; s++)
- putchar(*s);
- break;
- case 'S': /* Assume console can cope with wide chars */
- for (S = va_arg(ap, uint16_t *); *S != 0; S++)
- putchar(*S);
- break;
- case 'd': /* A lie, always prints unsigned */
- case 'u':
- case 'x':
- switch (l) {
- case 2:
- u = va_arg(ap, unsigned long long);
- break;
- case 1:
- u = va_arg(ap, unsigned long);
- break;
- default:
- u = va_arg(ap, unsigned int);
- break;
- }
- s = buf;
- if (c == 'd' || c == 'u') {
- do
- *s++ = '0' + (u % 10U);
- while (u /= 10);
- } else {
- do
- *s++ = hex[u & 0xfu];
- while (u >>= 4);
- }
- while (--s >= buf)
- putchar(*s);
- break;
- }
- }
- va_end(ap);
- return (0);
-}
diff --git a/stand/libsa/util.h b/stand/libsa/xlocale_private.h
index 88a99f1..96eed37 100644
--- a/stand/libsa/util.h
+++ b/stand/libsa/xlocale_private.h
@@ -1,6 +1,5 @@
/*-
- * Copyright (c) 2010 Pawel Jakub Dawidek <pjd@FreeBSD.org>
- * All rights reserved.
+ * Copyright (c) 2018 Netflix
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -11,10 +10,10 @@
* 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 AUTHORS AND CONTRIBUTORS ``AS IS'' AND
+ * 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 AUTHORS OR CONTRIBUTORS BE LIABLE
+ * 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)
@@ -26,28 +25,12 @@
* $FreeBSD$
*/
-#ifndef _UTIL_H_
-#define _UTIL_H_
+#ifndef STAND_XLOCALE_PRIVATE_H
+#define STAND_XLOCALE_PRIVATE_H 1
-#include <sys/types.h>
+typedef int locale_t;
+#define FIX_LOCALE(x)
+#define isspace_l(c, l) isspace(c)
+#define __get_locale() 0
-#include <stdarg.h>
-
-void memcpy(void *dst, const void *src, int len);
-void memset(void *b, int c, size_t len);
-int memcmp(const void *b1, const void *b2, size_t len);
-
-#define bcopy(src, dst, len) memcpy((dst), (src), (len))
-#define bzero(buf, size) memset((buf), 0, (size))
-#define bcmp(b1, b2, len) (memcmp((b1), (b2), (len)) != 0)
-
-int strcmp(const char *s1, const char *s2);
-int strncmp(const char *s1, const char *s2, size_t len);
-void strcpy(char *dst, const char *src);
-void strcat(char *dst, const char *src);
-char *strchr(const char *s, char ch);
-size_t strlen(const char *s);
-
-int printf(const char *fmt, ...);
-
-#endif /* !_UTIL_H_ */
+#endif /* STAND_XLOCALE_PRIVATE_H */
OpenPOWER on IntegriCloud