mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-23 05:42:29 +00:00
Fix bugs and make improvements
- Get clone() working on FreeBSD - Increase some Python build quotas - Add more atomic builtins to chibicc - Fix ASAN poisoning of alloca() memory - Make MODE= mandatory link path tinier - Improve the examples folder a little bit - Start working on some more resource limits - Make the linenoise auto-complete UI as good as GNU readline - Update compile.com, avoiding AVX codegen on non-AVX systems - Make sure empty path to syscalls like opendir raises ENOENT - Correctly polyfill ENOENT vs. ENOTDIR on the New Technology - Port bestline's paredit features to //third_party/linenoise - Remove workarounds for RHEL 5.0 bugs that were fixed in 5.1
This commit is contained in:
parent
c3fb624647
commit
ae638c0850
181 changed files with 2994 additions and 1367 deletions
52
examples/crashreport2.c
Normal file
52
examples/crashreport2.c
Normal file
|
@ -0,0 +1,52 @@
|
|||
#if 0
|
||||
/*─────────────────────────────────────────────────────────────────╗
|
||||
│ To the extent possible under law, Justine Tunney has waived │
|
||||
│ all copyright and related or neighboring rights to this file, │
|
||||
│ as it is written in the following disclaimers: │
|
||||
│ • http://unlicense.org/ │
|
||||
│ • http://creativecommons.org/publicdomain/zero/1.0/ │
|
||||
╚─────────────────────────────────────────────────────────────────*/
|
||||
#endif
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/log/log.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
|
||||
/**
|
||||
* @fileoverview CTRL+\ debugging example
|
||||
*
|
||||
* make -j8 -O o//examples/crashreport2.com
|
||||
* o//examples/crashreport2.com
|
||||
*
|
||||
* Assuming you call ShowCrashReports() from main(), you can press
|
||||
* `CTRL+\` at anny time to generate a `SIGQUIT` message that lets you
|
||||
* debug wrongness and freezups.
|
||||
*
|
||||
* On supported platforms, this will cause GDB to automatically attach.
|
||||
* The nice thing about this, is you can start stepping through your
|
||||
* code at the precice instruction where the interrupt happened. See
|
||||
* `libc/log/attachdebugger.c` to see how it works.
|
||||
*
|
||||
* If you wish to suppress the auto-GDB behavior, then:
|
||||
*
|
||||
* export GDB=
|
||||
*
|
||||
* Or alternatively:
|
||||
*
|
||||
* extern int __isworker;
|
||||
* __isworker = true;
|
||||
*
|
||||
* Will cause your `SIGQUIT` handler to just print a crash report
|
||||
* instead. This is useful for production software that might be running
|
||||
* in a terminal environment like GNU Screen, but it's not desirable to
|
||||
* have ten worker processes trying to attach GDB at once.
|
||||
*/
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
volatile int64_t x;
|
||||
ShowCrashReports();
|
||||
printf("please press ctrl+\\ and see what happens...\n");
|
||||
sigsuspend(0);
|
||||
printf("\n\n");
|
||||
printf("congratulations! your program is now resuming\n");
|
||||
return 0;
|
||||
}
|
|
@ -44,8 +44,8 @@
|
|||
#include "libc/str/str.h"
|
||||
#include "libc/time/time.h"
|
||||
#include "third_party/zlib/zlib.h"
|
||||
// clang-format off
|
||||
|
||||
/* clang-format off */
|
||||
#define DICT "usr/share/dict/hangman"
|
||||
#define MAXERR 7
|
||||
#define MINSCORE 0
|
||||
|
|
72
examples/rlimit.c
Normal file
72
examples/rlimit.c
Normal file
|
@ -0,0 +1,72 @@
|
|||
#if 0
|
||||
/*─────────────────────────────────────────────────────────────────╗
|
||||
│ To the extent possible under law, Justine Tunney has waived │
|
||||
│ all copyright and related or neighboring rights to this file, │
|
||||
│ as it is written in the following disclaimers: │
|
||||
│ • http://unlicense.org/ │
|
||||
│ • http://creativecommons.org/publicdomain/zero/1.0/ │
|
||||
╚─────────────────────────────────────────────────────────────────*/
|
||||
#endif
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/strace.internal.h"
|
||||
#include "libc/calls/struct/rlimit.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/intrin/kprintf.h"
|
||||
#include "libc/log/color.internal.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/consts/rlim.h"
|
||||
#include "libc/sysv/consts/rlimit.h"
|
||||
|
||||
/**
|
||||
* @fileoverview tool for printing and changing system resource limits
|
||||
*
|
||||
* This is what you do if you want to not accidentally bomb your system
|
||||
* with runaway code. If you haven't accidentally bombed your UNIX
|
||||
* system before then you're not pushing it hard enough.
|
||||
*/
|
||||
|
||||
static void SetLimit(int resource, uint64_t soft, uint64_t hard) {
|
||||
struct rlimit old;
|
||||
struct rlimit lim = {soft, hard};
|
||||
if (resource == 127) return;
|
||||
if (setrlimit(resource, &lim) == -1) {
|
||||
if (!getrlimit(resource, &old)) {
|
||||
lim.rlim_max = MIN(hard, old.rlim_max);
|
||||
lim.rlim_cur = MIN(soft, lim.rlim_max);
|
||||
if (!setrlimit(resource, &lim)) {
|
||||
fprintf(stderr, "%snote: setrlimit(%s) downgraded to {%,ld, %,ld}\n",
|
||||
__strace_rlimit_name(resource), lim.rlim_cur, lim.rlim_max);
|
||||
return;
|
||||
}
|
||||
}
|
||||
fprintf(stderr, "error: setrlimit(%s, %,ld, %,ld) failed %m%n",
|
||||
__strace_rlimit_name(resource), soft, hard);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int i, rc;
|
||||
struct rlimit rlim;
|
||||
|
||||
// // example of how you might change the limits
|
||||
// SetLimit(RLIMIT_CPU, 3, 33);
|
||||
// SetLimit(RLIMIT_NPROC, 4, 128);
|
||||
// SetLimit(RLIMIT_NOFILE, 32, 128);
|
||||
// SetLimit(RLIMIT_SIGPENDING, 16, 1024);
|
||||
// SetLimit(RLIMIT_AS, 8 * 1024 * 1024, 1l * 1024 * 1024 * 1024);
|
||||
// SetLimit(RLIMIT_RSS, 8 * 1024 * 1024, 1l * 1024 * 1024 * 1024);
|
||||
// SetLimit(RLIMIT_DATA, 8 * 1024 * 1024, 1l * 1024 * 1024 * 1024);
|
||||
// SetLimit(RLIMIT_FSIZE, 8 * 1000 * 1000, 1l * 1000 * 1000 * 1000);
|
||||
|
||||
for (i = 0; i < RLIM_NLIMITS; ++i) {
|
||||
rc = getrlimit(i, &rlim);
|
||||
printf("setrlimit(%-20s, %,16ld, %,16ld) → %d %s\n",
|
||||
__strace_rlimit_name(i), rlim.rlim_cur, rlim.rlim_max, rc,
|
||||
!rc ? "" : strerror(errno));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -16,12 +16,22 @@
|
|||
#include "libc/sysv/consts/sig.h"
|
||||
#include "third_party/xed/x86.h"
|
||||
|
||||
/**
|
||||
* @fileoverview How to change CPU state on signal delivery
|
||||
*
|
||||
* This program redefines division by zero so that it has a definition.
|
||||
* The definition is the meaning of life, the universe, and everything.
|
||||
* Normally crash signals like `SIGSEGV`, `SIGILL`, and `SIGFPE` aren't
|
||||
* recoverable. This example shows how it actually can be done with Xed
|
||||
* and this example should work on all supported platforms even Windows
|
||||
*/
|
||||
|
||||
void handler(int sig, siginfo_t *si, ucontext_t *ctx) {
|
||||
struct XedDecodedInst xedd;
|
||||
xed_decoded_inst_zero_set_mode(&xedd, XED_MACHINE_MODE_LONG_64);
|
||||
xed_instruction_length_decode(&xedd, (void *)ctx->uc_mcontext.rip, 15);
|
||||
ctx->uc_mcontext.rip += xedd.length;
|
||||
ctx->uc_mcontext.rax = 42;
|
||||
ctx->uc_mcontext.rax = 42; // set the DIV result registers rdx:rax
|
||||
ctx->uc_mcontext.rdx = 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue