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:
Jukka Jylänki 2015-02-11 15:31:40 +02:00
Родитель e835df2fda
Коммит 86b7039e97
1 изменённых файлов: 6 добавлений и 0 удалений

Просмотреть файл

@ -50,6 +50,9 @@ var RuntimeGenerator = {
// called, takes control of STATICTOP)
staticAlloc: function(size) {
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');
return ret;
},
@ -57,6 +60,9 @@ var RuntimeGenerator = {
// allocation on the top of memory, adjusted dynamically by sbrk
dynamicAlloc: function(size) {
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');
ret += '; if (DYNAMICTOP >= TOTAL_MEMORY) { var success = enlargeMemory(); if (!success) { DYNAMICTOP = ret; return 0; } }'
return ret;