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