From owner-freebsd-questions@FreeBSD.ORG Wed Feb 20 08:12:09 2008 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id A09BC16A403 for ; Wed, 20 Feb 2008 08:12:09 +0000 (UTC) (envelope-from wundram@beenic.net) Received: from mail.beenic.net (mail.beenic.net [83.246.72.40]) by mx1.freebsd.org (Postfix) with ESMTP id 2E33E13C4E3 for ; Wed, 20 Feb 2008 08:12:09 +0000 (UTC) (envelope-from wundram@beenic.net) Received: from [192.168.1.38] (a89-182-73-80.net-htp.de [89.182.73.80]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.beenic.net (Postfix) with ESMTP id 6B2AFA44529 for ; Wed, 20 Feb 2008 09:12:07 +0100 (CET) From: "Heiko Wundram (Beenic)" Organization: Beenic Networks GmbH To: freebsd-questions@freebsd.org Date: Wed, 20 Feb 2008 09:12:21 +0100 User-Agent: KMail/1.9.7 References: <1563a4fd0802192217v2776fd50hf299ee7d86d9fb5c@mail.gmail.com> In-Reply-To: <1563a4fd0802192217v2776fd50hf299ee7d86d9fb5c@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200802200912.21515.wundram@beenic.net> Subject: Re: 32 bit FreeBSD compiled binary coredumps on 64 bit(amd) FreeBSD X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 20 Feb 2008 08:12:09 -0000 Am Mittwoch, 20. Februar 2008 07:17:30 schrieb navneet Upadhyay: > I am compiling the binary on 32 bit FreeBSD and running it on 64 > (amd64)bit FreeBSD . FreeBSD says it is possible to do so. > But my application core dumps . I investigated the reason which is > as follows : > > The problem is in the call retval = sysctl(mib, 4, &kp, &sz, NULL, 0); > where sz is size of kp and where kp is a structure of type kinfo_proc. The > size of this structure on 32bit system is 768 and on 64 bit system is 1088. > > The call works on 32 bit system but when run on 64 bit system it coredumps > , because of the size mismatch of kinfo_proc . > > If i hardcode the sz to 1088 then it works on amd64 systems , how do i deal > with it. I am anticipating lot of coredumps like that, what is a generic > solution for such kinds of problems. Without investigating further whether the structure up to byte 768 is different (wrt. structure member offsets, and thus wrt. to hardcoded constants in the binary file), which would be a real showstopper for the i386"-emulation" on amd64 (and thus I can't see it being that way), see the documentation of sysctl: RETURN VALUES Upon successful completion, the value 0 is returned; otherwise the value -1 is returned and the global variable errno is set to indicate the error. ERRORS [ENOMEM] The length pointed to by oldlenp is too short to hold the requested value. So, basically, you should check in the call whether sysctl returned -1 (with errno set to ENOMEM), and enlarge the buffer if so, until it doesn't return -1 anymore. This should handle i386 and amd64 transparently (if the offsets up to byte 768 are equal/similar). In case you're trying to recompile the application on 64-bit, you should use sizeof() anyway to automatically adapt the initial buffer size reserved for the output buffer depending on the definition of the structure (which will also spare you pain if a FreeBSD upgrade changes the structure). -- Heiko Wundram Product & Application Development