Page MenuHomeFreeBSD

kern_exec: Add kern.stacktop sysctl.

Authored by on Sep 10 2021, 6:14 AM.
Referenced Files
Unknown Object (File)
Fri, May 26, 2:19 PM
Unknown Object (File)
May 5 2023, 3:30 PM
Unknown Object (File)
Apr 28 2023, 1:21 PM
Unknown Object (File)
Mar 4 2023, 8:31 AM
Unknown Object (File)
Feb 15 2023, 10:00 PM
Unknown Object (File)
Feb 11 2023, 7:33 PM
Unknown Object (File)
Feb 5 2023, 9:13 AM
Unknown Object (File)
Feb 5 2023, 9:13 AM



With stack gap enabled top of the stack is moved down by a random
amount of bytes. Because of that some multithreaded applications
which use kern.usrstack sysctl to calculate address of stacks for
their threads can fail. Add kern.stacktop sysctl, which can be used
to retrieve address of the stack after stack gap is applied to it.
Returns value identical to kern.usrstack for processes which have
no stack gap.

Diff Detail

rG FreeBSD src repository
Lint Not Applicable
Tests Not Applicable

Event Timeline created this revision.

Hi, do you have any further comments or remarks? If there are no objections, I'm going to merge this patch by EOW.


Style: need spaces around binary op '|'. Ignore other examples in this file, do it right for added code.


Fix style while there: return (error);


The op ('-') should be on the previous line, before line split. Also, why not to do single cast, instead of two:

val = (unsigned)(p->p_sysent->sv_usrstack - p->p_vmspace->vm_stkgap);

return (error);

kib added inline comments.

There should be a blank line after local variable declaration.

This revision is now accepted and ready to land.Oct 13 2021, 11:13 PM

Added newline after variable declaration.

This revision now requires review to proceed.Oct 14 2021, 9:16 AM
This revision is now accepted and ready to land.Oct 14 2021, 2:25 PM
This revision was automatically updated to reflect the committed changes.