aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-01-10 14:26:55 -0800
committerAlon Zakai <alonzakai@gmail.com>2013-01-10 14:26:55 -0800
commitbf3e22d4fccd928aa08da6829c058a65ed789c62 (patch)
tree15fc5112732c234c31eb452336ac9c2f413e3154 /src
parent453d7065c7da07fc432fbec562c861595798d042 (diff)
restore basic malloc/free implementation
Diffstat (limited to 'src')
-rw-r--r--src/library.js15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/library.js b/src/library.js
index 22fbe1c3..2e86b4bf 100644
--- a/src/library.js
+++ b/src/library.js
@@ -3603,6 +3603,21 @@ LibraryManager.library = {
// stdlib.h
// ==========================================================================
+ // tiny, fake malloc/free implementation. If the program actually uses malloc,
+ // a compiled version will be used; this will only be used if the runtime
+ // needs to allocate something, for which this is good enough if otherwise
+ // no malloc is needed.
+ malloc: function(bytes) {
+ /* Over-allocate to make sure it is byte-aligned by 8.
+ * This will leak memory, but this is only the dummy
+ * implementation (replaced by dlmalloc normally) so
+ * not an issue.
+ */
+ ptr = Runtime.staticAlloc(bytes + 8);
+ return (ptr+8) & 0xFFFFFFF8;
+ },
+ free: function(){},
+
calloc__deps: ['malloc'],
calloc: function(n, s) {
var ret = _malloc(n*s);