forked from emscripten-core/emscripten
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibrary_bootstrap_structInfo.js
44 lines (42 loc) · 1.55 KB
/
library_bootstrap_structInfo.js
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
// Copyright 2015 The Emscripten Authors. All rights reserved.
// Emscripten is available under two separate licenses, the MIT license and the
// University of Illinois/NCSA Open Source License. Both these licenses can be
// found in the LICENSE file.
//
// no merging, this is the entire library. it is literally just enough to run
// the bootstrap program that prints out C constants for us, we obviously need
// to run without any such constants ourselves...
assert(!LibraryManager.library);
LibraryManager.library = {
sysconf: function(name) {
assert(name == 30);
return PAGE_SIZE;
},
time: function(ptr) {
var ret = (Date.now()/1000)|0;
if (ptr) {
{{{ makeSetValue('ptr', 0, 'ret', 'i32') }}};
}
return ret;
},
sbrk: function(bytes) {
// Implement a Linux-like 'memory area' for our 'process'.
// Changes the size of the memory area by |bytes|; returns the
// address of the previous top ('break') of the memory area
// We control the "dynamic" memory - DYNAMIC_BASE to DYNAMICTOP
var self = _sbrk;
if (!self.called) {
HEAP32[DYNAMICTOP_PTR>>2] = alignUp(HEAP32[DYNAMICTOP_PTR>>2], 16777216); // make sure we start out aligned
self.called = true;
assert(dynamicAlloc);
self.alloc = dynamicAlloc;
dynamicAlloc = function() { abort('cannot dynamically allocate, sbrk now has control') };
}
var ret = HEAP32[DYNAMICTOP_PTR>>2];
if (bytes != 0) self.alloc(bytes);
return ret; // Previous break location.
},
malloc: function(x) {
return dynamicAlloc(x);
},
};