From owner-freebsd-amd64@FreeBSD.ORG Fri Jan 16 09:15:35 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 052691065795 for ; Fri, 16 Jan 2009 09:15:35 +0000 (UTC) (envelope-from jacques.fourie@gmail.com) Received: from fg-out-1718.google.com (fg-out-1718.google.com [72.14.220.152]) by mx1.freebsd.org (Postfix) with ESMTP id 7E1B58FC2A for ; Fri, 16 Jan 2009 09:15:34 +0000 (UTC) (envelope-from jacques.fourie@gmail.com) Received: by fg-out-1718.google.com with SMTP id l26so893114fgb.35 for ; Fri, 16 Jan 2009 01:15:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=OMhlaqZMbr/0bphrBOYTN3bAizaMsimrYKcCd8OgqJQ=; b=u3L4Mkv73neQnNE+Kcyx3sZwQwKgPV9pxrbkAUYVKcIicgyawkvYFde5mFnHv6Xj8T 7zOBACG/zQsNw52ic8VxaBkXlgXWQtEO5pqKrvPJSqkaKml1+xnAqkj/7nuBi42qvh/s TvlovZ3N6fL5zvwLEtfpPp3FIVwldX8Ig+RZI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=tAo6ZWpjl+FgMACKRTkRPhDKDoU5sClcaAC4vwC8p7sJGTOhljnwR7jKxN7nl4hPPD EwYHMHZfT9l+GODPw/Px0HzLIxr5+9/sxscgaj34jM4K+i1PCswz1Li++N2rv0RQ9LAi wz4Dtb4MHhywV8STdaT808x3DJlvgbeLBlLOc= MIME-Version: 1.0 Received: by 10.86.89.20 with SMTP id m20mr1098228fgb.71.1232095641673; Fri, 16 Jan 2009 00:47:21 -0800 (PST) In-Reply-To: <7d6fde3d0901160044x4d7735cep16f032cd99dbc835@mail.gmail.com> References: <7d6fde3d0901160041n55466290l55f737d274a40895@mail.gmail.com> <7d6fde3d0901160044x4d7735cep16f032cd99dbc835@mail.gmail.com> Date: Fri, 16 Jan 2009 10:47:21 +0200 Message-ID: From: Jacques Fourie To: Garrett Cooper Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Mailman-Approved-At: Fri, 16 Jan 2009 12:24:15 +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:15:36 -0000 On Fri, Jan 16, 2009 at 10:44 AM, Garrett Cooper wrote: > On Fri, Jan 16, 2009 at 12:41 AM, Garrett Cooper wrote: >> 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 >> >> /* 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)); >> } >> >> printf("%lu\n", len); >> >> return 0; >> >> } >> >> # output for len preset to 0: >> [gcooper@optimus ~]$ ./test2 >> Errno: 12 >> test2: Segmentation fault: 11 (core dumped) >> [gcooper@optimus ~]$ uname -a >> FreeBSD optimus.gateway.2wire.net 8.0-CURRENT FreeBSD 8.0-CURRENT #4: >> Sun Jan 11 12:30:31 PST 2009 >> root@optimus.gateway.2wire.net:/usr/obj/usr/src/sys/OPTIMUS amd64 >> >> [gcooper@orangebox /usr/home/gcooper]$ ./test >> Errno: 12 >> test: Error: Cannot allocate memory >> [gcooper@orangebox /usr/home/gcooper]$ uname -a >> FreeBSD orangebox.gateway.2wire.net 8.0-CURRENT FreeBSD 8.0-CURRENT >> #4: Sat Jan 3 22:54:52 PST 2009 >> gcooper@orangebox.gateway.2wire.net:/usr/obj/usr/src/sys/ORANGEBOX >> i386 >> >> # output for len not preset to 0: >> [gcooper@optimus ~]$ ./test2 >> Errno: 14 >> test2: Segmentation fault: 11 (core dumped) > > Almost forgot -- here are the actual values reported by sysctl(1), > just for reference: > > [gcooper@optimus ~]$ sysctl kern.ipc.shmall kern.ipc.shmmin kern.ipc.shmmax > kern.ipc.shmall: 8192 > kern.ipc.shmmin: 1 > kern.ipc.shmmax: 33554432 > > [gcooper@orangebox /usr/src/sys]$ sysctl kern.ipc.shmall > kern.ipc.shmmin kern.ipc.shmmax > kern.ipc.shmall: 8192 > kern.ipc.shmmin: 1 > kern.ipc.shmmax: 33554432 > > Thanks, > -Garrett > _______________________________________________ > freebsd-hackers@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-hackers > To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org" > You need to initialize len to the number of entries in the mib array. Try adding 'len = 4' before calling sysctlnametomib() and see if your issues go away.