mbed library sources. Supersedes mbed-src.

Fork of mbed by teralytic

Committer:
rodriguise
Date:
Mon Oct 17 18:47:01 2016 +0000
Revision:
148:4802eb17e82b
Parent:
147:30b64687e01f
backup

Who changed what in which revision?

UserRevisionLine numberNew contents of line
<> 147:30b64687e01f 1 /* mbed Microcontroller Library
<> 147:30b64687e01f 2 * Copyright (c) 2006-2016 ARM Limited
<> 147:30b64687e01f 3 *
<> 147:30b64687e01f 4 * Licensed under the Apache License, Version 2.0 (the "License");
<> 147:30b64687e01f 5 * you may not use this file except in compliance with the License.
<> 147:30b64687e01f 6 * You may obtain a copy of the License at
<> 147:30b64687e01f 7 *
<> 147:30b64687e01f 8 * http://www.apache.org/licenses/LICENSE-2.0
<> 147:30b64687e01f 9 *
<> 147:30b64687e01f 10 * Unless required by applicable law or agreed to in writing, software
<> 147:30b64687e01f 11 * distributed under the License is distributed on an "AS IS" BASIS,
<> 147:30b64687e01f 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<> 147:30b64687e01f 13 * See the License for the specific language governing permissions and
<> 147:30b64687e01f 14 * limitations under the License.
<> 147:30b64687e01f 15 */
<> 147:30b64687e01f 16
<> 147:30b64687e01f 17 #ifndef __MBED_MEM_TRACE_H__
<> 147:30b64687e01f 18 #define __MBED_MEM_TRACE_H__
<> 147:30b64687e01f 19
<> 147:30b64687e01f 20 #ifdef __cplusplus
<> 147:30b64687e01f 21 extern "C" {
<> 147:30b64687e01f 22 #endif
<> 147:30b64687e01f 23
<> 147:30b64687e01f 24 #include <stdint.h>
<> 147:30b64687e01f 25 #include <stddef.h>
<> 147:30b64687e01f 26
<> 147:30b64687e01f 27 /* Operation types for tracer */
<> 147:30b64687e01f 28 enum {
<> 147:30b64687e01f 29 MBED_MEM_TRACE_MALLOC,
<> 147:30b64687e01f 30 MBED_MEM_TRACE_REALLOC,
<> 147:30b64687e01f 31 MBED_MEM_TRACE_CALLOC,
<> 147:30b64687e01f 32 MBED_MEM_TRACE_FREE
<> 147:30b64687e01f 33 };
<> 147:30b64687e01f 34
<> 147:30b64687e01f 35 /* Prefix for the output of the default tracer */
<> 147:30b64687e01f 36 #define MBED_MEM_DEFAULT_TRACER_PREFIX "#"
<> 147:30b64687e01f 37
<> 147:30b64687e01f 38 /**
<> 147:30b64687e01f 39 * Type of the callback used by the memory tracer. This callback is called when a memory
<> 147:30b64687e01f 40 * allocation operation (malloc, realloc, calloc, free) is called and tracing is enabled
<> 147:30b64687e01f 41 * for that memory allocation function.
<> 147:30b64687e01f 42 *
<> 147:30b64687e01f 43 * @param op the ID of the operation (MBED_MEM_TRACE_MALLOC, MBED_MEM_TRACE_REALLOC,
<> 147:30b64687e01f 44 * MBED_MEM_TRACE_CALLOC or MBED_MEM_TRACE_FREE).
<> 147:30b64687e01f 45 * @param res the result that the memory operation returned (NULL for 'free').
<> 147:30b64687e01f 46 * @param caller the caller of the memory operation. Note that the value of 'caller' might be
<> 147:30b64687e01f 47 * unreliable.
<> 147:30b64687e01f 48 *
<> 147:30b64687e01f 49 * The rest of the parameters passed 'mbed_mem_trace_cb_t' are the same as the memory operations
<> 147:30b64687e01f 50 * that triggered its call (see 'man malloc' for details):
<> 147:30b64687e01f 51 *
<> 147:30b64687e01f 52 * - for malloc: cb(MBED_MEM_TRACE_MALLOC, res, caller, size).
<> 147:30b64687e01f 53 * - for realloc: cb(MBED_MEM_TRACE_REALLOC, res, caller, ptr, size).
<> 147:30b64687e01f 54 * - for calloc: cb(MBED_MEM_TRACE_CALLOC, res, caller, nmemb, size).
<> 147:30b64687e01f 55 * - for free: cb(MBED_MEM_TRACE_FREE, NULL, caller, ptr).
<> 147:30b64687e01f 56 */
<> 147:30b64687e01f 57 typedef void (*mbed_mem_trace_cb_t)(uint8_t op, void *res, void* caller, ...);
<> 147:30b64687e01f 58
<> 147:30b64687e01f 59 /**
<> 147:30b64687e01f 60 * Set the callback used by the memory tracer (use NULL for disable tracing).
<> 147:30b64687e01f 61 *
<> 147:30b64687e01f 62 * @param cb the callback to call on each memory operation.
<> 147:30b64687e01f 63 */
<> 147:30b64687e01f 64 void mbed_mem_trace_set_callback(mbed_mem_trace_cb_t cb);
<> 147:30b64687e01f 65
<> 147:30b64687e01f 66 /**
<> 147:30b64687e01f 67 * Trace a call to 'malloc'.
<> 147:30b64687e01f 68 * @param res the result of running 'malloc'.
<> 147:30b64687e01f 69 * @param size the 'size' argument given to 'malloc'.
<> 147:30b64687e01f 70 * @param caller the caller of the memory operation.
<> 147:30b64687e01f 71 * @return 'res' (the first argument).
<> 147:30b64687e01f 72 */
<> 147:30b64687e01f 73 void *mbed_mem_trace_malloc(void *res, size_t size, void *caller);
<> 147:30b64687e01f 74
<> 147:30b64687e01f 75 /**
<> 147:30b64687e01f 76 * Trace a call to 'realloc'.
<> 147:30b64687e01f 77 * @param res the result of running 'realloc'.
<> 147:30b64687e01f 78 * @param ptr the 'ptr' argument given to 'realloc'.
<> 147:30b64687e01f 79 * @param size the 'size' argument given to 'realloc'.
<> 147:30b64687e01f 80 *
<> 147:30b64687e01f 81 * @return 'res' (the first argument).
<> 147:30b64687e01f 82 */
<> 147:30b64687e01f 83 void *mbed_mem_trace_realloc(void *res, void *ptr, size_t size, void *caller);
<> 147:30b64687e01f 84
<> 147:30b64687e01f 85 /**
<> 147:30b64687e01f 86 * Trace a call to 'calloc'.
<> 147:30b64687e01f 87 * @param res the result of running 'calloc'.
<> 147:30b64687e01f 88 * @param nmemb the 'nmemb' argument given to 'calloc'.
<> 147:30b64687e01f 89 * @param size the 'size' argument given to 'calloc'.
<> 147:30b64687e01f 90 * @param caller the caller of the memory operation.
<> 147:30b64687e01f 91 * @Return 'res' (the first argument).
<> 147:30b64687e01f 92 */
<> 147:30b64687e01f 93 void *mbed_mem_trace_calloc(void *res, size_t num, size_t size, void *caller);
<> 147:30b64687e01f 94
<> 147:30b64687e01f 95 /**
<> 147:30b64687e01f 96 * Trace a call to 'free'.
<> 147:30b64687e01f 97 * @param ptr the 'ptr' argument given to 'free'.
<> 147:30b64687e01f 98 * @param caller the caller of the memory operation.
<> 147:30b64687e01f 99 */
<> 147:30b64687e01f 100 void mbed_mem_trace_free(void *ptr, void *caller);
<> 147:30b64687e01f 101
<> 147:30b64687e01f 102 /**
<> 147:30b64687e01f 103 * Default memory trace callback. DO NOT CALL DIRECTLY. It is meant to be used
<> 147:30b64687e01f 104 * as the second argument of 'mbed_mem_trace_setup'.
<> 147:30b64687e01f 105 *
<> 147:30b64687e01f 106 * The default callback outputs trace data using 'printf', in a format that's
<> 147:30b64687e01f 107 * easily parsable by an external tool. For each memory operation, the callback
<> 147:30b64687e01f 108 * outputs a line that begins with '#<op>:<0xresult>;<0xcaller>-':
<> 147:30b64687e01f 109 *
<> 147:30b64687e01f 110 * - 'op' identifies the memory operation ('m' for 'malloc', 'r' for 'realloc',
<> 147:30b64687e01f 111 * 'c' for 'calloc' and 'f' for 'free').
<> 147:30b64687e01f 112 * - 'result' (base 16) is the result of the memor operation. This is always NULL
<> 147:30b64687e01f 113 * for 'free', since 'free' doesn't return anything.
<> 147:30b64687e01f 114 * -'caller' (base 16) is the caller of the memory operation. Note that the value
<> 147:30b64687e01f 115 * of 'caller' might be unreliable.
<> 147:30b64687e01f 116 *
<> 147:30b64687e01f 117 * The rest of the output depends on the operation being traced:
<> 147:30b64687e01f 118 *
<> 147:30b64687e01f 119 * - for 'malloc': 'size', where 'size' is the original argument to 'malloc'.
<> 147:30b64687e01f 120 * - for 'realloc': '0xptr;size', where 'ptr' (base 16) and 'size' are the original arguments to 'realloc'.
<> 147:30b64687e01f 121 * - for 'calloc': 'nmemb;size', where 'nmemb' and 'size' are the original arguments to 'calloc'.
<> 147:30b64687e01f 122 * - for 'free': '0xptr', where 'ptr' (base 16) is the original argument to 'free'.
<> 147:30b64687e01f 123 *
<> 147:30b64687e01f 124 * Examples:
<> 147:30b64687e01f 125 *
<> 147:30b64687e01f 126 * - '#m:0x20003240;0x600d-50' encodes a 'malloc' that returned 0x20003240, was called
<> 147:30b64687e01f 127 * by the instruction at 0x600D with a the 'size' argument equal to 50.
<> 147:30b64687e01f 128 * - '#f:0x0;0x602f-0x20003240' encodes a 'free' that was called by the instruction at
<> 147:30b64687e01f 129 * 0x602f with the 'ptr' argument equal to 0x20003240.
<> 147:30b64687e01f 130 */
<> 147:30b64687e01f 131 void mbed_mem_trace_default_callback(uint8_t op, void *res, void *caller, ...);
<> 147:30b64687e01f 132
<> 147:30b64687e01f 133 #ifdef __cplusplus
<> 147:30b64687e01f 134 }
<> 147:30b64687e01f 135 #endif
<> 147:30b64687e01f 136
<> 147:30b64687e01f 137 #endif// #ifndef __MBED_MEM_TRACE_H__
<> 147:30b64687e01f 138