1 |
gbeauche |
1.1 |
/* |
2 |
|
|
* vm_alloc.h - Wrapper to various virtual memory allocation schemes |
3 |
|
|
* (supports mmap, vm_allocate or fallbacks to malloc) |
4 |
|
|
* |
5 |
cebix |
1.2 |
* Basilisk II (C) 1997-2002 Christian Bauer |
6 |
gbeauche |
1.1 |
* |
7 |
|
|
* This program is free software; you can redistribute it and/or modify |
8 |
|
|
* it under the terms of the GNU General Public License as published by |
9 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
10 |
|
|
* (at your option) any later version. |
11 |
|
|
* |
12 |
|
|
* This program is distributed in the hope that it will be useful, |
13 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
|
|
* GNU General Public License for more details. |
16 |
|
|
* |
17 |
|
|
* You should have received a copy of the GNU General Public License |
18 |
|
|
* along with this program; if not, write to the Free Software |
19 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
20 |
|
|
*/ |
21 |
|
|
|
22 |
|
|
// TODO: Win32 VM ? |
23 |
|
|
#ifndef VM_ALLOC_H |
24 |
|
|
#define VM_ALLOC_H |
25 |
|
|
|
26 |
|
|
#ifdef HAVE_UNISTD_H |
27 |
|
|
#include <unistd.h> |
28 |
|
|
#endif |
29 |
|
|
#ifdef HAVE_SYS_MMAN_H |
30 |
|
|
#include <sys/mman.h> |
31 |
|
|
#endif |
32 |
|
|
|
33 |
|
|
/* Return value of `vm_acquire' in case of an error. */ |
34 |
|
|
#ifdef HAVE_MACH_VM |
35 |
|
|
#define VM_MAP_FAILED ((void *)-1) |
36 |
|
|
#else |
37 |
|
|
#ifdef HAVE_MMAP_VM |
38 |
|
|
#define VM_MAP_FAILED ((void *)-1) |
39 |
|
|
#else |
40 |
|
|
#define VM_MAP_FAILED 0 |
41 |
|
|
#endif |
42 |
|
|
#endif |
43 |
|
|
|
44 |
|
|
/* Protection bits. */ |
45 |
|
|
#ifdef HAVE_MACH_VM |
46 |
|
|
#define VM_PAGE_NOACCESS VM_PROT_NONE |
47 |
|
|
#define VM_PAGE_READ VM_PROT_READ |
48 |
|
|
#define VM_PAGE_WRITE VM_PROT_WRITE |
49 |
|
|
#define VM_PAGE_EXECUTE VM_PROT_EXECUTE |
50 |
|
|
#else |
51 |
|
|
#ifdef HAVE_MMAP_VM |
52 |
|
|
#define VM_PAGE_NOACCESS PROT_NONE |
53 |
|
|
#define VM_PAGE_READ PROT_READ |
54 |
|
|
#define VM_PAGE_WRITE PROT_WRITE |
55 |
|
|
#define VM_PAGE_EXECUTE PROT_EXEC |
56 |
|
|
#else |
57 |
|
|
#define VM_PAGE_NOACCESS 0x0 |
58 |
|
|
#define VM_PAGE_READ 0x1 |
59 |
|
|
#define VM_PAGE_WRITE 0x2 |
60 |
|
|
#define VM_PAGE_EXECUTE 0x4 |
61 |
|
|
#endif |
62 |
|
|
#endif |
63 |
|
|
|
64 |
|
|
/* Default protection bits. */ |
65 |
|
|
#define VM_PAGE_DEFAULT (VM_PAGE_READ | VM_PAGE_WRITE) |
66 |
|
|
|
67 |
|
|
/* Initialize the VM system. Returns 0 if successful, -1 for errors. */ |
68 |
|
|
|
69 |
|
|
extern int vm_init(void); |
70 |
|
|
|
71 |
|
|
/* Deallocate all internal data used to wrap virtual memory allocators. */ |
72 |
|
|
|
73 |
|
|
extern void vm_exit(void); |
74 |
|
|
|
75 |
|
|
/* Allocate zero-filled memory of SIZE bytes. The mapping is private |
76 |
|
|
and default protection bits are read / write. The return value |
77 |
|
|
is the actual mapping address chosen or VM_MAP_FAILED for errors. */ |
78 |
|
|
|
79 |
|
|
extern void * vm_acquire(size_t size); |
80 |
|
|
|
81 |
|
|
/* Allocate zero-filled memory at exactly ADDR (which must be page-aligned). |
82 |
|
|
Returns 0 if successful, -1 on errors. */ |
83 |
|
|
|
84 |
|
|
extern int vm_acquire_fixed(void * addr, size_t size); |
85 |
|
|
|
86 |
|
|
/* Deallocate any mapping for the region starting at ADDR and extending |
87 |
|
|
LEN bytes. Returns 0 if successful, -1 on errors. */ |
88 |
|
|
|
89 |
|
|
extern int vm_release(void * addr, size_t size); |
90 |
|
|
|
91 |
|
|
/* Change the memory protection of the region starting at ADDR and |
92 |
|
|
extending LEN bytes to PROT. Returns 0 if successful, -1 for errors. */ |
93 |
|
|
|
94 |
|
|
extern int vm_protect(void * addr, size_t size, int prot); |
95 |
|
|
|
96 |
|
|
#endif /* VM_ALLOC_H */ |