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