summaryrefslogtreecommitdiff
path: root/src/kernel/mem/seg.h
blob: bec0d8c77b63da5c8ec3cc6fbb3cf37d26472cde (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#ifndef DEF_SEG_H
#define DEF_SEG_H

/*	Segments are pieces of usable memory in a process' address space.
	They have nothing to do with GDT segments, they are created over paging. */

#include "paging.h"

struct segment_map;
struct segment {
	private:
	// these functions must not be used directly by anyone
	virtual segment_map* i_map(page_directory* pagedir, size_t offset) = 0;
	virtual void i_unmap(segment_map*) = 0;

	public:
	int mappings;

	segment();
	virtual ~segment();

	virtual int handle_fault(segment_map* map, size_t addr, int write) = 0;	//0 if ok, 1 if segfault
	//parameter offset in seg_map doesn't need to be used
	segment_map *map(page_directory* pagedir, size_t offset);
	//	When unmapping a segment, the segment is deleted if it is not mapped anywhere anymore.
	void unmap(segment_map* map);
};

struct segment_map {
	segment* seg;
	page_directory* pagedir;
	size_t start, len;
	segment_map *next;
};

/// *************************************     SIMPLESEG stuff *****************

struct simpleseg : segment {
	int writable;
	size_t start, len;

	simpleseg(size_t start, size_t len, int writable);
	virtual ~simpleseg();

	virtual int handle_fault(segment_map* map, size_t addr, int write);	//0 if ok, 1 if segfault

	int resize(segment_map *map, size_t len);

	private:
	virtual segment_map* i_map(page_directory* pagedir, size_t offset);
	virtual void i_unmap(segment_map*);
};

#endif