|
@@ -0,0 +1,98 @@
|
|
|
+/*
|
|
|
+ * Copyright 2011 Institute of Communication and Computer Systems (ICCS)
|
|
|
+ *
|
|
|
+ * Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
+ * you may not use this file except in compliance with the License.
|
|
|
+ * You may obtain a copy of the License at
|
|
|
+ *
|
|
|
+ * http://www.apache.org/licenses/LICENSE-2.0
|
|
|
+ *
|
|
|
+ * Unless required by applicable law or agreed to in writing, software
|
|
|
+ * distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
+ * See the License for the specific language governing permissions and
|
|
|
+ * limitations under the License.
|
|
|
+ *
|
|
|
+ */
|
|
|
+
|
|
|
+/**
|
|
|
+ * \file single_allocator.c
|
|
|
+ * \author Ioannis Koutras (joko@microlab.ntua.gr)
|
|
|
+ * \date March, 2012
|
|
|
+ *
|
|
|
+ * \brief Implementations of malloc(), free() and realloc() calls while using
|
|
|
+ * just one allocator.
|
|
|
+ */
|
|
|
+
|
|
|
+#include <dmmlib/single_allocator.h>
|
|
|
+#include <dmmlib/initialize_allocator.h>
|
|
|
+#include "other.h"
|
|
|
+#include <dmmlib/dmmlib.h>
|
|
|
+
|
|
|
+void * malloc(size_t size) {
|
|
|
+ allocator_t *allocator;
|
|
|
+ heap_t *heap;
|
|
|
+ int heap_id;
|
|
|
+
|
|
|
+ allocator = &systemallocator;
|
|
|
+ /* Space aware allocators have to be already initialized, no need to do
|
|
|
+ * that here. */
|
|
|
+#ifndef NO_SYSTEM_CALLS
|
|
|
+ if(allocator->initialized != true) {
|
|
|
+ initialize_allocator(allocator);
|
|
|
+ }
|
|
|
+#endif /* NO_SYSTEM_CALLS */
|
|
|
+
|
|
|
+ /* FIXME Space aware allocators currently use one heap */
|
|
|
+#ifdef NO_SYSTEM_CALLS
|
|
|
+ heap_id = 0;
|
|
|
+#else /* NO_SYSTEM_CALLS */
|
|
|
+ heap_id = map_thread_heap();
|
|
|
+#endif /* NO_SYSTEM_CALLS */
|
|
|
+ heap = &allocator->heaps[heap_id];
|
|
|
+
|
|
|
+ return custom_ahmalloc(allocator, heap, size);
|
|
|
+}
|
|
|
+
|
|
|
+void free(void *ptr) {
|
|
|
+ allocator_t *allocator;
|
|
|
+ heap_t *heap;
|
|
|
+ int heap_id;
|
|
|
+
|
|
|
+ allocator = &systemallocator;
|
|
|
+
|
|
|
+ /* FIXME Space aware allocators currently use one heap */
|
|
|
+#ifdef NO_SYSTEM_CALLS
|
|
|
+ heap_id = 0;
|
|
|
+#else /* NO_SYSTEM_CALLS */
|
|
|
+ heap_id = map_thread_heap();
|
|
|
+#endif /* NO_SYSTEM_CALLS */
|
|
|
+ heap = &allocator->heaps[heap_id];
|
|
|
+
|
|
|
+ custom_ahfree(allocator, heap, ptr);
|
|
|
+}
|
|
|
+
|
|
|
+void * realloc(void *ptr, size_t size) {
|
|
|
+ allocator_t *allocator;
|
|
|
+ heap_t *heap;
|
|
|
+ int heap_id;
|
|
|
+
|
|
|
+ allocator = &systemallocator;
|
|
|
+ /* Space aware allocators have to be already initialized, no need to do
|
|
|
+ * that here. */
|
|
|
+#ifndef NO_SYSTEM_CALLS
|
|
|
+ if(allocator->initialized != true) {
|
|
|
+ initialize_allocator(allocator);
|
|
|
+ }
|
|
|
+#endif /* NO_SYSTEM_CALLS */
|
|
|
+
|
|
|
+ /* FIXME Space aware allocators currently use one heap */
|
|
|
+#ifdef NO_SYSTEM_CALLS
|
|
|
+ heap_id = 0;
|
|
|
+#else /* NO_SYSTEM_CALLS */
|
|
|
+ heap_id = map_thread_heap();
|
|
|
+#endif /* NO_SYSTEM_CALLS */
|
|
|
+ heap = &allocator->heaps[heap_id];
|
|
|
+
|
|
|
+ return custom_ahrealloc(allocator, heap, ptr, size);
|
|
|
+}
|