From owner-svn-src-all@FreeBSD.ORG Thu Nov 20 14:57:10 2008 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 4DB141065675; Thu, 20 Nov 2008 14:57:10 +0000 (UTC) (envelope-from luigi@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 38CA98FC12; Thu, 20 Nov 2008 14:57:10 +0000 (UTC) (envelope-from luigi@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id mAKEv9QD054682; Thu, 20 Nov 2008 14:57:09 GMT (envelope-from luigi@svn.freebsd.org) Received: (from luigi@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id mAKEv9re054681; Thu, 20 Nov 2008 14:57:09 GMT (envelope-from luigi@svn.freebsd.org) Message-Id: <200811201457.mAKEv9re054681@svn.freebsd.org> From: Luigi Rizzo Date: Thu, 20 Nov 2008 14:57:09 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r185132 - head/sys/boot/common X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 20 Nov 2008 14:57:10 -0000 Author: luigi Date: Thu Nov 20 14:57:09 2008 New Revision: 185132 URL: http://svn.freebsd.org/changeset/base/185132 Log: As reported in kern/118222, pxeboot in RELENG7 (and presumably above) exhibits some misbehaviours on machines with AMD64 CPUs, which at least in some cases I have tracked down to a heap overflow. It is unclear whether it depends on the CPU or on the pxe bios itself which may use more memory on AMD machines. Noticeably a pxeboot compiled from 6.x sources works fine on all machines I have tried so far, while a pxeboot compiled from 7.x sources does not. This patch is a first step in reducing the amount of memory used while processing the configuration files read by the loader at boot (some of them are quite large, 1700+ lines), and it does so by: + moving a buffer to static memory instead of allocating in the heap; + skipping empty lines; + reducing the amount of memory used for line descriptors; Unfortunately there are several changes between 6.x and above, affecting the compiler, the loader code itself, and libstand, and it is not so straightforward to These changes fix the behaviour on one motherboard with a single-core AMD cpu, but are still not enough e.g on an Asus M2N-VM (with a dual-core CPU). I need to investigate the problem a bit more before figuring out what should be committed to RELENG_7 PR: kern/118222 Modified: head/sys/boot/common/interp.c Modified: head/sys/boot/common/interp.c ============================================================================== --- head/sys/boot/common/interp.c Thu Nov 20 13:39:14 2008 (r185131) +++ head/sys/boot/common/interp.c Thu Nov 20 14:57:09 2008 (r185132) @@ -92,7 +92,7 @@ perform(int argc, char *argv[]) void interact(void) { - char input[256]; /* big enough? */ + static char input[256]; /* big enough? */ #ifndef BOOT_FORTH int argc; char **argv; @@ -178,14 +178,21 @@ command_include(int argc, char *argv[]) return(res); } +/* + * Header prepended to each line. The text immediately follows the header. + * We try to make this short in order to save memory -- the loader has + * limited memory available, and some of the forth files are very long. + */ struct includeline { - char *text; + struct includeline *next; +#ifndef BOOT_FORTH int flags; int line; #define SL_QUIET (1<<0) #define SL_IGNOREERR (1<<1) - struct includeline *next; +#endif + char text[0]; }; int @@ -236,13 +243,14 @@ include(const char *filename) } #endif /* Allocate script line structure and copy line, flags */ + if (*cp == '\0') + continue; /* ignore empty line, save memory */ sp = malloc(sizeof(struct includeline) + strlen(cp) + 1); - sp->text = (char *)sp + sizeof(struct includeline); strcpy(sp->text, cp); #ifndef BOOT_FORTH sp->flags = flags; -#endif sp->line = line; +#endif sp->next = NULL; if (script == NULL) {