Commit 1a3c927f authored by Jeffrey Lee's avatar Jeffrey Lee Committed by ROOL
Browse files

Fix GrowFreePool

Buggy since its introduction in Kernel-5_35-4_79_2_284, GrowFreePool was
attempting to grow the free pool by shrinking application space, an
operation which OS_ChangeDynamicArea doesn't support. Change it to grow
the free pool instead, and fix a couple of other issues that would have
caused it to work incorrectly (register corruption causing it to request
a size change of zero, and incorrect assumption that
OS_ChangeDynamicArea returns the amount unmoved, when really it returns
the amount moved)
parent 76d04b25
...@@ -5607,40 +5607,35 @@ GrowFreePool ROUT ...@@ -5607,40 +5607,35 @@ GrowFreePool ROUT
; Check to see if there's already enough space ; Check to see if there's already enough space
LDR r11, =ZeroPage+FreePoolDANode LDR r11, =ZeroPage+FreePoolDANode
LDR r2, [r11, #DANode_PMPSize] LDR r2, [r11, #DANode_PMPSize]
SUBS r0, r2, r1 CMP r2, r1
BHS %FT90 EXIT CS
[ ShrinkableDAs [ ShrinkableDAs
; Try and shrink shrinkables ; Try and shrink shrinkables
CLC
BL TryToShrinkShrinkables BL TryToShrinkShrinkables
EXIT CS EXIT CS
SUB r0, r2, r1 ; Update how many pages still needed
] ]
; Try shrinking application space, if r12 != appspace ; Try shrinking application space, if r12 != appspace
LDR lr, [r12, #DANode_Number] LDR lr, [r12, #DANode_Number]
CMP lr, #ChangeDyn_AplSpace CMP lr, #ChangeDyn_AplSpace
BEQ %FT80 BEQ %FT80
SUB r0, r1, r2
LDR r2, [r11, #CDASemaphore-FreePoolDANode] LDR r2, [r11, #CDASemaphore-FreePoolDANode]
MOV r0, #0 MOV r0, #0
STR r0, [r11, #CDASemaphore-FreePoolDANode] ; Allow nested call STR r0, [r11, #CDASemaphore-FreePoolDANode] ; Allow nested call
CMN r0, #DynArea_PMP_BigPageCount ; r0 is negative CMP r1, #DynArea_PMP_BigPageCount
MOVGT r1, r0, LSL #12 MOVLT r1, r1, LSL #12
LDRLE r1, =-DynArea_PMP_BigByteCount LDRGE r1, =DynArea_PMP_BigByteCount
MOV r0, #ChangeDyn_AplSpace MOV r0, #ChangeDyn_FreePool ; shrink appspace by growing free pool
SWI XOS_ChangeDynamicArea SWI XOS_ChangeDynamicArea
STR r2, [r11, #CDASemaphore-FreePoolDANode] ; reclaim semaphore STR r2, [r11, #CDASemaphore-FreePoolDANode] ; reclaim semaphore
MOVVS r1, #1 LDR r2, [r11, #DANode_PMPSize]
CMP r1, #0 ; if all moved FRAMLDR r1
BEQ %FT90 ; then success CMP r2, r1 ; Free pool >= desired size?
; Fall through... EXIT
80 80
CLC CLC
EXIT EXIT
90
SEC
EXIT
[ ShrinkableDAs [ ShrinkableDAs
; *********************************************************************************** ; ***********************************************************************************
; ;
......
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