From: Cristiano Giuffrida Date: Tue, 11 Mar 2014 23:02:34 +0000 (+0100) Subject: vm: Separate mmap regions. X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/zpipe.c?a=commitdiff_plain;h=refs%2Fchanges%2F90%2F3090%2F2;p=minix.git vm: Separate mmap regions. Add support for compact address layout. This feature can be enabled through the ac_layout=1 boot option. Change-Id: Ie20b808fce32b5c54d0a7e7210e0084a540e9613 --- diff --git a/minix/kernel/arch/earm/pre_init.c b/minix/kernel/arch/earm/pre_init.c index 9411c4216..e52efb91b 100644 --- a/minix/kernel/arch/earm/pre_init.c +++ b/minix/kernel/arch/earm/pre_init.c @@ -275,12 +275,12 @@ void get_parameters(kinfo_t *cbi, char *bootargs) mb_set_param(cbi->param_buf, BOARDVARNAME,(char *)get_board_name(machine.board_id) , cbi); - /* round user stack down to leave a gap to catch kernel + /* move user stack/data down to leave a gap to catch kernel * stack overflow; and to distinguish kernel and user addresses * at a glance (0xf.. vs 0xe..) */ - cbi->user_sp &= 0xF0000000; - cbi->user_end = cbi->user_sp; + cbi->user_sp = USR_STACKTOP; + cbi->user_end = USR_DATATOP; /* kernel bytes without bootstrap code/data that is currently * still needed but will be freed after bootstrapping. diff --git a/minix/kernel/arch/i386/pre_init.c b/minix/kernel/arch/i386/pre_init.c index 21822b526..f71739f7d 100644 --- a/minix/kernel/arch/i386/pre_init.c +++ b/minix/kernel/arch/i386/pre_init.c @@ -157,12 +157,12 @@ void get_parameters(u32_t ebx, kinfo_t *cbi) mb_set_param(cbi->param_buf, ARCHVARNAME, (char *)get_board_arch_name(BOARD_ID_INTEL), cbi); mb_set_param(cbi->param_buf, BOARDVARNAME,(char *)get_board_name(BOARD_ID_INTEL) , cbi); - /* round user stack down to leave a gap to catch kernel + /* move user stack/data down to leave a gap to catch kernel * stack overflow; and to distinguish kernel and user addresses * at a glance (0xf.. vs 0xe..) */ - cbi->user_sp &= 0xF0000000; - cbi->user_end = cbi->user_sp; + cbi->user_sp = USR_STACKTOP; + cbi->user_end = USR_DATATOP; /* kernel bytes without bootstrap code/data that is currently * still needed but will be freed after bootstrapping. diff --git a/minix/kernel/const.h b/minix/kernel/const.h index 7e7e3da9b..be16f21c0 100644 --- a/minix/kernel/const.h +++ b/minix/kernel/const.h @@ -30,4 +30,25 @@ /* for kputc() */ #define END_OF_KMESS 0 +/* User limits. */ +#ifndef USR_DATATOP +#ifndef _MINIX_MAGIC +#define USR_DATATOP 0xF0000000 +#else +#define USR_DATATOP 0xE0000000 /* TODO: is this necessary? */ +#endif +#endif + +#ifndef USR_STACKTOP +#define USR_STACKTOP USR_DATATOP +#endif + +#ifndef USR_DATATOP_COMPACT +#define USR_DATATOP_COMPACT USR_DATATOP +#endif + +#ifndef USR_STACKTOP_COMPACT +#define USR_STACKTOP_COMPACT 0x50000000 +#endif + #endif /* CONST_H */ diff --git a/minix/kernel/main.c b/minix/kernel/main.c index f351a06a2..b02b86d5b 100644 --- a/minix/kernel/main.c +++ b/minix/kernel/main.c @@ -426,6 +426,13 @@ void cstart() if(!value || system_hz < 2 || system_hz > 50000) /* sanity check */ system_hz = DEFAULT_HZ; + /* Get memory parameters. */ + value = env_get("ac_layout"); + if(value && atoi(value)) { + kinfo.user_sp = (vir_bytes) USR_STACKTOP_COMPACT; + kinfo.user_end = (vir_bytes) USR_DATATOP_COMPACT; + } + DEBUGEXTRA(("cstart\n")); /* Record miscellaneous information for user-space servers. */ diff --git a/minix/servers/vm/mmap.c b/minix/servers/vm/mmap.c index 9d146bf99..727914482 100644 --- a/minix/servers/vm/mmap.c +++ b/minix/servers/vm/mmap.c @@ -75,7 +75,7 @@ static struct vir_region *mmap_region(struct vmproc *vmp, vir_bytes addr, if (!vr) { /* No address given or address already in use. */ - vr = map_page_region(vmp, VM_PAGE_SIZE, VM_DATATOP, len, + vr = map_page_region(vmp, VM_MMAPBASE, VM_MMAPTOP, len, vrflags, mfflags, mt); } @@ -349,7 +349,7 @@ int do_map_phys(message *m) if(len % VM_PAGE_SIZE) len += VM_PAGE_SIZE - (len % VM_PAGE_SIZE); - if(!(vr = map_page_region(vmp, 0, VM_DATATOP, len, + if(!(vr = map_page_region(vmp, VM_MMAPBASE, VM_MMAPTOP, len, VR_DIRECT | VR_WRITABLE, 0, &mem_type_directphys))) { return ENOMEM; } @@ -419,8 +419,8 @@ int do_remap(message *m) vr = map_page_region(dvmp, da, 0, size, flags, 0, &mem_type_shared); else - vr = map_page_region(dvmp, 0, VM_DATATOP, size, flags, 0, - &mem_type_shared); + vr = map_page_region(dvmp, VM_MMAPBASE, VM_MMAPTOP, size, + flags, 0, &mem_type_shared); if(!vr) { printf("VM: re-map of shared area failed\n"); diff --git a/minix/servers/vm/vm.h b/minix/servers/vm/vm.h index 97bd5e3a5..3a6e56acc 100644 --- a/minix/servers/vm/vm.h +++ b/minix/servers/vm/vm.h @@ -62,8 +62,21 @@ #define NO_MEM ((phys_clicks) MAP_NONE) /* returned by alloc_mem() with mem is up */ /* And what is the highest addressable piece of memory? */ -#define VM_DATATOP kernel_boot_info.user_end -#define VM_STACKTOP kernel_boot_info.user_sp - +#define VM_DATATOP kernel_boot_info.user_end + +#define VM_STACKTOP kernel_boot_info.user_sp + +/* Live update will work only with magic instrumentation. Live update requires + * strict separation of regions within the process to succeed. Therefore, + * apply this strict separation only if magic instrumentation is used. + * Otherwise, do not place such limitations on processes. + */ +#ifdef _MINIX_MAGIC +#define VM_MMAPTOP (VM_STACKTOP-DEFAULT_STACK_LIMIT) +#define VM_MMAPBASE (VM_MMAPTOP/2) +#else +#define VM_MMAPTOP VM_DATATOP +#define VM_MMAPBASE VM_PAGE_SIZE #endif +#endif