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

FIX: Move the mem* functions to laihost_mem* functions. #130

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

Conversation

TheDarkBomber
Copy link

Currently, the functions memcpy, memset, memcmp, and memmove (not necessarily in that order) are declared directly in one of LAI's header files. This can cause conflicts if the kernel has already declared these functions.

To rectify this, this pull request changes those functions into functions required by the host. If the kernel has a standards-compliant implementation of these functions, they can easily integrate these into its LAI bindings by appending the following linker script:

laihost_memcpy = memcpy;
laihost_memset = memset;
laihost_memcmp = memcmp;
laihost_memmove = memmove;

This change will also make the behaviour of the LAI API more consistent, as other C standard functions are defined as host functions in LAI, such as malloc, realloc, and free; which a kernel developer would use a linker script to define the LAI bindings for.

These functions are highly likely to be included in operating
system kernels already. By prefixing these with lai_, this
prevents any conflicts and allows the kernel to be built
when including both LAI headers and the header containing
the kernel's `mem*` functions.
Requiring the host to implement these functions further emphasises
the point made in the previous commit.
@avdgrinten
Copy link
Member

avdgrinten commented Sep 27, 2022

This can cause conflicts if the kernel has already declared these functions.

What kind of conflicts? AFAICT lai declares these functions but it does not provide definitions.

@ArsenArsen
Copy link
Member

if a given definition of mem* conflicts with the one in lai, it's likely the wrong definition, and also, I'm decently sure the header declaring these isn't public anyway. adding new laihost symbols for functions that are de-facto standardized by gcc requiring them seems unuseful. what problem did you observe in practice that this solves? maybe there's a better solution

@thomtl
Copy link
Member

thomtl commented Sep 27, 2022

GCC requires these functions to be implemented in freestanding anyway,

Most of the compiler support routines used by GCC are present in libgcc, but there are a few exceptions. GCC requires the freestanding environment provide memcpy, memmove, memset and memcmp. Finally, if __builtin_trap is used, and the target does not implement the trap pattern, then GCC emits a call to abort.

From: https://gcc.gnu.org/onlinedocs/gcc/Standards.html#Standards

The reason the distinction between these and malloc is made, is because many kernels have different and nonstandard implementations of malloc.

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