Title: [8926] trunk/fs/binfmt_flat.c: [!no_src_qa!]
Revision
8926
Author
bhsong
Date
2010-06-18 04:33:22 -0400 (Fri, 18 Jun 2010)

Log Message

[!no_src_qa!]
[#6034], fix argv and envp pointer while using L1 stack

Modified Paths

Diff

Modified: trunk/fs/binfmt_flat.c (8925 => 8926)


--- trunk/fs/binfmt_flat.c	2010-06-18 08:30:08 UTC (rev 8925)
+++ trunk/fs/binfmt_flat.c	2010-06-18 08:33:22 UTC (rev 8926)
@@ -122,10 +122,16 @@
  * memory and creates the pointer tables from them, and puts their
  * addresses on the "stack", returning the new stack pointer value.
  */
-
+#ifndef CONFIG_APP_STACK_L1
 static unsigned long create_flat_tables(
 	unsigned long pp,
 	struct linux_binprm * bprm)
+#else
+static unsigned long create_flat_tables(
+	unsigned long pp,
+	struct linux_binprm * bprm,
+	unsigned long l1_ram_offset)
+#endif
 {
 	unsigned long *argv,*envp;
 	unsigned long * sp;
@@ -148,7 +154,11 @@
 	put_user(argc, sp);
 	current->mm->arg_start = (unsigned long) p;
 	while (argc-->0) {
+#ifndef CONFIG_APP_STACK_L1
 		put_user((unsigned long) p, argv++);
+#else
+		put_user((unsigned long) p + l1_ram_offset, argv++);
+#endif
 		do {
 			get_user(dummy, p); p++;
 		} while (dummy);
@@ -156,7 +166,11 @@
 	put_user((unsigned long) NULL, argv);
 	current->mm->arg_end = current->mm->env_start = (unsigned long) p;
 	while (envc-->0) {
-		put_user((unsigned long)p, envp); envp++;
+#ifndef CONFIG_APP_STACK_L1
+		put_user((unsigned long)p, envp++);
+#else
+		put_user((unsigned long)p + l1_ram_offset, envp++);
+#endif
 		do {
 			get_user(dummy, p); p++;
 		} while (dummy);
@@ -390,7 +404,7 @@
 #endif
 	flat_v2_reloc_t	r;
 	unsigned long *ptr;
-	
+
 	r.value = rl;
 #if defined(CONFIG_COLDFIRE)
 	ptr = (unsigned long *) (current->mm->start_code + r.reloc.offset);
@@ -403,7 +417,7 @@
 		"(address %p, currently %x) into segment %s\n",
 		r.reloc.offset, ptr, (int)*ptr, segment[r.reloc.type]);
 #endif
-	
+
 	switch (r.reloc.type) {
 	case OLD_FLAT_RELOC_TYPE_TEXT:
 		*ptr += current->mm->start_code;
@@ -422,7 +436,7 @@
 #ifdef DEBUG
 	printk("Relocation became %x\n", (int)*ptr);
 #endif
-}		
+}
 
 /****************************************************************************/
 
@@ -481,7 +495,7 @@
 		ret = -ENOEXEC;
 		goto err;
 	}
-	
+
 	/* Don't allow old format executables to use shared libraries */
 	if (rev == OLD_FLAT_VERSION && id != 0) {
 		printk("BINFMT_FLAT: shared libraries are not available before rev 0x%x\n",
@@ -587,7 +601,7 @@
 		fpos = ntohl(hdr->data_start);
 #ifdef CONFIG_BINFMT_ZFLAT
 		if (flags & FLAT_FLAG_GZDATA) {
-			result = decompress_exec(bprm, fpos, (char *) datapos, 
+			result = decompress_exec(bprm, fpos, (char *) datapos,
 						 data_len + (relocs * sizeof(unsigned long)), 0);
 		} else
 #endif
@@ -722,7 +736,7 @@
 	libinfo->lib_list[id].loaded = 1;
 	libinfo->lib_list[id].entry = (0x00ffffff & ntohl(hdr->entry)) + textpos;
 	libinfo->lib_list[id].build_date = ntohl(hdr->build_date);
-	
+
 	/*
 	 * We just load the allocations into some temporary memory to
 	 * help simplify all this mumbo jumbo
@@ -802,7 +816,7 @@
 		for (i=0; i < relocs; i++)
 			old_reloc(ntohl(reloc[i]));
 	}
-	
+
 	flush_icache_range(start_code, end_code);
 
 	if (flags & FLAT_FLAG_L1STK) {
@@ -826,7 +840,7 @@
 	}
 
 	/* zero the BSS,  BRK and stack areas */
-	memset((void*)(datapos + data_len), 0, bss_len + 
+	memset((void*)(datapos + data_len), 0, bss_len +
 			(memp + memp_size - stack_len -		/* end brk */
 			libinfo->lib_list[id].start_brk) +	/* start brk */
 			stack_len);
@@ -912,12 +926,12 @@
 	stack_len += (bprm->argc + 1) * sizeof(char *); /* the argv array */
 	stack_len += (bprm->envc + 1) * sizeof(char *); /* the envp array */
 	stack_len += FLAT_STACK_ALIGN - 1;  /* reserve for upcoming alignment */
-	
+
 	l1stack_base = 0;
 	res = load_flat_file(bprm, &libinfo, 0, &stack_len, &l1stack_base);
 	if (IS_ERR_VALUE(res))
 		return res;
-	
+
 	/* Update data segment pointers for all libraries */
 	for (i=0; i<MAX_SHARED_LIBS; i++)
 		if (libinfo.lib_list[i].loaded)
@@ -940,8 +954,16 @@
 		* (char *) --p =
 			((char *) page_address(bprm->page[i/PAGE_SIZE]))[i % PAGE_SIZE];
 
+#ifndef CONFIG_APP_STACK_L1
 	sp = (unsigned long *) create_flat_tables(p, bprm);
-	
+#else
+	if (l1stack_base)
+		sp = (unsigned long *) create_flat_tables(p, bprm, l1stack_base +
+				stack_len - ramstack_top);
+	else
+		sp = (unsigned long *) create_flat_tables(p, bprm, 0);
+#endif
+
 	/* Fake some return addresses to ensure the call chain will
 	 * initialise library in order for us.  We are required to call
 	 * lib 1 first, then 2, ... and finally the main program (id 0).
@@ -957,7 +979,7 @@
 		}
 	}
 #endif
-	
+
 	/* Stash our initial stack pointer into the mm structure */
 	current->mm->start_stack = (unsigned long )sp;
 
_______________________________________________
Linux-kernel-commits mailing list
[email protected]
https://blackfin.uclinux.org/mailman/listinfo/linux-kernel-commits

Reply via email to