This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: libiberty's physmem
- From: "Kaveh R. Ghazi" <ghazi at caipclassic dot rutgers dot edu>
- To: stevenb at suse dot de
- Cc: gcc-patches at gcc dot gnu dot org, sgk at troutmask dot apl dot washington dot edu
- Date: Thu, 8 Dec 2005 19:01:58 -0500 (EST)
- Subject: Re: libiberty's physmem
- References: <200512090000.16505.stevenb@suse.de>
> Index: physmem.c
> ===================================================================
> --- physmem.c (revision 108242)
> +++ physmem.c (working copy)
> @@ -134,9 +134,20 @@ physmem_total (void)
>
> #if HAVE_SYSCTL && defined HW_PHYSMEM
> { /* This works on *bsd and darwin. */
> - unsigned int physmem;
> + size_t physmem;
> size_t len = sizeof physmem;
> - static int mib[2] = { CTL_HW, HW_PHYSMEM };
> + static int mib[2];
> +
> + if (len == 4)
> + {
> + mib[0] = CTL_HW;
> + mib[1] = HW_PHYSMEM;
> + }
> + else if (len == 8)
> + {
> + mib[0] = CTL_HW;
> + mib[1] = HW_PHYSMEM64;
> + }
>
> if (sysctl (mib, ARRAY_SIZE (mib), &physmem, &len, NULL, 0) == 0
> && len == sizeof (physmem))
Don't you need to check #ifdef HW_PHYSMEM64 somewhere here? Otherwise
compilation will break on platforms that don't have it.
> @@ -240,9 +251,20 @@ physmem_available (void)
>
> #if HAVE_SYSCTL && defined HW_USERMEM
> { /* This works on *bsd and darwin. */
> - unsigned int usermem;
> + size_t usermem;
> size_t len = sizeof usermem;
> - static int mib[2] = { CTL_HW, HW_USERMEM };
> + static int mib[2];
> +
> + if (len == 4)
> + {
> + mib[0] = CTL_HW;
> + mib[1] = HW_PHYSMEM;
> + }
> + else if (len == 8)
> + {
> + mib[0] = CTL_HW;
> + mib[1] = HW_PHYSMEM64;
> + }
>
> if (sysctl (mib, ARRAY_SIZE (mib), &usermem, &len, NULL, 0) == 0
> && len == sizeof (usermem))
Copy-n-pasto? s/PHYSMEM/USERMEM/ ?
Did you compile physmem.c with -DDEBUG and run the standalone binary
to sanity check the values?
--Kaveh
--
Kaveh R. Ghazi ghazi@caip.rutgers.edu