Skip to content

Make sure pointers are correctly aligned in os_mmap_aligned() #84

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

Conversation

ldorau
Copy link
Contributor

@ldorau ldorau commented Dec 20, 2023

@ldorau ldorau requested a review from a team as a code owner December 20, 2023 09:06
@ldorau ldorau force-pushed the Make_sure_pointers_are_correctly_aligned_in_os_mmap_aligned branch from 58d296a to 23a96a5 Compare December 20, 2023 09:09
@ldorau
Copy link
Contributor Author

ldorau commented Dec 20, 2023

@igchor

@bratpiorka bratpiorka requested a review from igchor December 20, 2023 10:01

size_t head_len = aligned_addr - addr;
if (head_len > 0) {
// head_len has to be page-aligned, because aligned_addr has to be page-aligned
assert_is_page_aligned(head_len, page_size);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we just crash? Assert indicates a mistake in the code logic. Is this condition only possible by mistake? what if the page size 4kb and the requested alignment 6kb?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Code changed.
Done.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

BTW tests added in a separate PR: #93

Copy link
Member

Choose a reason for hiding this comment

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

I still only see asserts and not the INVALID_ARGUMENT error code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Assert indicates a mistake in the code logic. Those conditions are possible only by mistake.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I meant those asserts verify if os_alloc() passed a correct alignment. A user cannot trigger them changing the input alignment. All required checks are done in os_alloc() and os_alloc() passes only a correct alignment to this function. So IMHO those asserts are correct.

Copy link
Member

Choose a reason for hiding this comment

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

Ah yes, sorry, I missed the PR that changed the checks in os_alloc.

@ldorau ldorau force-pushed the Make_sure_pointers_are_correctly_aligned_in_os_mmap_aligned branch from c834b71 to 192d1df Compare December 21, 2023 15:02
@ldorau
Copy link
Contributor Author

ldorau commented Dec 21, 2023

@ldorau ldorau force-pushed the Make_sure_pointers_are_correctly_aligned_in_os_mmap_aligned branch from 192d1df to f3ede04 Compare December 21, 2023 15:16
@ldorau
Copy link
Contributor Author

ldorau commented Dec 21, 2023

Rebased

@ldorau ldorau merged commit 8853ffd into oneapi-src:main Dec 22, 2023
@ldorau ldorau deleted the Make_sure_pointers_are_correctly_aligned_in_os_mmap_aligned branch December 22, 2023 09:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants