Commit Graph

4 Commits

Author SHA1 Message Date
Pierre-Clément Tosi bfe4831212 vmbase: Handle stack overflows
Allocate the first page of the writable_data region for a stack to be
used by the exception handlers so that faults caused by accesses to the
SP from the main thread can be handled. As fault handlers push the
register file to the stack on entry, we would previously enter an
exception loop on stack overflow.

This works by reserving SP_EL0 for the "main" thread and relying on
current_exception_sp0 (from exceptions.S) switching to SP_EL1 when
taking an exception. SP_EL1 is first initialized to the bottom of the
newly allocated page while SP_EL0 is initialized to the value previously
used (note that SP_EL0 was previously unused).

Use the linker script to ensure that there is always at least one full
page between the end of .bss and the top (i.e. smallest address) of the
stack, in order to guarantee a permission fault on stack overflow, if
the MMU has been set properly.

Rely on the fact that the page preceding the page containing the EH
stack isn't mapped R/W to catch EH stack overflows (which would still
end up in an exception loop).

Bug: 279209532
Test: atest MicrodroidTests
Change-Id: Ie5a8dc06348bfb7db2742b1affec4d162d8b538c
Merged-In: Ie5a8dc06348bfb7db2742b1affec4d162d8b538c
2023-05-09 13:28:47 +00:00
Pierre-Clément Tosi 150ebc904e vmbase: Move stack to end of writable_data
Instead of imposing an arbitrary size for the stack, allows clients to
query a validated address range of a given size with boot_stack_range(),
which places the stack at the largest address possible, extending
downwards (common on AArch64).

Keep allocating 40 pages of stack in vmbase_example, rialto, and pvmfw.

Bug: 279209532
Bug: 270684188
Test: atest vmbase_example.integration_test
Test: atest rialto_test
Test: atest MicrodroidTests
Change-Id: If205ccd4fa408e32e5533b880a85f4cccbd3f005
Merged-In: If205ccd4fa408e32e5533b880a85f4cccbd3f005
2023-05-09 13:28:47 +00:00
Pierre-Clément Tosi 3c6d4d4fc6 vmbase: sections.ld: Fix bin_end as LMA
As the location counter seems to keep counting from the VMA addresses
(in the writable_data MEMORY), manually compute the linker variable to
ensure that it points to the actual end of the binary, in the image
MEMORY.

Bug: 238050226
Test: atest vmbase_example.integration_test
Change-Id: I00616aaebee82a82e2860ce22966a40e374d49c0
2022-10-17 12:56:50 +01:00
Andrew Walbran a5b7af5b4b Split out common part of linker script.
Bug: 223166344
Test: atest vmbase_example.integration_test
Change-Id: Idaf10e631ba33fcc7026c4e2f603778186215667
2022-07-07 17:57:22 +00:00