@ai-ecoverse/wasm-zip 3.0.0-1 → 3.0.0-2

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/LICENSE CHANGED
@@ -1,3 +1,5 @@
1
+ ==> LICENSE <==
2
+
1
3
  This is version 2007-Mar-4 of the Info-ZIP license.
2
4
  The definitive version of this document should be available at
3
5
  ftp://ftp.info-zip.org/pub/infozip/license.html indefinitely and
@@ -23,6 +25,69 @@ or implied. In no event shall Info-ZIP or its contributors be held liable
23
25
  for any direct, indirect, incidental, special or consequential damages
24
26
  arising out of the use of or inability to use this software.
25
27
 
28
+ Permission is granted to anyone to use this software for any purpose,
29
+ including commercial applications, and to alter it and redistribute it
30
+ freely, subject to the above disclaimer and the following restrictions:
31
+
32
+ 1. Redistributions of source code (in whole or in part) must retain
33
+ the above copyright notice, definition, disclaimer, and this list
34
+ of conditions.
35
+
36
+ 2. Redistributions in binary form (compiled executables and libraries)
37
+ must reproduce the above copyright notice, definition, disclaimer,
38
+ and this list of conditions in documentation and/or other materials
39
+ provided with the distribution. The sole exception to this condition
40
+ is redistribution of a standard UnZipSFX binary (including SFXWiz) as
41
+ part of a self-extracting archive; that is permitted without inclusion
42
+ of this license, as long as the normal SFX banner has not been removed
43
+ from the binary or disabled.
44
+
45
+ 3. Altered versions--including, but not limited to, ports to new operating
46
+ systems, existing ports with new graphical interfaces, versions with
47
+ modified or added functionality, and dynamic, shared, or static library
48
+ versions not from Info-ZIP--must be plainly marked as such and must not
49
+ be misrepresented as being the original source or, if binaries,
50
+ compiled from the original source. Such altered versions also must not
51
+ be misrepresented as being Info-ZIP releases--including, but not
52
+ limited to, labeling of the altered versions with the names "Info-ZIP"
53
+ (or any variation thereof, including, but not limited to, different
54
+ capitalizations), "Pocket UnZip," "WiZ" or "MacZip" without the
55
+ explicit permission of Info-ZIP. Such altered versions are further
56
+ prohibited from misrepresentative use of the Zip-Bugs or Info-ZIP
57
+ e-mail addresses or the Info-ZIP URL(s), such as to imply Info-ZIP
58
+ will provide support for the altered versions.
59
+
60
+ 4. Info-ZIP retains the right to use the names "Info-ZIP," "Zip," "UnZip,"
61
+ "UnZipSFX," "WiZ," "Pocket UnZip," "Pocket Zip," and "MacZip" for its
62
+ own source and binary releases.
63
+
64
+ ==> LICENSE <==
65
+
66
+ This is version 2009-Jan-02 of the Info-ZIP license.
67
+ The definitive version of this document should be available at
68
+ ftp://ftp.info-zip.org/pub/infozip/license.html indefinitely and
69
+ a copy at http://www.info-zip.org/pub/infozip/license.html.
70
+
71
+
72
+ Copyright (c) 1990-2009 Info-ZIP. All rights reserved.
73
+
74
+ For the purposes of this copyright and license, "Info-ZIP" is defined as
75
+ the following set of individuals:
76
+
77
+ Mark Adler, John Bush, Karl Davis, Harald Denker, Jean-Michel Dubois,
78
+ Jean-loup Gailly, Hunter Goatley, Ed Gordon, Ian Gorman, Chris Herborth,
79
+ Dirk Haase, Greg Hartwig, Robert Heath, Jonathan Hudson, Paul Kienitz,
80
+ David Kirschbaum, Johnny Lee, Onno van der Linden, Igor Mandrichenko,
81
+ Steve P. Miller, Sergio Monesi, Keith Owens, George Petrov, Greg Roelofs,
82
+ Kai Uwe Rommel, Steve Salisbury, Dave Smith, Steven M. Schweda,
83
+ Christian Spieler, Cosmin Truta, Antoine Verheijen, Paul von Behren,
84
+ Rich Wales, Mike White.
85
+
86
+ This software is provided "as is," without warranty of any kind, express
87
+ or implied. In no event shall Info-ZIP or its contributors be held liable
88
+ for any direct, indirect, incidental, special or consequential damages
89
+ arising out of the use of or inability to use this software.
90
+
26
91
  Permission is granted to anyone to use this software for any purpose,
27
92
  including commercial applications, and to alter it and redistribute it
28
93
  freely, subject to the above disclaimer and the following restrictions:
@@ -36,8 +101,8 @@ freely, subject to the above disclaimer and the following restrictions:
36
101
  and this list of conditions in documentation and/or other materials
37
102
  provided with the distribution. Additional documentation is not needed
38
103
  for executables where a command line license option provides these and
39
- a note regarding this option is in the executable's startup banner.
40
- The sole exception to this condition is redistribution of a standard
104
+ a note regarding this option is in the executable's startup banner. The
105
+ sole exception to this condition is redistribution of a standard
41
106
  UnZipSFX binary (including SFXWiz) as part of a self-extracting archive;
42
107
  that is permitted without inclusion of this license, as long as the
43
108
  normal SFX banner has not been removed from the binary or disabled.
package/README.md CHANGED
@@ -4,7 +4,14 @@
4
4
  slicc's wasm realm.
5
5
 
6
6
  ```bash
7
- ipk add -g @ai-ecoverse/wasm-zip
7
+ pnpm add -g @ai-ecoverse/wasm-zip
8
8
  zip out.zip file.txt
9
9
  unzip -l out.zip
10
10
  ```
11
+
12
+ - `zip -T` runs `unzip` itself, without a shell. A `-TT` command is a shell
13
+ command, so it needs one (`@ai-ecoverse/wasm-bash`).
14
+ - Non-ASCII names are UTF-8. `zip` sets the UTF-8 flag on them, and `unzip`
15
+ shows them and reads Info-ZIP's Unicode path field.
16
+ - `zip - … > file` and `zip - … | …` write valid archives, and `zip -s 0`
17
+ merges split archives (`zip -s 1m`) back with every byte.
package/bin/unzip CHANGED
@@ -176,26 +176,7 @@ if (ENVIRONMENT_IS_WORKER) {
176
176
  }
177
177
 
