SCM Repository
Annotation of /sml/trunk/src/runtime/memory/mem-mach.c
Parent Directory
|
Revision Log
Revision 249 -
(view)
(download)
(as text)
Original Path: sml/branches/SMLNJ/src/runtime/memory/mem-mach.c
1 : | monnier | 249 | /* mem-mach.c |
2 : | * | ||
3 : | * COPYRIGHT (c) 1993 by AT&T Bell Laboratories. | ||
4 : | * | ||
5 : | * Memory sub-system for the MACH operating system. | ||
6 : | * | ||
7 : | * The following routines are exported: | ||
8 : | * void InitMemory (); | ||
9 : | * mem_obj_t *AllocMemObj (Word_t szb); | ||
10 : | * void FreeMemObj (mem_obj_t *obj); | ||
11 : | * | ||
12 : | */ | ||
13 : | |||
14 : | #include "ml-unixdep.h" | ||
15 : | #include <mach/mach_types.h> | ||
16 : | #include "ml-base.h" | ||
17 : | #include "memory.h" | ||
18 : | |||
19 : | #ifndef HAS_VM_ALLOCATE | ||
20 : | # error expected HAS_VM_ALLOCATE | ||
21 : | #endif | ||
22 : | |||
23 : | struct mem_obj { | ||
24 : | Word_t *base; /* the base address of the object. */ | ||
25 : | Word_t sizeB; /* the object's size (in bytes) */ | ||
26 : | Word_t *mapBase; /* base address of the mapped region containing */ | ||
27 : | /* the object */ | ||
28 : | Word_t mapSizeB; /* the size of the mapped region containing */ | ||
29 : | /* the object */ | ||
30 : | }; | ||
31 : | |||
32 : | #define ALLOC_MEMOBJ() NEW_OBJ(mem_obj_t) | ||
33 : | #define FREE_MEMOBJ(p) FREE(p) | ||
34 : | |||
35 : | #include "mem-common.ins" | ||
36 : | |||
37 : | /* MEM_InitMemory: | ||
38 : | */ | ||
39 : | void MEM_InitMemory () | ||
40 : | { | ||
41 : | InitMemory(); | ||
42 : | |||
43 : | } /* MEM_InitMemory */ | ||
44 : | |||
45 : | |||
46 : | /* MapMemory: | ||
47 : | * | ||
48 : | * Map a BIBOP_PAGE_SZB aligned chunk of szb bytes of virtual memory. Return | ||
49 : | * the address of the mapped memory (or NIL on failure). | ||
50 : | */ | ||
51 : | PVT status_t MapMemory (mem_obj_t *obj, Addr_t szb) | ||
52 : | { | ||
53 : | Addr_t addr, offset; | ||
54 : | kern_return_t sts; | ||
55 : | |||
56 : | sts = vm_allocate(task_self(), &addr, szb+BIBOP_PAGE_SZB, TRUE); | ||
57 : | |||
58 : | if (sts) { | ||
59 : | errno = sts; | ||
60 : | return FAILURE; | ||
61 : | } | ||
62 : | |||
63 : | /* insure BIBOP_PAGE_SZB alignment */ | ||
64 : | offset = BIBOP_PAGE_SZB - (addr & (BIBOP_PAGE_SZB-1)); | ||
65 : | if (offset != 0) { | ||
66 : | /* align addr and discard unused portions of memory */ | ||
67 : | vm_deallocate (task_self(), addr, offset); | ||
68 : | addr += offset; | ||
69 : | vm_deallocate (task_self(), addr+szb, BIBOP_PAGE_SZB-offset); | ||
70 : | } | ||
71 : | else { | ||
72 : | vm_deallocate (task_self(), addr+szb, BIBOP_PAGE_SZB); | ||
73 : | } | ||
74 : | |||
75 : | obj->base = (Word_t *)addr; | ||
76 : | obj->sizeB = szb; | ||
77 : | |||
78 : | return SUCCESS; | ||
79 : | |||
80 : | } /* end of MapMemory */ | ||
81 : | |||
82 : | /* UnmapMemory: | ||
83 : | * | ||
84 : | * Unmap a chunk of virtual memory at addr. | ||
85 : | */ | ||
86 : | PVT void UnmapMemory (mem_obj_t *obj) | ||
87 : | { | ||
88 : | kern_return_t sts; | ||
89 : | |||
90 : | sts = vm_deallocate ( | ||
91 : | task_self(), | ||
92 : | (vm_address_t)(obj->base), | ||
93 : | (vm_size_t)(obj->sizeB)); | ||
94 : | |||
95 : | if (sts != KERN_SUCCESS) { | ||
96 : | Die ("error unmapping [%#x, %#x), errno = %d\n", | ||
97 : | obj->mapBase, (Addr_t)(obj->mapBase) + obj->mapSizeB, errno); | ||
98 : | } | ||
99 : | |||
100 : | } /* end of UnmapMemory */ |
root@smlnj-gforge.cs.uchicago.edu | ViewVC Help |
Powered by ViewVC 1.0.0 |