1*98b9484cSchristos /* Emulation of getpagesize() for systems that need it. */ 2*98b9484cSchristos 3*98b9484cSchristos /* 4*98b9484cSchristos 5*98b9484cSchristos @deftypefn Supplemental int getpagesize (void) 6*98b9484cSchristos 7*98b9484cSchristos Returns the number of bytes in a page of memory. This is the 8*98b9484cSchristos granularity of many of the system memory management routines. No 9*98b9484cSchristos guarantee is made as to whether or not it is the same as the basic 10*98b9484cSchristos memory management hardware page size. 11*98b9484cSchristos 12*98b9484cSchristos @end deftypefn 13*98b9484cSchristos 14*98b9484cSchristos BUGS 15*98b9484cSchristos 16*98b9484cSchristos Is intended as a reasonable replacement for systems where this 17*98b9484cSchristos is not provided as a system call. The value of 4096 may or may 18*98b9484cSchristos not be correct for the systems where it is returned as the default 19*98b9484cSchristos value. 20*98b9484cSchristos 21*98b9484cSchristos */ 22*98b9484cSchristos 23*98b9484cSchristos #ifndef VMS 24*98b9484cSchristos 25*98b9484cSchristos #include "config.h" 26*98b9484cSchristos 27*98b9484cSchristos #include <sys/types.h> 28*98b9484cSchristos #ifdef HAVE_SYS_PARAM_H 29*98b9484cSchristos #include <sys/param.h> 30*98b9484cSchristos #endif 31*98b9484cSchristos 32*98b9484cSchristos #undef GNU_OUR_PAGESIZE 33*98b9484cSchristos #if defined (HAVE_SYSCONF) && defined (HAVE_UNISTD_H) 34*98b9484cSchristos #include <unistd.h> 35*98b9484cSchristos #ifdef _SC_PAGESIZE 36*98b9484cSchristos #define GNU_OUR_PAGESIZE sysconf(_SC_PAGESIZE) 37*98b9484cSchristos #endif 38*98b9484cSchristos #endif 39*98b9484cSchristos 40*98b9484cSchristos #ifndef GNU_OUR_PAGESIZE 41*98b9484cSchristos # ifdef PAGESIZE 42*98b9484cSchristos # define GNU_OUR_PAGESIZE PAGESIZE 43*98b9484cSchristos # else /* no PAGESIZE */ 44*98b9484cSchristos # ifdef EXEC_PAGESIZE 45*98b9484cSchristos # define GNU_OUR_PAGESIZE EXEC_PAGESIZE 46*98b9484cSchristos # else /* no EXEC_PAGESIZE */ 47*98b9484cSchristos # ifdef NBPG 48*98b9484cSchristos # define GNU_OUR_PAGESIZE (NBPG * CLSIZE) 49*98b9484cSchristos # ifndef CLSIZE 50*98b9484cSchristos # define CLSIZE 1 51*98b9484cSchristos # endif /* CLSIZE */ 52*98b9484cSchristos # else /* no NBPG */ 53*98b9484cSchristos # ifdef NBPC 54*98b9484cSchristos # define GNU_OUR_PAGESIZE NBPC 55*98b9484cSchristos # else /* no NBPC */ 56*98b9484cSchristos # define GNU_OUR_PAGESIZE 4096 /* Just punt and use reasonable value */ 57*98b9484cSchristos # endif /* NBPC */ 58*98b9484cSchristos # endif /* NBPG */ 59*98b9484cSchristos # endif /* EXEC_PAGESIZE */ 60*98b9484cSchristos # endif /* PAGESIZE */ 61*98b9484cSchristos #endif /* GNU_OUR_PAGESIZE */ 62*98b9484cSchristos 63*98b9484cSchristos int getpagesize(void)64*98b9484cSchristosgetpagesize (void) 65*98b9484cSchristos { 66*98b9484cSchristos return (GNU_OUR_PAGESIZE); 67*98b9484cSchristos } 68*98b9484cSchristos 69*98b9484cSchristos #else /* VMS */ 70*98b9484cSchristos 71*98b9484cSchristos #if 0 /* older distributions of gcc-vms are missing <syidef.h> */ 72*98b9484cSchristos #include <syidef.h> 73*98b9484cSchristos #endif 74*98b9484cSchristos #ifndef SYI$_PAGE_SIZE /* VMS V5.4 and earlier didn't have this yet */ 75*98b9484cSchristos #define SYI$_PAGE_SIZE 4452 76*98b9484cSchristos #endif 77*98b9484cSchristos extern unsigned long lib$getsyi(const unsigned short *,...); 78*98b9484cSchristos getpagesize(void)79*98b9484cSchristosint getpagesize (void) 80*98b9484cSchristos { 81*98b9484cSchristos long pagsiz = 0L; 82*98b9484cSchristos unsigned short itmcod = SYI$_PAGE_SIZE; 83*98b9484cSchristos 84*98b9484cSchristos (void) lib$getsyi (&itmcod, (void *) &pagsiz); 85*98b9484cSchristos if (pagsiz == 0L) 86*98b9484cSchristos pagsiz = 512L; /* VAX default */ 87*98b9484cSchristos return (int) pagsiz; 88*98b9484cSchristos } 89*98b9484cSchristos 90*98b9484cSchristos #endif /* VMS */ 91