Home | History | Annotate | Download | only in util
      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 #ifdef 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  */
     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  */
     51 inline void memoryFree(void *pointer) {
     52   chreHeapFree(pointer);
     53 }
     54 
     55 }  // namespace chre
     56 
     57 #else
     58 #include "chre/platform/assert.h"
     59 #include "chre/platform/memory.h"
     60 #endif  // CHRE_IS_NANOAPP_BUILD
     61 
     62 #endif  // CHRE_UTIL_CONTAINER_SUPPORT_H_
     63