Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
emscripten-core
GitHub Repository: emscripten-core/emscripten
Path: blob/main/src/lib/libbootstrap.js
4150 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
$ExitStatus: class {
19
name = 'ExitStatus';
20
constructor(status) {
21
this.message = `Program terminated with exit(${status})`;
22
this.status = status;
23
}
24
},
25
26
$exitJS__deps: ['$ExitStatus'],
27
$exitJS: (code) => quit_(code, new ExitStatus(code)),
28
29
$handleException: (e) => {
30
if (e instanceof ExitStatus || e == 'unwind') {
31
return EXITSTATUS;
32
}
33
quit_(1, e);
34
},
35
36
fd_write__sig: 'iippp',
37
fd_write: (fd, iov, iovcnt, pnum) => {
38
// implementation almost copied from libwasi.js one for SYSCALLS_REQUIRE_FILESYSTEM=0
39
// (the only difference is that we can't use C_STRUCTS here)
40
var num = 0;
41
for (var i = 0; i < iovcnt; i++) {
42
var ptr = {{{ makeGetValue('iov', 0, '*') }}};
43
var len = {{{ makeGetValue('iov', POINTER_SIZE, '*') }}};
44
iov += {{{ POINTER_SIZE }}} * 2;
45
process.stdout.write(HEAPU8.subarray(ptr, ptr + len));
46
num += len;
47
}
48
{{{ makeSetValue('pnum', 0, 'num', '*') }}};
49
return 0;
50
},
51
});
52
53