mirror of
https://github.com/apache/nuttx.git
synced 2026-06-04 23:03:27 +08:00
add #undef for some libc function
since it's useful to redirect these functions to others sometime(e.g. validate the memory before write). Change-Id: I6253a9231af8809e8362f4bc5a1bd67fb094c3b0
This commit is contained in:
committed by
Gustavo Henrique Nihei
parent
82c17fd6fa
commit
def007e2d7
@@ -74,6 +74,41 @@ This directory contains the NuttX memory management logic. This include:
|
||||
mm/umm_heap - Holds the user-mode memory allocation interfaces
|
||||
mm/kmm_heap - Holds the kernel-mode memory allocation interfaces
|
||||
|
||||
Debugging:
|
||||
|
||||
Please follow these steps to hook all memory related routines:
|
||||
|
||||
1.Add a new header file(e.g. xxx_malloc.h):
|
||||
|
||||
...
|
||||
#include <malloc.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
|
||||
#ifndef __ASSEMBLY__
|
||||
FAR void *xxx_malloc(FAR const char *file, int line, size_t size);
|
||||
void xxx_free(FAR const char *file, int line, FAR const void *ptr);
|
||||
FAR void *xxx_memcpy(FAR const char *file, int line,
|
||||
FAR void *dst, FAR const void *src, size_t len);
|
||||
...
|
||||
#define malloc(s) xxx_malloc(__FILE__, __LINE__, s)
|
||||
#define free(p) xxx_free(__FILE__, __LINE__, p)
|
||||
#define memcpy(d, s, l) xxx_memcpy(__FILE__, __LINE__, d, s, l)
|
||||
...
|
||||
#endif
|
||||
...
|
||||
|
||||
2.Implement xxx_malloc, xxx_free, xxx_memcpy... in source code, you can:
|
||||
a.Modify some arguments(e.g. extend the allocation size for redzone)
|
||||
d.Check the critical arguments(e.g. pointer and length) in the range
|
||||
b.Forward to the original implementation(call malloc/free/memcpy)
|
||||
c.Attach the context info(e.g. file and line) before return
|
||||
|
||||
3.Enable the hook by either:
|
||||
a.Include xxx_malloc.h in your source code to hook one file
|
||||
b.Add -include xxx_malloc.h to CFLAGS to hook all source code
|
||||
|
||||
2) Granule Allocator.
|
||||
|
||||
A non-standard granule allocator is also available in this directory The
|
||||
|
||||
@@ -42,6 +42,7 @@
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#undef calloc /* See mm/README.txt */
|
||||
FAR void *calloc(size_t n, size_t elem_size)
|
||||
{
|
||||
#if defined(CONFIG_ARCH_ADDRENV) && defined(CONFIG_BUILD_KERNEL)
|
||||
|
||||
@@ -43,6 +43,7 @@
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#undef free /* See mm/README.txt */
|
||||
void free(FAR void *mem)
|
||||
{
|
||||
mm_free(USR_HEAP, mem);
|
||||
|
||||
@@ -49,6 +49,7 @@
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#undef malloc /* See mm/README.txt */
|
||||
FAR void *malloc(size_t size)
|
||||
{
|
||||
#if defined(CONFIG_ARCH_ADDRENV) && defined(CONFIG_BUILD_KERNEL)
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
#undef malloc_size /* See mm/README.txt */
|
||||
size_t malloc_size(FAR void *mem)
|
||||
{
|
||||
return mm_malloc_size(mem);
|
||||
|
||||
@@ -48,6 +48,7 @@
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#undef memalign /* See mm/README.txt */
|
||||
FAR void *memalign(size_t alignment, size_t size)
|
||||
{
|
||||
#if defined(CONFIG_ARCH_ADDRENV) && defined(CONFIG_BUILD_KERNEL)
|
||||
|
||||
@@ -50,6 +50,7 @@
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#undef realloc /* See mm/README.txt */
|
||||
FAR void *realloc(FAR void *oldmem, size_t size)
|
||||
{
|
||||
#if defined(CONFIG_ARCH_ADDRENV) && defined(CONFIG_BUILD_KERNEL)
|
||||
|
||||
@@ -49,6 +49,7 @@
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#undef zalloc /* See mm/README.txt */
|
||||
FAR void *zalloc(size_t size)
|
||||
{
|
||||
#ifdef CONFIG_ARCH_ADDRENV
|
||||
|
||||
Reference in New Issue
Block a user