Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/coreclr/vm/arm64/PInvokeStubs.asm
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,6 @@ RarePath

LEAF_END

INLINE_GETTHREAD_CONSTANT_POOL

; ------------------------------------------------------------------
; VarargPInvokeStub & VarargPInvokeGenILStub
;
Expand Down
51 changes: 22 additions & 29 deletions src/coreclr/vm/arm64/asmmacros.h
Original file line number Diff line number Diff line change
Expand Up @@ -313,52 +313,45 @@ __RedirectionFuncName SETS "|?RedirectedHandledJITCaseFor":CC:"$reason":CC:"@Thr

MEND

;-----------------------------------------------------------------------------
; Macro to get a pointer to the Thread* object for the currently executing thread
;
__tls_array equ 0x58 ;; offsetof(TEB, ThreadLocalStoragePointer)
;; -----------------------------------------------------------------------------
;;
;; Macro to get a pointer to a threadlocal symbol for the currently executing thread
;;

EXTERN _tls_index

GBLS __SECTIONREL_gCurrentThreadInfo
__SECTIONREL_gCurrentThreadInfo SETS "SECTIONREL_gCurrentThreadInfo"
__tls_array equ 0x58 ;; offsetof(TEB, ThreadLocalStoragePointer)

MACRO
INLINE_GETTHREAD $destReg, $trashReg
INLINE_GET_TLS_VAR $destReg, $trashReg, $variable

EXTERN _tls_index

;; The following macro variables are just some assembler magic to get the name of the 32-bit version
;; of $trashReg. It does it by string manipulation. Replaces something like x3 with w3.
LCLS TrashRegister32Bit
TrashRegister32Bit SETS "$trashReg"
TrashRegister32Bit SETS "w":CC:("$TrashRegister32Bit":RIGHT:((:LEN:TrashRegister32Bit) - 1))

ldr $trashReg, =_tls_index
ldr $TrashRegister32Bit, [$trashReg]
adrp $destReg, _tls_index
ldr $TrashRegister32Bit, [$destReg, _tls_index]
ldr $destReg, [xpr, #__tls_array]
ldr $destReg, [$destReg, $trashReg lsl #3]
ldr $trashReg, =$__SECTIONREL_gCurrentThreadInfo
ldr $trashReg, [$trashReg]
ldr $destReg, [$destReg, $trashReg] ; return gCurrentThreadInfo.m_pThread
ldr $destReg, [$destReg, $TrashRegister32Bit uxtw #3]
add $destReg, $destReg, #0, lsl #0xC
RELOC 0xA, $variable ;; IMAGE_REL_ARM64_SECREL_HIGH12A
add $destReg, $destReg, #0, lsl #0
RELOC 0x9, $variable ;; IMAGE_REL_ARM64_SECREL_LOW12A
MEND

;-----------------------------------------------------------------------------
; INLINE_GETTHREAD_CONSTANT_POOL macro has to be used after the last function in the .asm file that used
; INLINE_GETTHREAD. Optionally, it can be also used after any function that used INLINE_GETTHREAD
; to improve density, or to reduce distance between the constant pool and its use.
;
;; -----------------------------------------------------------------------------
;;
;; Macro to get a pointer to the Thread* object for the currently executing thread
;;
SETALIAS gCurrentThreadInfo, ?gCurrentThreadInfo@@3UThreadLocalInfo@@A

MACRO
INLINE_GETTHREAD_CONSTANT_POOL
INLINE_GETTHREAD $destReg, $trashReg

EXTERN $gCurrentThreadInfo

;; Section relocs are 32 bits. Using an extra DCD initialized to zero for 8-byte alignment.
$__SECTIONREL_gCurrentThreadInfo
DCD $gCurrentThreadInfo
RELOC 8, $gCurrentThreadInfo ;; SECREL
DCD 0

__SECTIONREL_gCurrentThreadInfo SETS "$__SECTIONREL_gCurrentThreadInfo":CC:"_"

INLINE_GET_TLS_VAR $destReg, $trashReg, $gCurrentThreadInfo
ldr $destReg, [$destReg] ;; return gCurrentThreadInfo.m_pThread

@VSadov VSadov Mar 13, 2024 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@EgorBo @mangod9 @jkotas as an example - this indirection would not be needed in NativeAOT as there is no ThreadInfo referring to Thread.
Instead the Thread itself is a tls object and the allocation context is inlined in it as first few fields.

Re: #99661

MEND