Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
41 lines (38 loc) · 1.03 KB

File metadata and controls

41 lines (38 loc) · 1.03 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <stdio.h>
#include <stdlib.h>
#include <emscripten/heap.h>
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;
}
}
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
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.