Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

erts: Fix global literal to correctly use erts_mem_guard #8964

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions erts/emulator/beam/erl_global_literals.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,20 +122,21 @@ Eterm *erts_global_literal_allocate(Uint heap_size, struct erl_off_heap_header *
expand_shared_global_literal_area(heap_size + GLOBAL_LITERAL_EXPAND_SIZE);
}

*ohp = &global_literal_chunk->area.off_heap;
hp = global_literal_chunk->hp;
global_literal_chunk->hp += heap_size;

#ifdef DEBUG
{
struct global_literal_chunk *chunk = global_literal_chunk;
erts_mem_guard(&chunk->area.start[0],
(chunk->area.end - &chunk->area.start[0]) * sizeof(Eterm),
erts_mem_guard(chunk,
(chunk->area.end - (Eterm*)chunk) * sizeof(Eterm),
1,
1);
}
#endif


*ohp = &global_literal_chunk->area.off_heap;
hp = global_literal_chunk->hp;
global_literal_chunk->hp += heap_size;

return hp;
}

Expand All @@ -145,8 +146,8 @@ void erts_global_literal_register(Eterm *variable, Eterm *hp, Uint heap_size) {
#ifdef DEBUG
{
struct global_literal_chunk *chunk = global_literal_chunk;
erts_mem_guard(&chunk->area.start[0],
(chunk->area.end - &chunk->area.start[0]) * sizeof(Eterm),
erts_mem_guard(chunk,
(chunk->area.end - (Eterm*)chunk) * sizeof(Eterm),
1,
0);
}
Expand Down
6 changes: 5 additions & 1 deletion erts/emulator/sys/common/erl_mmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@
#endif

int erts_mem_guard(void *p, UWord size, int readable, int writable) {

#if defined(WIN32)
DWORD oldProtect;
DWORD newProtect = PAGE_NOACCESS;
BOOL success;

if (readable && writable) {
newProtect = PAGE_READWRITE;
} else if (readable) {
Expand All @@ -53,6 +54,9 @@ int erts_mem_guard(void *p, UWord size, int readable, int writable) {
return success ? 0 : -1;
#elif defined(HAVE_SYS_MMAN_H)
int flags = 0;

/* Check that the ptr is aligned at page boundary */
ASSERT((Uint)p % sys_page_size == 0);

if (writable) {
flags |= PROT_WRITE;
Expand Down
Loading