Skip to content

Commit 2bda48d

Browse files
committed
More fixes for 4gb and 2gb high memory modes
1 parent 97053db commit 2bda48d

File tree

7 files changed

+84
-71
lines changed

7 files changed

+84
-71
lines changed

.circleci/config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,7 @@ jobs:
819819
browser_2gb.test_emscripten_animate_canvas_element_size_manual_css
820820
browser_2gb.test_fulles2_sdlproc
821821
browser_2gb.test_cubegeom*
822+
browser_2gb.test_html5_webgl_create_context*
822823
"
823824
test-browser-chrome-wasm64-4gb:
824825
executor: bionic
@@ -834,6 +835,7 @@ jobs:
834835
browser64_4gb.test_fetch*
835836
browser64_4gb.test_emscripten_animate_canvas_element_size_manual_css
836837
browser64_4gb.test_fulles2_sdlproc
838+
browser64_4gb.test_html5_webgl_create_context*
837839
"
838840
test-browser-firefox:
839841
executor: bionic

src/library_html5_webgl.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ var LibraryHtml5WebGL = {
1414
var len = arr.length;
1515
var writeLength = dstLength < len ? dstLength : len;
1616
var heap = heapType ? HEAPF32 : HEAP32;
17+
dst = {{{ getHeapOffset('dst', 'float') }}};
1718
for (var i = 0; i < writeLength; ++i) {
18-
heap[(dst >> 2) + i] = arr[i];
19+
heap[dst + i] = arr[i];
1920
}
2021
return len;
2122
},

