blob: d4440c4345bd266b6615cec0163257872e35d6a0 [file] [log] [blame]
Elliott Hughesde727ca2012-08-13 15:45:36 -07001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in
12 * the documentation and/or other materials provided with the
13 * distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28
29#include <ctype.h>
30#include <errno.h>
31#include <grp.h>
32#include <mntent.h>
33#include <netdb.h>
Elliott Hughesde727ca2012-08-13 15:45:36 -070034#include <pthread.h>
35#include <pwd.h>
36#include <stdio.h>
37#include <stdlib.h>
38#include <unistd.h>
39
Elliott Hughes3e898472013-02-12 16:40:24 +000040#include "private/android_filesystem_config.h"
Elliott Hughes3e898472013-02-12 16:40:24 +000041#include "private/ErrnoRestorer.h"
Elliott Hughes8f2a5a02013-03-15 15:30:25 -070042#include "private/libc_logging.h"
Yabin Cuia04c79b2014-11-18 16:14:54 -080043#include "private/ThreadLocalBuffer.h"
Elliott Hughes3e898472013-02-12 16:40:24 +000044
Elliott Hughes7874f1d2014-12-18 13:36:25 -080045// POSIX seems to envisage an implementation where the <pwd.h> functions are
46// implemented by brute-force searching with getpwent(3), and the <grp.h>
47// functions are implemented similarly with getgrent(3). This means that it's
48// okay for all the <grp.h> functions to share state, and all the <passwd.h>
49// functions to share state, but <grp.h> functions can't clobber <passwd.h>
50// functions' state and vice versa.
Yabin Cuia04c79b2014-11-18 16:14:54 -080051
Elliott Hughes7874f1d2014-12-18 13:36:25 -080052struct group_state_t {
Elliott Hughesde727ca2012-08-13 15:45:36 -070053 group group_;
54 char* group_members_[2];
Elliott Hughesde727ca2012-08-13 15:45:36 -070055 char group_name_buffer_[32];
Elliott Hughes7874f1d2014-12-18 13:36:25 -080056};
57
Elliott Hughes7874f1d2014-12-18 13:36:25 -080058struct passwd_state_t {
59 passwd passwd_;
Elliott Hughes8b5df392015-01-21 16:19:07 -080060 char name_buffer_[32];
Elliott Hughesde727ca2012-08-13 15:45:36 -070061 char dir_buffer_[32];
62 char sh_buffer_[32];
63};
64
Elliott Hughes61706932015-03-31 10:56:58 -070065static ThreadLocalBuffer<group_state_t> g_group_tls_buffer;
66static ThreadLocalBuffer<passwd_state_t> g_passwd_tls_buffer;
67
68static group_state_t* __group_state() {
69 group_state_t* result = g_group_tls_buffer.get();
70 if (result != nullptr) {
71 memset(result, 0, sizeof(group_state_t));
72 result->group_.gr_mem = result->group_members_;
73 }
74 return result;
Elliott Hughes7874f1d2014-12-18 13:36:25 -080075}
76
Elliott Hughesde727ca2012-08-13 15:45:36 -070077static int do_getpw_r(int by_name, const char* name, uid_t uid,
78 passwd* dst, char* buf, size_t byte_count,
79 passwd** result) {
80 // getpwnam_r and getpwuid_r don't modify errno, but library calls we
81 // make might.
Elliott Hughes3e898472013-02-12 16:40:24 +000082 ErrnoRestorer errno_restorer;
Elliott Hughesde727ca2012-08-13 15:45:36 -070083 *result = NULL;
84
85 // Our implementation of getpwnam(3) and getpwuid(3) use thread-local
86 // storage, so we can call them as long as we copy everything out
87 // before returning.
88 const passwd* src = by_name ? getpwnam(name) : getpwuid(uid); // NOLINT: see above.
89
90 // POSIX allows failure to find a match to be considered a non-error.
91 // Reporting success (0) but with *result NULL is glibc's behavior.
92 if (src == NULL) {
Elliott Hughes3e898472013-02-12 16:40:24 +000093 return (errno == ENOENT) ? 0 : errno;
Elliott Hughesde727ca2012-08-13 15:45:36 -070094 }
95
96 // Work out where our strings will go in 'buf', and whether we've got
97 // enough space.
98 size_t required_byte_count = 0;
99 dst->pw_name = buf;
100 required_byte_count += strlen(src->pw_name) + 1;
101 dst->pw_dir = buf + required_byte_count;
102 required_byte_count += strlen(src->pw_dir) + 1;
103 dst->pw_shell = buf + required_byte_count;
104 required_byte_count += strlen(src->pw_shell) + 1;
105 if (byte_count < required_byte_count) {
Elliott Hughesde727ca2012-08-13 15:45:36 -0700106 return ERANGE;
107 }
108
109 // Copy the strings.
Elliott Hughes3e898472013-02-12 16:40:24 +0000110 snprintf(buf, byte_count, "%s%c%s%c%s", src->pw_name, 0, src->pw_dir, 0, src->pw_shell);
Elliott Hughesde727ca2012-08-13 15:45:36 -0700111
Calin Juravlec7688742014-05-09 21:50:53 +0100112 // pw_passwd and pw_gecos are non-POSIX and unused (always NULL) in bionic.
Elliott Hughesde727ca2012-08-13 15:45:36 -0700113 dst->pw_passwd = NULL;
Elliott Hughes7874f1d2014-12-18 13:36:25 -0800114#if defined(__LP64__)
Calin Juravlec7688742014-05-09 21:50:53 +0100115 dst->pw_gecos = NULL;
116#endif
Elliott Hughesde727ca2012-08-13 15:45:36 -0700117
118 // Copy the integral fields.
119 dst->pw_gid = src->pw_gid;
120 dst->pw_uid = src->pw_uid;
121
122 *result = dst;
Elliott Hughesde727ca2012-08-13 15:45:36 -0700123 return 0;
124}
125
126int getpwnam_r(const char* name, passwd* pwd,
127 char* buf, size_t byte_count, passwd** result) {
128 return do_getpw_r(1, name, -1, pwd, buf, byte_count, result);
129}
130
131int getpwuid_r(uid_t uid, passwd* pwd,
132 char* buf, size_t byte_count, passwd** result) {
133 return do_getpw_r(0, NULL, uid, pwd, buf, byte_count, result);
134}
135
Elliott Hughes7874f1d2014-12-18 13:36:25 -0800136static passwd* android_iinfo_to_passwd(passwd_state_t* state,
Elliott Hughesde727ca2012-08-13 15:45:36 -0700137 const android_id_info* iinfo) {
Elliott Hughes8b5df392015-01-21 16:19:07 -0800138 snprintf(state->name_buffer_, sizeof(state->name_buffer_), "%s", iinfo->name);
Elliott Hughesde727ca2012-08-13 15:45:36 -0700139 snprintf(state->dir_buffer_, sizeof(state->dir_buffer_), "/");
140 snprintf(state->sh_buffer_, sizeof(state->sh_buffer_), "/system/bin/sh");
141
142 passwd* pw = &state->passwd_;
Elliott Hughes8b5df392015-01-21 16:19:07 -0800143 pw->pw_name = state->name_buffer_;
Elliott Hughesde727ca2012-08-13 15:45:36 -0700144 pw->pw_uid = iinfo->aid;
145 pw->pw_gid = iinfo->aid;
146 pw->pw_dir = state->dir_buffer_;
147 pw->pw_shell = state->sh_buffer_;
148 return pw;
149}
150
Elliott Hughes8b5df392015-01-21 16:19:07 -0800151static group* android_iinfo_to_group(group_state_t* state,
Elliott Hughesde727ca2012-08-13 15:45:36 -0700152 const android_id_info* iinfo) {
Elliott Hughes8b5df392015-01-21 16:19:07 -0800153 snprintf(state->group_name_buffer_, sizeof(state->group_name_buffer_), "%s", iinfo->name);
154
155 group* gr = &state->group_;
156 gr->gr_name = state->group_name_buffer_;
Elliott Hughesde727ca2012-08-13 15:45:36 -0700157 gr->gr_gid = iinfo->aid;
158 gr->gr_mem[0] = gr->gr_name;
Elliott Hughesde727ca2012-08-13 15:45:36 -0700159 return gr;
160}
161
Elliott Hughes7874f1d2014-12-18 13:36:25 -0800162static passwd* android_id_to_passwd(passwd_state_t* state, unsigned id) {
Elliott Hughesde727ca2012-08-13 15:45:36 -0700163 for (size_t n = 0; n < android_id_count; ++n) {
164 if (android_ids[n].aid == id) {
165 return android_iinfo_to_passwd(state, android_ids + n);
166 }
167 }
168 return NULL;
169}
170
Elliott Hughes7874f1d2014-12-18 13:36:25 -0800171static passwd* android_name_to_passwd(passwd_state_t* state, const char* name) {
Elliott Hughesde727ca2012-08-13 15:45:36 -0700172 for (size_t n = 0; n < android_id_count; ++n) {
173 if (!strcmp(android_ids[n].name, name)) {
174 return android_iinfo_to_passwd(state, android_ids + n);
175 }
176 }
177 return NULL;
178}
179
Elliott Hughes8b5df392015-01-21 16:19:07 -0800180static group* android_id_to_group(group_state_t* state, unsigned id) {
Elliott Hughesde727ca2012-08-13 15:45:36 -0700181 for (size_t n = 0; n < android_id_count; ++n) {
182 if (android_ids[n].aid == id) {
Elliott Hughes8b5df392015-01-21 16:19:07 -0800183 return android_iinfo_to_group(state, android_ids + n);
Elliott Hughesde727ca2012-08-13 15:45:36 -0700184 }
185 }
186 return NULL;
187}
188
Elliott Hughes8b5df392015-01-21 16:19:07 -0800189static group* android_name_to_group(group_state_t* state, const char* name) {
Elliott Hughesde727ca2012-08-13 15:45:36 -0700190 for (size_t n = 0; n < android_id_count; ++n) {
191 if (!strcmp(android_ids[n].name, name)) {
Elliott Hughes8b5df392015-01-21 16:19:07 -0800192 return android_iinfo_to_group(state, android_ids + n);
Elliott Hughesde727ca2012-08-13 15:45:36 -0700193 }
194 }
195 return NULL;
196}
197
198// Translate a user/group name to the corresponding user/group id.
Yabin Cuia04c79b2014-11-18 16:14:54 -0800199// all_a1234 -> 0 * AID_USER + AID_SHARED_GID_START + 1234 (group name only)
Elliott Hughesde727ca2012-08-13 15:45:36 -0700200// u0_a1234 -> 0 * AID_USER + AID_APP + 1234
201// u2_i1000 -> 2 * AID_USER + AID_ISOLATED_START + 1000
202// u1_system -> 1 * AID_USER + android_ids['system']
203// returns 0 and sets errno to ENOENT in case of error
Elliott Hughesc56af082015-01-22 11:02:59 -0800204static id_t app_id_from_name(const char* name, bool is_group) {
Yabin Cuia04c79b2014-11-18 16:14:54 -0800205 char* end;
206 unsigned long userid;
207 bool is_shared_gid = false;
208
209 if (is_group && name[0] == 'a' && name[1] == 'l' && name[2] == 'l') {
210 end = const_cast<char*>(name+3);
211 userid = 0;
212 is_shared_gid = true;
213 } else if (name[0] == 'u' && isdigit(name[1])) {
214 userid = strtoul(name+1, &end, 10);
215 } else {
Elliott Hughesde727ca2012-08-13 15:45:36 -0700216 errno = ENOENT;
217 return 0;
218 }
219
Elliott Hughesde727ca2012-08-13 15:45:36 -0700220 if (end[0] != '_' || end[1] == 0) {
221 errno = ENOENT;
222 return 0;
223 }
224
225 unsigned long appid = 0;
226 if (end[1] == 'a' && isdigit(end[2])) {
Yabin Cuia04c79b2014-11-18 16:14:54 -0800227 if (is_shared_gid) {
228 // end will point to \0 if the strtoul below succeeds.
229 appid = strtoul(end+2, &end, 10) + AID_SHARED_GID_START;
230 if (appid > AID_SHARED_GID_END) {
231 errno = ENOENT;
232 return 0;
233 }
234 } else {
235 // end will point to \0 if the strtoul below succeeds.
236 appid = strtoul(end+2, &end, 10) + AID_APP;
237 }
Elliott Hughesde727ca2012-08-13 15:45:36 -0700238 } else if (end[1] == 'i' && isdigit(end[2])) {
239 // end will point to \0 if the strtoul below succeeds.
240 appid = strtoul(end+2, &end, 10) + AID_ISOLATED_START;
241 } else {
242 for (size_t n = 0; n < android_id_count; n++) {
243 if (!strcmp(android_ids[n].name, end + 1)) {
244 appid = android_ids[n].aid;
245 // Move the end pointer to the null terminator.
246 end += strlen(android_ids[n].name) + 1;
247 }
248 }
249 }
250
251 // Check that the entire string was consumed by one of the 3 cases above.
252 if (end[0] != 0) {
253 errno = ENOENT;
254 return 0;
255 }
256
257 // Check that user id won't overflow.
258 if (userid > 1000) {
259 errno = ENOENT;
260 return 0;
261 }
262
263 // Check that app id is within range.
264 if (appid >= AID_USER) {
265 errno = ENOENT;
266 return 0;
267 }
268
Elliott Hughesc56af082015-01-22 11:02:59 -0800269 return (appid + userid*AID_USER);
Elliott Hughesde727ca2012-08-13 15:45:36 -0700270}
271
Yabin Cuia04c79b2014-11-18 16:14:54 -0800272static void print_app_name_from_uid(const uid_t uid, char* buffer, const int bufferlen) {
273 const uid_t appid = uid % AID_USER;
274 const uid_t userid = uid / AID_USER;
Kenny Root8a05a012012-09-13 14:31:50 -0700275 if (appid >= AID_ISOLATED_START) {
276 snprintf(buffer, bufferlen, "u%u_i%u", userid, appid - AID_ISOLATED_START);
Kenny Root8a05a012012-09-13 14:31:50 -0700277 } else if (appid < AID_APP) {
278 for (size_t n = 0; n < android_id_count; n++) {
279 if (android_ids[n].aid == appid) {
280 snprintf(buffer, bufferlen, "u%u_%s", userid, android_ids[n].name);
281 return;
Elliott Hughesde727ca2012-08-13 15:45:36 -0700282 }
283 }
Elliott Hughesde727ca2012-08-13 15:45:36 -0700284 } else {
Kenny Root8a05a012012-09-13 14:31:50 -0700285 snprintf(buffer, bufferlen, "u%u_a%u", userid, appid - AID_APP);
Elliott Hughesde727ca2012-08-13 15:45:36 -0700286 }
287}
288
Yabin Cuia04c79b2014-11-18 16:14:54 -0800289static void print_app_name_from_gid(const gid_t gid, char* buffer, const int bufferlen) {
290 const uid_t appid = gid % AID_USER;
291 const uid_t userid = gid / AID_USER;
292 if (appid >= AID_ISOLATED_START) {
293 snprintf(buffer, bufferlen, "u%u_i%u", userid, appid - AID_ISOLATED_START);
294 } else if (userid == 0 && appid >= AID_SHARED_GID_START && appid <= AID_SHARED_GID_END) {
295 snprintf(buffer, bufferlen, "all_a%u", appid - AID_SHARED_GID_START);
296 } else if (appid < AID_APP) {
297 for (size_t n = 0; n < android_id_count; n++) {
298 if (android_ids[n].aid == appid) {
299 snprintf(buffer, bufferlen, "u%u_%s", userid, android_ids[n].name);
300 return;
301 }
302 }
303 } else {
304 snprintf(buffer, bufferlen, "u%u_a%u", userid, appid - AID_APP);
305 }
Kenny Root2a54e5e2012-09-13 10:52:52 -0700306}
307
Elliott Hughesde727ca2012-08-13 15:45:36 -0700308// Translate a uid into the corresponding name.
309// 0 to AID_APP-1 -> "system", "radio", etc.
310// AID_APP to AID_ISOLATED_START-1 -> u0_a1234
311// AID_ISOLATED_START to AID_USER-1 -> u0_i1234
312// AID_USER+ -> u1_radio, u1_a1234, u2_i1234, etc.
313// returns a passwd structure (sets errno to ENOENT on failure).
Elliott Hughes7874f1d2014-12-18 13:36:25 -0800314static passwd* app_id_to_passwd(uid_t uid, passwd_state_t* state) {
Elliott Hughesde727ca2012-08-13 15:45:36 -0700315 if (uid < AID_APP) {
316 errno = ENOENT;
317 return NULL;
318 }
319
Elliott Hughes8b5df392015-01-21 16:19:07 -0800320 print_app_name_from_uid(uid, state->name_buffer_, sizeof(state->name_buffer_));
Yabin Cuia04c79b2014-11-18 16:14:54 -0800321
Kenny Root2a54e5e2012-09-13 10:52:52 -0700322 const uid_t appid = uid % AID_USER;
Kenny Root2a54e5e2012-09-13 10:52:52 -0700323 if (appid < AID_APP) {
324 snprintf(state->dir_buffer_, sizeof(state->dir_buffer_), "/");
325 } else {
326 snprintf(state->dir_buffer_, sizeof(state->dir_buffer_), "/data");
327 }
328
Elliott Hughesde727ca2012-08-13 15:45:36 -0700329 snprintf(state->sh_buffer_, sizeof(state->sh_buffer_), "/system/bin/sh");
330
Elliott Hughes7874f1d2014-12-18 13:36:25 -0800331 passwd* pw = &state->passwd_;
Elliott Hughes8b5df392015-01-21 16:19:07 -0800332 pw->pw_name = state->name_buffer_;
Elliott Hughesde727ca2012-08-13 15:45:36 -0700333 pw->pw_dir = state->dir_buffer_;
334 pw->pw_shell = state->sh_buffer_;
335 pw->pw_uid = uid;
336 pw->pw_gid = uid;
Elliott Hughesde727ca2012-08-13 15:45:36 -0700337 return pw;
338}
339
340// Translate a gid into the corresponding app_<gid>
341// group structure (sets errno to ENOENT on failure).
Elliott Hughes7874f1d2014-12-18 13:36:25 -0800342static group* app_id_to_group(gid_t gid, group_state_t* state) {
Elliott Hughesde727ca2012-08-13 15:45:36 -0700343 if (gid < AID_APP) {
344 errno = ENOENT;
345 return NULL;
346 }
347
Yabin Cuia04c79b2014-11-18 16:14:54 -0800348 print_app_name_from_gid(gid, state->group_name_buffer_, sizeof(state->group_name_buffer_));
Elliott Hughesde727ca2012-08-13 15:45:36 -0700349
350 group* gr = &state->group_;
351 gr->gr_name = state->group_name_buffer_;
352 gr->gr_gid = gid;
353 gr->gr_mem[0] = gr->gr_name;
Elliott Hughesde727ca2012-08-13 15:45:36 -0700354 return gr;
355}
356
Elliott Hughesde727ca2012-08-13 15:45:36 -0700357passwd* getpwuid(uid_t uid) { // NOLINT: implementing bad function.
Elliott Hughes61706932015-03-31 10:56:58 -0700358 passwd_state_t* state = g_passwd_tls_buffer.get();
Elliott Hughesde727ca2012-08-13 15:45:36 -0700359 if (state == NULL) {
360 return NULL;
361 }
362
363 passwd* pw = android_id_to_passwd(state, uid);
364 if (pw != NULL) {
365 return pw;
366 }
367 return app_id_to_passwd(uid, state);
368}
369
370passwd* getpwnam(const char* login) { // NOLINT: implementing bad function.
Elliott Hughes61706932015-03-31 10:56:58 -0700371 passwd_state_t* state = g_passwd_tls_buffer.get();
Elliott Hughesde727ca2012-08-13 15:45:36 -0700372 if (state == NULL) {
373 return NULL;
374 }
375
376 passwd* pw = android_name_to_passwd(state, login);
377 if (pw != NULL) {
378 return pw;
379 }
Yabin Cuia04c79b2014-11-18 16:14:54 -0800380 return app_id_to_passwd(app_id_from_name(login, false), state);
Elliott Hughesde727ca2012-08-13 15:45:36 -0700381}
382
Elliott Hughes6fa26e22012-10-22 16:04:56 -0700383// All users are in just one group, the one passed in.
384int getgrouplist(const char* /*user*/, gid_t group, gid_t* groups, int* ngroups) {
Elliott Hughes7874f1d2014-12-18 13:36:25 -0800385 if (*ngroups < 1) {
386 *ngroups = 1;
387 return -1;
388 }
389 groups[0] = group;
390 return (*ngroups = 1);
Elliott Hughesde727ca2012-08-13 15:45:36 -0700391}
392
393char* getlogin() { // NOLINT: implementing bad function.
394 passwd *pw = getpwuid(getuid()); // NOLINT: implementing bad function in terms of bad function.
395 return (pw != NULL) ? pw->pw_name : NULL;
396}
397
398group* getgrgid(gid_t gid) { // NOLINT: implementing bad function.
Elliott Hughes7874f1d2014-12-18 13:36:25 -0800399 group_state_t* state = __group_state();
Elliott Hughesde727ca2012-08-13 15:45:36 -0700400 if (state == NULL) {
401 return NULL;
402 }
403
Elliott Hughes8b5df392015-01-21 16:19:07 -0800404 group* gr = android_id_to_group(state, gid);
Elliott Hughesde727ca2012-08-13 15:45:36 -0700405 if (gr != NULL) {
406 return gr;
407 }
Elliott Hughesde727ca2012-08-13 15:45:36 -0700408 return app_id_to_group(gid, state);
409}
410
411group* getgrnam(const char* name) { // NOLINT: implementing bad function.
Elliott Hughes7874f1d2014-12-18 13:36:25 -0800412 group_state_t* state = __group_state();
Elliott Hughesde727ca2012-08-13 15:45:36 -0700413 if (state == NULL) {
414 return NULL;
415 }
416
Elliott Hughes8b5df392015-01-21 16:19:07 -0800417 if (android_name_to_group(state, name) != 0) {
Elliott Hughesde727ca2012-08-13 15:45:36 -0700418 return &state->group_;
419 }
Yabin Cuia04c79b2014-11-18 16:14:54 -0800420 return app_id_to_group(app_id_from_name(name, true), state);
Elliott Hughesde727ca2012-08-13 15:45:36 -0700421}
422
Elliott Hughes6fa26e22012-10-22 16:04:56 -0700423// We don't have an /etc/networks, so all inputs return NULL.
424netent* getnetbyname(const char* /*name*/) {
425 return NULL;
426}
427
428// We don't have an /etc/networks, so all inputs return NULL.
429netent* getnetbyaddr(uint32_t /*net*/, int /*type*/) {
430 return NULL;
431}
432
433// We don't have an /etc/protocols, so all inputs return NULL.
434protoent* getprotobyname(const char* /*name*/) {
435 return NULL;
436}
437
438// We don't have an /etc/protocols, so all inputs return NULL.
439protoent* getprotobynumber(int /*proto*/) {
440 return NULL;
441}
442
Elliott Hughes0e44bc32014-02-24 15:55:31 -0800443// Portable code should use sysconf(_SC_PAGE_SIZE) directly instead.
Bernhard Rosenkraenzer9ae59c02013-09-18 23:29:08 +0200444int getpagesize() {
Elliott Hughes91570ce2014-07-10 12:34:23 -0700445 // We dont use sysconf(3) here because that drags in stdio, which makes static binaries fat.
446 return PAGE_SIZE;
Bernhard Rosenkraenzer9ae59c02013-09-18 23:29:08 +0200447}