-
Notifications
You must be signed in to change notification settings - Fork 113
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
Haiku support proposal. #218
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
#pragma once | ||
|
||
#if defined(__HAIKU__) | ||
# include "pal_posix.h" | ||
|
||
# include <sys/mman.h> | ||
|
||
namespace snmalloc | ||
{ | ||
/** | ||
* Platform abstraction layer for Haiku. This provides features for this | ||
* system. | ||
*/ | ||
class PALHaiku : public PALPOSIX<PALHaiku> | ||
{ | ||
public: | ||
/** | ||
* Bitmap of PalFeatures flags indicating the optional features that this | ||
* PAL supports. | ||
* | ||
*/ | ||
static constexpr uint64_t pal_features = PALPOSIX::pal_features; | ||
|
||
/** | ||
* Notify platform that we will not be needing these pages. | ||
* Haiku does not provide madvise call per say only the posix equivalent. | ||
*/ | ||
void notify_not_using(void* p, size_t size) noexcept | ||
{ | ||
SNMALLOC_ASSERT(is_aligned_block<page_size>(p, size)); | ||
posix_madvise(p, size, POSIX_MADV_DONTNEED); | ||
davidchisnall marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
/** | ||
* OS specific function for zeroing memory | ||
* using MAP_NORESERVE for explicit over commit appliance. | ||
*/ | ||
template<bool page_aligned = false> | ||
void zero(void* p, size_t size) | ||
{ | ||
if (page_aligned || is_aligned_block<page_size>(p, size)) | ||
{ | ||
SNMALLOC_ASSERT(is_aligned_block<page_size>(p, size)); | ||
void* r = mmap( | ||
p, | ||
size, | ||
PROT_READ | PROT_WRITE, | ||
MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED | MAP_NORESERVE, | ||
-1, | ||
0); | ||
|
||
if (r != MAP_FAILED) | ||
return; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can't find documentation for the Haiku mmap call. Does it guarantee that the existing mapping is left in place if the map fails? |
||
} | ||
|
||
bzero(p, size); | ||
} | ||
|
||
/** | ||
* Reserve memory using MAP_NORESERVE for explicit | ||
* over commit applicance. | ||
*/ | ||
std::pair<void*, size_t> reserve_at_least(size_t size) | ||
davidchisnall marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
constexpr size_t min_size = | ||
bits::is64() ? bits::one_at_bit(32) : bits::one_at_bit(28); | ||
auto size_request = bits::max(size, min_size); | ||
|
||
void* p = mmap( | ||
nullptr, | ||
size_request, | ||
PROT_READ | PROT_WRITE, | ||
MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE, | ||
-1, | ||
0); | ||
|
||
if (p == MAP_FAILED) | ||
error("Out of memory"); | ||
|
||
return {p, size_request}; | ||
} | ||
}; | ||
} // namespace snmalloc | ||
#endif |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please can you leave a comment explaining this? Is there a Haiku TLS ABI doc that you can point at?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really but found out a bunch of complains about the same issue I ve faced. Haiku at large is not too well documented, kind of small community driven os project.