Skip to contentSkip to conversation

ia32 cleanup patch

Linux-ia64 David Mosberger 1 participant 1 message Sep 10, 2001 exec and binfmt

lore
Share & tools
lore
#0 lore raw

Here is a cleanup patch for the ia32 subsystem. Originally, the goal was to fix the problems that kept the ia32 subsystem from working when using an ia64 page size of 4KB, but I ended up cleaning up the ia32 mmap() and mprotect() in the end. The result is that 4KB page size should now work, plus realplayer seems to work fine now, too.

Don, could you take a look at it and perhaps run whatever ia32 test suite you have? If it looks good, I'd like to include these changes in the next ia64 patch.

	--david
arch/ia64/ia32/binfmt_elf32.c +23 -18
diff -urN lia64/arch/ia64/ia32/binfmt_elf32.c lia64-kdb/arch/ia64/ia32/binfmt_elf32.c
@@ -3,7 +3,7 @@
  *
  * Copyright (C) 1999 Arun Sharma <[email protected]>
  * Copyright (C) 2001 Hewlett-Packard Co
- * Copyright (C) 2001 David Mosberger-Tang <[email protected]>
+ *	David Mosberger-Tang <[email protected]>
  *
  * 06/16/00	A. Mallick	initialize csd/ssd/tssd/cflg for ia32_load_state
  * 04/13/01	D. Mosberger	dropped saving tssd in ar.k1---it's not needed
@@ -51,16 +51,13 @@
 /* Global descriptor table */
 unsigned long *ia32_gdt_table, *ia32_tss;
 
-struct page *
+static struct page *
 put_shared_page (struct task_struct * tsk, struct page *page, unsigned long address)
 {
 	pgd_t * pgd;
 	pmd_t * pmd;
 	pte_t * pte;
 
-	if (page_count(page) != 1)
-		printk("mem_map disagrees with %p at %08lx\n", (void *) page, address);
-
 	pgd = pgd_offset(tsk->mm, address);
 
 	spin_lock(&tsk->mm->page_table_lock);
@@ -96,6 +93,9 @@
 	 * Map GDT and TSS below 4GB, where the processor can find them.  We need to map
 	 * it with privilege level 3 because the IVE uses non-privileged accesses to these
 	 * tables.  IA-32 segmentation is used to protect against IA-32 accesses to them.
+	 *
+	 * Note: Since we don't have a vmarea for the GDT and TSS pages, we don't need
+	 *	 to worry about an exit()ing IA-32 task freeing these pages.
 	 */
 	put_shared_page(current, virt_to_page(ia32_gdt_table), IA32_GDT_OFFSET);
 	if (PAGE_SHIFT <= IA32_PAGE_SHIFT)
@@ -213,6 +213,7 @@
 	return 0;
 }
 
+#if 0
 static unsigned long
 ia32_mm_addr (unsigned long addr)
 {
@@ -224,34 +225,38 @@
 		return ELF_PAGESTART(addr);
 	return ELF_PAGEALIGN(addr);
 }
+#endif
 
 /*
- *  Normally we would do an `mmap' to map in the process's text section.
- *  This doesn't work with IA32 processes as the ELF file might specify
- *  a non page size aligned address.  Instead we will just allocate
- *  memory and read the data in from the file.  Slightly less efficient
- *  but it works.
+ * Normally we would do an `mmap' to map in the process's text section.  This doesn't work
+ * with IA32 processes as the ELF file might specify a non page size aligned address.
+ * Instead we will just allocate memory and read the data in from the file.  Slightly less
+ * efficient but it works.
  */
-extern long ia32_do_mmap (struct file *filep, unsigned int len, unsigned int prot,
-			  unsigned int flags, unsigned int fd, unsigned int offset);
-
 static unsigned long
 elf_map32 (struct file *filep, unsigned long addr, struct elf_phdr *eppnt, int prot, int type)
 {
 	unsigned long retval;
 
-	if (eppnt->p_memsz >= (1UL<<32) || addr > (1UL<<32) - eppnt->p_memsz)
-		return -EINVAL;
-
 	/*
-	 *  Make sure the elf interpreter doesn't get loaded at location 0
-	 *    so that NULL pointers correctly cause segfaults.
+	 * Make sure the elf interpreter doesn't get loaded at location 0 so that NULL
+	 * pointers correctly cause segfaults.
 	 */
 	if (addr = 0)
 		addr += PAGE_SIZE;
+
+#if 0
+	if (eppnt->p_memsz >= (1UL<<32) || addr > (1UL<<32) - eppnt->p_memsz)
+		return -EINVAL;
+
 	set_brk(ia32_mm_addr(addr), addr + eppnt->p_memsz);
 	memset((char *) addr + eppnt->p_filesz, 0, eppnt->p_memsz - eppnt->p_filesz);
 	kernel_read(filep, eppnt->p_offset, (char *) addr, eppnt->p_filesz);
 	retval = (unsigned long) addr;
+#else
+	retval = ia32_do_mmap(filep, (addr & IA32_PAGE_MASK),
+			      eppnt->p_filesz + (eppnt->p_vaddr & ~IA32_PAGE_MASK), prot, type,
+			      eppnt->p_offset - (eppnt->p_vaddr & ~IA32_PAGE_MASK));
+#endif
 	return retval;
 }
arch/ia64/ia32/ia32_entry.S +1 -1
diff -urN lia64/arch/ia64/ia32/ia32_entry.S lia64-kdb/arch/ia64/ia32/ia32_entry.S
@@ -85,7 +85,7 @@
 	st8.spill [r2]=r8			// store return value in slot for r8
 	br.call.sptk.few rp=invoke_syscall_trace // give parent a chance to catch return value
 .ret2:	alloc r2=ar.pfs,0,0,0,0			// drop the syscall argument frame
-	br.cond.sptk.many ia64_leave_kernel	// rp MUST be != ia64_leave_kernel!
+	br.cond.sptk.many ia64_leave_kernel
 END(ia32_trace_syscall)
 
 GLOBAL_ENTRY(sys32_vfork)
arch/ia64/ia32/sys_ia32.c +189 -86

363 lines not on this page · raw message

include/asm-ia64/ia32.h +3 -0
diff -urN lia64/include/asm-ia64/ia32.h lia64-kdb/include/asm-ia64/ia32.h
@@ -34,6 +34,8 @@
 
 #define IA32_PAGE_SHIFT		12	/* 4KB pages */
 #define IA32_PAGE_SIZE		(1ULL << IA32_PAGE_SHIFT)
+#define IA32_PAGE_MASK		(~(IA32_PAGE_SIZE - 1))
+#define IA32_PAGE_ALIGN(addr)	(((addr) + IA32_PAGE_SIZE - 1) & IA32_PAGE_MASK)
 #define IA32_CLOCKS_PER_SEC	100	/* Cast in stone for IA32 Linux */
 #define IA32_TICK(tick)		((unsigned long long)(tick) * IA32_CLOCKS_PER_SEC / CLOCKS_PER_SEC)
 
@@ -421,6 +423,7 @@
 extern void ia32_init_addr_space (struct pt_regs *regs);
 extern int ia32_setup_arg_pages (struct linux_binprm *bprm);
 extern int ia32_exception (struct pt_regs *regs, unsigned long isr);
+extern unsigned long ia32_do_mmap (struct file *, unsigned long, unsigned long, int, int, loff_t);
 
 #endif /* !CONFIG_IA32_SUPPORT */