2016-09-26 09:37:39 -04:00
|
|
|
/******************************************************************************
|
|
|
|
*
|
|
|
|
* Copyright (C) 2014 Google, Inc.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at:
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
#ifndef _ALLOCATOR_H_
|
|
|
|
#define _ALLOCATOR_H_
|
|
|
|
|
|
|
|
#include <stddef.h>
|
|
|
|
//#include <stdlib.h>
|
2017-06-13 08:52:26 -04:00
|
|
|
#include "sdkconfig.h"
|
2016-09-26 09:37:39 -04:00
|
|
|
|
|
|
|
typedef void *(*alloc_fn)(size_t size);
|
|
|
|
typedef void (*free_fn)(void *ptr);
|
|
|
|
|
|
|
|
typedef struct {
|
2016-11-24 13:10:15 -05:00
|
|
|
alloc_fn alloc;
|
|
|
|
free_fn free;
|
2016-09-26 09:37:39 -04:00
|
|
|
} allocator_t;
|
|
|
|
|
|
|
|
// allocator_t abstractions for the osi_*alloc and osi_free functions
|
|
|
|
extern const allocator_t allocator_malloc;
|
|
|
|
extern const allocator_t allocator_calloc;
|
|
|
|
|
|
|
|
char *osi_strdup(const char *str);
|
|
|
|
|
2016-12-12 15:10:44 -05:00
|
|
|
void *osi_malloc_func(size_t size);
|
|
|
|
void *osi_calloc_func(size_t size);
|
|
|
|
void osi_free_func(void *ptr);
|
|
|
|
|
|
|
|
#ifdef CONFIG_BLUEDROID_MEM_DEBUG
|
|
|
|
|
|
|
|
void osi_mem_dbg_init(void);
|
|
|
|
void osi_mem_dbg_record(void *p, int size, const char *func, int line);
|
2016-12-13 01:57:30 -05:00
|
|
|
void osi_mem_dbg_clean(void *p, const char *func, int line);
|
2016-12-12 15:10:44 -05:00
|
|
|
void osi_mem_dbg_show(void);
|
|
|
|
|
|
|
|
#define osi_malloc(size) \
|
|
|
|
({ \
|
|
|
|
void *p; \
|
|
|
|
\
|
2016-12-13 01:57:30 -05:00
|
|
|
p = calloc(1, (size)); \
|
2016-12-12 15:10:44 -05:00
|
|
|
osi_mem_dbg_record(p, size, __func__, __LINE__); \
|
2016-12-13 01:57:30 -05:00
|
|
|
(void *)p; \
|
2016-12-12 15:10:44 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
#define osi_calloc(size) \
|
|
|
|
({ \
|
|
|
|
void *p; \
|
|
|
|
\
|
2016-12-13 01:57:30 -05:00
|
|
|
p = calloc(1, (size)); \
|
2016-12-12 15:10:44 -05:00
|
|
|
osi_mem_dbg_record(p, size, __func__, __LINE__); \
|
2016-12-13 01:57:30 -05:00
|
|
|
(void *)p; \
|
2016-12-12 15:10:44 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
#define osi_free(ptr) \
|
|
|
|
({ \
|
2016-12-13 01:57:30 -05:00
|
|
|
osi_mem_dbg_clean(ptr, __func__, __LINE__); \
|
|
|
|
free((ptr)); \
|
2016-12-12 15:10:44 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2016-12-13 01:57:30 -05:00
|
|
|
#define osi_malloc(size) calloc(1, (size))
|
|
|
|
#define osi_calloc(size) calloc(1, (size))
|
|
|
|
#define osi_free(p) free((p))
|
2016-12-12 15:10:44 -05:00
|
|
|
|
|
|
|
#endif /* CONFIG_BLUEDROID_MEM_DEBUG */
|
2016-09-26 09:37:39 -04:00
|
|
|
|
|
|
|
#endif /* _ALLOCATOR_H_ */
|