1 /* 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 17 #include "thread.h" 18 19 namespace art { 20 21 void Thread::SetNativePriority(int) { 22 // Do nothing. 23 } 24 25 int Thread::GetNativePriority() { 26 return kNormThreadPriority; 27 } 28 29 static void SigAltStack(stack_t* new_stack, stack_t* old_stack) { 30 if (sigaltstack(new_stack, old_stack) == -1) { 31 PLOG(FATAL) << "sigaltstack failed"; 32 } 33 } 34 35 void Thread::SetUpAlternateSignalStack() { 36 // Create and set an alternate signal stack. 37 stack_t ss; 38 ss.ss_sp = new uint8_t[SIGSTKSZ]; 39 ss.ss_size = SIGSTKSZ; 40 ss.ss_flags = 0; 41 CHECK(ss.ss_sp != NULL); 42 SigAltStack(&ss, NULL); 43 44 // Double-check that it worked. 45 ss.ss_sp = NULL; 46 SigAltStack(NULL, &ss); 47 VLOG(threads) << "Alternate signal stack is " << PrettySize(ss.ss_size) << " at " << ss.ss_sp; 48 } 49 50 void Thread::TearDownAlternateSignalStack() { 51 // Get the pointer so we can free the memory. 52 stack_t ss; 53 SigAltStack(NULL, &ss); 54 uint8_t* allocated_signal_stack = reinterpret_cast<uint8_t*>(ss.ss_sp); 55 56 // Tell the kernel to stop using it. 57 ss.ss_sp = NULL; 58 ss.ss_flags = SS_DISABLE; 59 ss.ss_size = SIGSTKSZ; // Avoid ENOMEM failure with Mac OS' buggy libc. 60 SigAltStack(&ss, NULL); 61 62 // Free it. 63 delete[] allocated_signal_stack; 64 } 65 66 } // namespace art 67