Open no92 opened 9 months ago
Hi @no92,
I would love to contribute here, but I still have some questions regarding portability issues.
The goal is to implement the mincore
function. Does it require a specific implementation for different sysdeps, or could one generic implementation suffice?
Additionally, it's possible that I lack knowledge in these subjects, but I am eager to learn. I have a strong background in C, and with a bit more context, I'm confident that I can make a meaningful contribution here!
Let me know! :)
We'd want to leave the actual implementation up to sysdeps. E.g. on Linux mincore
is implemented via a system call, and other systems probably want to do their own thing.
Okay, I see. Totally makes sense!
So here the goal would be to implement the function for all supported os ?
That's kinda out of scope for mlibc, I think Linux is the only system we support that currently implements an mincore
syscall, and implementing it ourselves for everyone else would be quite a bit of work on our side. I don't think this even can be implemented without OS support, since it checks for page residency (whether accessing it will not require allocation or loading data from disk), not whether the page is mapped in in general, and pages becoming non-resident is supposed to be transparent, apart from maybe the time it takes to load it back in.
How mlibc deals with this is via sysdeps, which house the system-specific functions required by the various generic libc functions. Most sysdep functions are marked [[gnu::weak]]
, which means that if they're missing, they resolve to NULL at link time. The actual function that uses the sysdep then checks if that's the case, and if so, bails out with an ENOSYS
error (or whatever's appropriate). Once a particular system adds a way to provide the sysdep for mincore
, it can be added, and the generic function will just work on it.
Also, I've just had a look, and we apparently have mincore
in mlibc itself? I might be missing something, but perhaps @no92 meant to make this issue on the Managarm repo? It'd still be appreciated if you took up the task of doing that, but that's probably gonna be a more involved project than just the mlibc side and the Linux sysdep. I apologize for the confusion if that's the case!
Yeah I didn't notice the linux sysdep. I guess it would be nice to implement it for managarm, as we don't have many cases where a page wouldn't be resident in memory that shouldn't be too hard™.
@no92 so it would not be in this repo but on the Managarm's one ?
Managarm's sysdeps are implemented in this repo, under sysdeps/managarm
.
Okay, and you think that it's a good first issue ? @no92
Implementing mincore for linux, managarm and probably most other sysdeps should be trivial and would fix warnings with some GTK apps.