From afab3ffcce1054ec887fb347700819d69a9c8151 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Tue, 28 Jul 2015 14:58:37 -0700 Subject: [PATCH] Move PAGE_MASK into . I'm removing the TODO on the assumption that being compatible with glibc is more useful than BSD. The new internal "bionic_page.h" header factors out some duplication between libc and the linker. Bug: http://b/22735893 Change-Id: I4aec4dcba5886fb6f6b9290a8f85660643261321 --- libc/bionic/libc_init_static.cpp | 8 +------- libc/include/limits.h | 3 --- libc/include/sys/user.h | 3 +++ libc/private/bionic_page.h | 33 ++++++++++++++++++++++++++++++++ linker/linker.h | 15 +++------------ 5 files changed, 40 insertions(+), 22 deletions(-) create mode 100644 libc/private/bionic_page.h diff --git a/libc/bionic/libc_init_static.cpp b/libc/bionic/libc_init_static.cpp index ef57af650..2b1a8cb2c 100644 --- a/libc/bionic/libc_init_static.cpp +++ b/libc/bionic/libc_init_static.cpp @@ -49,16 +49,10 @@ #include "libc_init_common.h" #include "pthread_internal.h" +#include "private/bionic_page.h" #include "private/bionic_tls.h" #include "private/KernelArgumentBlock.h" -// Returns the address of the page containing address 'x'. -#define PAGE_START(x) ((x) & PAGE_MASK) - -// Returns the address of the next page after address 'x', unless 'x' is -// itself at the start of a page. -#define PAGE_END(x) PAGE_START((x) + (PAGE_SIZE-1)) - extern "C" int __cxa_atexit(void (*)(void *), void *, void *); static void call_array(void(**list)()) { diff --git a/libc/include/limits.h b/libc/include/limits.h index 6ae629be7..685e1847d 100644 --- a/libc/include/limits.h +++ b/libc/include/limits.h @@ -89,9 +89,6 @@ #define PAGESIZE PAGE_SIZE #endif -/* glibc's PAGE_MASK is the bitwise negation of BSD's! TODO: remove? */ -#define PAGE_MASK (~(PAGE_SIZE - 1)) - #define SEM_VALUE_MAX 0x3fffffff /* POSIX says these belong in but BSD has some in . */ diff --git a/libc/include/sys/user.h b/libc/include/sys/user.h index d63fe6aa5..12af664d5 100644 --- a/libc/include/sys/user.h +++ b/libc/include/sys/user.h @@ -35,6 +35,9 @@ __BEGIN_DECLS +#define PAGE_SIZE 4096 +#define PAGE_MASK (~(PAGE_SIZE - 1)) + #if __i386__ struct user_fpregs_struct { diff --git a/libc/private/bionic_page.h b/libc/private/bionic_page.h new file mode 100644 index 000000000..0beb70843 --- /dev/null +++ b/libc/private/bionic_page.h @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _BIONIC_PAGE_H_ +#define _BIONIC_PAGE_H_ + +// Get PAGE_SIZE and PAGE_MASK. +#include + +// Returns the address of the page containing address 'x'. +#define PAGE_START(x) ((x) & PAGE_MASK) + +// Returns the offset of address 'x' in its page. +#define PAGE_OFFSET(x) ((x) & ~PAGE_MASK) + +// Returns the address of the next page after address 'x', unless 'x' is +// itself at the start of a page. +#define PAGE_END(x) PAGE_START((x) + (PAGE_SIZE-1)) + +#endif // _BIONIC_PAGE_H_ diff --git a/linker/linker.h b/linker/linker.h index b1d256677..6f8bf1fdf 100644 --- a/linker/linker.h +++ b/linker/linker.h @@ -29,13 +29,14 @@ #ifndef _LINKER_H_ #define _LINKER_H_ +#include #include #include #include -#include -#include #include +#include +#include "private/bionic_page.h" #include "private/libc_logging.h" #include "linked_list.h" @@ -77,16 +78,6 @@ #define ELF64_R_TYPE(info) (((info) >> 56) & 0xff) #endif -// Returns the address of the page containing address 'x'. -#define PAGE_START(x) ((x) & PAGE_MASK) - -// Returns the offset of address 'x' in its page. -#define PAGE_OFFSET(x) ((x) & ~PAGE_MASK) - -// Returns the address of the next page after address 'x', unless 'x' is -// itself at the start of a page. -#define PAGE_END(x) PAGE_START((x) + (PAGE_SIZE-1)) - #define FLAG_LINKED 0x00000001 #define FLAG_EXE 0x00000004 // The main executable #define FLAG_LINKER 0x00000010 // The linker itself