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:
parent
82c17fd6fa
commit
def007e2d7
@ -41,9 +41,17 @@
|
||||
* IEEE Std 1003.1-2008
|
||||
*/
|
||||
|
||||
#ifndef bcmp /* See mm/README.txt */
|
||||
#define bcmp(b1,b2,len) memcmp(b1,b2,(size_t)len)
|
||||
#endif
|
||||
|
||||
#ifndef bcopy /* See mm/README.txt */
|
||||
#define bcopy(b1,b2,len) (void)memmove(b2,b1,len)
|
||||
#endif
|
||||
|
||||
#ifndef bzero /* See mm/README.txt */
|
||||
#define bzero(s,n) (void)memset(s,0,n)
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Inline Functions
|
||||
|
@ -30,6 +30,7 @@
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
#undef aligned_alloc /* See mm/README.txt */
|
||||
FAR void *aligned_alloc(size_t align, size_t size)
|
||||
{
|
||||
return lib_memalign(align, size);
|
||||
|
@ -28,6 +28,7 @@
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
#undef atoi /* See mm/README.txt */
|
||||
int atoi(FAR const char *nptr)
|
||||
{
|
||||
return strtol(nptr, NULL, 10);
|
||||
|
@ -28,6 +28,7 @@
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
#undef atol /* See mm/README.txt */
|
||||
long atol(FAR const char *nptr)
|
||||
{
|
||||
return strtol(nptr, NULL, 10);
|
||||
|
@ -31,6 +31,7 @@
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
#undef posix_memalign /* See mm/README.txt */
|
||||
int posix_memalign(FAR void **mem, size_t align, size_t size)
|
||||
{
|
||||
*mem = lib_memalign(align, size);
|
||||
|
@ -49,6 +49,7 @@
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#undef valloc /* See mm/README.txt */
|
||||
FAR void *valloc(size_t size)
|
||||
{
|
||||
return lib_memalign(sysconf(_SC_PAGESIZE), size);
|
||||
|
@ -32,6 +32,7 @@
|
||||
* Name: index
|
||||
****************************************************************************/
|
||||
|
||||
#undef index /* See mm/README.txt */
|
||||
FAR char *index(FAR const char *s, int c)
|
||||
{
|
||||
return strchr(s, c);
|
||||
|
@ -46,6 +46,7 @@
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#undef memccpy /* See mm/README.txt */
|
||||
FAR void *memccpy(FAR void *s1, FAR const void *s2, int c, size_t n)
|
||||
{
|
||||
FAR unsigned char *pout = (FAR unsigned char *)s1;
|
||||
|
@ -44,6 +44,7 @@
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#undef memchr /* See mm/README.txt */
|
||||
FAR void *memchr(FAR const void *s, int c, size_t n)
|
||||
{
|
||||
FAR const unsigned char *p = (FAR const unsigned char *)s;
|
||||
|
@ -31,6 +31,7 @@
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_LIBC_ARCH_MEMCMP
|
||||
#undef memcmp /* See mm/README.txt */
|
||||
int memcmp(FAR const void *s1, FAR const void *s2, size_t n)
|
||||
{
|
||||
unsigned char *p1 = (unsigned char *)s1;
|
||||
|
@ -35,6 +35,7 @@
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_LIBC_ARCH_MEMCPY
|
||||
#undef memcpy /* See mm/README.txt */
|
||||
FAR void *memcpy(FAR void *dest, FAR const void *src, size_t n)
|
||||
{
|
||||
FAR unsigned char *pout = (FAR unsigned char *)dest;
|
||||
|
@ -31,6 +31,7 @@
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_LIBC_ARCH_MEMMOVE
|
||||
#undef memmove /* See mm/README.txt */
|
||||
FAR void *memmove(FAR void *dest, FAR const void *src, size_t count)
|
||||
{
|
||||
FAR char *tmp;
|
||||
|
@ -47,6 +47,7 @@
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_LIBC_ARCH_MEMSET
|
||||
#undef memset /* See mm/README.txt */
|
||||
FAR void *memset(FAR void *s, int c, size_t n)
|
||||
{
|
||||
#ifdef CONFIG_MEMSET_OPTSPEED
|
||||
|
@ -32,6 +32,7 @@
|
||||
* Name: rindex
|
||||
****************************************************************************/
|
||||
|
||||
#undef rindex /* See mm/README.txt */
|
||||
FAR char *rindex(FAR const char *s, int c)
|
||||
{
|
||||
return strrchr(s, c);
|
||||
|
@ -32,6 +32,7 @@
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_ARCH_STRCASECMP
|
||||
#undef strcasecmp /* See mm/README.txt */
|
||||
int strcasecmp(FAR const char *cs, FAR const char *ct)
|
||||
{
|
||||
int result;
|
||||
|
@ -31,6 +31,7 @@
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_ARCH_STRCAT
|
||||
#undef strcat /* See mm/README.txt */
|
||||
char *strcat(char *dest, const char *src)
|
||||
{
|
||||
char *ret = dest;
|
||||
|
@ -45,6 +45,7 @@
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_LIBC_ARCH_STRCHR
|
||||
#undef strchr /* See mm/README.txt */
|
||||
FAR char *strchr(FAR const char *s, int c)
|
||||
{
|
||||
if (s)
|
||||
|
@ -31,6 +31,7 @@
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_LIBC_ARCH_STRCMP
|
||||
#undef strcmp /* See mm/README.txt */
|
||||
int strcmp(FAR const char *cs, FAR const char *ct)
|
||||
{
|
||||
register signed char result;
|
||||
|
@ -43,6 +43,7 @@
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_LIBC_ARCH_STRCPY
|
||||
#undef strcpy /* See mm/README.txt */
|
||||
FAR char *strcpy(FAR char *dest, FAR const char *src)
|
||||
{
|
||||
char *tmp = dest;
|
||||
|
@ -39,6 +39,7 @@
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#undef strcspn /* See mm/README.txt */
|
||||
size_t strcspn(const char *s, const char *reject)
|
||||
{
|
||||
size_t i;
|
||||
|
@ -32,6 +32,7 @@
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
#undef strdup /* See mm/README.txt */
|
||||
FAR char *strdup(FAR const char *s)
|
||||
{
|
||||
FAR char *news = NULL;
|
||||
|
@ -31,6 +31,7 @@
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_LIBC_ARCH_STRLEN
|
||||
#undef strlen /* See mm/README.txt */
|
||||
size_t strlen(const char *s)
|
||||
{
|
||||
const char *sc;
|
||||
|
@ -33,6 +33,7 @@
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_ARCH_STRNCASECMP
|
||||
#undef strncasecmp /* See mm/README.txt */
|
||||
int strncasecmp(const char *cs, const char *ct, size_t nb)
|
||||
{
|
||||
int result = 0;
|
||||
|
@ -31,6 +31,7 @@
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_ARCH_STRNCAT
|
||||
#undef strncat /* See mm/README.txt */
|
||||
char *strncat(char *dest, const char *src, size_t n)
|
||||
{
|
||||
char *ret = dest;
|
||||
|
@ -31,6 +31,7 @@
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_ARCH_STRNCMP
|
||||
#undef strncmp /* See mm/README.txt */
|
||||
int strncmp(const char *cs, const char *ct, size_t nb)
|
||||
{
|
||||
int result = 0;
|
||||
|
@ -52,6 +52,7 @@
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_LIBC_ARCH_STRNCPY
|
||||
#undef strncpy /* See mm/README.txt */
|
||||
FAR char *strncpy(FAR char *dest, FAR const char *src, size_t n)
|
||||
{
|
||||
FAR char *ret = dest; /* Value to be returned */
|
||||
|
@ -49,6 +49,7 @@
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#undef strndup /* See mm/README.txt */
|
||||
FAR char *strndup(FAR const char *s, size_t size)
|
||||
{
|
||||
FAR char *news = NULL;
|
||||
|
@ -30,6 +30,7 @@
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
#undef strpbrk /* See mm/README.txt */
|
||||
FAR char *strpbrk(FAR const char *str, FAR const char *charset)
|
||||
{
|
||||
/* Sanity checking */
|
||||
|
@ -34,6 +34,7 @@
|
||||
* occurrence of the character c in the string s.
|
||||
*/
|
||||
|
||||
#undef strrchr /* See mm/README.txt */
|
||||
FAR char *strrchr(FAR const char *s, int c)
|
||||
{
|
||||
if (s)
|
||||
|
@ -39,6 +39,7 @@
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#undef strspn /* See mm/README.txt */
|
||||
size_t strspn(const char *s, const char *accept)
|
||||
{
|
||||
size_t i;
|
||||
|
@ -30,6 +30,7 @@
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
#undef strstr /* See mm/README.txt */
|
||||
FAR char *strstr(FAR const char *str, FAR const char *substr)
|
||||
{
|
||||
FAR const char *candidate; /* Candidate in str with matching start character */
|
||||
|
@ -66,6 +66,7 @@ static char *g_saveptr = NULL;
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#undef strtok /* See mm/README.txt */
|
||||
char *strtok(char *str, const char *delim)
|
||||
{
|
||||
return strtok_r(str, delim, &g_saveptr);
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user