File size: 1,724 Bytes
00df61d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/**
 * @license
 * Copyright 2015 The Emscripten Authors
 * SPDX-License-Identifier: MIT
 */

// When bootstrapping struct info, we can't use the full library because
// it itself depends on the struct info information.

#if !BOOTSTRAPPING_STRUCT_INFO
assert(false, "libbootstrap.js only designed for use with BOOTSTRAPPING_STRUCT_INFO")
#endif

assert(Object.keys(LibraryManager.library).length === 0);
addToLibrary({
  $callRuntimeCallbacks: () => {},

  $HEAP8: undefined,
  $HEAPU8: undefined,
  $HEAP16: undefined,
  $HEAPU16: undefined,
  $HEAP32: undefined,
  $HEAPU32: undefined,
  $HEAPF32: undefined,
  $HEAPF64: undefined,
#if WASM_BIGINT
  $HEAP64: undefined,
  $HEAPU64: undefined,
#endif

  $wasmMemory: 'memory',

  $ExitStatus: class {
    name = 'ExitStatus';
    constructor(status) {
      this.message = `Program terminated with exit(${status})`;
      this.status = status;
    }
  },

  $exitJS__deps: ['$ExitStatus'],
  $exitJS: (code) => quit_(code, new ExitStatus(code)),

  $handleException: (e) => {
    if (e instanceof ExitStatus || e == 'unwind') {
      return EXITSTATUS;
    }
    quit_(1, e);
  },

  fd_write__sig: 'iippp',
  fd_write: (fd, iov, iovcnt, pnum) => {
    // implementation almost copied from libwasi.js one for SYSCALLS_REQUIRE_FILESYSTEM=0
    // (the only difference is that we can't use C_STRUCTS here)
    var num = 0;
    for (var i = 0; i < iovcnt; i++) {
      var ptr = {{{ makeGetValue('iov', 0, '*') }}};
      var len = {{{ makeGetValue('iov', POINTER_SIZE, '*') }}};
      iov += {{{ POINTER_SIZE }}} * 2;
      process.stdout.write(HEAPU8.subarray(ptr, ptr + len));
      num += len;
    }
    {{{ makeSetValue('pnum', 0, 'num', '*') }}};
    return 0;
  },
});