Changeset View
Changeset View
Standalone View
Standalone View
lib/libthr/thread/thr_stack.c
Show All 24 Lines | |||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||||
* SUCH DAMAGE. | * SUCH DAMAGE. | ||||
*/ | */ | ||||
#include <sys/cdefs.h> | #include <sys/cdefs.h> | ||||
__FBSDID("$FreeBSD$"); | __FBSDID("$FreeBSD$"); | ||||
#include <sys/types.h> | #include <sys/param.h> | ||||
#include <sys/auxv.h> | |||||
#include <sys/mman.h> | #include <sys/mman.h> | ||||
#include <sys/queue.h> | #include <sys/queue.h> | ||||
#include <sys/resource.h> | #include <sys/resource.h> | ||||
#include <sys/sysctl.h> | #include <sys/sysctl.h> | ||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include <pthread.h> | #include <pthread.h> | ||||
#include <link.h> | #include <link.h> | ||||
▲ Show 20 Lines • Show All 102 Lines • ▼ Show 20 Lines | mprotect((char *)thrd->attr.stackaddr_attr + | ||||
_rtld_get_stack_prot()); | _rtld_get_stack_prot()); | ||||
} | } | ||||
static void | static void | ||||
singlethread_map_stacks_exec(void) | singlethread_map_stacks_exec(void) | ||||
{ | { | ||||
int mib[2]; | int mib[2]; | ||||
struct rlimit rlim; | struct rlimit rlim; | ||||
u_long usrstack; | u_long usrstack, stacksz; | ||||
size_t len; | size_t len; | ||||
if (elf_aux_info(AT_USRSTACKBASE, &usrstack, sizeof(usrstack)) != 0) { | |||||
mib[0] = CTL_KERN; | mib[0] = CTL_KERN; | ||||
mib[1] = KERN_USRSTACK; | mib[1] = KERN_USRSTACK; | ||||
len = sizeof(usrstack); | len = sizeof(usrstack); | ||||
if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), &usrstack, &len, NULL, 0) | if (sysctl(mib, nitems(mib), &usrstack, &len, NULL, 0) == -1) | ||||
imp: Use nitem(mib) to allow this to all be on 1 line maybe?
| |||||
== -1) | |||||
return; | return; | ||||
} | |||||
if (elf_aux_info(AT_USRSTACKLIM, &len, sizeof(len)) != 0 && | |||||
getrlimit(RLIMIT_STACK, &rlim) == -1) | |||||
return; | |||||
if (elf_aux_info(AT_USRSTACKLIM, &stacksz, sizeof(stacksz)) != 0) { | |||||
if (getrlimit(RLIMIT_STACK, &rlim) == -1) | if (getrlimit(RLIMIT_STACK, &rlim) == -1) | ||||
return; | return; | ||||
mprotect((void *)(uintptr_t)(usrstack - rlim.rlim_cur), | stacksz = rlim.rlim_cur; | ||||
rlim.rlim_cur, _rtld_get_stack_prot()); | } | ||||
mprotect((void *)(uintptr_t)(usrstack - stacksz), stacksz, | |||||
_rtld_get_stack_prot()); | |||||
Done Inline ActionsShould libthr panic if this call fails? It would provide a more useful failure mode if some W^X policy is enabled, no? Same for __libc_map_stacks_exec(). markj: Should libthr panic if this call fails? It would provide a more useful failure mode if some W^X… | |||||
Done Inline ActionsNo, I do not think so. I highly dislike system libraries abruptly terminating the process. If it can continue, it should. kib: No, I do not think so. I highly dislike system libraries abruptly terminating the process. If… | |||||
} | } | ||||
void | void | ||||
__thr_map_stacks_exec(void) | __thr_map_stacks_exec(void) | ||||
{ | { | ||||
struct pthread *curthread, *thrd; | struct pthread *curthread, *thrd; | ||||
struct stack *st; | struct stack *st; | ||||
▲ Show 20 Lines • Show All 148 Lines • Show Last 20 Lines |
Use nitem(mib) to allow this to all be on 1 line maybe?