]> pd.if.org Git - liblfds/blob - liblfds/liblfds7.1.0/test_and_benchmark/libtest/src/libtest_misc/libtest_misc_memory_helpers.c
Initial import (all versions, including the new 7.1.0)
[liblfds] / liblfds / liblfds7.1.0 / test_and_benchmark / libtest / src / libtest_misc / libtest_misc_memory_helpers.c
1 /***** includes *****/
2 #include "libtest_misc_internal.h"
3
4
5
6
7
8 /****************************************************************************/
9 void *libtest_misc_aligned_malloc( lfds710_pal_uint_t size, lfds710_pal_uint_t align_in_bytes )
10 {
11   lfds710_pal_uint_t
12     offset;
13
14   void
15     *memory,
16     *original_memory;
17
18   // TRD : size can be any value in its range
19   // TRD : align_in_bytes can be any value in its range
20
21   /* TRD : helper function to provide aligned allocations
22            no porting required
23   */
24
25   original_memory = memory = libtest_pal_malloc( size + sizeof(void *) + align_in_bytes );
26
27   if( memory != NULL )
28   {
29     memory = (void **) memory + 1;
30     offset = align_in_bytes - (lfds710_pal_uint_t) memory % align_in_bytes;
31     memory = (char unsigned *) memory + offset;
32     *( (void **) memory - 1 ) = original_memory;
33   }
34
35   return memory;
36 }
37
38
39
40
41
42 /****************************************************************************/
43 void libtest_misc_aligned_free( void *memory )
44 {
45   LFDS710_PAL_ASSERT( memory != NULL );
46
47   // TRD : the "void *" stored above memory points to the root of the allocation
48   libtest_pal_free( *( (void **) memory - 1 ) );
49
50   return;
51 }
52