ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/Unix/vm_alloc.h
Revision: 1.12
Committed: 2007-01-13T18:21:30Z (17 years, 10 months ago) by gbeauche
Content type: text/plain
Branch: MAIN
Changes since 1.11: +0 -1 lines
Log Message:
Remove the 33-bit addressing hack as it's overly complex for not much gain.
Rather, use an address override prefix (0x67) though Intel Core optimization
reference guide says to avoid LCP prefixes. In practise, impact on performance
is measurably marginal on e.g. Speedometer tests.

File Contents

# Content
1 /*
2 * vm_alloc.h - Wrapper to various virtual memory allocation schemes
3 * (supports mmap, vm_allocate or fallbacks to malloc)
4 *
5 * Basilisk II (C) 1997-2005 Christian Bauer
6 *
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 #ifndef VM_ALLOC_H
23 #define VM_ALLOC_H
24
25 #ifdef HAVE_UNISTD_H
26 #include <unistd.h>
27 #include <sys/types.h>
28 #endif
29 #ifdef HAVE_SYS_MMAN_H
30 #include <sys/mman.h>
31 #endif
32 #ifdef HAVE_MACH_VM
33 extern "C" {
34 #include <mach/mach.h>
35 }
36 #endif
37
38 /* Return value of `vm_acquire' in case of an error. */
39 #ifdef HAVE_MACH_VM
40 #define VM_MAP_FAILED ((void *)-1)
41 #else
42 #ifdef HAVE_MMAP_VM
43 #define VM_MAP_FAILED ((void *)-1)
44 #else
45 #define VM_MAP_FAILED 0
46 #endif
47 #endif
48
49 /* Mapping options. */
50 #define VM_MAP_SHARED 0x01
51 #define VM_MAP_PRIVATE 0x02
52 #define VM_MAP_FIXED 0x04
53 #define VM_MAP_32BIT 0x08
54
55 /* Default mapping options. */
56 #define VM_MAP_DEFAULT (VM_MAP_PRIVATE)
57
58 /* Protection bits. */
59 #ifdef HAVE_MACH_VM
60 #define VM_PAGE_NOACCESS VM_PROT_NONE
61 #define VM_PAGE_READ VM_PROT_READ
62 #define VM_PAGE_WRITE VM_PROT_WRITE
63 #define VM_PAGE_EXECUTE VM_PROT_EXECUTE
64 #else
65 #ifdef HAVE_MMAP_VM
66 #define VM_PAGE_NOACCESS PROT_NONE
67 #define VM_PAGE_READ PROT_READ
68 #define VM_PAGE_WRITE PROT_WRITE
69 #define VM_PAGE_EXECUTE PROT_EXEC
70 #else
71 #define VM_PAGE_NOACCESS 0x0
72 #define VM_PAGE_READ 0x1
73 #define VM_PAGE_WRITE 0x2
74 #define VM_PAGE_EXECUTE 0x4
75 #endif
76 #endif
77
78 /* Default protection bits. */
79 #define VM_PAGE_DEFAULT (VM_PAGE_READ | VM_PAGE_WRITE)
80
81 /* Initialize the VM system. Returns 0 if successful, -1 for errors. */
82
83 extern int vm_init(void);
84
85 /* Deallocate all internal data used to wrap virtual memory allocators. */
86
87 extern void vm_exit(void);
88
89 /* Allocate zero-filled memory of SIZE bytes. The mapping is private
90 and default protection bits are read / write. The return value
91 is the actual mapping address chosen or VM_MAP_FAILED for errors. */
92
93 extern void * vm_acquire(size_t size, int options = VM_MAP_DEFAULT);
94
95 /* Allocate zero-filled memory at exactly ADDR (which must be page-aligned).
96 Returns 0 if successful, -1 on errors. */
97
98 extern int vm_acquire_fixed(void * addr, size_t size, int options = VM_MAP_DEFAULT);
99
100 /* Deallocate any mapping for the region starting at ADDR and extending
101 LEN bytes. Returns 0 if successful, -1 on errors. */
102
103 extern int vm_release(void * addr, size_t size);
104
105 /* Change the memory protection of the region starting at ADDR and
106 extending LEN bytes to PROT. Returns 0 if successful, -1 for errors. */
107
108 extern int vm_protect(void * addr, size_t size, int prot);
109
110 /* Returns the size of a page. */
111
112 extern int vm_get_page_size(void);
113
114 #endif /* VM_ALLOC_H */