Skip to content

Fix pal_memory.c on OpenBSD#125010

Open
sethjackson wants to merge 1 commit intodotnet:mainfrom
sethjackson:fix-pal-memory
Open

Fix pal_memory.c on OpenBSD#125010
sethjackson wants to merge 1 commit intodotnet:mainfrom
sethjackson:fix-pal-memory

Conversation

@sethjackson
Copy link
Contributor

OpenBSD does not have an implementation of MALLOC_SIZE so reuse the TARGET_SUNOS one.

#define MALLOC_SIZE(s) malloc_usable_size(s)
#elif defined(TARGET_SUNOS)
#elif defined(TARGET_OPENBSD) || defined(TARGET_SUNOS)
#define MALLOC_SIZE(s) (*((size_t*)(s)-1))
Copy link
Member

Choose a reason for hiding this comment

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

Does this implementation actually work on OpenBSD?

Copy link
Contributor Author

@sethjackson sethjackson Feb 28, 2026

Choose a reason for hiding this comment

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

Now that I look at it again - no I do not think it will at all.

I don't think there is any implementation of malloc_size that will work. A bit unsure how to proceed here?

Copy link
Member

Choose a reason for hiding this comment

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

This is only need for efficient implementation of aligned realloc. You should be able to provide less efficient implementation that does not depend on malloc_size

Copy link
Member

Choose a reason for hiding this comment

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

(Every C allocator has to know the size internally to support realloc. It is unfortunate that OpenBSD does not expose it as an API. they have it as an internal macro only https://github.com/libressl/openbsd/blob/master/src/lib/libc/stdlib/malloc.c#L328-L330 .)

@jkotas jkotas added the os-openbsd OpenBSD OS, currently not officially supported label Feb 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-PAL-coreclr community-contribution Indicates that the PR has been added by a community member os-openbsd OpenBSD OS, currently not officially supported

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants