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
This commit is contained in:
parent
9a7c084993
commit
6562843997
@ -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. */
|
||||
|
@ -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, unsigned nblk)
|
||||
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, unsigned nblk)
|
||||
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);
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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__)
|
||||
|
@ -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);
|
||||
}
|
@ -1,53 +0,0 @@
|
||||
/*-
|
||||
* Copyright (c) 2010 Pawel Jakub Dawidek <pjd@FreeBSD.org>
|
||||
* 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 AUTHORS 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
|
||||
* 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef _UTIL_H_
|
||||
#define _UTIL_H_
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#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_ */
|
@ -30,7 +30,7 @@
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#include "util.h"
|
||||
#include "stand.h"
|
||||
#include "mips.h"
|
||||
|
||||
/*-
|
||||
|
@ -30,7 +30,7 @@
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#include "util.h"
|
||||
#include "stand.h"
|
||||
#include "mips.h"
|
||||
#include "cfi.h"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user