system/include/emscripten/html5_webgl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
extern "C" {
1515
#endif
1616

17-
typedef intptr_t EMSCRIPTEN_WEBGL_CONTEXT_HANDLE;
17+
typedef uintptr_t EMSCRIPTEN_WEBGL_CONTEXT_HANDLE;
1818

1919
typedef int EMSCRIPTEN_WEBGL_CONTEXT_PROXY_MODE;
2020
#define EMSCRIPTEN_WEBGL_CONTEXT_PROXY_DISALLOW 0

test/browser/emmalloc_memgrowth.cpp

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,30 @@
55
uint64_t nextAllocationSize = 16*1024*1024;
66
bool allocHasFailed = false;
77

8-
void grow_memory()
9-
{
10-
uint8_t *ptr = (uint8_t*)malloc((size_t)nextAllocationSize);
11-
EM_ASM({}, ptr); // Pass ptr out to confuse LLVM that it is used, so it won't optimize it away in -O1 and higher.
12-
size_t heapSize = emscripten_get_heap_size();
13-
printf("Allocated %zu: %d. Heap size: %zu\n", (size_t)nextAllocationSize, ptr ? 1 : 0, heapSize);
14-
if (ptr)
15-
{
16-
if (!allocHasFailed)
17-
{
18-
nextAllocationSize *= 2;
19-
// Make sure we don't overflow, and also exercise malloc(-1) to gracefully return 0 in ABORTING_MALLOC=0 mode.
20-
if (nextAllocationSize > 0xFFFFFFFFULL)
21-
nextAllocationSize = 0xFFFFFFFFULL;
22-
}
23-
}
24-
else
25-
{
26-
nextAllocationSize /= 2;
27-
allocHasFailed = true;
28-
}
8+
void grow_memory() {
9+
uint8_t *ptr = (uint8_t*)malloc((size_t)nextAllocationSize);
10+
EM_ASM({}, ptr); // Pass ptr out to confuse LLVM that it is used, so it won't optimize it away in -O1 and higher.
11+
size_t heapSize = emscripten_get_heap_size();
12+
printf("Allocated %zu: %d. Heap size: %zu\n", (size_t)nextAllocationSize, ptr ? 1 : 0, heapSize);
13+
if (ptr) {
14+
if (!allocHasFailed) {
15+
nextAllocationSize *= 2;
16+
// Make sure we don't overflow, and also exercise malloc(-1) to gracefully return 0 in ABORTING_MALLOC=0 mode.
17+
if (nextAllocationSize > 0xFFFFFFFFULL)
18+
nextAllocationSize = 0xFFFFFFFFULL;
19+
}
20+
} else {
21+
nextAllocationSize /= 2;
22+
allocHasFailed = true;
23+
}
2924
}
3025

31-
int main()
32-
{
33-
// Exhaust all available memory.
34-
for(int i = 0; i < 50; ++i)
35-
grow_memory();
36-
// If we get this far without crashing on OOM, we are ok!
37-
printf("Test finished!\n");
38-
#ifdef REPORT_RESULT
39-
REPORT_RESULT(0);
40-
#endif
26+
int main() {
27+
// Exhaust all available memory.
28+
for(int i = 0; i < 50; ++i) {
29+
grow_memory();
30+
}
31+
// If we get this far without crashing on OOM, we are ok!
32+
printf("Test finished!\n");
33+
return 0;
4134
}

test/browser/webgl_create_context.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ void loop() {
6060
assert(emscripten_webgl_get_current_context() == 0);
6161
context = emscripten_webgl_create_context("#canvas", &attrs);
6262

63-
assert(context > 0); // Must have received a valid context.
63+
assert(context != NULL); // Must have received a valid context.
6464
res = emscripten_webgl_make_context_current(context);
6565
assert(res == EMSCRIPTEN_RESULT_SUCCESS);
6666
assert(emscripten_webgl_get_current_context() == context);
@@ -104,7 +104,7 @@ int main() {
104104

105105
assert(emscripten_webgl_get_current_context() == 0);
106106
EMSCRIPTEN_WEBGL_CONTEXT_HANDLE context = emscripten_webgl_create_context("#customCanvas", &attrs);
107-
assert(context > 0); // Must have received a valid context.
107+
assert(context != NULL); // Must have received a valid context.
108108
EMSCRIPTEN_RESULT res = emscripten_webgl_make_context_current(context);
109109
assert(res == EMSCRIPTEN_RESULT_SUCCESS);
110110
assert(emscripten_webgl_get_current_context() == context);

test/fs/test_idbfs_sync.c

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,17 @@
1515

1616
int result = 1;
1717

18-
void success()
19-
{
18+
void success() {
2019
REPORT_RESULT(result);
2120
#ifdef FORCE_EXIT
2221
emscripten_force_exit(0);
2322
#endif
2423
}
2524

2625
void test() {
27-
2826
int fd;
2927
struct stat st;
30-
28+
3129
#if FIRST
3230

3331
// for each file, we first make sure it doesn't currently exist
@@ -49,22 +47,20 @@ void test() {
4947
fd = open("/working1/waka.txt", O_RDWR | O_CREAT, 0666);
5048
if (fd == -1)
5149
result = -5000 - errno;
52-
else
53-
{
50+
else {
5451
if (write(fd,"az",2) != 2)
5552
result = -6000 - errno;
5653
if (close(fd) != 0)
5754
result = -7000 - errno;
5855
}
59-
56+
6057
// a file whose contents are random-ish string set by the test_browser.py file
6158
if ((stat("/working1/moar.txt", &st) != -1) || (errno != ENOENT))
6259
result = -8000 - errno;
6360
fd = open("/working1/moar.txt", O_RDWR | O_CREAT, 0666);
6461
if (fd == -1)
6562
result = -9000 - errno;
66-
else
67-
{
63+
else {
6864
if (write(fd, SECRET, strlen(SECRET)) != strlen(SECRET))
6965
result = -10000 - errno;
7066
if (close(fd) != 0)
@@ -92,8 +88,7 @@ void test() {
9288
fd = open("/working1/waka.txt", O_RDONLY);
9389
if (fd == -1)
9490
result = -17000 - errno;
95-
else
96-
{
91+
else {
9792
char bf[4];
9893
int bytes_read = read(fd,&bf[0],sizeof(bf));
9994
if (bytes_read != 2)
@@ -105,19 +100,17 @@ void test() {
105100
if (unlink("/working1/waka.txt") != 0)
106101
result = -21000 - errno;
107102
}
108-
103+
109104
// does the random-ish file exist and does it contain SECRET?
110105
fd = open("/working1/moar.txt", O_RDONLY);
111-
if (fd == -1)
106+
if (fd == -1) {
112107
result = -22000 - errno;
113-
else
114-
{
108+
} else {
115109
char bf[256];
116110
int bytes_read = read(fd,&bf[0],sizeof(bf));
117-
if (bytes_read != strlen(SECRET))
111+
if (bytes_read != strlen(SECRET)) {
118112
result = -23000;
119-
else
120-
{
113+
} else {
121114
bf[strlen(SECRET)] = 0;
122115
if (strcmp(bf,SECRET) != 0)
123116
result = -24000;
@@ -129,14 +122,13 @@ void test() {
129122
}
130123

131124
// does the directory exist?
132-
if (stat("/working1/dir", &st) != 0)
125+
if (stat("/working1/dir", &st) != 0) {
133126
result = -27000 - errno;
134-
else
135-
{
127+
} else {
136128
if (!S_ISDIR(st.st_mode))
137129
result = -28000;
138-
if (rmdir("/working1/dir") != 0)
139-
result = -29000 - errno;
130+
if (rmdir("/working1/dir") != 0)
131+
result = -29000 - errno;
140132
}
141133

142134
#endif
@@ -164,20 +156,18 @@ void test() {
164156
ccall('success', 'v');
165157
});
166158
);
167-
168159
}
169160

170161
int main() {
171-
172162
EM_ASM(
173163
FS.mkdir('/working1');
174164
FS.mount(IDBFS, {}, '/working1');
175165

176166
#if !FIRST
177-
// syncfs(true, f) should not break on already-existing directories:
178-
FS.mkdir('/working1/dir');
167+
// syncfs(true, f) should not break on already-existing directories:
168+
FS.mkdir('/working1/dir');
179169
#endif
180-
170+
181171
// sync from persisted state into memory and then
182172
// run the 'test' function
183173
FS.syncfs(true, function (err) {
@@ -187,6 +177,5 @@ int main() {
187177
);
188178

189179
emscripten_exit_with_live_runtime();
190-
191180
return 0;
192181
}

0 commit comments

Comments
 (0)