Skip to content
This repository has been archived by the owner on Nov 29, 2024. It is now read-only.

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
BaseMax committed Nov 18, 2024
2 parents 2e87d95 + 4f83806 commit 77c05c7
Showing 1 changed file with 327 additions and 0 deletions.
327 changes: 327 additions & 0 deletions salam-wa.js
Original file line number Diff line number Diff line change
Expand Up @@ -4363,6 +4363,333 @@ function ___syscall_open(path, flags, varargs) {
if (typeof FS == 'undefined' || !(e instanceof FS.ErrnoError)) throw e;
return -e.errno;
}
<<<<<<< HEAD
=======
}

var __abort_js = () => {
abort('native code called abort()');
};

var __emscripten_memcpy_js = (dest, src, num) => HEAPU8.copyWithin(dest, src, src + num);

var getHeapMax = () =>
// Stay one Wasm page short of 4GB: while e.g. Chrome is able to allocate
// full 4GB Wasm memories, the size will wrap back to 0 bytes in Wasm side
// for any code that deals with heap sizes, which would require special
// casing all heap size related code to treat 0 specially.
2147483648;


var _emscripten_get_now = () => performance.now();

var growMemory = (size) => {
var b = wasmMemory.buffer;
var pages = ((size - b.byteLength + 65535) / 65536) | 0;
try {
// round size grow request up to wasm page size (fixed 64KB per spec)
wasmMemory.grow(pages); // .grow() takes a delta compared to the previous size
updateMemoryViews();
return 1 /*success*/;
} catch(e) {
err(`growMemory: Attempted to grow heap from ${b.byteLength} bytes to ${size} bytes, but got error: ${e}`);
}
// implicit 0 return to save code size (caller will cast "undefined" into 0
// anyhow)
};
var _emscripten_resize_heap = (requestedSize) => {
var oldSize = HEAPU8.length;
// With CAN_ADDRESS_2GB or MEMORY64, pointers are already unsigned.
requestedSize >>>= 0;
// With multithreaded builds, races can happen (another thread might increase the size
// in between), so return a failure, and let the caller retry.
assert(requestedSize > oldSize);

// Memory resize rules:
// 1. Always increase heap size to at least the requested size, rounded up
// to next page multiple.
// 2a. If MEMORY_GROWTH_LINEAR_STEP == -1, excessively resize the heap
// geometrically: increase the heap size according to
// MEMORY_GROWTH_GEOMETRIC_STEP factor (default +20%), At most
// overreserve by MEMORY_GROWTH_GEOMETRIC_CAP bytes (default 96MB).
// 2b. If MEMORY_GROWTH_LINEAR_STEP != -1, excessively resize the heap
// linearly: increase the heap size by at least
// MEMORY_GROWTH_LINEAR_STEP bytes.
// 3. Max size for the heap is capped at 2048MB-WASM_PAGE_SIZE, or by
// MAXIMUM_MEMORY, or by ASAN limit, depending on which is smallest
// 4. If we were unable to allocate as much memory, it may be due to
// over-eager decision to excessively reserve due to (3) above.
// Hence if an allocation fails, cut down on the amount of excess
// growth, in an attempt to succeed to perform a smaller allocation.

// A limit is set for how much we can grow. We should not exceed that
// (the wasm binary specifies it, so if we tried, we'd fail anyhow).
var maxHeapSize = getHeapMax();
if (requestedSize > maxHeapSize) {
err(`Cannot enlarge memory, requested ${requestedSize} bytes, but the limit is ${maxHeapSize} bytes!`);
return false;
}

// Loop through potential heap size increases. If we attempt a too eager
// reservation that fails, cut down on the attempted size and reserve a
// smaller bump instead. (max 3 times, chosen somewhat arbitrarily)
for (var cutDown = 1; cutDown <= 4; cutDown *= 2) {
var overGrownHeapSize = oldSize * (1 + 0.2 / cutDown); // ensure geometric growth
// but limit overreserving (default to capping at +96MB overgrowth at most)
overGrownHeapSize = Math.min(overGrownHeapSize, requestedSize + 100663296 );

var newSize = Math.min(maxHeapSize, alignMemory(Math.max(requestedSize, overGrownHeapSize), 65536));

var t0 = _emscripten_get_now();
var replacement = growMemory(newSize);
var t1 = _emscripten_get_now();
dbg(`Heap resize call from ${oldSize} to ${newSize} took ${(t1 - t0)} msecs. Success: ${!!replacement}`);
if (replacement) {

return true;
}
}
err(`Failed to grow the heap from ${oldSize} bytes to ${newSize} bytes, not enough memory!`);
return false;
};

var ENV = {
};

var getExecutableName = () => {
return thisProgram || './this.program';
};
var getEnvStrings = () => {
if (!getEnvStrings.strings) {
// Default values.
// Browser language detection #8751
var lang = ((typeof navigator == 'object' && navigator.languages && navigator.languages[0]) || 'C').replace('-', '_') + '.UTF-8';
var env = {
'USER': 'web_user',
'LOGNAME': 'web_user',
'PATH': '/',
'PWD': '/',
'HOME': '/home/web_user',
'LANG': lang,
'_': getExecutableName()
};
// Apply the user-provided values, if any.
for (var x in ENV) {
// x is a key in ENV; if ENV[x] is undefined, that means it was
// explicitly set to be so. We allow user code to do that to
// force variables with default values to remain unset.
if (ENV[x] === undefined) delete env[x];
else env[x] = ENV[x];
}
var strings = [];
for (var x in env) {
strings.push(`${x}=${env[x]}`);
}
getEnvStrings.strings = strings;
}
return getEnvStrings.strings;
};

var stringToAscii = (str, buffer) => {
for (var i = 0; i < str.length; ++i) {
assert(str.charCodeAt(i) === (str.charCodeAt(i) & 0xff));
HEAP8[buffer++] = str.charCodeAt(i);checkInt8(str.charCodeAt(i));
}
// Null-terminate the string
HEAP8[buffer] = 0;checkInt8(0);
};
var _environ_get = (__environ, environ_buf) => {
var bufSize = 0;
getEnvStrings().forEach((string, i) => {
var ptr = environ_buf + bufSize;
HEAPU32[(((__environ)+(i*4))>>2)] = ptr;checkInt32(ptr);
stringToAscii(string, ptr);
bufSize += string.length + 1;
});
return 0;
};

var _environ_sizes_get = (penviron_count, penviron_buf_size) => {
var strings = getEnvStrings();
HEAPU32[((penviron_count)>>2)] = strings.length;checkInt32(strings.length);
var bufSize = 0;
strings.forEach((string) => bufSize += string.length + 1);
HEAPU32[((penviron_buf_size)>>2)] = bufSize;checkInt32(bufSize);
return 0;
};


var runtimeKeepaliveCounter = 0;
var keepRuntimeAlive = () => noExitRuntime || runtimeKeepaliveCounter > 0;
var _proc_exit = (code) => {
EXITSTATUS = code;
if (!keepRuntimeAlive()) {
Module['onExit']?.(code);
ABORT = true;
}
quit_(code, new ExitStatus(code));
};


/** @suppress {duplicate } */
/** @param {boolean|number=} implicit */
var exitJS = (status, implicit) => {
EXITSTATUS = status;

checkUnflushedContent();

// if exit() was called explicitly, warn the user if the runtime isn't actually being shut down
if (keepRuntimeAlive() && !implicit) {
var msg = `program exited (with status: ${status}), but keepRuntimeAlive() is set (counter=${runtimeKeepaliveCounter}) due to an async operation, so halting execution but not exiting the runtime or preventing further async execution (you can use emscripten_force_exit, if you want to force a true shutdown)`;
err(msg);
}

_proc_exit(status);
};
var _exit = exitJS;

function _fd_close(fd) {
try {

var stream = SYSCALLS.getStreamFromFD(fd);
FS.close(stream);
return 0;
} catch (e) {
if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
return e.errno;
}
}

/** @param {number=} offset */
var doReadv = (stream, iov, iovcnt, offset) => {
var ret = 0;
for (var i = 0; i < iovcnt; i++) {
var ptr = HEAPU32[((iov)>>2)];
var len = HEAPU32[(((iov)+(4))>>2)];
iov += 8;
var curr = FS.read(stream, HEAP8, ptr, len, offset);
if (curr < 0) return -1;
ret += curr;
if (curr < len) break; // nothing more to read
if (typeof offset != 'undefined') {
offset += curr;
}
}
return ret;
};

