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

cgmemmgr,macos: add missing shared_map_lock initialization #47419

Merged
merged 1 commit into from
Nov 2, 2022
Merged
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
12 changes: 8 additions & 4 deletions src/cgmemmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,12 @@ static _Atomic(size_t) map_offset{0};
// Hopefully no one will set a ulimit for this to be a problem...
static constexpr size_t map_size_inc_default = 128 * 1024 * 1024;
static size_t map_size = 0;
static uv_mutex_t shared_map_lock;
static struct _make_shared_map_lock {
uv_mutex_t mtx;
_make_shared_map_lock() {
uv_mutex_init(&mtx);
};
} shared_map_lock;

static size_t get_map_size_inc()
{
Expand Down Expand Up @@ -264,7 +269,7 @@ static void *alloc_shared_page(size_t size, size_t *id, bool exec)
*id = off;
size_t map_size_inc = get_map_size_inc();
if (__unlikely(off + size > map_size)) {
uv_mutex_lock(&shared_map_lock);
uv_mutex_lock(&shared_map_lock.mtx);
size_t old_size = map_size;
while (off + size > map_size)
map_size += map_size_inc;
Expand All @@ -275,7 +280,7 @@ static void *alloc_shared_page(size_t size, size_t *id, bool exec)
abort();
}
}
uv_mutex_unlock(&shared_map_lock);
uv_mutex_unlock(&shared_map_lock.mtx);
}
return create_shared_map(size, off);
}
Expand Down Expand Up @@ -313,7 +318,6 @@ ssize_t pwrite_addr(int fd, const void *buf, size_t nbyte, uintptr_t addr)
// Use `get_self_mem_fd` which has a guard to call this only once.
static int _init_self_mem()
{
uv_mutex_init(&shared_map_lock);
struct utsname kernel;
uname(&kernel);
int major, minor;
Expand Down