Skip to content

Commit

Permalink
More fixes for 4gb and 2gb high memory modes
Browse files Browse the repository at this point in the history
  • Loading branch information
sbc100 committed Feb 6, 2024
1 parent 97053db commit 631316e
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 71 deletions.
2 changes: 2 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,7 @@ jobs:
browser_2gb.test_emscripten_animate_canvas_element_size_manual_css
browser_2gb.test_fulles2_sdlproc
browser_2gb.test_cubegeom*
browser_2gb.test_html5_webgl_create_context*
"
test-browser-chrome-wasm64-4gb:
executor: bionic
Expand All @@ -834,6 +835,7 @@ jobs:
browser64_4gb.test_fetch*
browser64_4gb.test_emscripten_animate_canvas_element_size_manual_css
browser64_4gb.test_fulles2_sdlproc
browser64_4gb.test_html5_webgl_create_context*
"
test-browser-firefox:
executor: bionic
Expand Down
3 changes: 2 additions & 1 deletion src/library_html5_webgl.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ var LibraryHtml5WebGL = {
var len = arr.length;
var writeLength = dstLength < len ? dstLength : len;
var heap = heapType ? HEAPF32 : HEAP32;
dst = {{{ getHeapOffset('dst', 'float') }}};
for (var i = 0; i < writeLength; ++i) {
heap[(dst >> 2) + i] = arr[i];
heap[dst + i] = arr[i];
}
return len;
},
Expand Down
2 changes: 1 addition & 1 deletion system/include/emscripten/html5_webgl.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
extern "C" {
#endif

typedef intptr_t EMSCRIPTEN_WEBGL_CONTEXT_HANDLE;
typedef uintptr_t EMSCRIPTEN_WEBGL_CONTEXT_HANDLE;

typedef int EMSCRIPTEN_WEBGL_CONTEXT_PROXY_MODE;
#define EMSCRIPTEN_WEBGL_CONTEXT_PROXY_DISALLOW 0
Expand Down
55 changes: 24 additions & 31 deletions test/browser/emmalloc_memgrowth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,30 @@
uint64_t nextAllocationSize = 16*1024*1024;
bool allocHasFailed = false;

void grow_memory()
{
uint8_t *ptr = (uint8_t*)malloc((size_t)nextAllocationSize);
EM_ASM({}, ptr); // Pass ptr out to confuse LLVM that it is used, so it won't optimize it away in -O1 and higher.
size_t heapSize = emscripten_get_heap_size();
printf("Allocated %zu: %d. Heap size: %zu\n", (size_t)nextAllocationSize, ptr ? 1 : 0, heapSize);
if (ptr)
{
if (!allocHasFailed)
{
nextAllocationSize *= 2;
// Make sure we don't overflow, and also exercise malloc(-1) to gracefully return 0 in ABORTING_MALLOC=0 mode.
if (nextAllocationSize > 0xFFFFFFFFULL)
nextAllocationSize = 0xFFFFFFFFULL;
}
}
else
{
nextAllocationSize /= 2;
allocHasFailed = true;
}
void grow_memory() {
uint8_t *ptr = (uint8_t*)malloc((size_t)nextAllocationSize);
EM_ASM({}, ptr); // Pass ptr out to confuse LLVM that it is used, so it won't optimize it away in -O1 and higher.
size_t heapSize = emscripten_get_heap_size();
printf("Allocated %zu: %d. Heap size: %zu\n", (size_t)nextAllocationSize, ptr ? 1 : 0, heapSize);
if (ptr) {
if (!allocHasFailed) {
nextAllocationSize *= 2;
// Make sure we don't overflow, and also exercise malloc(-1) to gracefully return 0 in ABORTING_MALLOC=0 mode.
if (nextAllocationSize > 0xFFFFFFFFULL)
nextAllocationSize = 0xFFFFFFFFULL;
}
} else {
nextAllocationSize /= 2;
allocHasFailed = true;
}
}

int main()
{
// Exhaust all available memory.
for(int i = 0; i < 50; ++i)
grow_memory();
// If we get this far without crashing on OOM, we are ok!
printf("Test finished!\n");
#ifdef REPORT_RESULT
REPORT_RESULT(0);
#endif
int main() {
// Exhaust all available memory.
for(int i = 0; i < 50; ++i) {
grow_memory();
}
// If we get this far without crashing on OOM, we are ok!
printf("Test finished!\n");
return 0;
}
4 changes: 2 additions & 2 deletions test/browser/webgl_create_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void loop() {
assert(emscripten_webgl_get_current_context() == 0);
context = emscripten_webgl_create_context("#canvas", &attrs);

assert(context > 0); // Must have received a valid context.
assert(context != 0); // Must have received a valid context.
res = emscripten_webgl_make_context_current(context);
assert(res == EMSCRIPTEN_RESULT_SUCCESS);
assert(emscripten_webgl_get_current_context() == context);
Expand Down Expand Up @@ -104,7 +104,7 @@ int main() {

assert(emscripten_webgl_get_current_context() == 0);
EMSCRIPTEN_WEBGL_CONTEXT_HANDLE context = emscripten_webgl_create_context("#customCanvas", &attrs);
assert(context > 0); // Must have received a valid context.
assert(context != 0); // Must have received a valid context.
EMSCRIPTEN_RESULT res = emscripten_webgl_make_context_current(context);
assert(res == EMSCRIPTEN_RESULT_SUCCESS);
assert(emscripten_webgl_get_current_context() == context);
Expand Down
47 changes: 18 additions & 29 deletions test/fs/test_idbfs_sync.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,17 @@

int result = 1;

void success()
{
void success() {
REPORT_RESULT(result);
#ifdef FORCE_EXIT
emscripten_force_exit(0);
#endif
}

void test() {

int fd;
struct stat st;

#if FIRST

// for each file, we first make sure it doesn't currently exist
Expand All @@ -49,22 +47,20 @@ void test() {
fd = open("/working1/waka.txt", O_RDWR | O_CREAT, 0666);
if (fd == -1)
result = -5000 - errno;
else
{
else {
if (write(fd,"az",2) != 2)
result = -6000 - errno;
if (close(fd) != 0)
result = -7000 - errno;
}

// a file whose contents are random-ish string set by the test_browser.py file
if ((stat("/working1/moar.txt", &st) != -1) || (errno != ENOENT))
result = -8000 - errno;
fd = open("/working1/moar.txt", O_RDWR | O_CREAT, 0666);
if (fd == -1)
result = -9000 - errno;
else
{
else {
if (write(fd, SECRET, strlen(SECRET)) != strlen(SECRET))
result = -10000 - errno;
if (close(fd) != 0)
Expand Down Expand Up @@ -92,8 +88,7 @@ void test() {
fd = open("/working1/waka.txt", O_RDONLY);
if (fd == -1)
result = -17000 - errno;
else
{
else {
char bf[4];
int bytes_read = read(fd,&bf[0],sizeof(bf));
if (bytes_read != 2)
Expand All @@ -105,19 +100,17 @@ void test() {
if (unlink("/working1/waka.txt") != 0)
result = -21000 - errno;
}

// does the random-ish file exist and does it contain SECRET?
fd = open("/working1/moar.txt", O_RDONLY);
if (fd == -1)
if (fd == -1) {
result = -22000 - errno;
else
{
} else {
char bf[256];
int bytes_read = read(fd,&bf[0],sizeof(bf));
if (bytes_read != strlen(SECRET))
if (bytes_read != strlen(SECRET)) {
result = -23000;
else
{
} else {
bf[strlen(SECRET)] = 0;
if (strcmp(bf,SECRET) != 0)
result = -24000;
Expand All @@ -129,14 +122,13 @@ void test() {
}

// does the directory exist?
if (stat("/working1/dir", &st) != 0)
if (stat("/working1/dir", &st) != 0) {
result = -27000 - errno;
else
{
} else {
if (!S_ISDIR(st.st_mode))
result = -28000;
if (rmdir("/working1/dir") != 0)
result = -29000 - errno;
if (rmdir("/working1/dir") != 0)
result = -29000 - errno;
}

#endif
Expand Down Expand Up @@ -164,20 +156,18 @@ void test() {
ccall('success', 'v');
});
);

}

int main() {

EM_ASM(
FS.mkdir('/working1');
FS.mount(IDBFS, {}, '/working1');

#if !FIRST
// syncfs(true, f) should not break on already-existing directories:
FS.mkdir('/working1/dir');
// syncfs(true, f) should not break on already-existing directories:
FS.mkdir('/working1/dir');
#endif

// sync from persisted state into memory and then
// run the 'test' function
FS.syncfs(true, function (err) {
Expand All @@ -187,6 +177,5 @@ int main() {
);

emscripten_exit_with_live_runtime();

return 0;
}
Loading

0 comments on commit 631316e

Please sign in to comment.