blob: 26075c4df678dfda59c7d413912a120337e3a298 [file] [log] [blame]
Marco Nelissenc57fe212016-05-31 09:45:43 -07001/*
2 * Copyright (C) 2016 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 _MEDIA_UTILS_H
18#define _MEDIA_UTILS_H
19
20namespace android {
21
Jeff Vander Stoep4bc7ad92016-10-01 20:26:51 -070022extern "C" void __asan_init(void) __attribute__((weak));
Evgenii Stepanov7bd26ab2018-07-27 11:58:12 -070023extern "C" void __hwasan_init(void) __attribute__((weak));
Jeff Vander Stoep4bc7ad92016-10-01 20:26:51 -070024
25static inline int running_with_asan() {
Evgenii Stepanov7bd26ab2018-07-27 11:58:12 -070026 return &__asan_init != 0 || &__hwasan_init != 0;
Jeff Vander Stoep4bc7ad92016-10-01 20:26:51 -070027}
28
Marco Nelissenc57fe212016-05-31 09:45:43 -070029/**
30 Limit the amount of memory a process can allocate using setrlimit(RLIMIT_AS).
31 The value to use will be read from the specified system property, or if the
32 property doesn't exist it will use the specified number of bytes or the
33 specified percentage of total memory, whichever is smaller.
34*/
35void limitProcessMemory(
36 const char *property,
37 size_t numberOfBytes,
38 size_t percentageOfTotalMem);
39
40} // namespace android
41
42#endif // _MEDIA_UTILS_H