mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-02 02:32:27 +00:00
Rewrite memory manager
Actually Portable Executable now supports Android. Cosmo's old mmap code required a 47 bit address space. The new implementation is very agnostic and supports both smaller address spaces (e.g. embedded) and even modern 56-bit PML5T paging for x86 which finally came true on Zen4 Threadripper Cosmopolitan no longer requires UNIX systems to observe the Windows 64kb granularity; i.e. sysconf(_SC_PAGE_SIZE) will now report the host native page size. This fixes a longstanding POSIX conformance issue, concerning file mappings that overlap the end of file. Other aspects of conformance have been improved too, such as the subtleties of address assignment and and the various subtleties surrounding MAP_FIXED and MAP_FIXED_NOREPLACE On Windows, mappings larger than 100 megabytes won't be broken down into thousands of independent 64kb mappings. Support for MAP_STACK is removed by this change; please use NewCosmoStack() instead. Stack overflow avoidance is now being implemented using the POSIX thread APIs. Please use GetStackBottom() and GetStackAddr(), instead of the old error-prone GetStackAddr() and HaveStackMemory() APIs which are removed.
This commit is contained in:
parent
7f6d0b8709
commit
6ffed14b9c
150 changed files with 1893 additions and 5634 deletions
|
@ -17,6 +17,7 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "tool/net/ljson.h"
|
||||
#include "libc/assert.h"
|
||||
#include "libc/intrin/likely.h"
|
||||
#include "libc/log/check.h"
|
||||
#include "libc/log/log.h"
|
||||
|
@ -28,6 +29,7 @@
|
|||
#include "libc/str/tab.internal.h"
|
||||
#include "libc/str/utf16.h"
|
||||
#include "libc/sysv/consts/auxv.h"
|
||||
#include "libc/thread/thread.h"
|
||||
#include "third_party/double-conversion/wrapper.h"
|
||||
#include "third_party/lua/cosmo.h"
|
||||
#include "third_party/lua/lauxlib.h"
|
||||
|
@ -91,19 +93,18 @@ static const char kJsonStr[256] = {
|
|||
};
|
||||
|
||||
static struct DecodeJson Parse(struct lua_State *L, const char *p,
|
||||
const char *e, int context, int depth) {
|
||||
const char *e, int context, int depth,
|
||||
uintptr_t bsp) {
|
||||
long x;
|
||||
char w[4];
|
||||
luaL_Buffer b;
|
||||
struct DecodeJson r;
|
||||
const char *a, *reason;
|
||||
int A, B, C, D, c, d, i, u;
|
||||
if (UNLIKELY(!depth)) {
|
||||
if (UNLIKELY(!depth))
|
||||
return (struct DecodeJson){-1, "maximum depth exceeded"};
|
||||
}
|
||||
if (UNLIKELY(!HaveStackMemory(getauxval(AT_PAGESZ)))) {
|
||||
if (UNLIKELY(GetStackPointer() < bsp))
|
||||
return (struct DecodeJson){-1, "out of stack"};
|
||||
}
|
||||
for (a = p, d = +1; p < e;) {
|
||||
switch ((c = *p++ & 255)) {
|
||||
case ' ': // spaces
|
||||
|
@ -240,7 +241,7 @@ static struct DecodeJson Parse(struct lua_State *L, const char *p,
|
|||
goto OnColonCommaKey;
|
||||
lua_newtable(L); // +1
|
||||
for (context = ARRAY, i = 0;;) {
|
||||
r = Parse(L, p, e, context, depth - 1); // +2
|
||||
r = Parse(L, p, e, context, depth - 1, bsp); // +2
|
||||
if (UNLIKELY(r.rc == -1)) {
|
||||
lua_pop(L, 1);
|
||||
return r;
|
||||
|
@ -279,7 +280,7 @@ static struct DecodeJson Parse(struct lua_State *L, const char *p,
|
|||
lua_newtable(L); // +1
|
||||
context = KEY | OBJECT;
|
||||
for (;;) {
|
||||
r = Parse(L, p, e, context, depth - 1); // +2
|
||||
r = Parse(L, p, e, context, depth - 1, bsp); // +2
|
||||
if (r.rc == -1) {
|
||||
lua_pop(L, 1);
|
||||
return r;
|
||||
|
@ -288,7 +289,7 @@ static struct DecodeJson Parse(struct lua_State *L, const char *p,
|
|||
if (!r.rc) {
|
||||
return (struct DecodeJson){1, p};
|
||||
}
|
||||
r = Parse(L, p, e, COLON, depth - 1); // +3
|
||||
r = Parse(L, p, e, COLON, depth - 1, bsp); // +3
|
||||
if (r.rc == -1) {
|
||||
lua_pop(L, 2);
|
||||
return r;
|
||||
|
@ -599,8 +600,9 @@ static struct DecodeJson Parse(struct lua_State *L, const char *p,
|
|||
struct DecodeJson DecodeJson(struct lua_State *L, const char *p, size_t n) {
|
||||
if (n == -1)
|
||||
n = p ? strlen(p) : 0;
|
||||
uintptr_t bsp = GetStackBottom() + 4096;
|
||||
if (lua_checkstack(L, DEPTH * 3 + LUA_MINSTACK)) {
|
||||
return Parse(L, p, p + n, 0, DEPTH);
|
||||
return Parse(L, p, p + n, 0, DEPTH, bsp);
|
||||
} else {
|
||||
return (struct DecodeJson){-1, "can't set stack depth"};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue