Browse Source

Patch from Tobias Anderberg <tobias.anderberg@axis.com> to abstract
out page alignment issues. As we we were assuming 4k pages, which
need not be the case...

Eric Andersen 22 năm trước cách đây
mục cha
commit
a46c34c4ec

+ 5 - 0
ldso/ldso/arm/dl-sysdep.h

@@ -117,3 +117,8 @@ static inline unsigned long arm_modulus(unsigned long m, unsigned long p) {
 }
 
 #define do_rem(result, n, base)  result=arm_modulus(n,base);
+
+/* 4096 bytes alignment */
+#define PAGE_ALIGN 0xfffff000
+#define ADDR_ALIGN 0xfff
+#define OFFS_ALIGN 0x7ffff000

+ 5 - 0
ldso/ldso/arm/ld_sysdep.h

@@ -117,3 +117,8 @@ static inline unsigned long arm_modulus(unsigned long m, unsigned long p) {
 }
 
 #define do_rem(result, n, base)  result=arm_modulus(n,base);
+
+/* 4096 bytes alignment */
+#define PAGE_ALIGN 0xfffff000
+#define ADDR_ALIGN 0xfff
+#define OFFS_ALIGN 0x7ffff000

+ 10 - 10
ldso/ldso/dl-elf.c

@@ -448,9 +448,9 @@ struct elf_resolve *_dl_load_elf_shared_library(int secure,
 				char *cpnt;
 
 				status = (char *) _dl_mmap((char *) ((piclib ? libaddr : 0) + 
-					(ppnt->p_vaddr & 0xfffff000)), (ppnt->p_vaddr & 0xfff) 
+					(ppnt->p_vaddr & PAGE_ALIGN)), (ppnt->p_vaddr & ADDR_ALIGN) 
 					+ ppnt->p_filesz, LXFLAGS(ppnt->p_flags), flags, infile, 
-					ppnt->p_offset & 0x7ffff000);
+					ppnt->p_offset & OFFS_ALIGN);
 
 				if (_dl_mmap_check_error(status)) {
 					_dl_dprintf(2, "%s: can't map '%s'\n", 
@@ -462,9 +462,9 @@ struct elf_resolve *_dl_load_elf_shared_library(int secure,
 				};
 
 				/* Pad the last page with zeroes. */
-				cpnt = (char *) (status + (ppnt->p_vaddr & 0xfff) +
+				cpnt = (char *) (status + (ppnt->p_vaddr & ADDR_ALIGN) +
 							  ppnt->p_filesz);
-				while (((unsigned long) cpnt) & 0xfff)
+				while (((unsigned long) cpnt) & ADDR_ALIGN)
 					*cpnt++ = 0;
 
 				/* I am not quite sure if this is completely
@@ -473,17 +473,17 @@ struct elf_resolve *_dl_load_elf_shared_library(int secure,
 				 * /dev/zero if there are any pages left over
 				 * that are not mapped as part of the file */
 
-				map_size = (ppnt->p_vaddr + ppnt->p_filesz + 0xfff) & 0xfffff000;
+				map_size = (ppnt->p_vaddr + ppnt->p_filesz + ADDR_ALIGN) & PAGE_ALIGN;
 				if (map_size < ppnt->p_vaddr + ppnt->p_memsz)
 					status = (char *) _dl_mmap((char *) map_size + 
 						(piclib ? libaddr : 0), 
 						ppnt->p_vaddr + ppnt->p_memsz - map_size, 
 						LXFLAGS(ppnt->p_flags), flags | MAP_ANONYMOUS, -1, 0);
 			} else
-				status = (char *) _dl_mmap((char *) (ppnt->p_vaddr & 0xfffff000) 
-					+ (piclib ? libaddr : 0), (ppnt->p_vaddr & 0xfff) + 
+				status = (char *) _dl_mmap((char *) (ppnt->p_vaddr & PAGE_ALIGN) 
+					+ (piclib ? libaddr : 0), (ppnt->p_vaddr & ADDR_ALIGN) + 
 					ppnt->p_filesz, LXFLAGS(ppnt->p_flags), flags, 
-					infile, ppnt->p_offset & 0x7ffff000);
+					infile, ppnt->p_offset & OFFS_ALIGN);
 			if (_dl_mmap_check_error(status)) {
 				_dl_dprintf(2, "%s: can't map '%s'\n", _dl_progname, libname);
 				_dl_internal_error_number = DL_ERROR_MMAP_FAILED;
@@ -559,8 +559,8 @@ struct elf_resolve *_dl_load_elf_shared_library(int secure,
 		for (i = 0; i < epnt->e_phnum; i++, ppnt++) {
 			if (ppnt->p_type == PT_LOAD && !(ppnt->p_flags & PF_W))
 				_dl_mprotect((void *) ((piclib ? libaddr : 0) + 
-					    (ppnt->p_vaddr & 0xfffff000)), 
-					(ppnt->p_vaddr & 0xfff) + (unsigned long) ppnt->p_filesz, 
+					    (ppnt->p_vaddr & PAGE_ALIGN)), 
+					(ppnt->p_vaddr & ADDR_ALIGN) + (unsigned long) ppnt->p_filesz, 
 					PROT_READ | PROT_WRITE | PROT_EXEC);
 		}
 	}

+ 5 - 0
ldso/ldso/i386/dl-sysdep.h

@@ -74,3 +74,8 @@ struct elf_resolve;
 extern unsigned long _dl_linux_resolver(struct elf_resolve * tpnt, int reloc_entry);
 
 #define do_rem(result, n, base)  result = (n % base)
+
+/* 4096 bytes alignment */
+#define PAGE_ALIGN 0xfffff000
+#define ADDR_ALIGN 0xfff
+#define OFFS_ALIGN 0x7ffff000

+ 5 - 0
ldso/ldso/i386/ld_sysdep.h

@@ -74,3 +74,8 @@ struct elf_resolve;
 extern unsigned long _dl_linux_resolver(struct elf_resolve * tpnt, int reloc_entry);
 
 #define do_rem(result, n, base)  result = (n % base)
+
+/* 4096 bytes alignment */
+#define PAGE_ALIGN 0xfffff000
+#define ADDR_ALIGN 0xfff
+#define OFFS_ALIGN 0x7ffff000

+ 7 - 7
ldso/ldso/ldso.c

@@ -448,8 +448,8 @@ DL_BOOT(unsigned long args)
 					header->e_phoff);
 			for (i = 0; i < header->e_phnum; i++, ppnt++) {
 				if (ppnt->p_type == PT_LOAD && !(ppnt->p_flags & PF_W)) {
-					_dl_mprotect((void *) (load_addr + (ppnt->p_vaddr & 0xfffff000)), 
-							(ppnt->p_vaddr & 0xfff) + (unsigned long) ppnt->p_filesz, 
+					_dl_mprotect((void *) (load_addr + (ppnt->p_vaddr & PAGE_ALIGN)), 
+							(ppnt->p_vaddr & ADDR_ALIGN) + (unsigned long) ppnt->p_filesz, 
 							PROT_READ | PROT_WRITE | PROT_EXEC);
 				}
 			}
@@ -460,8 +460,8 @@ DL_BOOT(unsigned long args)
 			ppnt = (elf_phdr *) auxvt[AT_PHDR].a_un.a_ptr;
 			for (i = 0; i < auxvt[AT_PHNUM].a_un.a_val; i++, ppnt++) {
 				if (ppnt->p_type == PT_LOAD && !(ppnt->p_flags & PF_W))
-					_dl_mprotect((void *) (ppnt->p_vaddr & 0xfffff000),
-								 (ppnt->p_vaddr & 0xfff) +
+					_dl_mprotect((void *) (ppnt->p_vaddr & PAGE_ALIGN),
+								 (ppnt->p_vaddr & ADDR_ALIGN) +
 								 (unsigned long) ppnt->p_filesz,
 								 PROT_READ | PROT_WRITE | PROT_EXEC);
 			}
@@ -720,7 +720,7 @@ static void _dl_get_ready_to_run(struct elf_resolve *tpnt, struct elf_resolve *a
 			int readsize = 0;
 			char *pnt, *pnt1, buf[1024];
 			tpnt->libname = _dl_strdup((char *) ppnt->p_offset +
-					(auxvt[AT_PHDR].a_un.a_val & 0xfffff000));
+					(auxvt[AT_PHDR].a_un.a_val & PAGE_ALIGN));
 			
 			/* Determine if the shared lib loader is a symlink */
 			_dl_memset(buf, 0, sizeof(buf));
@@ -1107,8 +1107,8 @@ static void _dl_get_ready_to_run(struct elf_resolve *tpnt, struct elf_resolve *a
 		for (tpnt = _dl_loaded_modules; tpnt; tpnt = tpnt->next) {
 			for (ppnt = tpnt->ppnt, i = 0; i < tpnt->n_phent; i++, ppnt++) {
 				if (ppnt->p_type == PT_LOAD && !(ppnt->p_flags & PF_W) && tpnt->dynamic_info[DT_TEXTREL]) {
-					_dl_mprotect((void *) (tpnt->loadaddr + (ppnt->p_vaddr & 0xfffff000)), 
-							(ppnt->p_vaddr & 0xfff) + (unsigned long) ppnt->p_filesz, LXFLAGS(ppnt->p_flags));
+					_dl_mprotect((void *) (tpnt->loadaddr + (ppnt->p_vaddr & PAGE_ALIGN)), 
+							(ppnt->p_vaddr & ADDR_ALIGN) + (unsigned long) ppnt->p_filesz, LXFLAGS(ppnt->p_flags));
 				}
 			}
 		}

+ 5 - 0
ldso/ldso/m68k/dl-sysdep.h

@@ -81,3 +81,8 @@ extern unsigned int _dl_linux_resolver (int, int, struct elf_resolve *, int);
 /* Define this because we do not want to call .udiv in the library.
    Not needed for m68k.  */
 #define do_rem(result, n, base)  ((result) = (n) % (base))
+
+/* 4096 bytes alignment */
+#define PAGE_ALIGN 0xfffff000
+#define ADDR_ALIGN 0xfff
+#define OFFS_ALIGN 0x7ffff000

+ 5 - 0
ldso/ldso/m68k/ld_sysdep.h

@@ -81,3 +81,8 @@ extern unsigned int _dl_linux_resolver (int, int, struct elf_resolve *, int);
 /* Define this because we do not want to call .udiv in the library.
    Not needed for m68k.  */
 #define do_rem(result, n, base)  ((result) = (n) % (base))
+
+/* 4096 bytes alignment */
+#define PAGE_ALIGN 0xfffff000
+#define ADDR_ALIGN 0xfff
+#define OFFS_ALIGN 0x7ffff000

+ 5 - 0
ldso/ldso/mips/dl-sysdep.h

@@ -129,3 +129,8 @@ unsigned long _dl_linux_resolver(unsigned long sym_index,
 
 
 #define do_rem(result, n, base)  result = (n % base)
+
+/* 4096 bytes alignment */
+#define PAGE_ALIGN 0xfffff000
+#define ADDR_ALIGN 0xfff
+#define OFFS_ALIGN 0x7ffff000

+ 5 - 0
ldso/ldso/mips/ld_sysdep.h

@@ -129,3 +129,8 @@ unsigned long _dl_linux_resolver(unsigned long sym_index,
 
 
 #define do_rem(result, n, base)  result = (n % base)
+
+/* 4096 bytes alignment */
+#define PAGE_ALIGN 0xfffff000
+#define ADDR_ALIGN 0xfff
+#define OFFS_ALIGN 0x7ffff000

+ 5 - 0
ldso/ldso/powerpc/dl-sysdep.h

@@ -120,3 +120,8 @@ void _dl_init_got(unsigned long *lpnt,struct elf_resolve *tpnt);
 
 
 #define do_rem(result, n, base)  result = (n % base)
+
+/* 4096 bytes alignment */
+#define PAGE_ALIGN 0xfffff000
+#define ADDR_ALIGN 0xfff
+#define OFFS_ALIGN 0x7ffff000

+ 5 - 0
ldso/ldso/powerpc/ld_sysdep.h

@@ -120,3 +120,8 @@ void _dl_init_got(unsigned long *lpnt,struct elf_resolve *tpnt);
 
 
 #define do_rem(result, n, base)  result = (n % base)
+
+/* 4096 bytes alignment */
+#define PAGE_ALIGN 0xfffff000
+#define ADDR_ALIGN 0xfff
+#define OFFS_ALIGN 0x7ffff000

+ 10 - 10
ldso/ldso/readelflib1.c

@@ -448,9 +448,9 @@ struct elf_resolve *_dl_load_elf_shared_library(int secure,
 				char *cpnt;
 
 				status = (char *) _dl_mmap((char *) ((piclib ? libaddr : 0) + 
-					(ppnt->p_vaddr & 0xfffff000)), (ppnt->p_vaddr & 0xfff) 
+					(ppnt->p_vaddr & PAGE_ALIGN)), (ppnt->p_vaddr & ADDR_ALIGN) 
 					+ ppnt->p_filesz, LXFLAGS(ppnt->p_flags), flags, infile, 
-					ppnt->p_offset & 0x7ffff000);
+					ppnt->p_offset & OFFS_ALIGN);
 
 				if (_dl_mmap_check_error(status)) {
 					_dl_dprintf(2, "%s: can't map '%s'\n", 
@@ -462,9 +462,9 @@ struct elf_resolve *_dl_load_elf_shared_library(int secure,
 				};
 
 				/* Pad the last page with zeroes. */
-				cpnt = (char *) (status + (ppnt->p_vaddr & 0xfff) +
+				cpnt = (char *) (status + (ppnt->p_vaddr & ADDR_ALIGN) +
 							  ppnt->p_filesz);
-				while (((unsigned long) cpnt) & 0xfff)
+				while (((unsigned long) cpnt) & ADDR_ALIGN)
 					*cpnt++ = 0;
 
 				/* I am not quite sure if this is completely
@@ -473,17 +473,17 @@ struct elf_resolve *_dl_load_elf_shared_library(int secure,
 				 * /dev/zero if there are any pages left over
 				 * that are not mapped as part of the file */
 
-				map_size = (ppnt->p_vaddr + ppnt->p_filesz + 0xfff) & 0xfffff000;
+				map_size = (ppnt->p_vaddr + ppnt->p_filesz + ADDR_ALIGN) & PAGE_ALIGN;
 				if (map_size < ppnt->p_vaddr + ppnt->p_memsz)
 					status = (char *) _dl_mmap((char *) map_size + 
 						(piclib ? libaddr : 0), 
 						ppnt->p_vaddr + ppnt->p_memsz - map_size, 
 						LXFLAGS(ppnt->p_flags), flags | MAP_ANONYMOUS, -1, 0);
 			} else
-				status = (char *) _dl_mmap((char *) (ppnt->p_vaddr & 0xfffff000) 
-					+ (piclib ? libaddr : 0), (ppnt->p_vaddr & 0xfff) + 
+				status = (char *) _dl_mmap((char *) (ppnt->p_vaddr & PAGE_ALIGN) 
+					+ (piclib ? libaddr : 0), (ppnt->p_vaddr & ADDR_ALIGN) + 
 					ppnt->p_filesz, LXFLAGS(ppnt->p_flags), flags, 
-					infile, ppnt->p_offset & 0x7ffff000);
+					infile, ppnt->p_offset & OFFS_ALIGN);
 			if (_dl_mmap_check_error(status)) {
 				_dl_dprintf(2, "%s: can't map '%s'\n", _dl_progname, libname);
 				_dl_internal_error_number = DL_ERROR_MMAP_FAILED;
@@ -559,8 +559,8 @@ struct elf_resolve *_dl_load_elf_shared_library(int secure,
 		for (i = 0; i < epnt->e_phnum; i++, ppnt++) {
 			if (ppnt->p_type == PT_LOAD && !(ppnt->p_flags & PF_W))
 				_dl_mprotect((void *) ((piclib ? libaddr : 0) + 
-					    (ppnt->p_vaddr & 0xfffff000)), 
-					(ppnt->p_vaddr & 0xfff) + (unsigned long) ppnt->p_filesz, 
+					    (ppnt->p_vaddr & PAGE_ALIGN)), 
+					(ppnt->p_vaddr & ADDR_ALIGN) + (unsigned long) ppnt->p_filesz, 
 					PROT_READ | PROT_WRITE | PROT_EXEC);
 		}
 	}

+ 4 - 0
ldso/ldso/sparc/dl-sysdep.h

@@ -123,3 +123,7 @@ __asm__("mov %%g0,%%Y\n\t" \
 #define _dl_linux_resolve _elf_rtbndr
 #endif
 
+/* 4096 bytes alignment */
+#define PAGE_ALIGN 0xfffff000
+#define ADDR_ALIGN 0xfff
+#define OFFS_ALIGN 0x7ffff000

+ 4 - 0
ldso/ldso/sparc/ld_sysdep.h

@@ -123,3 +123,7 @@ __asm__("mov %%g0,%%Y\n\t" \
 #define _dl_linux_resolve _elf_rtbndr
 #endif
 
+/* 4096 bytes alignment */
+#define PAGE_ALIGN 0xfffff000
+#define ADDR_ALIGN 0xfff
+#define OFFS_ALIGN 0x7ffff000