-
Notifications
You must be signed in to change notification settings - Fork 1
Working 64-bit MinGW build with Scons #49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
cf17af0
scons: CPPDEFINES instead of /D flag in one spot
slipher 915943c
Windows: Add winmm to always-linked system libs
slipher 629b03d
scons: remove unused forced include machinery
slipher e33a011
tests/run_py/nacl.scons: move PATH changes to end
slipher 4c3de6a
scons: implement build with (mostly) MinGW
slipher 2e76830
Port nacl_switch_unwind_win.asm to GNU syntax
slipher a7539d0
README: MinGW build
slipher File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
src/trusted/service_runtime/arch/x86_64/nacl_switch_unwind_win.S
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| // Ported to GNU syntax from nacl_switch_unwind_win.asm | ||
| // used this random GCC assembly dump from reddit as a template for SEH directives... | ||
| // https://www.reddit.com/r/Assembly_language/comments/1cc94of/what_do_the_seh_tags_mean/ | ||
|
|
||
| // Copyright (c) 2012 The Native Client Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| #include "native_client/src/include/nacl_asm.h" | ||
|
|
||
| #define push_reg(R) push R; .seh_pushreg R; | ||
|
|
||
| .text | ||
|
|
||
| // This routine passes control on to NaClSwitch(), after setting up a | ||
| // trusted stack that will later be used for running | ||
| // NaClSyscallCSegHook(). The stack is set up so that it can be | ||
| // unwound, which involves storing a return address with unwind info. | ||
| // To generate unwind info, we need to use Microsoft's x86-64 | ||
| // assembler. | ||
| // | ||
| // We want to make the stack unwindable so that a last-chance exception | ||
| // handler registered with SetUnhandledExceptionFilter() -- in | ||
| // particular, Breakpad's handler -- will get called when a hardware | ||
| // exception occurs. x86-64 Windows uses stack unwinding to find | ||
| // exception handlers, and the last-chance handler is not guaranteed to | ||
| // get called if the stack is malformed. For background, see: | ||
| // http://code.google.com/p/nativeclient/issues/detail?id=2237 | ||
| // http://code.google.com/p/nativeclient/issues/detail?id=2414 | ||
|
|
||
| // Arg 1 (rcx): user_context (&natp->user), passed on to NaClSwitch() | ||
| // Arg 2 (rdx): address of natp->user.trusted_stack_ptr | ||
| .seh_proc NaclSwitchSavingStackPtr | ||
| DEFINE_GLOBAL_HIDDEN_FUNCTION(NaClSwitchSavingStackPtr): | ||
| // Save all callee-saved registers. This is necessary in case | ||
| // the caller is using a frame pointer. The Windows ABI | ||
| // permits the caller to use any callee-saved register as a | ||
| // frame pointer, not just rbp, so we have to save them all. | ||
| push_reg(%rbp) | ||
| push_reg(%r12) | ||
| push_reg(%r13) | ||
| push_reg(%r14) | ||
| push_reg(%r15) | ||
| push_reg(%rdi) | ||
| push_reg(%rsi) | ||
| push_reg(%rbx) | ||
| // Allocate 0x20 bytes for the shadow space, plus an additional | ||
| // 8 bytes to align the stack pointer. | ||
| sub $0x28, %rsp | ||
| .seh_stackalloc 0x28 | ||
| .seh_endprologue | ||
| // Save rsp-8 in struct NaClThreadContext. | ||
| // i.e. Save the value of rsp as it will appear after the | ||
| // return address is pushed by the 'call' instruction. | ||
| mov %rsp, %r12 | ||
| sub $8, %r12 | ||
| mov %r12, 0(%rdx) | ||
|
|
||
| call *IDENTIFIER(NaClSwitch)(%rip) | ||
|
|
||
| // We get here after returning from a system call. | ||
| // NaClSyscallCSegHook returned the struct NaClThreadContext | ||
| // pointer. Now make that the argument to the NaClSwitch | ||
| // function. Note that the address of this instruction, pushed | ||
| // by the call above as its return address, stays at the top of | ||
| // the trusted stack. It will be reused again and again, as | ||
| // the return address when NaClSyscallCSegHook returns after | ||
| // each system call. Hence it's important to use a jmp rather | ||
| // than a call here, so that this return address is not clobbered. | ||
| // The NaClSwitch functions never look at the incoming | ||
| // (trusted) stack--they immediately switch the rsp to the | ||
| // untrusted stack pointer--so they don't care whether they're | ||
| // entered via call or jmp. | ||
| mov %rax, %rcx | ||
| jmp *IDENTIFIER(NaClSwitch)(%rip) | ||
| .seh_endproc |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.