Skip to content
Open
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
2 changes: 1 addition & 1 deletion context/cocore.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#if !defined(__APPLE__)
#if !(defined(__APPLE__) || defined(__OpenBSD__))
#include <malloc.h>
#endif
#include <assert.h>
Expand Down
8 changes: 8 additions & 0 deletions context/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@
#define MALLOC_ALIGNED(alignment, size) valloc(size)
#define FREE_ALIGNED(mem) free(mem)

#elif defined(__OpenBSD__)
/* OpenBSD stack memory has to be specially allocated with mmap() */
#define MALLOC_ALIGNED(alignment, size) \
mmap(NULL, size, PROT_READ | PROT_WRITE, \
MAP_ANONYMOUS | MAP_PRIVATE | MAP_STACK, -1, 0)
#define FREE_ALIGNED(mem) ((void) 0)
/* XXX will leak memory; maybe won't crash with short-lived processes */
Comment on lines +70 to +71

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, here's the short form. Try:

#define FREE_ALIGNED(mem, length)  munmap(mem, length)

and make all the associated required changes (including adding length to all the other #defines and fixing the call), and see if this works.

This is more expensive than malloc/free ... but then we're doing system calls for the guard pages anyway, so this is probably ok.


#elif defined(WIN32)
/* This is what we have to use on 32-bit Windows. */
#define MALLOC_ALIGNED(alignment, size) \
Expand Down
Loading