@php-wasm/node 1.1.3 → 1.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/asyncify/7_2_34/php_7_2.wasm +0 -0
- package/asyncify/7_3_33/php_7_3.wasm +0 -0
- package/asyncify/7_4_33/php_7_4.wasm +0 -0
- package/asyncify/8_0_30/php_8_0.wasm +0 -0
- package/asyncify/8_1_23/php_8_1.wasm +0 -0
- package/asyncify/8_2_10/php_8_2.wasm +0 -0
- package/asyncify/8_3_0/php_8_3.wasm +0 -0
- package/asyncify/8_4_0/php_8_4.wasm +0 -0
- package/asyncify/php_7_2.js +178 -138
- package/asyncify/php_7_3.js +177 -137
- package/asyncify/php_7_4.js +176 -136
- package/asyncify/php_8_0.js +180 -140
- package/asyncify/php_8_1.js +179 -139
- package/asyncify/php_8_2.js +180 -140
- package/asyncify/php_8_3.js +180 -140
- package/asyncify/php_8_4.js +179 -139
- package/fs_ext.node +0 -0
- package/index.cjs +9170 -3617
- package/index.js +9054 -3617
- package/jspi/7_2_34/php_7_2.wasm +0 -0
- package/jspi/7_3_33/php_7_3.wasm +0 -0
- package/jspi/7_4_33/php_7_4.wasm +0 -0
- package/jspi/8_0_30/php_8_0.wasm +0 -0
- package/jspi/8_1_23/php_8_1.wasm +0 -0
- package/jspi/8_2_10/php_8_2.wasm +0 -0
- package/jspi/8_3_0/php_8_3.wasm +0 -0
- package/jspi/8_4_0/php_8_4.wasm +0 -0
- package/jspi/php_7_2.js +1922 -1286
- package/jspi/php_7_3.js +1922 -1286
- package/jspi/php_7_4.js +9262 -7705
- package/jspi/php_8_0.js +1922 -1286
- package/jspi/php_8_1.js +2434 -1798
- package/jspi/php_8_2.js +2414 -1778
- package/jspi/php_8_3.js +2414 -1778
- package/jspi/php_8_4.js +2414 -1778
- package/lib/file-lock-manager-for-node.d.ts +149 -0
- package/lib/file-lock-manager.d.ts +96 -0
- package/lib/index.d.ts +2 -0
- package/lib/load-runtime.d.ts +31 -2
- package/package.json +10 -9
package/jspi/php_8_0.js
CHANGED
|
@@ -8,7 +8,7 @@ import path from 'path';
|
|
|
8
8
|
|
|
9
9
|
const dependencyFilename = path.join(__dirname, '8_0_30', 'php_8_0.wasm');
|
|
10
10
|
export { dependencyFilename };
|
|
11
|
-
export const dependenciesTotalSize =
|
|
11
|
+
export const dependenciesTotalSize = 17169869;
|
|
12
12
|
export function init(RuntimeName, PHPLoader) {
|
|
13
13
|
// The rest of the code comes from the built php.js file and esm-suffix.js
|
|
14
14
|
// include: shell.js
|
|
@@ -5227,7 +5227,360 @@ export function init(RuntimeName, PHPLoader) {
|
|
|
5227
5227
|
|
|
5228
5228
|
var syscallGetVarargP = syscallGetVarargI;
|
|
5229
5229
|
|
|
5230
|
-
|
|
5230
|
+
var stringToUTF8 = (str, outPtr, maxBytesToWrite) =>
|
|
5231
|
+
stringToUTF8Array(str, HEAPU8, outPtr, maxBytesToWrite);
|
|
5232
|
+
|
|
5233
|
+
Module['stringToUTF8'] = stringToUTF8;
|
|
5234
|
+
|
|
5235
|
+
var stackAlloc = (sz) => __emscripten_stack_alloc(sz);
|
|
5236
|
+
|
|
5237
|
+
/** @suppress {duplicate } */ var stringToUTF8OnStack = (str) => {
|
|
5238
|
+
var size = lengthBytesUTF8(str) + 1;
|
|
5239
|
+
var ret = stackAlloc(size);
|
|
5240
|
+
stringToUTF8(str, ret, size);
|
|
5241
|
+
return ret;
|
|
5242
|
+
};
|
|
5243
|
+
|
|
5244
|
+
var allocateUTF8OnStack = stringToUTF8OnStack;
|
|
5245
|
+
|
|
5246
|
+
var PHPWASM = {
|
|
5247
|
+
init: function () {
|
|
5248
|
+
// The /internal directory is required by the C module. It's where the
|
|
5249
|
+
// stdout, stderr, and headers information are written for the JavaScript
|
|
5250
|
+
// code to read later on.
|
|
5251
|
+
FS.mkdir('/internal');
|
|
5252
|
+
// The files from the shared directory are shared between all the
|
|
5253
|
+
// PHP processes managed by PHPProcessManager.
|
|
5254
|
+
FS.mkdir('/internal/shared');
|
|
5255
|
+
// The files from the preload directory are preloaded using the
|
|
5256
|
+
// auto_prepend_file php.ini directive.
|
|
5257
|
+
FS.mkdir('/internal/shared/preload');
|
|
5258
|
+
// Create stdout and stderr devices. We can't just use Emscripten's
|
|
5259
|
+
// default stdout and stderr devices because they stop processing data
|
|
5260
|
+
// on the first null byte. However, when dealing with binary data,
|
|
5261
|
+
// null bytes are valid and common.
|
|
5262
|
+
FS.registerDevice(FS.makedev(64, 0), {
|
|
5263
|
+
open: () => {},
|
|
5264
|
+
close: () => {},
|
|
5265
|
+
read: () => 0,
|
|
5266
|
+
write: (stream, buffer, offset, length, pos) => {
|
|
5267
|
+
const chunk = buffer.subarray(offset, offset + length);
|
|
5268
|
+
PHPWASM.onStdout(chunk);
|
|
5269
|
+
return length;
|
|
5270
|
+
},
|
|
5271
|
+
});
|
|
5272
|
+
FS.mkdev('/internal/stdout', FS.makedev(64, 0));
|
|
5273
|
+
FS.registerDevice(FS.makedev(63, 0), {
|
|
5274
|
+
open: () => {},
|
|
5275
|
+
close: () => {},
|
|
5276
|
+
read: () => 0,
|
|
5277
|
+
write: (stream, buffer, offset, length, pos) => {
|
|
5278
|
+
const chunk = buffer.subarray(offset, offset + length);
|
|
5279
|
+
PHPWASM.onStderr(chunk);
|
|
5280
|
+
return length;
|
|
5281
|
+
},
|
|
5282
|
+
});
|
|
5283
|
+
FS.mkdev('/internal/stderr', FS.makedev(63, 0));
|
|
5284
|
+
FS.registerDevice(FS.makedev(62, 0), {
|
|
5285
|
+
open: () => {},
|
|
5286
|
+
close: () => {},
|
|
5287
|
+
read: () => 0,
|
|
5288
|
+
write: (stream, buffer, offset, length, pos) => {
|
|
5289
|
+
const chunk = buffer.subarray(offset, offset + length);
|
|
5290
|
+
PHPWASM.onHeaders(chunk);
|
|
5291
|
+
return length;
|
|
5292
|
+
},
|
|
5293
|
+
});
|
|
5294
|
+
FS.mkdev('/internal/headers', FS.makedev(62, 0));
|
|
5295
|
+
// Handle events.
|
|
5296
|
+
PHPWASM.EventEmitter = ENVIRONMENT_IS_NODE
|
|
5297
|
+
? require('events').EventEmitter
|
|
5298
|
+
: class EventEmitter {
|
|
5299
|
+
constructor() {
|
|
5300
|
+
this.listeners = {};
|
|
5301
|
+
}
|
|
5302
|
+
emit(eventName, data) {
|
|
5303
|
+
if (this.listeners[eventName]) {
|
|
5304
|
+
this.listeners[eventName].forEach(
|
|
5305
|
+
(callback) => {
|
|
5306
|
+
callback(data);
|
|
5307
|
+
}
|
|
5308
|
+
);
|
|
5309
|
+
}
|
|
5310
|
+
}
|
|
5311
|
+
once(eventName, callback) {
|
|
5312
|
+
const self = this;
|
|
5313
|
+
function removedCallback() {
|
|
5314
|
+
callback(...arguments);
|
|
5315
|
+
self.removeListener(eventName, removedCallback);
|
|
5316
|
+
}
|
|
5317
|
+
this.on(eventName, removedCallback);
|
|
5318
|
+
}
|
|
5319
|
+
removeAllListeners(eventName) {
|
|
5320
|
+
if (eventName) {
|
|
5321
|
+
delete this.listeners[eventName];
|
|
5322
|
+
} else {
|
|
5323
|
+
this.listeners = {};
|
|
5324
|
+
}
|
|
5325
|
+
}
|
|
5326
|
+
removeListener(eventName, callback) {
|
|
5327
|
+
if (this.listeners[eventName]) {
|
|
5328
|
+
const idx =
|
|
5329
|
+
this.listeners[eventName].indexOf(callback);
|
|
5330
|
+
if (idx !== -1) {
|
|
5331
|
+
this.listeners[eventName].splice(idx, 1);
|
|
5332
|
+
}
|
|
5333
|
+
}
|
|
5334
|
+
}
|
|
5335
|
+
};
|
|
5336
|
+
// Clean up the fd -> childProcess mapping when the fd is closed:
|
|
5337
|
+
const originalClose = FS.close;
|
|
5338
|
+
FS.close = function (stream) {
|
|
5339
|
+
originalClose(stream);
|
|
5340
|
+
delete PHPWASM.child_proc_by_fd[stream.fd];
|
|
5341
|
+
};
|
|
5342
|
+
PHPWASM.child_proc_by_fd = {};
|
|
5343
|
+
PHPWASM.child_proc_by_pid = {};
|
|
5344
|
+
PHPWASM.input_devices = {};
|
|
5345
|
+
const originalWrite = TTY.stream_ops.write;
|
|
5346
|
+
TTY.stream_ops.write = function (stream, ...rest) {
|
|
5347
|
+
const retval = originalWrite(stream, ...rest);
|
|
5348
|
+
// Implicit flush since PHP's fflush() doesn't seem to trigger the fsync event
|
|
5349
|
+
// @TODO: Fix this at the wasm level
|
|
5350
|
+
stream.tty.ops.fsync(stream.tty);
|
|
5351
|
+
return retval;
|
|
5352
|
+
};
|
|
5353
|
+
const originalPutChar = TTY.stream_ops.put_char;
|
|
5354
|
+
TTY.stream_ops.put_char = function (tty, val) {
|
|
5355
|
+
/**
|
|
5356
|
+
* Buffer newlines that Emscripten normally ignores.
|
|
5357
|
+
*
|
|
5358
|
+
* Emscripten doesn't do it by default because its default
|
|
5359
|
+
* print function is console.log that implicitly adds a newline. We are overwriting
|
|
5360
|
+
* it with an environment-specific function that outputs exaclty what it was given,
|
|
5361
|
+
* e.g. in Node.js it's process.stdout.write(). Therefore, we need to mak sure
|
|
5362
|
+
* all the newlines make it to the output buffer.
|
|
5363
|
+
*/ if (val === 10) tty.output.push(val);
|
|
5364
|
+
return originalPutChar(tty, val);
|
|
5365
|
+
};
|
|
5366
|
+
},
|
|
5367
|
+
onHeaders: function (chunk) {
|
|
5368
|
+
if (Module['onHeaders']) {
|
|
5369
|
+
Module['onHeaders'](chunk);
|
|
5370
|
+
return;
|
|
5371
|
+
}
|
|
5372
|
+
console.log('headers', {
|
|
5373
|
+
chunk,
|
|
5374
|
+
});
|
|
5375
|
+
},
|
|
5376
|
+
onStdout: function (chunk) {
|
|
5377
|
+
if (Module['onStdout']) {
|
|
5378
|
+
Module['onStdout'](chunk);
|
|
5379
|
+
return;
|
|
5380
|
+
}
|
|
5381
|
+
if (ENVIRONMENT_IS_NODE) {
|
|
5382
|
+
process.stdout.write(chunk);
|
|
5383
|
+
} else {
|
|
5384
|
+
console.log('stdout', {
|
|
5385
|
+
chunk,
|
|
5386
|
+
});
|
|
5387
|
+
}
|
|
5388
|
+
},
|
|
5389
|
+
onStderr: function (chunk) {
|
|
5390
|
+
if (Module['onStderr']) {
|
|
5391
|
+
Module['onStderr'](chunk);
|
|
5392
|
+
return;
|
|
5393
|
+
}
|
|
5394
|
+
if (ENVIRONMENT_IS_NODE) {
|
|
5395
|
+
process.stderr.write(chunk);
|
|
5396
|
+
} else {
|
|
5397
|
+
console.warn('stderr', {
|
|
5398
|
+
chunk,
|
|
5399
|
+
});
|
|
5400
|
+
}
|
|
5401
|
+
},
|
|
5402
|
+
getAllWebSockets: function (sock) {
|
|
5403
|
+
const webSockets = new Set();
|
|
5404
|
+
if (sock.server) {
|
|
5405
|
+
sock.server.clients.forEach((ws) => {
|
|
5406
|
+
webSockets.add(ws);
|
|
5407
|
+
});
|
|
5408
|
+
}
|
|
5409
|
+
for (const peer of PHPWASM.getAllPeers(sock)) {
|
|
5410
|
+
webSockets.add(peer.socket);
|
|
5411
|
+
}
|
|
5412
|
+
return Array.from(webSockets);
|
|
5413
|
+
},
|
|
5414
|
+
getAllPeers: function (sock) {
|
|
5415
|
+
const peers = new Set();
|
|
5416
|
+
if (sock.server) {
|
|
5417
|
+
sock.pending
|
|
5418
|
+
.filter((pending) => pending.peers)
|
|
5419
|
+
.forEach((pending) => {
|
|
5420
|
+
for (const peer of Object.values(pending.peers)) {
|
|
5421
|
+
peers.add(peer);
|
|
5422
|
+
}
|
|
5423
|
+
});
|
|
5424
|
+
}
|
|
5425
|
+
if (sock.peers) {
|
|
5426
|
+
for (const peer of Object.values(sock.peers)) {
|
|
5427
|
+
peers.add(peer);
|
|
5428
|
+
}
|
|
5429
|
+
}
|
|
5430
|
+
return Array.from(peers);
|
|
5431
|
+
},
|
|
5432
|
+
awaitData: function (ws) {
|
|
5433
|
+
return PHPWASM.awaitEvent(ws, 'message');
|
|
5434
|
+
},
|
|
5435
|
+
awaitConnection: function (ws) {
|
|
5436
|
+
if (ws.OPEN === ws.readyState) {
|
|
5437
|
+
return [Promise.resolve(), PHPWASM.noop];
|
|
5438
|
+
}
|
|
5439
|
+
return PHPWASM.awaitEvent(ws, 'open');
|
|
5440
|
+
},
|
|
5441
|
+
awaitClose: function (ws) {
|
|
5442
|
+
if ([ws.CLOSING, ws.CLOSED].includes(ws.readyState)) {
|
|
5443
|
+
return [Promise.resolve(), PHPWASM.noop];
|
|
5444
|
+
}
|
|
5445
|
+
return PHPWASM.awaitEvent(ws, 'close');
|
|
5446
|
+
},
|
|
5447
|
+
awaitError: function (ws) {
|
|
5448
|
+
if ([ws.CLOSING, ws.CLOSED].includes(ws.readyState)) {
|
|
5449
|
+
return [Promise.resolve(), PHPWASM.noop];
|
|
5450
|
+
}
|
|
5451
|
+
return PHPWASM.awaitEvent(ws, 'error');
|
|
5452
|
+
},
|
|
5453
|
+
awaitEvent: function (ws, event) {
|
|
5454
|
+
let resolve;
|
|
5455
|
+
const listener = () => {
|
|
5456
|
+
resolve();
|
|
5457
|
+
};
|
|
5458
|
+
const promise = new Promise(function (_resolve) {
|
|
5459
|
+
resolve = _resolve;
|
|
5460
|
+
ws.once(event, listener);
|
|
5461
|
+
});
|
|
5462
|
+
const cancel = () => {
|
|
5463
|
+
ws.removeListener(event, listener);
|
|
5464
|
+
// Rejecting the promises bubbles up and kills the entire
|
|
5465
|
+
// node process. Let's resolve them on the next tick instead
|
|
5466
|
+
// to give the caller some space to unbind any handlers.
|
|
5467
|
+
setTimeout(resolve);
|
|
5468
|
+
};
|
|
5469
|
+
return [promise, cancel];
|
|
5470
|
+
},
|
|
5471
|
+
noop: function () {},
|
|
5472
|
+
spawnProcess: function (command, args, options) {
|
|
5473
|
+
if (Module['spawnProcess']) {
|
|
5474
|
+
const spawnedPromise = Module['spawnProcess'](
|
|
5475
|
+
command,
|
|
5476
|
+
args,
|
|
5477
|
+
options
|
|
5478
|
+
);
|
|
5479
|
+
return Promise.resolve(spawnedPromise).then(function (spawned) {
|
|
5480
|
+
if (!spawned || !spawned.on) {
|
|
5481
|
+
throw new Error(
|
|
5482
|
+
'spawnProcess() must return an EventEmitter but returned a different type.'
|
|
5483
|
+
);
|
|
5484
|
+
}
|
|
5485
|
+
return spawned;
|
|
5486
|
+
});
|
|
5487
|
+
}
|
|
5488
|
+
if (ENVIRONMENT_IS_NODE) {
|
|
5489
|
+
return require('child_process').spawn(command, args, {
|
|
5490
|
+
...options,
|
|
5491
|
+
shell: true,
|
|
5492
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
5493
|
+
timeout: 100,
|
|
5494
|
+
});
|
|
5495
|
+
}
|
|
5496
|
+
const e = new Error(
|
|
5497
|
+
'popen(), proc_open() etc. are unsupported in the browser. Call php.setSpawnHandler() ' +
|
|
5498
|
+
'and provide a callback to handle spawning processes, or disable a popen(), proc_open() ' +
|
|
5499
|
+
'and similar functions via php.ini.'
|
|
5500
|
+
);
|
|
5501
|
+
e.code = 'SPAWN_UNSUPPORTED';
|
|
5502
|
+
throw e;
|
|
5503
|
+
},
|
|
5504
|
+
shutdownSocket: function (socketd, how) {
|
|
5505
|
+
// This implementation only supports websockets at the moment
|
|
5506
|
+
const sock = getSocketFromFD(socketd);
|
|
5507
|
+
const peer = Object.values(sock.peers)[0];
|
|
5508
|
+
if (!peer) {
|
|
5509
|
+
return -1;
|
|
5510
|
+
}
|
|
5511
|
+
try {
|
|
5512
|
+
peer.socket.close();
|
|
5513
|
+
SOCKFS.websocket_sock_ops.removePeer(sock, peer);
|
|
5514
|
+
return 0;
|
|
5515
|
+
} catch (e) {
|
|
5516
|
+
console.log('Socket shutdown error', e);
|
|
5517
|
+
return -1;
|
|
5518
|
+
}
|
|
5519
|
+
},
|
|
5520
|
+
};
|
|
5521
|
+
|
|
5522
|
+
function _js_getpid() {
|
|
5523
|
+
return PHPLoader.processId ?? 42;
|
|
5524
|
+
}
|
|
5525
|
+
|
|
5526
|
+
function _js_wasm_trace(format, ...args) {
|
|
5527
|
+
if (PHPLoader.trace instanceof Function) {
|
|
5528
|
+
PHPLoader.trace(_js_getpid(), format, ...args);
|
|
5529
|
+
}
|
|
5530
|
+
}
|
|
5531
|
+
|
|
5532
|
+
function _fd_close(fd) {
|
|
5533
|
+
_js_wasm_trace('fd_close(%d)', fd);
|
|
5534
|
+
const [vfsPath, pathResolutionErrno] = locking.get_vfs_path_from_fd(fd);
|
|
5535
|
+
if (pathResolutionErrno !== 0) {
|
|
5536
|
+
_js_wasm_trace(
|
|
5537
|
+
'fd_close(%d) get_vfs_path_from_fd error %d',
|
|
5538
|
+
fd,
|
|
5539
|
+
pathResolutionErrno
|
|
5540
|
+
);
|
|
5541
|
+
return -ERRNO_CODES.EBADF;
|
|
5542
|
+
}
|
|
5543
|
+
const result = _builtin_fd_close(fd);
|
|
5544
|
+
if (result === 0 && locking.maybeLockedFds.has(fd)) {
|
|
5545
|
+
const nativeFilePath =
|
|
5546
|
+
locking.get_native_path_from_vfs_path(vfsPath);
|
|
5547
|
+
return PHPLoader.fileLockManager
|
|
5548
|
+
.releaseLocksForProcessFd(
|
|
5549
|
+
PHPLoader.processId,
|
|
5550
|
+
fd,
|
|
5551
|
+
nativeFilePath
|
|
5552
|
+
)
|
|
5553
|
+
.then(() => {
|
|
5554
|
+
_js_wasm_trace('fd_close(%d) release locks success', fd);
|
|
5555
|
+
})
|
|
5556
|
+
.catch((e) => {
|
|
5557
|
+
_js_wasm_trace("fd_close(%d) error '%s'", fd, e);
|
|
5558
|
+
})
|
|
5559
|
+
.then(() => {
|
|
5560
|
+
_js_wasm_trace('fd_close(%d) result %d', fd, result);
|
|
5561
|
+
return result;
|
|
5562
|
+
})
|
|
5563
|
+
.finally(() => {
|
|
5564
|
+
locking.maybeLockedFds.delete(fd);
|
|
5565
|
+
});
|
|
5566
|
+
} else {
|
|
5567
|
+
_js_wasm_trace('fd_close(%d) result %d', fd, result);
|
|
5568
|
+
return result;
|
|
5569
|
+
}
|
|
5570
|
+
}
|
|
5571
|
+
|
|
5572
|
+
function _builtin_fd_close(fd) {
|
|
5573
|
+
try {
|
|
5574
|
+
var stream = SYSCALLS.getStreamFromFD(fd);
|
|
5575
|
+
FS.close(stream);
|
|
5576
|
+
return 0;
|
|
5577
|
+
} catch (e) {
|
|
5578
|
+
if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
|
|
5579
|
+
return e.errno;
|
|
5580
|
+
}
|
|
5581
|
+
}
|
|
5582
|
+
|
|
5583
|
+
function _builtin_fcntl64(fd, cmd, varargs) {
|
|
5231
5584
|
SYSCALLS.varargs = varargs;
|
|
5232
5585
|
try {
|
|
5233
5586
|
var stream = SYSCALLS.getStreamFromFD(fd);
|
|
@@ -5275,13 +5628,446 @@ export function init(RuntimeName, PHPLoader) {
|
|
|
5275
5628
|
// See https://github.com/emscripten-core/emscripten/issues/23697
|
|
5276
5629
|
return 0;
|
|
5277
5630
|
}
|
|
5278
|
-
return -28;
|
|
5279
|
-
} catch (e) {
|
|
5280
|
-
if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
|
|
5281
|
-
return -e.errno;
|
|
5631
|
+
return -28;
|
|
5632
|
+
} catch (e) {
|
|
5633
|
+
if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
|
|
5634
|
+
return -e.errno;
|
|
5635
|
+
}
|
|
5636
|
+
}
|
|
5637
|
+
|
|
5638
|
+
var locking = {
|
|
5639
|
+
maybeLockedFds: new Set(),
|
|
5640
|
+
F_RDLCK: 0,
|
|
5641
|
+
F_WRLCK: 1,
|
|
5642
|
+
F_UNLCK: 2,
|
|
5643
|
+
lockStateToFcntl: {
|
|
5644
|
+
shared: 0,
|
|
5645
|
+
exclusive: 1,
|
|
5646
|
+
unlocked: 2,
|
|
5647
|
+
},
|
|
5648
|
+
fcntlToLockState: {
|
|
5649
|
+
0: 'shared',
|
|
5650
|
+
1: 'exclusive',
|
|
5651
|
+
2: 'unlocked',
|
|
5652
|
+
},
|
|
5653
|
+
is_shared_fs_node(node) {
|
|
5654
|
+
if (node?.isSharedFS) {
|
|
5655
|
+
return true;
|
|
5656
|
+
}
|
|
5657
|
+
// Handle PROXYFS nodes which wrap other nodes.
|
|
5658
|
+
if (!node?.mount?.opts?.fs?.lookupPath) {
|
|
5659
|
+
return false;
|
|
5660
|
+
}
|
|
5661
|
+
const vfsPath = NODEFS.realPath(node);
|
|
5662
|
+
const underlyingNode = node.mount.opts.fs.lookupPath(vfsPath)?.node;
|
|
5663
|
+
return !!underlyingNode?.isSharedFS;
|
|
5664
|
+
},
|
|
5665
|
+
is_path_to_shared_fs(path) {
|
|
5666
|
+
const { node } = FS.lookupPath(path);
|
|
5667
|
+
return locking.is_shared_fs_node(node);
|
|
5668
|
+
},
|
|
5669
|
+
get_fd_access_mode(fd) {
|
|
5670
|
+
const emscripten_F_GETFL = Number('3');
|
|
5671
|
+
const emscripten_O_ACCMODE = Number('2097155');
|
|
5672
|
+
return (
|
|
5673
|
+
_builtin_fcntl64(fd, emscripten_F_GETFL) & emscripten_O_ACCMODE
|
|
5674
|
+
);
|
|
5675
|
+
},
|
|
5676
|
+
get_vfs_path_from_fd(fd) {
|
|
5677
|
+
try {
|
|
5678
|
+
return [FS.readlink(`/proc/self/fd/${fd}`), 0];
|
|
5679
|
+
} catch (error) {
|
|
5680
|
+
return [null, ERRNO_CODES.EBADF];
|
|
5681
|
+
}
|
|
5682
|
+
},
|
|
5683
|
+
get_native_path_from_vfs_path(vfsPath) {
|
|
5684
|
+
const { node } = FS.lookupPath(vfsPath);
|
|
5685
|
+
return NODEFS.realPath(node);
|
|
5686
|
+
},
|
|
5687
|
+
check_lock_params(fd, l_type) {
|
|
5688
|
+
const emscripten_O_RDONLY = Number('0');
|
|
5689
|
+
const emscripten_O_WRONLY = Number('1');
|
|
5690
|
+
const accessMode = locking.get_fd_access_mode(fd);
|
|
5691
|
+
if (
|
|
5692
|
+
(l_type === locking.F_WRLCK &&
|
|
5693
|
+
accessMode === emscripten_O_RDONLY) ||
|
|
5694
|
+
(l_type === locking.F_RDLCK &&
|
|
5695
|
+
accessMode === emscripten_O_WRONLY)
|
|
5696
|
+
) {
|
|
5697
|
+
return ERRNO_CODES.EBADF;
|
|
5698
|
+
}
|
|
5699
|
+
return 0;
|
|
5700
|
+
},
|
|
5701
|
+
};
|
|
5702
|
+
|
|
5703
|
+
async function ___syscall_fcntl64(fd, cmd, varargs) {
|
|
5704
|
+
// Necessary to use varargs accessor
|
|
5705
|
+
SYSCALLS.varargs = varargs;
|
|
5706
|
+
// These constants are replaced by Emscripten during the build process
|
|
5707
|
+
const emscripten_F_GETLK = Number('12');
|
|
5708
|
+
const emscripten_F_SETLK = Number('13');
|
|
5709
|
+
const emscripten_F_SETLKW = Number('14');
|
|
5710
|
+
const emscripten_SEEK_SET = Number('0');
|
|
5711
|
+
// NOTE: With the exception of l_type, these offsets are not exposed to
|
|
5712
|
+
// JS by Emscripten, so we hardcode them here.
|
|
5713
|
+
const emscripten_flock_l_type_offset = 0;
|
|
5714
|
+
const emscripten_flock_l_whence_offset = 2;
|
|
5715
|
+
const emscripten_flock_l_start_offset = 8;
|
|
5716
|
+
const emscripten_flock_l_len_offset = 16;
|
|
5717
|
+
const emscripten_flock_l_pid_offset = 24;
|
|
5718
|
+
/**
|
|
5719
|
+
* Read the flock struct at the given address.
|
|
5720
|
+
*
|
|
5721
|
+
* @param {bigint} flockStructAddress - the address of the flock struct
|
|
5722
|
+
* @returns the flock struct
|
|
5723
|
+
*/ function read_flock_struct(flockStructAddress) {
|
|
5724
|
+
/*
|
|
5725
|
+
* NOTE: Since we are using HEAP<WORD_SIZE> vars like HEAP16 and HEAP64,
|
|
5726
|
+
* we need to adjust offsets to address the word size of each HEAP.
|
|
5727
|
+
*
|
|
5728
|
+
* For example, an offset of 64 bytes is the following for each HEAP:
|
|
5729
|
+
* - HEAP8: 64 (the 64th byte)
|
|
5730
|
+
* - HEAP16: 32 (the 32nd 16-bit word)
|
|
5731
|
+
* - HEAP32: 16 (the 16th 32-bit word)
|
|
5732
|
+
* - HEAP64: 8 (the 8th 64-bit word)
|
|
5733
|
+
*
|
|
5734
|
+
* We get a word offset by dividing the byte offset by the word size.
|
|
5735
|
+
*/ return {
|
|
5736
|
+
l_type: HEAP16[ // Shift right by 1 to divide by 2^1.
|
|
5737
|
+
(flockStructAddress + emscripten_flock_l_type_offset) >> 1
|
|
5738
|
+
],
|
|
5739
|
+
l_whence:
|
|
5740
|
+
HEAP16[ // Shift right by 1 to divide by 2^1.
|
|
5741
|
+
(flockStructAddress +
|
|
5742
|
+
emscripten_flock_l_whence_offset) >>
|
|
5743
|
+
1
|
|
5744
|
+
],
|
|
5745
|
+
l_start:
|
|
5746
|
+
HEAP64[ // Shift right by 3 to divide by 2^3.
|
|
5747
|
+
(flockStructAddress +
|
|
5748
|
+
emscripten_flock_l_start_offset) >>
|
|
5749
|
+
3
|
|
5750
|
+
],
|
|
5751
|
+
l_len: HEAP64[ // Shift right by 3 to divide by 2^3.
|
|
5752
|
+
(flockStructAddress + emscripten_flock_l_len_offset) >> 3
|
|
5753
|
+
],
|
|
5754
|
+
l_pid: HEAP32[ // Shift right by 2 to divide by 2^2.
|
|
5755
|
+
(flockStructAddress + emscripten_flock_l_pid_offset) >> 2
|
|
5756
|
+
],
|
|
5757
|
+
};
|
|
5758
|
+
}
|
|
5759
|
+
/**
|
|
5760
|
+
* Update the flock struct at the given address with the given fields.
|
|
5761
|
+
*
|
|
5762
|
+
* @param {bigint} flockStructAddress - the address of the flock struct
|
|
5763
|
+
* @param {object} fields - the fields to update
|
|
5764
|
+
*/ function update_flock_struct(flockStructAddress, fields) {
|
|
5765
|
+
/*
|
|
5766
|
+
* NOTE: Since we are using HEAP<WORD_SIZE> vars like HEAP16 and HEAP64,
|
|
5767
|
+
* we need to adjust offsets to address the word size of each HEAP.
|
|
5768
|
+
*
|
|
5769
|
+
* For example, an offset of 64 bytes is the following for each HEAP:
|
|
5770
|
+
* - HEAP8: 64 (the 64th byte)
|
|
5771
|
+
* - HEAP16: 32 (the 32nd 16-bit word)
|
|
5772
|
+
* - HEAP32: 16 (the 16th 32-bit word)
|
|
5773
|
+
* - HEAP64: 8 (the 8th 64-bit word)
|
|
5774
|
+
*
|
|
5775
|
+
* We get a word offset by dividing the byte offset by the word size.
|
|
5776
|
+
*/ if (fields.l_type !== undefined) {
|
|
5777
|
+
HEAP16[ // Shift right by 1 to divide by 2^1.
|
|
5778
|
+
(flockStructAddress + emscripten_flock_l_type_offset) >> 1
|
|
5779
|
+
] = fields.l_type;
|
|
5780
|
+
}
|
|
5781
|
+
if (fields.l_whence !== undefined) {
|
|
5782
|
+
HEAP16[ // Shift right by 1 to divide by 2^1.
|
|
5783
|
+
(flockStructAddress + emscripten_flock_l_whence_offset) >> 1
|
|
5784
|
+
] = fields.l_whence;
|
|
5785
|
+
}
|
|
5786
|
+
if (fields.l_start !== undefined) {
|
|
5787
|
+
HEAP64[ // Shift right by 3 to divide by 2^3.
|
|
5788
|
+
(flockStructAddress + emscripten_flock_l_start_offset) >> 3
|
|
5789
|
+
] = fields.l_start;
|
|
5790
|
+
}
|
|
5791
|
+
if (fields.l_len !== undefined) {
|
|
5792
|
+
HEAP64[ // Shift right by 3 to divide by 2^3.
|
|
5793
|
+
(flockStructAddress + emscripten_flock_l_len_offset) >> 3
|
|
5794
|
+
] = fields.l_len;
|
|
5795
|
+
}
|
|
5796
|
+
if (fields.l_pid !== undefined) {
|
|
5797
|
+
HEAP32[ // Shift right by 2 to divide by 2^2.
|
|
5798
|
+
(flockStructAddress + emscripten_flock_l_pid_offset) >> 2
|
|
5799
|
+
] = fields.l_pid;
|
|
5800
|
+
}
|
|
5801
|
+
}
|
|
5802
|
+
/**
|
|
5803
|
+
* Resolve the base address of the range depending on the whence and start offset.
|
|
5804
|
+
*
|
|
5805
|
+
* @param {number} fd - the file descriptor
|
|
5806
|
+
* @param {number} whence - what the start offset is relative to
|
|
5807
|
+
* @param {bigint} startOffset - the offset from the whence
|
|
5808
|
+
* @returns The resolved offset and the errno. If there is an error,
|
|
5809
|
+
* the resolved offset is null, and the errno is non-zero.
|
|
5810
|
+
*/ function get_base_address(fd, whence, startOffset) {
|
|
5811
|
+
let baseAddress;
|
|
5812
|
+
switch (whence) {
|
|
5813
|
+
case emscripten_SEEK_SET:
|
|
5814
|
+
baseAddress = 0n;
|
|
5815
|
+
break;
|
|
5816
|
+
|
|
5817
|
+
case emscripten_SEEK_CUR:
|
|
5818
|
+
baseAddress = FS.lseek(fd, 0, whence);
|
|
5819
|
+
break;
|
|
5820
|
+
|
|
5821
|
+
case emscripten_SEEK_END:
|
|
5822
|
+
baseAddress = _wasm_get_end_offset(fd);
|
|
5823
|
+
break;
|
|
5824
|
+
|
|
5825
|
+
default:
|
|
5826
|
+
return [null, ERRNO_CODES.EINVAL];
|
|
5827
|
+
}
|
|
5828
|
+
if (baseAddress == -1) {
|
|
5829
|
+
// We cannot resolve the offset within the file.
|
|
5830
|
+
// Let's treat this as a problem with the file descriptor.
|
|
5831
|
+
return [null, ERRNO_CODES.EBADF];
|
|
5832
|
+
}
|
|
5833
|
+
const resolvedOffset = baseAddress + startOffset;
|
|
5834
|
+
if (resolvedOffset < 0) {
|
|
5835
|
+
// This is not a valid offset. Report args as invalid.
|
|
5836
|
+
return [null, ERRNO_CODES.EINVAL];
|
|
5837
|
+
}
|
|
5838
|
+
return [resolvedOffset, 0];
|
|
5839
|
+
}
|
|
5840
|
+
const pid = PHPLoader.processId;
|
|
5841
|
+
switch (cmd) {
|
|
5842
|
+
case emscripten_F_GETLK: {
|
|
5843
|
+
_js_wasm_trace('fcntl(%d, F_GETLK)', fd);
|
|
5844
|
+
let vfsPath;
|
|
5845
|
+
let errno;
|
|
5846
|
+
[vfsPath, errno] = locking.get_vfs_path_from_fd(fd);
|
|
5847
|
+
if (errno !== 0) {
|
|
5848
|
+
_js_wasm_trace(
|
|
5849
|
+
'fcntl(%d, F_GETLK) %s get_vfs_path_from_fd errno %d',
|
|
5850
|
+
fd,
|
|
5851
|
+
vfsPath,
|
|
5852
|
+
errno
|
|
5853
|
+
);
|
|
5854
|
+
return -ERRNO_CODES.EBADF;
|
|
5855
|
+
}
|
|
5856
|
+
if (!locking.is_path_to_shared_fs(vfsPath)) {
|
|
5857
|
+
_js_wasm_trace(
|
|
5858
|
+
"fcntl(%d, F_GETLK) locking is not implemented for non-NodeFS path '%s'",
|
|
5859
|
+
fd,
|
|
5860
|
+
vfsPath
|
|
5861
|
+
);
|
|
5862
|
+
// If not a NodeFS path, we can't lock it.
|
|
5863
|
+
// Default to succeeding as Emscripten does.
|
|
5864
|
+
update_flock_struct(flockStructAddr, {
|
|
5865
|
+
l_type: F_UNLCK,
|
|
5866
|
+
});
|
|
5867
|
+
return 0;
|
|
5868
|
+
}
|
|
5869
|
+
const flockStructAddr = syscallGetVarargP();
|
|
5870
|
+
const flockStruct = read_flock_struct(flockStructAddr);
|
|
5871
|
+
if (!(flockStruct.l_type in locking.fcntlToLockState)) {
|
|
5872
|
+
return -ERRNO_CODES.EINVAL;
|
|
5873
|
+
}
|
|
5874
|
+
errno = locking.check_lock_params(fd, flockStruct.l_type);
|
|
5875
|
+
if (errno !== 0) {
|
|
5876
|
+
_js_wasm_trace(
|
|
5877
|
+
'fcntl(%d, F_GETLK) %s check_lock_params errno %d',
|
|
5878
|
+
fd,
|
|
5879
|
+
vfsPath,
|
|
5880
|
+
errno
|
|
5881
|
+
);
|
|
5882
|
+
return -ERRNO_CODES.EINVAL;
|
|
5883
|
+
}
|
|
5884
|
+
const requestedLockType =
|
|
5885
|
+
locking.fcntlToLockState[flockStruct.l_type];
|
|
5886
|
+
let absoluteStartOffset;
|
|
5887
|
+
[absoluteStartOffset, errno] = get_base_address(
|
|
5888
|
+
fd,
|
|
5889
|
+
flockStruct.l_whence,
|
|
5890
|
+
flockStruct.l_start
|
|
5891
|
+
);
|
|
5892
|
+
if (errno !== 0) {
|
|
5893
|
+
_js_wasm_trace(
|
|
5894
|
+
'fcntl(%d, F_GETLK) %s get_base_address errno %d',
|
|
5895
|
+
fd,
|
|
5896
|
+
vfsPath,
|
|
5897
|
+
errno
|
|
5898
|
+
);
|
|
5899
|
+
return -ERRNO_CODES.EINVAL;
|
|
5900
|
+
}
|
|
5901
|
+
const nativeFilePath =
|
|
5902
|
+
locking.get_native_path_from_vfs_path(vfsPath);
|
|
5903
|
+
return PHPLoader.fileLockManager
|
|
5904
|
+
.findFirstConflictingByteRangeLock(nativeFilePath, {
|
|
5905
|
+
type: requestedLockType,
|
|
5906
|
+
start: absoluteStartOffset,
|
|
5907
|
+
end: absoluteStartOffset + flockStruct.l_len,
|
|
5908
|
+
pid,
|
|
5909
|
+
})
|
|
5910
|
+
.then((conflictingLock) => {
|
|
5911
|
+
if (conflictingLock === undefined) {
|
|
5912
|
+
_js_wasm_trace(
|
|
5913
|
+
'fcntl(%d, F_GETLK) %s findFirstConflictingByteRangeLock type=unlocked start=0x%x end=0x%x',
|
|
5914
|
+
fd,
|
|
5915
|
+
vfsPath,
|
|
5916
|
+
absoluteStartOffset,
|
|
5917
|
+
absoluteStartOffset + flockStruct.l_len
|
|
5918
|
+
);
|
|
5919
|
+
update_flock_struct(flockStructAddr, {
|
|
5920
|
+
l_type: F_UNLCK,
|
|
5921
|
+
});
|
|
5922
|
+
return 0;
|
|
5923
|
+
}
|
|
5924
|
+
_js_wasm_trace(
|
|
5925
|
+
'fcntl(%d, F_GETLK) %s findFirstConflictingByteRangeLock type=%s start=0x%x end=0x%x conflictingLock %d',
|
|
5926
|
+
fd,
|
|
5927
|
+
vfsPath,
|
|
5928
|
+
conflictingLock.type,
|
|
5929
|
+
conflictingLock.start,
|
|
5930
|
+
conflictingLock.end,
|
|
5931
|
+
conflictingLock.pid
|
|
5932
|
+
);
|
|
5933
|
+
const fcntlLockState =
|
|
5934
|
+
locking.lockStateToFcntl[conflictingLock.type];
|
|
5935
|
+
update_flock_struct(flockStructAddr, {
|
|
5936
|
+
l_type: fcntlLockState,
|
|
5937
|
+
l_whence: emscripten_SEEK_SET,
|
|
5938
|
+
l_start: conflictingLock.start,
|
|
5939
|
+
l_len: conflictingLock.end - conflictingLock.start,
|
|
5940
|
+
l_pid: conflictingLock.pid,
|
|
5941
|
+
});
|
|
5942
|
+
return 0;
|
|
5943
|
+
})
|
|
5944
|
+
.catch((e) => {
|
|
5945
|
+
_js_wasm_trace(
|
|
5946
|
+
'fcntl(%d, F_GETLK) %s findFirstConflictingByteRangeLock error %s',
|
|
5947
|
+
fd,
|
|
5948
|
+
vfsPath,
|
|
5949
|
+
e
|
|
5950
|
+
);
|
|
5951
|
+
return -ERRNO_CODES.EINVAL;
|
|
5952
|
+
});
|
|
5953
|
+
}
|
|
5954
|
+
|
|
5955
|
+
case emscripten_F_SETLK: {
|
|
5956
|
+
_js_wasm_trace('fcntl(%d, F_SETLK)', fd);
|
|
5957
|
+
let vfsPath;
|
|
5958
|
+
let errno;
|
|
5959
|
+
[vfsPath, errno] = locking.get_vfs_path_from_fd(fd);
|
|
5960
|
+
if (errno !== 0) {
|
|
5961
|
+
_js_wasm_trace(
|
|
5962
|
+
'fcntl(%d, F_SETLK) %s get_vfs_path_from_fd errno %d',
|
|
5963
|
+
fd,
|
|
5964
|
+
vfsPath,
|
|
5965
|
+
errno
|
|
5966
|
+
);
|
|
5967
|
+
return -errno;
|
|
5968
|
+
}
|
|
5969
|
+
if (!locking.is_path_to_shared_fs(vfsPath)) {
|
|
5970
|
+
_js_wasm_trace(
|
|
5971
|
+
'fcntl(%d, F_SETLK) locking is not implemented for non-NodeFS path %s',
|
|
5972
|
+
fd,
|
|
5973
|
+
vfsPath
|
|
5974
|
+
);
|
|
5975
|
+
// If not a NodeFS path, we can't lock it.
|
|
5976
|
+
// Default to succeeding as Emscripten does.
|
|
5977
|
+
return 0;
|
|
5978
|
+
}
|
|
5979
|
+
var flockStructAddr = syscallGetVarargP();
|
|
5980
|
+
const flockStruct = read_flock_struct(flockStructAddr);
|
|
5981
|
+
let absoluteStartOffset;
|
|
5982
|
+
[absoluteStartOffset, errno] = get_base_address(
|
|
5983
|
+
fd,
|
|
5984
|
+
flockStruct.l_whence,
|
|
5985
|
+
flockStruct.l_start
|
|
5986
|
+
);
|
|
5987
|
+
if (errno !== 0) {
|
|
5988
|
+
_js_wasm_trace(
|
|
5989
|
+
'fcntl(%d, F_SETLK) %s get_base_address errno %d',
|
|
5990
|
+
fd,
|
|
5991
|
+
vfsPath,
|
|
5992
|
+
errno
|
|
5993
|
+
);
|
|
5994
|
+
return -errno;
|
|
5995
|
+
}
|
|
5996
|
+
if (!(flockStruct.l_type in locking.fcntlToLockState)) {
|
|
5997
|
+
_js_wasm_trace(
|
|
5998
|
+
'fcntl(%d, F_SETLK) %s invalid lock type %d',
|
|
5999
|
+
fd,
|
|
6000
|
+
vfsPath,
|
|
6001
|
+
flockStruct.l_type
|
|
6002
|
+
);
|
|
6003
|
+
return -ERRNO_CODES.EINVAL;
|
|
6004
|
+
}
|
|
6005
|
+
errno = locking.check_lock_params(fd, flockStruct.l_type);
|
|
6006
|
+
if (errno !== 0) {
|
|
6007
|
+
_js_wasm_trace(
|
|
6008
|
+
'fcntl(%d, F_SETLK) %s check_lock_params errno %d',
|
|
6009
|
+
fd,
|
|
6010
|
+
vfsPath,
|
|
6011
|
+
errno
|
|
6012
|
+
);
|
|
6013
|
+
return -errno;
|
|
6014
|
+
}
|
|
6015
|
+
locking.maybeLockedFds.add(fd);
|
|
6016
|
+
const requestedLockType =
|
|
6017
|
+
locking.fcntlToLockState[flockStruct.l_type];
|
|
6018
|
+
const rangeLock = {
|
|
6019
|
+
type: requestedLockType,
|
|
6020
|
+
start: absoluteStartOffset,
|
|
6021
|
+
end: absoluteStartOffset + flockStruct.l_len,
|
|
6022
|
+
pid,
|
|
6023
|
+
};
|
|
6024
|
+
const nativeFilePath =
|
|
6025
|
+
locking.get_native_path_from_vfs_path(vfsPath);
|
|
6026
|
+
_js_wasm_trace(
|
|
6027
|
+
'fcntl(%d, F_SETLK) %s calling lockFileByteRange for range lock %s',
|
|
6028
|
+
fd,
|
|
6029
|
+
vfsPath,
|
|
6030
|
+
rangeLock
|
|
6031
|
+
);
|
|
6032
|
+
return PHPLoader.fileLockManager
|
|
6033
|
+
.lockFileByteRange(nativeFilePath, rangeLock)
|
|
6034
|
+
.then((succeeded) => {
|
|
6035
|
+
_js_wasm_trace(
|
|
6036
|
+
'fcntl(%d, F_SETLK) %s lockFileByteRange returned %d for range lock %s',
|
|
6037
|
+
fd,
|
|
6038
|
+
vfsPath,
|
|
6039
|
+
succeeded,
|
|
6040
|
+
rangeLock
|
|
6041
|
+
);
|
|
6042
|
+
return succeeded ? 0 : -ERRNO_CODES.EAGAIN;
|
|
6043
|
+
})
|
|
6044
|
+
.catch((e) => {
|
|
6045
|
+
_js_wasm_trace(
|
|
6046
|
+
'fcntl(%d, F_SETLK) %s lockFileByteRange error %s for range lock %s',
|
|
6047
|
+
fd,
|
|
6048
|
+
vfsPath,
|
|
6049
|
+
e,
|
|
6050
|
+
rangeLock
|
|
6051
|
+
);
|
|
6052
|
+
return -ERRNO_CODES.EINVAL;
|
|
6053
|
+
});
|
|
6054
|
+
}
|
|
6055
|
+
|
|
6056
|
+
// @TODO: Implement waiting for lock
|
|
6057
|
+
case emscripten_F_SETLKW: {
|
|
6058
|
+
// We do not yet support the blocking form of flock().
|
|
6059
|
+
// We respond with EDEADLK to indicate failure
|
|
6060
|
+
// because it is a known errno for a failed F_SETLKW command.
|
|
6061
|
+
return -ERRNO_CODES.EDEADLK;
|
|
6062
|
+
}
|
|
6063
|
+
|
|
6064
|
+
default:
|
|
6065
|
+
return _builtin_fcntl64(fd, cmd, varargs);
|
|
5282
6066
|
}
|
|
5283
6067
|
}
|
|
5284
6068
|
|
|
6069
|
+
___syscall_fcntl64.isAsync = true;
|
|
6070
|
+
|
|
5285
6071
|
function ___syscall_fdatasync(fd) {
|
|
5286
6072
|
try {
|
|
5287
6073
|
var stream = SYSCALLS.getStreamFromFD(fd);
|
|
@@ -5313,11 +6099,6 @@ export function init(RuntimeName, PHPLoader) {
|
|
|
5313
6099
|
}
|
|
5314
6100
|
}
|
|
5315
6101
|
|
|
5316
|
-
var stringToUTF8 = (str, outPtr, maxBytesToWrite) =>
|
|
5317
|
-
stringToUTF8Array(str, HEAPU8, outPtr, maxBytesToWrite);
|
|
5318
|
-
|
|
5319
|
-
Module['stringToUTF8'] = stringToUTF8;
|
|
5320
|
-
|
|
5321
6102
|
function ___syscall_getcwd(buf, size) {
|
|
5322
6103
|
try {
|
|
5323
6104
|
if (size === 0) return -28;
|
|
@@ -5836,408 +6617,28 @@ export function init(RuntimeName, PHPLoader) {
|
|
|
5836
6617
|
},
|
|
5837
6618
|
close(stream) {
|
|
5838
6619
|
var pipe = stream.node.pipe;
|
|
5839
|
-
pipe.refcnt--;
|
|
5840
|
-
if (pipe.refcnt === 0) {
|
|
5841
|
-
pipe.buckets = null;
|
|
5842
|
-
}
|
|
5843
|
-
},
|
|
5844
|
-
},
|
|
5845
|
-
nextname() {
|
|
5846
|
-
if (!PIPEFS.nextname.current) {
|
|
5847
|
-
PIPEFS.nextname.current = 0;
|
|
5848
|
-
}
|
|
5849
|
-
return 'pipe[' + PIPEFS.nextname.current++ + ']';
|
|
5850
|
-
},
|
|
5851
|
-
};
|
|
5852
|
-
|
|
5853
|
-
function ___syscall_pipe(fdPtr) {
|
|
5854
|
-
try {
|
|
5855
|
-
if (fdPtr == 0) {
|
|
5856
|
-
throw new FS.ErrnoError(21);
|
|
5857
|
-
}
|
|
5858
|
-
var res = PIPEFS.createPipe();
|
|
5859
|
-
HEAP32[fdPtr >> 2] = res.readable_fd;
|
|
5860
|
-
HEAP32[(fdPtr + 4) >> 2] = res.writable_fd;
|
|
5861
|
-
return 0;
|
|
5862
|
-
} catch (e) {
|
|
5863
|
-
if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
|
|
5864
|
-
return -e.errno;
|
|
5865
|
-
}
|
|
5866
|
-
}
|
|
5867
|
-
|
|
5868
|
-
function ___syscall_poll(fds, nfds, timeout) {
|
|
5869
|
-
try {
|
|
5870
|
-
var nonzero = 0;
|
|
5871
|
-
for (var i = 0; i < nfds; i++) {
|
|
5872
|
-
var pollfd = fds + 8 * i;
|
|
5873
|
-
var fd = HEAP32[pollfd >> 2];
|
|
5874
|
-
var events = HEAP16[(pollfd + 4) >> 1];
|
|
5875
|
-
var mask = 32;
|
|
5876
|
-
var stream = FS.getStream(fd);
|
|
5877
|
-
if (stream) {
|
|
5878
|
-
mask = SYSCALLS.DEFAULT_POLLMASK;
|
|
5879
|
-
if (stream.stream_ops?.poll) {
|
|
5880
|
-
mask = stream.stream_ops.poll(stream, -1);
|
|
5881
|
-
}
|
|
5882
|
-
}
|
|
5883
|
-
mask &= events | 8 | 16;
|
|
5884
|
-
if (mask) nonzero++;
|
|
5885
|
-
HEAP16[(pollfd + 6) >> 1] = mask;
|
|
5886
|
-
}
|
|
5887
|
-
return nonzero;
|
|
5888
|
-
} catch (e) {
|
|
5889
|
-
if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
|
|
5890
|
-
return -e.errno;
|
|
5891
|
-
}
|
|
5892
|
-
}
|
|
5893
|
-
|
|
5894
|
-
function ___syscall_readlinkat(dirfd, path, buf, bufsize) {
|
|
5895
|
-
try {
|
|
5896
|
-
path = SYSCALLS.getStr(path);
|
|
5897
|
-
path = SYSCALLS.calculateAt(dirfd, path);
|
|
5898
|
-
if (bufsize <= 0) return -28;
|
|
5899
|
-
var ret = FS.readlink(path);
|
|
5900
|
-
var len = Math.min(bufsize, lengthBytesUTF8(ret));
|
|
5901
|
-
var endChar = HEAP8[buf + len];
|
|
5902
|
-
stringToUTF8(ret, buf, bufsize + 1);
|
|
5903
|
-
// readlink is one of the rare functions that write out a C string, but does never append a null to the output buffer(!)
|
|
5904
|
-
// stringToUTF8() always appends a null byte, so restore the character under the null byte after the write.
|
|
5905
|
-
HEAP8[buf + len] = endChar;
|
|
5906
|
-
return len;
|
|
5907
|
-
} catch (e) {
|
|
5908
|
-
if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
|
|
5909
|
-
return -e.errno;
|
|
5910
|
-
}
|
|
5911
|
-
}
|
|
5912
|
-
|
|
5913
|
-
function ___syscall_recvfrom(fd, buf, len, flags, addr, addrlen) {
|
|
5914
|
-
try {
|
|
5915
|
-
var sock = getSocketFromFD(fd);
|
|
5916
|
-
var msg = sock.sock_ops.recvmsg(
|
|
5917
|
-
sock,
|
|
5918
|
-
len,
|
|
5919
|
-
typeof flags !== 'undefined' ? flags : 0
|
|
5920
|
-
);
|
|
5921
|
-
if (!msg) return 0;
|
|
5922
|
-
// socket is closed
|
|
5923
|
-
if (addr) {
|
|
5924
|
-
var errno = writeSockaddr(
|
|
5925
|
-
addr,
|
|
5926
|
-
sock.family,
|
|
5927
|
-
DNS.lookup_name(msg.addr),
|
|
5928
|
-
msg.port,
|
|
5929
|
-
addrlen
|
|
5930
|
-
);
|
|
5931
|
-
}
|
|
5932
|
-
HEAPU8.set(msg.buffer, buf);
|
|
5933
|
-
return msg.buffer.byteLength;
|
|
5934
|
-
} catch (e) {
|
|
5935
|
-
if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
|
|
5936
|
-
return -e.errno;
|
|
5937
|
-
}
|
|
5938
|
-
}
|
|
5939
|
-
|
|
5940
|
-
function ___syscall_renameat(olddirfd, oldpath, newdirfd, newpath) {
|
|
5941
|
-
try {
|
|
5942
|
-
oldpath = SYSCALLS.getStr(oldpath);
|
|
5943
|
-
newpath = SYSCALLS.getStr(newpath);
|
|
5944
|
-
oldpath = SYSCALLS.calculateAt(olddirfd, oldpath);
|
|
5945
|
-
newpath = SYSCALLS.calculateAt(newdirfd, newpath);
|
|
5946
|
-
FS.rename(oldpath, newpath);
|
|
5947
|
-
return 0;
|
|
5948
|
-
} catch (e) {
|
|
5949
|
-
if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
|
|
5950
|
-
return -e.errno;
|
|
5951
|
-
}
|
|
5952
|
-
}
|
|
5953
|
-
|
|
5954
|
-
function ___syscall_rmdir(path) {
|
|
5955
|
-
try {
|
|
5956
|
-
path = SYSCALLS.getStr(path);
|
|
5957
|
-
FS.rmdir(path);
|
|
5958
|
-
return 0;
|
|
5959
|
-
} catch (e) {
|
|
5960
|
-
if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
|
|
5961
|
-
return -e.errno;
|
|
5962
|
-
}
|
|
5963
|
-
}
|
|
5964
|
-
|
|
5965
|
-
function ___syscall_sendto(fd, message, length, flags, addr, addr_len) {
|
|
5966
|
-
try {
|
|
5967
|
-
var sock = getSocketFromFD(fd);
|
|
5968
|
-
if (!addr) {
|
|
5969
|
-
// send, no address provided
|
|
5970
|
-
return FS.write(sock.stream, HEAP8, message, length);
|
|
5971
|
-
}
|
|
5972
|
-
var dest = getSocketAddress(addr, addr_len);
|
|
5973
|
-
// sendto an address
|
|
5974
|
-
return sock.sock_ops.sendmsg(
|
|
5975
|
-
sock,
|
|
5976
|
-
HEAP8,
|
|
5977
|
-
message,
|
|
5978
|
-
length,
|
|
5979
|
-
dest.addr,
|
|
5980
|
-
dest.port
|
|
5981
|
-
);
|
|
5982
|
-
} catch (e) {
|
|
5983
|
-
if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
|
|
5984
|
-
return -e.errno;
|
|
5985
|
-
}
|
|
5986
|
-
}
|
|
5987
|
-
|
|
5988
|
-
function ___syscall_socket(domain, type, protocol) {
|
|
5989
|
-
try {
|
|
5990
|
-
var sock = SOCKFS.createSocket(domain, type, protocol);
|
|
5991
|
-
return sock.stream.fd;
|
|
5992
|
-
} catch (e) {
|
|
5993
|
-
if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
|
|
5994
|
-
return -e.errno;
|
|
5995
|
-
}
|
|
5996
|
-
}
|
|
5997
|
-
|
|
5998
|
-
function ___syscall_stat64(path, buf) {
|
|
5999
|
-
try {
|
|
6000
|
-
path = SYSCALLS.getStr(path);
|
|
6001
|
-
return SYSCALLS.writeStat(buf, FS.stat(path));
|
|
6002
|
-
} catch (e) {
|
|
6003
|
-
if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
|
|
6004
|
-
return -e.errno;
|
|
6005
|
-
}
|
|
6006
|
-
}
|
|
6007
|
-
|
|
6008
|
-
function ___syscall_statfs64(path, size, buf) {
|
|
6009
|
-
try {
|
|
6010
|
-
SYSCALLS.writeStatFs(buf, FS.statfs(SYSCALLS.getStr(path)));
|
|
6011
|
-
return 0;
|
|
6012
|
-
} catch (e) {
|
|
6013
|
-
if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
|
|
6014
|
-
return -e.errno;
|
|
6015
|
-
}
|
|
6016
|
-
}
|
|
6017
|
-
|
|
6018
|
-
function ___syscall_symlinkat(target, dirfd, linkpath) {
|
|
6019
|
-
try {
|
|
6020
|
-
target = SYSCALLS.getStr(target);
|
|
6021
|
-
linkpath = SYSCALLS.getStr(linkpath);
|
|
6022
|
-
linkpath = SYSCALLS.calculateAt(dirfd, linkpath);
|
|
6023
|
-
FS.symlink(target, linkpath);
|
|
6024
|
-
return 0;
|
|
6025
|
-
} catch (e) {
|
|
6026
|
-
if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
|
|
6027
|
-
return -e.errno;
|
|
6028
|
-
}
|
|
6029
|
-
}
|
|
6030
|
-
|
|
6031
|
-
function ___syscall_unlinkat(dirfd, path, flags) {
|
|
6032
|
-
try {
|
|
6033
|
-
path = SYSCALLS.getStr(path);
|
|
6034
|
-
path = SYSCALLS.calculateAt(dirfd, path);
|
|
6035
|
-
if (flags === 0) {
|
|
6036
|
-
FS.unlink(path);
|
|
6037
|
-
} else if (flags === 512) {
|
|
6038
|
-
FS.rmdir(path);
|
|
6039
|
-
} else {
|
|
6040
|
-
abort('Invalid flags passed to unlinkat');
|
|
6041
|
-
}
|
|
6042
|
-
return 0;
|
|
6043
|
-
} catch (e) {
|
|
6044
|
-
if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
|
|
6045
|
-
return -e.errno;
|
|
6046
|
-
}
|
|
6047
|
-
}
|
|
6048
|
-
|
|
6049
|
-
var readI53FromI64 = (ptr) =>
|
|
6050
|
-
HEAPU32[ptr >> 2] + HEAP32[(ptr + 4) >> 2] * 4294967296;
|
|
6051
|
-
|
|
6052
|
-
function ___syscall_utimensat(dirfd, path, times, flags) {
|
|
6053
|
-
try {
|
|
6054
|
-
path = SYSCALLS.getStr(path);
|
|
6055
|
-
path = SYSCALLS.calculateAt(dirfd, path, true);
|
|
6056
|
-
var now = Date.now(),
|
|
6057
|
-
atime,
|
|
6058
|
-
mtime;
|
|
6059
|
-
if (!times) {
|
|
6060
|
-
atime = now;
|
|
6061
|
-
mtime = now;
|
|
6062
|
-
} else {
|
|
6063
|
-
var seconds = readI53FromI64(times);
|
|
6064
|
-
var nanoseconds = HEAP32[(times + 8) >> 2];
|
|
6065
|
-
if (nanoseconds == 1073741823) {
|
|
6066
|
-
atime = now;
|
|
6067
|
-
} else if (nanoseconds == 1073741822) {
|
|
6068
|
-
atime = null;
|
|
6069
|
-
} else {
|
|
6070
|
-
atime = seconds * 1e3 + nanoseconds / (1e3 * 1e3);
|
|
6071
|
-
}
|
|
6072
|
-
times += 16;
|
|
6073
|
-
seconds = readI53FromI64(times);
|
|
6074
|
-
nanoseconds = HEAP32[(times + 8) >> 2];
|
|
6075
|
-
if (nanoseconds == 1073741823) {
|
|
6076
|
-
mtime = now;
|
|
6077
|
-
} else if (nanoseconds == 1073741822) {
|
|
6078
|
-
mtime = null;
|
|
6079
|
-
} else {
|
|
6080
|
-
mtime = seconds * 1e3 + nanoseconds / (1e3 * 1e3);
|
|
6620
|
+
pipe.refcnt--;
|
|
6621
|
+
if (pipe.refcnt === 0) {
|
|
6622
|
+
pipe.buckets = null;
|
|
6081
6623
|
}
|
|
6624
|
+
},
|
|
6625
|
+
},
|
|
6626
|
+
nextname() {
|
|
6627
|
+
if (!PIPEFS.nextname.current) {
|
|
6628
|
+
PIPEFS.nextname.current = 0;
|
|
6082
6629
|
}
|
|
6083
|
-
|
|
6084
|
-
|
|
6085
|
-
if ((mtime ?? atime) !== null) {
|
|
6086
|
-
FS.utime(path, atime, mtime);
|
|
6087
|
-
}
|
|
6088
|
-
return 0;
|
|
6089
|
-
} catch (e) {
|
|
6090
|
-
if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
|
|
6091
|
-
return -e.errno;
|
|
6092
|
-
}
|
|
6093
|
-
}
|
|
6094
|
-
|
|
6095
|
-
var __abort_js = () => abort('');
|
|
6096
|
-
|
|
6097
|
-
var __emscripten_lookup_name = (name) => {
|
|
6098
|
-
// uint32_t _emscripten_lookup_name(const char *name);
|
|
6099
|
-
var nameString = UTF8ToString(name);
|
|
6100
|
-
return inetPton4(DNS.lookup_name(nameString));
|
|
6101
|
-
};
|
|
6102
|
-
|
|
6103
|
-
var runtimeKeepaliveCounter = 0;
|
|
6104
|
-
|
|
6105
|
-
var __emscripten_runtime_keepalive_clear = () => {
|
|
6106
|
-
noExitRuntime = false;
|
|
6107
|
-
runtimeKeepaliveCounter = 0;
|
|
6108
|
-
};
|
|
6109
|
-
|
|
6110
|
-
function __gmtime_js(time, tmPtr) {
|
|
6111
|
-
time = bigintToI53Checked(time);
|
|
6112
|
-
var date = new Date(time * 1e3);
|
|
6113
|
-
HEAP32[tmPtr >> 2] = date.getUTCSeconds();
|
|
6114
|
-
HEAP32[(tmPtr + 4) >> 2] = date.getUTCMinutes();
|
|
6115
|
-
HEAP32[(tmPtr + 8) >> 2] = date.getUTCHours();
|
|
6116
|
-
HEAP32[(tmPtr + 12) >> 2] = date.getUTCDate();
|
|
6117
|
-
HEAP32[(tmPtr + 16) >> 2] = date.getUTCMonth();
|
|
6118
|
-
HEAP32[(tmPtr + 20) >> 2] = date.getUTCFullYear() - 1900;
|
|
6119
|
-
HEAP32[(tmPtr + 24) >> 2] = date.getUTCDay();
|
|
6120
|
-
var start = Date.UTC(date.getUTCFullYear(), 0, 1, 0, 0, 0, 0);
|
|
6121
|
-
var yday = ((date.getTime() - start) / (1e3 * 60 * 60 * 24)) | 0;
|
|
6122
|
-
HEAP32[(tmPtr + 28) >> 2] = yday;
|
|
6123
|
-
}
|
|
6124
|
-
|
|
6125
|
-
var isLeapYear = (year) =>
|
|
6126
|
-
year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
|
|
6127
|
-
|
|
6128
|
-
var MONTH_DAYS_LEAP_CUMULATIVE = [
|
|
6129
|
-
0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335,
|
|
6130
|
-
];
|
|
6131
|
-
|
|
6132
|
-
var MONTH_DAYS_REGULAR_CUMULATIVE = [
|
|
6133
|
-
0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334,
|
|
6134
|
-
];
|
|
6135
|
-
|
|
6136
|
-
var ydayFromDate = (date) => {
|
|
6137
|
-
var leap = isLeapYear(date.getFullYear());
|
|
6138
|
-
var monthDaysCumulative = leap
|
|
6139
|
-
? MONTH_DAYS_LEAP_CUMULATIVE
|
|
6140
|
-
: MONTH_DAYS_REGULAR_CUMULATIVE;
|
|
6141
|
-
var yday = monthDaysCumulative[date.getMonth()] + date.getDate() - 1;
|
|
6142
|
-
// -1 since it's days since Jan 1
|
|
6143
|
-
return yday;
|
|
6144
|
-
};
|
|
6145
|
-
|
|
6146
|
-
function __localtime_js(time, tmPtr) {
|
|
6147
|
-
time = bigintToI53Checked(time);
|
|
6148
|
-
var date = new Date(time * 1e3);
|
|
6149
|
-
HEAP32[tmPtr >> 2] = date.getSeconds();
|
|
6150
|
-
HEAP32[(tmPtr + 4) >> 2] = date.getMinutes();
|
|
6151
|
-
HEAP32[(tmPtr + 8) >> 2] = date.getHours();
|
|
6152
|
-
HEAP32[(tmPtr + 12) >> 2] = date.getDate();
|
|
6153
|
-
HEAP32[(tmPtr + 16) >> 2] = date.getMonth();
|
|
6154
|
-
HEAP32[(tmPtr + 20) >> 2] = date.getFullYear() - 1900;
|
|
6155
|
-
HEAP32[(tmPtr + 24) >> 2] = date.getDay();
|
|
6156
|
-
var yday = ydayFromDate(date) | 0;
|
|
6157
|
-
HEAP32[(tmPtr + 28) >> 2] = yday;
|
|
6158
|
-
HEAP32[(tmPtr + 36) >> 2] = -(date.getTimezoneOffset() * 60);
|
|
6159
|
-
// Attention: DST is in December in South, and some regions don't have DST at all.
|
|
6160
|
-
var start = new Date(date.getFullYear(), 0, 1);
|
|
6161
|
-
var summerOffset = new Date(
|
|
6162
|
-
date.getFullYear(),
|
|
6163
|
-
6,
|
|
6164
|
-
1
|
|
6165
|
-
).getTimezoneOffset();
|
|
6166
|
-
var winterOffset = start.getTimezoneOffset();
|
|
6167
|
-
var dst =
|
|
6168
|
-
(summerOffset != winterOffset &&
|
|
6169
|
-
date.getTimezoneOffset() ==
|
|
6170
|
-
Math.min(winterOffset, summerOffset)) | 0;
|
|
6171
|
-
HEAP32[(tmPtr + 32) >> 2] = dst;
|
|
6172
|
-
}
|
|
6173
|
-
|
|
6174
|
-
var __mktime_js = function (tmPtr) {
|
|
6175
|
-
var ret = (() => {
|
|
6176
|
-
var date = new Date(
|
|
6177
|
-
HEAP32[(tmPtr + 20) >> 2] + 1900,
|
|
6178
|
-
HEAP32[(tmPtr + 16) >> 2],
|
|
6179
|
-
HEAP32[(tmPtr + 12) >> 2],
|
|
6180
|
-
HEAP32[(tmPtr + 8) >> 2],
|
|
6181
|
-
HEAP32[(tmPtr + 4) >> 2],
|
|
6182
|
-
HEAP32[tmPtr >> 2],
|
|
6183
|
-
0
|
|
6184
|
-
);
|
|
6185
|
-
// There's an ambiguous hour when the time goes back; the tm_isdst field is
|
|
6186
|
-
// used to disambiguate it. Date() basically guesses, so we fix it up if it
|
|
6187
|
-
// guessed wrong, or fill in tm_isdst with the guess if it's -1.
|
|
6188
|
-
var dst = HEAP32[(tmPtr + 32) >> 2];
|
|
6189
|
-
var guessedOffset = date.getTimezoneOffset();
|
|
6190
|
-
var start = new Date(date.getFullYear(), 0, 1);
|
|
6191
|
-
var summerOffset = new Date(
|
|
6192
|
-
date.getFullYear(),
|
|
6193
|
-
6,
|
|
6194
|
-
1
|
|
6195
|
-
).getTimezoneOffset();
|
|
6196
|
-
var winterOffset = start.getTimezoneOffset();
|
|
6197
|
-
var dstOffset = Math.min(winterOffset, summerOffset);
|
|
6198
|
-
// DST is in December in South
|
|
6199
|
-
if (dst < 0) {
|
|
6200
|
-
// Attention: some regions don't have DST at all.
|
|
6201
|
-
HEAP32[(tmPtr + 32) >> 2] = Number(
|
|
6202
|
-
summerOffset != winterOffset && dstOffset == guessedOffset
|
|
6203
|
-
);
|
|
6204
|
-
} else if (dst > 0 != (dstOffset == guessedOffset)) {
|
|
6205
|
-
var nonDstOffset = Math.max(winterOffset, summerOffset);
|
|
6206
|
-
var trueOffset = dst > 0 ? dstOffset : nonDstOffset;
|
|
6207
|
-
// Don't try setMinutes(date.getMinutes() + ...) -- it's messed up.
|
|
6208
|
-
date.setTime(
|
|
6209
|
-
date.getTime() + (trueOffset - guessedOffset) * 6e4
|
|
6210
|
-
);
|
|
6211
|
-
}
|
|
6212
|
-
HEAP32[(tmPtr + 24) >> 2] = date.getDay();
|
|
6213
|
-
var yday = ydayFromDate(date) | 0;
|
|
6214
|
-
HEAP32[(tmPtr + 28) >> 2] = yday;
|
|
6215
|
-
// To match expected behavior, update fields from date
|
|
6216
|
-
HEAP32[tmPtr >> 2] = date.getSeconds();
|
|
6217
|
-
HEAP32[(tmPtr + 4) >> 2] = date.getMinutes();
|
|
6218
|
-
HEAP32[(tmPtr + 8) >> 2] = date.getHours();
|
|
6219
|
-
HEAP32[(tmPtr + 12) >> 2] = date.getDate();
|
|
6220
|
-
HEAP32[(tmPtr + 16) >> 2] = date.getMonth();
|
|
6221
|
-
HEAP32[(tmPtr + 20) >> 2] = date.getYear();
|
|
6222
|
-
var timeMs = date.getTime();
|
|
6223
|
-
if (isNaN(timeMs)) {
|
|
6224
|
-
return -1;
|
|
6225
|
-
}
|
|
6226
|
-
// Return time in microseconds
|
|
6227
|
-
return timeMs / 1e3;
|
|
6228
|
-
})();
|
|
6229
|
-
return BigInt(ret);
|
|
6630
|
+
return 'pipe[' + PIPEFS.nextname.current++ + ']';
|
|
6631
|
+
},
|
|
6230
6632
|
};
|
|
6231
6633
|
|
|
6232
|
-
function
|
|
6233
|
-
offset = bigintToI53Checked(offset);
|
|
6634
|
+
function ___syscall_pipe(fdPtr) {
|
|
6234
6635
|
try {
|
|
6235
|
-
if (
|
|
6236
|
-
|
|
6237
|
-
|
|
6238
|
-
var
|
|
6239
|
-
HEAP32[
|
|
6240
|
-
|
|
6636
|
+
if (fdPtr == 0) {
|
|
6637
|
+
throw new FS.ErrnoError(21);
|
|
6638
|
+
}
|
|
6639
|
+
var res = PIPEFS.createPipe();
|
|
6640
|
+
HEAP32[fdPtr >> 2] = res.readable_fd;
|
|
6641
|
+
HEAP32[(fdPtr + 4) >> 2] = res.writable_fd;
|
|
6241
6642
|
return 0;
|
|
6242
6643
|
} catch (e) {
|
|
6243
6644
|
if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
|
|
@@ -6245,991 +6646,1073 @@ export function init(RuntimeName, PHPLoader) {
|
|
|
6245
6646
|
}
|
|
6246
6647
|
}
|
|
6247
6648
|
|
|
6248
|
-
function
|
|
6249
|
-
offset = bigintToI53Checked(offset);
|
|
6649
|
+
function ___syscall_poll(fds, nfds, timeout) {
|
|
6250
6650
|
try {
|
|
6251
|
-
var
|
|
6252
|
-
|
|
6253
|
-
|
|
6651
|
+
var nonzero = 0;
|
|
6652
|
+
for (var i = 0; i < nfds; i++) {
|
|
6653
|
+
var pollfd = fds + 8 * i;
|
|
6654
|
+
var fd = HEAP32[pollfd >> 2];
|
|
6655
|
+
var events = HEAP16[(pollfd + 4) >> 1];
|
|
6656
|
+
var mask = 32;
|
|
6657
|
+
var stream = FS.getStream(fd);
|
|
6658
|
+
if (stream) {
|
|
6659
|
+
mask = SYSCALLS.DEFAULT_POLLMASK;
|
|
6660
|
+
if (stream.stream_ops?.poll) {
|
|
6661
|
+
mask = stream.stream_ops.poll(stream, -1);
|
|
6662
|
+
}
|
|
6663
|
+
}
|
|
6664
|
+
mask &= events | 8 | 16;
|
|
6665
|
+
if (mask) nonzero++;
|
|
6666
|
+
HEAP16[(pollfd + 6) >> 1] = mask;
|
|
6254
6667
|
}
|
|
6668
|
+
return nonzero;
|
|
6255
6669
|
} catch (e) {
|
|
6256
6670
|
if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
|
|
6257
6671
|
return -e.errno;
|
|
6258
6672
|
}
|
|
6259
6673
|
}
|
|
6260
6674
|
|
|
6261
|
-
|
|
6262
|
-
|
|
6263
|
-
|
|
6264
|
-
|
|
6265
|
-
|
|
6266
|
-
|
|
6267
|
-
|
|
6268
|
-
|
|
6269
|
-
|
|
6270
|
-
|
|
6271
|
-
|
|
6272
|
-
|
|
6273
|
-
|
|
6274
|
-
|
|
6275
|
-
|
|
6276
|
-
|
|
6277
|
-
var _proc_exit = (code) => {
|
|
6278
|
-
EXITSTATUS = code;
|
|
6279
|
-
if (!keepRuntimeAlive()) {
|
|
6280
|
-
Module['onExit']?.(code);
|
|
6281
|
-
ABORT = true;
|
|
6282
|
-
}
|
|
6283
|
-
quit_(code, new ExitStatus(code));
|
|
6284
|
-
};
|
|
6285
|
-
|
|
6286
|
-
/** @suppress {duplicate } */ /** @param {boolean|number=} implicit */ var exitJS =
|
|
6287
|
-
(status, implicit) => {
|
|
6288
|
-
EXITSTATUS = status;
|
|
6289
|
-
if (!keepRuntimeAlive()) {
|
|
6290
|
-
exitRuntime();
|
|
6291
|
-
}
|
|
6292
|
-
_proc_exit(status);
|
|
6293
|
-
};
|
|
6294
|
-
|
|
6295
|
-
var _exit = exitJS;
|
|
6296
|
-
|
|
6297
|
-
Module['_exit'] = _exit;
|
|
6298
|
-
|
|
6299
|
-
var maybeExit = () => {
|
|
6300
|
-
if (runtimeExited) {
|
|
6301
|
-
return;
|
|
6302
|
-
}
|
|
6303
|
-
if (!keepRuntimeAlive()) {
|
|
6304
|
-
try {
|
|
6305
|
-
_exit(EXITSTATUS);
|
|
6306
|
-
} catch (e) {
|
|
6307
|
-
handleException(e);
|
|
6308
|
-
}
|
|
6675
|
+
function ___syscall_readlinkat(dirfd, path, buf, bufsize) {
|
|
6676
|
+
try {
|
|
6677
|
+
path = SYSCALLS.getStr(path);
|
|
6678
|
+
path = SYSCALLS.calculateAt(dirfd, path);
|
|
6679
|
+
if (bufsize <= 0) return -28;
|
|
6680
|
+
var ret = FS.readlink(path);
|
|
6681
|
+
var len = Math.min(bufsize, lengthBytesUTF8(ret));
|
|
6682
|
+
var endChar = HEAP8[buf + len];
|
|
6683
|
+
stringToUTF8(ret, buf, bufsize + 1);
|
|
6684
|
+
// readlink is one of the rare functions that write out a C string, but does never append a null to the output buffer(!)
|
|
6685
|
+
// stringToUTF8() always appends a null byte, so restore the character under the null byte after the write.
|
|
6686
|
+
HEAP8[buf + len] = endChar;
|
|
6687
|
+
return len;
|
|
6688
|
+
} catch (e) {
|
|
6689
|
+
if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
|
|
6690
|
+
return -e.errno;
|
|
6309
6691
|
}
|
|
6310
|
-
}
|
|
6692
|
+
}
|
|
6311
6693
|
|
|
6312
|
-
|
|
6313
|
-
if (runtimeExited || ABORT) {
|
|
6314
|
-
return;
|
|
6315
|
-
}
|
|
6694
|
+
function ___syscall_recvfrom(fd, buf, len, flags, addr, addrlen) {
|
|
6316
6695
|
try {
|
|
6317
|
-
|
|
6318
|
-
|
|
6696
|
+
var sock = getSocketFromFD(fd);
|
|
6697
|
+
var msg = sock.sock_ops.recvmsg(
|
|
6698
|
+
sock,
|
|
6699
|
+
len,
|
|
6700
|
+
typeof flags !== 'undefined' ? flags : 0
|
|
6701
|
+
);
|
|
6702
|
+
if (!msg) return 0;
|
|
6703
|
+
// socket is closed
|
|
6704
|
+
if (addr) {
|
|
6705
|
+
var errno = writeSockaddr(
|
|
6706
|
+
addr,
|
|
6707
|
+
sock.family,
|
|
6708
|
+
DNS.lookup_name(msg.addr),
|
|
6709
|
+
msg.port,
|
|
6710
|
+
addrlen
|
|
6711
|
+
);
|
|
6712
|
+
}
|
|
6713
|
+
HEAPU8.set(msg.buffer, buf);
|
|
6714
|
+
return msg.buffer.byteLength;
|
|
6319
6715
|
} catch (e) {
|
|
6320
|
-
|
|
6321
|
-
|
|
6322
|
-
};
|
|
6323
|
-
|
|
6324
|
-
var _emscripten_get_now = () => performance.now();
|
|
6325
|
-
|
|
6326
|
-
var __setitimer_js = (which, timeout_ms) => {
|
|
6327
|
-
// First, clear any existing timer.
|
|
6328
|
-
if (timers[which]) {
|
|
6329
|
-
clearTimeout(timers[which].id);
|
|
6330
|
-
delete timers[which];
|
|
6716
|
+
if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
|
|
6717
|
+
return -e.errno;
|
|
6331
6718
|
}
|
|
6332
|
-
|
|
6333
|
-
// more to do.
|
|
6334
|
-
if (!timeout_ms) return 0;
|
|
6335
|
-
var id = setTimeout(() => {
|
|
6336
|
-
delete timers[which];
|
|
6337
|
-
callUserCallback(() =>
|
|
6338
|
-
__emscripten_timeout(which, _emscripten_get_now())
|
|
6339
|
-
);
|
|
6340
|
-
}, timeout_ms);
|
|
6341
|
-
timers[which] = {
|
|
6342
|
-
id,
|
|
6343
|
-
timeout_ms,
|
|
6344
|
-
};
|
|
6345
|
-
return 0;
|
|
6346
|
-
};
|
|
6719
|
+
}
|
|
6347
6720
|
|
|
6348
|
-
|
|
6349
|
-
|
|
6350
|
-
|
|
6351
|
-
|
|
6352
|
-
|
|
6353
|
-
|
|
6354
|
-
|
|
6355
|
-
|
|
6356
|
-
|
|
6357
|
-
|
|
6358
|
-
|
|
6359
|
-
// compares whether the output of the given date the same (Standard) or less
|
|
6360
|
-
// (DST).
|
|
6361
|
-
var stdTimezoneOffset = Math.max(winterOffset, summerOffset);
|
|
6362
|
-
// timezone is specified as seconds west of UTC ("The external variable
|
|
6363
|
-
// `timezone` shall be set to the difference, in seconds, between
|
|
6364
|
-
// Coordinated Universal Time (UTC) and local standard time."), the same
|
|
6365
|
-
// as returned by stdTimezoneOffset.
|
|
6366
|
-
// See http://pubs.opengroup.org/onlinepubs/009695399/functions/tzset.html
|
|
6367
|
-
HEAPU32[timezone >> 2] = stdTimezoneOffset * 60;
|
|
6368
|
-
HEAP32[daylight >> 2] = Number(winterOffset != summerOffset);
|
|
6369
|
-
var extractZone = (timezoneOffset) => {
|
|
6370
|
-
// Why inverse sign?
|
|
6371
|
-
// Read here https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTimezoneOffset
|
|
6372
|
-
var sign = timezoneOffset >= 0 ? '-' : '+';
|
|
6373
|
-
var absOffset = Math.abs(timezoneOffset);
|
|
6374
|
-
var hours = String(Math.floor(absOffset / 60)).padStart(2, '0');
|
|
6375
|
-
var minutes = String(absOffset % 60).padStart(2, '0');
|
|
6376
|
-
return `UTC${sign}${hours}${minutes}`;
|
|
6377
|
-
};
|
|
6378
|
-
var winterName = extractZone(winterOffset);
|
|
6379
|
-
var summerName = extractZone(summerOffset);
|
|
6380
|
-
if (summerOffset < winterOffset) {
|
|
6381
|
-
// Northern hemisphere
|
|
6382
|
-
stringToUTF8(winterName, std_name, 17);
|
|
6383
|
-
stringToUTF8(summerName, dst_name, 17);
|
|
6384
|
-
} else {
|
|
6385
|
-
stringToUTF8(winterName, dst_name, 17);
|
|
6386
|
-
stringToUTF8(summerName, std_name, 17);
|
|
6721
|
+
function ___syscall_renameat(olddirfd, oldpath, newdirfd, newpath) {
|
|
6722
|
+
try {
|
|
6723
|
+
oldpath = SYSCALLS.getStr(oldpath);
|
|
6724
|
+
newpath = SYSCALLS.getStr(newpath);
|
|
6725
|
+
oldpath = SYSCALLS.calculateAt(olddirfd, oldpath);
|
|
6726
|
+
newpath = SYSCALLS.calculateAt(newdirfd, newpath);
|
|
6727
|
+
FS.rename(oldpath, newpath);
|
|
6728
|
+
return 0;
|
|
6729
|
+
} catch (e) {
|
|
6730
|
+
if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
|
|
6731
|
+
return -e.errno;
|
|
6387
6732
|
}
|
|
6388
|
-
}
|
|
6389
|
-
|
|
6390
|
-
var _emscripten_date_now = () => Date.now();
|
|
6391
|
-
|
|
6392
|
-
var nowIsMonotonic = 1;
|
|
6393
|
-
|
|
6394
|
-
var checkWasiClock = (clock_id) => clock_id >= 0 && clock_id <= 3;
|
|
6733
|
+
}
|
|
6395
6734
|
|
|
6396
|
-
function
|
|
6397
|
-
|
|
6398
|
-
|
|
6399
|
-
|
|
6400
|
-
|
|
6401
|
-
|
|
6402
|
-
|
|
6403
|
-
|
|
6404
|
-
now = _emscripten_date_now();
|
|
6405
|
-
} else if (nowIsMonotonic) {
|
|
6406
|
-
now = _emscripten_get_now();
|
|
6407
|
-
} else {
|
|
6408
|
-
return 52;
|
|
6735
|
+
function ___syscall_rmdir(path) {
|
|
6736
|
+
try {
|
|
6737
|
+
path = SYSCALLS.getStr(path);
|
|
6738
|
+
FS.rmdir(path);
|
|
6739
|
+
return 0;
|
|
6740
|
+
} catch (e) {
|
|
6741
|
+
if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
|
|
6742
|
+
return -e.errno;
|
|
6409
6743
|
}
|
|
6410
|
-
// "now" is in ms, and wasi times are in ns.
|
|
6411
|
-
var nsec = Math.round(now * 1e3 * 1e3);
|
|
6412
|
-
HEAP64[ptime >> 3] = BigInt(nsec);
|
|
6413
|
-
return 0;
|
|
6414
6744
|
}
|
|
6415
6745
|
|
|
6416
|
-
|
|
6417
|
-
// Stay one Wasm page short of 4GB: while e.g. Chrome is able to allocate
|
|
6418
|
-
// full 4GB Wasm memories, the size will wrap back to 0 bytes in Wasm side
|
|
6419
|
-
// for any code that deals with heap sizes, which would require special
|
|
6420
|
-
// casing all heap size related code to treat 0 specially.
|
|
6421
|
-
2147483648;
|
|
6422
|
-
|
|
6423
|
-
var _emscripten_get_heap_max = () => getHeapMax();
|
|
6424
|
-
|
|
6425
|
-
var growMemory = (size) => {
|
|
6426
|
-
var b = wasmMemory.buffer;
|
|
6427
|
-
var pages = ((size - b.byteLength + 65535) / 65536) | 0;
|
|
6746
|
+
function ___syscall_sendto(fd, message, length, flags, addr, addr_len) {
|
|
6428
6747
|
try {
|
|
6429
|
-
|
|
6430
|
-
|
|
6431
|
-
|
|
6432
|
-
|
|
6433
|
-
return 1;
|
|
6434
|
-
} catch (e) {}
|
|
6435
|
-
};
|
|
6436
|
-
|
|
6437
|
-
var _emscripten_resize_heap = (requestedSize) => {
|
|
6438
|
-
var oldSize = HEAPU8.length;
|
|
6439
|
-
// With CAN_ADDRESS_2GB or MEMORY64, pointers are already unsigned.
|
|
6440
|
-
requestedSize >>>= 0;
|
|
6441
|
-
// With multithreaded builds, races can happen (another thread might increase the size
|
|
6442
|
-
// in between), so return a failure, and let the caller retry.
|
|
6443
|
-
// Memory resize rules:
|
|
6444
|
-
// 1. Always increase heap size to at least the requested size, rounded up
|
|
6445
|
-
// to next page multiple.
|
|
6446
|
-
// 2a. If MEMORY_GROWTH_LINEAR_STEP == -1, excessively resize the heap
|
|
6447
|
-
// geometrically: increase the heap size according to
|
|
6448
|
-
// MEMORY_GROWTH_GEOMETRIC_STEP factor (default +20%), At most
|
|
6449
|
-
// overreserve by MEMORY_GROWTH_GEOMETRIC_CAP bytes (default 96MB).
|
|
6450
|
-
// 2b. If MEMORY_GROWTH_LINEAR_STEP != -1, excessively resize the heap
|
|
6451
|
-
// linearly: increase the heap size by at least
|
|
6452
|
-
// MEMORY_GROWTH_LINEAR_STEP bytes.
|
|
6453
|
-
// 3. Max size for the heap is capped at 2048MB-WASM_PAGE_SIZE, or by
|
|
6454
|
-
// MAXIMUM_MEMORY, or by ASAN limit, depending on which is smallest
|
|
6455
|
-
// 4. If we were unable to allocate as much memory, it may be due to
|
|
6456
|
-
// over-eager decision to excessively reserve due to (3) above.
|
|
6457
|
-
// Hence if an allocation fails, cut down on the amount of excess
|
|
6458
|
-
// growth, in an attempt to succeed to perform a smaller allocation.
|
|
6459
|
-
// A limit is set for how much we can grow. We should not exceed that
|
|
6460
|
-
// (the wasm binary specifies it, so if we tried, we'd fail anyhow).
|
|
6461
|
-
var maxHeapSize = getHeapMax();
|
|
6462
|
-
if (requestedSize > maxHeapSize) {
|
|
6463
|
-
return false;
|
|
6464
|
-
}
|
|
6465
|
-
// Loop through potential heap size increases. If we attempt a too eager
|
|
6466
|
-
// reservation that fails, cut down on the attempted size and reserve a
|
|
6467
|
-
// smaller bump instead. (max 3 times, chosen somewhat arbitrarily)
|
|
6468
|
-
for (var cutDown = 1; cutDown <= 4; cutDown *= 2) {
|
|
6469
|
-
var overGrownHeapSize = oldSize * (1 + 0.2 / cutDown);
|
|
6470
|
-
// ensure geometric growth
|
|
6471
|
-
// but limit overreserving (default to capping at +96MB overgrowth at most)
|
|
6472
|
-
overGrownHeapSize = Math.min(
|
|
6473
|
-
overGrownHeapSize,
|
|
6474
|
-
requestedSize + 100663296
|
|
6475
|
-
);
|
|
6476
|
-
var newSize = Math.min(
|
|
6477
|
-
maxHeapSize,
|
|
6478
|
-
alignMemory(Math.max(requestedSize, overGrownHeapSize), 65536)
|
|
6479
|
-
);
|
|
6480
|
-
var replacement = growMemory(newSize);
|
|
6481
|
-
if (replacement) {
|
|
6482
|
-
return true;
|
|
6748
|
+
var sock = getSocketFromFD(fd);
|
|
6749
|
+
if (!addr) {
|
|
6750
|
+
// send, no address provided
|
|
6751
|
+
return FS.write(sock.stream, HEAP8, message, length);
|
|
6483
6752
|
}
|
|
6753
|
+
var dest = getSocketAddress(addr, addr_len);
|
|
6754
|
+
// sendto an address
|
|
6755
|
+
return sock.sock_ops.sendmsg(
|
|
6756
|
+
sock,
|
|
6757
|
+
HEAP8,
|
|
6758
|
+
message,
|
|
6759
|
+
length,
|
|
6760
|
+
dest.addr,
|
|
6761
|
+
dest.port
|
|
6762
|
+
);
|
|
6763
|
+
} catch (e) {
|
|
6764
|
+
if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
|
|
6765
|
+
return -e.errno;
|
|
6484
6766
|
}
|
|
6485
|
-
|
|
6486
|
-
};
|
|
6487
|
-
|
|
6488
|
-
var runtimeKeepalivePush = () => {
|
|
6489
|
-
runtimeKeepaliveCounter += 1;
|
|
6490
|
-
};
|
|
6491
|
-
|
|
6492
|
-
var runtimeKeepalivePop = () => {
|
|
6493
|
-
runtimeKeepaliveCounter -= 1;
|
|
6494
|
-
};
|
|
6767
|
+
}
|
|
6495
6768
|
|
|
6496
|
-
|
|
6497
|
-
|
|
6498
|
-
|
|
6499
|
-
|
|
6500
|
-
|
|
6501
|
-
|
|
6502
|
-
|
|
6769
|
+
function ___syscall_socket(domain, type, protocol) {
|
|
6770
|
+
try {
|
|
6771
|
+
var sock = SOCKFS.createSocket(domain, type, protocol);
|
|
6772
|
+
return sock.stream.fd;
|
|
6773
|
+
} catch (e) {
|
|
6774
|
+
if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
|
|
6775
|
+
return -e.errno;
|
|
6776
|
+
}
|
|
6777
|
+
}
|
|
6503
6778
|
|
|
6504
|
-
|
|
6505
|
-
|
|
6779
|
+
function ___syscall_stat64(path, buf) {
|
|
6780
|
+
try {
|
|
6781
|
+
path = SYSCALLS.getStr(path);
|
|
6782
|
+
return SYSCALLS.writeStat(buf, FS.stat(path));
|
|
6783
|
+
} catch (e) {
|
|
6784
|
+
if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
|
|
6785
|
+
return -e.errno;
|
|
6786
|
+
}
|
|
6787
|
+
}
|
|
6506
6788
|
|
|
6507
|
-
|
|
6789
|
+
function ___syscall_statfs64(path, size, buf) {
|
|
6790
|
+
try {
|
|
6791
|
+
SYSCALLS.writeStatFs(buf, FS.statfs(SYSCALLS.getStr(path)));
|
|
6792
|
+
return 0;
|
|
6793
|
+
} catch (e) {
|
|
6794
|
+
if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
|
|
6795
|
+
return -e.errno;
|
|
6796
|
+
}
|
|
6797
|
+
}
|
|
6508
6798
|
|
|
6509
|
-
|
|
6799
|
+
function ___syscall_symlinkat(target, dirfd, linkpath) {
|
|
6800
|
+
try {
|
|
6801
|
+
target = SYSCALLS.getStr(target);
|
|
6802
|
+
linkpath = SYSCALLS.getStr(linkpath);
|
|
6803
|
+
linkpath = SYSCALLS.calculateAt(dirfd, linkpath);
|
|
6804
|
+
FS.symlink(target, linkpath);
|
|
6805
|
+
return 0;
|
|
6806
|
+
} catch (e) {
|
|
6807
|
+
if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
|
|
6808
|
+
return -e.errno;
|
|
6809
|
+
}
|
|
6810
|
+
}
|
|
6510
6811
|
|
|
6511
|
-
|
|
6812
|
+
function ___syscall_unlinkat(dirfd, path, flags) {
|
|
6813
|
+
try {
|
|
6814
|
+
path = SYSCALLS.getStr(path);
|
|
6815
|
+
path = SYSCALLS.calculateAt(dirfd, path);
|
|
6816
|
+
if (flags === 0) {
|
|
6817
|
+
FS.unlink(path);
|
|
6818
|
+
} else if (flags === 512) {
|
|
6819
|
+
FS.rmdir(path);
|
|
6820
|
+
} else {
|
|
6821
|
+
abort('Invalid flags passed to unlinkat');
|
|
6822
|
+
}
|
|
6823
|
+
return 0;
|
|
6824
|
+
} catch (e) {
|
|
6825
|
+
if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
|
|
6826
|
+
return -e.errno;
|
|
6827
|
+
}
|
|
6828
|
+
}
|
|
6512
6829
|
|
|
6513
|
-
var
|
|
6830
|
+
var readI53FromI64 = (ptr) =>
|
|
6831
|
+
HEAPU32[ptr >> 2] + HEAP32[(ptr + 4) >> 2] * 4294967296;
|
|
6514
6832
|
|
|
6515
|
-
|
|
6516
|
-
|
|
6517
|
-
|
|
6518
|
-
|
|
6519
|
-
var
|
|
6520
|
-
|
|
6521
|
-
|
|
6522
|
-
|
|
6523
|
-
|
|
6524
|
-
|
|
6525
|
-
|
|
6526
|
-
|
|
6527
|
-
|
|
6528
|
-
|
|
6529
|
-
|
|
6530
|
-
|
|
6531
|
-
|
|
6532
|
-
|
|
6533
|
-
|
|
6534
|
-
|
|
6535
|
-
|
|
6536
|
-
|
|
6537
|
-
|
|
6538
|
-
|
|
6539
|
-
|
|
6540
|
-
if (
|
|
6541
|
-
|
|
6833
|
+
function ___syscall_utimensat(dirfd, path, times, flags) {
|
|
6834
|
+
try {
|
|
6835
|
+
path = SYSCALLS.getStr(path);
|
|
6836
|
+
path = SYSCALLS.calculateAt(dirfd, path, true);
|
|
6837
|
+
var now = Date.now(),
|
|
6838
|
+
atime,
|
|
6839
|
+
mtime;
|
|
6840
|
+
if (!times) {
|
|
6841
|
+
atime = now;
|
|
6842
|
+
mtime = now;
|
|
6843
|
+
} else {
|
|
6844
|
+
var seconds = readI53FromI64(times);
|
|
6845
|
+
var nanoseconds = HEAP32[(times + 8) >> 2];
|
|
6846
|
+
if (nanoseconds == 1073741823) {
|
|
6847
|
+
atime = now;
|
|
6848
|
+
} else if (nanoseconds == 1073741822) {
|
|
6849
|
+
atime = null;
|
|
6850
|
+
} else {
|
|
6851
|
+
atime = seconds * 1e3 + nanoseconds / (1e3 * 1e3);
|
|
6852
|
+
}
|
|
6853
|
+
times += 16;
|
|
6854
|
+
seconds = readI53FromI64(times);
|
|
6855
|
+
nanoseconds = HEAP32[(times + 8) >> 2];
|
|
6856
|
+
if (nanoseconds == 1073741823) {
|
|
6857
|
+
mtime = now;
|
|
6858
|
+
} else if (nanoseconds == 1073741822) {
|
|
6859
|
+
mtime = null;
|
|
6860
|
+
} else {
|
|
6861
|
+
mtime = seconds * 1e3 + nanoseconds / (1e3 * 1e3);
|
|
6862
|
+
}
|
|
6542
6863
|
}
|
|
6543
|
-
|
|
6544
|
-
|
|
6545
|
-
|
|
6864
|
+
// null here means UTIME_OMIT was passed. If both were set to UTIME_OMIT then
|
|
6865
|
+
// we can skip the call completely.
|
|
6866
|
+
if ((mtime ?? atime) !== null) {
|
|
6867
|
+
FS.utime(path, atime, mtime);
|
|
6546
6868
|
}
|
|
6547
|
-
|
|
6869
|
+
return 0;
|
|
6870
|
+
} catch (e) {
|
|
6871
|
+
if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
|
|
6872
|
+
return -e.errno;
|
|
6548
6873
|
}
|
|
6549
|
-
|
|
6550
|
-
};
|
|
6874
|
+
}
|
|
6551
6875
|
|
|
6552
|
-
var
|
|
6553
|
-
|
|
6554
|
-
|
|
6555
|
-
|
|
6556
|
-
|
|
6557
|
-
|
|
6876
|
+
var __abort_js = () => abort('');
|
|
6877
|
+
|
|
6878
|
+
var __emscripten_lookup_name = (name) => {
|
|
6879
|
+
// uint32_t _emscripten_lookup_name(const char *name);
|
|
6880
|
+
var nameString = UTF8ToString(name);
|
|
6881
|
+
return inetPton4(DNS.lookup_name(nameString));
|
|
6558
6882
|
};
|
|
6559
6883
|
|
|
6560
|
-
var
|
|
6561
|
-
|
|
6562
|
-
|
|
6563
|
-
|
|
6564
|
-
|
|
6565
|
-
stringToAscii(string, ptr);
|
|
6566
|
-
bufSize += string.length + 1;
|
|
6567
|
-
});
|
|
6568
|
-
return 0;
|
|
6884
|
+
var runtimeKeepaliveCounter = 0;
|
|
6885
|
+
|
|
6886
|
+
var __emscripten_runtime_keepalive_clear = () => {
|
|
6887
|
+
noExitRuntime = false;
|
|
6888
|
+
runtimeKeepaliveCounter = 0;
|
|
6569
6889
|
};
|
|
6570
6890
|
|
|
6571
|
-
|
|
6572
|
-
|
|
6573
|
-
|
|
6574
|
-
|
|
6575
|
-
|
|
6576
|
-
|
|
6577
|
-
|
|
6891
|
+
function __gmtime_js(time, tmPtr) {
|
|
6892
|
+
time = bigintToI53Checked(time);
|
|
6893
|
+
var date = new Date(time * 1e3);
|
|
6894
|
+
HEAP32[tmPtr >> 2] = date.getUTCSeconds();
|
|
6895
|
+
HEAP32[(tmPtr + 4) >> 2] = date.getUTCMinutes();
|
|
6896
|
+
HEAP32[(tmPtr + 8) >> 2] = date.getUTCHours();
|
|
6897
|
+
HEAP32[(tmPtr + 12) >> 2] = date.getUTCDate();
|
|
6898
|
+
HEAP32[(tmPtr + 16) >> 2] = date.getUTCMonth();
|
|
6899
|
+
HEAP32[(tmPtr + 20) >> 2] = date.getUTCFullYear() - 1900;
|
|
6900
|
+
HEAP32[(tmPtr + 24) >> 2] = date.getUTCDay();
|
|
6901
|
+
var start = Date.UTC(date.getUTCFullYear(), 0, 1, 0, 0, 0, 0);
|
|
6902
|
+
var yday = ((date.getTime() - start) / (1e3 * 60 * 60 * 24)) | 0;
|
|
6903
|
+
HEAP32[(tmPtr + 28) >> 2] = yday;
|
|
6904
|
+
}
|
|
6905
|
+
|
|
6906
|
+
var isLeapYear = (year) =>
|
|
6907
|
+
year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
|
|
6908
|
+
|
|
6909
|
+
var MONTH_DAYS_LEAP_CUMULATIVE = [
|
|
6910
|
+
0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335,
|
|
6911
|
+
];
|
|
6912
|
+
|
|
6913
|
+
var MONTH_DAYS_REGULAR_CUMULATIVE = [
|
|
6914
|
+
0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334,
|
|
6915
|
+
];
|
|
6916
|
+
|
|
6917
|
+
var ydayFromDate = (date) => {
|
|
6918
|
+
var leap = isLeapYear(date.getFullYear());
|
|
6919
|
+
var monthDaysCumulative = leap
|
|
6920
|
+
? MONTH_DAYS_LEAP_CUMULATIVE
|
|
6921
|
+
: MONTH_DAYS_REGULAR_CUMULATIVE;
|
|
6922
|
+
var yday = monthDaysCumulative[date.getMonth()] + date.getDate() - 1;
|
|
6923
|
+
// -1 since it's days since Jan 1
|
|
6924
|
+
return yday;
|
|
6578
6925
|
};
|
|
6579
6926
|
|
|
6580
|
-
function
|
|
6581
|
-
|
|
6582
|
-
|
|
6583
|
-
|
|
6584
|
-
|
|
6585
|
-
|
|
6586
|
-
|
|
6587
|
-
|
|
6588
|
-
|
|
6927
|
+
function __localtime_js(time, tmPtr) {
|
|
6928
|
+
time = bigintToI53Checked(time);
|
|
6929
|
+
var date = new Date(time * 1e3);
|
|
6930
|
+
HEAP32[tmPtr >> 2] = date.getSeconds();
|
|
6931
|
+
HEAP32[(tmPtr + 4) >> 2] = date.getMinutes();
|
|
6932
|
+
HEAP32[(tmPtr + 8) >> 2] = date.getHours();
|
|
6933
|
+
HEAP32[(tmPtr + 12) >> 2] = date.getDate();
|
|
6934
|
+
HEAP32[(tmPtr + 16) >> 2] = date.getMonth();
|
|
6935
|
+
HEAP32[(tmPtr + 20) >> 2] = date.getFullYear() - 1900;
|
|
6936
|
+
HEAP32[(tmPtr + 24) >> 2] = date.getDay();
|
|
6937
|
+
var yday = ydayFromDate(date) | 0;
|
|
6938
|
+
HEAP32[(tmPtr + 28) >> 2] = yday;
|
|
6939
|
+
HEAP32[(tmPtr + 36) >> 2] = -(date.getTimezoneOffset() * 60);
|
|
6940
|
+
// Attention: DST is in December in South, and some regions don't have DST at all.
|
|
6941
|
+
var start = new Date(date.getFullYear(), 0, 1);
|
|
6942
|
+
var summerOffset = new Date(
|
|
6943
|
+
date.getFullYear(),
|
|
6944
|
+
6,
|
|
6945
|
+
1
|
|
6946
|
+
).getTimezoneOffset();
|
|
6947
|
+
var winterOffset = start.getTimezoneOffset();
|
|
6948
|
+
var dst =
|
|
6949
|
+
(summerOffset != winterOffset &&
|
|
6950
|
+
date.getTimezoneOffset() ==
|
|
6951
|
+
Math.min(winterOffset, summerOffset)) | 0;
|
|
6952
|
+
HEAP32[(tmPtr + 32) >> 2] = dst;
|
|
6589
6953
|
}
|
|
6590
6954
|
|
|
6591
|
-
function
|
|
6592
|
-
|
|
6593
|
-
var
|
|
6594
|
-
|
|
6595
|
-
|
|
6596
|
-
|
|
6597
|
-
|
|
6598
|
-
|
|
6599
|
-
|
|
6600
|
-
|
|
6601
|
-
|
|
6602
|
-
|
|
6603
|
-
|
|
6604
|
-
|
|
6605
|
-
|
|
6606
|
-
|
|
6955
|
+
var __mktime_js = function (tmPtr) {
|
|
6956
|
+
var ret = (() => {
|
|
6957
|
+
var date = new Date(
|
|
6958
|
+
HEAP32[(tmPtr + 20) >> 2] + 1900,
|
|
6959
|
+
HEAP32[(tmPtr + 16) >> 2],
|
|
6960
|
+
HEAP32[(tmPtr + 12) >> 2],
|
|
6961
|
+
HEAP32[(tmPtr + 8) >> 2],
|
|
6962
|
+
HEAP32[(tmPtr + 4) >> 2],
|
|
6963
|
+
HEAP32[tmPtr >> 2],
|
|
6964
|
+
0
|
|
6965
|
+
);
|
|
6966
|
+
// There's an ambiguous hour when the time goes back; the tm_isdst field is
|
|
6967
|
+
// used to disambiguate it. Date() basically guesses, so we fix it up if it
|
|
6968
|
+
// guessed wrong, or fill in tm_isdst with the guess if it's -1.
|
|
6969
|
+
var dst = HEAP32[(tmPtr + 32) >> 2];
|
|
6970
|
+
var guessedOffset = date.getTimezoneOffset();
|
|
6971
|
+
var start = new Date(date.getFullYear(), 0, 1);
|
|
6972
|
+
var summerOffset = new Date(
|
|
6973
|
+
date.getFullYear(),
|
|
6974
|
+
6,
|
|
6975
|
+
1
|
|
6976
|
+
).getTimezoneOffset();
|
|
6977
|
+
var winterOffset = start.getTimezoneOffset();
|
|
6978
|
+
var dstOffset = Math.min(winterOffset, summerOffset);
|
|
6979
|
+
// DST is in December in South
|
|
6980
|
+
if (dst < 0) {
|
|
6981
|
+
// Attention: some regions don't have DST at all.
|
|
6982
|
+
HEAP32[(tmPtr + 32) >> 2] = Number(
|
|
6983
|
+
summerOffset != winterOffset && dstOffset == guessedOffset
|
|
6984
|
+
);
|
|
6985
|
+
} else if (dst > 0 != (dstOffset == guessedOffset)) {
|
|
6986
|
+
var nonDstOffset = Math.max(winterOffset, summerOffset);
|
|
6987
|
+
var trueOffset = dst > 0 ? dstOffset : nonDstOffset;
|
|
6988
|
+
// Don't try setMinutes(date.getMinutes() + ...) -- it's messed up.
|
|
6989
|
+
date.setTime(
|
|
6990
|
+
date.getTime() + (trueOffset - guessedOffset) * 6e4
|
|
6991
|
+
);
|
|
6607
6992
|
}
|
|
6608
|
-
|
|
6609
|
-
|
|
6610
|
-
|
|
6611
|
-
|
|
6612
|
-
|
|
6613
|
-
|
|
6614
|
-
|
|
6615
|
-
|
|
6616
|
-
|
|
6617
|
-
|
|
6618
|
-
|
|
6619
|
-
|
|
6620
|
-
|
|
6621
|
-
iov,
|
|
6622
|
-
iovcnt,
|
|
6623
|
-
offset
|
|
6624
|
-
) => {
|
|
6625
|
-
var ret = 0;
|
|
6626
|
-
for (var i = 0; i < iovcnt; i++) {
|
|
6627
|
-
var ptr = HEAPU32[iov >> 2];
|
|
6628
|
-
var len = HEAPU32[(iov + 4) >> 2];
|
|
6629
|
-
iov += 8;
|
|
6630
|
-
var curr = FS.read(stream, HEAP8, ptr, len, offset);
|
|
6631
|
-
if (curr < 0) return -1;
|
|
6632
|
-
ret += curr;
|
|
6633
|
-
if (curr < len) break;
|
|
6634
|
-
// nothing more to read
|
|
6635
|
-
if (typeof offset != 'undefined') {
|
|
6636
|
-
offset += curr;
|
|
6993
|
+
HEAP32[(tmPtr + 24) >> 2] = date.getDay();
|
|
6994
|
+
var yday = ydayFromDate(date) | 0;
|
|
6995
|
+
HEAP32[(tmPtr + 28) >> 2] = yday;
|
|
6996
|
+
// To match expected behavior, update fields from date
|
|
6997
|
+
HEAP32[tmPtr >> 2] = date.getSeconds();
|
|
6998
|
+
HEAP32[(tmPtr + 4) >> 2] = date.getMinutes();
|
|
6999
|
+
HEAP32[(tmPtr + 8) >> 2] = date.getHours();
|
|
7000
|
+
HEAP32[(tmPtr + 12) >> 2] = date.getDate();
|
|
7001
|
+
HEAP32[(tmPtr + 16) >> 2] = date.getMonth();
|
|
7002
|
+
HEAP32[(tmPtr + 20) >> 2] = date.getYear();
|
|
7003
|
+
var timeMs = date.getTime();
|
|
7004
|
+
if (isNaN(timeMs)) {
|
|
7005
|
+
return -1;
|
|
6637
7006
|
}
|
|
6638
|
-
|
|
6639
|
-
|
|
7007
|
+
// Return time in microseconds
|
|
7008
|
+
return timeMs / 1e3;
|
|
7009
|
+
})();
|
|
7010
|
+
return BigInt(ret);
|
|
6640
7011
|
};
|
|
6641
7012
|
|
|
6642
|
-
function
|
|
7013
|
+
function __mmap_js(len, prot, flags, fd, offset, allocated, addr) {
|
|
7014
|
+
offset = bigintToI53Checked(offset);
|
|
6643
7015
|
try {
|
|
7016
|
+
if (isNaN(offset)) return 61;
|
|
6644
7017
|
var stream = SYSCALLS.getStreamFromFD(fd);
|
|
6645
|
-
var
|
|
6646
|
-
|
|
7018
|
+
var res = FS.mmap(stream, len, offset, prot, flags);
|
|
7019
|
+
var ptr = res.ptr;
|
|
7020
|
+
HEAP32[allocated >> 2] = res.allocated;
|
|
7021
|
+
HEAPU32[addr >> 2] = ptr;
|
|
6647
7022
|
return 0;
|
|
6648
7023
|
} catch (e) {
|
|
6649
7024
|
if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
|
|
6650
|
-
return e.errno;
|
|
7025
|
+
return -e.errno;
|
|
6651
7026
|
}
|
|
6652
7027
|
}
|
|
6653
7028
|
|
|
6654
|
-
function
|
|
7029
|
+
function __munmap_js(addr, len, prot, flags, fd, offset) {
|
|
6655
7030
|
offset = bigintToI53Checked(offset);
|
|
6656
7031
|
try {
|
|
6657
|
-
if (isNaN(offset)) return 61;
|
|
6658
7032
|
var stream = SYSCALLS.getStreamFromFD(fd);
|
|
6659
|
-
|
|
6660
|
-
|
|
6661
|
-
|
|
6662
|
-
stream.getdents = null;
|
|
6663
|
-
// reset readdir state
|
|
6664
|
-
return 0;
|
|
7033
|
+
if (prot & 2) {
|
|
7034
|
+
SYSCALLS.doMsync(addr, stream, len, flags, offset);
|
|
7035
|
+
}
|
|
6665
7036
|
} catch (e) {
|
|
6666
7037
|
if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
|
|
6667
|
-
return e.errno;
|
|
7038
|
+
return -e.errno;
|
|
6668
7039
|
}
|
|
6669
7040
|
}
|
|
6670
7041
|
|
|
6671
|
-
|
|
6672
|
-
|
|
6673
|
-
|
|
6674
|
-
|
|
6675
|
-
|
|
6676
|
-
|
|
6677
|
-
|
|
6678
|
-
|
|
6679
|
-
|
|
6680
|
-
|
|
6681
|
-
iov += 8;
|
|
6682
|
-
var curr = FS.write(stream, HEAP8, ptr, len, offset);
|
|
6683
|
-
if (curr < 0) return -1;
|
|
6684
|
-
ret += curr;
|
|
6685
|
-
if (curr < len) {
|
|
6686
|
-
// No more space to write.
|
|
6687
|
-
break;
|
|
6688
|
-
}
|
|
6689
|
-
if (typeof offset != 'undefined') {
|
|
6690
|
-
offset += curr;
|
|
6691
|
-
}
|
|
7042
|
+
var timers = {};
|
|
7043
|
+
|
|
7044
|
+
var handleException = (e) => {
|
|
7045
|
+
// Certain exception types we do not treat as errors since they are used for
|
|
7046
|
+
// internal control flow.
|
|
7047
|
+
// 1. ExitStatus, which is thrown by exit()
|
|
7048
|
+
// 2. "unwind", which is thrown by emscripten_unwind_to_js_event_loop() and others
|
|
7049
|
+
// that wish to return to JS event loop.
|
|
7050
|
+
if (e instanceof ExitStatus || e == 'unwind') {
|
|
7051
|
+
return EXITSTATUS;
|
|
6692
7052
|
}
|
|
6693
|
-
|
|
7053
|
+
quit_(1, e);
|
|
6694
7054
|
};
|
|
6695
7055
|
|
|
6696
|
-
|
|
6697
|
-
try {
|
|
6698
|
-
var stream = SYSCALLS.getStreamFromFD(fd);
|
|
6699
|
-
var num = doWritev(stream, iov, iovcnt);
|
|
6700
|
-
HEAPU32[pnum >> 2] = num;
|
|
6701
|
-
return 0;
|
|
6702
|
-
} catch (e) {
|
|
6703
|
-
if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
|
|
6704
|
-
return e.errno;
|
|
6705
|
-
}
|
|
6706
|
-
}
|
|
7056
|
+
var keepRuntimeAlive = () => noExitRuntime || runtimeKeepaliveCounter > 0;
|
|
6707
7057
|
|
|
6708
|
-
var
|
|
6709
|
-
|
|
6710
|
-
|
|
6711
|
-
|
|
6712
|
-
|
|
6713
|
-
var type = 0;
|
|
6714
|
-
var proto = 0;
|
|
6715
|
-
var ai;
|
|
6716
|
-
function allocaddrinfo(family, type, proto, canon, addr, port) {
|
|
6717
|
-
var sa, salen, ai;
|
|
6718
|
-
var errno;
|
|
6719
|
-
salen = family === 10 ? 28 : 16;
|
|
6720
|
-
addr = family === 10 ? inetNtop6(addr) : inetNtop4(addr);
|
|
6721
|
-
sa = _malloc(salen);
|
|
6722
|
-
errno = writeSockaddr(sa, family, addr, port);
|
|
6723
|
-
assert(!errno);
|
|
6724
|
-
ai = _malloc(32);
|
|
6725
|
-
HEAP32[(ai + 4) >> 2] = family;
|
|
6726
|
-
HEAP32[(ai + 8) >> 2] = type;
|
|
6727
|
-
HEAP32[(ai + 12) >> 2] = proto;
|
|
6728
|
-
HEAPU32[(ai + 24) >> 2] = canon;
|
|
6729
|
-
HEAPU32[(ai + 20) >> 2] = sa;
|
|
6730
|
-
if (family === 10) {
|
|
6731
|
-
HEAP32[(ai + 16) >> 2] = 28;
|
|
6732
|
-
} else {
|
|
6733
|
-
HEAP32[(ai + 16) >> 2] = 16;
|
|
6734
|
-
}
|
|
6735
|
-
HEAP32[(ai + 28) >> 2] = 0;
|
|
6736
|
-
return ai;
|
|
6737
|
-
}
|
|
6738
|
-
if (hint) {
|
|
6739
|
-
flags = HEAP32[hint >> 2];
|
|
6740
|
-
family = HEAP32[(hint + 4) >> 2];
|
|
6741
|
-
type = HEAP32[(hint + 8) >> 2];
|
|
6742
|
-
proto = HEAP32[(hint + 12) >> 2];
|
|
6743
|
-
}
|
|
6744
|
-
if (type && !proto) {
|
|
6745
|
-
proto = type === 2 ? 17 : 6;
|
|
6746
|
-
}
|
|
6747
|
-
if (!type && proto) {
|
|
6748
|
-
type = proto === 17 ? 2 : 1;
|
|
6749
|
-
}
|
|
6750
|
-
// If type or proto are set to zero in hints we should really be returning multiple addrinfo values, but for
|
|
6751
|
-
// now default to a TCP STREAM socket so we can at least return a sensible addrinfo given NULL hints.
|
|
6752
|
-
if (proto === 0) {
|
|
6753
|
-
proto = 6;
|
|
6754
|
-
}
|
|
6755
|
-
if (type === 0) {
|
|
6756
|
-
type = 1;
|
|
6757
|
-
}
|
|
6758
|
-
if (!node && !service) {
|
|
6759
|
-
return -2;
|
|
6760
|
-
}
|
|
6761
|
-
if (flags & ~(1 | 2 | 4 | 1024 | 8 | 16 | 32)) {
|
|
6762
|
-
return -1;
|
|
6763
|
-
}
|
|
6764
|
-
if (hint !== 0 && HEAP32[hint >> 2] & 2 && !node) {
|
|
6765
|
-
return -1;
|
|
6766
|
-
}
|
|
6767
|
-
if (flags & 32) {
|
|
6768
|
-
// TODO
|
|
6769
|
-
return -2;
|
|
6770
|
-
}
|
|
6771
|
-
if (type !== 0 && type !== 1 && type !== 2) {
|
|
6772
|
-
return -7;
|
|
6773
|
-
}
|
|
6774
|
-
if (family !== 0 && family !== 2 && family !== 10) {
|
|
6775
|
-
return -6;
|
|
6776
|
-
}
|
|
6777
|
-
if (service) {
|
|
6778
|
-
service = UTF8ToString(service);
|
|
6779
|
-
port = parseInt(service, 10);
|
|
6780
|
-
if (isNaN(port)) {
|
|
6781
|
-
if (flags & 1024) {
|
|
6782
|
-
return -2;
|
|
6783
|
-
}
|
|
6784
|
-
// TODO support resolving well-known service names from:
|
|
6785
|
-
// http://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.txt
|
|
6786
|
-
return -8;
|
|
6787
|
-
}
|
|
6788
|
-
}
|
|
6789
|
-
if (!node) {
|
|
6790
|
-
if (family === 0) {
|
|
6791
|
-
family = 2;
|
|
6792
|
-
}
|
|
6793
|
-
if ((flags & 1) === 0) {
|
|
6794
|
-
if (family === 2) {
|
|
6795
|
-
addr = _htonl(2130706433);
|
|
6796
|
-
} else {
|
|
6797
|
-
addr = [0, 0, 0, _htonl(1)];
|
|
6798
|
-
}
|
|
6799
|
-
}
|
|
6800
|
-
ai = allocaddrinfo(family, type, proto, null, addr, port);
|
|
6801
|
-
HEAPU32[out >> 2] = ai;
|
|
6802
|
-
return 0;
|
|
7058
|
+
var _proc_exit = (code) => {
|
|
7059
|
+
EXITSTATUS = code;
|
|
7060
|
+
if (!keepRuntimeAlive()) {
|
|
7061
|
+
Module['onExit']?.(code);
|
|
7062
|
+
ABORT = true;
|
|
6803
7063
|
}
|
|
6804
|
-
|
|
6805
|
-
|
|
6806
|
-
|
|
6807
|
-
|
|
6808
|
-
|
|
6809
|
-
|
|
6810
|
-
|
|
6811
|
-
|
|
6812
|
-
addr = [0, 0, _htonl(65535), addr];
|
|
6813
|
-
family = 10;
|
|
6814
|
-
} else {
|
|
6815
|
-
return -2;
|
|
7064
|
+
quit_(code, new ExitStatus(code));
|
|
7065
|
+
};
|
|
7066
|
+
|
|
7067
|
+
/** @suppress {duplicate } */ /** @param {boolean|number=} implicit */ var exitJS =
|
|
7068
|
+
(status, implicit) => {
|
|
7069
|
+
EXITSTATUS = status;
|
|
7070
|
+
if (!keepRuntimeAlive()) {
|
|
7071
|
+
exitRuntime();
|
|
6816
7072
|
}
|
|
6817
|
-
|
|
6818
|
-
|
|
6819
|
-
|
|
6820
|
-
|
|
6821
|
-
|
|
6822
|
-
|
|
6823
|
-
|
|
6824
|
-
|
|
6825
|
-
|
|
7073
|
+
_proc_exit(status);
|
|
7074
|
+
};
|
|
7075
|
+
|
|
7076
|
+
var _exit = exitJS;
|
|
7077
|
+
|
|
7078
|
+
Module['_exit'] = _exit;
|
|
7079
|
+
|
|
7080
|
+
var maybeExit = () => {
|
|
7081
|
+
if (runtimeExited) {
|
|
7082
|
+
return;
|
|
7083
|
+
}
|
|
7084
|
+
if (!keepRuntimeAlive()) {
|
|
7085
|
+
try {
|
|
7086
|
+
_exit(EXITSTATUS);
|
|
7087
|
+
} catch (e) {
|
|
7088
|
+
handleException(e);
|
|
6826
7089
|
}
|
|
6827
7090
|
}
|
|
6828
|
-
|
|
6829
|
-
|
|
6830
|
-
|
|
6831
|
-
|
|
7091
|
+
};
|
|
7092
|
+
|
|
7093
|
+
var callUserCallback = (func) => {
|
|
7094
|
+
if (runtimeExited || ABORT) {
|
|
7095
|
+
return;
|
|
6832
7096
|
}
|
|
6833
|
-
|
|
6834
|
-
|
|
7097
|
+
try {
|
|
7098
|
+
func();
|
|
7099
|
+
maybeExit();
|
|
7100
|
+
} catch (e) {
|
|
7101
|
+
handleException(e);
|
|
6835
7102
|
}
|
|
6836
|
-
|
|
6837
|
-
|
|
6838
|
-
|
|
6839
|
-
|
|
6840
|
-
|
|
6841
|
-
|
|
6842
|
-
|
|
6843
|
-
|
|
7103
|
+
};
|
|
7104
|
+
|
|
7105
|
+
var _emscripten_get_now = () => performance.now();
|
|
7106
|
+
|
|
7107
|
+
var __setitimer_js = (which, timeout_ms) => {
|
|
7108
|
+
// First, clear any existing timer.
|
|
7109
|
+
if (timers[which]) {
|
|
7110
|
+
clearTimeout(timers[which].id);
|
|
7111
|
+
delete timers[which];
|
|
6844
7112
|
}
|
|
6845
|
-
|
|
6846
|
-
|
|
7113
|
+
// A timeout of zero simply cancels the current timeout so we have nothing
|
|
7114
|
+
// more to do.
|
|
7115
|
+
if (!timeout_ms) return 0;
|
|
7116
|
+
var id = setTimeout(() => {
|
|
7117
|
+
delete timers[which];
|
|
7118
|
+
callUserCallback(() =>
|
|
7119
|
+
__emscripten_timeout(which, _emscripten_get_now())
|
|
7120
|
+
);
|
|
7121
|
+
}, timeout_ms);
|
|
7122
|
+
timers[which] = {
|
|
7123
|
+
id,
|
|
7124
|
+
timeout_ms,
|
|
7125
|
+
};
|
|
6847
7126
|
return 0;
|
|
6848
7127
|
};
|
|
6849
7128
|
|
|
6850
|
-
var
|
|
6851
|
-
|
|
6852
|
-
|
|
6853
|
-
|
|
6854
|
-
|
|
6855
|
-
var
|
|
6856
|
-
var
|
|
6857
|
-
|
|
6858
|
-
|
|
6859
|
-
|
|
6860
|
-
|
|
6861
|
-
|
|
6862
|
-
|
|
6863
|
-
|
|
6864
|
-
|
|
6865
|
-
|
|
6866
|
-
|
|
6867
|
-
|
|
6868
|
-
|
|
6869
|
-
|
|
6870
|
-
|
|
7129
|
+
var __tzset_js = (timezone, daylight, std_name, dst_name) => {
|
|
7130
|
+
// TODO: Use (malleable) environment variables instead of system settings.
|
|
7131
|
+
var currentYear = new Date().getFullYear();
|
|
7132
|
+
var winter = new Date(currentYear, 0, 1);
|
|
7133
|
+
var summer = new Date(currentYear, 6, 1);
|
|
7134
|
+
var winterOffset = winter.getTimezoneOffset();
|
|
7135
|
+
var summerOffset = summer.getTimezoneOffset();
|
|
7136
|
+
// Local standard timezone offset. Local standard time is not adjusted for
|
|
7137
|
+
// daylight savings. This code uses the fact that getTimezoneOffset returns
|
|
7138
|
+
// a greater value during Standard Time versus Daylight Saving Time (DST).
|
|
7139
|
+
// Thus it determines the expected output during Standard Time, and it
|
|
7140
|
+
// compares whether the output of the given date the same (Standard) or less
|
|
7141
|
+
// (DST).
|
|
7142
|
+
var stdTimezoneOffset = Math.max(winterOffset, summerOffset);
|
|
7143
|
+
// timezone is specified as seconds west of UTC ("The external variable
|
|
7144
|
+
// `timezone` shall be set to the difference, in seconds, between
|
|
7145
|
+
// Coordinated Universal Time (UTC) and local standard time."), the same
|
|
7146
|
+
// as returned by stdTimezoneOffset.
|
|
7147
|
+
// See http://pubs.opengroup.org/onlinepubs/009695399/functions/tzset.html
|
|
7148
|
+
HEAPU32[timezone >> 2] = stdTimezoneOffset * 60;
|
|
7149
|
+
HEAP32[daylight >> 2] = Number(winterOffset != summerOffset);
|
|
7150
|
+
var extractZone = (timezoneOffset) => {
|
|
7151
|
+
// Why inverse sign?
|
|
7152
|
+
// Read here https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTimezoneOffset
|
|
7153
|
+
var sign = timezoneOffset >= 0 ? '-' : '+';
|
|
7154
|
+
var absOffset = Math.abs(timezoneOffset);
|
|
7155
|
+
var hours = String(Math.floor(absOffset / 60)).padStart(2, '0');
|
|
7156
|
+
var minutes = String(absOffset % 60).padStart(2, '0');
|
|
7157
|
+
return `UTC${sign}${hours}${minutes}`;
|
|
7158
|
+
};
|
|
7159
|
+
var winterName = extractZone(winterOffset);
|
|
7160
|
+
var summerName = extractZone(summerOffset);
|
|
7161
|
+
if (summerOffset < winterOffset) {
|
|
7162
|
+
// Northern hemisphere
|
|
7163
|
+
stringToUTF8(winterName, std_name, 17);
|
|
7164
|
+
stringToUTF8(summerName, dst_name, 17);
|
|
7165
|
+
} else {
|
|
7166
|
+
stringToUTF8(winterName, dst_name, 17);
|
|
7167
|
+
stringToUTF8(summerName, std_name, 17);
|
|
6871
7168
|
}
|
|
6872
|
-
|
|
6873
|
-
|
|
6874
|
-
|
|
6875
|
-
|
|
6876
|
-
|
|
6877
|
-
|
|
7169
|
+
};
|
|
7170
|
+
|
|
7171
|
+
var _emscripten_date_now = () => Date.now();
|
|
7172
|
+
|
|
7173
|
+
var nowIsMonotonic = 1;
|
|
7174
|
+
|
|
7175
|
+
var checkWasiClock = (clock_id) => clock_id >= 0 && clock_id <= 3;
|
|
7176
|
+
|
|
7177
|
+
function _clock_time_get(clk_id, ignored_precision, ptime) {
|
|
7178
|
+
ignored_precision = bigintToI53Checked(ignored_precision);
|
|
7179
|
+
if (!checkWasiClock(clk_id)) {
|
|
7180
|
+
return 28;
|
|
6878
7181
|
}
|
|
6879
|
-
|
|
6880
|
-
|
|
6881
|
-
|
|
7182
|
+
var now;
|
|
7183
|
+
// all wasi clocks but realtime are monotonic
|
|
7184
|
+
if (clk_id === 0) {
|
|
7185
|
+
now = _emscripten_date_now();
|
|
7186
|
+
} else if (nowIsMonotonic) {
|
|
7187
|
+
now = _emscripten_get_now();
|
|
7188
|
+
} else {
|
|
7189
|
+
return 52;
|
|
6882
7190
|
}
|
|
7191
|
+
// "now" is in ms, and wasi times are in ns.
|
|
7192
|
+
var nsec = Math.round(now * 1e3 * 1e3);
|
|
7193
|
+
HEAP64[ptime >> 3] = BigInt(nsec);
|
|
6883
7194
|
return 0;
|
|
7195
|
+
}
|
|
7196
|
+
|
|
7197
|
+
var getHeapMax = () =>
|
|
7198
|
+
// Stay one Wasm page short of 4GB: while e.g. Chrome is able to allocate
|
|
7199
|
+
// full 4GB Wasm memories, the size will wrap back to 0 bytes in Wasm side
|
|
7200
|
+
// for any code that deals with heap sizes, which would require special
|
|
7201
|
+
// casing all heap size related code to treat 0 specially.
|
|
7202
|
+
2147483648;
|
|
7203
|
+
|
|
7204
|
+
var _emscripten_get_heap_max = () => getHeapMax();
|
|
7205
|
+
|
|
7206
|
+
var growMemory = (size) => {
|
|
7207
|
+
var b = wasmMemory.buffer;
|
|
7208
|
+
var pages = ((size - b.byteLength + 65535) / 65536) | 0;
|
|
7209
|
+
try {
|
|
7210
|
+
// round size grow request up to wasm page size (fixed 64KB per spec)
|
|
7211
|
+
wasmMemory.grow(pages);
|
|
7212
|
+
// .grow() takes a delta compared to the previous size
|
|
7213
|
+
updateMemoryViews();
|
|
7214
|
+
return 1;
|
|
7215
|
+
} catch (e) {}
|
|
7216
|
+
};
|
|
7217
|
+
|
|
7218
|
+
var _emscripten_resize_heap = (requestedSize) => {
|
|
7219
|
+
var oldSize = HEAPU8.length;
|
|
7220
|
+
// With CAN_ADDRESS_2GB or MEMORY64, pointers are already unsigned.
|
|
7221
|
+
requestedSize >>>= 0;
|
|
7222
|
+
// With multithreaded builds, races can happen (another thread might increase the size
|
|
7223
|
+
// in between), so return a failure, and let the caller retry.
|
|
7224
|
+
// Memory resize rules:
|
|
7225
|
+
// 1. Always increase heap size to at least the requested size, rounded up
|
|
7226
|
+
// to next page multiple.
|
|
7227
|
+
// 2a. If MEMORY_GROWTH_LINEAR_STEP == -1, excessively resize the heap
|
|
7228
|
+
// geometrically: increase the heap size according to
|
|
7229
|
+
// MEMORY_GROWTH_GEOMETRIC_STEP factor (default +20%), At most
|
|
7230
|
+
// overreserve by MEMORY_GROWTH_GEOMETRIC_CAP bytes (default 96MB).
|
|
7231
|
+
// 2b. If MEMORY_GROWTH_LINEAR_STEP != -1, excessively resize the heap
|
|
7232
|
+
// linearly: increase the heap size by at least
|
|
7233
|
+
// MEMORY_GROWTH_LINEAR_STEP bytes.
|
|
7234
|
+
// 3. Max size for the heap is capped at 2048MB-WASM_PAGE_SIZE, or by
|
|
7235
|
+
// MAXIMUM_MEMORY, or by ASAN limit, depending on which is smallest
|
|
7236
|
+
// 4. If we were unable to allocate as much memory, it may be due to
|
|
7237
|
+
// over-eager decision to excessively reserve due to (3) above.
|
|
7238
|
+
// Hence if an allocation fails, cut down on the amount of excess
|
|
7239
|
+
// growth, in an attempt to succeed to perform a smaller allocation.
|
|
7240
|
+
// A limit is set for how much we can grow. We should not exceed that
|
|
7241
|
+
// (the wasm binary specifies it, so if we tried, we'd fail anyhow).
|
|
7242
|
+
var maxHeapSize = getHeapMax();
|
|
7243
|
+
if (requestedSize > maxHeapSize) {
|
|
7244
|
+
return false;
|
|
7245
|
+
}
|
|
7246
|
+
// Loop through potential heap size increases. If we attempt a too eager
|
|
7247
|
+
// reservation that fails, cut down on the attempted size and reserve a
|
|
7248
|
+
// smaller bump instead. (max 3 times, chosen somewhat arbitrarily)
|
|
7249
|
+
for (var cutDown = 1; cutDown <= 4; cutDown *= 2) {
|
|
7250
|
+
var overGrownHeapSize = oldSize * (1 + 0.2 / cutDown);
|
|
7251
|
+
// ensure geometric growth
|
|
7252
|
+
// but limit overreserving (default to capping at +96MB overgrowth at most)
|
|
7253
|
+
overGrownHeapSize = Math.min(
|
|
7254
|
+
overGrownHeapSize,
|
|
7255
|
+
requestedSize + 100663296
|
|
7256
|
+
);
|
|
7257
|
+
var newSize = Math.min(
|
|
7258
|
+
maxHeapSize,
|
|
7259
|
+
alignMemory(Math.max(requestedSize, overGrownHeapSize), 65536)
|
|
7260
|
+
);
|
|
7261
|
+
var replacement = growMemory(newSize);
|
|
7262
|
+
if (replacement) {
|
|
7263
|
+
return true;
|
|
7264
|
+
}
|
|
7265
|
+
}
|
|
7266
|
+
return false;
|
|
7267
|
+
};
|
|
7268
|
+
|
|
7269
|
+
var runtimeKeepalivePush = () => {
|
|
7270
|
+
runtimeKeepaliveCounter += 1;
|
|
7271
|
+
};
|
|
7272
|
+
|
|
7273
|
+
var runtimeKeepalivePop = () => {
|
|
7274
|
+
runtimeKeepaliveCounter -= 1;
|
|
7275
|
+
};
|
|
7276
|
+
|
|
7277
|
+
/** @param {number=} timeout */ var safeSetTimeout = (func, timeout) => {
|
|
7278
|
+
runtimeKeepalivePush();
|
|
7279
|
+
return setTimeout(() => {
|
|
7280
|
+
runtimeKeepalivePop();
|
|
7281
|
+
callUserCallback(func);
|
|
7282
|
+
}, timeout);
|
|
6884
7283
|
};
|
|
6885
7284
|
|
|
6886
|
-
var
|
|
6887
|
-
|
|
6888
|
-
map: {},
|
|
6889
|
-
};
|
|
7285
|
+
var _emscripten_sleep = (ms) =>
|
|
7286
|
+
Asyncify.handleSleep((wakeUp) => safeSetTimeout(wakeUp, ms));
|
|
6890
7287
|
|
|
6891
|
-
|
|
6892
|
-
|
|
6893
|
-
|
|
6894
|
-
|
|
6895
|
-
|
|
6896
|
-
|
|
6897
|
-
|
|
6898
|
-
|
|
6899
|
-
|
|
6900
|
-
|
|
6901
|
-
|
|
6902
|
-
//
|
|
6903
|
-
|
|
6904
|
-
|
|
6905
|
-
|
|
6906
|
-
|
|
6907
|
-
|
|
7288
|
+
Module['_emscripten_sleep'] = _emscripten_sleep;
|
|
7289
|
+
|
|
7290
|
+
_emscripten_sleep.isAsync = true;
|
|
7291
|
+
|
|
7292
|
+
var ENV = PHPLoader.ENV || {};
|
|
7293
|
+
|
|
7294
|
+
var getExecutableName = () => thisProgram || './this.program';
|
|
7295
|
+
|
|
7296
|
+
var getEnvStrings = () => {
|
|
7297
|
+
if (!getEnvStrings.strings) {
|
|
7298
|
+
// Default values.
|
|
7299
|
+
// Browser language detection #8751
|
|
7300
|
+
var lang =
|
|
7301
|
+
(
|
|
7302
|
+
(typeof navigator == 'object' &&
|
|
7303
|
+
navigator.languages &&
|
|
7304
|
+
navigator.languages[0]) ||
|
|
7305
|
+
'C'
|
|
7306
|
+
).replace('-', '_') + '.UTF-8';
|
|
7307
|
+
var env = {
|
|
7308
|
+
USER: 'web_user',
|
|
7309
|
+
LOGNAME: 'web_user',
|
|
7310
|
+
PATH: '/',
|
|
7311
|
+
PWD: '/',
|
|
7312
|
+
HOME: '/home/web_user',
|
|
7313
|
+
LANG: lang,
|
|
7314
|
+
_: getExecutableName(),
|
|
7315
|
+
};
|
|
7316
|
+
// Apply the user-provided values, if any.
|
|
7317
|
+
for (var x in ENV) {
|
|
7318
|
+
// x is a key in ENV; if ENV[x] is undefined, that means it was
|
|
7319
|
+
// explicitly set to be so. We allow user code to do that to
|
|
7320
|
+
// force variables with default values to remain unset.
|
|
7321
|
+
if (ENV[x] === undefined) delete env[x];
|
|
7322
|
+
else env[x] = ENV[x];
|
|
6908
7323
|
}
|
|
6909
|
-
|
|
6910
|
-
|
|
6911
|
-
|
|
6912
|
-
|
|
6913
|
-
|
|
6914
|
-
HEAPU32[(pe + 4) >> 2] = aliasListBuf;
|
|
6915
|
-
HEAP32[(pe + 8) >> 2] = proto;
|
|
6916
|
-
return pe;
|
|
6917
|
-
}
|
|
6918
|
-
// Populate the protocol 'database'. The entries are limited to tcp and udp, though it is fairly trivial
|
|
6919
|
-
// to add extra entries from /etc/protocols if desired - though not sure if that'd actually be useful.
|
|
6920
|
-
var list = Protocols.list;
|
|
6921
|
-
var map = Protocols.map;
|
|
6922
|
-
if (list.length === 0) {
|
|
6923
|
-
var entry = allocprotoent('tcp', 6, ['TCP']);
|
|
6924
|
-
list.push(entry);
|
|
6925
|
-
map['tcp'] = map['6'] = entry;
|
|
6926
|
-
entry = allocprotoent('udp', 17, ['UDP']);
|
|
6927
|
-
list.push(entry);
|
|
6928
|
-
map['udp'] = map['17'] = entry;
|
|
7324
|
+
var strings = [];
|
|
7325
|
+
for (var x in env) {
|
|
7326
|
+
strings.push(`${x}=${env[x]}`);
|
|
7327
|
+
}
|
|
7328
|
+
getEnvStrings.strings = strings;
|
|
6929
7329
|
}
|
|
6930
|
-
|
|
7330
|
+
return getEnvStrings.strings;
|
|
6931
7331
|
};
|
|
6932
7332
|
|
|
6933
|
-
var
|
|
6934
|
-
|
|
6935
|
-
|
|
6936
|
-
|
|
6937
|
-
|
|
6938
|
-
|
|
7333
|
+
var stringToAscii = (str, buffer) => {
|
|
7334
|
+
for (var i = 0; i < str.length; ++i) {
|
|
7335
|
+
HEAP8[buffer++] = str.charCodeAt(i);
|
|
7336
|
+
}
|
|
7337
|
+
// Null-terminate the string
|
|
7338
|
+
HEAP8[buffer] = 0;
|
|
6939
7339
|
};
|
|
6940
7340
|
|
|
6941
|
-
var
|
|
6942
|
-
|
|
6943
|
-
|
|
6944
|
-
|
|
6945
|
-
|
|
7341
|
+
var _environ_get = (__environ, environ_buf) => {
|
|
7342
|
+
var bufSize = 0;
|
|
7343
|
+
getEnvStrings().forEach((string, i) => {
|
|
7344
|
+
var ptr = environ_buf + bufSize;
|
|
7345
|
+
HEAPU32[(__environ + i * 4) >> 2] = ptr;
|
|
7346
|
+
stringToAscii(string, ptr);
|
|
7347
|
+
bufSize += string.length + 1;
|
|
7348
|
+
});
|
|
7349
|
+
return 0;
|
|
6946
7350
|
};
|
|
6947
7351
|
|
|
6948
|
-
var
|
|
6949
|
-
|
|
6950
|
-
|
|
6951
|
-
var
|
|
6952
|
-
|
|
6953
|
-
|
|
6954
|
-
return
|
|
7352
|
+
var _environ_sizes_get = (penviron_count, penviron_buf_size) => {
|
|
7353
|
+
var strings = getEnvStrings();
|
|
7354
|
+
HEAPU32[penviron_count >> 2] = strings.length;
|
|
7355
|
+
var bufSize = 0;
|
|
7356
|
+
strings.forEach((string) => (bufSize += string.length + 1));
|
|
7357
|
+
HEAPU32[penviron_buf_size >> 2] = bufSize;
|
|
7358
|
+
return 0;
|
|
6955
7359
|
};
|
|
6956
7360
|
|
|
6957
|
-
|
|
6958
|
-
|
|
6959
|
-
|
|
6960
|
-
|
|
6961
|
-
|
|
6962
|
-
|
|
6963
|
-
|
|
6964
|
-
|
|
6965
|
-
|
|
6966
|
-
|
|
6967
|
-
|
|
6968
|
-
|
|
6969
|
-
|
|
6970
|
-
|
|
6971
|
-
|
|
6972
|
-
|
|
6973
|
-
// on the first null byte. However, when dealing with binary data,
|
|
6974
|
-
// null bytes are valid and common.
|
|
6975
|
-
FS.registerDevice(FS.makedev(64, 0), {
|
|
6976
|
-
open: () => {},
|
|
6977
|
-
close: () => {},
|
|
6978
|
-
read: () => 0,
|
|
6979
|
-
write: (stream, buffer, offset, length, pos) => {
|
|
6980
|
-
const chunk = buffer.subarray(offset, offset + length);
|
|
6981
|
-
PHPWASM.onStdout(chunk);
|
|
6982
|
-
return length;
|
|
6983
|
-
},
|
|
6984
|
-
});
|
|
6985
|
-
FS.mkdev('/internal/stdout', FS.makedev(64, 0));
|
|
6986
|
-
FS.registerDevice(FS.makedev(63, 0), {
|
|
6987
|
-
open: () => {},
|
|
6988
|
-
close: () => {},
|
|
6989
|
-
read: () => 0,
|
|
6990
|
-
write: (stream, buffer, offset, length, pos) => {
|
|
6991
|
-
const chunk = buffer.subarray(offset, offset + length);
|
|
6992
|
-
PHPWASM.onStderr(chunk);
|
|
6993
|
-
return length;
|
|
6994
|
-
},
|
|
6995
|
-
});
|
|
6996
|
-
FS.mkdev('/internal/stderr', FS.makedev(63, 0));
|
|
6997
|
-
FS.registerDevice(FS.makedev(62, 0), {
|
|
6998
|
-
open: () => {},
|
|
6999
|
-
close: () => {},
|
|
7000
|
-
read: () => 0,
|
|
7001
|
-
write: (stream, buffer, offset, length, pos) => {
|
|
7002
|
-
const chunk = buffer.subarray(offset, offset + length);
|
|
7003
|
-
PHPWASM.onHeaders(chunk);
|
|
7004
|
-
return length;
|
|
7005
|
-
},
|
|
7006
|
-
});
|
|
7007
|
-
FS.mkdev('/internal/headers', FS.makedev(62, 0));
|
|
7008
|
-
// Handle events.
|
|
7009
|
-
PHPWASM.EventEmitter = ENVIRONMENT_IS_NODE
|
|
7010
|
-
? require('events').EventEmitter
|
|
7011
|
-
: class EventEmitter {
|
|
7012
|
-
constructor() {
|
|
7013
|
-
this.listeners = {};
|
|
7014
|
-
}
|
|
7015
|
-
emit(eventName, data) {
|
|
7016
|
-
if (this.listeners[eventName]) {
|
|
7017
|
-
this.listeners[eventName].forEach(
|
|
7018
|
-
(callback) => {
|
|
7019
|
-
callback(data);
|
|
7020
|
-
}
|
|
7021
|
-
);
|
|
7022
|
-
}
|
|
7023
|
-
}
|
|
7024
|
-
once(eventName, callback) {
|
|
7025
|
-
const self = this;
|
|
7026
|
-
function removedCallback() {
|
|
7027
|
-
callback(...arguments);
|
|
7028
|
-
self.removeListener(eventName, removedCallback);
|
|
7029
|
-
}
|
|
7030
|
-
this.on(eventName, removedCallback);
|
|
7031
|
-
}
|
|
7032
|
-
removeAllListeners(eventName) {
|
|
7033
|
-
if (eventName) {
|
|
7034
|
-
delete this.listeners[eventName];
|
|
7035
|
-
} else {
|
|
7036
|
-
this.listeners = {};
|
|
7037
|
-
}
|
|
7038
|
-
}
|
|
7039
|
-
removeListener(eventName, callback) {
|
|
7040
|
-
if (this.listeners[eventName]) {
|
|
7041
|
-
const idx =
|
|
7042
|
-
this.listeners[eventName].indexOf(callback);
|
|
7043
|
-
if (idx !== -1) {
|
|
7044
|
-
this.listeners[eventName].splice(idx, 1);
|
|
7045
|
-
}
|
|
7046
|
-
}
|
|
7047
|
-
}
|
|
7048
|
-
};
|
|
7049
|
-
// Clean up the fd -> childProcess mapping when the fd is closed:
|
|
7050
|
-
const originalClose = FS.close;
|
|
7051
|
-
FS.close = function (stream) {
|
|
7052
|
-
originalClose(stream);
|
|
7053
|
-
delete PHPWASM.child_proc_by_fd[stream.fd];
|
|
7054
|
-
};
|
|
7055
|
-
PHPWASM.child_proc_by_fd = {};
|
|
7056
|
-
PHPWASM.child_proc_by_pid = {};
|
|
7057
|
-
PHPWASM.input_devices = {};
|
|
7058
|
-
const originalWrite = TTY.stream_ops.write;
|
|
7059
|
-
TTY.stream_ops.write = function (stream, ...rest) {
|
|
7060
|
-
const retval = originalWrite(stream, ...rest);
|
|
7061
|
-
// Implicit flush since PHP's fflush() doesn't seem to trigger the fsync event
|
|
7062
|
-
// @TODO: Fix this at the wasm level
|
|
7063
|
-
stream.tty.ops.fsync(stream.tty);
|
|
7064
|
-
return retval;
|
|
7065
|
-
};
|
|
7066
|
-
const originalPutChar = TTY.stream_ops.put_char;
|
|
7067
|
-
TTY.stream_ops.put_char = function (tty, val) {
|
|
7068
|
-
/**
|
|
7069
|
-
* Buffer newlines that Emscripten normally ignores.
|
|
7070
|
-
*
|
|
7071
|
-
* Emscripten doesn't do it by default because its default
|
|
7072
|
-
* print function is console.log that implicitly adds a newline. We are overwriting
|
|
7073
|
-
* it with an environment-specific function that outputs exaclty what it was given,
|
|
7074
|
-
* e.g. in Node.js it's process.stdout.write(). Therefore, we need to mak sure
|
|
7075
|
-
* all the newlines make it to the output buffer.
|
|
7076
|
-
*/ if (val === 10) tty.output.push(val);
|
|
7077
|
-
return originalPutChar(tty, val);
|
|
7078
|
-
};
|
|
7079
|
-
},
|
|
7080
|
-
onHeaders: function (chunk) {
|
|
7081
|
-
if (Module['onHeaders']) {
|
|
7082
|
-
Module['onHeaders'](chunk);
|
|
7083
|
-
return;
|
|
7361
|
+
function _fd_fdstat_get(fd, pbuf) {
|
|
7362
|
+
try {
|
|
7363
|
+
var rightsBase = 0;
|
|
7364
|
+
var rightsInheriting = 0;
|
|
7365
|
+
var flags = 0;
|
|
7366
|
+
{
|
|
7367
|
+
var stream = SYSCALLS.getStreamFromFD(fd);
|
|
7368
|
+
// All character devices are terminals (other things a Linux system would
|
|
7369
|
+
// assume is a character device, like the mouse, we have special APIs for).
|
|
7370
|
+
var type = stream.tty
|
|
7371
|
+
? 2
|
|
7372
|
+
: FS.isDir(stream.mode)
|
|
7373
|
+
? 3
|
|
7374
|
+
: FS.isLink(stream.mode)
|
|
7375
|
+
? 7
|
|
7376
|
+
: 4;
|
|
7084
7377
|
}
|
|
7085
|
-
|
|
7086
|
-
|
|
7087
|
-
|
|
7088
|
-
|
|
7089
|
-
|
|
7090
|
-
|
|
7091
|
-
|
|
7092
|
-
|
|
7378
|
+
HEAP8[pbuf] = type;
|
|
7379
|
+
HEAP16[(pbuf + 2) >> 1] = flags;
|
|
7380
|
+
HEAP64[(pbuf + 8) >> 3] = BigInt(rightsBase);
|
|
7381
|
+
HEAP64[(pbuf + 16) >> 3] = BigInt(rightsInheriting);
|
|
7382
|
+
return 0;
|
|
7383
|
+
} catch (e) {
|
|
7384
|
+
if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
|
|
7385
|
+
return e.errno;
|
|
7386
|
+
}
|
|
7387
|
+
}
|
|
7388
|
+
|
|
7389
|
+
/** @param {number=} offset */ var doReadv = (
|
|
7390
|
+
stream,
|
|
7391
|
+
iov,
|
|
7392
|
+
iovcnt,
|
|
7393
|
+
offset
|
|
7394
|
+
) => {
|
|
7395
|
+
var ret = 0;
|
|
7396
|
+
for (var i = 0; i < iovcnt; i++) {
|
|
7397
|
+
var ptr = HEAPU32[iov >> 2];
|
|
7398
|
+
var len = HEAPU32[(iov + 4) >> 2];
|
|
7399
|
+
iov += 8;
|
|
7400
|
+
var curr = FS.read(stream, HEAP8, ptr, len, offset);
|
|
7401
|
+
if (curr < 0) return -1;
|
|
7402
|
+
ret += curr;
|
|
7403
|
+
if (curr < len) break;
|
|
7404
|
+
// nothing more to read
|
|
7405
|
+
if (typeof offset != 'undefined') {
|
|
7406
|
+
offset += curr;
|
|
7093
7407
|
}
|
|
7094
|
-
|
|
7095
|
-
|
|
7096
|
-
|
|
7097
|
-
|
|
7098
|
-
|
|
7099
|
-
|
|
7408
|
+
}
|
|
7409
|
+
return ret;
|
|
7410
|
+
};
|
|
7411
|
+
|
|
7412
|
+
function _fd_read(fd, iov, iovcnt, pnum) {
|
|
7413
|
+
try {
|
|
7414
|
+
var stream = SYSCALLS.getStreamFromFD(fd);
|
|
7415
|
+
var num = doReadv(stream, iov, iovcnt);
|
|
7416
|
+
HEAPU32[pnum >> 2] = num;
|
|
7417
|
+
return 0;
|
|
7418
|
+
} catch (e) {
|
|
7419
|
+
if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
|
|
7420
|
+
return e.errno;
|
|
7421
|
+
}
|
|
7422
|
+
}
|
|
7423
|
+
|
|
7424
|
+
function _fd_seek(fd, offset, whence, newOffset) {
|
|
7425
|
+
offset = bigintToI53Checked(offset);
|
|
7426
|
+
try {
|
|
7427
|
+
if (isNaN(offset)) return 61;
|
|
7428
|
+
var stream = SYSCALLS.getStreamFromFD(fd);
|
|
7429
|
+
FS.llseek(stream, offset, whence);
|
|
7430
|
+
HEAP64[newOffset >> 3] = BigInt(stream.position);
|
|
7431
|
+
if (stream.getdents && offset === 0 && whence === 0)
|
|
7432
|
+
stream.getdents = null;
|
|
7433
|
+
// reset readdir state
|
|
7434
|
+
return 0;
|
|
7435
|
+
} catch (e) {
|
|
7436
|
+
if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
|
|
7437
|
+
return e.errno;
|
|
7438
|
+
}
|
|
7439
|
+
}
|
|
7440
|
+
|
|
7441
|
+
/** @param {number=} offset */ var doWritev = (
|
|
7442
|
+
stream,
|
|
7443
|
+
iov,
|
|
7444
|
+
iovcnt,
|
|
7445
|
+
offset
|
|
7446
|
+
) => {
|
|
7447
|
+
var ret = 0;
|
|
7448
|
+
for (var i = 0; i < iovcnt; i++) {
|
|
7449
|
+
var ptr = HEAPU32[iov >> 2];
|
|
7450
|
+
var len = HEAPU32[(iov + 4) >> 2];
|
|
7451
|
+
iov += 8;
|
|
7452
|
+
var curr = FS.write(stream, HEAP8, ptr, len, offset);
|
|
7453
|
+
if (curr < 0) return -1;
|
|
7454
|
+
ret += curr;
|
|
7455
|
+
if (curr < len) {
|
|
7456
|
+
// No more space to write.
|
|
7457
|
+
break;
|
|
7100
7458
|
}
|
|
7101
|
-
|
|
7102
|
-
|
|
7103
|
-
if (Module['onStderr']) {
|
|
7104
|
-
Module['onStderr'](chunk);
|
|
7105
|
-
return;
|
|
7459
|
+
if (typeof offset != 'undefined') {
|
|
7460
|
+
offset += curr;
|
|
7106
7461
|
}
|
|
7107
|
-
|
|
7108
|
-
|
|
7462
|
+
}
|
|
7463
|
+
return ret;
|
|
7464
|
+
};
|
|
7465
|
+
|
|
7466
|
+
function _fd_write(fd, iov, iovcnt, pnum) {
|
|
7467
|
+
try {
|
|
7468
|
+
var stream = SYSCALLS.getStreamFromFD(fd);
|
|
7469
|
+
var num = doWritev(stream, iov, iovcnt);
|
|
7470
|
+
HEAPU32[pnum >> 2] = num;
|
|
7471
|
+
return 0;
|
|
7472
|
+
} catch (e) {
|
|
7473
|
+
if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
|
|
7474
|
+
return e.errno;
|
|
7475
|
+
}
|
|
7476
|
+
}
|
|
7477
|
+
|
|
7478
|
+
var _getaddrinfo = (node, service, hint, out) => {
|
|
7479
|
+
var addr = 0;
|
|
7480
|
+
var port = 0;
|
|
7481
|
+
var flags = 0;
|
|
7482
|
+
var family = 0;
|
|
7483
|
+
var type = 0;
|
|
7484
|
+
var proto = 0;
|
|
7485
|
+
var ai;
|
|
7486
|
+
function allocaddrinfo(family, type, proto, canon, addr, port) {
|
|
7487
|
+
var sa, salen, ai;
|
|
7488
|
+
var errno;
|
|
7489
|
+
salen = family === 10 ? 28 : 16;
|
|
7490
|
+
addr = family === 10 ? inetNtop6(addr) : inetNtop4(addr);
|
|
7491
|
+
sa = _malloc(salen);
|
|
7492
|
+
errno = writeSockaddr(sa, family, addr, port);
|
|
7493
|
+
assert(!errno);
|
|
7494
|
+
ai = _malloc(32);
|
|
7495
|
+
HEAP32[(ai + 4) >> 2] = family;
|
|
7496
|
+
HEAP32[(ai + 8) >> 2] = type;
|
|
7497
|
+
HEAP32[(ai + 12) >> 2] = proto;
|
|
7498
|
+
HEAPU32[(ai + 24) >> 2] = canon;
|
|
7499
|
+
HEAPU32[(ai + 20) >> 2] = sa;
|
|
7500
|
+
if (family === 10) {
|
|
7501
|
+
HEAP32[(ai + 16) >> 2] = 28;
|
|
7109
7502
|
} else {
|
|
7110
|
-
|
|
7111
|
-
chunk,
|
|
7112
|
-
});
|
|
7113
|
-
}
|
|
7114
|
-
},
|
|
7115
|
-
getAllWebSockets: function (sock) {
|
|
7116
|
-
const webSockets = new Set();
|
|
7117
|
-
if (sock.server) {
|
|
7118
|
-
sock.server.clients.forEach((ws) => {
|
|
7119
|
-
webSockets.add(ws);
|
|
7120
|
-
});
|
|
7121
|
-
}
|
|
7122
|
-
for (const peer of PHPWASM.getAllPeers(sock)) {
|
|
7123
|
-
webSockets.add(peer.socket);
|
|
7124
|
-
}
|
|
7125
|
-
return Array.from(webSockets);
|
|
7126
|
-
},
|
|
7127
|
-
getAllPeers: function (sock) {
|
|
7128
|
-
const peers = new Set();
|
|
7129
|
-
if (sock.server) {
|
|
7130
|
-
sock.pending
|
|
7131
|
-
.filter((pending) => pending.peers)
|
|
7132
|
-
.forEach((pending) => {
|
|
7133
|
-
for (const peer of Object.values(pending.peers)) {
|
|
7134
|
-
peers.add(peer);
|
|
7135
|
-
}
|
|
7136
|
-
});
|
|
7503
|
+
HEAP32[(ai + 16) >> 2] = 16;
|
|
7137
7504
|
}
|
|
7138
|
-
|
|
7139
|
-
|
|
7140
|
-
|
|
7505
|
+
HEAP32[(ai + 28) >> 2] = 0;
|
|
7506
|
+
return ai;
|
|
7507
|
+
}
|
|
7508
|
+
if (hint) {
|
|
7509
|
+
flags = HEAP32[hint >> 2];
|
|
7510
|
+
family = HEAP32[(hint + 4) >> 2];
|
|
7511
|
+
type = HEAP32[(hint + 8) >> 2];
|
|
7512
|
+
proto = HEAP32[(hint + 12) >> 2];
|
|
7513
|
+
}
|
|
7514
|
+
if (type && !proto) {
|
|
7515
|
+
proto = type === 2 ? 17 : 6;
|
|
7516
|
+
}
|
|
7517
|
+
if (!type && proto) {
|
|
7518
|
+
type = proto === 17 ? 2 : 1;
|
|
7519
|
+
}
|
|
7520
|
+
// If type or proto are set to zero in hints we should really be returning multiple addrinfo values, but for
|
|
7521
|
+
// now default to a TCP STREAM socket so we can at least return a sensible addrinfo given NULL hints.
|
|
7522
|
+
if (proto === 0) {
|
|
7523
|
+
proto = 6;
|
|
7524
|
+
}
|
|
7525
|
+
if (type === 0) {
|
|
7526
|
+
type = 1;
|
|
7527
|
+
}
|
|
7528
|
+
if (!node && !service) {
|
|
7529
|
+
return -2;
|
|
7530
|
+
}
|
|
7531
|
+
if (flags & ~(1 | 2 | 4 | 1024 | 8 | 16 | 32)) {
|
|
7532
|
+
return -1;
|
|
7533
|
+
}
|
|
7534
|
+
if (hint !== 0 && HEAP32[hint >> 2] & 2 && !node) {
|
|
7535
|
+
return -1;
|
|
7536
|
+
}
|
|
7537
|
+
if (flags & 32) {
|
|
7538
|
+
// TODO
|
|
7539
|
+
return -2;
|
|
7540
|
+
}
|
|
7541
|
+
if (type !== 0 && type !== 1 && type !== 2) {
|
|
7542
|
+
return -7;
|
|
7543
|
+
}
|
|
7544
|
+
if (family !== 0 && family !== 2 && family !== 10) {
|
|
7545
|
+
return -6;
|
|
7546
|
+
}
|
|
7547
|
+
if (service) {
|
|
7548
|
+
service = UTF8ToString(service);
|
|
7549
|
+
port = parseInt(service, 10);
|
|
7550
|
+
if (isNaN(port)) {
|
|
7551
|
+
if (flags & 1024) {
|
|
7552
|
+
return -2;
|
|
7141
7553
|
}
|
|
7554
|
+
// TODO support resolving well-known service names from:
|
|
7555
|
+
// http://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.txt
|
|
7556
|
+
return -8;
|
|
7142
7557
|
}
|
|
7143
|
-
|
|
7144
|
-
|
|
7145
|
-
|
|
7146
|
-
|
|
7147
|
-
|
|
7148
|
-
|
|
7149
|
-
|
|
7150
|
-
|
|
7558
|
+
}
|
|
7559
|
+
if (!node) {
|
|
7560
|
+
if (family === 0) {
|
|
7561
|
+
family = 2;
|
|
7562
|
+
}
|
|
7563
|
+
if ((flags & 1) === 0) {
|
|
7564
|
+
if (family === 2) {
|
|
7565
|
+
addr = _htonl(2130706433);
|
|
7566
|
+
} else {
|
|
7567
|
+
addr = [0, 0, 0, _htonl(1)];
|
|
7568
|
+
}
|
|
7151
7569
|
}
|
|
7152
|
-
|
|
7153
|
-
|
|
7154
|
-
|
|
7155
|
-
|
|
7156
|
-
|
|
7570
|
+
ai = allocaddrinfo(family, type, proto, null, addr, port);
|
|
7571
|
+
HEAPU32[out >> 2] = ai;
|
|
7572
|
+
return 0;
|
|
7573
|
+
}
|
|
7574
|
+
// try as a numeric address
|
|
7575
|
+
node = UTF8ToString(node);
|
|
7576
|
+
addr = inetPton4(node);
|
|
7577
|
+
if (addr !== null) {
|
|
7578
|
+
// incoming node is a valid ipv4 address
|
|
7579
|
+
if (family === 0 || family === 2) {
|
|
7580
|
+
family = 2;
|
|
7581
|
+
} else if (family === 10 && flags & 8) {
|
|
7582
|
+
addr = [0, 0, _htonl(65535), addr];
|
|
7583
|
+
family = 10;
|
|
7584
|
+
} else {
|
|
7585
|
+
return -2;
|
|
7157
7586
|
}
|
|
7158
|
-
|
|
7159
|
-
|
|
7160
|
-
|
|
7161
|
-
|
|
7162
|
-
|
|
7587
|
+
} else {
|
|
7588
|
+
addr = inetPton6(node);
|
|
7589
|
+
if (addr !== null) {
|
|
7590
|
+
// incoming node is a valid ipv6 address
|
|
7591
|
+
if (family === 0 || family === 10) {
|
|
7592
|
+
family = 10;
|
|
7593
|
+
} else {
|
|
7594
|
+
return -2;
|
|
7595
|
+
}
|
|
7163
7596
|
}
|
|
7164
|
-
|
|
7165
|
-
|
|
7166
|
-
|
|
7167
|
-
|
|
7168
|
-
|
|
7169
|
-
|
|
7170
|
-
|
|
7171
|
-
|
|
7172
|
-
|
|
7173
|
-
|
|
7174
|
-
|
|
7175
|
-
|
|
7176
|
-
|
|
7177
|
-
|
|
7178
|
-
|
|
7179
|
-
|
|
7180
|
-
|
|
7181
|
-
|
|
7182
|
-
|
|
7183
|
-
|
|
7184
|
-
|
|
7185
|
-
|
|
7186
|
-
|
|
7187
|
-
|
|
7188
|
-
|
|
7189
|
-
|
|
7190
|
-
|
|
7191
|
-
|
|
7192
|
-
|
|
7193
|
-
|
|
7194
|
-
|
|
7195
|
-
|
|
7196
|
-
|
|
7197
|
-
|
|
7198
|
-
|
|
7199
|
-
|
|
7597
|
+
}
|
|
7598
|
+
if (addr != null) {
|
|
7599
|
+
ai = allocaddrinfo(family, type, proto, node, addr, port);
|
|
7600
|
+
HEAPU32[out >> 2] = ai;
|
|
7601
|
+
return 0;
|
|
7602
|
+
}
|
|
7603
|
+
if (flags & 4) {
|
|
7604
|
+
return -2;
|
|
7605
|
+
}
|
|
7606
|
+
// try as a hostname
|
|
7607
|
+
// resolve the hostname to a temporary fake address
|
|
7608
|
+
node = DNS.lookup_name(node);
|
|
7609
|
+
addr = inetPton4(node);
|
|
7610
|
+
if (family === 0) {
|
|
7611
|
+
family = 2;
|
|
7612
|
+
} else if (family === 10) {
|
|
7613
|
+
addr = [0, 0, _htonl(65535), addr];
|
|
7614
|
+
}
|
|
7615
|
+
ai = allocaddrinfo(family, type, proto, null, addr, port);
|
|
7616
|
+
HEAPU32[out >> 2] = ai;
|
|
7617
|
+
return 0;
|
|
7618
|
+
};
|
|
7619
|
+
|
|
7620
|
+
var _getnameinfo = (sa, salen, node, nodelen, serv, servlen, flags) => {
|
|
7621
|
+
var info = readSockaddr(sa, salen);
|
|
7622
|
+
if (info.errno) {
|
|
7623
|
+
return -6;
|
|
7624
|
+
}
|
|
7625
|
+
var port = info.port;
|
|
7626
|
+
var addr = info.addr;
|
|
7627
|
+
var overflowed = false;
|
|
7628
|
+
if (node && nodelen) {
|
|
7629
|
+
var lookup;
|
|
7630
|
+
if (flags & 1 || !(lookup = DNS.lookup_addr(addr))) {
|
|
7631
|
+
if (flags & 8) {
|
|
7632
|
+
return -2;
|
|
7633
|
+
}
|
|
7634
|
+
} else {
|
|
7635
|
+
addr = lookup;
|
|
7200
7636
|
}
|
|
7201
|
-
|
|
7202
|
-
|
|
7203
|
-
|
|
7204
|
-
shell: true,
|
|
7205
|
-
stdio: ['pipe', 'pipe', 'pipe'],
|
|
7206
|
-
timeout: 100,
|
|
7207
|
-
});
|
|
7637
|
+
var numBytesWrittenExclNull = stringToUTF8(addr, node, nodelen);
|
|
7638
|
+
if (numBytesWrittenExclNull + 1 >= nodelen) {
|
|
7639
|
+
overflowed = true;
|
|
7208
7640
|
}
|
|
7209
|
-
|
|
7210
|
-
|
|
7211
|
-
|
|
7212
|
-
|
|
7213
|
-
)
|
|
7214
|
-
|
|
7215
|
-
throw e;
|
|
7216
|
-
},
|
|
7217
|
-
shutdownSocket: function (socketd, how) {
|
|
7218
|
-
// This implementation only supports websockets at the moment
|
|
7219
|
-
const sock = getSocketFromFD(socketd);
|
|
7220
|
-
const peer = Object.values(sock.peers)[0];
|
|
7221
|
-
if (!peer) {
|
|
7222
|
-
return -1;
|
|
7641
|
+
}
|
|
7642
|
+
if (serv && servlen) {
|
|
7643
|
+
port = '' + port;
|
|
7644
|
+
var numBytesWrittenExclNull = stringToUTF8(port, serv, servlen);
|
|
7645
|
+
if (numBytesWrittenExclNull + 1 >= servlen) {
|
|
7646
|
+
overflowed = true;
|
|
7223
7647
|
}
|
|
7224
|
-
|
|
7225
|
-
|
|
7226
|
-
|
|
7227
|
-
|
|
7228
|
-
|
|
7229
|
-
|
|
7230
|
-
|
|
7648
|
+
}
|
|
7649
|
+
if (overflowed) {
|
|
7650
|
+
// Note: even when we overflow, getnameinfo() is specced to write out the truncated results.
|
|
7651
|
+
return -12;
|
|
7652
|
+
}
|
|
7653
|
+
return 0;
|
|
7654
|
+
};
|
|
7655
|
+
|
|
7656
|
+
var Protocols = {
|
|
7657
|
+
list: [],
|
|
7658
|
+
map: {},
|
|
7659
|
+
};
|
|
7660
|
+
|
|
7661
|
+
var _setprotoent = (stayopen) => {
|
|
7662
|
+
// void setprotoent(int stayopen);
|
|
7663
|
+
// Allocate and populate a protoent structure given a name, protocol number and array of aliases
|
|
7664
|
+
function allocprotoent(name, proto, aliases) {
|
|
7665
|
+
// write name into buffer
|
|
7666
|
+
var nameBuf = _malloc(name.length + 1);
|
|
7667
|
+
stringToAscii(name, nameBuf);
|
|
7668
|
+
// write aliases into buffer
|
|
7669
|
+
var j = 0;
|
|
7670
|
+
var length = aliases.length;
|
|
7671
|
+
var aliasListBuf = _malloc((length + 1) * 4);
|
|
7672
|
+
// Use length + 1 so we have space for the terminating NULL ptr.
|
|
7673
|
+
for (var i = 0; i < length; i++, j += 4) {
|
|
7674
|
+
var alias = aliases[i];
|
|
7675
|
+
var aliasBuf = _malloc(alias.length + 1);
|
|
7676
|
+
stringToAscii(alias, aliasBuf);
|
|
7677
|
+
HEAPU32[(aliasListBuf + j) >> 2] = aliasBuf;
|
|
7231
7678
|
}
|
|
7232
|
-
|
|
7679
|
+
HEAPU32[(aliasListBuf + j) >> 2] = 0;
|
|
7680
|
+
// Terminating NULL pointer.
|
|
7681
|
+
// generate protoent
|
|
7682
|
+
var pe = _malloc(12);
|
|
7683
|
+
HEAPU32[pe >> 2] = nameBuf;
|
|
7684
|
+
HEAPU32[(pe + 4) >> 2] = aliasListBuf;
|
|
7685
|
+
HEAP32[(pe + 8) >> 2] = proto;
|
|
7686
|
+
return pe;
|
|
7687
|
+
}
|
|
7688
|
+
// Populate the protocol 'database'. The entries are limited to tcp and udp, though it is fairly trivial
|
|
7689
|
+
// to add extra entries from /etc/protocols if desired - though not sure if that'd actually be useful.
|
|
7690
|
+
var list = Protocols.list;
|
|
7691
|
+
var map = Protocols.map;
|
|
7692
|
+
if (list.length === 0) {
|
|
7693
|
+
var entry = allocprotoent('tcp', 6, ['TCP']);
|
|
7694
|
+
list.push(entry);
|
|
7695
|
+
map['tcp'] = map['6'] = entry;
|
|
7696
|
+
entry = allocprotoent('udp', 17, ['UDP']);
|
|
7697
|
+
list.push(entry);
|
|
7698
|
+
map['udp'] = map['17'] = entry;
|
|
7699
|
+
}
|
|
7700
|
+
_setprotoent.index = 0;
|
|
7701
|
+
};
|
|
7702
|
+
|
|
7703
|
+
var _getprotobyname = (name) => {
|
|
7704
|
+
// struct protoent *getprotobyname(const char *);
|
|
7705
|
+
name = UTF8ToString(name);
|
|
7706
|
+
_setprotoent(true);
|
|
7707
|
+
var result = Protocols.map[name];
|
|
7708
|
+
return result;
|
|
7709
|
+
};
|
|
7710
|
+
|
|
7711
|
+
var _getprotobynumber = (number) => {
|
|
7712
|
+
// struct protoent *getprotobynumber(int proto);
|
|
7713
|
+
_setprotoent(true);
|
|
7714
|
+
var result = Protocols.map[number];
|
|
7715
|
+
return result;
|
|
7233
7716
|
};
|
|
7234
7717
|
|
|
7235
7718
|
function _js_create_input_device(deviceId) {
|
|
@@ -7267,6 +7750,98 @@ export function init(RuntimeName, PHPLoader) {
|
|
|
7267
7750
|
return allocateUTF8OnStack(devicePath);
|
|
7268
7751
|
}
|
|
7269
7752
|
|
|
7753
|
+
async function _js_flock(fd, op) {
|
|
7754
|
+
_js_wasm_trace('js_flock(%d, %d)', fd, op);
|
|
7755
|
+
// Emscripten does not expose these constants to JS, so we hardcode them here.
|
|
7756
|
+
// Based on
|
|
7757
|
+
// https://github.com/emscripten-core/emscripten/blob/76860cc47cef67f5712a7a03a247bc1baabf7ba4/system/lib/libc/musl/include/sys/file.h#L7-L10
|
|
7758
|
+
const emscripten_LOCK_SH = 1;
|
|
7759
|
+
const emscripten_LOCK_EX = 2;
|
|
7760
|
+
const emscripten_LOCK_NB = 4;
|
|
7761
|
+
const emscripten_LOCK_UN = 8;
|
|
7762
|
+
const flockToLockOpType = {
|
|
7763
|
+
[emscripten_LOCK_SH]: 'shared',
|
|
7764
|
+
[emscripten_LOCK_EX]: 'exclusive',
|
|
7765
|
+
[emscripten_LOCK_UN]: 'unlocked',
|
|
7766
|
+
};
|
|
7767
|
+
let vfsPath;
|
|
7768
|
+
let errno;
|
|
7769
|
+
[vfsPath, errno] = locking.get_vfs_path_from_fd(fd);
|
|
7770
|
+
if (errno !== 0) {
|
|
7771
|
+
_js_wasm_trace(
|
|
7772
|
+
'js_flock(%d, %d) get_vfs_path_from_fd errno %d',
|
|
7773
|
+
fd,
|
|
7774
|
+
op,
|
|
7775
|
+
vfsPath,
|
|
7776
|
+
errno
|
|
7777
|
+
);
|
|
7778
|
+
return -errno;
|
|
7779
|
+
}
|
|
7780
|
+
if (!locking.is_path_to_shared_fs(vfsPath)) {
|
|
7781
|
+
_js_wasm_trace(
|
|
7782
|
+
'flock(%d, %d) locking is not implemented for non-NodeFS path %s',
|
|
7783
|
+
fd,
|
|
7784
|
+
op,
|
|
7785
|
+
vfsPath
|
|
7786
|
+
);
|
|
7787
|
+
// If not a NodeFS path, we can't lock it.
|
|
7788
|
+
// Default to succeeding as Emscripten does.
|
|
7789
|
+
return 0;
|
|
7790
|
+
}
|
|
7791
|
+
errno = locking.check_lock_params(fd, op);
|
|
7792
|
+
if (errno !== 0) {
|
|
7793
|
+
_js_wasm_trace(
|
|
7794
|
+
'js_flock(%d, %d) check_lock_params errno %d',
|
|
7795
|
+
fd,
|
|
7796
|
+
op,
|
|
7797
|
+
errno
|
|
7798
|
+
);
|
|
7799
|
+
return -errno;
|
|
7800
|
+
}
|
|
7801
|
+
// @TODO: Consider supporting blocking mode of flock()
|
|
7802
|
+
if (op & (emscripten_LOCK_NB === 0)) {
|
|
7803
|
+
_js_wasm_trace(
|
|
7804
|
+
'js_flock(%d, %d) blocking mode of flock() is not implemented',
|
|
7805
|
+
fd,
|
|
7806
|
+
op
|
|
7807
|
+
);
|
|
7808
|
+
// We do not yet support the blocking form of flock().
|
|
7809
|
+
// We respond with EINVAL to indicate failure
|
|
7810
|
+
// because it is a known errno for a failed blocking flock().
|
|
7811
|
+
return -ERRNO_CODES.EINVAL;
|
|
7812
|
+
}
|
|
7813
|
+
const maskedOp =
|
|
7814
|
+
op & (emscripten_LOCK_SH | emscripten_LOCK_EX | emscripten_LOCK_UN);
|
|
7815
|
+
const lockOpType = flockToLockOpType[maskedOp];
|
|
7816
|
+
if (lockOpType === undefined) {
|
|
7817
|
+
_js_wasm_trace(
|
|
7818
|
+
'js_flock(%d, %d) invalid flock() operation',
|
|
7819
|
+
fd,
|
|
7820
|
+
op
|
|
7821
|
+
);
|
|
7822
|
+
return -ERRNO_CODES.EINVAL;
|
|
7823
|
+
}
|
|
7824
|
+
const nativeFilePath = locking.get_native_path_from_vfs_path(vfsPath);
|
|
7825
|
+
const obtainedLock = await PHPLoader.fileLockManager.lockWholeFile(
|
|
7826
|
+
nativeFilePath,
|
|
7827
|
+
{
|
|
7828
|
+
type: lockOpType,
|
|
7829
|
+
pid: PHPLoader.processId,
|
|
7830
|
+
fd,
|
|
7831
|
+
}
|
|
7832
|
+
);
|
|
7833
|
+
_js_wasm_trace(
|
|
7834
|
+
'js_flock(%d, %d) lockWholeFile %s returned %d',
|
|
7835
|
+
fd,
|
|
7836
|
+
op,
|
|
7837
|
+
vfsPath,
|
|
7838
|
+
obtainedLock
|
|
7839
|
+
);
|
|
7840
|
+
return obtainedLock ? 0 : -ERRNO_CODES.EWOULDBLOCK;
|
|
7841
|
+
}
|
|
7842
|
+
|
|
7843
|
+
_js_flock.isAsync = true;
|
|
7844
|
+
|
|
7270
7845
|
function _js_open_process(
|
|
7271
7846
|
command,
|
|
7272
7847
|
argsPtr,
|
|
@@ -7539,6 +8114,21 @@ export function init(RuntimeName, PHPLoader) {
|
|
|
7539
8114
|
return 0;
|
|
7540
8115
|
}
|
|
7541
8116
|
|
|
8117
|
+
var _js_release_file_locks = async function js_release_file_locks() {
|
|
8118
|
+
_js_wasm_trace('js_release_file_locks()');
|
|
8119
|
+
const pid = PHPLoader.processId;
|
|
8120
|
+
return await PHPLoader.fileLockManager
|
|
8121
|
+
.releaseLocksForProcess(pid)
|
|
8122
|
+
.then(() => {
|
|
8123
|
+
_js_wasm_trace('js_release_file_locks succeeded');
|
|
8124
|
+
})
|
|
8125
|
+
.catch((e) => {
|
|
8126
|
+
_js_wasm_trace('js_release_file_locks error %s', e);
|
|
8127
|
+
});
|
|
8128
|
+
};
|
|
8129
|
+
|
|
8130
|
+
_js_release_file_locks.isAsync = true;
|
|
8131
|
+
|
|
7542
8132
|
function _js_waitpid(pid, exitCodePtr) {
|
|
7543
8133
|
if (!PHPWASM.child_proc_by_pid[pid]) {
|
|
7544
8134
|
return -1;
|
|
@@ -8465,9 +9055,13 @@ export function init(RuntimeName, PHPLoader) {
|
|
|
8465
9055
|
/** @export */ getprotobyname: _getprotobyname,
|
|
8466
9056
|
/** @export */ getprotobynumber: _getprotobynumber,
|
|
8467
9057
|
/** @export */ js_create_input_device: _js_create_input_device,
|
|
9058
|
+
/** @export */ js_flock: _js_flock,
|
|
9059
|
+
/** @export */ js_getpid: _js_getpid,
|
|
8468
9060
|
/** @export */ js_open_process: _js_open_process,
|
|
8469
9061
|
/** @export */ js_process_status: _js_process_status,
|
|
9062
|
+
/** @export */ js_release_file_locks: _js_release_file_locks,
|
|
8470
9063
|
/** @export */ js_waitpid: _js_waitpid,
|
|
9064
|
+
/** @export */ js_wasm_trace: _js_wasm_trace,
|
|
8471
9065
|
/** @export */ proc_exit: _proc_exit,
|
|
8472
9066
|
/** @export */ strptime: _strptime,
|
|
8473
9067
|
/** @export */ wasm_close: _wasm_close,
|
|
@@ -8493,6 +9087,12 @@ export function init(RuntimeName, PHPLoader) {
|
|
|
8493
9087
|
|
|
8494
9088
|
var _fflush = (a0) => (_fflush = wasmExports['fflush'])(a0);
|
|
8495
9089
|
|
|
9090
|
+
var _flock = (Module['_flock'] = (a0, a1) =>
|
|
9091
|
+
(_flock = Module['_flock'] = wasmExports['flock'])(a0, a1));
|
|
9092
|
+
|
|
9093
|
+
var _getpid = (Module['_getpid'] = () =>
|
|
9094
|
+
(_getpid = Module['_getpid'] = wasmExports['getpid'])());
|
|
9095
|
+
|
|
8496
9096
|
var _wasm_popen = (Module['_wasm_popen'] = (a0, a1) =>
|
|
8497
9097
|
(_wasm_popen = Module['_wasm_popen'] = wasmExports['wasm_popen'])(
|
|
8498
9098
|
a0,
|
|
@@ -8607,6 +9207,16 @@ export function init(RuntimeName, PHPLoader) {
|
|
|
8607
9207
|
var _wasm_free = (Module['_wasm_free'] = (a0) =>
|
|
8608
9208
|
(_wasm_free = Module['_wasm_free'] = wasmExports['wasm_free'])(a0));
|
|
8609
9209
|
|
|
9210
|
+
var _wasm_get_end_offset = (Module['_wasm_get_end_offset'] = (a0) =>
|
|
9211
|
+
(_wasm_get_end_offset = Module['_wasm_get_end_offset'] =
|
|
9212
|
+
wasmExports['wasm_get_end_offset'])(a0));
|
|
9213
|
+
|
|
9214
|
+
var _wasm_trace = (Module['_wasm_trace'] = (a0, a1) =>
|
|
9215
|
+
(_wasm_trace = Module['_wasm_trace'] = wasmExports['wasm_trace'])(
|
|
9216
|
+
a0,
|
|
9217
|
+
a1
|
|
9218
|
+
));
|
|
9219
|
+
|
|
8610
9220
|
var ___funcs_on_exit = () =>
|
|
8611
9221
|
(___funcs_on_exit = wasmExports['__funcs_on_exit'])();
|
|
8612
9222
|
|
|
@@ -8754,6 +9364,32 @@ export function init(RuntimeName, PHPLoader) {
|
|
|
8754
9364
|
PHPLoader['free'] =
|
|
8755
9365
|
typeof _free === 'function' ? _free : PHPLoader['_wasm_free'];
|
|
8756
9366
|
|
|
9367
|
+
if (typeof NODEFS === 'object') {
|
|
9368
|
+
// We override NODEFS.createNode() to add an `isSharedFS` flag to all NODEFS
|
|
9369
|
+
// nodes. This way we can tell whether file-locking is needed and possible
|
|
9370
|
+
// for an FS node, even if wrapped with PROXYFS.
|
|
9371
|
+
const originalCreateNode = NODEFS.createNode;
|
|
9372
|
+
NODEFS.createNode = function createNodeWithSharedFlag() {
|
|
9373
|
+
const node = originalCreateNode.apply(NODEFS, arguments);
|
|
9374
|
+
node.isSharedFS = true;
|
|
9375
|
+
return node;
|
|
9376
|
+
};
|
|
9377
|
+
|
|
9378
|
+
var originalHashAddNode = FS.hashAddNode;
|
|
9379
|
+
FS.hashAddNode = function hashAddNodeIfNotSharedFS(node) {
|
|
9380
|
+
if (
|
|
9381
|
+
typeof locking === 'object' &&
|
|
9382
|
+
locking?.is_shared_fs_node(node)
|
|
9383
|
+
) {
|
|
9384
|
+
// Avoid caching shared VFS nodes so multiple instances
|
|
9385
|
+
// can access the same underlying filesystem without
|
|
9386
|
+
// conflicting caches.
|
|
9387
|
+
return;
|
|
9388
|
+
}
|
|
9389
|
+
return originalHashAddNode.apply(FS, arguments);
|
|
9390
|
+
};
|
|
9391
|
+
}
|
|
9392
|
+
|
|
8757
9393
|
return PHPLoader;
|
|
8758
9394
|
|
|
8759
9395
|
// Close the opening bracket from esm-prefix.js:
|