summaryrefslogtreecommitdiffstats
path: root/cpukit/libtrace/record/record-wrap-malloc.c
blob: 2ec3e9c0239b1ddf82b35d2a39b93e31af10c6a6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*
 * SPDX-License-Identifier: BSD-2-Clause
 *
 * Copyright (C) 2018, 2019 embedded brains GmbH
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#if HAVE_CONFIG_H
#include "config.h"
#endif

#include <rtems/record.h>

#include <stdlib.h>

typedef void *Record_Aligned_alloc(size_t, size_t);

Record_Aligned_alloc aligned_alloc;
Record_Aligned_alloc __real_aligned_alloc;
Record_Aligned_alloc __wrap_aligned_alloc;

void *__wrap_aligned_alloc( size_t alignment, size_t size )
{
  void *ptr;

  rtems_record_entry_2(
    RTEMS_RECORD_ALIGNED_ALLOC_ENTRY,
    alignment,
    size
  );
  ptr = __real_aligned_alloc( alignment, size );
  rtems_record_exit_1(
    RTEMS_RECORD_ALIGNED_ALLOC_EXIT,
    (rtems_record_data) ptr
  );
  return ptr;
}

typedef void *Record_Calloc( size_t, size_t );

Record_Calloc calloc;
Record_Calloc __real_calloc;
Record_Calloc __wrap_calloc;

void *__wrap_calloc( size_t nelem, size_t elsize )
{
  void *ptr;

  rtems_record_entry_2( RTEMS_RECORD_CALLOC_ENTRY, nelem, elsize );
  ptr = __real_calloc( nelem, elsize );
  rtems_record_exit_1( RTEMS_RECORD_CALLOC_EXIT, (rtems_record_data) ptr );
  return ptr;
}

typedef void *Record_Malloc( size_t );

Record_Malloc malloc;
Record_Malloc __real_malloc;
Record_Malloc __wrap_malloc;

void *__wrap_malloc( size_t size )
{
  void *ptr;

  rtems_record_entry_1( RTEMS_RECORD_MALLOC_ENTRY, size );
  ptr = __real_malloc( size );
  rtems_record_exit_1( RTEMS_RECORD_MALLOC_EXIT, (rtems_record_data) ptr );
  return ptr;
}

typedef void Record_Free( void *ptr );

Record_Free free;
Record_Free __real_free;
Record_Free __wrap_free;

void __wrap_free( void *ptr )
{
  rtems_record_entry_1( RTEMS_RECORD_FREE_ENTRY, (rtems_record_data) ptr );
  __real_free( ptr );
  rtems_record_entry( RTEMS_RECORD_FREE_EXIT );
}

typedef int Record_POSIX_memalign( void **, size_t, size_t );

Record_POSIX_memalign posix_memalign;
Record_POSIX_memalign __real_posix_memalign;
Record_POSIX_memalign __wrap_posix_memalign;

int __wrap_posix_memalign( void **memptr, size_t alignment, size_t size )
{
  int eno;

  rtems_record_entry_3(
    RTEMS_RECORD_POSIX_MEMALIGN_ENTRY,
    (rtems_record_data) memptr,
    alignment,
    size
  );
  eno = __real_posix_memalign( memptr, alignment, size );
  rtems_record_exit_2(
    RTEMS_RECORD_POSIX_MEMALIGN_EXIT,
    eno,
    (rtems_record_data) ( memptr != NULL ? *memptr : NULL )
  );
  return eno;
}

typedef void *Record_Realloc( void *, size_t );

Record_Realloc realloc;
Record_Realloc __real_realloc;
Record_Realloc __wrap_realloc;

void *__wrap_realloc( void *ptr, size_t size )
{
  rtems_record_entry_2(
    RTEMS_RECORD_REALLOC_ENTRY,
    (rtems_record_data) ptr,
    size
  );
  ptr = __real_realloc( ptr, size );
  rtems_record_exit_1( RTEMS_RECORD_REALLOC_EXIT, (rtems_record_data) ptr );
  return ptr;
}