178
178
  readAsync = async (url) => {
179
- // Fetch has some additional restrictions over XHR, like it can't be used on a file:// url.
180
- // See https://github.com/github/fetch/pull/92#issuecomment-140665932
181
- // Cordova or Electron apps are typically loaded from a file:// url.
182
- // So use XHR on webview if URL is a file URL.
183
- if (isFileURI(url)) {
184
- return new Promise((resolve, reject) => {
185
- var xhr = new XMLHttpRequest();
186
- xhr.open('GET', url, true);
187
- xhr.responseType = 'arraybuffer';
188
- xhr.onload = () => {
189
- if (xhr.status == 200 || (xhr.status == 0 && xhr.response)) { // file URLs can return 0
190
- resolve(xhr.response);
191
- return;
192
- }
193
- reject(xhr.status);
194
- };
195
- xhr.onerror = reject;
196
- xhr.send(null);
197
- });
198
- }
179
+ assert(!isFileURI(url), "readAsync does not work with file:// URLs");
199
180
  var response = await fetch(url, { credentials: 'same-origin' });
200
181
  if (response.ok) {
201
182
  return response.arrayBuffer();
@@ -483,6 +464,8 @@ var
483
464
 
484
465
  var runtimeInitialized = false;
485
466
 
467
+ var runtimeExited = false;
468
+
486
469
 
487
470
 
488
471
  function updateMemoryViews() {
@@ -541,6 +524,18 @@ function preMain() {
541
524
  // No ATMAINS hooks
542
525
  }
543
526
 
527
+ function exitRuntime() {
528
+ assert(!runtimeExited);
529
+ checkStackCookie();
530
+ // PThreads reuse the runtime from the main thread.
531
+ ___funcs_on_exit(); // Native atexit() functions
532
+ // Begin ATEXITS hooks
533
+ FS.quit();
534
+ TTY.shutdown();
535
+ // End ATEXITS hooks
536
+ runtimeExited = true;
537
+ }
538
+
544
539
  function postRun() {
545
540
  checkStackCookie();
546
541
  // PThreads reuse the runtime from the main thread.
@@ -594,6 +589,7 @@ function abort(what) {
594
589
  function createExportWrapper(name, nargs) {
595
590
  return (...args) => {
596
591
  assert(runtimeInitialized, `native function \`${name}\` called before runtime initialization`);
592
+ assert(!runtimeExited, `native function \`${name}\` called after runtime exit (use NO_EXIT_RUNTIME to keep it alive after main() exits)`);
597
593
  var f = wasmExports[name];
598
594
  assert(f, `exported native function \`${name}\` not found`);
599
595
  // Only assert for too many arguments. Too few can be valid since the missing arguments will be zero filled.
@@ -654,8 +650,6 @@ async function instantiateArrayBuffer(binaryFile, imports) {
654
650
 
655
651
  async function instantiateAsync(binary, binaryFile, imports) {
656
652
  if (!binary
657
- // Don't use streaming for file:// delivered objects in a webview, fetch them synchronously.
658
- && !isFileURI(binaryFile)
659
653
  // Avoid instantiateStreaming() on Node.js environment for now, as while
660
654
  // Node.js v18.1.0 implements it, it does not have a full fetch()
661
655
  // implementation yet.
@@ -860,7 +854,7 @@ async function createWasm() {
860
854
  }
861
855
  }
862
856
 
863
- var noExitRuntime = true;
857
+ var noExitRuntime = false;
864
858
 
865
859
  var ptrToString = (ptr) => {
866
860
  assert(typeof ptr === 'number', `ptrToString expects a number, got ${typeof ptr}`);
@@ -906,6 +900,21 @@ async function createWasm() {
906
900
 
907
901
 
908
902
 
903
+ var wasmTableMirror = [];
904
+
905
+
906
+ var getWasmTableEntry = (funcPtr) => {
907
+ var func = wasmTableMirror[funcPtr];
908
+ if (!func) {
909
+ /** @suppress {checkTypes} */
910
+ wasmTableMirror[funcPtr] = func = wasmTable.get(funcPtr);
911
+ }
912
+ /** @suppress {checkTypes} */
913
+ assert(wasmTable.get(funcPtr) == func, 'JavaScript-side Wasm function table mirror is out of date!');
914
+ return func;
915
+ };
916
+ var ___call_sighandler = (fp, sig) => getWasmTableEntry(fp)(sig);
917
+
909
918
  var PATH = {
910
919
  isAbs:(path) => path.charAt(0) === '/',
911
920
  splitPath:(filename) => {
@@ -1588,6 +1597,13 @@ async function createWasm() {
1588
1597
  write(stream, buffer, offset, length, position, canOwn) {
1589
1598
  // The data buffer should be a typed array view
1590
1599
  assert(!(buffer instanceof ArrayBuffer));
1600
+ // If the buffer is located in main memory (HEAP), and if
1601
+ // memory can grow, we can't hold on to references of the
1602
+ // memory buffer, as they may get invalidated. That means we
1603
+ // need to copy its contents.
1604
+ if (buffer.buffer === HEAP8.buffer) {
1605
+ canOwn = false;
1606
+ }
1591
1607
 
1592
1608
  if (!length) return 0;
1593
1609
  var node = stream.node;
@@ -4085,6 +4101,12 @@ async function createWasm() {
4085
4101
  var __abort_js = () =>
4086
4102
  abort('native code called abort()');
4087
4103
 
4104
+ var runtimeKeepaliveCounter = 0;
4105
+ var __emscripten_runtime_keepalive_clear = () => {
4106
+ noExitRuntime = false;
4107
+ runtimeKeepaliveCounter = 0;
4108
+ };
4109
+
4088
4110
  var INT53_MAX = 9007199254740992;
4089
4111
 
4090
4112
  var INT53_MIN = -9007199254740992;
@@ -4200,14 +4222,83 @@ async function createWasm() {
4200
4222
  }
4201
4223
  };
4202
4224
 
4203
- var abortOnCannotGrowMemory = (requestedSize) => {
4204
- abort(`Cannot enlarge memory arrays to size ${requestedSize} bytes (OOM). Either (1) compile with -sINITIAL_MEMORY=X with X higher than the current value ${HEAP8.length}, (2) compile with -sALLOW_MEMORY_GROWTH which allows increasing the size at runtime, or (3) if you want malloc to return NULL (0) instead of this abort, compile with -sABORTING_MALLOC=0`);
4225
+ var getHeapMax = () =>
4226
+ // Stay one Wasm page short of 4GB: while e.g. Chrome is able to allocate
4227
+ // full 4GB Wasm memories, the size will wrap back to 0 bytes in Wasm side
4228
+ // for any code that deals with heap sizes, which would require special
4229
+ // casing all heap size related code to treat 0 specially.
4230
+ 2147483648;
4231
+
4232
+ var alignMemory = (size, alignment) => {
4233
+ assert(alignment, "alignment argument is required");
4234
+ return Math.ceil(size / alignment) * alignment;
4235
+ };
4236
+
4237
+ var growMemory = (size) => {
4238
+ var oldHeapSize = wasmMemory.buffer.byteLength;
4239
+ var pages = ((size - oldHeapSize + 65535) / 65536) | 0;
4240
+ try {
4241
+ // round size grow request up to wasm page size (fixed 64KB per spec)
4242
+ wasmMemory.grow(pages); // .grow() takes a delta compared to the previous size
4243
+ updateMemoryViews();
4244
+ return 1 /*success*/;
4245
+ } catch(e) {
4246
+ err(`growMemory: Attempted to grow heap from ${oldHeapSize} bytes to ${size} bytes, but got error: ${e}`);
4247
+ }
4248
+ // implicit 0 return to save code size (caller will cast "undefined" into 0
4249
+ // anyhow)
4205
4250
  };
4206
4251
  var _emscripten_resize_heap = (requestedSize) => {
4207
4252
  var oldSize = HEAPU8.length;
4208
4253
  // With CAN_ADDRESS_2GB or MEMORY64, pointers are already unsigned.
4209
4254
  requestedSize >>>= 0;
4210
- abortOnCannotGrowMemory(requestedSize);
4255
+ // With multithreaded builds, races can happen (another thread might increase the size
4256
+ // in between), so return a failure, and let the caller retry.
4257
+ assert(requestedSize > oldSize);
4258
+
4259
+ // Memory resize rules:
4260
+ // 1. Always increase heap size to at least the requested size, rounded up
4261
+ // to next page multiple.
4262
+ // 2a. If MEMORY_GROWTH_LINEAR_STEP == -1, excessively resize the heap
4263
+ // geometrically: increase the heap size according to
4264
+ // MEMORY_GROWTH_GEOMETRIC_STEP factor (default +20%), At most
4265
+ // overreserve by MEMORY_GROWTH_GEOMETRIC_CAP bytes (default 96MB).
4266
+ // 2b. If MEMORY_GROWTH_LINEAR_STEP != -1, excessively resize the heap
4267
+ // linearly: increase the heap size by at least
4268
+ // MEMORY_GROWTH_LINEAR_STEP bytes.
4269
+ // 3. Max size for the heap is capped at 2048MB-WASM_PAGE_SIZE, or by
4270
+ // MAXIMUM_MEMORY, or by ASAN limit, depending on which is smallest
4271
+ // 4. If we were unable to allocate as much memory, it may be due to
4272
+ // over-eager decision to excessively reserve due to (3) above.
4273
+ // Hence if an allocation fails, cut down on the amount of excess
4274
+ // growth, in an attempt to succeed to perform a smaller allocation.
4275
+
4276
+ // A limit is set for how much we can grow. We should not exceed that
4277
+ // (the wasm binary specifies it, so if we tried, we'd fail anyhow).
4278
+ var maxHeapSize = getHeapMax();
4279
+ if (requestedSize > maxHeapSize) {
4280
+ err(`Cannot enlarge memory, requested ${requestedSize} bytes, but the limit is ${maxHeapSize} bytes!`);
4281
+ return false;
4282
+ }
4283
+
4284
+ // Loop through potential heap size increases. If we attempt a too eager
4285
+ // reservation that fails, cut down on the attempted size and reserve a
4286
+ // smaller bump instead. (max 3 times, chosen somewhat arbitrarily)
4287
+ for (var cutDown = 1; cutDown <= 4; cutDown *= 2) {
4288
+ var overGrownHeapSize = oldSize * (1 + 0.2 / cutDown); // ensure geometric growth
4289
+ // but limit overreserving (default to capping at +96MB overgrowth at most)
4290
+ overGrownHeapSize = Math.min(overGrownHeapSize, requestedSize + 100663296 );
4291
+
4292
+ var newSize = Math.min(maxHeapSize, alignMemory(Math.max(requestedSize, overGrownHeapSize), 65536));
4293
+
4294
+ var replacement = growMemory(newSize);
4295
+ if (replacement) {
4296
+
4297
+ return true;
4298
+ }
4299
+ }
4300
+ err(`Failed to grow the heap from ${oldSize} bytes to ${newSize} bytes, not enough memory!`);
4301
+ return false;
4211
4302
  };
4212
4303
 
4213
4304
  var ENV = {
@@ -4270,7 +4361,6 @@ async function createWasm() {
4270
4361
  };
4271
4362
 
4272
4363
 
4273
- var runtimeKeepaliveCounter = 0;
4274
4364
  var keepRuntimeAlive = () => noExitRuntime || runtimeKeepaliveCounter > 0;
4275
4365
  var _proc_exit = (code) => {
4276
4366
  EXITSTATUS = code;
@@ -4286,7 +4376,9 @@ async function createWasm() {
4286
4376
  var exitJS = (status, implicit) => {
4287
4377
  EXITSTATUS = status;
4288
4378
 
4289
- checkUnflushedContent();
4379
+ if (!keepRuntimeAlive()) {
4380
+ exitRuntime();
4381
+ }
4290
4382
 
4291
4383
  // if exit() was called explicitly, warn the user if the runtime isn't actually being shut down
4292
4384
  if (keepRuntimeAlive() && !implicit) {
@@ -4389,23 +4481,22 @@ async function createWasm() {
4389
4481
 
4390
4482
  /** @param {number=} offset */
4391
4483
  var doWritev = (stream, iov, iovcnt, offset) => {
4392
- var ret = 0;
4393
- for (var i = 0; i < iovcnt; i++) {
4394
- var ptr = HEAPU32[((iov)>>2)];
4395
- var len = HEAPU32[(((iov)+(4))>>2)];
4396
- iov += 8;
4397
- var curr = FS.write(stream, HEAP8, ptr, len, offset);
4398
- if (curr < 0) return -1;
4399
- ret += curr;
4400
- if (curr < len) {
4401
- // No more space to write.
4402
- break;
4403
- }
4404
- if (typeof offset != 'undefined') {
4405
- offset += curr;
4406
- }
4484
+ if (iovcnt == 1) {
4485
+ return FS.write(stream, HEAP8, HEAPU32[iov >> 2], HEAPU32[(iov + 4) >> 2], offset);
4407
4486
  }
4408
- return ret;
4487
+ var total = 0;
4488
+ for (var i = 0, p = iov; i < iovcnt; i++, p += 8) {
4489
+ total += HEAPU32[(p + 4) >> 2];
4490
+ }
4491
+ var view = new Uint8Array(total);
4492
+ var voff = 0;
4493
+ for (var i = 0; i < iovcnt; i++, iov += 8) {
4494
+ var ptr = HEAPU32[iov >> 2];
4495
+ var len = HEAPU32[(iov + 4) >> 2];
4496
+ view.set(HEAPU8.subarray(ptr, ptr + len), voff);
4497
+ voff += len;
4498
+ }
4499
+ return FS.write(stream, view, 0, total, offset);
4409
4500
  };
4410
4501
 
4411
4502
  function _fd_write(fd, iov, iovcnt, pnum) {
@@ -4422,6 +4513,7 @@ async function createWasm() {
4422
4513
  }
4423
4514
 
4424
4515
 
4516
+
4425
4517
  var handleException = (e) => {
4426
4518
  // Certain exception types we do not treat as errors since they are used for
4427
4519
  // internal control flow.
@@ -4434,7 +4526,7 @@ async function createWasm() {
4434
4526
  checkStackCookie();
4435
4527
  if (e instanceof WebAssembly.RuntimeError) {
4436
4528
  if (_emscripten_stack_get_current() <= 0) {
4437
- err('Stack overflow detected. You can try increasing -sSTACK_SIZE (currently set to 65536)');
4529
+ err('Stack overflow detected. You can try increasing -sSTACK_SIZE (currently set to 524288)');
4438
4530
  }
4439
4531
  }
4440
4532
  quit_(1, e);
@@ -4450,6 +4542,20 @@ async function createWasm() {
4450
4542
  return ret;
4451
4543
  };
4452
4544
 
4545
+
4546
+
4547
+ var FS_createPath = (...args) => FS.createPath(...args);
4548
+
4549
+
4550
+
4551
+ var FS_unlink = (...args) => FS.unlink(...args);
4552
+
4553
+ var FS_createLazyFile = (...args) => FS.createLazyFile(...args);
4554
+
4555
+ var FS_createDevice = (...args) => FS.createDevice(...args);
4556
+
4557
+
4558
+
4453
4559
  FS.createPreloadedFile = FS_createPreloadedFile;
4454
4560
  FS.preloadFile = FS_preloadFile;
4455
4561
  FS.staticInit();;
@@ -4500,6 +4606,16 @@ if (Module['wasmBinary']) wasmBinary = Module['wasmBinary'];
4500
4606
  }
4501
4607
 
4502
4608
  // Begin runtime exports
4609
+ Module['callMain'] = callMain;
4610
+ Module['addRunDependency'] = addRunDependency;
4611
+ Module['removeRunDependency'] = removeRunDependency;
4612
+ Module['FS_preloadFile'] = FS_preloadFile;
4613
+ Module['FS_unlink'] = FS_unlink;
4614
+ Module['FS_createPath'] = FS_createPath;
4615
+ Module['FS_createDevice'] = FS_createDevice;
4616
+ Module['FS'] = FS;
4617
+ Module['FS_createDataFile'] = FS_createDataFile;
4618
+ Module['FS_createLazyFile'] = FS_createLazyFile;
4503
4619
  var missingLibrarySymbols = [
4504
4620
  'writeI53ToI64',
4505
4621
  'writeI53ToI64Clamped',
@@ -4514,8 +4630,6 @@ if (Module['wasmBinary']) wasmBinary = Module['wasmBinary'];
4514
4630
  'setTempRet0',
4515
4631
  'createNamedFunction',
4516
4632
  'zeroMemory',
4517
- 'getHeapMax',
4518
- 'growMemory',
4519
4633
  'withStackSave',
4520
4634
  'inetPton4',
4521
4635
  'inetNtop4',
@@ -4533,7 +4647,6 @@ if (Module['wasmBinary']) wasmBinary = Module['wasmBinary'];
4533
4647
  'callUserCallback',
4534
4648
  'maybeExit',
4535
4649
  'asmjsMangle',
4536
- 'alignMemory',
4537
4650
  'HandleAllocator',
4538
4651
  'addOnInit',
4539
4652
  'addOnPostCtor',
@@ -4666,7 +4779,6 @@ missingLibrarySymbols.forEach(missingLibrarySymbol)
4666
4779
  'run',
4667
4780
  'out',
4668
4781
  'err',
4669
- 'callMain',
4670
4782
  'abort',
4671
4783
  'wasmExports',
4672
4784
  'HEAPF32',
@@ -4690,7 +4802,8 @@ missingLibrarySymbols.forEach(missingLibrarySymbol)
4690
4802
  'stackAlloc',
4691
4803
  'ptrToString',
4692
4804
  'exitJS',
4693
- 'abortOnCannotGrowMemory',
4805
+ 'getHeapMax',
4806
+ 'growMemory',
4694
4807
  'ENV',
4695
4808
  'ERRNO_CODES',
4696
4809
  'strError',
@@ -4704,13 +4817,12 @@ missingLibrarySymbols.forEach(missingLibrarySymbol)
4704
4817
  'handleException',
4705
4818
  'keepRuntimeAlive',
4706
4819
  'asyncLoad',
4820
+ 'alignMemory',
4707
4821
  'mmapAlloc',
4708
4822
  'wasmTable',
4709
4823
  'wasmMemory',
4710
4824
  'getUniqueRunDependency',
4711
4825
  'noExitRuntime',
4712
- 'addRunDependency',
4713
- 'removeRunDependency',
4714
4826
  'addOnPreRun',
4715
4827
  'addOnPostRun',
4716
4828
  'freeTableIndexes',
@@ -4764,16 +4876,11 @@ missingLibrarySymbols.forEach(missingLibrarySymbol)
4764
4876
  'SYSCALLS',
4765
4877
  'preloadPlugins',
4766
4878
  'FS_createPreloadedFile',
4767
- 'FS_preloadFile',
4768
4879
  'FS_modeStringToFlags',
4769
4880
  'FS_getMode',
4770
4881
  'FS_stdin_getChar_buffer',
4771
4882
  'FS_stdin_getChar',
4772
- 'FS_unlink',
4773
- 'FS_createPath',
4774
- 'FS_createDevice',
4775
4883
  'FS_readFile',
4776
- 'FS',
4777
4884
  'FS_root',
4778
4885
  'FS_mounts',
4779
4886
  'FS_devices',
@@ -4877,9 +4984,7 @@ missingLibrarySymbols.forEach(missingLibrarySymbol)
4877
4984
  'FS_findObject',
4878
4985
  'FS_analyzePath',
4879
4986
  'FS_createFile',
4880
- 'FS_createDataFile',
4881
4987
  'FS_forceLoadFile',
4882
- 'FS_createLazyFile',
4883
4988
  'FS_absolutePath',
4884
4989
  'FS_createFolder',
4885
4990
  'FS_createLink',
@@ -4916,11 +5021,25 @@ unexportedSymbols.forEach(unexportedRuntimeSymbol);
4916
5021
  function checkIncomingModuleAPI() {
4917
5022
  ignoredModuleProp('fetchSettings');
4918
5023
  }
5024
+ function slicc_sleep_ms(ms) { if (typeof SharedArrayBuffer === 'function' && typeof Atomics === 'object') { Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms); return; } const end = Date.now() + ms; while (Date.now() < end) {} }
5025
+ function slicc_default_getpid_js() { return (Module.sliccPid | 0) || 42; }
5026
+ function slicc_default_getppid_js() { return (Module.sliccPpid | 0) || 1; }
5027
+ function slicc_kill_js(pid,sig) { if (Module.sliccKernel && Module.sliccKernel.kill) return Module.sliccKernel.kill(pid, sig); return 1; }
5028
+ function slicc_pause_js() { if (Module.sliccKernel && Module.sliccKernel.pause) return Module.sliccKernel.pause(); return -52; }
5029
+ function slicc_cred_js(out) { const k = Module.sliccKernel; if (!k || !k.cred) return -52; const c = k.cred(); if (typeof c === 'number') return c; ['ruid', 'euid', 'suid', 'rgid', 'egid', 'sgid'].forEach((key, i) => { HEAPU32[(out >> 2) + i] = c[key] >>> 0; }); return 0; }
5030
+ function slicc_groups_js(list,cap) { const k = Module.sliccKernel; if (!k || !k.cred) return -52; const c = k.cred(); if (typeof c === 'number') return c; if (cap === 0) return c.groups.length; if (cap < c.groups.length) return -28; c.groups.forEach((g, i) => { HEAPU32[(list >> 2) + i] = g >>> 0; }); return c.groups.length; }
5031
+ function slicc_setcred_js(ruid,euid,suid,rgid,egid,sgid) { const k = Module.sliccKernel; if (!k || !k.setcred) return -52; const change = {}; const ids = { ruid, euid, suid, rgid, egid, sgid }; for (const key in ids) if (ids[key] !== -1) change[key] = ids[key] >>> 0; const r = k.setcred(change); return typeof r === 'number' ? r : 0; }
5032
+ function slicc_setgroups_js(list,n) { const k = Module.sliccKernel; if (!k || !k.setcred) return -52; const groups = []; for (let i = 0; i < n; i++) groups.push(HEAPU32[(list >> 2) + i]); const r = k.setcred({ groups }); return typeof r === 'number' ? r : 0; }
4919
5033
 
4920
5034
  // Imports from the Wasm binary.
4921
5035
  var _main = Module['_main'] = makeInvalidEarlyAccess('_main');
4922
5036
  var _strerror = makeInvalidEarlyAccess('_strerror');
4923
5037
  var _fflush = makeInvalidEarlyAccess('_fflush');
5038
+ var _slicc_sigpipe = Module['_slicc_sigpipe'] = makeInvalidEarlyAccess('_slicc_sigpipe');
5039
+ var _slicc_raise = Module['_slicc_raise'] = makeInvalidEarlyAccess('_slicc_raise');
5040
+ var _slicc_sig_mask = Module['_slicc_sig_mask'] = makeInvalidEarlyAccess('_slicc_sig_mask');
5041
+ var _slicc_cred_euid = Module['_slicc_cred_euid'] = makeInvalidEarlyAccess('_slicc_cred_euid');
5042
+ var ___funcs_on_exit = makeInvalidEarlyAccess('___funcs_on_exit');
4924
5043
  var _emscripten_stack_get_end = makeInvalidEarlyAccess('_emscripten_stack_get_end');
4925
5044
  var _emscripten_stack_get_base = makeInvalidEarlyAccess('_emscripten_stack_get_base');
4926
5045
  var _emscripten_stack_init = makeInvalidEarlyAccess('_emscripten_stack_init');
@@ -4931,11 +5050,17 @@ var _emscripten_stack_get_current = makeInvalidEarlyAccess('_emscripten_stack_ge
4931
5050
  var memory = makeInvalidEarlyAccess('memory');
4932
5051
  var __indirect_function_table = makeInvalidEarlyAccess('__indirect_function_table');
4933
5052
  var wasmMemory = makeInvalidEarlyAccess('wasmMemory');
5053
+ var wasmTable = makeInvalidEarlyAccess('wasmTable');
4934
5054
 
4935
5055
  function assignWasmExports(wasmExports) {
4936
5056
  assert(typeof wasmExports['__main_argc_argv'] != 'undefined', 'missing Wasm export: __main_argc_argv');
4937
5057
  assert(typeof wasmExports['strerror'] != 'undefined', 'missing Wasm export: strerror');
4938
5058
  assert(typeof wasmExports['fflush'] != 'undefined', 'missing Wasm export: fflush');
5059
+ assert(typeof wasmExports['slicc_sigpipe'] != 'undefined', 'missing Wasm export: slicc_sigpipe');
5060
+ assert(typeof wasmExports['slicc_raise'] != 'undefined', 'missing Wasm export: slicc_raise');
5061
+ assert(typeof wasmExports['slicc_sig_mask'] != 'undefined', 'missing Wasm export: slicc_sig_mask');
5062
+ assert(typeof wasmExports['slicc_cred_euid'] != 'undefined', 'missing Wasm export: slicc_cred_euid');
5063
+ assert(typeof wasmExports['__funcs_on_exit'] != 'undefined', 'missing Wasm export: __funcs_on_exit');
4939
5064
  assert(typeof wasmExports['emscripten_stack_get_end'] != 'undefined', 'missing Wasm export: emscripten_stack_get_end');
4940
5065
  assert(typeof wasmExports['emscripten_stack_get_base'] != 'undefined', 'missing Wasm export: emscripten_stack_get_base');
4941
5066
  assert(typeof wasmExports['emscripten_stack_init'] != 'undefined', 'missing Wasm export: emscripten_stack_init');
@@ -4948,6 +5073,11 @@ function assignWasmExports(wasmExports) {
4948
5073
  _main = Module['_main'] = createExportWrapper('__main_argc_argv', 2);
4949
5074
  _strerror = createExportWrapper('strerror', 1);
4950
5075
  _fflush = createExportWrapper('fflush', 1);
5076
+ _slicc_sigpipe = Module['_slicc_sigpipe'] = createExportWrapper('slicc_sigpipe', 0);
5077
+ _slicc_raise = Module['_slicc_raise'] = createExportWrapper('slicc_raise', 1);
5078
+ _slicc_sig_mask = Module['_slicc_sig_mask'] = createExportWrapper('slicc_sig_mask', 1);
5079
+ _slicc_cred_euid = Module['_slicc_cred_euid'] = createExportWrapper('slicc_cred_euid', 0);
5080
+ ___funcs_on_exit = createExportWrapper('__funcs_on_exit', 0);
4951
5081
  _emscripten_stack_get_end = wasmExports['emscripten_stack_get_end'];
4952
5082
  _emscripten_stack_get_base = wasmExports['emscripten_stack_get_base'];
4953
5083
  _emscripten_stack_init = wasmExports['emscripten_stack_init'];
@@ -4956,10 +5086,12 @@ function assignWasmExports(wasmExports) {
4956
5086
  __emscripten_stack_alloc = wasmExports['_emscripten_stack_alloc'];
4957
5087
  _emscripten_stack_get_current = wasmExports['emscripten_stack_get_current'];
4958
5088
  memory = wasmMemory = wasmExports['memory'];
4959
- __indirect_function_table = wasmExports['__indirect_function_table'];
5089
+ __indirect_function_table = wasmTable = wasmExports['__indirect_function_table'];
4960
5090
  }
4961
5091
 
4962
5092
  var wasmImports = {
5093
+ /** @export */
5094
+ __call_sighandler: ___call_sighandler,
4963
5095
  /** @export */
4964
5096
  __syscall_chmod: ___syscall_chmod,
4965
5097
  /** @export */
@@ -4997,6 +5129,8 @@ var wasmImports = {
4997
5129
  /** @export */
4998
5130
  _abort_js: __abort_js,
4999
5131
  /** @export */
5132
+ _emscripten_runtime_keepalive_clear: __emscripten_runtime_keepalive_clear,
5133
+ /** @export */
5000
5134
  _gmtime_js: __gmtime_js,
5001
5135
  /** @export */
5002
5136
  _localtime_js: __localtime_js,
@@ -5019,7 +5153,17 @@ var wasmImports = {
5019
5153
  /** @export */
5020
5154
  fd_seek: _fd_seek,
5021
5155
  /** @export */
5022
- fd_write: _fd_write
5156
+ fd_write: _fd_write,
5157
+ /** @export */
5158
+ proc_exit: _proc_exit,
5159
+ /** @export */
5160
+ slicc_cred_js,
5161
+ /** @export */
5162
+ slicc_default_getpid_js,
5163
+ /** @export */
5164
+ slicc_kill_js,
5165
+ /** @export */
5166
+ slicc_pause_js
5023
5167
  };
5024
5168
 
5025
5169
 
@@ -5099,7 +5243,7 @@ function run(args = arguments_) {
5099
5243
  Module['onRuntimeInitialized']?.();
5100
5244
  consumedModuleProp('onRuntimeInitialized');
5101
5245
 
5102
- var noInitialRun = Module['noInitialRun'] || false;
5246
+ var noInitialRun = Module['noInitialRun'] || true;
5103
5247
  if (!noInitialRun) callMain(args);
5104
5248
 
5105
5249
  postRun();
@@ -5118,45 +5262,6 @@ function run(args = arguments_) {
5118
5262
  checkStackCookie();
5119
5263
  }
5120
5264
 
5121
- function checkUnflushedContent() {
5122
- // Compiler settings do not allow exiting the runtime, so flushing
5123
- // the streams is not possible. but in ASSERTIONS mode we check
5124
- // if there was something to flush, and if so tell the user they
5125
- // should request that the runtime be exitable.
5126
- // Normally we would not even include flush() at all, but in ASSERTIONS
5127
- // builds we do so just for this check, and here we see if there is any
5128
- // content to flush, that is, we check if there would have been
5129
- // something a non-ASSERTIONS build would have not seen.
5130
- // How we flush the streams depends on whether we are in SYSCALLS_REQUIRE_FILESYSTEM=0
5131
- // mode (which has its own special function for this; otherwise, all
5132
- // the code is inside libc)
5133
- var oldOut = out;
5134
- var oldErr = err;
5135
- var has = false;
5136
- out = err = (x) => {
5137
- has = true;
5138
- }
5139
- try { // it doesn't matter if it fails
5140
- _fflush(0);
5141
- // also flush in the JS FS layer
5142
- for (var name of ['stdout', 'stderr']) {
5143
- var info = FS.analyzePath('/dev/' + name);
5144
- if (!info) return;
5145
- var stream = info.object;
5146
- var rdev = stream.rdev;
5147
- var tty = TTY.ttys[rdev];
5148
- if (tty?.output?.length) {
5149
- has = true;
5150
- }
5151
- }
5152
- } catch(e) {}
5153
- out = oldOut;
5154
- err = oldErr;
5155
- if (has) {
5156
- warnOnce('stdio streams had content in them that was not flushed. you should set EXIT_RUNTIME to 1 (see the Emscripten FAQ), or make sure to emit a newline when you printf etc.');
5157
- }
5158
- }
5159
-
5160
5265
  var wasmExports;
5161
5266
 
5162
5267
  // With async instantation wasmExports is assigned asynchronously when the
package/bin/unzip.wasm CHANGED
Binary file
package/bin/zip CHANGED
@@ -510,6 +510,7 @@ function initRuntime() {
510
510
  // Begin ATINITS hooks
511
511
  if (!Module['noFSInit'] && !FS.initialized) FS.init();
512
512
  TTY.init();
513
+ PIPEFS.root = FS.mount(PIPEFS, {}, null);
513
514
  // End ATINITS hooks
514
515
 
515
516
  wasmExports['__wasm_call_ctors']();
@@ -3941,6 +3942,256 @@ async function createWasm() {
3941
3942
  }
3942
3943
  }
3943
3944
 
3945
+ var PIPEFS = {
3946
+ BUCKET_BUFFER_SIZE:8192,
3947
+ mount(mount) {
3948
+ // Do not pollute the real root directory or its child nodes with pipes
3949
+ // Looks like it is OK to create another pseudo-root node not linked to the FS.root hierarchy this way
3950
+ return FS.createNode(null, '/', 16384 | 0o777, 0);
3951
+ },
3952
+ createPipe() {
3953
+ var pipe = {
3954
+ buckets: [],
3955
+ // refcnt 2 because pipe has a read end and a write end. We need to be
3956
+ // able to read from the read end after write end is closed.
3957
+ refcnt : 2,
3958
+ timestamp: new Date(),
3959
+ };
3960
+
3961
+ pipe.buckets.push({
3962
+ buffer: new Uint8Array(PIPEFS.BUCKET_BUFFER_SIZE),
3963
+ offset: 0,
3964
+ roffset: 0
3965
+ });
3966
+
3967
+ var rName = PIPEFS.nextname();
3968
+ var wName = PIPEFS.nextname();
3969
+ var rNode = FS.createNode(PIPEFS.root, rName, 4096, 0);
3970
+ var wNode = FS.createNode(PIPEFS.root, wName, 4096, 0);
3971
+
3972
+ rNode.pipe = pipe;
3973
+ wNode.pipe = pipe;
3974
+
3975
+ var readableStream = FS.createStream({
3976
+ path: rName,
3977
+ node: rNode,
3978
+ flags: 0,
3979
+ seekable: false,
3980
+ stream_ops: PIPEFS.stream_ops
3981
+ });
3982
+ rNode.stream = readableStream;
3983
+
3984
+ var writableStream = FS.createStream({
3985
+ path: wName,
3986
+ node: wNode,
3987
+ flags: 1,
3988
+ seekable: false,
3989
+ stream_ops: PIPEFS.stream_ops
3990
+ });
3991
+ wNode.stream = writableStream;
3992
+
3993
+ return {
3994
+ readable_fd: readableStream.fd,
3995
+ writable_fd: writableStream.fd
3996
+ };
3997
+ },
3998
+ stream_ops:{
3999
+ getattr(stream) {
4000
+ var node = stream.node;
4001
+ var timestamp = node.pipe.timestamp;
4002
+ return {
4003
+ dev: 14,
4004
+ ino: node.id,
4005
+ mode: 0o10600,
4006
+ nlink: 1,
4007
+ uid: 0,
4008
+ gid: 0,
4009
+ rdev: 0,
4010
+ size: 0,
4011
+ atime: timestamp,
4012
+ mtime: timestamp,
4013
+ ctime: timestamp,
4014
+ blksize: 4096,
4015
+ blocks: 0,
4016
+ };
4017
+ },
4018
+ poll(stream, timeout, notifyCallback) {
4019
+ var pipe = stream.node.pipe;
4020
+
4021
+ if ((stream.flags & 2097155) === 1) {
4022
+ return (256 | 4);
4023
+ }
4024
+ for (var bucket of pipe.buckets) {
4025
+ if (bucket.offset - bucket.roffset > 0) {
4026
+ return (64 | 1);
4027
+ }
4028
+ }
4029
+
4030
+ return 0;
4031
+ },
4032
+ dup(stream) {
4033
+ stream.node.pipe.refcnt++;
4034
+ },
4035
+ ioctl(stream, request, varargs) {
4036
+ return 28;
4037
+ },
4038
+ fsync(stream) {
4039
+ return 28;
4040
+ },
4041
+ read(stream, buffer, offset, length, position /* ignored */) {
4042
+ var pipe = stream.node.pipe;
4043
+ var currentLength = 0;
4044
+
4045
+ for (var bucket of pipe.buckets) {
4046
+ currentLength += bucket.offset - bucket.roffset;
4047
+ }
4048
+
4049
+ assert(buffer instanceof ArrayBuffer || ArrayBuffer.isView(buffer));
4050
+ var data = buffer.subarray(offset, offset + length);
4051
+
4052
+ if (length <= 0) {
4053
+ return 0;
4054
+ }
4055
+ if (currentLength == 0) {
4056
+ // Behave as if the read end is always non-blocking
4057
+ throw new FS.ErrnoError(6);
4058
+ }
4059
+ var toRead = Math.min(currentLength, length);
4060
+
4061
+ var totalRead = toRead;
4062
+ var toRemove = 0;
4063
+
4064
+ for (var bucket of pipe.buckets) {
4065
+ var bucketSize = bucket.offset - bucket.roffset;
4066
+
4067
+ if (toRead <= bucketSize) {
4068
+ var tmpSlice = bucket.buffer.subarray(bucket.roffset, bucket.offset);
4069
+ if (toRead < bucketSize) {
4070
+ tmpSlice = tmpSlice.subarray(0, toRead);
4071
+ bucket.roffset += toRead;
4072
+ } else {
4073
+ toRemove++;
4074
+ }
4075
+ data.set(tmpSlice);
4076
+ break;
4077
+ } else {
4078
+ var tmpSlice = bucket.buffer.subarray(bucket.roffset, bucket.offset);
4079
+ data.set(tmpSlice);
4080
+ data = data.subarray(tmpSlice.byteLength);
4081
+ toRead -= tmpSlice.byteLength;
4082
+ toRemove++;
4083
+ }
4084
+ }
4085
+
4086
+ if (toRemove && toRemove == pipe.buckets.length) {
4087
+ // Do not generate excessive garbage in use cases such as
4088
+ // write several bytes, read everything, write several bytes, read everything...
4089
+ toRemove--;
4090
+ pipe.buckets[toRemove].offset = 0;
4091
+ pipe.buckets[toRemove].roffset = 0;
4092
+ }
4093
+
4094
+ pipe.buckets.splice(0, toRemove);
4095
+
4096
+ return totalRead;
4097
+ },
4098
+ write(stream, buffer, offset, length, position /* ignored */) {
4099
+ var pipe = stream.node.pipe;
4100
+
4101
+ assert(buffer instanceof ArrayBuffer || ArrayBuffer.isView(buffer));
4102
+ var data = buffer.subarray(offset, offset + length);
4103
+
4104
+ var dataLen = data.byteLength;
4105
+ if (dataLen <= 0) {
4106
+ return 0;
4107
+ }
4108
+
4109
+ var currBucket = null;
4110
+
4111
+ if (pipe.buckets.length == 0) {
4112
+ currBucket = {
4113
+ buffer: new Uint8Array(PIPEFS.BUCKET_BUFFER_SIZE),
4114
+ offset: 0,
4115
+ roffset: 0
4116
+ };
4117
+ pipe.buckets.push(currBucket);
4118
+ } else {
4119
+ currBucket = pipe.buckets[pipe.buckets.length - 1];
4120
+ }
4121
+
4122
+ assert(currBucket.offset <= PIPEFS.BUCKET_BUFFER_SIZE);
4123
+
4124
+ var freeBytesInCurrBuffer = PIPEFS.BUCKET_BUFFER_SIZE - currBucket.offset;
4125
+ if (freeBytesInCurrBuffer >= dataLen) {
4126
+ currBucket.buffer.set(data, currBucket.offset);
4127
+ currBucket.offset += dataLen;
4128
+ return dataLen;
4129
+ } else if (freeBytesInCurrBuffer > 0) {
4130
+ currBucket.buffer.set(data.subarray(0, freeBytesInCurrBuffer), currBucket.offset);
4131
+ currBucket.offset += freeBytesInCurrBuffer;
4132
+ data = data.subarray(freeBytesInCurrBuffer, data.byteLength);
4133
+ }
4134
+
4135
+ var numBuckets = (data.byteLength / PIPEFS.BUCKET_BUFFER_SIZE) | 0;
4136
+ var remElements = data.byteLength % PIPEFS.BUCKET_BUFFER_SIZE;
4137
+
4138
+ for (var i = 0; i < numBuckets; i++) {
4139
+ var newBucket = {
4140
+ buffer: new Uint8Array(PIPEFS.BUCKET_BUFFER_SIZE),
4141
+ offset: PIPEFS.BUCKET_BUFFER_SIZE,
4142
+ roffset: 0
4143
+ };
4144
+ pipe.buckets.push(newBucket);
4145
+ newBucket.buffer.set(data.subarray(0, PIPEFS.BUCKET_BUFFER_SIZE));
4146
+ data = data.subarray(PIPEFS.BUCKET_BUFFER_SIZE, data.byteLength);
4147
+ }
4148
+
4149
+ if (remElements > 0) {
4150
+ var newBucket = {
4151
+ buffer: new Uint8Array(PIPEFS.BUCKET_BUFFER_SIZE),
4152
+ offset: data.byteLength,
4153
+ roffset: 0
4154
+ };
4155
+ pipe.buckets.push(newBucket);
4156
+ newBucket.buffer.set(data);
4157
+ }
4158
+
4159
+ return dataLen;
4160
+ },
4161
+ close(stream) {
4162
+ var pipe = stream.node.pipe;
4163
+ pipe.refcnt--;
4164
+ if (pipe.refcnt === 0) {
4165
+ pipe.buckets = null;
4166
+ }
4167
+ },
4168
+ },
4169
+ nextname() {
4170
+ if (!PIPEFS.nextname.current) {
4171
+ PIPEFS.nextname.current = 0;
4172
+ }
4173
+ return 'pipe[' + (PIPEFS.nextname.current++) + ']';
4174
+ },
4175
+ };
4176
+ function ___syscall_pipe(fdPtr) {
4177
+ try {
4178
+
4179
+ if (fdPtr == 0) {
4180
+ throw new FS.ErrnoError(21);
4181
+ }
4182
+
4183
+ var res = PIPEFS.createPipe();
4184
+
4185
+ HEAP32[((fdPtr)>>2)] = res.readable_fd;
4186
+ HEAP32[(((fdPtr)+(4))>>2)] = res.writable_fd;
4187
+
4188
+ return 0;
4189
+ } catch (e) {
4190
+ if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
4191
+ return -e.errno;
4192
+ }
4193
+ }
4194
+
3944
4195
 
3945
4196
 
3946
4197
  function ___syscall_readlinkat(dirfd, path, buf, bufsize) {
@@ -4077,45 +4328,6 @@ async function createWasm() {
4077
4328
  runtimeKeepaliveCounter = 0;
4078
4329
  };
4079
4330
 
4080
- var __emscripten_system = (command) => {
4081
- if (ENVIRONMENT_IS_NODE) {
4082
- if (!command) return 1; // shell is available
4083
-
4084
- var cmdstr = UTF8ToString(command);
4085
- if (!cmdstr.length) return 0; // this is what glibc seems to do (shell works test?)
4086
-
4087
- var cp = require('child_process');
4088
- var ret = cp.spawnSync(cmdstr, [], {shell:true, stdio:'inherit'});
4089
-
4090
- var _W_EXITCODE = (ret, sig) => ((ret) << 8 | (sig));
4091
-
4092
- // this really only can happen if process is killed by signal
4093
- if (ret.status === null) {
4094
- // sadly node doesn't expose such function
4095
- var signalToNumber = (sig) => {
4096
- // implement only the most common ones, and fallback to SIGINT
4097
- switch (sig) {
4098
- case 'SIGHUP': return 1;
4099
- case 'SIGQUIT': return 3;
4100
- case 'SIGFPE': return 8;
4101
- case 'SIGKILL': return 9;
4102
- case 'SIGALRM': return 14;
4103
- case 'SIGTERM': return 15;
4104
- default: return 2;
4105
- }
4106
- }
4107
- return _W_EXITCODE(0, signalToNumber(ret.signal));
4108
- }
4109
-
4110
- return _W_EXITCODE(ret.status, 0);
4111
- }
4112
- // int system(const char *command);
4113
- // http://pubs.opengroup.org/onlinepubs/000095399/functions/system.html
4114
- // Can't call external programs.
4115
- if (!command) return 0; // no shell available
4116
- return -52;
4117
- };
4118
-
4119
4331
  var isLeapYear = (year) => year%4 === 0 && (year%100 !== 0 || year%400 === 0);
4120
4332
 
4121
4333
  var MONTH_DAYS_LEAP_CUMULATIVE = [0,31,60,91,121,152,182,213,244,274,305,335];
@@ -4556,23 +4768,22 @@ async function createWasm() {
4556
4768
 
4557
4769
  /** @param {number=} offset */
4558
4770
  var doWritev = (stream, iov, iovcnt, offset) => {
4559
- var ret = 0;
4560
- for (var i = 0; i < iovcnt; i++) {
4561
- var ptr = HEAPU32[((iov)>>2)];
4562
- var len = HEAPU32[(((iov)+(4))>>2)];
4563
- iov += 8;
4564
- var curr = FS.write(stream, HEAP8, ptr, len, offset);
4565
- if (curr < 0) return -1;
4566
- ret += curr;
4567
- if (curr < len) {
4568
- // No more space to write.
4569
- break;
4570
- }
4571
- if (typeof offset != 'undefined') {
4572
- offset += curr;
4573
- }
4771
+ if (iovcnt == 1) {
4772
+ return FS.write(stream, HEAP8, HEAPU32[iov >> 2], HEAPU32[(iov + 4) >> 2], offset);
4574
4773
  }
4575
- return ret;
4774
+ var total = 0;
4775
+ for (var i = 0, p = iov; i < iovcnt; i++, p += 8) {
4776
+ total += HEAPU32[(p + 4) >> 2];
4777
+ }
4778
+ var view = new Uint8Array(total);
4779
+ var voff = 0;
4780
+ for (var i = 0; i < iovcnt; i++, iov += 8) {
4781
+ var ptr = HEAPU32[iov >> 2];
4782
+ var len = HEAPU32[(iov + 4) >> 2];
4783
+ view.set(HEAPU8.subarray(ptr, ptr + len), voff);
4784
+ voff += len;
4785
+ }
4786
+ return FS.write(stream, view, 0, total, offset);
4576
4787
  };
4577
4788
 
4578
4789
  function _fd_write(fd, iov, iovcnt, pnum) {
@@ -5097,8 +5308,18 @@ unexportedSymbols.forEach(unexportedRuntimeSymbol);
5097
5308
  function checkIncomingModuleAPI() {
5098
5309
  ignoredModuleProp('fetchSettings');
5099
5310
  }
5311
+ function slicc_spawn_capture_js(path,argv,envp,cwd,in_fd,out_fd,err_fd,actions,nactions) { const strings = (ptr) => { const out = []; for (let i = 0; ptr; i++) { const s = HEAPU32[(ptr >> 2) + i]; if (!s) break; out.push(UTF8ToString(s)); } return out; }; const isTty = (st) => st && FS.isChrdev(st.node.mode); const file = UTF8ToString(path); if (!file) return -44; const args = strings(argv); const envList = strings(envp); const env = {}; for (const kv of envList) { const eq = kv.indexOf('='); if (eq > 0) env[kv.slice(0, eq)] = kv.slice(eq + 1); } if (Module.sliccKernel) { const pairs = []; for (let i = 0; i < nactions; i++) { pairs.push([HEAP32[(actions >> 2) + 2 * i], HEAP32[(actions >> 2) + 2 * i + 1]]); } return Module.sliccKernel.spawn(file, args, envList.length ? env : null, cwd ? UTF8ToString(cwd) : null, [in_fd === -2 ? 0 : in_fd, out_fd, err_fd], pairs); } let input; if (in_fd >= 0) { try { const st = FS.getStream(in_fd); if (st && !isTty(st)) { const chunks = []; const buf = new Uint8Array(65536); let n; while ((n = FS.read(st, buf, 0, buf.length)) > 0) chunks.push(buf.slice(0, n)); if (chunks.length) input = Buffer.concat(chunks); } } catch (e) { } } if (Module.sliccBeforeSpawn) Module.sliccBeforeSpawn(); let r; try { r = require('child_process').spawnSync(file, args.slice(1), { cwd: cwd ? UTF8ToString(cwd) : FS.cwd(), env: envList.length ? env : process.env, input, }); } catch (e) { return e && e.code === 'ENOENT' ? -44 : -29; } finally { if (Module.sliccAfterSpawn) Module.sliccAfterSpawn(); } if (r.error) return r.error.code === 'ENOENT' ? -44 : -29; const put = (fd, data) => { if (fd < 0 || !data || !data.length) return; const bytes = typeof data === 'string' ? new TextEncoder().encode(data) : data; let st; try { st = FS.getStream(fd); } catch (e) {} if ((fd === 1 || fd === 2) && (!st || isTty(st))) { (fd === 1 ? process.stdout : process.stderr).write(bytes); return; } if (st) FS.write(st, bytes, 0, bytes.length); }; put(out_fd, r.stdout); put(err_fd, r.stderr); Module.sliccExited = Module.sliccExited || new Map(); Module.sliccNextPid = Module.sliccNextPid || 1000; const pid = ++Module.sliccNextPid; Module.sliccExited.set(pid, r.signal ? 9 : ((r.status ?? 1) & 0xff) << 8); return pid; }
5312
+ function slicc_wait_js(pid,status,options) { const nohang = options & 1; const gone = (st) => (st & 0xff) !== 0x7f && st !== 0xffff; const done = Module.sliccExited; const kernel = Module.sliccKernel; if (kernel) { const put = (reaped, st) => { if (status && reaped > 0) HEAP32[status >> 2] = st; return reaped; }; const exitedKey = pid > 0 ? (done?.has(pid) ? pid : undefined) : done?.keys().next().value; if (exitedKey !== undefined) { const st = done.get(exitedKey); done.delete(exitedKey); return put(exitedKey, st); } const aliases = Module.sliccAliases; if (pid > 0 && aliases?.has(pid)) { const r = kernel.wait(aliases.get(pid), !!nohang, options); if (typeof r === 'number') return r; if (r[0] > 0 && gone(r[1])) aliases.delete(pid); return put(r[0] > 0 ? pid : 0, r[1]); } const r = kernel.wait(pid, !!nohang, options); if (typeof r === 'number') return r; for (const [forkPid, kernelPid] of aliases ?? []) { if (kernelPid !== r[0]) continue; if (gone(r[1])) aliases.delete(forkPid); return put(forkPid, r[1]); } return put(r[0], r[1]); } if (!done || done.size === 0) return -12; const key = pid > 0 ? pid : done.keys().next().value; if (!done.has(key)) return -12; if (status) HEAP32[status >> 2] = done.get(key); done.delete(key); return key; }
5313
+ function slicc_exec_detach(pid) { if (!Module.sliccKernel || typeof SliccFork === 'undefined' || !SliccFork.stack.length) return 0; SliccFork.execPid = pid; return 1; }
5100
5314
  function slicc_sleep_ms(ms) { if (typeof SharedArrayBuffer === 'function' && typeof Atomics === 'object') { Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms); return; } const end = Date.now() + ms; while (Date.now() < end) {} }
5315
+ function slicc_default_getpid_js() { return (Module.sliccPid | 0) || 42; }
5316
+ function slicc_default_getppid_js() { return (Module.sliccPpid | 0) || 1; }
5101
5317
  function slicc_kill_js(pid,sig) { if (Module.sliccKernel && Module.sliccKernel.kill) return Module.sliccKernel.kill(pid, sig); return 1; }
5318
+ function slicc_pause_js() { if (Module.sliccKernel && Module.sliccKernel.pause) return Module.sliccKernel.pause(); return -52; }
5319
+ function slicc_cred_js(out) { const k = Module.sliccKernel; if (!k || !k.cred) return -52; const c = k.cred(); if (typeof c === 'number') return c; ['ruid', 'euid', 'suid', 'rgid', 'egid', 'sgid'].forEach((key, i) => { HEAPU32[(out >> 2) + i] = c[key] >>> 0; }); return 0; }
5320
+ function slicc_groups_js(list,cap) { const k = Module.sliccKernel; if (!k || !k.cred) return -52; const c = k.cred(); if (typeof c === 'number') return c; if (cap === 0) return c.groups.length; if (cap < c.groups.length) return -28; c.groups.forEach((g, i) => { HEAPU32[(list >> 2) + i] = g >>> 0; }); return c.groups.length; }
5321
+ function slicc_setcred_js(ruid,euid,suid,rgid,egid,sgid) { const k = Module.sliccKernel; if (!k || !k.setcred) return -52; const change = {}; const ids = { ruid, euid, suid, rgid, egid, sgid }; for (const key in ids) if (ids[key] !== -1) change[key] = ids[key] >>> 0; const r = k.setcred(change); return typeof r === 'number' ? r : 0; }
5322
+ function slicc_setgroups_js(list,n) { const k = Module.sliccKernel; if (!k || !k.setcred) return -52; const groups = []; for (let i = 0; i < n; i++) groups.push(HEAPU32[(list >> 2) + i]); const r = k.setcred({ groups }); return typeof r === 'number' ? r : 0; }
5102
5323
 
5103
5324
  // Imports from the Wasm binary.
5104
5325
  var _strerror = makeInvalidEarlyAccess('_strerror');
@@ -5107,11 +5328,12 @@ var _main = Module['_main'] = makeInvalidEarlyAccess('_main');
5107
5328
  var _slicc_sigpipe = Module['_slicc_sigpipe'] = makeInvalidEarlyAccess('_slicc_sigpipe');
5108
5329
  var _slicc_raise = Module['_slicc_raise'] = makeInvalidEarlyAccess('_slicc_raise');
5109
5330
  var _slicc_sig_mask = Module['_slicc_sig_mask'] = makeInvalidEarlyAccess('_slicc_sig_mask');
5331
+ var _slicc_cred_euid = Module['_slicc_cred_euid'] = makeInvalidEarlyAccess('_slicc_cred_euid');
5110
5332
  var ___funcs_on_exit = makeInvalidEarlyAccess('___funcs_on_exit');
5111
- var _emscripten_stack_get_end = makeInvalidEarlyAccess('_emscripten_stack_get_end');
5112
- var _emscripten_stack_get_base = makeInvalidEarlyAccess('_emscripten_stack_get_base');
5113
5333
  var _emscripten_stack_init = makeInvalidEarlyAccess('_emscripten_stack_init');
5114
5334
  var _emscripten_stack_get_free = makeInvalidEarlyAccess('_emscripten_stack_get_free');
5335
+ var _emscripten_stack_get_base = makeInvalidEarlyAccess('_emscripten_stack_get_base');
5336
+ var _emscripten_stack_get_end = makeInvalidEarlyAccess('_emscripten_stack_get_end');
5115
5337
  var __emscripten_stack_restore = makeInvalidEarlyAccess('__emscripten_stack_restore');
5116
5338
  var __emscripten_stack_alloc = makeInvalidEarlyAccess('__emscripten_stack_alloc');
5117
5339
  var _emscripten_stack_get_current = makeInvalidEarlyAccess('_emscripten_stack_get_current');
@@ -5127,11 +5349,12 @@ function assignWasmExports(wasmExports) {
5127
5349
  assert(typeof wasmExports['slicc_sigpipe'] != 'undefined', 'missing Wasm export: slicc_sigpipe');
5128
5350
  assert(typeof wasmExports['slicc_raise'] != 'undefined', 'missing Wasm export: slicc_raise');
5129
5351
  assert(typeof wasmExports['slicc_sig_mask'] != 'undefined', 'missing Wasm export: slicc_sig_mask');
5352
+ assert(typeof wasmExports['slicc_cred_euid'] != 'undefined', 'missing Wasm export: slicc_cred_euid');
5130
5353
  assert(typeof wasmExports['__funcs_on_exit'] != 'undefined', 'missing Wasm export: __funcs_on_exit');
5131
- assert(typeof wasmExports['emscripten_stack_get_end'] != 'undefined', 'missing Wasm export: emscripten_stack_get_end');
5132
- assert(typeof wasmExports['emscripten_stack_get_base'] != 'undefined', 'missing Wasm export: emscripten_stack_get_base');
5133
5354
  assert(typeof wasmExports['emscripten_stack_init'] != 'undefined', 'missing Wasm export: emscripten_stack_init');
5134
5355
  assert(typeof wasmExports['emscripten_stack_get_free'] != 'undefined', 'missing Wasm export: emscripten_stack_get_free');
5356
+ assert(typeof wasmExports['emscripten_stack_get_base'] != 'undefined', 'missing Wasm export: emscripten_stack_get_base');
5357
+ assert(typeof wasmExports['emscripten_stack_get_end'] != 'undefined', 'missing Wasm export: emscripten_stack_get_end');
5135
5358
  assert(typeof wasmExports['_emscripten_stack_restore'] != 'undefined', 'missing Wasm export: _emscripten_stack_restore');
5136
5359
  assert(typeof wasmExports['_emscripten_stack_alloc'] != 'undefined', 'missing Wasm export: _emscripten_stack_alloc');
5137
5360
  assert(typeof wasmExports['emscripten_stack_get_current'] != 'undefined', 'missing Wasm export: emscripten_stack_get_current');
@@ -5143,11 +5366,12 @@ function assignWasmExports(wasmExports) {
5143
5366
  _slicc_sigpipe = Module['_slicc_sigpipe'] = createExportWrapper('slicc_sigpipe', 0);
5144
5367
  _slicc_raise = Module['_slicc_raise'] = createExportWrapper('slicc_raise', 1);
5145
5368
  _slicc_sig_mask = Module['_slicc_sig_mask'] = createExportWrapper('slicc_sig_mask', 1);
5369
+ _slicc_cred_euid = Module['_slicc_cred_euid'] = createExportWrapper('slicc_cred_euid', 0);
5146
5370
  ___funcs_on_exit = createExportWrapper('__funcs_on_exit', 0);
5147
- _emscripten_stack_get_end = wasmExports['emscripten_stack_get_end'];
5148
- _emscripten_stack_get_base = wasmExports['emscripten_stack_get_base'];
5149
5371
  _emscripten_stack_init = wasmExports['emscripten_stack_init'];
5150
5372
  _emscripten_stack_get_free = wasmExports['emscripten_stack_get_free'];
5373
+ _emscripten_stack_get_base = wasmExports['emscripten_stack_get_base'];
5374
+ _emscripten_stack_get_end = wasmExports['emscripten_stack_get_end'];
5151
5375
  __emscripten_stack_restore = wasmExports['_emscripten_stack_restore'];
5152
5376
  __emscripten_stack_alloc = wasmExports['_emscripten_stack_alloc'];
5153
5377
  _emscripten_stack_get_current = wasmExports['emscripten_stack_get_current'];
@@ -5175,6 +5399,8 @@ var wasmImports = {
5175
5399
  /** @export */
5176
5400
  __syscall_openat: ___syscall_openat,
5177
5401
  /** @export */
5402
+ __syscall_pipe: ___syscall_pipe,
5403
+ /** @export */
5178
5404
  __syscall_readlinkat: ___syscall_readlinkat,
5179
5405
  /** @export */
5180
5406
  __syscall_renameat: ___syscall_renameat,
@@ -5191,8 +5417,6 @@ var wasmImports = {
5191
5417
  /** @export */
5192
5418
  _emscripten_runtime_keepalive_clear: __emscripten_runtime_keepalive_clear,
5193
5419
  /** @export */
5194
- _emscripten_system: __emscripten_system,
5195
- /** @export */
5196
5420
  _localtime_js: __localtime_js,
5197
5421
  /** @export */
5198
5422
  _mktime_js: __mktime_js,
@@ -5221,7 +5445,19 @@ var wasmImports = {
5221
5445
  /** @export */
5222
5446
  fd_write: _fd_write,
5223
5447
  /** @export */
5224
- proc_exit: _proc_exit
5448
+ proc_exit: _proc_exit,
5449
+ /** @export */
5450
+ slicc_cred_js,
5451
+ /** @export */
5452
+ slicc_default_getpid_js,
5453
+ /** @export */
5454
+ slicc_kill_js,
5455
+ /** @export */
5456
+ slicc_pause_js,
5457
+ /** @export */
5458
+ slicc_spawn_capture_js,
5459
+ /** @export */
5460
+ slicc_wait_js
5225
5461
  };
5226
5462
 
5227
5463
 
package/bin/zip.wasm CHANGED
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-ecoverse/wasm-zip",
3
- "version": "3.0.0-1",
3
+ "version": "3.0.0-2",
4
4
  "description": "Info-ZIP zip 3.0 + unzip 6.0 for wasm / slicc (emscripten)",
5
5
  "license": "Info-ZIP",
6
6
  "repository": {