From owner-svn-src-head@freebsd.org Fri Dec 15 23:16:58 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 8683AE8EFD2; Fri, 15 Dec 2017 23:16:58 +0000 (UTC) (envelope-from imp@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id D5A286916B; Fri, 15 Dec 2017 23:16:55 +0000 (UTC) (envelope-from imp@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id vBFNGsP1041323; Fri, 15 Dec 2017 23:16:54 GMT (envelope-from imp@FreeBSD.org) Received: (from imp@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id vBFNGr9P041314; Fri, 15 Dec 2017 23:16:53 GMT (envelope-from imp@FreeBSD.org) Message-Id: <201712152316.vBFNGr9P041314@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: imp set sender to imp@FreeBSD.org using -f From: Warner Losh Date: Fri, 15 Dec 2017 23:16:53 +0000 (UTC) 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 X-SVN-Group: head X-SVN-Commit-Author: imp X-SVN-Commit-Paths: in head/stand: i386/common i386/gptboot i386/zfsboot libsa mips/beri/common X-SVN-Commit-Revision: 326887 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 15 Dec 2017 23:16:58 -0000 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 +#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 +#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 -/* 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 __FBSDID("$FreeBSD$"); +#include "stand.h" + #include #include #include @@ -36,15 +38,10 @@ __FBSDID("$FreeBSD$"); #include -/* 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"