summaryrefslogtreecommitdiff
path: root/nuttx/libxx
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2013-03-09 21:12:20 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2013-03-09 21:12:20 +0000
commitdda5be5c1fc672b5d9cb3a910b5e0cb0a41046c5 (patch)
tree0af32db840a032a50312791977b7d129def1d5b3 /nuttx/libxx
parent2ac33dcffabd9422659c3b013ed8624c09ae90e4 (diff)
downloadpx4-nuttx-dda5be5c1fc672b5d9cb3a910b5e0cb0a41046c5.tar.gz
px4-nuttx-dda5be5c1fc672b5d9cb3a910b5e0cb0a41046c5.tar.bz2
px4-nuttx-dda5be5c1fc672b5d9cb3a910b5e0cb0a41046c5.zip
More changes for a kernel-mode allocator (more to be done)
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5724 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/libxx')
-rw-r--r--nuttx/libxx/libxx_cxa_atexit.cxx5
-rw-r--r--nuttx/libxx/libxx_delete.cxx7
-rw-r--r--nuttx/libxx/libxx_deletea.cxx7
-rw-r--r--nuttx/libxx/libxx_internal.hxx22
-rw-r--r--nuttx/libxx/libxx_new.cxx7
-rw-r--r--nuttx/libxx/libxx_newa.cxx5
6 files changed, 38 insertions, 15 deletions
diff --git a/nuttx/libxx/libxx_cxa_atexit.cxx b/nuttx/libxx/libxx_cxa_atexit.cxx
index cd31f94f6..d7a82fe5b 100644
--- a/nuttx/libxx/libxx_cxa_atexit.cxx
+++ b/nuttx/libxx/libxx_cxa_atexit.cxx
@@ -39,7 +39,6 @@
#include <nuttx/config.h>
-#include <cstdlib>
#include <cassert>
#include "libxx_internal.hxx"
@@ -91,7 +90,7 @@ extern "C"
DEBUGASSERT(alloc && alloc->func);
alloc->func(alloc->arg);
- free(alloc);
+ lib_free(alloc);
}
#endif
@@ -124,7 +123,7 @@ extern "C"
// information.
FAR struct __cxa_atexit_s *alloc =
- (FAR struct __cxa_atexit_s *)malloc(sizeof(struct __cxa_atexit_s));
+ (FAR struct __cxa_atexit_s *)lib_malloc(sizeof(struct __cxa_atexit_s));
if (alloc)
{
diff --git a/nuttx/libxx/libxx_delete.cxx b/nuttx/libxx/libxx_delete.cxx
index d9203a228..4de6f338a 100644
--- a/nuttx/libxx/libxx_delete.cxx
+++ b/nuttx/libxx/libxx_delete.cxx
@@ -1,7 +1,7 @@
//***************************************************************************
// libxx/libxx_new.cxx
//
-// Copyright (C) 2009 Gregory Nutt. All rights reserved.
+// Copyright (C) 2009, 2013 Gregory Nutt. All rights reserved.
// Author: Gregory Nutt <gnutt@nuttx.org>
//
// Redistribution and use in source and binary forms, with or without
@@ -38,7 +38,8 @@
//***************************************************************************
#include <nuttx/config.h>
-#include <cstdlib>
+
+#include "libxx_internal.hxx"
//***************************************************************************
// Definitions
@@ -58,5 +59,5 @@
void operator delete(void* ptr)
{
- free(ptr);
+ lib_free(ptr);
}
diff --git a/nuttx/libxx/libxx_deletea.cxx b/nuttx/libxx/libxx_deletea.cxx
index e7cfee647..a25a60717 100644
--- a/nuttx/libxx/libxx_deletea.cxx
+++ b/nuttx/libxx/libxx_deletea.cxx
@@ -1,7 +1,7 @@
//***************************************************************************
// libxx/libxx_newa.cxx
//
-// Copyright (C) 2009 Gregory Nutt. All rights reserved.
+// Copyright (C) 2009, 2013 Gregory Nutt. All rights reserved.
// Author: Gregory Nutt <gnutt@nuttx.org>
//
// Redistribution and use in source and binary forms, with or without
@@ -38,7 +38,8 @@
//***************************************************************************
#include <nuttx/config.h>
-#include <cstdlib>
+
+#include "libxx_internal.hxx"
//***************************************************************************
// Definitions
@@ -58,5 +59,5 @@
void operator delete[](void *ptr)
{
- free(ptr);
+ lib_free(ptr);
}
diff --git a/nuttx/libxx/libxx_internal.hxx b/nuttx/libxx/libxx_internal.hxx
index fe84c763e..74d5526ce 100644
--- a/nuttx/libxx/libxx_internal.hxx
+++ b/nuttx/libxx/libxx_internal.hxx
@@ -1,7 +1,7 @@
//***************************************************************************
// lib/libxx_internal.h
//
-// Copyright (C) 2012 Gregory Nutt. All rights reserved.
+// Copyright (C) 2012-2013 Gregory Nutt. All rights reserved.
// Author: Gregory Nutt <gnutt@nuttx.org>
//
// Redistribution and use in source and binary forms, with or without
@@ -46,6 +46,26 @@
// Definitions
//***************************************************************************
+// The NuttX C library an be build in two modes: (1) as a standard, C-libary
+// that can be used by normal, user-space applications, or (2) as a special,
+// kernel-mode C-library only used within the OS. If NuttX is not being
+// built as separated kernel- and user-space modules, then only the first
+// mode is supported.
+
+#if defined(CONFIG_NUTTX_KERNEL) && defined(__KERNEL__)
+# include <nuttx/kmalloc.h>
+# define lib_malloc(s) kmalloc(s)
+# define lib_zalloc(s) kzalloc(s)
+# define lib_realloc(p,s) krealloc(p,s)
+# define lib_free(p) kfree(p)
+#else
+# include <cstdlib>
+# define lib_malloc(s) malloc(s)
+# define lib_zalloc(s) zalloc(s)
+# define lib_realloc(p,s) realloc(p,s)
+# define lib_free(p) free(p)
+#endif
+
//***************************************************************************
// Public Types
//***************************************************************************/
diff --git a/nuttx/libxx/libxx_new.cxx b/nuttx/libxx/libxx_new.cxx
index 0563b6580..3158e8605 100644
--- a/nuttx/libxx/libxx_new.cxx
+++ b/nuttx/libxx/libxx_new.cxx
@@ -1,7 +1,7 @@
//***************************************************************************
// libxx/libxx_new.cxx
//
-// Copyright (C) 2009 Gregory Nutt. All rights reserved.
+// Copyright (C) 2009, 2013 Gregory Nutt. All rights reserved.
// Author: Gregory Nutt <gnutt@nuttx.org>
//
// Redistribution and use in source and binary forms, with or without
@@ -39,9 +39,10 @@
#include <nuttx/config.h>
#include <cstddef>
-#include <cstdlib>
#include <debug.h>
+#include "libxx_internal.hxx"
+
//***************************************************************************
// Definitions
//***************************************************************************
@@ -84,7 +85,7 @@ void *operator new(unsigned int nbytes)
// Perform the allocation
- void *alloc = malloc(nbytes);
+ void *alloc = lib_malloc(nbytes);
#ifdef CONFIG_DEBUG
if (alloc == 0)
diff --git a/nuttx/libxx/libxx_newa.cxx b/nuttx/libxx/libxx_newa.cxx
index ad7806865..b5b280356 100644
--- a/nuttx/libxx/libxx_newa.cxx
+++ b/nuttx/libxx/libxx_newa.cxx
@@ -39,9 +39,10 @@
#include <nuttx/config.h>
#include <cstddef>
-#include <cstdlib>
#include <debug.h>
+#include "libxx_internal.hxx"
+
//***************************************************************************
// Definitions
//***************************************************************************
@@ -84,7 +85,7 @@ void *operator new[](unsigned int nbytes)
// Perform the allocation
- void *alloc = malloc(nbytes);
+ void *alloc = lib_malloc(nbytes);
#ifdef CONFIG_DEBUG
if (alloc == 0)