]> pd.if.org Git - liblfds/blob - liblfds/liblfds6.0.0/liblfds600/src/lfds600_abstraction/lfds600_abstraction_aligned_malloc.c
Initial import (all versions, including the new 7.1.0)
[liblfds] / liblfds / liblfds6.0.0 / liblfds600 / src / lfds600_abstraction / lfds600_abstraction_aligned_malloc.c
1 #include "lfds600_abstraction_internal.h"
2
3
4
5
6
7 /****************************************************************************/
8 #if (defined _WIN32 && defined _MSC_VER && !defined WIN_KERNEL_BUILD)
9
10   /* TRD : any Windows (user-mode) on any CPU with the Microsoft C compiler
11
12            _WIN32             indicates 64-bit or 32-bit Windows
13            _MSC_VER           indicates Microsoft C compiler
14            !WIN_KERNEL_BUILD  indicates Windows user-mode
15   */
16
17   void *lfds600_abstraction_aligned_malloc( size_t size, size_t align_in_bytes )
18   {
19     void
20       *rv;
21
22     rv = _aligned_malloc( size, align_in_bytes );
23
24     return( rv );
25   }
26
27 #endif
28
29
30
31
32
33 /****************************************************************************/
34 #if (_XOPEN_SOURCE >= 600)
35
36   /* TRD : any OS on any CPU with any compiler with POSIX 6.00 or better
37
38            _XOPEN_SOURCE  is actually set by the user, not by the compiler
39                           it is the way the user signals to the compiler what
40                           level of POSIX should be available
41                           (it assumes of course the compiler has support for the given level of POSIX requested)
42   */
43
44   void *lfds600_abstraction_aligned_malloc( size_t size, size_t align_in_bytes )
45   {
46     int
47       rv;
48
49     void
50       *memory;
51
52     rv = posix_memalign( &memory, align_in_bytes, size );
53
54     // TRD : posix_memalign returns 0 on success, docs do not say *memory == NULL on fail
55     if( rv != 0 )
56       memory = NULL;
57
58     return( memory );
59   }
60
61 #endif
62
63
64
65
66
67 /****************************************************************************/
68 #if (defined _WIN32 && defined _MSC_VER && defined WIN_KERNEL_BUILD)
69
70   /* TRD : any Windows (kernel) on any CPU with the Microsoft C compiler
71
72            _WIN32            indicates 64-bit or 32-bit Windows
73            _MSC_VER          indicates Microsoft C compiler
74            WIN_KERNEL_BUILD  indicates Windows kernel
75   */
76
77   void *lfds600_abstraction_aligned_malloc( size_t size, size_t align_in_bytes )
78   {
79     void
80       *rv;
81
82     /* TRD : ExAllocatePoolWithTag() allocates memory aligned on 8 bytes on 32-bit CPUs
83              and on 16 bytes on 64-bit CPUs, which is what we want
84
85              as such, align_in_bytes is not needed; we must refer to it to avoid the
86              compiler warning
87     */
88
89     align_in_bytes;
90
91     rv = ExAllocatePoolWithTag( NonPagedPool, size, 'sdfl' );
92
93     return( rv );
94   }
95
96 #endif
97