Skip to content
This repository was archived by the owner on Feb 5, 2024. It is now read-only.

Alignment guarantees of malloc #4

Open
krtab opened this issue Jan 16, 2024 · 4 comments
Open

Alignment guarantees of malloc #4

krtab opened this issue Jan 16, 2024 · 4 comments

Comments

@krtab
Copy link

krtab commented Jan 16, 2024

void *malloc(size_t size) {
unsigned int r = bump_pointer;
/* for (int i = 0; i < size; ++i) */
/* *((unsigned char *)bump_pointer + i) = 'i'; */
bump_pointer += size;
return (void *)owi_malloc(r, size);
}

We currently make no guarantee on the returned pointer alignment. Malloc's pointer alignment seems not to be completely clearly defined, and even less clearly implemented, but it is reasonable for a C programmer on x64 to expect malloc(8) to return an 8-aligned pointer.

@krtab
Copy link
Author

krtab commented Jan 16, 2024

@filipeom : Eric volunteers to fix it and I'll mentor him if it is fine with you.

@filipeom
Copy link
Member

Malloc's pointer alignment seems not to be completely clearly defined, and even less clearly implemented

Yes you are correct, we do not implement nor have any mechanism to guarantee pointer alignment.

Eric volunteers to fix it and I'll mentor him if it is fine with you.

Of course! Thank you so much! 😃

@filipeom
Copy link
Member

I don't know if you saw, but this c frontend is moving to owi directly: OCamlPro/owi#100. We might have to patch this there as well

@epatrizio
Copy link

Thanks @filipeom @krtab !
It helps me to understand the interface between Owi symbolic and C language
OCamlPro/owi#104

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants