On Thu, Nov 04, 2021 at 07:13:35AM +0100, overcq wrote:
> Theo de Raadt <[email protected]> wrote:
>
> > overcq <[email protected]> wrote:
> >>> I don't know how much stack each task will need, and I reserve all tasks
> >> equally from all available memory. When a new task is created,
> >> I take away the top of the stack from everyone else, so that again
> >> all tasks have the same amount of the stack reserved. But I allocate
> >> real memory only after the task reaches for this memory.
> >> >> Perhaps the solution is not to change this protection, as it is only
> >> a matter of ensuring that real memory is not allocated before it is used
> > > That is not making any sense to me.
> > > The mmap calls do not allocate memory.
> > > Instead, mmap allocates address space, indicating a allocation/permission
> > policy, which allows the kernel to fault in (provide) memory when required.
> > > A page of memory in the range is not actually allocated from the system
> > until code touches it.
>
> However, I need to know how much of the stack is currently allocated
> and how much remains only reserved.
Why do you need to know that?
It sounds you made an overly compliated allocation scheme to re-do in
userland what the vm subsystem already does for all pages.
A simple scheme is: mmap for every task its maxium stack size. Stack
pages touched will be provided with memory by the kernel. Pages unused
will not be allocated physical pages.
Can you explain why the above scheme would not work for you?
>
> What if I do:
> mmap( PROT_READ|PROT_WRITE, MAP_STACK )
> mprotect( PROT_NONE )
> ?
>
> Will a safety belt be unfastened or is there any other protection?
>
-Otto
PS: I could not read your code due to the exotic formatting style.
You're free to do it like you want, but if you're asking for
assistence it helps to conform to generally accepted practice.