Commit 76d04b25 authored by Jeffrey Lee's avatar Jeffrey Lee Committed by ROOL
Browse files

Fix combined freepool + appspace shrink

When a DA tries to grow by more than the free pool size, the kernel
should try to take the necessary remaining amount from application
space. Historically this was handled as a combined "take from freepool
and appspace" operation, but with Kernel-5_35-4_79_2_284 this was
changed to use a nested call to OS_ChangeDynamicArea, so first appspace
is shrunk into the free pool and then the target DA is grown using just
the free pool.

However the code was foolishly trying to use ChangeDyn_AplSpace as the
argument to OS_ChangeDynamicArea, which that call doesn't recognise as a
valid DA number. Change it to use ChangeDyn_FreePool ("grow free pool
from appspace"), and also fix up a stack imbalance that would have
caused it to misbehave regardless of the outcome.
parent 86fe0712
......@@ -5405,17 +5405,16 @@ AreaGrow ROUT
LDR r3, =ZeroPage
MOV r0, #0
STR r0, [r3, #CDASemaphore] ; Allow nested call
RSB r1, r1, r2, LSL #12 ; free pool size minus total amount = app space size change needed
MOV r0, #ChangeDyn_AplSpace
SWI XOS_ChangeDynamicArea
SUB r1, r1, r2, LSL #12 ; total amount minus free pool size = free pool size change needed
MOV r0, #ChangeDyn_FreePool
SWI XOS_ChangeDynamicArea ; attempt to grow free pool (by shrinking appspace)
STR pc, [r3, #CDASemaphore] ; reclaim semaphore
MOVVS r1, #1
CMP r1, #0 ; if not all moved
Pull "r0-r1"
MOVNE r1, #0 ; then claim nothing moved
BNE %BT61 ; and return error
; Double-check that the free pool did actually grow large enough
; (just paranoia for now, but may be important in future)
Pull "r0-r1,r3"
MOVVS r1, #0 ; if failed, report nothing moved
BVS %BT61 ; and return error
; Check that the free pool did actually grow large enough
; (might have been a partial grow, or maybe something else claimed some
; memory while CDASemaphore was unlocked)
LDR r3, [r11, #DANode_PMPSize]
CMP r3, r1, LSR #12
MOVLO r1, #0
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment