mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-25 20:10:29 +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
|
@ -25,6 +25,7 @@
|
|||
#include "libc/mem/gc.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/runtime/memtrack.internal.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/stdalign.internal.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/consts/map.h"
|
||||
|
@ -162,7 +163,7 @@ struct ElfWriter *elfwriter_open(const char *path, int mode, int arch) {
|
|||
CHECK_NOTNULL((elf = calloc(1, sizeof(struct ElfWriter))));
|
||||
CHECK_NOTNULL((elf->path = strdup(path)));
|
||||
CHECK_NE(-1, (elf->fd = open(elf->path, O_CREAT | O_TRUNC | O_RDWR, mode)));
|
||||
CHECK_NE(-1, ftruncate(elf->fd, (elf->mapsize = FRAMESIZE)));
|
||||
CHECK_NE(-1, ftruncate(elf->fd, (elf->mapsize = __granularity())));
|
||||
CHECK_NE(MAP_FAILED, (elf->map = mmap((void *)(intptr_t)kFixedmapStart,
|
||||
elf->mapsize, PROT_READ | PROT_WRITE,
|
||||
MAP_SHARED | MAP_FIXED, elf->fd, 0)));
|
||||
|
@ -233,7 +234,7 @@ void *elfwriter_reserve(struct ElfWriter *elf, size_t size) {
|
|||
do {
|
||||
greed = greed + (greed >> 1);
|
||||
} while (need > greed);
|
||||
greed = ROUNDUP(greed, FRAMESIZE);
|
||||
greed = ROUNDUP(greed, __granularity());
|
||||
CHECK_NE(-1, ftruncate(elf->fd, greed));
|
||||
CHECK_NE(MAP_FAILED, mmap((char *)elf->map + elf->mapsize,
|
||||
greed - elf->mapsize, PROT_READ | PROT_WRITE,
|
||||
|
|
|
@ -1767,7 +1767,6 @@ Keywords={
|
|||
"FLT_MIN",
|
||||
"FLT_MAX",
|
||||
"__SAUCE__",
|
||||
"FRAMESIZE",
|
||||
"ARG_MAX",
|
||||
"PATH_MAX",
|
||||
"BUFSIZ",
|
||||
|
|
|
@ -235,7 +235,6 @@
|
|||
|
||||
(defconst cosmo-cpp-constants-cosmopolitan
|
||||
'("__SAUCE__"
|
||||
"FRAMESIZE"
|
||||
"ARG_MAX"
|
||||
"PATH_MAX"
|
||||
"BUFSIZ"
|
||||
|
|
|
@ -28,14 +28,14 @@ void *Calloc(size_t a, size_t b) {
|
|||
static size_t n;
|
||||
z = a * b;
|
||||
if (!p) {
|
||||
n = FRAMESIZE;
|
||||
p = mmap((void *)0x300000000000, FRAMESIZE, PROT_READ | PROT_WRITE,
|
||||
n = __granularity();
|
||||
p = mmap((void *)0x300000000000, __granularity(), PROT_READ | PROT_WRITE,
|
||||
MAP_ANONYMOUS | MAP_PRIVATE | MAP_FIXED, -1, 0);
|
||||
}
|
||||
if (i + z > n) {
|
||||
mmap(p + i, FRAMESIZE, PROT_READ | PROT_WRITE,
|
||||
mmap(p + i, __granularity(), PROT_READ | PROT_WRITE,
|
||||
MAP_ANONYMOUS | MAP_PRIVATE | MAP_FIXED, -1, 0);
|
||||
n += FRAMESIZE;
|
||||
n += __granularity();
|
||||
}
|
||||
r = p + i;
|
||||
i += z;
|
||||
|
|
|
@ -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"};
|
||||
}
|
||||
|
|
|
@ -171,7 +171,6 @@ __static_yoink("blink_xnu_aarch64"); // is apple silicon
|
|||
|
||||
#define VERSION 0x020200
|
||||
#define HASH_LOAD_FACTOR /* 1. / */ 4
|
||||
#define MONITOR_MICROS 150000
|
||||
#define READ(F, P, N) readv(F, &(struct iovec){P, N}, 1)
|
||||
#define WRITE(F, P, N) writev(F, &(struct iovec){P, N}, 1)
|
||||
#define AppendCrlf(P) mempcpy(P, "\r\n", 2)
|
||||
|
@ -477,7 +476,6 @@ static int oldloglevel;
|
|||
static int messageshandled;
|
||||
static int sslticketlifetime;
|
||||
static uint32_t clientaddrsize;
|
||||
static atomic_int terminatemonitor;
|
||||
|
||||
static char *brand;
|
||||
static size_t zsize;
|
||||
|
@ -501,13 +499,11 @@ static struct pollfd *polls;
|
|||
static size_t payloadlength;
|
||||
static int64_t cacheseconds;
|
||||
static char *cachedirective;
|
||||
static const char *monitortty;
|
||||
static struct Strings stagedirs;
|
||||
static struct Strings hidepaths;
|
||||
static const char *launchbrowser;
|
||||
static const char ctIdx = 'c'; // a pseudo variable to get address of
|
||||
|
||||
static pthread_t monitorth;
|
||||
static struct Buffer inbuf_actual;
|
||||
static struct Buffer inbuf;
|
||||
static struct Buffer oldin;
|
||||
|
@ -5024,7 +5020,7 @@ static int LuaProgramTokenBucket(lua_State *L) {
|
|||
VERBOSEF("(token) please run the blackholed program; see our website!");
|
||||
}
|
||||
}
|
||||
tokenbucket.b = _mapshared(ROUNDUP(1ul << cidr, FRAMESIZE));
|
||||
tokenbucket.b = _mapshared(ROUNDUP(1ul << cidr, __granularity()));
|
||||
memset(tokenbucket.b, 127, 1ul << cidr);
|
||||
tokenbucket.cidr = cidr;
|
||||
tokenbucket.reject = reject;
|
||||
|
@ -6676,13 +6672,6 @@ static int ExitWorker(void) {
|
|||
isexitingworker = true;
|
||||
return eintr();
|
||||
}
|
||||
if (monitortty) {
|
||||
terminatemonitor = true;
|
||||
if (monitorth) {
|
||||
pthread_join(monitorth, 0);
|
||||
monitorth = 0;
|
||||
}
|
||||
}
|
||||
LuaDestroy();
|
||||
_Exit(0);
|
||||
}
|
||||
|
@ -6715,169 +6704,6 @@ static int EnableSandbox(void) {
|
|||
}
|
||||
}
|
||||
|
||||
static void *MemoryMonitor(void *arg) {
|
||||
static struct termios oldterm;
|
||||
static int tty;
|
||||
sigset_t ss;
|
||||
bool ok;
|
||||
size_t intervals;
|
||||
struct winsize ws;
|
||||
unsigned char rez;
|
||||
struct termios term;
|
||||
char *b, *addr;
|
||||
struct MemoryInterval *mi, *mi2;
|
||||
long i, j, gen, pages;
|
||||
int rc, id, color, color2, workers;
|
||||
id = atomic_load_explicit(&shared->workers, memory_order_relaxed);
|
||||
DEBUGF("(memv) started for pid %d on tid %d", getpid(), gettid());
|
||||
|
||||
sigemptyset(&ss);
|
||||
sigaddset(&ss, SIGHUP);
|
||||
sigaddset(&ss, SIGINT);
|
||||
sigaddset(&ss, SIGQUIT);
|
||||
sigaddset(&ss, SIGTERM);
|
||||
sigaddset(&ss, SIGPIPE);
|
||||
sigaddset(&ss, SIGUSR1);
|
||||
sigaddset(&ss, SIGUSR2);
|
||||
sigprocmask(SIG_BLOCK, &ss, 0);
|
||||
|
||||
pthread_spin_lock(&shared->montermlock);
|
||||
if (!id) {
|
||||
if ((tty = open(monitortty, O_RDWR | O_NOCTTY)) != -1) {
|
||||
tcgetattr(tty, &oldterm);
|
||||
term = oldterm;
|
||||
term.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON);
|
||||
term.c_lflag &= ~(ECHO | ICANON | IEXTEN | ISIG);
|
||||
term.c_oflag |= OPOST | ONLCR;
|
||||
term.c_iflag |= IUTF8;
|
||||
term.c_cflag |= CS8;
|
||||
term.c_cc[VMIN] = 1;
|
||||
term.c_cc[VTIME] = 0;
|
||||
tcsetattr(tty, TCSANOW, &term);
|
||||
WRITE(tty, "\e[?25l", 6);
|
||||
}
|
||||
}
|
||||
pthread_spin_unlock(&shared->montermlock);
|
||||
|
||||
if (tty != -1) {
|
||||
for (gen = 0, mi = 0, b = 0; !terminatemonitor;) {
|
||||
workers = atomic_load_explicit(&shared->workers, memory_order_relaxed);
|
||||
if (id)
|
||||
id = MAX(1, MIN(id, workers));
|
||||
if (!id && workers) {
|
||||
usleep(50000);
|
||||
continue;
|
||||
}
|
||||
|
||||
++gen;
|
||||
intervals = atomic_load_explicit(&_mmi.i, memory_order_relaxed);
|
||||
if ((mi2 = realloc(mi, (intervals += 3) * sizeof(*mi)))) {
|
||||
mi = mi2;
|
||||
mi[0].x = (intptr_t)__executable_start >> 16;
|
||||
mi[0].size = _etext - __executable_start;
|
||||
mi[0].flags = 0;
|
||||
mi[1].x = (intptr_t)_etext >> 16;
|
||||
mi[1].size = _edata - _etext;
|
||||
mi[1].flags = 0;
|
||||
mi[2].x = (intptr_t)_edata >> 16;
|
||||
mi[2].size = _end - _edata;
|
||||
mi[2].flags = 0;
|
||||
__mmi_lock();
|
||||
if (_mmi.i == intervals - 3) {
|
||||
memcpy(mi + 3, _mmi.p, _mmi.i * sizeof(*mi));
|
||||
ok = true;
|
||||
} else {
|
||||
ok = false;
|
||||
}
|
||||
__mmi_unlock();
|
||||
if (!ok) {
|
||||
VERBOSEF("(memv) retrying due to contention on mmap table");
|
||||
continue;
|
||||
}
|
||||
|
||||
ws.ws_col = 80;
|
||||
ws.ws_row = 40;
|
||||
tcgetwinsize(tty, &ws);
|
||||
|
||||
appendr(&b, 0);
|
||||
appends(&b, "\e[H\e[1m");
|
||||
|
||||
for (i = 0; i < intervals; ++i) {
|
||||
addr = (char *)((int64_t)((uint64_t)mi[i].x << 32) >> 16);
|
||||
color = 0;
|
||||
appendf(&b, "\e[0m%lx", addr);
|
||||
int pagesz = getauxval(AT_PAGESZ);
|
||||
pages = (mi[i].size + pagesz - 1) / pagesz;
|
||||
for (j = 0; j < pages; ++j) {
|
||||
rc = mincore(addr + j * pagesz, pagesz, &rez);
|
||||
if (!rc) {
|
||||
if (rez & 1) {
|
||||
if (mi[i].flags & MAP_SHARED) {
|
||||
color2 = 105;
|
||||
} else {
|
||||
color2 = 42;
|
||||
}
|
||||
} else {
|
||||
color2 = 41;
|
||||
}
|
||||
} else {
|
||||
errno = 0;
|
||||
color2 = 0;
|
||||
}
|
||||
if (color != color2) {
|
||||
color = color2;
|
||||
appendf(&b, "\e[%dm", color);
|
||||
}
|
||||
if (mi[i].flags & MAP_ANONYMOUS) {
|
||||
appendw(&b, ' ');
|
||||
} else {
|
||||
appendw(&b, '/');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
appendf(&b,
|
||||
"\e[0m ID=%d PID=%d WS=%dx%d WORKERS=%d MODE=" MODE
|
||||
" GEN=%ld\e[J",
|
||||
id, getpid(), ws.ws_col, ws.ws_row, workers, gen);
|
||||
|
||||
pthread_spin_lock(&shared->montermlock);
|
||||
WRITE(tty, b, appendz(b).i);
|
||||
appendr(&b, 0);
|
||||
usleep(MONITOR_MICROS);
|
||||
pthread_spin_unlock(&shared->montermlock);
|
||||
} else {
|
||||
// running out of memory temporarily is a real possibility here
|
||||
// the right thing to do, is stand aside and let lua try to fix
|
||||
WARNF("(memv) we require more vespene gas");
|
||||
usleep(MONITOR_MICROS);
|
||||
}
|
||||
}
|
||||
|
||||
if (!id) {
|
||||
appendr(&b, 0);
|
||||
appends(&b, "\e[H\e[J\e[?25h");
|
||||
WRITE(tty, b, appendz(b).i);
|
||||
tcsetattr(tty, TCSANOW, &oldterm);
|
||||
}
|
||||
|
||||
DEBUGF("(memv) exiting...");
|
||||
close(tty);
|
||||
free(mi);
|
||||
free(b);
|
||||
}
|
||||
|
||||
DEBUGF("(memv) done");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void MonitorMemory(void) {
|
||||
errno_t err;
|
||||
if ((err = pthread_create(&monitorth, 0, MemoryMonitor, 0))) {
|
||||
WARNF("(memv) failed to start memory monitor %s", strerror(err));
|
||||
}
|
||||
}
|
||||
|
||||
static int HandleConnection(size_t i) {
|
||||
uint32_t ip;
|
||||
int pid, tok, rc = 0;
|
||||
|
@ -6939,9 +6765,6 @@ static int HandleConnection(size_t i) {
|
|||
} else {
|
||||
switch ((pid = fork())) {
|
||||
case 0:
|
||||
if (!IsTiny() && monitortty) {
|
||||
MonitorMemory();
|
||||
}
|
||||
meltdown = false;
|
||||
__isworker = true;
|
||||
connectionclose = false;
|
||||
|
@ -7445,7 +7268,6 @@ static void GetOpts(int argc, char *argv[]) {
|
|||
CASE('h', PrintUsage(1, EXIT_SUCCESS));
|
||||
CASE('M', ProgramMaxPayloadSize(ParseInt(optarg)));
|
||||
#if !IsTiny()
|
||||
CASE('W', monitortty = optarg);
|
||||
case 'f':
|
||||
funtrace = true;
|
||||
if (ftrace_install() == -1) {
|
||||
|
@ -7517,7 +7339,7 @@ void RedBean(int argc, char *argv[]) {
|
|||
heartbeatinterval.tv_sec = 5;
|
||||
CHECK_GT(CLK_TCK, 0);
|
||||
CHECK_NE(MAP_FAILED,
|
||||
(shared = mmap(NULL, ROUNDUP(sizeof(struct Shared), FRAMESIZE),
|
||||
(shared = mmap(NULL, ROUNDUP(sizeof(struct Shared), __granularity()),
|
||||
PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS,
|
||||
-1, 0)));
|
||||
if (daemonize) {
|
||||
|
@ -7578,14 +7400,6 @@ void RedBean(int argc, char *argv[]) {
|
|||
inbuf = inbuf_actual;
|
||||
isinitialized = true;
|
||||
CallSimpleHookIfDefined("OnServerStart");
|
||||
if (!IsTiny()) {
|
||||
if (monitortty && (daemonize || uniprocess)) {
|
||||
monitortty = 0;
|
||||
}
|
||||
if (monitortty) {
|
||||
MonitorMemory();
|
||||
}
|
||||
}
|
||||
#ifdef STATIC
|
||||
EventLoop(timespec_tomillis(heartbeatinterval));
|
||||
#else
|
||||
|
@ -7596,13 +7410,6 @@ void RedBean(int argc, char *argv[]) {
|
|||
}
|
||||
#endif
|
||||
if (!isexitingworker) {
|
||||
if (!IsTiny()) {
|
||||
terminatemonitor = true;
|
||||
if (monitorth) {
|
||||
pthread_join(monitorth, 0);
|
||||
monitorth = 0;
|
||||
}
|
||||
}
|
||||
HandleShutdown();
|
||||
CallSimpleHookIfDefined("OnServerStop");
|
||||
}
|
||||
|
|
|
@ -970,7 +970,7 @@ int Plinko(int argc, char *argv[]) {
|
|||
}
|
||||
|
||||
if (mmap((void *)0x200000000000,
|
||||
ROUNDUP((TERM + 1) * sizeof(g_mem[0]), FRAMESIZE),
|
||||
ROUNDUP((TERM + 1) * sizeof(g_mem[0]), __granularity()),
|
||||
PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE | MAP_FIXED, -1,
|
||||
0) == MAP_FAILED ||
|
||||
mmap((void *)(0x200000000000 +
|
||||
|
@ -979,7 +979,7 @@ int Plinko(int argc, char *argv[]) {
|
|||
PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE | MAP_FIXED, -1,
|
||||
0) == MAP_FAILED ||
|
||||
mmap((void *)0x400000000000,
|
||||
ROUNDUP((TERM + 1) * sizeof(g_mem[0]), FRAMESIZE),
|
||||
ROUNDUP((TERM + 1) * sizeof(g_mem[0]), __granularity()),
|
||||
PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE | MAP_FIXED, -1,
|
||||
0) == MAP_FAILED ||
|
||||
mmap((void *)(0x400000000000 +
|
||||
|
|
|
@ -452,7 +452,7 @@ static void PrintImage(unsigned yn, unsigned xn,
|
|||
size_t size;
|
||||
char *v, *vt;
|
||||
size = yn * (xn * (32 + (2 + (1 + 3) * 3) * 2 + 1 + 3)) * 1 + 5 + 1;
|
||||
size = ROUNDUP(size, FRAMESIZE);
|
||||
size = ROUNDUP(size, __granularity());
|
||||
CHECK_NOTNULL((vt = _mapanon(size)));
|
||||
v = RenderImage(vt, yn, xn, rgb);
|
||||
*v++ = '\r';
|
||||
|
@ -550,8 +550,8 @@ static void LoadFile(const char *path, size_t yn, size_t xn, void *rgb) {
|
|||
stbir_resize_uint8(data, gotx, goty, 0, rgb, xn * XS, yn * YS, 0, CN);
|
||||
#else
|
||||
CHECK_EQ(CN, 3);
|
||||
data2size = ROUNDUP(sizeof(float) * goty * gotx * CN, FRAMESIZE);
|
||||
data3size = ROUNDUP(sizeof(float) * yn * YS * xn * XS * CN, FRAMESIZE);
|
||||
data2size = ROUNDUP(sizeof(float) * goty * gotx * CN, __granularity());
|
||||
data3size = ROUNDUP(sizeof(float) * yn * YS * xn * XS * CN, __granularity());
|
||||
CHECK_NOTNULL((data2 = _mapanon(data2size)));
|
||||
CHECK_NOTNULL((data3 = _mapanon(data3size)));
|
||||
rgb2lin(goty * gotx * CN, data2, data);
|
||||
|
@ -625,7 +625,7 @@ int main(int argc, char *argv[]) {
|
|||
// FIXME: on the conversion stage should do 2Y because of halfblocks
|
||||
// printf( "filename >%s<\tx >%d<\ty >%d<\n\n", filename, x_, y_);
|
||||
size = y_ * YS * x_ * XS * CN;
|
||||
CHECK_NOTNULL((rgb = _mapanon(ROUNDUP(size, FRAMESIZE))));
|
||||
CHECK_NOTNULL((rgb = _mapanon(ROUNDUP(size, __granularity()))));
|
||||
for (i = optind; i < argc; ++i) {
|
||||
if (!argv[i])
|
||||
continue;
|
||||
|
@ -636,7 +636,7 @@ int main(int argc, char *argv[]) {
|
|||
}
|
||||
PrintImage(y_, x_, rgb);
|
||||
}
|
||||
munmap(rgb, ROUNDUP(size, FRAMESIZE));
|
||||
munmap(rgb, ROUNDUP(size, __granularity()));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -37,7 +37,8 @@ forceinline void ConvolveGradient(unsigned yn, unsigned xn,
|
|||
size_t size;
|
||||
unsigned y, x, i, j, k;
|
||||
float py[4], px[4], (*tmp)[yn][xn][4];
|
||||
tmp = _mapanon((size = ROUNDUP(sizeof(float) * 4 * xn * yn, FRAMESIZE)));
|
||||
tmp =
|
||||
_mapanon((size = ROUNDUP(sizeof(float) * 4 * xn * yn, __granularity())));
|
||||
for (y = 0; y < yn - KW + 1; ++y) {
|
||||
for (x = 0; x < xn - KW + 1; ++x) {
|
||||
for (k = 0; k < 4; ++k)
|
||||
|
|
|
@ -281,8 +281,8 @@ static void SetupCanvas(void) {
|
|||
munmap(buffer, buffersize);
|
||||
}
|
||||
displaysize = ROUNDUP(ROUNDUP((tyn * txn) << zoom, 16), 1ul << zoom);
|
||||
canvassize = ROUNDUP(displaysize, FRAMESIZE);
|
||||
buffersize = ROUNDUP(tyn * txn * 16 + 4096, FRAMESIZE);
|
||||
canvassize = ROUNDUP(displaysize, __granularity());
|
||||
buffersize = ROUNDUP(tyn * txn * 16 + 4096, __granularity());
|
||||
canvas = Allocate(canvassize);
|
||||
buffer = Allocate(buffersize);
|
||||
}
|
||||
|
|
|
@ -785,7 +785,7 @@ static void RasterIt(void) {
|
|||
static bool once;
|
||||
static void *buf;
|
||||
if (!once) {
|
||||
buf = _mapanon(ROUNDUP(fb0_.size, FRAMESIZE));
|
||||
buf = _mapanon(ROUNDUP(fb0_.size, __granularity()));
|
||||
once = true;
|
||||
}
|
||||
WriteToFrameBuffer(fb0_.vscreen.yres_virtual, fb0_.vscreen.xres_virtual, buf,
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
int fd;
|
||||
bool exited;
|
||||
struct stat st;
|
||||
char buf[FRAMESIZE];
|
||||
char buf[65536];
|
||||
|
||||
int WriteString(const char *s) {
|
||||
return write(1, s, strlen(s));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue