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