Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(37)

Side by Side Diff: src/ia32/macro-assembler-ia32.cc

Issue 1637015: Add stack alignment check to ia32 and x64 (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 10 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/ia32/macro-assembler-ia32.h ('k') | src/platform-linux.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2009 the V8 project authors. All rights reserved. 1 // Copyright 2006-2009 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 1517 matching lines...) Expand 10 before | Expand all | Expand 10 after
1528 1528
1529 void MacroAssembler::Check(Condition cc, const char* msg) { 1529 void MacroAssembler::Check(Condition cc, const char* msg) {
1530 Label L; 1530 Label L;
1531 j(cc, &L, taken); 1531 j(cc, &L, taken);
1532 Abort(msg); 1532 Abort(msg);
1533 // will not return here 1533 // will not return here
1534 bind(&L); 1534 bind(&L);
1535 } 1535 }
1536 1536
1537 1537
1538 void MacroAssembler::CheckStackAlignment() {
1539 int frame_alignment = OS::ActivationFrameAlignment();
1540 int frame_alignment_mask = frame_alignment - 1;
1541 if (frame_alignment > kPointerSize) {
1542 ASSERT(IsPowerOf2(frame_alignment));
1543 Label alignment_as_expected;
1544 test(esp, Immediate(frame_alignment_mask));
1545 j(zero, &alignment_as_expected);
1546 // Abort if stack is not aligned.
1547 int3();
1548 bind(&alignment_as_expected);
1549 }
1550 }
1551
1552
1538 void MacroAssembler::Abort(const char* msg) { 1553 void MacroAssembler::Abort(const char* msg) {
1539 // We want to pass the msg string like a smi to avoid GC 1554 // We want to pass the msg string like a smi to avoid GC
1540 // problems, however msg is not guaranteed to be aligned 1555 // problems, however msg is not guaranteed to be aligned
1541 // properly. Instead, we pass an aligned pointer that is 1556 // properly. Instead, we pass an aligned pointer that is
1542 // a proper v8 smi, but also pass the alignment difference 1557 // a proper v8 smi, but also pass the alignment difference
1543 // from the real pointer as a smi. 1558 // from the real pointer as a smi.
1544 intptr_t p1 = reinterpret_cast<intptr_t>(msg); 1559 intptr_t p1 = reinterpret_cast<intptr_t>(msg);
1545 intptr_t p0 = (p1 & ~kSmiTagMask) + kSmiTag; 1560 intptr_t p0 = (p1 & ~kSmiTagMask) + kSmiTag;
1546 ASSERT(reinterpret_cast<Object*>(p0)->IsSmi()); 1561 ASSERT(reinterpret_cast<Object*>(p0)->IsSmi());
1547 #ifdef DEBUG 1562 #ifdef DEBUG
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
1627 void MacroAssembler::CallCFunction(ExternalReference function, 1642 void MacroAssembler::CallCFunction(ExternalReference function,
1628 int num_arguments) { 1643 int num_arguments) {
1629 // Trashing eax is ok as it will be the return value. 1644 // Trashing eax is ok as it will be the return value.
1630 mov(Operand(eax), Immediate(function)); 1645 mov(Operand(eax), Immediate(function));
1631 CallCFunction(eax, num_arguments); 1646 CallCFunction(eax, num_arguments);
1632 } 1647 }
1633 1648
1634 1649
1635 void MacroAssembler::CallCFunction(Register function, 1650 void MacroAssembler::CallCFunction(Register function,
1636 int num_arguments) { 1651 int num_arguments) {
1652 // Check stack alignment.
1653 if (FLAG_debug_code) {
1654 CheckStackAlignment();
1655 }
1656
1637 call(Operand(function)); 1657 call(Operand(function));
1638 if (OS::ActivationFrameAlignment() != 0) { 1658 if (OS::ActivationFrameAlignment() != 0) {
1639 mov(esp, Operand(esp, num_arguments * kPointerSize)); 1659 mov(esp, Operand(esp, num_arguments * kPointerSize));
1640 } else { 1660 } else {
1641 add(Operand(esp), Immediate(num_arguments * sizeof(int32_t))); 1661 add(Operand(esp), Immediate(num_arguments * sizeof(int32_t)));
1642 } 1662 }
1643 } 1663 }
1644 1664
1645 1665
1646 CodePatcher::CodePatcher(byte* address, int size) 1666 CodePatcher::CodePatcher(byte* address, int size)
1647 : address_(address), size_(size), masm_(address, size + Assembler::kGap) { 1667 : address_(address), size_(size), masm_(address, size + Assembler::kGap) {
1648 // Create a new macro assembler pointing to the address of the code to patch. 1668 // Create a new macro assembler pointing to the address of the code to patch.
1649 // The size is adjusted with kGap on order for the assembler to generate size 1669 // The size is adjusted with kGap on order for the assembler to generate size
1650 // bytes of instructions without failing with buffer size constraints. 1670 // bytes of instructions without failing with buffer size constraints.
1651 ASSERT(masm_.reloc_info_writer.pos() == address_ + size_ + Assembler::kGap); 1671 ASSERT(masm_.reloc_info_writer.pos() == address_ + size_ + Assembler::kGap);
1652 } 1672 }
1653 1673
1654 1674
1655 CodePatcher::~CodePatcher() { 1675 CodePatcher::~CodePatcher() {
1656 // Indicate that code has changed. 1676 // Indicate that code has changed.
1657 CPU::FlushICache(address_, size_); 1677 CPU::FlushICache(address_, size_);
1658 1678
1659 // Check that the code was patched as expected. 1679 // Check that the code was patched as expected.
1660 ASSERT(masm_.pc_ == address_ + size_); 1680 ASSERT(masm_.pc_ == address_ + size_);
1661 ASSERT(masm_.reloc_info_writer.pos() == address_ + size_ + Assembler::kGap); 1681 ASSERT(masm_.reloc_info_writer.pos() == address_ + size_ + Assembler::kGap);
1662 } 1682 }
1663 1683
1664 1684
1665 } } // namespace v8::internal 1685 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/ia32/macro-assembler-ia32.h ('k') | src/platform-linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698