/*
* Copyright (c) 2011, 2012, 2013 Richard Braun.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
*
* Virtual memory map management.
*/
#ifndef _VM_VM_MAP_H
#define _VM_VM_MAP_H
#include
#include
#include
#include
#include
#include
#include
#include
#include
/*
* Mapping flags.
*
* Unless otherwise mentioned, these can also be used as map entry flags.
*/
#define VM_MAP_NOMERGE 0x10000
#define VM_MAP_FIXED 0x20000 /* Not an entry flag */
/*
* Macro used to forge "packed" flags.
*/
#define VM_MAP_FLAGS(prot, maxprot, inherit, advice, mapflags) \
((prot) | ((maxprot) << 4) | ((inherit) << 8) | ((advice) << 12) \
| (mapflags))
/*
* Flags usable as map entry flags.
*
* Map entry flags also use the packed format.
*/
#define VM_MAP_ENTRY_MASK (VM_MAP_NOMERGE | 0xffff)
/*
* Macros used to extract specific properties out of packed flags.
*/
#define VM_MAP_PROT(flags) ((flags) & 0xf)
#define VM_MAP_MAXPROT(flags) (((flags) & 0xf0) >> 4)
#define VM_MAP_INHERIT(flags) (((flags) & 0xf00) >> 8)
#define VM_MAP_ADVICE(flags) (((flags) & 0xf000) >> 12)
/*
* Memory range descriptor.
*/
struct vm_map_entry {
struct list list_node;
struct rbtree_node tree_node;
unsigned long start;
unsigned long end;
struct vm_object *object;
uint64_t offset;
int flags;
};
/*
* Memory map.
*/
struct vm_map {
struct mutex lock;
struct list entry_list;
struct rbtree entry_tree;
unsigned int nr_entries;
unsigned long start;
unsigned long end;
size_t size;
struct vm_map_entry *lookup_cache;
unsigned long find_cache;
size_t find_cache_threshold;
struct pmap *pmap;
};
/*
* Create a virtual mapping.
*/
int vm_map_enter(struct vm_map *map, struct vm_object *object, uint64_t offset,
unsigned long *startp, size_t size, size_t align, int flags);
/*
* Remove mappings from start to end.
*/
void vm_map_remove(struct vm_map *map, unsigned long start, unsigned long end);
/*
* Page fault handling.
*
* Access is one of VM_PROT_READ, VM_PROT_WRITE or VM_PROT_EXECUTE.
*/
int vm_map_fault(struct vm_map *map, unsigned long addr, int access);
/*
* Set up the vm_map module.
*/
void vm_map_setup(void);
/*
* Create a VM map.
*/
int vm_map_create(struct vm_map **mapp);
/*
* Display information about a memory map.
*/
void vm_map_info(struct vm_map *map);
#endif /* _VM_VM_MAP_H */