mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-31 17:52:27 +00:00
Make fixes and improvements
- Invent iso8601us() for faster timestamps - Improve --strace descriptions of sigset_t - Rebuild the Landlock Make bootstrap binary - Introduce MODE=sysv for non-Windows builds - Permit OFD fcntl() locks under pledge(flock) - redbean can now protect your kernel from ddos - Have vfork() fallback to sys_fork() not fork() - Change kmalloc() to not die when out of memory - Improve documentation for some termios functions - Rewrite putenv() and friends to conform to POSIX - Fix linenoise + strace verbosity issue on Windows - Fix regressions in our ability to show backtraces - Change redbean SetHeader() to no-op if value is nil - Improve fcntl() so SQLite locks work in non-WAL mode - Remove some unnecessary work during fork() on Windows - Create redbean-based SSL reverse proxy for IPv4 TurfWar - Fix ape/apeinstall.sh warning when using non-bash shells - Add ProgramTrustedIp(), and IsTrustedIp() APIs to redbean - Support $PWD, $UID, $GID, and $EUID in command interpreter - Introduce experimental JTqFpD APE prefix for non-Windows builds - Invent blackhole daemon for firewalling IP addresses via UNIX named socket - Add ProgramTokenBucket(), AcquireToken(), and CountTokens() APIs to redbean
This commit is contained in:
parent
648bf6555c
commit
f7ff77d865
209 changed files with 3818 additions and 998 deletions
|
@ -29,7 +29,7 @@
|
|||
#include "libc/thread/thread.h"
|
||||
#include "libc/thread/tls.h"
|
||||
|
||||
#define KMALLOC_ALIGN __BIGGEST_ALIGNMENT__
|
||||
#define KMALLOC_ALIGN sizeof(intptr_t)
|
||||
|
||||
static struct {
|
||||
char *endptr;
|
||||
|
@ -55,21 +55,37 @@ __attribute__((__constructor__)) static void kmalloc_init(void) {
|
|||
* The code malloc() depends upon uses this function to allocate memory.
|
||||
* The returned memory can't be freed, and leak detection is impossible.
|
||||
* This function panics when memory isn't available.
|
||||
*
|
||||
* Memory returned by this function is aligned on the word size, and as
|
||||
* such, kmalloc() shouldn't be used for vector operations.
|
||||
*
|
||||
* @return zero-initialized memory on success, or null w/ errno
|
||||
* @raise ENOMEM if we require more vespene gas
|
||||
*/
|
||||
void *kmalloc(size_t size) {
|
||||
char *start;
|
||||
size_t i, n;
|
||||
char *p, *e;
|
||||
size_t i, n, t;
|
||||
n = ROUNDUP(size + (IsAsan() * 8), KMALLOC_ALIGN);
|
||||
kmalloc_lock();
|
||||
i = g_kmalloc.total;
|
||||
g_kmalloc.total += n;
|
||||
start = (char *)kMemtrackKmallocStart;
|
||||
if (!g_kmalloc.endptr) g_kmalloc.endptr = start;
|
||||
g_kmalloc.endptr =
|
||||
_extend(start, g_kmalloc.total, g_kmalloc.endptr, MAP_PRIVATE,
|
||||
kMemtrackKmallocStart + kMemtrackKmallocSize);
|
||||
t = g_kmalloc.total;
|
||||
e = g_kmalloc.endptr;
|
||||
i = t;
|
||||
t += n;
|
||||
p = (char *)kMemtrackKmallocStart;
|
||||
if (!e) e = p;
|
||||
if ((e = _extend(p, t, e, MAP_PRIVATE,
|
||||
kMemtrackKmallocStart + kMemtrackKmallocSize))) {
|
||||
g_kmalloc.endptr = e;
|
||||
g_kmalloc.total = t;
|
||||
} else {
|
||||
p = 0;
|
||||
}
|
||||
kmalloc_unlock();
|
||||
_unassert(!((intptr_t)(start + i) & (KMALLOC_ALIGN - 1)));
|
||||
if (IsAsan()) __asan_poison(start + i + size, n - size, kAsanHeapOverrun);
|
||||
return start + i;
|
||||
if (p) {
|
||||
_unassert(!((intptr_t)(p + i) & (KMALLOC_ALIGN - 1)));
|
||||
if (IsAsan()) __asan_poison(p + i + size, n - size, kAsanHeapOverrun);
|
||||
return p + i;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue