diff options
author | Alon Zakai <alonzakai@gmail.com> | 2012-08-03 13:45:34 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2012-08-03 13:45:34 -0700 |
commit | ace5387ed5bda1e711277994329c2fd3997d90b4 (patch) | |
tree | 488fd8056cbfd026e9e1893e29c7f73b5cef9cf0 | |
parent | 14bd8deb1c0f30700928b108fdfe0578d8a851ba (diff) |
keep FS.streams dense by allocating stdin, stdout, stderr in low memory, and filling the space around them
-rw-r--r-- | src/library.js | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/library.js b/src/library.js index 8d2c628e..0269efe9 100644 --- a/src/library.js +++ b/src/library.js @@ -484,14 +484,18 @@ LibraryManager.library = { eof: false, ungotten: [] }; - _stdin = allocate([1], 'void*', ALLOC_STATIC); - _stdout = allocate([2], 'void*', ALLOC_STATIC); - _stderr = allocate([3], 'void*', ALLOC_STATIC); + // Allocate these on the stack (and never free, we are called from ATINIT or earlier), to keep their locations low + _stdin = allocate([1], 'void*', ALLOC_STACK); + _stdout = allocate([2], 'void*', ALLOC_STACK); + _stderr = allocate([3], 'void*', ALLOC_STACK); // Other system paths FS.createPath('/', 'dev/shm/tmp', true, true); // temp files // Newlib initialization + for (var i = FS.streams.length; i < Math.max(_stdin, _stdout, _stderr) + {{{ QUANTUM_SIZE }}}; i++) { + FS.streams[i] = null; // Make sure to keep FS.streams dense + } FS.streams[_stdin] = FS.streams[1]; FS.streams[_stdout] = FS.streams[2]; FS.streams[_stderr] = FS.streams[3]; @@ -548,7 +552,7 @@ LibraryManager.library = { ___setErrNo(ERRNO_CODES.EACCES); return 0; } - var id = FS.streams.length; + var id = FS.streams.length; // Keep dense var contents = []; for (var key in target.contents) contents.push(key); FS.streams[id] = { @@ -1077,7 +1081,7 @@ LibraryManager.library = { finalPath = path.parentPath + '/' + path.name; } // Actually create an open stream. - var id = FS.streams.length; + var id = FS.streams.length; // Keep dense if (target.isFolder) { var entryBuffer = 0; if (___dirent_struct_layout) { @@ -1144,7 +1148,7 @@ LibraryManager.library = { for (var member in stream) { newStream[member] = stream[member]; } - if (arg in FS.streams) arg = FS.streams.length; + arg = FS.streams.length; // Keep dense FS.streams[arg] = newStream; return arg; case {{{ cDefine('F_GETFD') }}}: |