1 /*
2 Copyright (c) 2003, 2021, Oracle and/or its affiliates.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License, version 2.0,
6 as published by the Free Software Foundation.
7
8 This program is also distributed with certain software (including
9 but not limited to OpenSSL) that is licensed under separate terms,
10 as designated in a particular file or component or in included license
11 documentation. The authors of MySQL hereby grant you an additional
12 permission to link the program and your derivative works with the
13 separately licensed software that they have included with MySQL.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 */
24
25
26 #include <ndb_global.h>
27
28 #include <NdbMem.h>
29
NdbMem_Create()30 void NdbMem_Create()
31 {
32 /* Do nothing */
33 return;
34 }
35
NdbMem_Destroy()36 void NdbMem_Destroy()
37 {
38 /* Do nothing */
39 return;
40 }
41
42
NdbMem_Allocate(size_t size)43 void* NdbMem_Allocate(size_t size)
44 {
45 void* mem_allocated;
46 assert(size > 0);
47 mem_allocated= (void*)malloc(size);
48 return mem_allocated;
49 }
50
NdbMem_AllocateAlign(size_t size,size_t alignment)51 void* NdbMem_AllocateAlign(size_t size, size_t alignment)
52 {
53 (void)alignment; /* remove warning for unused parameter */
54 /*
55 return (void*)memalign(alignment, size);
56 TEMP fix
57 */
58 return (void*)malloc(size);
59 }
60
61
NdbMem_Free(void * ptr)62 void NdbMem_Free(void* ptr)
63 {
64 free(ptr);
65 }
66
67
NdbMem_MemLockAll(int i)68 int NdbMem_MemLockAll(int i){
69 if (i == 1)
70 {
71 #if defined(HAVE_MLOCKALL) && defined(MCL_CURRENT) && defined (MCL_FUTURE)
72 return mlockall(MCL_CURRENT | MCL_FUTURE);
73 #else
74 return -1;
75 #endif
76 }
77 #if defined(HAVE_MLOCKALL) && defined(MCL_CURRENT)
78 return mlockall(MCL_CURRENT);
79 #else
80 return -1;
81 #endif
82 }
83
NdbMem_MemUnlockAll()84 int NdbMem_MemUnlockAll(){
85 #if defined(HAVE_MLOCKALL) && defined(MCL_CURRENT)
86 return munlockall();
87 #else
88 return -1;
89 #endif
90 }
91
NdbMem_MemLock(const void * ptr,size_t len)92 int NdbMem_MemLock(const void * ptr, size_t len)
93 {
94 #if defined(HAVE_MLOCK)
95 return mlock(ptr, len);
96 #else
97 return -1;
98 #endif
99 }
100