1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
;; 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 "kxarm.h"
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; DATA SECTIONS ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
__tls_array equ 0x2C ;; offsetof(TEB, ThreadLocalStoragePointer)
POINTER_SIZE equ 0x04
;; TLS variables
AREA |.tls$|, DATA
ThunkParamSlot % 0x4
TEXTAREA
EXTERN _tls_index
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Interop Thunks Helpers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; RhCommonStub
;;
NESTED_ENTRY RhCommonStub
;; Custom calling convention:
;; red zone has pointer to the current thunk's data block (data contains 2 pointer values: context + target pointers)
;; Copy red zone value into r12 so that the PROLOG_PUSH doesn't destroy it
PROLOG_NOP ldr r12, [sp, #-4]
PROLOG_PUSH {r0-r3}
;; 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
ldr r3, =_tls_index
ldr r2, [r3]
mrc p15, #0, r3, c13, c0, #2
ldr r3, [r3, #__tls_array]
ldr r2, [r3, r2, lsl #2] ;; r2 <- our TLS base
;; r2 = base address of TLS data
;; r12 = address of context cell in thunk's data
;; store thunk address in thread static
ldr r1, [r12]
ldr r3, =ThunkParamSlot
str r1, [r2, r3] ;; ThunkParamSlot <- context slot data
;; Now load the target address and jump to it.
ldr r12, [r12, #POINTER_SIZE]
EPILOG_POP {r0-r3}
bx r12
NESTED_END RhCommonStub
;;
;; IntPtr RhGetCommonStubAddress()
;;
LEAF_ENTRY RhGetCommonStubAddress
ldr r0, =RhCommonStub
bx lr
LEAF_END RhGetCommonStubAddress
;;
;; IntPtr RhGetCurrentThunkContext()
;;
LEAF_ENTRY RhGetCurrentThunkContext
ldr r3, =_tls_index
ldr r2, [r3]
mrc p15, #0, r3, c13, c0, #2
ldr r3, [r3, #__tls_array]
ldr r2, [r3, r2, lsl #2] ;; r2 <- our TLS base
ldr r3, =ThunkParamSlot
ldr r0, [r2, r3] ;; r0 <- ThunkParamSlot
bx lr
LEAF_END RhGetCurrentThunkContext
END
|