lai icon indicating copy to clipboard operation
lai copied to clipboard

FIX: Move the `mem*` functions to `laihost_mem*` functions.

Open TheDarkBomber opened this issue 3 years ago • 3 comments

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.

TheDarkBomber avatar Sep 27 '22 17:09 TheDarkBomber

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.

avdgrinten avatar Sep 27 '22 17:09 avdgrinten

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

ArsenArsen avatar Sep 27 '22 17:09 ArsenArsen

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.

thomtl avatar Sep 27 '22 19:09 thomtl