Skip to content

Stack protection idea #167

@stevesims

Description

@stevesims

On boot, MOS will set up a stack. As MOS runs in ADL mode, this means the underlying SPL register is set up to point to that stack, which is presented as the SP register to ADL-mode code.

No stack is set up for Z80 mode code, i.e. the underlying SPS register is not set up. Thus programs run in Z80 mode should consider the SP register as undefined on startup.

To protect the MOS stack, on running a new ADL-mode program MOS could create a new stack by allocating a chunk of memory on the heap, and set SP to point to that before running the program, saving the current MOS stack pointer. Once execution has been returned from the program, the original MOS stack can be restored.

As part of this idea, it may be worth considering whether making an API call from code running in ADL-mode should just use the SP as-is, using the program's stack, or whether it should swap it out for the saved MOS stack pointer.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions