From owner-freebsd-stable@FreeBSD.ORG Wed Jul 23 20:09:15 2003 Return-Path: Delivered-To: freebsd-stable@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id D0CF937B401 for ; Wed, 23 Jul 2003 20:09:15 -0700 (PDT) Received: from mailgate.sri.com (mailgate.SRI.COM [128.18.243.11]) by mx1.FreeBSD.org (Postfix) with SMTP id 039B643F3F for ; Wed, 23 Jul 2003 20:09:15 -0700 (PDT) (envelope-from gilham@csl.sri.com) Received: (qmail 23760 invoked from network); 24 Jul 2003 02:20:11 -0000 Received: from localhost (HELO mailgate.SRI.COM) (127.0.0.1) by mailgate.sri.com with SMTP; 24 Jul 2003 02:20:11 -0000 Received: from quarter.csl.sri.com ([130.107.1.30]) by mailgate.SRI.COM (SAVSMTP 3.1.0.29) with SMTP id M2003072319201126074 for ; Wed, 23 Jul 2003 19:20:11 -0700 Received: from snapdragon.csl.sri.com (snapdragon.csl.sri.com [130.107.19.20]) by quarter.csl.sri.com (8.12.9/8.12.9) with ESMTP id h6O2K8dW032615; Wed, 23 Jul 2003 19:20:08 -0700 Message-Id: <200307240220.h6O2K8dW032615@quarter.csl.sri.com> To: freebsd-stable@freebsd.org Date: Wed, 23 Jul 2003 19:20:08 -0700 From: Fred Gilham cc: gilham@sdl.sri.com Subject: Question about malloc, mmap etc. X-BeenThere: freebsd-stable@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Production branch of FreeBSD source code List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 24 Jul 2003 03:09:16 -0000 I'm trying to do a little system hacking on CMU Lisp. Currently CMU Lisp has a minimum of two files needed to execute. One is a program usually called "lisp" that the OS runs, which basically a loader for the other file, a lisp.core file that contains the actual lisp system. People have been asking for a way to make a "lisp executable" meaning putting everything into a single file. It's more than just tidiness --- the core and loader have to stay synchronized, and in the normal process of keeping the system up to date you can sometimes wind up with an old core file that you can no longer run because you don't have the corresponding loader any more and it would be tedious to recover it. Anyway I created a utility that post-processes the lisp.core file, creating three ELF compatible ".o" files, one for each memory space that lisp uses. I then hacked a linker script so that GNU ld will put these .o files in the executable and add the proper program headers. It all worked, and I can actually run the resulting executable. Unfortunately it doesn't get far. The first time it calls malloc, malloc tries to call sbrk (I think it's sbrk) twice and those calls return invalid argument errors. Malloc then returns 0. I used ktrace and the "U" malloc_option to determine this --- the calls show up as follows: 89021 testit CALL readlink(0x680bbf14,0xbfbff3b0,0x3f) 89021 testit NAMI "/etc/malloc.conf" 89021 testit RET readlink -1 errno 2 No such file or directory 89021 testit CALL utrace(0xbfbff3a4,0xc) 89021 testit USER 12 00 00 00 00 00 00 00 00 00 00 00 00 89021 testit RET utrace 0 89021 testit CALL mmap(0,0x1000,0x3,0x1002,0xffffffff,0,0,0) 89021 testit RET mmap 1745698816/0x680d4000 89021 testit CALL break(0x8067000) 89021 testit RET break -1 errno 22 Invalid argument 89021 testit CALL break(0x81e6000) 89021 testit RET break -1 errno 22 Invalid argument 89021 testit CALL utrace(0xbfbff414,0xc) 89021 testit USER 12 00 00 00 00 00 00 18 00 00 00 00 00 89021 testit RET utrace 0 I tried to look at the source to see if I could find out what is causing the "break" calls to return EINVAL but I couldn't find the actual code that does these system calls. The man page says EINVAL gets returned when "The requested break value was beyond the beginning of the data segment," which doesn't quite make sense to me. The segments my program creates are at 0x10000000, 0x28f00000 and 0x48000000 if that makes a difference. Anyway my question is whether anyone knows why this might be happening or if someone can point me in the right direction to find out. Thanks for any help! -- Fred Gilham gilham@csl.sri.com If you want to be largely ignored by women, playing jazz guitar is pretty good strategy... --- Bob Russell