@@ -310,7 +310,18 @@ static void restore_live_registers(StubAssembler* sasm, bool restore_fpu_registe
310310 __ add (sp, sp, 32 * wordSize);
311311 }
312312
313+ #ifdef R18_RESERVED
314+ /*
315+ Do not modify r18_tls when restoring registers if it is a reserved register. On Windows,
316+ for example, r18_tls is used to store the pointer to the current thread's TEB (where TLS
317+ variables are stored). Therefore, modifying r18_tls would corrupt the TEB pointer.
318+ */
319+ __ pop (RegSet::range (r0, r17), sp);
320+ __ ldp (zr, r19, Address (__ post (sp, 2 * wordSize)));
321+ __ pop (RegSet::range (r20, r29), sp);
322+ #else
313323 __ pop (RegSet::range (r0, r29), sp);
324+ #endif
314325}
315326
316327static void restore_live_registers_except_r0 (StubAssembler* sasm, bool restore_fpu_registers = true ) {
@@ -323,8 +334,20 @@ static void restore_live_registers_except_r0(StubAssembler* sasm, bool restore_f
323334 __ add (sp, sp, 32 * wordSize);
324335 }
325336
337+ #ifdef R18_RESERVED
338+ /*
339+ Do not modify r18_tls when restoring registers if it is a reserved register. On Windows,
340+ for example, r18_tls is used to store the pointer to the current thread's TEB (where TLS
341+ variables are stored). Therefore, modifying r18_tls would corrupt the TEB pointer.
342+ */
343+ __ ldp (zr, r1, Address (__ post (sp, 2 * wordSize)));
344+ __ pop (RegSet::range (r2, r17), sp);
345+ __ ldp (zr, r19, Address (__ post (sp, 2 * wordSize)));
346+ __ pop (RegSet::range (r20, r29), sp);
347+ #else
326348 __ ldp (zr, r1, Address (__ post (sp, 16 )));
327349 __ pop (RegSet::range (r2, r29), sp);
350+ #endif
328351}
329352
330353
0 commit comments