Commit Graph

49 Commits

Author SHA1 Message Date
b63a9f5ba9 Kernel: Improve strdup_from_user and add copy to and from user
Still a bit funky, that's why we're not using it in read() and write() yet.
2022-11-05 11:54:55 +01:00
ffcaac0ca3 Kernel: Add validate_user_write() and validate_user_read()
Not at copy_from_user and copy_to_user yet, but an improvement over blindly using physical memory.
2022-11-04 22:46:48 +01:00
249c79f8a3 Kernel, libc: Add ioctl()
Right now, only the framebuffer supports this system call, to query its dimensions.
2022-11-02 20:59:42 +01:00
feab66c0d3 Kernel: Remove the paint() system call
That was a very old one from back in the old days. Now that the framebuffer is finally a device file,
and it can be memory-mapped by user programs for more performance,
this syscall is MORE than obsolete.
2022-11-02 20:35:06 +01:00
8f2308c80d Kernel: Implement mmap-able device files (regular files are not mmap-able yet) 2022-11-02 20:24:07 +01:00
52d4f34f05 Kernel, libc: Implement umask() 2022-10-30 19:55:38 +01:00
688a640a16 Kernel: Add the clock_gettime syscall, which replaces clock as it can be used for more stuff 2022-10-30 09:07:59 +01:00
1c4f1ab867 Kernel, libc: Add setuid() and setgid() system calls 2022-10-28 17:19:26 +02:00
26b20938de Kernel, libc: Use mode in mkdir() 2022-10-28 17:11:35 +02:00
1c35eabb2b open(): Add a third optional mode argument 2022-10-27 07:52:57 +02:00
7d20c507b1 Kernel, libc, userspace: Implement command-line arguments (argv)
The only thing missing now is for sh to pass them on.
2022-10-26 18:57:06 +02:00
af452e2b2a Kernel, libc: Add dup2() 2022-10-25 18:58:06 +02:00
58b01b74e2 Kernel, libc: Add stat() 2022-10-23 18:35:32 +02:00
78d72c2f0c Kernel, libc: Add a getdents() system call
This is meant to be a low-level interface to implement dirent.h on top of.
2022-10-23 14:03:46 +02:00
bcdcfc4b45 Kernel: Add a pstat() system call
Not part of C or POSIX, but since there is no procfs right now, I thought it would be nice to have an interface to query process information.
It works like this: you pass the process ID and a pointer to a struct pstat (can be null).
If the process ID is -1, the kernel picks the process with the highest PID.
Then, if the pointer to a pstat struct is not null, the kernel fills it in with the process's information, and returns the process's PID.
2022-10-22 14:26:29 +02:00
fcf191aa7a Kernel, libc: Add fstat() 2022-10-21 18:31:09 +02:00
f7cf395f71 Kernel, libc: Add access() 2022-10-20 19:03:24 +02:00
27448611b3 UserMemory: do not map refs into kernel memory
This is bad design. But it fails if mapped, since something overwrites KernelHeap.
2022-10-20 18:50:07 +02:00
48d4a5910a Kernel: Add a few convenience functions to manipulate userland memory 2022-10-19 17:13:16 +02:00
671f2a2de3 Kernel, libc: Implement waitpid()
FIXME: exec() is now doing weird page table stuff. But at least it works, no panics :)
2022-10-18 21:30:52 +02:00
52d391507d Kernel: Rename the getpid() syscall to getprocid()
Now, we have one single system call to fetch all sorts of identifiers:
PID, PPID, UID, GID; EUID, EGID, and more...
2022-10-18 17:36:17 +02:00
8b17065718 Kernel, libc: Rename gettid() to getpid() and move it to unistd.h 2022-10-17 20:08:44 +02:00
87ef210759 Kernel, libc: Remove spawn()
Now, fork() and exec() are both implemented. More POSIX-y, thus spawn can be removed.
2022-10-17 19:55:01 +02:00
64f5078494 Kernel, libc: Implement fork()
This time for real.

Also, add a new per-user-task virtual address allocator (UserHeap), so that mmap'ed pages are in user range and can be copied.
2022-10-17 18:43:35 +02:00
9b39d618de Kernel, libc: Implement spawn()
This function is a Luna alternative to fork() and exec().

Why? Simply because I can't figure out for the life of me how to implement a working fork().

