mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-01 10:12:27 +00:00
Fix MODE=optlinux and MODE=tiny builds
This commit is contained in:
parent
5660ec4741
commit
0602ff6bab
12 changed files with 75 additions and 36 deletions
|
@ -80,19 +80,19 @@ void SetUp(void) {
|
|||
sigaction(SIGSEGV, &sa, 0);
|
||||
}
|
||||
|
||||
int StackOverflow(void);
|
||||
int (*pStackOverflow)(void) = StackOverflow;
|
||||
int StackOverflow(void) {
|
||||
return pStackOverflow();
|
||||
int StackOverflow(int d) {
|
||||
char A[8];
|
||||
for (int i = 0; i < sizeof(A); i++)
|
||||
A[i] = d + i;
|
||||
if (__veil("r", d))
|
||||
return StackOverflow(d + 1) + A[d % sizeof(A)];
|
||||
return 0;
|
||||
}
|
||||
|
||||
TEST(stackoverflow, standardStack_altStack_process_longjmp) {
|
||||
if (IsTiny())
|
||||
return; // TODO(jart): why?
|
||||
|
||||
int jumpcode;
|
||||
if (!(jumpcode = setjmp(recover))) {
|
||||
exit(pStackOverflow());
|
||||
exit(StackOverflow(0));
|
||||
}
|
||||
ASSERT_EQ(123, jumpcode);
|
||||
ASSERT_TRUE(smashed_stack);
|
||||
|
|
|
@ -51,10 +51,13 @@ void CrashHandler(int sig, siginfo_t *si, void *ctx) {
|
|||
longjmp(recover, 123);
|
||||
}
|
||||
|
||||
int StackOverflow(void);
|
||||
int (*pStackOverflow)(void) = StackOverflow;
|
||||
int StackOverflow(void) {
|
||||
return pStackOverflow();
|
||||
int StackOverflow(int d) {
|
||||
char A[8];
|
||||
for (int i = 0; i < sizeof(A); i++)
|
||||
A[i] = d + i;
|
||||
if (__veil("r", d))
|
||||
return StackOverflow(d + 1) + A[d % sizeof(A)];
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *MyPosixThread(void *arg) {
|
||||
|
@ -71,7 +74,7 @@ void *MyPosixThread(void *arg) {
|
|||
sigaction(SIGBUS, &sa, &o1);
|
||||
sigaction(SIGSEGV, &sa, &o2);
|
||||
if (!(jumpcode = setjmp(recover))) {
|
||||
exit(pStackOverflow());
|
||||
exit(StackOverflow(0));
|
||||
}
|
||||
ASSERT_EQ(123, jumpcode);
|
||||
sigaction(SIGSEGV, &o2, 0);
|
||||
|
|
|
@ -85,10 +85,13 @@ void CrashHandler(int sig, siginfo_t *si, void *arg) {
|
|||
#endif
|
||||
}
|
||||
|
||||
int StackOverflow(void);
|
||||
int (*pStackOverflow)(void) = StackOverflow;
|
||||
int StackOverflow(void) {
|
||||
return pStackOverflow();
|
||||
int StackOverflow(int d) {
|
||||
char A[8];
|
||||
for (int i = 0; i < sizeof(A); i++)
|
||||
A[i] = d + i;
|
||||
if (__veil("r", d))
|
||||
return StackOverflow(d + 1) + A[d % sizeof(A)];
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *MyPosixThread(void *arg) {
|
||||
|
@ -103,7 +106,7 @@ void *MyPosixThread(void *arg) {
|
|||
sa.sa_sigaction = CrashHandler;
|
||||
sigaction(SIGBUS, &sa, 0);
|
||||
sigaction(SIGSEGV, &sa, 0);
|
||||
exit(pStackOverflow());
|
||||
exit(StackOverflow(0));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -45,10 +45,13 @@ void CrashHandler(int sig) {
|
|||
pthread_exit((void *)123L);
|
||||
}
|
||||
|
||||
int StackOverflow(void);
|
||||
int (*pStackOverflow)(void) = StackOverflow;
|
||||
int StackOverflow(void) {
|
||||
return pStackOverflow();
|
||||
int StackOverflow(int d) {
|
||||
char A[8];
|
||||
for (int i = 0; i < sizeof(A); i++)
|
||||
A[i] = d + i;
|
||||
if (__veil("r", d))
|
||||
return StackOverflow(d + 1) + A[d % sizeof(A)];
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *MyPosixThread(void *arg) {
|
||||
|
@ -63,7 +66,7 @@ void *MyPosixThread(void *arg) {
|
|||
sa.sa_handler = CrashHandler;
|
||||
sigaction(SIGBUS, &sa, 0);
|
||||
sigaction(SIGSEGV, &sa, 0);
|
||||
exit(pStackOverflow());
|
||||
exit(StackOverflow(0));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -34,14 +34,17 @@ void CrashHandler(int sig) {
|
|||
pthread_exit(0);
|
||||
}
|
||||
|
||||
int StackOverflow(void);
|
||||
int (*pStackOverflow)(void) = StackOverflow;
|
||||
int StackOverflow(void) {
|
||||
return pStackOverflow();
|
||||
int StackOverflow(int d) {
|
||||
char A[8];
|
||||
for (int i = 0; i < sizeof(A); i++)
|
||||
A[i] = d + i;
|
||||
if (__veil("r", d))
|
||||
return StackOverflow(d + 1) + A[d % sizeof(A)];
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *MyPosixThread(void *arg) {
|
||||
exit(pStackOverflow());
|
||||
exit(StackOverflow(0));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "libc/intrin/weaken.h"
|
||||
#include "libc/limits.h"
|
||||
#include "libc/log/log.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/mem/leaks.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/runtime/internal.h"
|
||||
|
@ -28,8 +29,15 @@
|
|||
#include "libc/str/str.h"
|
||||
#ifdef __x86_64__
|
||||
|
||||
int StackOverflow(void) {
|
||||
return _weaken(StackOverflow)();
|
||||
#include <stdlib.h>
|
||||
|
||||
int StackOverflow(int d) {
|
||||
char A[8];
|
||||
for (int i = 0; i < sizeof(A); i++)
|
||||
A[i] = d + i;
|
||||
if (__veil("r", d))
|
||||
return StackOverflow(d + 1) + A[d % sizeof(A)];
|
||||
return 0;
|
||||
}
|
||||
|
||||
void FpuCrash(void) {
|
||||
|
@ -85,14 +93,21 @@ int NpeCrash(char *p) {
|
|||
return *p;
|
||||
}
|
||||
|
||||
int StackOverflowCrash(int d) {
|
||||
char A[8];
|
||||
for (int i = 0; i < sizeof(A); i++)
|
||||
A[i] = d + i;
|
||||
if (__veil("r", d))
|
||||
return StackOverflowCrash(d + 1) + A[d % sizeof(A)];
|
||||
return 0;
|
||||
}
|
||||
|
||||
void (*pFpuCrash)(void) = FpuCrash;
|
||||
void (*pBssOverrunCrash)(int) = BssOverrunCrash;
|
||||
void (*pDataOverrunCrash)(int) = DataOverrunCrash;
|
||||
int (*pRodataOverrunCrash)(int) = RodataOverrunCrash;
|
||||
char *(*pStackOverrunCrash)(int) = StackOverrunCrash;
|
||||
char *(*pMemoryLeakCrash)(void) = MemoryLeakCrash;
|
||||
int (*pNpeCrash)(char *) = NpeCrash;
|
||||
int (*pStackOverflow)(void) = StackOverflow;
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
ShowCrashReports();
|
||||
|
@ -112,7 +127,7 @@ int main(int argc, char *argv[]) {
|
|||
pDataOverrunCrash(10 + 1);
|
||||
exit(0);
|
||||
case 5:
|
||||
exit((intptr_t)pStackOverrunCrash(10 + 10000));
|
||||
exit(StackOverflowCrash(0));
|
||||
case 6:
|
||||
exit((intptr_t)pMemoryLeakCrash());
|
||||
case 7:
|
||||
|
@ -120,7 +135,7 @@ int main(int argc, char *argv[]) {
|
|||
case 8:
|
||||
exit(pNpeCrash(0));
|
||||
case 9:
|
||||
exit(pStackOverflow());
|
||||
exit(StackOverflow(0));
|
||||
default:
|
||||
fputs("error: unrecognized argument\n", stderr);
|
||||
exit(1);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue