blob: e8d01ccb3056b8c2f91d5125ccbb7b859ca3a406 [file] [log] [blame]
Elliott Hughes8daa0922011-09-11 13:46:25 -07001/*
2 * Copyright (C) 2011 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
Vladimir Markoe45883e2022-01-11 12:38:35 +000017#include <signal.h>
18#include <sys/mman.h>
19
Vladimir Markoebdaa2b2022-01-17 10:16:34 +000020#include "base/globals.h"
21#include "base/bit_utils.h"
Elliott Hughes8daa0922011-09-11 13:46:25 -070022#include "thread.h"
23
Elliott Hughes8daa0922011-09-11 13:46:25 -070024namespace art {
25
Elliott Hughesd6a23bd2013-07-16 14:19:52 -070026void Thread::SetUpAlternateSignalStack() {
27 // Bionic does this for us.
28}
29
30void Thread::TearDownAlternateSignalStack() {
31 // Bionic does this for us.
32}
33
Vladimir Markoe45883e2022-01-11 12:38:35 +000034void Thread::MadviseAwayAlternateSignalStack() {
35 stack_t old_ss;
36 int result = sigaltstack(nullptr, &old_ss);
37 CHECK_EQ(result, 0);
Vladimir Markoebdaa2b2022-01-17 10:16:34 +000038 // Only call `madvise()` on enabled page-aligned alternate signal stack. Processes can
39 // create different arbitrary alternate signal stacks and we do not want to erroneously
40 // `madvise()` away pages that may hold data other than the alternate signal stack.
41 if ((old_ss.ss_flags & SS_DISABLE) == 0 &&
42 IsAligned<kPageSize>(old_ss.ss_sp) &&
43 IsAligned<kPageSize>(old_ss.ss_size)) {
44 CHECK_EQ(old_ss.ss_flags & SS_ONSTACK, 0);
45 result = madvise(old_ss.ss_sp, old_ss.ss_size, MADV_DONTNEED);
46 CHECK_EQ(result, 0);
47 }
Vladimir Markoe45883e2022-01-11 12:38:35 +000048}
49
Elliott Hughes8daa0922011-09-11 13:46:25 -070050} // namespace art