Vulnerability Development mailing list archives

RE: Getting passwords from the heap?


From: Michael Wojcik <Michael.Wojcik () merant com>
Date: Mon, 2 Jul 2001 09:53:14 -0700

I had a private note from Mike Harris following my previous post in this
thread.  Mike noted the Compaq/DEC Alpha architecture uses 8K pages.  He
didn't say whether this is true for all OSes; as he also noted, the x86
architecture - in more recent generations - supports large 4M pages as well
as the more commonly used 4K ones.  (There was an excellent article in _Dr.
Dobb's Journal_ some months back on using large x86 pages.)

After reading his note I realized I should probably have mentioned that
SUSv2-compliant[1] OSes generally will tell you the page size using sysconf:

----- cut here -----
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main(void)
{
   long PageSize;

   /* Get page size in bytes */
   PageSize = sysconf(_SC_PAGESIZE);

   if (PageSize < 0)
      {
      /* sysconf doesn't set errno, so perror isn't useful here */
      fputs("error in sysconf\n", stderr);
      return EXIT_FAILURE;
      }
   else if (PageSize == 0)
      {
      /* sysconf doesn't set errno, so perror isn't useful here */
      fputs("page size is unknown\n", stderr);
      return EXIT_FAILURE;
      }
   else
      {
      printf("page size in bytes: %ld\n", PageSize);
      }

   return EXIT_SUCCESS;
}
----- cut here -----

Many Unixish OSes also provide a "pagesize" command which prints the page
size in bytes, and a getpagesize() function which is equivalent to
sysconf(_SC_PAGESIZE).  They apparently originated in BSD4.2 and were picked
up in SVR4.

Note, though, in the context of this thread, that the page size is not
likely to be a terribly useful piece of information.

[1] "SUSv2" is the Single Unix Specification version 2.  sysconf is a POSIX
function, but _SC_PAGESIZE is not part of POSIX.2 AFAIK.

Michael Wojcik             michael.wojcik () merant com
MERANT
Department of English, Miami University


Current thread: