00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00040 #define VHALLOC_PREGION_BASE 0xc00000000
00041 #define VHALLOC_PREGION_METADATA_SIZE (1024*1024)
00042 #define VHALLOC_PREGION_HOLE_SIZE 0
00043 #define VHALLOC_PREGION_HEAP_SIZE (1024*1024*1024)
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068 #include <mnemosyne.h>
00069 #include <stdint.h>
00070 #include <stdlib.h>
00071 #include <sys/mman.h>
00072 #include <pcm.h>
00073 #include "vistaheap.h"
00074 #include "genalloc.h"
00075 #include "vhalloc.h"
00076
00077
00078 __attribute__ ((section("PERSISTENT"))) int vhalloc_init_done = 0;
00079 __attribute__ ((section("PERSISTENT"))) uint64_t vhalloc_pregion = 0x0;
00080
00081 static int volatile_init_done = 0;
00082 static vistaheap *vistaheap_main;
00083 static vistaheap *vistaheap_nugget;
00084
00085 TM_PURE static inline
00086 void
00087 _init(void)
00088 {
00089 size_t size;
00090 void *metadata_base;
00091 void *metadata_hardlimit;
00092 void *heap_base;
00093 void *heap_hardlimit;
00094
00095 if (vhalloc_init_done) {
00096 if (!volatile_init_done) {
00097 vistaheap_main = (vistaheap *) vhalloc_pregion;
00098 vistaheap_nugget = (vistaheap *) (vhalloc_pregion + sizeof(vistaheap));
00099 volatile_init_done = 1;
00100 }
00101 return;
00102 }
00103
00104 if (vhalloc_pregion == 0x0) {
00105 size = sizeof(vistaheap) * 2 +
00106 VHALLOC_PREGION_METADATA_SIZE +
00107 VHALLOC_PREGION_HOLE_SIZE +
00108 VHALLOC_PREGION_HEAP_SIZE;
00109 TM_WAIVER {
00110 vhalloc_pregion = (uint64_t) m_pmap((void *) VHALLOC_PREGION_BASE, size, PROT_READ|PROT_WRITE, 0);
00111 }
00112 if ((void *) vhalloc_pregion == (void *) -1) {
00113 TM_WAIVER {
00114 abort();
00115 }
00116 }
00117 }
00118
00119 vistaheap_main = (vistaheap *) vhalloc_pregion;
00120 vistaheap_nugget = (vistaheap *) (vhalloc_pregion + sizeof(vistaheap));
00121 metadata_base = (void *) (vhalloc_pregion + sizeof(vistaheap)*2);
00122 metadata_hardlimit = (void *) (((uintptr_t) metadata_base) + VHALLOC_PREGION_METADATA_SIZE);
00123 heap_base = (void *) (((uintptr_t) metadata_hardlimit) + VHALLOC_PREGION_HOLE_SIZE);
00124 heap_hardlimit = (void *) (((uintptr_t) heap_base) + VHALLOC_PREGION_HEAP_SIZE);
00125
00126 __tm_atomic
00127 {
00128 vistaheap_init(vistaheap_nugget, metadata_base, metadata_hardlimit, NULL);
00129 vistaheap_init(vistaheap_main, heap_base, heap_hardlimit, vistaheap_nugget);
00130 vhalloc_init_done = 1;
00131 }
00132 volatile_init_done = 1;
00133 }
00134
00135 struct header_s {
00136 size_t sz;
00137 };
00138
00139
00140 size_t VHALLOC_OBJSIZE(void *ptr)
00141 {
00142 struct header_s* header_ptr;
00143 header_ptr = (struct header_s *) ((char *)ptr - sizeof(struct header_s));
00144 return header_ptr->sz;
00145 }
00146
00147
00148 void *
00149 VHALLOC_PMALLOC(size_t sz)
00150 {
00151 void *ptr;
00152 struct header_s* header_ptr;
00153 _init();
00154
00155 ptr = vistaheap_malloc(vistaheap_main, sz + sizeof(struct header_s));
00156 header_ptr = (struct header_s *) ptr;
00157 header_ptr->sz = sz;
00158 return (void *) ((char *) ptr + sizeof(struct header_s));
00159 }
00160
00161
00162 void
00163 vhalloc_pfree(void *ptr)
00164 {
00165
00166 }