course_os
course_os copied to clipboard
Kernel "libc"
We will need a restricted set of libc-like functions in the kernel. E.g., some way of printing output for debugging, some initial way of dynamically allocating memory a la kmalloc, etc.
From some cursory research it seems like this will take a bit of mucking around in assembly to get the basic library routines up. Is that correct?
It might possibly involve some assembly but I would think that the majority is in C.
We're not reinventing the wheel here, so we'll be able to use things like stdlib.h to construct this libc? I think I would be interested in working on this.
Well, we cannot use code from glibc or alike that because of license issues but we can take code from musl-libc (http://www.musl-libc.org) which is under MIT license.
However, for the kernel we should focus on only the library functions that we really need since the library is only needed inside the kernel and nowhere else. For some that we will need, e.g., a way for the kernel to print debug output, we can discuss how we want them because it does not necessarily have to be printf. Just to give an example, some people (most prominently the designers of Solaris) believe that kernel code should not support variable length strings for reliability and security reasons, etc.
I would like to request a string compare function like memcmp. All it does is compare two strings of bytes.
So we are allowed to use anything from the musl library? Once it is added to the repo that is.
Yes, if we want certain functionality from it we can pull it in. Just make sure that all copyright headers are left in place to correctly attribute the authorship of the code.
Do you guys need any help with this? Jeremy and I are trying to write the ELF parser, but we can't do anything until we have libc finished.
Hi guys... First off, my apologies. I've been dealing with a lot of family stuff recently (brother in hospital, thousands of miles in road trips to deal with these issues), and I've fallen behind. Any help would be welcome, primarily if you could identify the key functionality you need from the library to get the parser to work. I will focus on getting those items completed. Again, my apologies for dropping the ball on this one...
For the argument parser, all we need at the moment is a memory comparing function like memcmp so that we can compare two strings. I'll let you know if the parser needs anything else.
Would memcmp and strcmp be helpful? I'll get those added in ASAP.
memcmp and strmp added. Config.mk and makefile updated, Make run works. Added COPYRIGHT, since I used and made minor changes to the musl-libc.
Hey, no worries. For the ELF parser, we mainly need read and print functionality.
Read as the IO call? I don't think we will have this any time soon, it requires an IO subsystem. I would think that in the first phase you can consider the program binary to be mapped into memory and you will get a pointer to the start.
Thanks for adding those two functions. Do you think you could push your changes so I can use them?
Ok, I merged the header and source for libc to master. Please make sure to read the comments in the files. To avoid conflict with existing functions, I prepended the functions with os_, so to call strcmp, you'd use os_strcmp
I've been thinking that a function to split a string (like strtok) may be useful. Is that something that should be in our libc?
If you have a use for it, you should add it or ask the klibc maintainers to add it.
Would it be alright with you guys (the people working on libc) if I went ahead and added strtok or something like it from MUSL?
I'll add strtok. Anything else you would like to request while I'm at it?
I think memcpy (or a function that copies a region of memory from one location to another) could be useful.
^That was an accident, sorry.
I'll try to get this done today (along with strtok if it's not there already).
Are you guys still working on klibc? I wouldn't mind adding strtok from MUSL myself if that's alright with you guys.
I've added a couple of functions from MUSL to klibc. However, I think strtok is not working properly, so I'm going try to figure out what the problem is.
Hey Sheldon, thanks for picking up the slack on this. I'm still dealing with a lot of family stuff, so it is much appreciated.
Is there anything that is critical right now that I can resume working on?
@SheldonSandbekkhaug I wrote a strtok in our test_framework branch. It doesn't work yet, but I could send it to you if you want.
ascensionra, no problem! I just want to get things done, you know? :)
SUMDude21, I had copied the strtok from MUSL. I put it in klibc.c under os_strtok(). It turns out the problem with strtok was actually in strspn and strcspn (for some reason, those work in desktop Linux but not in CourseOS on the virtual machine). I just replaced the MUSL versions of strspn and strcspn with functions I wrote myself, so there may be hidden bugs that I haven't found yet. See commit d3615e93fd74f7aa51a1ed5bf09eadf3ade7d771
@SheldonSandbekkhaug All right I'll write some tests for them, anything else I can help with?
I can't think of anything at the moment, though things will come up, except if you ever need to use a library function in the kernel, just add it from MUSL if you can!