2 #include <sys/sysctl.h>
10 int stack_variable
= 1;
13 int name
[] = {CTL_KERN
, KERN_USRSTACK
};
14 size_t len
= sizeof(unsigned long);
16 if (sysctlbyname("kern.usrstack", &v1
, &len
, NULL
, 0) < 0) {
17 perror("sysctlbyname failed:");
21 if (sysctl(name
, 2, &v2
, &len
, NULL
, 0) < 0) {
22 perror("sysctl failed:");
29 printf("FAIL usrstack different\n");
30 printf("v1 %lx v2 %lx\n", v1
, v2
);
34 /* the purpose of this is to check that the sysctl isn't
35 returning the host stack. I expec the difference to be less than 0x1000 */
36 if (v1
- (unsigned long)&stack_variable
> 0x2000U
) {
37 printf("FAIL usrstack fishy\n");
38 printf("v1 %lx stack_variable %p diff %lx\n", v1
, &stack_variable
, v1
- (unsigned long)&stack_variable
);