mirror of
https://github.com/apache/nuttx.git
synced 2026-06-04 14:53:47 +08:00
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
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
//***************************************************************************/
|
||||
|
||||
+4
-3
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user