Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
emscripten-core
GitHub Repository: emscripten-core/emscripten
Path: blob/main/src/lib/libbootstrap.js
6162 views
1
/**
2
* @license
3
* Copyright 2015 The Emscripten Authors
4
* SPDX-License-Identifier: MIT
5
*/
6
7
// When bootstrapping struct info, we can't use the full library because
8
// it itself depends on the struct info information.
9
10
#if !BOOTSTRAPPING_STRUCT_INFO
11
assert(false, "libbootstrap.js only designed for use with BOOTSTRAPPING_STRUCT_INFO")
12
#endif
13
14
assert(Object.keys(LibraryManager.library).length === 0);
15
addToLibrary({
16
$callRuntimeCallbacks: () => {},
17
18
$wasmMemory: 'memory',
19
20
$ExitStatus: class {
21
name = 'ExitStatus';
22
constructor(status) {
23
this.message = `Program terminated with exit(${status})`;
24
this.status = status;
25
}
26
},
27
28
$exitJS__deps: ['$ExitStatus'],
29
$exitJS: (code) => quit_(code, new ExitStatus(code)),
30
31
$handleException: (e) => {
32
if (e instanceof ExitStatus || e == 'unwind') {
33
return EXITSTATUS;
34
}
35
quit_(1, e);
36
},
37
38
fd_write__sig: 'iippp',
39
fd_write: (fd, iov, iovcnt, pnum) => {
40
// implementation almost copied from libwasi.js one for SYSCALLS_REQUIRE_FILESYSTEM=0
41
// (the only difference is that we can't use C_STRUCTS here)
42
var num = 0;
43
for (var i = 0; i < iovcnt; i++) {
44
var ptr = {{{ makeGetValue('iov', 0, '*') }}};
45
var len = {{{ makeGetValue('iov', POINTER_SIZE, '*') }}};
46
iov += {{{ POINTER_SIZE }}} * 2;
47
process.stdout.write(HEAPU8.subarray(ptr, ptr + len));
48
num += len;
49
}
50
{{{ makeSetValue('pnum', 0, 'num', '*') }}};
51
return 0;
52
},
53
});
54
55