From owner-freebsd-amd64@FreeBSD.ORG Fri Jan 16 09:19:43 2009 Return-Path: Delivered-To: amd64@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id AD00910656BD for ; Fri, 16 Jan 2009 09:19:43 +0000 (UTC) (envelope-from christoph.mallon@gmx.de) Received: from mail.gmx.net (mail.gmx.net [213.165.64.20]) by mx1.freebsd.org (Postfix) with SMTP id EE44E8FC1D for ; Fri, 16 Jan 2009 09:19:42 +0000 (UTC) (envelope-from christoph.mallon@gmx.de) Received: (qmail invoked by alias); 16 Jan 2009 08:53:01 -0000 Received: from p54A3E7DB.dip.t-dialin.net (EHLO tron.homeunix.org) [84.163.231.219] by mail.gmx.net (mp056) with SMTP; 16 Jan 2009 09:53:01 +0100 X-Authenticated: #1673122 X-Provags-ID: V01U2FsdGVkX18o3C8/cC0oIDTtXxxDZ+wo92yQJK/699sT82PYiv iRjmRnbw9N3jjG Message-ID: <49704AEC.3080709@gmx.de> Date: Fri, 16 Jan 2009 09:53:00 +0100 From: Christoph Mallon User-Agent: Thunderbird 2.0.0.19 (X11/20090103) MIME-Version: 1.0 To: Garrett Cooper References: <7d6fde3d0901160041n55466290l55f737d274a40895@mail.gmail.com> In-Reply-To: <7d6fde3d0901160041n55466290l55f737d274a40895@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Y-GMX-Trusted: 0 X-FuHaFi: 0.57 X-Mailman-Approved-At: Fri, 16 Jan 2009 12:24:30 +0000 Cc: "amd64@freebsd.org" , Hackers freeBSD Subject: Re: Confused by segfault with legitimate call to strerror(3) on amd64 / sysctl(3) setting `odd' errno's X-BeenThere: freebsd-amd64@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Porting FreeBSD to the AMD64 platform List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 16 Jan 2009 09:19:44 -0000 Garrett Cooper schrieb: > Hi amd64 and Hackers, > Uh, I'm really confused why 1) this error (errno => ENOMEM) would > occur when I have more than enough free memory (both on x86 and amd64) > and 2) why strerror would segfault in the call to errx in the attached > sourcefile on amd64 only. Not initializing len causes the second > output sample (errno => 14, which is EFAULT). > Any ideas? > Please CC me if mailing on amd64@ as I'm not subscribed to the list. > Thanks, > -Garrett len is not uninitialised. This leads to undefined behaviour. Anything can happen. Probably the syscall overwrites parts of the stack because len has some (random) high value. > /* Program */ > #include > #include > #include > #include > #include > > int > main() { > > int mib[4]; > > size_t len; > > if (sysctlnametomib("kern.ipc.shmmax", mib, &len) != 0) { > printf("Errno: %d\n", errno); > errx(errno, "Error: %s", strerror(errno)); The use of errno is wrong. printf might change errno. Store the errno into a local variable before you do any call, which might modify it.