News for hackers. Stuff that matters.
Re:Writing ARM64 Code for Apple Platforms by smoldesu on Thursday June 24, 2021 @10:29AM (#27618041)
Unless Apple can produce a sufficient explanation of why you wouldn't use that register, I see no reason why developers wouldn't.
Re:Writing ARM64 Code for Apple Platforms by aarch64 on Thursday June 24, 2021 @10:54AM (#27618509)
Here is ARM's explanation in the AAPCS64 (ARM 64-bit Architecture Procedure Call Standard):

> Software developers creating platform-independent code are advised to avoid using r18 if at all possible. Most compilers provide a mechanism to prevent specific registers from being used for general allocation; portable hand-coded assembler should avoid it entirely. It should not be assumed that treating the register as callee-saved will be sufficient to satisfy the requirements of the platform. Virtualization code must, of course, treat the register as they would any other resource provided to the virtual machine.

From: https://github.com/ARM-software/abi-aa/blob/2bcab1e3b22d5517...

Re:Writing ARM64 Code for Apple Platforms by somebody_amzn on Thursday June 24, 2021 @11:03AM (#27618642)
To elaborate:

On Darwin, x18 is used as a scratch register in context switches on hardware where Meltdown mitigations are needed.

As such, it is cleaned on each ctx switch on that hardware.

On M1, it's currently usable by applications, but that is not part of the ABI contract and might change at any time without notice.

On Windows, x18 is the TEB (thread environment block) register. It must as such _not_ be touched by apps either.

Re:Writing ARM64 Code for Apple Platforms by NobodyNada on Thursday June 24, 2021 @12:52PM (#27620320)
> On Darwin, x18 is used [...] on hardware where Meltdown mitigations are needed. [...] On M1, it's currently usable by applications

I’m confused. x18 is an ARM register, but I thought Meltdown only affected x86 chips. Were iOS devices vulnerable to Meltdown too? Or did you mean not x18 specifically but some equivalent OS-reserved x86 register?

Re:Writing ARM64 Code for Apple Platforms by somebody_amzn on Thursday June 24, 2021 @12:55PM (#27620388)
Yeah, Meltdown did affect quite some Arm CPUs, including the Cortex-A75 too.

However, due to specific features of the Arm architecture, it was patchable without a significant performance hit.

(see this section: https://siguza.github.io/KTRR/#meltdownspectre-mitigations-1..., which made the need for actually doing a page table switch avoidable)

Re:Writing ARM64 Code for Apple Platforms by NobodyNada on Thursday June 24, 2021 @01:05PM (#27620574)
Interesting, thanks for the link!
Re:Writing ARM64 Code for Apple Platforms by saagarjha on Thursday June 24, 2021 @03:21PM (#27622612)
x18 happens to also be used by Rosetta, and is restored in those cases.