This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: libiberty's physmem


 > 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]