Commit 5c141032 authored by Léo Grange's avatar Léo Grange

add definition of mem_areas interface

parent 84461507
#ifndef _SYS_MEM_AREA_H
#define _SYS_MEM_AREA_H
#include <utils/types.h>
#include <utils/list.h>
* Generic memory-mapping interface, using segmentation-based mapping.
// generic flags :
// type of area
#define MEM_AREA_TYPE_FILE (1<<0)
#define MEM_AREA_TYPE_ANON (1<<1)
// some kind of area are allowed to grow
#define MEM_AREA_MAYGROW (1<<2)
// flag used if area grows bottom-up instead of top-down (which is the default)
#define MEM_AREA_GROW_UP (1<<3)
struct mem_area {
int flags;
// begin address of this area in process address space, and maximum size
void *address;
size_t max_size;
// type-specific data (determined by flags)
union {
struct {
// file structure of the file mapped to this area
struct file *f;
// origin's position in the file
size_t origin;
} file;
struct {
// current size (useful in case of growing areas)
size_t size;
} anon;
// device type?
struct list_head list;
struct process;
* Initialize memory area subsystem.
void mem_area_init();
* Return a newly allocated memory area, not initialized.
struct mem_area *mem_area_alloc();
* Look for the given address in given process address space, and return the
* corresponding memory area.
* NULL is returned if address don't belong to its address space.
struct mem_area *mem_area_find(struct process *proc, void *address);
* Insert a memory area inside the given process' address space.
* Return 0 if inserted successfully, negative value else (e.g. overlay on other
* areas).
int mem_area_insert(struct process *proc, struct mem_area *area);
* Copy a part of this area content to the given *physical* address.
* This function *DO NOT* deal with virtual addresses, and don't check for page
* boundaries. The caller should check if given address range still belong
* to the appropriate process, and is already "allocated" and usable!
* Offset is relative to the beginning of this area.
* Return non-zero in error case.
int mem_area_copy_raw(struct mem_area *area, size_t offset, void *dest, size_t size);
#endif //_SYS_MEM_AREA_H
......@@ -8,6 +8,7 @@
#include <utils/bitfield.h>
#include <interface/fixos/fcntl.h>
#include <interface/fixos/errno.h>
#include <sys/mem_areas.h>
#include <loader/elfloader/loader.h>
#include <fs/vfs_file.h>
......@@ -110,6 +111,8 @@ struct process *process_alloc() {
arch_adrsp_init(& proc->addr_space);
proc->dir_list = NULL;
sigemptyset(& proc->sig_blocked);
sigemptyset(& proc->sig_pending);
......@@ -66,6 +66,8 @@ struct process {
// virtual memory managing data :
struct addr_space addr_space;
struct page_dir *dir_list;
// address space areas (see sys/mem_area.h)
struct list_head mem_areas;
// files opened by process, index is file descriptor
struct file *files[PROCESS_MAX_FILE];
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment