blob: 5a410c2781aa27b429a6af621289d2813dfba330 [file] [log] [blame]
Steven Morelandd22659b2020-10-05 23:20:11 +00001/*
2 * Copyright (C) 2020 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 <cutils/memory.h>
18
19#include <log/log.h>
20
Elliott Hughes44448242021-01-15 17:46:28 -080021#if !defined(__APPLE__)
Elliott Hughes66304a02021-01-15 11:04:10 -080022#include <malloc.h>
Elliott Hughes44448242021-01-15 17:46:28 -080023#endif
Steven Morelandd22659b2020-10-05 23:20:11 +000024
25void process_disable_memory_mitigations() {
26 bool success = false;
27#ifdef __BIONIC__
Elliott Hughes66304a02021-01-15 11:04:10 -080028 success = mallopt(M_BIONIC_DISABLE_MEMORY_MITIGATIONS, 0);
Steven Morelandd22659b2020-10-05 23:20:11 +000029#endif
30
Elliott Hughes66304a02021-01-15 11:04:10 -080031 // TODO: if b/158870657 is fixed and scudo is used globally,
32 // we can assert on failure rather than just log.
Steven Morelandd22659b2020-10-05 23:20:11 +000033 if (success) {
34 ALOGI("Disabled memory mitigations for process.");
35 } else {
36 ALOGE("Could not disable memory mitigations for process.");
37 }
38}