mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-27 23:08:31 +00:00
Make numerous improvements
- Python static hello world now 1.8mb - Python static fully loaded now 10mb - Python HTTPS client now uses MbedTLS - Python REPL now completes import stmts - Increase stack size for Python for now - Begin synthesizing posixpath and ntpath - Restore Python \N{UNICODE NAME} support - Restore Python NFKD symbol normalization - Add optimized code path for Intel SHA-NI - Get more Python unit tests passing faster - Get Python help() pagination working on NT - Python hashlib now supports MbedTLS PBKDF2 - Make memcpy/memmove/memcmp/bcmp/etc. faster - Add Mersenne Twister and Vigna to LIBC_RAND - Provide privileged __printf() for error code - Fix zipos opendir() so that it reports ENOTDIR - Add basic chmod() implementation for Windows NT - Add Cosmo's best functions to Python cosmo module - Pin function trace indent depth to that of caller - Show memory diagram on invalid access in MODE=dbg - Differentiate stack overflow on crash in MODE=dbg - Add stb_truetype and tools for analyzing font files - Upgrade to UNICODE 13 and reduce its binary footprint - COMPILE.COM now logs resource usage of build commands - Start implementing basic poll() support on bare metal - Set getauxval(AT_EXECFN) to GetModuleFileName() on NT - Add descriptions to strerror() in non-TINY build modes - Add COUNTBRANCH() macro to help with micro-optimizations - Make error / backtrace / asan / memory code more unbreakable - Add fast perfect C implementation of μ-Law and a-Law audio codecs - Make strtol() functions consistent with other libc implementations - Improve Linenoise implementation (see also github.com/jart/bestline) - COMPILE.COM now suppresses stdout/stderr of successful build commands
This commit is contained in:
parent
fa7b4f5bd1
commit
39bf41f4eb
806 changed files with 77494 additions and 63859 deletions
|
@ -21,6 +21,7 @@
|
|||
#include "libc/calls/internal.h"
|
||||
#include "libc/calls/sigbits.h"
|
||||
#include "libc/calls/struct/sigset.h"
|
||||
#include "libc/log/libfatal.internal.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/runtime/symbols.internal.h"
|
||||
#include "libc/sysv/consts/prot.h"
|
||||
|
@ -43,37 +44,37 @@
|
|||
*
|
||||
* @see ape/ape.lds
|
||||
*/
|
||||
privileged void __hook(void *ifunc, struct SymbolTable *symbols) {
|
||||
privileged noinstrument noasan void __hook(void *ifunc,
|
||||
struct SymbolTable *symbols) {
|
||||
size_t i;
|
||||
char *p, *pe;
|
||||
intptr_t addr;
|
||||
uint64_t code, mcode;
|
||||
unsigned char *p, *pe;
|
||||
sigset_t mask, oldmask;
|
||||
const intptr_t kMcount = (intptr_t)&mcount;
|
||||
const intptr_t kProgramCodeStart = (intptr_t)&_ereal;
|
||||
const intptr_t kPrivilegedStart = (intptr_t)&__privileged_start;
|
||||
const bool kIsBinaryAligned = !(kPrivilegedStart & (PAGESIZE - 1));
|
||||
intptr_t kMcount = (intptr_t)&mcount;
|
||||
intptr_t kProgramCodeStart = (intptr_t)&_ereal;
|
||||
intptr_t kPrivilegedStart = (intptr_t)&__privileged_start;
|
||||
bool kIsBinaryAligned = !(kPrivilegedStart & (PAGESIZE - 1));
|
||||
sigfillset(&mask);
|
||||
sigprocmask(SIG_BLOCK, &mask, &oldmask);
|
||||
if (mprotect((void *)symbols->addr_base,
|
||||
kPrivilegedStart - symbols->addr_base,
|
||||
kIsBinaryAligned ? PROT_READ | PROT_WRITE
|
||||
: PROT_READ | PROT_WRITE | PROT_EXEC) != -1) {
|
||||
for (i = 0; i < symbols->count - 1; ++i) {
|
||||
if (symbols->addr_base + symbols->symbols[i].addr_rva <
|
||||
kProgramCodeStart) {
|
||||
continue; /* skip over real mode symbols */
|
||||
for (i = 0; i < symbols->count; ++i) {
|
||||
if (symbols->addr_base + symbols->symbols[i].x < kProgramCodeStart) {
|
||||
continue;
|
||||
}
|
||||
if (symbols->addr_base + symbols->symbols[i].addr_rva >=
|
||||
kPrivilegedStart) {
|
||||
break; /* stop before privileged symbols */
|
||||
if (symbols->addr_base + symbols->symbols[i].y >= kPrivilegedStart) {
|
||||
break;
|
||||
}
|
||||
for (p = (unsigned char *)(symbols->addr_base +
|
||||
symbols->symbols[i].addr_rva),
|
||||
pe = (unsigned char *)(symbols->addr_base +
|
||||
symbols->symbols[i + 1].addr_rva);
|
||||
p < pe - 8; ++p) {
|
||||
code = READ64LE(p);
|
||||
for (p = (char *)symbols->addr_base + symbols->symbols[i].x,
|
||||
pe = (char *)symbols->addr_base + symbols->symbols[i].y;
|
||||
p + 8 - 1 <= pe; ++p) {
|
||||
code = ((uint64_t)(255 & p[7]) << 070 | (uint64_t)(255 & p[6]) << 060 |
|
||||
(uint64_t)(255 & p[5]) << 050 | (uint64_t)(255 & p[4]) << 040 |
|
||||
(uint64_t)(255 & p[3]) << 030 | (uint64_t)(255 & p[2]) << 020 |
|
||||
(uint64_t)(255 & p[1]) << 010 | (uint64_t)(255 & p[0]) << 000);
|
||||
|
||||
/*
|
||||
* Test for -mrecord-mcount (w/ -fpie or -fpic)
|
||||
|
@ -95,10 +96,10 @@ privileged void __hook(void *ifunc, struct SymbolTable *symbols) {
|
|||
p[0] = 0x67;
|
||||
p[1] = 0xE8;
|
||||
addr = (intptr_t)ifunc - ((intptr_t)&p[2] + 4);
|
||||
p[2] = addr >> 000;
|
||||
p[3] = addr >> 010;
|
||||
p[4] = addr >> 020;
|
||||
p[5] = addr >> 030;
|
||||
p[2] = (addr & 0x000000ff) >> 000;
|
||||
p[3] = (addr & 0x0000ff00) >> 010;
|
||||
p[4] = (addr & 0x00ff0000) >> 020;
|
||||
p[5] = (addr & 0xff000000) >> 030;
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -111,10 +112,10 @@ privileged void __hook(void *ifunc, struct SymbolTable *symbols) {
|
|||
if (p[-1] != 0x66 /* nopw 0x0(%rax,%rax,1) [donotwant] */) {
|
||||
p[0] = 0xE8 /* call Jvds */;
|
||||
addr = (intptr_t)ifunc - ((intptr_t)&p[1] + 4);
|
||||
p[1] = addr >> 000;
|
||||
p[2] = addr >> 010;
|
||||
p[3] = addr >> 020;
|
||||
p[4] = addr >> 030;
|
||||
p[1] = (addr & 0x000000ff) >> 000;
|
||||
p[2] = (addr & 0x0000ff00) >> 010;
|
||||
p[3] = (addr & 0x00ff0000) >> 020;
|
||||
p[4] = (addr & 0xff000000) >> 030;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue