Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 15 Dec 2017 23:16:53 +0000 (UTC)
From:      Warner Losh <imp@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r326887 - in head/stand: i386/common i386/gptboot i386/zfsboot libsa mips/beri/common
Message-ID:  <201712152316.vBFNGr9P041314@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: imp
Date: Fri Dec 15 23:16:53 2017
New Revision: 326887
URL: https://svnweb.freebsd.org/changeset/base/326887

Log:
  Remove the 'mini libstand in libstand' that util.[ch] provided. These
  weren't needed, and their existance interfered with things in subtle
  ways. One of these subtle ways was that malloc could be different
  based on what files were included when (even within the same .c file,
  it turns out). Move to a single malloc implementation as well by
  adding the calls to setheap() to gptboot.c and zfsboot.c. Once upon a
  time, these boot loaders strove to not use libstand. However, with the
  proliferation of features, that striving is too hard for too little
  gain and lead to stupid mistakes.
  
  This fixes the GELI-enabled (but not even using) boot environment. The
  geli routines were calling libstand malloc but zfsboot.c and gptboot.c
  were using the mini libstand malloc, so this failed when we tried to
  probe for GELI partitions. Subtle changes in build order when moving
  to self-contained stand build in r326593 toggled what it used from one
  type to another due to odd nesting of the zfs implementation code that
  differed subtly between zfsloader and zfsboot.
  
  Sponsored by: Netflix

Deleted:
  head/stand/libsa/util.c
  head/stand/libsa/util.h
Modified:
  head/stand/i386/common/cons.c
  head/stand/i386/common/drv.c
  head/stand/i386/gptboot/gptboot.c
  head/stand/i386/zfsboot/zfsboot.c
  head/stand/libsa/gpt.c
  head/stand/libsa/stand.h
  head/stand/mips/beri/common/altera_jtag_uart.c
  head/stand/mips/beri/common/cfi.c

Modified: head/stand/i386/common/cons.c
==============================================================================
--- head/stand/i386/common/cons.c	Fri Dec 15 23:16:47 2017	(r326886)
+++ head/stand/i386/common/cons.c	Fri Dec 15 23:16:53 2017	(r326887)
@@ -22,9 +22,10 @@ __FBSDID("$FreeBSD$");
 
 #include <btxv86.h>
 
+#include "stand.h"
+
 #include "lib.h"
 #include "rbx.h"
-#include "util.h"
 #include "cons.h"
 
 #define SECOND		18	/* Circa that many ticks in a second. */

Modified: head/stand/i386/common/drv.c
==============================================================================
--- head/stand/i386/common/drv.c	Fri Dec 15 23:16:47 2017	(r326886)
+++ head/stand/i386/common/drv.c	Fri Dec 15 23:16:53 2017	(r326887)
@@ -21,8 +21,8 @@ __FBSDID("$FreeBSD$");
 
 #include <btxv86.h>
 
+#include "stand.h"
 #include "rbx.h"
-#include "util.h"
 #include "drv.h"
 #include "edd.h"
 
@@ -69,7 +69,7 @@ drvread(struct dsk *dskp, void *buf, daddr_t lba, unsi
 	v86.esi = VTOPOFF(&packet);
 	v86int();
 	if (V86_CY(v86.efl)) {
-		printf("%s: error %u lba %u\n",
+		printf("%s: error %u lba %llu\n",
 		    BOOTPROG, v86.eax >> 8 & 0xff, lba);
 		return (-1);
 	}
@@ -94,7 +94,7 @@ drvwrite(struct dsk *dskp, void *buf, daddr_t lba, uns
 	v86.esi = VTOPOFF(&packet);
 	v86int();
 	if (V86_CY(v86.efl)) {
-		printf("error %u lba %u\n", v86.eax >> 8 & 0xff, lba);
+		printf("error %u lba %llu\n", v86.eax >> 8 & 0xff, lba);
 		return (-1);
 	}
 	return (0);

Modified: head/stand/i386/gptboot/gptboot.c
==============================================================================
--- head/stand/i386/gptboot/gptboot.c	Fri Dec 15 23:16:47 2017	(r326886)
+++ head/stand/i386/gptboot/gptboot.c	Fri Dec 15 23:16:53 2017	(r326887)
@@ -32,15 +32,12 @@ __FBSDID("$FreeBSD$");
 
 #include <btxv86.h>
 
-/* Forward declared to avoid warnings -- these shouldn't be needed */
-int strcasecmp(const char *s1, const char *s2);
-void explicit_bzero(void *b, size_t len);
+#include "stand.h"
 
 #include "bootargs.h"
 #include "lib.h"
 #include "rbx.h"
 #include "drv.h"
-#include "util.h"
 #include "cons.h"
 #include "gpt.h"
 #include "paths.h"
@@ -109,35 +106,11 @@ void exit(int);
 static void load(void);
 static int parse_cmds(char *, int *);
 static int dskread(void *, daddr_t, unsigned);
-void *malloc(size_t n);
-void free(void *ptr);
 #ifdef LOADER_GELI_SUPPORT
 static int vdev_read(void *vdev __unused, void *priv, off_t off, void *buf,
 	size_t bytes);
 #endif
 
-void *
-malloc(size_t n)
-{
-	char *p = heap_next;
-	if (p + n > heap_end) {
-		printf("malloc failure\n");
-		for (;;)
-		    ;
-		/* NOTREACHED */
-		return (0);
-	}
-	heap_next += n;
-	return (p);
-}
-
-void
-free(void *ptr)
-{
-
-	return;
-}
-
 #include "ufsread.c"
 #include "gpt.c"
 #ifdef LOADER_GELI_SUPPORT
@@ -291,6 +264,7 @@ main(void)
 		heap_next = (char *)dmadat + sizeof(*dmadat);
 		heap_end = (char *)PTOV(bios_basemem);
 	}
+	setheap(heap_next, heap_end);
 
 	v86.ctl = V86_FLAGS;
 	v86.efl = PSL_RESERVED_DEFAULT | PSL_I;

Modified: head/stand/i386/zfsboot/zfsboot.c
==============================================================================
--- head/stand/i386/zfsboot/zfsboot.c	Fri Dec 15 23:16:47 2017	(r326886)
+++ head/stand/i386/zfsboot/zfsboot.c	Fri Dec 15 23:16:53 2017	(r326887)
@@ -16,6 +16,8 @@
 #include <sys/cdefs.h>
 __FBSDID("$FreeBSD$");
 
+#include "stand.h"
+
 #include <sys/param.h>
 #include <sys/errno.h>
 #include <sys/diskmbr.h>
@@ -36,15 +38,10 @@ __FBSDID("$FreeBSD$");
 
 #include <btxv86.h>
 
-/* Forward declared to avoid warnings -- these shouldn't be needed */
-int strcasecmp(const char *s1, const char *s2);
-void explicit_bzero(void *b, size_t len);
-
 #include "lib.h"
 #include "rbx.h"
 #include "drv.h"
 #include "edd.h"
-#include "util.h"
 #include "cons.h"
 #include "bootargs.h"
 #include "paths.h"
@@ -127,40 +124,8 @@ void reboot(void);
 static void load(void);
 static int parse_cmd(void);
 static void bios_getmem(void);
-void *malloc(size_t n);
-void free(void *ptr);
 int main(void);
 
-void *
-malloc(size_t n)
-{
-	char *p = heap_next;
-	if (p + n > heap_end) {
-		printf("malloc failure\n");
-		for (;;)
-		    ;
-		/* NOTREACHED */
-		return (0);
-	}
-	heap_next += n;
-	return (p);
-}
-
-void
-free(void *ptr)
-{
-
-	return;
-}
-
-static char *
-strdup(const char *s)
-{
-	char *p = malloc(strlen(s) + 1);
-	strcpy(p, s);
-	return (p);
-}
-
 #ifdef LOADER_GELI_SUPPORT
 #include "geliboot.c"
 static char gelipw[GELI_PW_MAXLEN];
@@ -503,7 +468,6 @@ drvsize_ext(struct dsk *dskp)
 	if (V86_CY(v86.efl) ||	/* carry set */
 	    (v86.edx & 0xff) <= (unsigned)(dskp->drive & 0x7f)) /* unit # bad */
 		return (0);
-
 	cyl = ((v86.ecx & 0xc0) << 2) + ((v86.ecx & 0xff00) >> 8) + 1;
 	/* Convert max head # -> # of heads */
 	hds = ((v86.edx & 0xff00) >> 8) + 1;
@@ -721,6 +685,7 @@ main(void)
 	heap_next = (char *)dmadat + sizeof(*dmadat);
 	heap_end = (char *)PTOV(bios_basemem);
     }
+    setheap(heap_next, heap_end);
 
     dsk = malloc(sizeof(struct dsk));
     dsk->drive = *(uint8_t *)PTOV(ARGS);

Modified: head/stand/libsa/gpt.c
==============================================================================
--- head/stand/libsa/gpt.c	Fri Dec 15 23:16:47 2017	(r326886)
+++ head/stand/libsa/gpt.c	Fri Dec 15 23:16:53 2017	(r326887)
@@ -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;

Modified: head/stand/libsa/stand.h
==============================================================================
--- head/stand/libsa/stand.h	Fri Dec 15 23:16:47 2017	(r326886)
+++ head/stand/libsa/stand.h	Fri Dec 15 23:16:53 2017	(r326887)
@@ -265,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);
 
@@ -427,7 +421,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__)

Modified: head/stand/mips/beri/common/altera_jtag_uart.c
==============================================================================
--- head/stand/mips/beri/common/altera_jtag_uart.c	Fri Dec 15 23:16:47 2017	(r326886)
+++ head/stand/mips/beri/common/altera_jtag_uart.c	Fri Dec 15 23:16:53 2017	(r326887)
@@ -30,7 +30,7 @@
  * $FreeBSD$
  */
 
-#include "util.h"
+#include "stand.h"
 #include "mips.h"
 
 /*-

Modified: head/stand/mips/beri/common/cfi.c
==============================================================================
--- head/stand/mips/beri/common/cfi.c	Fri Dec 15 23:16:47 2017	(r326886)
+++ head/stand/mips/beri/common/cfi.c	Fri Dec 15 23:16:53 2017	(r326887)
@@ -30,7 +30,7 @@
  * $FreeBSD$
  */
 
-#include "util.h"
+#include "stand.h"
 #include "mips.h"
 #include "cfi.h"
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201712152316.vBFNGr9P041314>