• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef CHRE_UTIL_CONTAINER_SUPPORT_H_
18 #define CHRE_UTIL_CONTAINER_SUPPORT_H_
19 
20 /**
21  * @file Provides replacements for macros and functions that are normally
22  * provided by the CHRE framework implementation. These portable implementations
23  * are implemented using the CHRE API rather than private system APIs.
24  */
25 
26 #if defined CHRE_IS_NANOAPP_BUILD
27 
28 #include <chre.h>
29 
30 #include "chre/util/nanoapp/assert.h"
31 
32 namespace chre {
33 
34 /**
35  * Provides the memoryAlloc function that is normally provided by the CHRE
36  * runtime. It maps into chreHeapAlloc.
37  *
38  * @param size the size of the allocation to make.
39  * @return a pointer to allocated memory or nullptr if allocation failed.
40  */
memoryAlloc(size_t size)41 inline void *memoryAlloc(size_t size) {
42   return chreHeapAlloc(static_cast<uint32_t>(size));
43 }
44 
45 /**
46  * Provides the memoryFree function that is normally provided by the CHRE
47  * runtime. It maps into chreHeapFree.
48  *
49  * @param pointer the allocation to release.
50  */
memoryFree(void * pointer)51 inline void memoryFree(void *pointer) {
52   chreHeapFree(pointer);
53 }
54 
55 }  // namespace chre
56 
57 #elif defined CHRE_IS_HOST_BUILD
58 
59 #include "chre/util/host/assert.h"
60 
61 namespace chre {
62 
memoryAlloc(size_t size)63 inline void *memoryAlloc(size_t size) {
64   return malloc(size);
65 }
66 
memoryFree(void * pointer)67 inline void memoryFree(void *pointer) {
68   free(pointer);
69 }
70 
71 }  // namespace chre
72 
73 #else
74 #include "chre/platform/assert.h"
75 #include "chre/platform/memory.h"
76 #endif  // CHRE_IS_NANOAPP_BUILD
77 
78 #endif  // CHRE_UTIL_CONTAINER_SUPPORT_H_
79