Debian Codegraph @

memory/build/fallback.cpp

raw
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7 #include "mozmemory.h"
8 #include "mozjemalloc.h"
9 #include <stdlib.h>
10
11 #ifndef HAVE_MEMALIGN
12 MOZ_MEMORY_API void* memalign(size_t aAlignment, size_t aSize) {
13 # ifdef XP_WIN
14 return _aligned_malloc(aSize, aAlignment);
15 # else
16 void* ret;
17 if (posix_memalign(&ret, aAlignment, aSize) != 0) {
18 return nullptr;
19 }
20 return ret;
21 # endif
22 }
23 #endif
24
25 struct SystemMalloc {
26 #define MALLOC_DECL(name, return_type, ...) \
27 static inline return_type name(ARGS_HELPER(TYPED_ARGS, ##__VA_ARGS__)) { \
28 return ::name(ARGS_HELPER(ARGS, ##__VA_ARGS__)); \
29 }
30 #define MALLOC_FUNCS MALLOC_FUNCS_MALLOC_BASE
31 #include "malloc_decls.h"
32 };
33
34 #define MALLOC_DECL(name, return_type, ...) \
35 MOZ_JEMALLOC_API return_type name(ARGS_HELPER(TYPED_ARGS, ##__VA_ARGS__)) { \
36 return DummyArenaAllocator<SystemMalloc>::name( \
37 ARGS_HELPER(ARGS, ##__VA_ARGS__)); \
38 }
39 #define MALLOC_FUNCS MALLOC_FUNCS_ARENA
40 #include "malloc_decls.h"