MCPcopy Index your code
hub / github.com/sql-js/sql.js / _sbrk

Function _sbrk

js/sql-debug.js:397891–397918  ·  view source on GitHub ↗
(increment)

Source from the content-addressed store, hash-verified

397889 return (end-num)|0;
397890}
397891function _sbrk(increment) {
397892 increment = increment|0;
397893 var oldDynamicTop = 0;
397894 var oldDynamicTopOnChange = 0;
397895 var newDynamicTop = 0;
397896 var totalMemory = 0;
397897 increment = ((increment + 15) & -16)|0;
397898 oldDynamicTop = HEAP32[DYNAMICTOP_PTR>>2]|0;
397899 newDynamicTop = oldDynamicTop + increment | 0;
397900
397901 if (((increment|0) > 0 & (newDynamicTop|0) < (oldDynamicTop|0)) // Detect and fail if we would wrap around signed 32-bit int.
397902 | (newDynamicTop|0) < 0) { // Also underflow, sbrk() should be able to be used to subtract.
397903 abortOnCannotGrowMemory()|0;
397904 ___setErrNo(12);
397905 return -1;
397906 }
397907
397908 HEAP32[DYNAMICTOP_PTR>>2] = newDynamicTop;
397909 totalMemory = getTotalMemory()|0;
397910 if ((newDynamicTop|0) > (totalMemory|0)) {
397911 if ((enlargeMemory()|0) == 0) {
397912 HEAP32[DYNAMICTOP_PTR>>2] = oldDynamicTop;
397913 ___setErrNo(12);
397914 return -1;
397915 }
397916 }
397917 return oldDynamicTop|0;
397918}
397919
397920
397921function dynCall_i(index) {

Callers 1

_mallocFunction · 0.85

Calls 4

abortOnCannotGrowMemoryFunction · 0.70
___setErrNoFunction · 0.70
getTotalMemoryFunction · 0.70
enlargeMemoryFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…