function _fd_read(fd, iov, iovcnt, pnum) {
try {

var stream = SYSCALLS.getStreamFromFD(fd);
var num = doReadv(stream, iov, iovcnt);
HEAPU32[((pnum)>>2)] = num;checkInt32(num);
return 0;
} catch (e) {
if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
return e.errno;
}
}


var convertI32PairToI53Checked = (lo, hi) => {
assert(lo == (lo >>> 0) || lo == (lo|0)); // lo should either be a i32 or a u32
assert(hi === (hi|0)); // hi should be a i32
return ((hi + 0x200000) >>> 0 < 0x400001 - !!lo) ? (lo >>> 0) + hi * 4294967296 : NaN;
};
function _fd_seek(fd,offset_low, offset_high,whence,newOffset) {
var offset = convertI32PairToI53Checked(offset_low, offset_high);


try {

if (isNaN(offset)) return 61;
var stream = SYSCALLS.getStreamFromFD(fd);
FS.llseek(stream, offset, whence);
(tempI64 = [stream.position>>>0,(tempDouble = stream.position,(+(Math.abs(tempDouble))) >= 1.0 ? (tempDouble > 0.0 ? (+(Math.floor((tempDouble)/4294967296.0)))>>>0 : (~~((+(Math.ceil((tempDouble - +(((~~(tempDouble)))>>>0))/4294967296.0)))))>>>0) : 0)], HEAP32[((newOffset)>>2)] = tempI64[0],HEAP32[(((newOffset)+(4))>>2)] = tempI64[1]);checkInt64(stream.position);
if (stream.getdents && offset === 0 && whence === 0) stream.getdents = null; // reset readdir state
return 0;
} catch (e) {
if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
return e.errno;
}
;
}

/** @param {number=} offset */
var doWritev = (stream, iov, iovcnt, offset) => {
var ret = 0;
for (var i = 0; i < iovcnt; i++) {
var ptr = HEAPU32[((iov)>>2)];
var len = HEAPU32[(((iov)+(4))>>2)];
iov += 8;
var curr = FS.write(stream, HEAP8, ptr, len, offset);
if (curr < 0) return -1;
ret += curr;
if (curr < len) {
// No more space to write.
break;
}
if (typeof offset != 'undefined') {
offset += curr;
}
}
return ret;
};

function _fd_write(fd, iov, iovcnt, pnum) {
try {

var stream = SYSCALLS.getStreamFromFD(fd);
var num = doWritev(stream, iov, iovcnt);
HEAPU32[((pnum)>>2)] = num;checkInt32(num);
return 0;
} catch (e) {
if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
return e.errno;
}
}


var handleException = (e) => {
// Certain exception types we do not treat as errors since they are used for
// internal control flow.
// 1. ExitStatus, which is thrown by exit()
// 2. "unwind", which is thrown by emscripten_unwind_to_js_event_loop() and others
// that wish to return to JS event loop.
if (e instanceof ExitStatus || e == 'unwind') {
return EXITSTATUS;
}
checkStackCookie();
if (e instanceof WebAssembly.RuntimeError) {
if (_emscripten_stack_get_current() <= 0) {
err('Stack overflow detected. You can try increasing -sSTACK_SIZE (currently set to 8388608)');
}
}
quit_(1, e);
};


var stringToUTF8 = (str, outPtr, maxBytesToWrite) => {
assert(typeof maxBytesToWrite == 'number', 'stringToUTF8(str, outPtr, maxBytesToWrite) is missing the third parameter that specifies the length of the output buffer!');
return stringToUTF8Array(str, HEAPU8, outPtr, maxBytesToWrite);
};

var stackAlloc = (sz) => __emscripten_stack_alloc(sz);
var stringToUTF8OnStack = (str) => {
var size = lengthBytesUTF8(str) + 1;
var ret = stackAlloc(size);
stringToUTF8(str, ret, size);
return ret;
};

FS.createPreloadedFile = FS_createPreloadedFile;
FS.staticInit();
// Set module methods based on EXPORTED_RUNTIME_METHODS
;
function checkIncomingModuleAPI() {
ignoredModuleProp('fetchSettings');
>>>>>>> 4f83806ea21c491863aba6239ff1f1376fb137bf
}

function _abort() {
Expand Down

0 comments on commit 77c05c7

Please sign in to comment.