@@ -118,6 +118,10 @@ __prepare_sig_handler:
118118 tst sp , # 0x7 @ 8 - bytes aligned
119119 bne __stack_alignment_fault
120120
121+ @ Copy TLS to the new stack frame
122+ ldr r0 , [ sp , #OFFSET_TLS_USR ]
123+ str r0 , [ sp , #( - SVC_STACK_FRAME_SIZE + OFFSET_TLS_USR) ]
124+
121125 str sp , [ sp , #( - SVC_STACK_FRAME_SIZE + OFFSET_SP) ] @ save sp
122126
123127 @ Build a new stack frame based on the current
@@ -169,7 +173,7 @@ __prepare_sig_handler:
169173@ ARM EABI: the syscall nr is stored in r7
170174. align 5
171175syscall_interrupt:
172-
176+
173177 @ At the exception entry , the stack must be 8 - byte aligned.
174178 @ If it is not the case (gcc might not respect the AAPCS convention for optimization purposes) ,
175179 @ sp will be adjusted. The original sp is preserved and will be correctly restored at the exit.
@@ -199,9 +203,13 @@ syscall_interrupt:
199203 add lr , sp , #OFFSET_SP_USR
200204 stmia lr , { sp , lr}^
201205
206+ @ Save user space TLS context
207+ mrc p15 , 0 , r0 , c13 , c0 , 0
208+ str r0 , [ sp , #OFFSET_TLS_USR ]
209+
202210 cmp r7 , #SYSCALL_sigreturn
203211 beq __after_push_sp_usr
204-
212+
205213 ldr r0 , [ sp , #OFFSET_SP_USR ]
206214 ldr r1 , .LCcurrent
207215 ldr r1 , [ r1 ]
@@ -254,6 +262,10 @@ __ret_from_fork:
254262 check_pending_signal
255263#endif / * CONFIG_IPC_SIGNAL * /
256264
265+ @ Restore user space TLS context
266+ ldr lr , [ sp , #OFFSET_TLS_USR ]
267+ mcr p15 , 0 , lr , c13 , c0 , 0
268+
257269 @ get the saved spsr and adjust the stack pointer
258270 ldr lr , [ sp , #OFFSET_PSR ]
259271 msr spsr , lr
@@ -270,14 +282,14 @@ __ret_from_fork:
270282
271283 ldmia sp , { sp , lr , pc}^
272284
273-
285+
274286
275287@ Used at entry point of a fork'd process (setting the return value to 0 )
276288ret_from_fork:
277289 mov r0 , # 0
278290
279291 b __ret_from_fork
280-
292+
281293. align 5
282294prefetch_abort:
283295
@@ -363,6 +375,10 @@ irq:
363375 addeq lr , sp , #OFFSET_SP_USR
364376 stmeqia lr , { sp , lr}^
365377
378+ @ Save user space TLS context
379+ mrc p15 , 0 , r0 , c13 , c0 , 0
380+ str r0 , [ sp , #OFFSET_TLS_USR ]
381+
366382 @ Retrieve the lr_irq to set the pc out of this routine
367383 ldr lr , [ r0 , # 4 ] @ retrieve lr_irq to set lr_svc
368384 sub lr , lr , # 4 @ Adjust the lr since it is automatically set from pc ( in advance of 2 instructions due to the pipeline)
@@ -388,6 +404,10 @@ irq:
388404 check_pending_signal
389405#endif / * CONFIG_IPC_SIGNAL * /
390406
407+ @ Restore user space TLS context
408+ ldr lr , [ sp , #OFFSET_TLS_USR ]
409+ mcr p15 , 0 , lr , c13 , c0 , 0
410+
391411 ldr lr , [ sp , #OFFSET_PSR ] @ get the saved spsr and adjust the stack pointer
392412 msr spsr , lr
393413
0 commit comments