Skip to content
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

Conversion from function pointer to void* isn't portable #8

Closed
othias opened this issue Oct 3, 2018 · 1 comment
Closed

Conversion from function pointer to void* isn't portable #8

othias opened this issue Oct 3, 2018 · 1 comment

Comments

@othias
Copy link

othias commented Oct 3, 2018

Hi :)

Thank you for your library, one minor nitpick though: the plthook_replace function takes the function pointer as a void*, and that conversion isn't guaranteed to work per C11 standard, 6.3.2.3 §1 :

"A pointer to void may be converted to or from a pointer to any object type. A pointer to any object type may be converted to a pointer to void and back again; the result shall compare equal to the original pointer."

So the conversion from/to void* is only guaranteed to work for object pointers, it says nothing about function pointers. However, (C11 standard, 6.3.2.3 §8) :

"A pointer to a function of one type may be converted to a pointer to a function of another type and back again; the result shall compare equal to the original pointer."

So an easy fix could be to change void* to void (*)(void), which could be typedef'd to something like plthook_func or similar.

Thanks!

@kubo
Copy link
Owner

kubo commented Feb 17, 2019

Thanks for pointing it. I confirmed what you quoted in the C11 final draft.

However I don't change the pointer type. That's because:
(1) plthook itself isn't portable. It works only on limited platforms. So I don't care whether the conversion is portable or not on unsupported platforms.
(2) This tool is based on the technique which isn't guaranteed to work; changing PLT entries in a running process. So I don't care whether the conversion is guaranteed or not as long as it works fine. It is small issue compared with the tool's basis,
(3) Other tools, such as Microsoft Detours, use void *.

Well, I'll change my thought when a real-world compiler cannot convert void* to a pointer to a function or vise versa.

@kubo kubo closed this as completed Feb 17, 2019
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

No branches or pull requests

2 participants