Merge "Partial inlining of the stub check." into ics-mr1-plus-art
diff --git a/src/logging.cc b/src/logging.cc
index 4aacd3b..b0f3055 100644
--- a/src/logging.cc
+++ b/src/logging.cc
@@ -55,7 +55,7 @@
// Abort if necessary.
if (data_->severity == FATAL) {
- Runtime::Abort(data_->file, data_->line_number);
+ Runtime::Abort();
}
delete data_;
diff --git a/src/runtime.cc b/src/runtime.cc
index 37887e2..3f80260 100644
--- a/src/runtime.cc
+++ b/src/runtime.cc
@@ -146,7 +146,7 @@
return abort_lock;
}
-void Runtime::Abort(const char* file, int line) {
+void Runtime::Abort() {
// Ensure that we don't have multiple threads trying to abort at once,
// which would result in significantly worse diagnostics.
MutexLock mu(GetAbortLock());
@@ -159,10 +159,7 @@
AbortState state;
LOG(INTERNAL_FATAL) << Dumpable<AbortState>(state);
- // Perform any platform-specific pre-abort actions.
- PlatformAbort(file, line);
-
- // use abort hook if we have one
+ // Call the abort hook if we have one.
if (Runtime::Current() != NULL && Runtime::Current()->abort_ != NULL) {
Runtime::Current()->abort_();
// notreached
diff --git a/src/runtime.h b/src/runtime.h
index dc61b15..b682b67 100644
--- a/src/runtime.h
+++ b/src/runtime.h
@@ -120,7 +120,7 @@
// This isn't marked ((noreturn)) because then gcc will merge multiple calls
// in a single function together. This reduces code size slightly, but means
// that the native stack trace we get may point at the wrong call site.
- static void Abort(const char* file, int line);
+ static void Abort();
// Attaches the calling native thread to the runtime.
void AttachCurrentThread(const char* thread_name, bool as_daemon, Object* thread_group);
@@ -246,7 +246,6 @@
void SetCompileTimeClassPath(const ClassLoader* class_loader, std::vector<const DexFile*>& class_path);
private:
- static void PlatformAbort(const char*, int);
static void InitPlatformSignalHandlers();
Runtime();
diff --git a/src/runtime_android.cc b/src/runtime_android.cc
index b64f8a1..2013294 100644
--- a/src/runtime_android.cc
+++ b/src/runtime_android.cc
@@ -18,10 +18,6 @@
namespace art {
-void Runtime::PlatformAbort(const char*, int) {
- // On a device, debuggerd will give us a stack trace. Nothing to do here.
-}
-
void Runtime::InitPlatformSignalHandlers() {
// On a device, debuggerd will give us a stack trace. Nothing to do here.
}
diff --git a/src/runtime_linux.cc b/src/runtime_linux.cc
index c4d4b3c..b7e7d01 100644
--- a/src/runtime_linux.cc
+++ b/src/runtime_linux.cc
@@ -56,11 +56,11 @@
}
// backtrace_symbols(3) gives us lines like this:
- // "/usr/local/google/home/enh/a1/out/host/linux-x86/bin/../lib/libartd.so(_ZN3art7Runtime13PlatformAbortEPKci+0x15b) [0xf76c5af3]"
+ // "/usr/local/google/home/enh/a1/out/host/linux-x86/bin/../lib/libartd.so(_ZN3art7Runtime5AbortEPKci+0x15b) [0xf76c5af3]"
// "[0xf7b62057]"
// We extract the pieces and demangle, so we can produce output like this:
- // libartd.so:-1] #00 art::Runtime::PlatformAbort(char const*, int) +0x15b [0xf770dd51]
+ // libartd.so:-1] #00 art::Runtime::Abort(char const*, int) +0x15b [0xf770dd51]
for (size_t i = 0; i < frame_count; ++i) {
std::string text(symbols[i]);
@@ -180,6 +180,9 @@
signal_name = "SIGPIPE";
}
+ // Remove ourselves as signal handler for this signal, in case of recursion.
+ signal(signal_number, SIG_DFL);
+
LOG(INTERNAL_FATAL) << "*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***\n"
<< StringPrintf("Fatal signal %d (%s), code %d (%s)",
signal_number, signal_name,
@@ -200,11 +203,6 @@
}
}
-void Runtime::PlatformAbort(const char* /*file*/, int /*line_number*/) {
- // On the host, we don't have debuggerd to dump a stack for us when we LOG(FATAL).
- Backtrace();
-}
-
void Runtime::InitPlatformSignalHandlers() {
// On the host, we don't have debuggerd to dump a stack for us when something unexpected happens.
struct sigaction action;
diff --git a/src/thread_x86.cc b/src/thread_x86.cc
index 73b0465..30d19d4 100644
--- a/src/thread_x86.cc
+++ b/src/thread_x86.cc
@@ -26,6 +26,13 @@
#if defined(__APPLE__)
#include <architecture/i386/table.h>
#include <i386/user_ldt.h>
+struct descriptor_table_entry_t {
+ uint16_t limit0;
+ uint16_t base0;
+ unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
+ unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
+} __attribute__((packed));
+#define MODIFY_LDT_CONTENTS_DATA 0
#else
#include <asm/ldt.h>
#endif
@@ -33,53 +40,88 @@
namespace art {
void Thread::InitCpu() {
-#if defined(__APPLE__)
- UNIMPLEMENTED(WARNING);
-#else
static Mutex modify_ldt_lock("modify_ldt lock");
MutexLock mu(modify_ldt_lock);
- // Read LDT
+ const uintptr_t base = reinterpret_cast<uintptr_t>(this);
+ const size_t limit = kPageSize;
+
+ const int contents = MODIFY_LDT_CONTENTS_DATA;
+ const int seg_32bit = 1;
+ const int read_exec_only = 0;
+ const int limit_in_pages = 0;
+ const int seg_not_present = 0;
+ const int useable = 1;
+
+ int entry_number = -1;
+
+#if defined(__APPLE__)
+ descriptor_table_entry_t entry;
+ memset(&entry, 0, sizeof(entry));
+ entry.limit0 = (limit & 0x0ffff);
+ entry.limit = (limit & 0xf0000) >> 16;
+ entry.base0 = (base & 0x0000ffff);
+ entry.base1 = (base & 0x00ff0000) >> 16;
+ entry.base2 = (base & 0xff000000) >> 24;
+ entry.type = ((read_exec_only ^ 1) << 1) | (contents << 2);
+ entry.s = 1;
+ entry.dpl = 0x3;
+ entry.p = seg_not_present ^ 1;
+ entry.avl = useable;
+ entry.l = 0;
+ entry.d = seg_32bit;
+ entry.g = limit_in_pages;
+
+ entry_number = i386_set_ldt(LDT_AUTO_ALLOC, (ldt_entry*)(void*)(&entry), 1);
+ if (entry_number == -1) {
+ PLOG(FATAL) << "i386_set_ldt failed";
+ }
+#else
+ // Read current LDT entries.
CHECK_EQ((size_t)LDT_ENTRY_SIZE, sizeof(uint64_t));
std::vector<uint64_t> ldt(LDT_ENTRIES);
size_t ldt_size(sizeof(uint64_t) * ldt.size());
memset(&ldt[0], 0, ldt_size);
+ // TODO: why doesn't this return LDT_ENTRY_SIZE * LDT_ENTRIES for the main thread?
syscall(__NR_modify_ldt, 0, &ldt[0], ldt_size);
- // Create empty slot to point at current Thread*
+
+ // Find the first empty slot.
+ for (entry_number = 0; entry_number < LDT_ENTRIES && ldt[entry_number] != 0; ++entry_number) {
+ }
+ if (entry_number >= LDT_ENTRIES) {
+ LOG(FATAL) << "Failed to find a free LDT slot";
+ }
+
+ // Update LDT entry.
user_desc ldt_entry;
memset(&ldt_entry, 0, sizeof(ldt_entry));
- ldt_entry.entry_number = -1;
- ldt_entry.base_addr = (unsigned int)this;
- ldt_entry.limit = kPageSize;
- ldt_entry.seg_32bit = 1;
- ldt_entry.contents = MODIFY_LDT_CONTENTS_DATA;
- ldt_entry.read_exec_only = 0;
- ldt_entry.limit_in_pages = 0;
- ldt_entry.seg_not_present = 0;
- ldt_entry.useable = 1;
- for (int i = 0; i < LDT_ENTRIES; i++) {
- if (ldt[i] == 0) {
- ldt_entry.entry_number = i;
- break;
- }
- }
- if (ldt_entry.entry_number >= LDT_ENTRIES) {
- LOG(FATAL) << "Failed to find available LDT slot";
- }
- // Update LDT
+ ldt_entry.entry_number = entry_number;
+ ldt_entry.base_addr = base;
+ ldt_entry.limit = limit;
+ ldt_entry.seg_32bit = seg_32bit;
+ ldt_entry.contents = contents;
+ ldt_entry.read_exec_only = read_exec_only;
+ ldt_entry.limit_in_pages = limit_in_pages;
+ ldt_entry.seg_not_present = seg_not_present;
+ ldt_entry.useable = useable;
CHECK_EQ(0, syscall(__NR_modify_ldt, 1, &ldt_entry, sizeof(ldt_entry)));
- // Change FS to be new LDT entry
+ entry_number = ldt_entry.entry_number;
+#endif
+
+ // Change %fs to be new LDT entry.
uint16_t table_indicator = 1 << 2; // LDT
uint16_t rpl = 3; // Requested privilege level
- uint16_t selector = (ldt_entry.entry_number << 3) | table_indicator | rpl;
+ uint16_t selector = (entry_number << 3) | table_indicator | rpl;
// TODO: use our assembler to generate code
asm volatile("movw %w0, %%fs"
: // output
: "q"(selector) // input
:); // clobber
- // Allow easy indirection back to Thread*
+
+ // Allow easy indirection back to Thread*.
self_ = this;
- // Sanity check reads from FS goes to this Thread*
+
+ // Sanity check that reads from %fs point to this Thread*.
Thread* self_check;
// TODO: use our assembler to generate code
CHECK_EQ(THREAD_SELF_OFFSET, OFFSETOF_MEMBER(Thread, self_));
@@ -88,7 +130,6 @@
: "r"(THREAD_SELF_OFFSET) // input
:); // clobber
CHECK_EQ(self_check, this);
-#endif
}
} // namespace art