Steven Moreland | d22659b | 2020-10-05 23:20:11 +0000 | [diff] [blame] | 1 | /* |
| 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 Hughes | 4444824 | 2021-01-15 17:46:28 -0800 | [diff] [blame] | 21 | #if !defined(__APPLE__) |
Elliott Hughes | 66304a0 | 2021-01-15 11:04:10 -0800 | [diff] [blame] | 22 | #include <malloc.h> |
Elliott Hughes | 4444824 | 2021-01-15 17:46:28 -0800 | [diff] [blame] | 23 | #endif |
Steven Moreland | d22659b | 2020-10-05 23:20:11 +0000 | [diff] [blame] | 24 | |
| 25 | void process_disable_memory_mitigations() { |
| 26 | bool success = false; |
| 27 | #ifdef __BIONIC__ |
Elliott Hughes | 66304a0 | 2021-01-15 11:04:10 -0800 | [diff] [blame] | 28 | success = mallopt(M_BIONIC_DISABLE_MEMORY_MITIGATIONS, 0); |
Steven Moreland | d22659b | 2020-10-05 23:20:11 +0000 | [diff] [blame] | 29 | #endif |
| 30 | |
Elliott Hughes | 66304a0 | 2021-01-15 11:04:10 -0800 | [diff] [blame] | 31 | // TODO: if b/158870657 is fixed and scudo is used globally, |
| 32 | // we can assert on failure rather than just log. |
Steven Moreland | d22659b | 2020-10-05 23:20:11 +0000 | [diff] [blame] | 33 | if (success) { |
| 34 | ALOGI("Disabled memory mitigations for process."); |
| 35 | } else { |
| 36 | ALOGE("Could not disable memory mitigations for process."); |
| 37 | } |
| 38 | } |