Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/corert.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFaizur Rahman <shrah@microsoft.com>2017-02-20 05:22:59 +0300
committerFaizur Rahman <shrah@microsoft.com>2017-02-23 23:00:20 +0300
commit61dbdc79b0ae4f33a48869d9d72cc40a0777ee1c (patch)
treecaa9e700accc6321be90ac384cda025376e30913 /src/Native/Runtime/amd64
parent4d2c17183d335ab54b1b3ead2985c3469bc0de63 (diff)
Delegate Marshalling
Initital support for delegate marshalling. - Enabled only in full runtime - Doesn't work in non-windows platforms - Only supports open static delegates
Diffstat (limited to 'src/Native/Runtime/amd64')
-rw-r--r--src/Native/Runtime/amd64/InteropThunksHelpers.S22
-rw-r--r--src/Native/Runtime/amd64/InteropThunksHelpers.asm101
2 files changed, 123 insertions, 0 deletions
diff --git a/src/Native/Runtime/amd64/InteropThunksHelpers.S b/src/Native/Runtime/amd64/InteropThunksHelpers.S
new file mode 100644
index 000000000..e6b7c67ce
--- /dev/null
+++ b/src/Native/Runtime/amd64/InteropThunksHelpers.S
@@ -0,0 +1,22 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+.intel_syntax noprefix
+#include <unixasmmacros.inc>
+
+//TODO: Implement these stub method for non-windows
+
+LEAF_ENTRY RhpCommonStub, _TEXT
+ int 3
+LEAF_END RhpCommonStub, _TEXT
+
+
+LEAF_ENTRY RhpGetCommonStubAddress, _TEXT
+ int 3
+LEAF_END RhpGetCommonStubAddress, _TEXT
+
+
+LEAF_ENTRY RhpGetCurrentThunkContext, _TEXT
+ int 3
+LEAF_END RhpGetCurrentThunkContext, _TEXT \ No newline at end of file
diff --git a/src/Native/Runtime/amd64/InteropThunksHelpers.asm b/src/Native/Runtime/amd64/InteropThunksHelpers.asm
new file mode 100644
index 000000000..eb694cf73
--- /dev/null
+++ b/src/Native/Runtime/amd64/InteropThunksHelpers.asm
@@ -0,0 +1,101 @@
+;; Licensed to the .NET Foundation under one or more agreements.
+;; The .NET Foundation licenses this file to you under the MIT license.
+;; See the LICENSE file in the project root for more information.
+
+
+;; -----------------------------------------------------------------------------------------------------------
+;;#include "asmmacros.inc"
+;; -----------------------------------------------------------------------------------------------------------
+
+LEAF_ENTRY macro Name, Section
+ Section segment para 'CODE'
+ align 16
+ public Name
+ Name proc
+endm
+
+LEAF_END macro Name, Section
+ Name endp
+ Section ends
+endm
+
+; - TAILCALL_RAX: ("jmp rax") should be used for tailcalls, this emits an instruction
+; sequence which is recognized by the unwinder as a valid epilogue terminator
+TAILJMP_RAX TEXTEQU <DB 048h, 0FFh, 0E0h>
+
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; DATA SECTIONS ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+_tls_array equ 58h ;; offsetof(TEB, ThreadLocalStoragePointer)
+
+POINTER_SIZE equ 08h
+
+;; TLS variables
+_TLS SEGMENT ALIAS(".tls$")
+ ThunkParamSlot DQ 0000000000000000H
+_TLS ENDS
+
+EXTRN _tls_index:DWORD
+
+
+;;;;;;;;;;;;;;;;;;;;;;; Interop Thunks Helpers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;;
+;; RhpCommonStub
+;;
+LEAF_ENTRY RhpCommonStub, _TEXT
+ ;; There are arbitrary callers passing arguments with arbitrary signatures.
+ ;; Custom calling convention:
+ ;; r10: pointer to the current thunk's data block (data contains 2 pointer values: context + target pointers)
+
+ ;; Save context data into the ThunkParamSlot thread-local variable
+ ;; A pointer to the delegate and function pointer for open static delegate should have been saved in the thunk's context cell during thunk allocation
+ mov [rsp + 8], rcx ;; Save rcx in a home scratch location. Pushing the
+ ;; register on the stack will break callstack unwind
+ mov ecx, [_tls_index]
+ mov r11, gs:[_tls_array]
+ mov rax, [r11 + rcx * POINTER_SIZE]
+
+ mov rcx, [rsp + 8] ;; Restore rcx
+
+ ;; rax = base address of TLS data
+ ;; r10 = address of context cell in thunk's data
+ ;; r11 = trashed
+ ;; r12 = trashed
+
+ ;; store thunk address in thread static
+ mov r11, [r10]
+ xor r8, r8
+ mov r8d, SECTIONREL ThunkParamSlot
+ mov [rax + r8], r11 ;; ThunkParamSlot <- context slot data
+
+ ;; jump to the target
+ mov rax, [r10 + POINTER_SIZE]
+ TAILJMP_RAX
+LEAF_END RhpCommonStub, _TEXT
+
+
+;;
+;; IntPtr RhpGetCommonStubAddress()
+;;
+LEAF_ENTRY RhpGetCommonStubAddress, _TEXT
+ lea rax, [RhpCommonStub]
+ ret
+LEAF_END RhpGetCommonStubAddress, _TEXT
+
+
+;;
+;; IntPtr RhpGetCurrentThunkContext()
+;;
+LEAF_ENTRY RhpGetCurrentThunkContext, _TEXT
+ mov r10d, [_tls_index]
+ mov r11, gs:[_tls_array]
+ mov r10, [r11 + r10 * POINTER_SIZE]
+ xor r8, r8
+ mov r8d, SECTIONREL ThunkParamSlot
+ mov rax, [r10 + r8] ;; rax <- ThunkParamSlot
+ ret
+LEAF_END RhpGetCurrentThunkContext, _TEXT
+
+
+end