summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Johns <chrisj@rtems.org>2012-05-08 08:47:31 +1000
committerChris Johns <chrisj@rtems.org>2012-05-08 08:47:31 +1000
commitb78c02ab55ae3c0a932901896051617e1a212952 (patch)
treed8ce5cd954bc7d6a830d49f4e6abc210c77fefab
parent7f7cdc2de97f006def935f3b2788a24dd25248eb (diff)
Add RTL allocator.
Add a custom allocator that can be hooked. The default heap allocator in this code does nothing more than wrap the libc heap allocator. Fix up the RTL initialise to better handle the locking and initialisation of internal structures.
-rw-r--r--rtl-alloc-heap.c30
-rw-r--r--rtl-alloc-heap.h47
-rw-r--r--rtl-allocator.c79
-rw-r--r--rtl-allocator.h88
-rw-r--r--rtl-obj-cache.c5
-rw-r--r--rtl-obj.c38
-rw-r--r--rtl-string.c32
-rw-r--r--rtl-string.h35
-rw-r--r--rtl-sym.c4
-rw-r--r--rtl-trace.h1
-rw-r--r--rtl.c66
-rw-r--r--rtl.h3
-rw-r--r--wscript3
13 files changed, 390 insertions, 41 deletions
diff --git a/rtl-alloc-heap.c b/rtl-alloc-heap.c
new file mode 100644
index 0000000..1f3c8dd
--- /dev/null
+++ b/rtl-alloc-heap.c
@@ -0,0 +1,30 @@
+/*
+ * COPYRIGHT (c) 2012 Chris Johns <chrisj@rtems.org>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.org/license/LICENSE.
+ */
+/**
+ * @file
+ *
+ * @ingroup rtems_rtl
+ *
+ * @brief RTEMS Run-Time Linker Allocator for the standard heap.
+ */
+
+#include <stdlib.h>
+
+#include "rtl-alloc-heap.h"
+
+void
+rtems_rtl_alloc_heap (bool allocate,
+ rtems_rtl_alloc_tag_t tag,
+ void** address,
+ size_t size)
+{
+ if (allocate)
+ *address = malloc (size);
+ else
+ free (*address);
+}
diff --git a/rtl-alloc-heap.h b/rtl-alloc-heap.h
new file mode 100644
index 0000000..b31a3db
--- /dev/null
+++ b/rtl-alloc-heap.h
@@ -0,0 +1,47 @@
+/*
+ * COPYRIGHT (c) 2012 Chris Johns <chrisj@rtems.org>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.org/license/LICENSE.
+ */
+/**
+ * @file
+ *
+ * @ingroup rtems_rtl
+ *
+ * @brief RTEMS Run-Time Linker Allocator for the standard heap.
+ */
+
+#if !defined (_RTEMS_RTL_ALLOC_HEAP_H_)
+#define _RTEMS_RTL_ALLOC_HEAP_H_
+
+#include <rtl-allocator.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/**
+ * Allocator handler for the standard libc heap.
+ *
+ * @param allocation If true the request is to allocate memory else free.
+ * @param tag The type of allocation request.
+ * @param address Pointer to the memory address. If an allocation the value is
+ * unspecific on entry and the allocated address or NULL on
+ * exit. The NULL value means the allocation failed. If a delete
+ * or free request the memory address is the block to free. A
+ * free request of NULL is silently ignored.
+ * @param size The size of the allocation if an allocation request and
+ * not used if deleting or freeing a previous allocation.
+ */
+void rtems_rtl_alloc_heap(bool allocate,
+ rtems_rtl_alloc_tag_t tag,
+ void** address,
+ size_t size);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif
diff --git a/rtl-allocator.c b/rtl-allocator.c
new file mode 100644
index 0000000..93235db
--- /dev/null
+++ b/rtl-allocator.c
@@ -0,0 +1,79 @@
+/*
+ * COPYRIGHT (c) 2012 Chris Johns <chrisj@rtems.org>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.org/license/LICENSE.
+ */
+/**
+ * @file
+ *
+ * @ingroup rtems_rtl
+ *
+ * @brief RTEMS Run-Time Linker Allocator
+ */
+
+#include <stdio.h>
+
+#include <rtl.h>
+#include <rtl-trace.h>
+
+/**
+ * Tags as symbols for tracing.
+ */
+#if RTEMS_RTL_TRACE
+static const char* tag_labels[4] =
+{
+ "SYMBOL",
+ "STRING",
+ "OBJECT",
+ "MODULE"
+};
+#define rtems_rtl_trace_tag_label(_l) tag_labels[_l]
+#else
+#define rtems_rtl_trace_tag_label(_l) ""
+#endif
+
+void*
+rtems_rtl_alloc_new(rtems_rtl_alloc_tag_t tag, size_t size)
+{
+ rtems_rtl_data_t* rtl = rtems_rtl_lock ();
+ void* address = NULL;
+
+ if (rtl)
+ rtl->allocator (true, tag, &address, size);
+
+ if (rtems_rtl_trace (RTEMS_RTL_TRACE_ALLOCATOR))
+ printf ("alloc: new: %s addr=%p size=%zu\n",
+ rtems_rtl_trace_tag_label (tag), address, size);
+
+ rtems_rtl_unlock ();
+
+ return address;
+}
+
+void
+rtems_rtl_alloc_del(rtems_rtl_alloc_tag_t tag, void* address)
+{
+ rtems_rtl_data_t* rtl = rtems_rtl_lock ();
+
+ if (rtems_rtl_trace (RTEMS_RTL_TRACE_ALLOCATOR))
+ printf ("alloc: del: %s addr=%p\n",
+ rtems_rtl_trace_tag_label (tag), address);
+
+ if (rtl)
+ rtl->allocator (false, tag, &address, 0);
+
+ rtems_rtl_unlock ();
+}
+
+rtems_rtl_allocator_t
+rtems_rtl_alloc_hook(rtems_rtl_allocator_t handler)
+{
+ rtems_rtl_data_t* rtl = rtems_rtl_lock ();
+ rtems_rtl_allocator_t previous = rtl->allocator;
+ rtl->allocator = handler;
+ rtems_rtl_unlock ();
+ return previous;
+}
+
diff --git a/rtl-allocator.h b/rtl-allocator.h
new file mode 100644
index 0000000..6f1e9bb
--- /dev/null
+++ b/rtl-allocator.h
@@ -0,0 +1,88 @@
+/*
+ * COPYRIGHT (c) 2012 Chris Johns <chrisj@rtems.org>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.org/license/LICENSE.
+ */
+/**
+ * @file
+ *
+ * @ingroup rtems_rtl
+ *
+ * @brief RTEMS Run-Time Linker Allocator
+ */
+
+#if !defined (_RTEMS_RTL_ALLOCATOR_H_)
+#define _RTEMS_RTL_ALLOCATOR_H_
+
+#include <stdbool.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/**
+ * Define the types of allocation the loader requires.
+ */
+enum rtems_rtl_alloc_tags_e {
+ RTEMS_RTL_ALLOC_SYMBOL, /**< A symbol in the symbol table. */
+ RTEMS_RTL_ALLOC_STRING, /**< A runtime loader string. */
+ RTEMS_RTL_ALLOC_OBJECT, /**< An RTL object. */
+ RTEMS_RTL_ALLOC_MODULE /**< The module's code, data and bss memory. */
+};
+
+typedef enum rtems_rtl_alloc_tags_e rtems_rtl_alloc_tag_t;
+
+/**
+ * Allocator handler handles all RTL allocations. It can be hooked and
+ * overridded for customised allocation schemes or memory maps.
+ *
+ * @param allocation If true the request is to allocate memory else free.
+ * @param tag The type of allocation request.
+ * @param address Pointer to the memory address. If an allocation the value is
+ * unspecific on entry and the allocated address or NULL on
+ * exit. The NULL value means the allocation failed. If a delete
+ * or free request the memory address is the block to free. A
+ * free request of NULL is silently ignored.
+ * @param size The size of the allocation if an allocation request and
+ * not used if deleting or freeing a previous allocation.
+ */
+typedef void (*rtems_rtl_allocator_t)(bool allocate,
+ rtems_rtl_alloc_tag_t tag,
+ void** address,
+ size_t size);
+
+/**
+ * The Runtime Loader allocator new allocates new memory.
+ *
+ * @param tag The type of allocation request.
+ * @param size The size of the allocation.
+ * @return void* The memory address or NULL is not memory available.
+ */
+void* rtems_rtl_alloc_new(rtems_rtl_alloc_tag_t tag, size_t size);
+
+/**
+ * The Runtime Loader allocator delete deletes allocated memory.
+ *
+ * @param tag The type of allocation request.
+ * @param address The memory address to delete. A NULL is ignored.
+ */
+void rtems_rtl_alloc_del(rtems_rtl_alloc_tag_t tag, void* address);
+
+/**
+ * Hook the Runtime Loader allocatior. A handler can call the previous handler
+ * in the chain to use it for specific tags. The default handler uses the
+ * system heap. Do not unhook your handler if memory it allocates has not been
+ * returned.
+ *
+ * @param handler The handler to use as the allocator.
+ * @return rtems_rtl_alloc_handler_t The previous handler.
+ */
+rtems_rtl_allocator_t rtems_rtl_alloc_hook(rtems_rtl_allocator_t handler);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif
diff --git a/rtl-obj-cache.c b/rtl-obj-cache.c
index f46592f..6e071c5 100644
--- a/rtl-obj-cache.c
+++ b/rtl-obj-cache.c
@@ -22,6 +22,7 @@
#include <string.h>
#include <unistd.h>
+#include <rtl-allocator.h>
#include <rtl-obj-cache.h>
#include <rtl-error.h>
@@ -32,7 +33,7 @@ rtems_rtl_obj_cache_open (rtems_rtl_obj_cache_t* cache, size_t size)
cache->offset = 0;
cache->size = size;
cache->level = 0;
- cache->buffer = malloc (size);
+ cache->buffer = rtems_rtl_alloc_new (RTEMS_RTL_ALLOC_OBJECT, size);
if (!cache->buffer)
{
rtems_rtl_set_error (ENOMEM, "no memory for cache buffer");
@@ -44,7 +45,7 @@ rtems_rtl_obj_cache_open (rtems_rtl_obj_cache_t* cache, size_t size)
void
rtems_rtl_obj_cache_close (rtems_rtl_obj_cache_t* cache)
{
- free (cache->buffer);
+ rtems_rtl_alloc_del (RTEMS_RTL_ALLOC_OBJECT, cache->buffer);
cache->fd = -1;
cache->level = 0;
}
diff --git a/rtl-obj.c b/rtl-obj.c
index cd710b9..0274977 100644
--- a/rtl-obj.c
+++ b/rtl-obj.c
@@ -30,12 +30,14 @@
#include <rtl-chain-iterator.h>
#include <rtl-obj.h>
#include "rtl-error.h"
+#include "rtl-string.h"
#include "rtl-trace.h"
rtems_rtl_obj_t*
rtems_rtl_obj_alloc (void)
{
- rtems_rtl_obj_t* obj = malloc (sizeof (rtems_rtl_obj_t));
+ rtems_rtl_obj_t* obj = rtems_rtl_alloc_new (RTEMS_RTL_ALLOC_OBJECT,
+ sizeof (rtems_rtl_obj_t));
if (obj)
{
/*
@@ -54,10 +56,10 @@ rtems_rtl_obj_alloc (void)
static void
rtems_rtl_obj_free_names (rtems_rtl_obj_t* obj)
{
- free ((void*) obj->oname);
- free ((void*) obj->aname);
+ rtems_rtl_alloc_del (RTEMS_RTL_ALLOC_STRING, (void*) obj->oname);
+ rtems_rtl_alloc_del (RTEMS_RTL_ALLOC_STRING, (void*) obj->aname);
if ((obj->fname != obj->aname) && (obj->fname != obj->oname))
- free ((void*) obj->fname);
+ rtems_rtl_alloc_del (RTEMS_RTL_ALLOC_STRING, (void*) obj->fname);
}
bool
@@ -71,10 +73,9 @@ rtems_rtl_obj_free (rtems_rtl_obj_t* obj)
if (!rtems_chain_is_node_off_chain (&obj->link))
rtems_chain_extract (&obj->link);
rtems_rtl_obj_symbol_erase (obj);
- if (obj->text_base)
- free (obj->text_base);
+ rtems_rtl_alloc_del (RTEMS_RTL_ALLOC_MODULE, obj->text_base);
rtems_rtl_obj_free_names (obj);
- free (obj);
+ rtems_rtl_alloc_del (RTEMS_RTL_ALLOC_OBJECT, obj);
return true;
}
@@ -105,7 +106,7 @@ rtems_rtl_obj_parse_name (rtems_rtl_obj_t* obj, const char* name)
aname = NULL;
- oname = malloc (p - name + 1);
+ oname = rtems_rtl_alloc_new (RTEMS_RTL_ALLOC_STRING, p - name + 1);
if (oname == NULL)
{
rtems_rtl_set_error (ENOMEM, "no memory for object file name");
@@ -135,10 +136,10 @@ rtems_rtl_obj_parse_name (rtems_rtl_obj_t* obj, const char* name)
if (o == NULL)
o = e;
- oname = malloc (o - p + 1);
+ oname = rtems_rtl_alloc_new (RTEMS_RTL_ALLOC_STRING, o - p + 1);
if (oname == NULL)
{
- free (aname);
+ rtems_rtl_alloc_del (RTEMS_RTL_ALLOC_STRING, aname);
rtems_rtl_set_error (ENOMEM, "no memory for object file name");
return false;
}
@@ -368,7 +369,7 @@ rtems_rtl_obj_find_file (rtems_rtl_obj_t* obj, const char* name)
/*
* Allocate the path fragment, separator, name, terminating nul.
*/
- p = malloc ((d - s) + 1 + l + 1);
+ p = rtems_rtl_alloc_new (RTEMS_RTL_ALLOC_STRING, (d - s) + 1 + l + 1);
if (p == NULL)
{
rtems_rtl_set_error (ENOMEM, "no memory searching for object file");
@@ -382,7 +383,7 @@ rtems_rtl_obj_find_file (rtems_rtl_obj_t* obj, const char* name)
p[(d - s) + 1 + l] = '\0';
if (stat (p, &sb) < 0)
- free (p);
+ rtems_rtl_alloc_del (RTEMS_RTL_ALLOC_STRING, p);
else
{
/*
@@ -416,14 +417,15 @@ rtems_rtl_obj_add_section (rtems_rtl_obj_t* obj,
int info,
uint32_t flags)
{
- rtems_rtl_obj_sect_t* sect = malloc (sizeof (rtems_rtl_obj_sect_t));
+ rtems_rtl_obj_sect_t* sect = rtems_rtl_alloc_new (RTEMS_RTL_ALLOC_OBJECT,
+ sizeof (rtems_rtl_obj_sect_t));
if (!sect)
{
rtems_rtl_set_error (ENOMEM, "adding allocated section");
return false;
}
sect->section = section;
- sect->name = strdup (name);
+ sect->name = rtems_rtl_strdup (name);
sect->size = size;
sect->offset = offset;
sect->alignment = alignment;
@@ -448,8 +450,8 @@ rtems_rtl_obj_erase_sections (rtems_rtl_obj_t* obj)
rtems_rtl_obj_sect_t* sect = (rtems_rtl_obj_sect_t*) node;
rtems_chain_node* next_node = rtems_chain_next (node);
rtems_chain_extract (node);
- free ((void*) sect->name);
- free (node);
+ rtems_rtl_alloc_del (RTEMS_RTL_ALLOC_STRING, (void*) sect->name);
+ rtems_rtl_alloc_del (RTEMS_RTL_ALLOC_OBJECT, node);
node = next_node;
}
}
@@ -670,7 +672,7 @@ rtems_rtl_obj_load_sections (rtems_rtl_obj_t* obj, int fd)
* so the heap does not become fragmented.
*/
obj->exec_size = text_size + const_size + data_size + bss_size;
- obj->text_base = malloc (obj->exec_size);
+ obj->text_base = rtems_rtl_alloc_new (RTEMS_RTL_ALLOC_OBJECT, obj->exec_size);
if (!obj->text_base)
{
obj->exec_size = 0;
@@ -707,7 +709,7 @@ rtems_rtl_obj_load_sections (rtems_rtl_obj_t* obj, int fd)
!rtems_rtl_obj_sections_loader (&obj->sections, RTEMS_RTL_OBJ_SECT_BSS,
fd, obj->ooffset, obj->bss_base))
{
- free (obj->text_base);
+ rtems_rtl_alloc_del (RTEMS_RTL_ALLOC_MODULE, obj->text_base);
obj->exec_size = 0;
obj->text_base = 0;
obj->data_base = 0;
diff --git a/rtl-string.c b/rtl-string.c
new file mode 100644
index 0000000..cba7616
--- /dev/null
+++ b/rtl-string.c
@@ -0,0 +1,32 @@
+/*
+ * COPYRIGHT (c) 2012 Chris Johns <chrisj@rtems.org>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.org/license/LICENSE.
+ */
+/**
+ * @file
+ *
+ * @ingroup rtems_rtl
+ *
+ * @brief RTEMS Run-Time Linker String managment.
+ */
+
+#include <string.h>
+
+#include "rtl-allocator.h"
+#include "rtl-string.h"
+
+char*
+rtems_rtl_strdup (const char *s1)
+{
+ size_t len = strlen (s1);
+ char* s2 = rtems_rtl_alloc_new (RTEMS_RTL_ALLOC_STRING, len + 1);
+ if (s2)
+ {
+ memcpy (s2, s1, len);
+ s2[len] = '\0';
+ }
+ return s2;
+}
diff --git a/rtl-string.h b/rtl-string.h
new file mode 100644
index 0000000..00d2c9c
--- /dev/null
+++ b/rtl-string.h
@@ -0,0 +1,35 @@
+/*
+ * COPYRIGHT (c) 2012 Chris Johns <chrisj@rtems.org>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.org/license/LICENSE.
+ */
+/**
+ * @file
+ *
+ * @ingroup rtems_rtl
+ *
+ * @brief RTEMS Run-Time Linker String managment.
+ */
+
+#if !defined (_RTEMS_RTL_STRING_H_)
+#define _RTEMS_RTL_STRING_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/**
+ * A string duplicate that uses the RTL allocator.
+ *
+ * @param s1 The string to duplicate.
+ * @return char* The copy of the string. NULL if there is no memory.
+ */
+char* rtems_rtl_strdup(const char *s1);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif
diff --git a/rtl-sym.c b/rtl-sym.c
index f4ca8f5..163b683 100644
--- a/rtl-sym.c
+++ b/rtl-sym.c
@@ -125,7 +125,7 @@ rtems_rtl_symbol_global_add (rtems_rtl_obj_t* obj,
printf ("rtl: global symbol add: %zi\n", count);
obj->global_size = count * sizeof (rtems_rtl_obj_sym_t);
- obj->global_table = malloc (obj->global_size);
+ obj->global_table = rtems_rtl_alloc_new (RTEMS_RTL_ALLOC_SYMBOL, obj->global_size);
if (!obj->global_table)
{
obj->global_size = 0;
@@ -221,7 +221,7 @@ rtems_rtl_obj_symbol_erase (rtems_rtl_obj_t* obj)
for (s = 0, sym = obj->global_table; s < obj->global_syms; ++s, ++sym)
if (!rtems_chain_is_node_off_chain (&sym->node))
rtems_chain_extract (&sym->node);
- free (obj->global_table);
+ rtems_rtl_alloc_del (RTEMS_RTL_ALLOC_SYMBOL, obj->global_table);
obj->global_table = NULL;
obj->global_size = 0;
obj->global_syms = 0;
diff --git a/rtl-trace.h b/rtl-trace.h
index 848e966..0dc96ab 100644
--- a/rtl-trace.h
+++ b/rtl-trace.h
@@ -44,6 +44,7 @@ typedef uint32_t rtems_rtl_trace_mask;
#define RTEMS_RTL_TRACE_RELOC (1UL << 4)
#define RTEMS_RTL_TRACE_GLOBAL_SYM (1UL << 5)
#define RTEMS_RTL_TRACE_LOAD_SECT (1UL << 6)
+#define RTEMS_RTL_TRACE_ALLOCATOR (1UL << 7)
/**
* Call to check if this part is bring traced. If RTEMS_RTL_TRACE is defined to
diff --git a/rtl.c b/rtl.c
index 5cfeef9..78d395c 100644
--- a/rtl.c
+++ b/rtl.c
@@ -26,6 +26,7 @@
#include <rtems/libio_.h>
#include <rtl.h>
+#include "rtl-alloc-heap.h"
#include "rtl-error.h"
#include "rtl-trace.h"
@@ -34,7 +35,7 @@
*/
#define RTEMS_MUTEX_ATTRIBS \
(RTEMS_PRIORITY | RTEMS_BINARY_SEMAPHORE | \
- RTEMS_NO_INHERIT_PRIORITY | RTEMS_NO_PRIORITY_CEILING | RTEMS_LOCAL)
+ RTEMS_INHERIT_PRIORITY | RTEMS_NO_PRIORITY_CEILING | RTEMS_LOCAL)
/**
* Symbol table cache size. They can be big so the cache needs space to work.
@@ -85,7 +86,11 @@ rtems_rtl_data_init (void)
if (!rtl)
{
rtems_status_code sc;
-
+ rtems_id lock;
+
+ /*
+ * Always in the heap.
+ */
rtl = malloc (sizeof (rtems_rtl_data_t));
if (!rtl)
{
@@ -95,26 +100,42 @@ rtems_rtl_data_init (void)
*rtl = (rtems_rtl_data_t) { 0 };
- rtems_chain_initialize_empty (&rtl->objects);
+ /*
+ * The default allocator uses the libc heap.
+ */
+ rtl->allocator = rtems_rtl_alloc_heap;
- rtl->base = rtems_rtl_obj_alloc ();
- if (!rtl->base)
+ /*
+ * Create the RTL lock.
+ */
+ sc = rtems_semaphore_create (rtems_build_name ('R', 'T', 'L', 'D'),
+ 1, RTEMS_MUTEX_ATTRIBS,
+ RTEMS_NO_PRIORITY, &lock);
+ if (sc != RTEMS_SUCCESSFUL)
{
free (rtl);
return false;
}
+ sc = rtems_semaphore_obtain (lock, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
+ if (sc != RTEMS_SUCCESSFUL)
+ {
+ rtems_semaphore_delete (lock);
+ free (rtl);
+ return false;
+ }
+
+ rtl->lock = lock;
+
/*
- * Need to malloc the memory so the free does not complain.
+ * Initialise the objects list and create any required services.
*/
- rtl->base->oname = strdup ("rtems-kernel");
+ rtems_chain_initialize_empty (&rtl->objects);
- rtems_chain_append (&rtl->objects, &rtl->base->link);
-
if (!rtems_rtl_symbol_table_open (&rtl->globals,
RTEMS_RTL_SYMS_GLOBAL_BUCKETS))
{
- rtems_rtl_obj_free (rtl->base);
+ rtems_semaphore_delete (lock);
free (rtl);
return false;
}
@@ -123,7 +144,7 @@ rtems_rtl_data_init (void)
RTEMS_RTL_ELF_SYMBOL_CACHE))
{
rtems_rtl_symbol_table_close (&rtl->globals);
- rtems_rtl_obj_free (rtl->base);
+ rtems_semaphore_delete (lock);
free (rtl);
return false;
}
@@ -133,7 +154,7 @@ rtems_rtl_data_init (void)
{
rtems_rtl_obj_cache_close (&rtl->symbols);
rtems_rtl_symbol_table_close (&rtl->globals);
- rtems_rtl_obj_free (rtl->base);
+ rtems_semaphore_delete (lock);
free (rtl);
return false;
}
@@ -144,24 +165,29 @@ rtems_rtl_data_init (void)
rtems_rtl_obj_cache_close (&rtl->strings);
rtems_rtl_obj_cache_close (&rtl->symbols);
rtems_rtl_symbol_table_close (&rtl->globals);
- rtems_rtl_obj_free (rtl->base);
+ rtems_semaphore_delete (lock);
free (rtl);
return false;
}
- sc = rtems_semaphore_create(rtems_build_name ('R', 'T', 'L', 'D'),
- 1, RTEMS_MUTEX_ATTRIBS,
- RTEMS_NO_PRIORITY, &rtl->lock);
- if (sc != RTEMS_SUCCESSFUL)
+ rtl->base = rtems_rtl_obj_alloc ();
+ if (!rtl->base)
{
rtems_rtl_obj_cache_close (&rtl->relocs);
rtems_rtl_obj_cache_close (&rtl->strings);
rtems_rtl_obj_cache_close (&rtl->symbols);
rtems_rtl_symbol_table_close (&rtl->globals);
- rtems_rtl_obj_free (rtl->base);
+ rtems_semaphore_delete (lock);
free (rtl);
return false;
}
+
+ /*
+ * Need to malloc the memory so the free does not complain.
+ */
+ rtl->base->oname = strdup ("rtems-kernel");
+
+ rtems_chain_append (&rtl->objects, &rtl->base->link);
}
rtems_libio_unlock ();
@@ -169,6 +195,8 @@ rtems_rtl_data_init (void)
rtems_rtl_path_append (".");
rtems_rtl_base_global_syms_init ();
+
+ rtems_rtl_unlock ();
}
return true;
}
@@ -424,7 +452,7 @@ rtems_rtl_path_update (bool prepend, const char* path)
else
prepend = true;
- paths = malloc (len + 1);
+ paths = rtems_rtl_alloc_new (RTEMS_RTL_ALLOC_STRING, len + 1);
if (!paths)
{
diff --git a/rtl.h b/rtl.h
index c1029cf..0ebfce1 100644
--- a/rtl.h
+++ b/rtl.h
@@ -23,6 +23,8 @@
#include <rtems/chain.h>
// #include <rtems/rtl/rtl-elf.h>
+
+#include <rtl-allocator.h>
#include <rtl-fwd.h>
#include <rtl-elf.h>
#include <rtl-obj.h>
@@ -79,6 +81,7 @@ typedef void (*rtems_rtl_cdtor_t)(void);
struct rtems_rtl_data_s
{
rtems_id lock; /**< The RTL lock id */
+ rtems_rtl_allocator_t allocator; /**< The memory allocator handler. */
rtems_chain_control objects; /**< List if loaded object files. */
const char* paths; /**< Search paths for archives. */
rtems_rtl_symbols_t globals; /**< Global symbol table. */
diff --git a/wscript b/wscript
index 7baaa0f..c2c7f80 100644
--- a/wscript
+++ b/wscript
@@ -53,6 +53,8 @@ def rtl_source(bld, arch):
source = ['dlfcn.c',
'dlfcn-shell.c',
'rtl.c',
+ 'rtl-alloc-heap.c',
+ 'rtl-allocator.c',
'rtl-chain-iterator.c',
'rtl-debugger.c',
'rtl-elf.c',
@@ -60,6 +62,7 @@ def rtl_source(bld, arch):
'rtl-obj.c',
'rtl-obj-cache.c',
'rtl-shell.c',
+ 'rtl-string.c',
'rtl-sym.c',
'rtl-trace.c',
'rtl-mdreloc-' + arch + '.c'])