Skip to content

quirc image memory page alignment #122

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

graindcafe
Copy link

This PR make quirc use mmap instead of calloc to allocate memory of quirc->image.
The use case I have for this is to be able to use mmap() on the application side with the flag MAP_FIXED and memory address given by quirc. The image I capture is accessible in a dmabuf, I access it by using mmap() with the dmabuf’s fd. With quirc using calloc(), my call to mmap() fails because of non-aligned memory page.
Instead of calloc/free, this PR proposes to use mmap/munmap.
I believe this does not alter the behaviour of quirc.

@dlbeer
Copy link
Owner

dlbeer commented Dec 27, 2021

This is a good idea. However:

  • mmap() returns MAP_FAILED on error, not NULL

  • Windows is a supported platform for quirc, so you'll need to either use something platform-independent or introduce a pair of portable wrappers that use mmap/munmap on Unix and whatever's appropriate on Windows.

Another alternative may be to continue using malloc, but to over-allocate by PAGE_SIZE, so that you guarantee yourself room to shift to a page-aligned address within the allocated block.

@graindcafe
Copy link
Author

graindcafe commented Dec 27, 2021

Thanks for the review, gonna fix this.

Do you think it's okay to revert to previous calloc/free for windows with some preprocessor checks? Not sure if it's relevant to have page alignment for Windows, but in such a case maybe I should use _aligned_malloc.

@dlbeer
Copy link
Owner

dlbeer commented Dec 27, 2021 via email

alfrentgen pushed a commit to alfrentgen/quirc that referenced this pull request Feb 28, 2022
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.

2 participants