2008-11-19 13:26:10 +01:00
|
|
|
/* Function prototypes. */
|
|
|
|
|
|
|
|
struct vmproc;
|
|
|
|
struct stat;
|
|
|
|
struct memory;
|
2010-01-14 16:24:16 +01:00
|
|
|
struct vir_region;
|
|
|
|
struct phys_region;
|
2008-11-19 13:26:10 +01:00
|
|
|
|
|
|
|
#include <minix/ipc.h>
|
|
|
|
#include <minix/endpoint.h>
|
|
|
|
#include <minix/safecopies.h>
|
2010-01-19 22:00:20 +01:00
|
|
|
#include <minix/vm.h>
|
2008-11-19 13:26:10 +01:00
|
|
|
#include <timers.h>
|
|
|
|
#include <stdio.h>
|
2010-05-05 13:35:04 +02:00
|
|
|
|
2012-10-31 19:24:14 +01:00
|
|
|
#include "pt.h"
|
2008-11-19 13:26:10 +01:00
|
|
|
#include "vm.h"
|
2010-10-15 11:10:14 +02:00
|
|
|
#include "yielded.h"
|
2008-11-19 13:26:10 +01:00
|
|
|
|
|
|
|
/* alloc.c */
|
2012-12-29 01:16:33 +01:00
|
|
|
void *reservedqueue_new(int, int, int, int);
|
|
|
|
int reservedqueue_alloc(void *, phys_bytes *, void **);
|
|
|
|
void reservedqueue_add(void *, void *, phys_bytes);
|
|
|
|
void alloc_cycle(void);
|
No more intel/minix segments.
This commit removes all traces of Minix segments (the text/data/stack
memory map abstraction in the kernel) and significance of Intel segments
(hardware segments like CS, DS that add offsets to all addressing before
page table translation). This ultimately simplifies the memory layout
and addressing and makes the same layout possible on non-Intel
architectures.
There are only two types of addresses in the world now: virtual
and physical; even the kernel and processes have the same virtual
address space. Kernel and user processes can be distinguished at a
glance as processes won't use 0xF0000000 and above.
No static pre-allocated memory sizes exist any more.
Changes to booting:
. The pre_init.c leaves the kernel and modules exactly as
they were left by the bootloader in physical memory
. The kernel starts running using physical addressing,
loaded at a fixed location given in its linker script by the
bootloader. All code and data in this phase are linked to
this fixed low location.
. It makes a bootstrap pagetable to map itself to a
fixed high location (also in linker script) and jumps to
the high address. All code and data then use this high addressing.
. All code/data symbols linked at the low addresses is prefixed by
an objcopy step with __k_unpaged_*, so that that code cannot
reference highly-linked symbols (which aren't valid yet) or vice
versa (symbols that aren't valid any more).
. The two addressing modes are separated in the linker script by
collecting the unpaged_*.o objects and linking them with low
addresses, and linking the rest high. Some objects are linked
twice, once low and once high.
. The bootstrap phase passes a lot of information (e.g. free memory
list, physical location of the modules, etc.) using the kinfo
struct.
. After this bootstrap the low-linked part is freed.
. The kernel maps in VM into the bootstrap page table so that VM can
begin executing. Its first job is to make page tables for all other
boot processes. So VM runs before RS, and RS gets a fully dynamic,
VM-managed address space. VM gets its privilege info from RS as usual
but that happens after RS starts running.
. Both the kernel loading VM and VM organizing boot processes happen
using the libexec logic. This removes the last reason for VM to
still know much about exec() and vm/exec.c is gone.
Further Implementation:
. All segments are based at 0 and have a 4 GB limit.
. The kernel is mapped in at the top of the virtual address
space so as not to constrain the user processes.
. Processes do not use segments from the LDT at all; there are
no segments in the LDT any more, so no LLDT is needed.
. The Minix segments T/D/S are gone and so none of the
user-space or in-kernel copy functions use them. The copy
functions use a process endpoint of NONE to realize it's
a physical address, virtual otherwise.
. The umap call only makes sense to translate a virtual address
to a physical address now.
. Segments-related calls like newmap and alloc_segments are gone.
. All segments-related translation in VM is gone (vir2map etc).
. Initialization in VM is simpler as no moving around is necessary.
. VM and all other boot processes can be linked wherever they wish
and will be mapped in at the right location by the kernel and VM
respectively.
Other changes:
. The multiboot code is less special: it does not use mb_print
for its diagnostics any more but uses printf() as normal, saving
the output into the diagnostics buffer, only printing to the
screen using the direct print functions if a panic() occurs.
. The multiboot code uses the flexible 'free memory map list'
style to receive the list of free memory if available.
. The kernel determines the memory layout of the processes to
a degree: it tells VM where the kernel starts and ends and
where the kernel wants the top of the process to be. VM then
uses this entire range, i.e. the stack is right at the top,
and mmap()ped bits of memory are placed below that downwards,
and the break grows upwards.
Other Consequences:
. Every process gets its own page table as address spaces
can't be separated any more by segments.
. As all segments are 0-based, there is no distinction between
virtual and linear addresses, nor between userspace and
kernel addresses.
. Less work is done when context switching, leading to a net
performance increase. (8% faster on my machine for 'make servers'.)
. The layout and configuration of the GDT makes sysenter and syscall
possible.
2012-05-07 16:03:35 +02:00
|
|
|
void mem_sanitycheck(char *file, int line);
|
2012-03-24 16:16:34 +01:00
|
|
|
phys_clicks alloc_mem(phys_clicks clicks, u32_t flags);
|
|
|
|
void memstats(int *nodes, int *pages, int *largest);
|
|
|
|
void printmemstats(void);
|
|
|
|
void usedpages_reset(void);
|
|
|
|
int usedpages_add_f(phys_bytes phys, phys_bytes len, char *file, int
|
|
|
|
line);
|
|
|
|
void free_mem(phys_clicks base, phys_clicks clicks);
|
2013-02-08 19:11:42 +01:00
|
|
|
void mem_add_total_pages(int pages);
|
2009-09-21 16:49:49 +02:00
|
|
|
#define usedpages_add(a, l) usedpages_add_f(a, l, __FILE__, __LINE__)
|
2008-11-19 13:26:10 +01:00
|
|
|
|
2012-03-24 16:16:34 +01:00
|
|
|
void mem_init(struct memory *chunks);
|
2008-11-19 13:26:10 +01:00
|
|
|
|
|
|
|
/* utility.c */
|
2012-03-24 16:16:34 +01:00
|
|
|
void get_mem_chunks(struct memory *mem_chunks);
|
|
|
|
int vm_isokendpt(endpoint_t ep, int *proc);
|
|
|
|
int get_stack_ptr(int proc_nr, vir_bytes *sp);
|
|
|
|
int do_info(message *);
|
|
|
|
int swap_proc_slot(struct vmproc *src_vmp, struct vmproc *dst_vmp);
|
|
|
|
int swap_proc_dyn_data(struct vmproc *src_vmp, struct vmproc *dst_vmp);
|
2008-11-19 13:26:10 +01:00
|
|
|
|
|
|
|
/* exit.c */
|
2012-03-24 16:16:34 +01:00
|
|
|
void clear_proc(struct vmproc *vmp);
|
|
|
|
int do_exit(message *msg);
|
|
|
|
int do_willexit(message *msg);
|
2012-06-06 00:50:13 +02:00
|
|
|
int do_procctl(message *msg);
|
2012-03-24 16:16:34 +01:00
|
|
|
void free_proc(struct vmproc *vmp);
|
2008-11-19 13:26:10 +01:00
|
|
|
|
|
|
|
/* fork.c */
|
2012-03-24 16:16:34 +01:00
|
|
|
int do_fork(message *msg);
|
2008-11-19 13:26:10 +01:00
|
|
|
|
|
|
|
/* break.c */
|
2012-03-24 16:16:34 +01:00
|
|
|
int do_brk(message *msg);
|
|
|
|
int real_brk(struct vmproc *vmp, vir_bytes v);
|
2008-11-19 13:26:10 +01:00
|
|
|
|
2010-01-14 16:24:16 +01:00
|
|
|
/* map_mem.c */
|
2012-03-24 16:16:34 +01:00
|
|
|
int map_memory(endpoint_t sour, endpoint_t dest, vir_bytes virt_s,
|
|
|
|
vir_bytes virt_d, vir_bytes length, int flag);
|
|
|
|
int unmap_memory(endpoint_t sour, endpoint_t dest, vir_bytes virt_s,
|
|
|
|
vir_bytes virt_d, vir_bytes length, int flag);
|
2010-01-14 16:24:16 +01:00
|
|
|
|
2008-11-19 13:26:10 +01:00
|
|
|
/* mmap.c */
|
2012-03-24 16:16:34 +01:00
|
|
|
int do_mmap(message *msg);
|
|
|
|
int do_munmap(message *msg);
|
|
|
|
int do_map_phys(message *msg);
|
|
|
|
int do_unmap_phys(message *msg);
|
|
|
|
int do_remap(message *m);
|
|
|
|
int do_get_phys(message *m);
|
|
|
|
int do_get_refcount(message *m);
|
2008-11-19 13:26:10 +01:00
|
|
|
|
|
|
|
/* pagefaults.c */
|
2012-03-24 16:16:34 +01:00
|
|
|
void do_pagefaults(message *m);
|
|
|
|
void do_memory(void);
|
|
|
|
char *pf_errstr(u32_t err);
|
|
|
|
int handle_memory(struct vmproc *vmp, vir_bytes mem, vir_bytes len, int
|
|
|
|
wrflag);
|
2008-11-19 13:26:10 +01:00
|
|
|
|
|
|
|
/* $(ARCH)/pagetable.c */
|
No more intel/minix segments.
This commit removes all traces of Minix segments (the text/data/stack
memory map abstraction in the kernel) and significance of Intel segments
(hardware segments like CS, DS that add offsets to all addressing before
page table translation). This ultimately simplifies the memory layout
and addressing and makes the same layout possible on non-Intel
architectures.
There are only two types of addresses in the world now: virtual
and physical; even the kernel and processes have the same virtual
address space. Kernel and user processes can be distinguished at a
glance as processes won't use 0xF0000000 and above.
No static pre-allocated memory sizes exist any more.
Changes to booting:
. The pre_init.c leaves the kernel and modules exactly as
they were left by the bootloader in physical memory
. The kernel starts running using physical addressing,
loaded at a fixed location given in its linker script by the
bootloader. All code and data in this phase are linked to
this fixed low location.
. It makes a bootstrap pagetable to map itself to a
fixed high location (also in linker script) and jumps to
the high address. All code and data then use this high addressing.
. All code/data symbols linked at the low addresses is prefixed by
an objcopy step with __k_unpaged_*, so that that code cannot
reference highly-linked symbols (which aren't valid yet) or vice
versa (symbols that aren't valid any more).
. The two addressing modes are separated in the linker script by
collecting the unpaged_*.o objects and linking them with low
addresses, and linking the rest high. Some objects are linked
twice, once low and once high.
. The bootstrap phase passes a lot of information (e.g. free memory
list, physical location of the modules, etc.) using the kinfo
struct.
. After this bootstrap the low-linked part is freed.
. The kernel maps in VM into the bootstrap page table so that VM can
begin executing. Its first job is to make page tables for all other
boot processes. So VM runs before RS, and RS gets a fully dynamic,
VM-managed address space. VM gets its privilege info from RS as usual
but that happens after RS starts running.
. Both the kernel loading VM and VM organizing boot processes happen
using the libexec logic. This removes the last reason for VM to
still know much about exec() and vm/exec.c is gone.
Further Implementation:
. All segments are based at 0 and have a 4 GB limit.
. The kernel is mapped in at the top of the virtual address
space so as not to constrain the user processes.
. Processes do not use segments from the LDT at all; there are
no segments in the LDT any more, so no LLDT is needed.
. The Minix segments T/D/S are gone and so none of the
user-space or in-kernel copy functions use them. The copy
functions use a process endpoint of NONE to realize it's
a physical address, virtual otherwise.
. The umap call only makes sense to translate a virtual address
to a physical address now.
. Segments-related calls like newmap and alloc_segments are gone.
. All segments-related translation in VM is gone (vir2map etc).
. Initialization in VM is simpler as no moving around is necessary.
. VM and all other boot processes can be linked wherever they wish
and will be mapped in at the right location by the kernel and VM
respectively.
Other changes:
. The multiboot code is less special: it does not use mb_print
for its diagnostics any more but uses printf() as normal, saving
the output into the diagnostics buffer, only printing to the
screen using the direct print functions if a panic() occurs.
. The multiboot code uses the flexible 'free memory map list'
style to receive the list of free memory if available.
. The kernel determines the memory layout of the processes to
a degree: it tells VM where the kernel starts and ends and
where the kernel wants the top of the process to be. VM then
uses this entire range, i.e. the stack is right at the top,
and mmap()ped bits of memory are placed below that downwards,
and the break grows upwards.
Other Consequences:
. Every process gets its own page table as address spaces
can't be separated any more by segments.
. As all segments are 0-based, there is no distinction between
virtual and linear addresses, nor between userspace and
kernel addresses.
. Less work is done when context switching, leading to a net
performance increase. (8% faster on my machine for 'make servers'.)
. The layout and configuration of the GDT makes sysenter and syscall
possible.
2012-05-07 16:03:35 +02:00
|
|
|
void pt_init();
|
2012-09-18 13:17:50 +02:00
|
|
|
void vm_freepages(vir_bytes vir, int pages);
|
2012-03-24 16:16:34 +01:00
|
|
|
void pt_init_mem(void);
|
|
|
|
void pt_check(struct vmproc *vmp);
|
|
|
|
int pt_new(pt_t *pt);
|
|
|
|
void pt_free(pt_t *pt);
|
|
|
|
int pt_map_in_range(struct vmproc *src_vmp, struct vmproc *dst_vmp,
|
|
|
|
vir_bytes start, vir_bytes end);
|
|
|
|
int pt_ptmap(struct vmproc *src_vmp, struct vmproc *dst_vmp);
|
|
|
|
int pt_ptalloc_in_range(pt_t *pt, vir_bytes start, vir_bytes end, u32_t
|
|
|
|
flags, int verify);
|
|
|
|
void pt_clearmapcache(void);
|
|
|
|
int pt_writemap(struct vmproc * vmp, pt_t *pt, vir_bytes v, phys_bytes
|
|
|
|
physaddr, size_t bytes, u32_t flags, u32_t writemapflags);
|
|
|
|
int pt_checkrange(pt_t *pt, vir_bytes v, size_t bytes, int write);
|
|
|
|
int pt_bind(pt_t *pt, struct vmproc *who);
|
2012-12-29 01:16:33 +01:00
|
|
|
void *vm_mappages(phys_bytes p, int pages);
|
2012-03-24 16:16:34 +01:00
|
|
|
void *vm_allocpage(phys_bytes *p, int cat);
|
2012-12-17 19:26:52 +01:00
|
|
|
void *vm_allocpages(phys_bytes *p, int cat, int pages);
|
2012-10-08 03:38:03 +02:00
|
|
|
void *vm_allocpagedir(phys_bytes *p);
|
2012-03-24 16:16:34 +01:00
|
|
|
int pt_mapkernel(pt_t *pt);
|
|
|
|
void vm_pagelock(void *vir, int lockflag);
|
|
|
|
int vm_addrok(void *vir, int write);
|
2012-09-18 22:19:22 +02:00
|
|
|
int get_vm_self_pages(void);
|
2009-09-21 16:49:49 +02:00
|
|
|
|
2008-11-19 13:26:10 +01:00
|
|
|
#if SANITYCHECKS
|
2012-03-24 16:16:34 +01:00
|
|
|
void pt_sanitycheck(pt_t *pt, char *file, int line);
|
2008-11-19 13:26:10 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* slaballoc.c */
|
2012-03-24 16:16:34 +01:00
|
|
|
void *slaballoc(int bytes);
|
|
|
|
void slabfree(void *mem, int bytes);
|
|
|
|
void slabstats(void);
|
|
|
|
void slab_sanitycheck(char *file, int line);
|
2008-11-19 13:26:10 +01:00
|
|
|
#define SLABALLOC(var) (var = slaballoc(sizeof(*var)))
|
2010-04-12 13:25:24 +02:00
|
|
|
#define SLABFREE(ptr) do { slabfree(ptr, sizeof(*(ptr))); (ptr) = NULL; } while(0)
|
2009-04-22 14:39:29 +02:00
|
|
|
#if SANITYCHECKS
|
2009-09-21 16:49:49 +02:00
|
|
|
|
2012-03-24 16:16:34 +01:00
|
|
|
void slabunlock(void *mem, int bytes);
|
|
|
|
void slablock(void *mem, int bytes);
|
|
|
|
int slabsane_f(char *file, int line, void *mem, int bytes);
|
2009-04-22 14:39:29 +02:00
|
|
|
#endif
|
2008-11-19 13:26:10 +01:00
|
|
|
|
|
|
|
/* region.c */
|
2012-03-24 16:16:34 +01:00
|
|
|
void map_region_init(void);
|
|
|
|
struct vir_region * map_page_region(struct vmproc *vmp, vir_bytes min,
|
2012-10-11 15:15:49 +02:00
|
|
|
vir_bytes max, vir_bytes length, u32_t flags, int mapflags,
|
|
|
|
mem_type_t *memtype);
|
2012-03-24 16:16:34 +01:00
|
|
|
struct vir_region * map_proc_kernel(struct vmproc *dst);
|
|
|
|
int map_region_extend(struct vmproc *vmp, struct vir_region *vr,
|
|
|
|
vir_bytes delta);
|
2012-04-07 01:19:28 +02:00
|
|
|
int map_region_extend_upto_v(struct vmproc *vmp, vir_bytes vir);
|
2012-03-24 16:16:34 +01:00
|
|
|
int map_unmap_region(struct vmproc *vmp, struct vir_region *vr,
|
2012-09-18 13:17:52 +02:00
|
|
|
vir_bytes offset, vir_bytes len);
|
2012-03-24 16:16:34 +01:00
|
|
|
int map_free_proc(struct vmproc *vmp);
|
|
|
|
int map_proc_copy(struct vmproc *dst, struct vmproc *src);
|
|
|
|
int map_proc_copy_from(struct vmproc *dst, struct vmproc *src, struct
|
|
|
|
vir_region *start_src_vr);
|
2012-09-18 13:17:52 +02:00
|
|
|
struct vir_region *map_lookup(struct vmproc *vmp, vir_bytes addr,
|
|
|
|
struct phys_region **pr);
|
2012-03-24 16:16:34 +01:00
|
|
|
int map_pf(struct vmproc *vmp, struct vir_region *region, vir_bytes
|
|
|
|
offset, int write);
|
|
|
|
int map_pin_memory(struct vmproc *vmp);
|
|
|
|
int map_handle_memory(struct vmproc *vmp, struct vir_region *region,
|
|
|
|
vir_bytes offset, vir_bytes len, int write);
|
|
|
|
void map_printmap(struct vmproc *vmp);
|
|
|
|
int map_writept(struct vmproc *vmp);
|
|
|
|
void printregionstats(struct vmproc *vmp);
|
|
|
|
void map_setparent(struct vmproc *vmp);
|
|
|
|
int yielded_block_cmp(struct block_id *, struct block_id *);
|
2012-10-11 15:15:49 +02:00
|
|
|
struct phys_region *map_clone_ph_block(struct vmproc *vmp,
|
2012-12-17 19:26:52 +01:00
|
|
|
struct vir_region *region, struct phys_region *ph);
|
2012-10-11 15:15:49 +02:00
|
|
|
u32_t vrallocflags(u32_t flags);
|
|
|
|
int map_free(struct vir_region *region);
|
2012-12-17 19:26:52 +01:00
|
|
|
struct phys_region *physblock_get(struct vir_region *region, vir_bytes offset);
|
|
|
|
void physblock_set(struct vir_region *region, vir_bytes offset,
|
|
|
|
struct phys_region *newphysr);
|
2012-03-24 16:16:34 +01:00
|
|
|
|
|
|
|
struct vir_region * map_region_lookup_tag(struct vmproc *vmp, u32_t
|
|
|
|
tag);
|
|
|
|
void map_region_set_tag(struct vir_region *vr, u32_t tag);
|
|
|
|
u32_t map_region_get_tag(struct vir_region *vr);
|
|
|
|
int map_get_phys(struct vmproc *vmp, vir_bytes addr, phys_bytes *r);
|
|
|
|
int map_get_ref(struct vmproc *vmp, vir_bytes addr, u8_t *cnt);
|
2012-10-11 15:15:49 +02:00
|
|
|
int physregions(struct vir_region *vr);
|
2012-03-24 16:16:34 +01:00
|
|
|
|
|
|
|
void get_stats_info(struct vm_stats_info *vsi);
|
|
|
|
void get_usage_info(struct vmproc *vmp, struct vm_usage_info *vui);
|
2012-09-18 22:19:22 +02:00
|
|
|
void get_usage_info_kernel(struct vm_usage_info *vui);
|
2012-03-24 16:16:34 +01:00
|
|
|
int get_region_info(struct vmproc *vmp, struct vm_region_info *vri, int
|
|
|
|
count, vir_bytes *nextp);
|
|
|
|
int copy_abs2region(phys_bytes abs, struct vir_region *destregion,
|
|
|
|
phys_bytes offset, phys_bytes len);
|
2008-11-19 13:26:10 +01:00
|
|
|
#if SANITYCHECKS
|
2012-03-24 16:16:34 +01:00
|
|
|
void map_sanitycheck(char *file, int line);
|
|
|
|
void blockstats(void);
|
2008-11-19 13:26:10 +01:00
|
|
|
#endif
|
2012-03-24 16:16:34 +01:00
|
|
|
int do_forgetblocks(message *m);
|
|
|
|
int do_forgetblock(message *m);
|
|
|
|
int do_yieldblockgetblock(message *m);
|
|
|
|
vir_bytes free_yielded(vir_bytes bytes);
|
2008-11-19 13:26:10 +01:00
|
|
|
|
2009-09-21 16:49:49 +02:00
|
|
|
/* rs.c */
|
2012-03-24 16:16:34 +01:00
|
|
|
int do_rs_set_priv(message *m);
|
|
|
|
int do_rs_update(message *m);
|
|
|
|
int do_rs_memctl(message *m);
|
2008-11-19 13:26:10 +01:00
|
|
|
|
2009-09-21 16:49:49 +02:00
|
|
|
/* queryexit.c */
|
2012-03-24 16:16:34 +01:00
|
|
|
int do_query_exit(message *m);
|
|
|
|
int do_watch_exit(message *m);
|
|
|
|
int do_notify_sig(message *m);
|
|
|
|
void init_query_exit(void);
|
2012-09-18 13:17:51 +02:00
|
|
|
|
|
|
|
/* pb.c */
|
|
|
|
struct phys_block *pb_new(phys_bytes phys);
|
2012-10-11 15:15:49 +02:00
|
|
|
void pb_free(struct phys_block *);
|
2012-09-18 13:17:51 +02:00
|
|
|
struct phys_region *pb_reference(struct phys_block *newpb,
|
|
|
|
vir_bytes offset, struct vir_region *region);
|
2012-09-18 13:17:52 +02:00
|
|
|
void pb_unreferenced(struct vir_region *region, struct phys_region *pr, int rm);
|
2012-10-11 15:15:49 +02:00
|
|
|
void pb_link(struct phys_region *newphysr, struct phys_block *newpb,
|
|
|
|
vir_bytes offset, struct vir_region *parent);
|
|
|
|
|
|
|
|
/* mem_directphys.c */
|
|
|
|
void phys_setphys(struct vir_region *vr, phys_bytes startaddr);
|
|
|
|
|
|
|
|
/* mem_shared.c */
|
|
|
|
void shared_setsource(struct vir_region *vr, endpoint_t ep, struct vir_region *src);
|