So meanwhile, we have spawn() as a replacement. exec() still exists, though.
2022-10-16 18:48:35 +02:00
d2e2883a79 Kernel: Make mkdir() accessible to userspace 2022-10-16 17:22:12 +02:00
62a2bcf2ff Kernel: Add a clock() system call 2022-10-15 13:17:26 +02:00
3a9dddaa57 Kernel, libc: Remove the rand() system call
That's why we now have a VFS and a /dev pseudo-filesystem. To provide that kind of things.

Remember, everything is a file!!

The new way to ask the kernel for random numbers is to read from /dev/random.
2022-10-15 13:04:48 +02:00
613f8170b6 Kernel, libc: Implement mprotect() and use proper PROT_* values 2022-10-15 12:57:14 +02:00
5c61252061 Kernel: Add a new fcntl() system call 2022-10-15 10:56:06 +02:00
5d41b4b113 Almost there...
exec() is not working yet. But the rest are!!
2022-10-13 22:13:04 +02:00
9cddf9485d ELFLoader: Make check_elf_image return how much memory the executable will use on success 2022-10-12 19:20:14 +02:00
3ac9fed23a ELFLoader: Add check_elf_image() and check_elf_image_from_filesystem()
These two functions validate an image, without actually loading it. Very useful for exec!
2022-10-12 18:37:00 +02:00
261fc73146 ELFLoader: Read the ELF file header by header using the VFS
Instead of just allocating one big redundant blob of memory and reading into it, then having to free it...
2022-10-12 18:23:52 +02:00
f8b3567042 Kernel: Add an exec() syscall
Very bare-bones for now. Doesn't support arguments or environment (we don't have that stuff right now), and the executable is not a valid ELF, it terminates the task.

But it's a start!
2022-10-12 17:42:01 +02:00
4e3ef9593d Scheduler: Move ELF image freeing to ELFLoader 2022-10-12 17:08:17 +02:00
854f585e1a Kernel: Add a seek() system call
Now, time for libc support!!
2022-10-12 15:28:52 +02:00
d3ac590e24 Kernel: Remove the sys_getversion() syscall
User programs can now acquire this information by reading /dev/version.
2022-10-11 21:31:28 +02:00
12cf37d0a7 Kernel/syscalls: Modify sys_write to accept a file descriptor and write to it
Previously, sys_write only wrote to the tty. Now, it uses the VFS interface, as it should.
2022-10-11 21:06:12 +02:00
0131193379 ELFLoader, Scheduler: Transition to use VFS
We should start to drop the old InitRD API, which only allows for files to be loaded from the initrd, and which forces pathnames to be relative (bin/init)
With VFS, we can load any kind of file from any kind of filesystem, and using paths that make sense (/bin/init)
2022-10-11 19:33:48 +02:00
da2ede3450 Kernel, libc, userspace: Implement file descriptors
Kernel: Implement a descriptor struct which stores the opened node and read offset, and give each task 8 of those.
Implement three syscalls: sys_read, sys_open and sys_close (sys_write still writes to the console instead of using a fd, for now)
Implement three new errors: ENOENT, EBADF and EMFILE.

libc: Implement the new errors, and the new syscalls in syscall().
Also fix _RETURN_WITH_ERRNO() to set errno correctly, which was making strerror() return null, thus crashing perror().

userspace: make init demonstrate the new file API.
2022-10-10 20:21:39 +02:00
f83a6ace51 Kernel, libc: Add support for providing a status code to exit()
The exit() libc function already accepted an integer, but didn't pass it on to the kernel since we had no mechanism for it to do that.
Now, the kernel stores a task's exit status to display it later (and in the future, return it to userspace via wait()/waitpid())
2022-10-08 17:56:40 +02:00
dc389da74e Implement an ELFImage struct
This struct allows us to keep track of what memory is used by the loaded executable. For some reason, freeing this memory when the task exits triggers a kernel page fault, so I'm not doing that right now.
2022-10-07 17:54:05 +02:00
dae2ff8d50 Add mmap and munmap syscalls, and thus, add malloc and free to libc!! (yet again, thanks to the wonderful liballoc) 2022-10-02 20:45:04 +02:00
8e6741ebd6 Rename SYS_version to SYS_getversion 2022-10-02 17:25:56 +02:00
ac6fdce737 Add 2 new syscalls (sys_version, sys_gettid) 2022-10-01 17:30:31 +02:00
6e6cf5b2b0 Add an ELF Loader!! 2022-10-01 12:15:56 +02:00
ef5994e389 Proper userspace program 2022-09-29 20:06:18 +02:00
f25014a8ed refine syscalls 2022-09-29 19:17:43 +02:00