On Sun, May 4, 2008 at 6:35 PM, Anant Narayanan <anant@xxxxxx> wrote: > Hi, > > While implementing a binary format loader for a foreign executable format, What foreign executable is that? As far as I can see, Linux kernel can handle the following types of foreign executable: ./fs/binfmt_elf.c: retval = setup_arg_pages(bprm, randomize_stack_top(STACK_TOP), ./fs/binfmt_elf_fdpic.c: retval = setup_arg_pages(bprm, current->mm->start_stack, ./fs/binfmt_som.c: setup_arg_pages(bprm, STACK_TOP, EXSTACK_DEFAULT); ./fs/binfmt_aout.c: retval = setup_arg_pages(bprm, STACK_TOP, EXSTACK_DEFAULT); ./arch/ia64/ia32/binfmt_elf32.c: ret = setup_arg_pages(bprm, IA32_STACK_TOP, executable_stack); ./arch/mips/kernel/irixelf.c: setup_arg_pages(bprm, STACK_TOP, EXSTACK_DEFAULT); ./arch/x86/ia32/ia32_aout.c: retval = setup_arg_pages(bprm, IA32_STACK_TOP, EXSTACK_DEFAULT); Possibly u can customized based on one of these pattern. > we have found the need to setup the user stack starting at (virtual) address > 0xE0000000 instead of the usual 0xC0000000. However a call to Possibly u can have small variations, which u can see via (which grep for all the stack space virtual address of all the processes): cat /proc/*/maps|grep stack: bfcc6000-bfcdb000 rw-p bffeb000 00:00 0 [stack] bf8f8000-bf90d000 rw-p bffeb000 00:00 0 [stack] bfed1000-bfee6000 rw-p bffeb000 00:00 0 [stack] bffa8000-bffbd000 rw-p bffeb000 00:00 0 [stack] bfa2d000-bfa42000 rw-p bffeb000 00:00 0 [stack] And the random address u see is in done when loading the elf (fs/binfmt_elf.c) load_elf_binary(): /* Do this so that we can load the interpreter, if need be. We will change some of these later */ current->mm->free_area_cache = current->mm->mmap_base; current->mm->cached_hole_size = 0; retval = setup_arg_pages(bprm, randomize_stack_top(STACK_TOP), executable_stack); if (retval < 0) { send_sig(SIGKILL, current, 0); goto out_free_dentry; } > setup_arg_pages() with that value returns -EINVAL. > > Is there any way to setup the stack such that it starts at 0xE0000000 and > grows downwards? > Yes, u can specify upward or downwards depending on architecture: Inside setup_arg_pages() (fs/exec.c): #ifdef CONFIG_STACK_GROWSUP stack_base = vma->vm_end + EXTRA_STACK_VM_PAGES * PAGE_SIZE; #else stack_base = vma->vm_start - EXTRA_STACK_VM_PAGES * PAGE_SIZE; #endif ret = expand_stack(vma, stack_base); Finally, is the big picture. In general, it is not EASY to change the memory layout for the different component like stack space etc, as it may affect other component (different standards are involved, and if they really overlapped, then kmapping mechanism is needed to share the memory - essentially playing around with the pagetable mechanism). Specifically, if u cat /proc/iomem: /proc>cat iomem 00000000-0009fbff : System RAM 0009fc00-0009ffff : reserved 000a0000-000bffff : Video RAM area 000c0000-000cc7ff : Video ROM 000f0000-000fffff : System ROM 00100000-7ff8ffff : System RAM 00400000-0063df98 : Kernel code 0063df99-00765adf : Kernel data 007ab000-0086297f : Kernel bss 7ff90000-7ff9dfff : ACPI Tables 7ff9e000-7ffdffff : ACPI Non-volatile Storage 7ffe0000-7fffffff : reserved 88000000-880000ff : 0000:00:1f.3 bfe00000-dfdfffff : PCI Bus 0000:01 c0000000-cfffffff : 0000:01:00.0 dfe00000-dfefffff : PCI Bus 0000:04 e0000000-efffffff : PCI MMCONFIG 0 e0000000-efffffff : pnp 00:0e f8700000-fe7fffff : PCI Bus 0000:01 fa000000-fbffffff : 0000:01:00.0 fd000000-fdffffff : 0000:01:00.0 And u can see that the 0xe000000 is occupied by someone else. Correct me if wrong....but nevertheless, u can still put the stack area there of course - using mmapping mechanism. What is this MMCONFIG area BTW? -- Regards, Peter Teoh -- To unsubscribe from this list: send an email with "unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx Please read the FAQ at http://kernelnewbies.org/FAQ