xref: /freebsd/lib/libsys/getpagesize.c (revision f70c5a0925c621ce862327a1f335394e731fbaed)
1*f70c5a09SBrooks Davis /*-
2*f70c5a09SBrooks Davis  * SPDX-License-Identifier: BSD-3-Clause
3*f70c5a09SBrooks Davis  *
4*f70c5a09SBrooks Davis  * Copyright (c) 1989, 1993
5*f70c5a09SBrooks Davis  *	The Regents of the University of California.  All rights reserved.
6*f70c5a09SBrooks Davis  *
7*f70c5a09SBrooks Davis  * Redistribution and use in source and binary forms, with or without
8*f70c5a09SBrooks Davis  * modification, are permitted provided that the following conditions
9*f70c5a09SBrooks Davis  * are met:
10*f70c5a09SBrooks Davis  * 1. Redistributions of source code must retain the above copyright
11*f70c5a09SBrooks Davis  *    notice, this list of conditions and the following disclaimer.
12*f70c5a09SBrooks Davis  * 2. Redistributions in binary form must reproduce the above copyright
13*f70c5a09SBrooks Davis  *    notice, this list of conditions and the following disclaimer in the
14*f70c5a09SBrooks Davis  *    documentation and/or other materials provided with the distribution.
15*f70c5a09SBrooks Davis  * 3. Neither the name of the University nor the names of its contributors
16*f70c5a09SBrooks Davis  *    may be used to endorse or promote products derived from this software
17*f70c5a09SBrooks Davis  *    without specific prior written permission.
18*f70c5a09SBrooks Davis  *
19*f70c5a09SBrooks Davis  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20*f70c5a09SBrooks Davis  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21*f70c5a09SBrooks Davis  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22*f70c5a09SBrooks Davis  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23*f70c5a09SBrooks Davis  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24*f70c5a09SBrooks Davis  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25*f70c5a09SBrooks Davis  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26*f70c5a09SBrooks Davis  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27*f70c5a09SBrooks Davis  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28*f70c5a09SBrooks Davis  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29*f70c5a09SBrooks Davis  * SUCH DAMAGE.
30*f70c5a09SBrooks Davis  */
31*f70c5a09SBrooks Davis 
32*f70c5a09SBrooks Davis #include <sys/param.h>
33*f70c5a09SBrooks Davis #include <sys/auxv.h>
34*f70c5a09SBrooks Davis 
35*f70c5a09SBrooks Davis #include "libc_private.h"
36*f70c5a09SBrooks Davis 
37*f70c5a09SBrooks Davis /*
38*f70c5a09SBrooks Davis  * NB: This function may be called from malloc(3) at initialization
39*f70c5a09SBrooks Davis  * NB: so must not result in a malloc(3) related call!
40*f70c5a09SBrooks Davis  */
41*f70c5a09SBrooks Davis 
42*f70c5a09SBrooks Davis int
getpagesize(void)43*f70c5a09SBrooks Davis getpagesize(void)
44*f70c5a09SBrooks Davis {
45*f70c5a09SBrooks Davis 	int value;
46*f70c5a09SBrooks Davis 
47*f70c5a09SBrooks Davis 	if (_elf_aux_info(AT_PAGESZ, &value, sizeof(value)) != 0)
48*f70c5a09SBrooks Davis 		value = PAGE_SIZE;
49*f70c5a09SBrooks Davis 
50*f70c5a09SBrooks Davis 	return (value);
51*f70c5a09SBrooks Davis }
52