Page MenuHomeFreeBSD

libthr: Use kern.stacktop for thread stack calculation.
ClosedPublic

Authored by dgr_semihalf.com on Sep 10 2021, 6:14 AM.
Tags
None
Referenced Files
Unknown Object (File)
Sun, Apr 7, 11:11 AM
Unknown Object (File)
Sun, Apr 7, 9:33 AM
Unknown Object (File)
Fri, Apr 5, 10:32 PM
Unknown Object (File)
Fri, Apr 5, 10:12 PM
Unknown Object (File)
Fri, Apr 5, 8:44 PM
Unknown Object (File)
Mar 1 2024, 5:29 PM
Unknown Object (File)
Mar 1 2024, 1:56 AM
Unknown Object (File)
Feb 26 2024, 7:33 AM

Details

Summary

Use the new kern.stacktop sysctl to retrieve the address of stack top
instead of kern.usrstack. kern.usrstack does not have any knowledge
of the stack gap, so this can cause problems with thread stacks.
Using kern.stacktop sysctl should fix most of those problems.
kern.usrstack is used as a fallback when kern.stacktop cannot be read.

Rename usrstack variables to stacktop to reflect this change.

Fixes problems with firefox and thunderbird not starting with
stack gap enabled.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

dgr_semihalf.com created this revision.
lib/libthr/thread/thr_init.c
470

People will need to remember to installkernel before installworld (as documented). Supporting both for a period of time may avoid POLA with mismatching kernel and userland, i.e. check for stacktop first and if that fails check for usrstack. like this?

mib[1] = KERN_STACKTOP;
len = sizeof (_stacktop);
if (sysctl(mib, 2, &_stacktop, &len, NULL, 0) == -1) {
        mib[1] = KERN_USRSTACK;
        if (sysctl(mib, 2, &_stacktop, &len, NULL, 0) == -1)
                PANIC("Cannot get kern.stacktop from sysctl");
}
dgr_semihalf.com edited the summary of this revision. (Show Details)

Add kern.usrstack fallback if kern.stacktop was not found.

Additionally, change sizeof(mib) / sizeof(mib[0]) to nitems() macro in singlethread_map_stacks_exec() function.

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

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