Add a runtime check to static/dynamicAlloc functions to ensure that pthreads don't accidentally run wrong type of allocate() call.
This commit is contained in:
Родитель
e835df2fda
Коммит
86b7039e97
|
@ -50,6 +50,9 @@ var RuntimeGenerator = {
|
||||||
// called, takes control of STATICTOP)
|
// called, takes control of STATICTOP)
|
||||||
staticAlloc: function(size) {
|
staticAlloc: function(size) {
|
||||||
if (ASSERTIONS) size = '(assert(!staticSealed),' + size + ')'; // static area must not be sealed
|
if (ASSERTIONS) size = '(assert(!staticSealed),' + size + ')'; // static area must not be sealed
|
||||||
|
#if USE_PTHREADS
|
||||||
|
if (typeof ENVIRONMENT_IS_PTHREAD !== 'undefined' && ENVIRONMENT_IS_PTHREAD) throw 'Runtime.staticAlloc is not available in pthreads!'; // This is because each worker has its own copy of STATICTOP, of which main thread is authoritative.
|
||||||
|
#endif
|
||||||
var ret = RuntimeGenerator.alloc(size, 'STATIC');
|
var ret = RuntimeGenerator.alloc(size, 'STATIC');
|
||||||
return ret;
|
return ret;
|
||||||
},
|
},
|
||||||
|
@ -57,6 +60,9 @@ var RuntimeGenerator = {
|
||||||
// allocation on the top of memory, adjusted dynamically by sbrk
|
// allocation on the top of memory, adjusted dynamically by sbrk
|
||||||
dynamicAlloc: function(size) {
|
dynamicAlloc: function(size) {
|
||||||
if (ASSERTIONS) size = '(assert(DYNAMICTOP > 0),' + size + ')'; // dynamic area must be ready
|
if (ASSERTIONS) size = '(assert(DYNAMICTOP > 0),' + size + ')'; // dynamic area must be ready
|
||||||
|
#if USE_PTHREADS
|
||||||
|
if (typeof ENVIRONMENT_IS_PTHREAD !== 'undefined' && ENVIRONMENT_IS_PTHREAD) throw 'Runtime.dynamicAlloc is not available in pthreads!'; // This is because each worker has its own copy of DYNAMICTOP, of which main thread is authoritative.
|
||||||
|
#endif
|
||||||
var ret = RuntimeGenerator.alloc(size, 'DYNAMIC');
|
var ret = RuntimeGenerator.alloc(size, 'DYNAMIC');
|
||||||
ret += '; if (DYNAMICTOP >= TOTAL_MEMORY) { var success = enlargeMemory(); if (!success) { DYNAMICTOP = ret; return 0; } }'
|
ret += '; if (DYNAMICTOP >= TOTAL_MEMORY) { var success = enlargeMemory(); if (!success) { DYNAMICTOP = ret; return 0; } }'
|
||||||
return ret;
|
return ret;
|
||||||
|
|
Загрузка…
Ссылка в новой задаче