1 /*
2  * Copyright (C) 2018 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 #include <chre.h>
18 
19 #include <cinttypes>
20 #include <cstdarg>
21 #include <cstdio>
22 #include <cstdlib>
23 
24 #include "chre/util/macros.h"
25 
26 /**
27  * @file
28  *
29  * This file supplies implementations for functions used by container_support.h
30  * to allow CHRE containers to be used standalone.
31  */
32 
chreHeapAlloc(uint32_t bytes)33 void *chreHeapAlloc(uint32_t bytes) {
34   return malloc(bytes);
35 }
36 
chreHeapFree(void * ptr)37 void chreHeapFree(void *ptr) {
38   free(ptr);
39 }
40 
chreAbort(uint32_t abortCode)41 void chreAbort(uint32_t abortCode) {
42   // We do not use exit() here because it accepts a signed int and we really
43   // want abort() semantics. Log the failure and abort().
44   fprintf(stderr, "Aborting with code %" PRIu32 "\n", abortCode);
45   abort();
46 }
47 
48 WEAK_SYMBOL
chreLog(enum chreLogLevel level,const char * formatStr,...)49 void chreLog(enum chreLogLevel level, const char *formatStr, ...) {
50   UNUSED_VAR(level);
51   va_list argList;
52   va_start(argList, formatStr);
53   vprintf(formatStr, argList);
54   va_end(argList);
55 }