#KivotOS
1 messages · Page 1 of 1 (latest)
Helloo

I know why I'm getting invalid bits in my PTEs
forgot to clear the pagee
how dare you discriminate against bits
time to pull up gdb
oh no where the program at? (its not there. its all zeroes)
the fuck is this tlb
the thing is that it perfectly works using kernel page map but doesnt work using its own page map.
but i well know userland cant work sharing whole kernel page map
thanks, theres not much
Thanks, Qwinci recommended me to use freelists
fooor some reason copying whole kernel page map to the user process works but it doesnt work with a fresh one
Day 2 of progress report.
Todo:
- Fix the pagemap thing
wtf, who set up NX flag? 😢
i found the issue. stack was too huge therefore it overlapped the code
and stack ofc had NX flag because i love safety
for stack, yes
but not for codee
but the code is still not there for some reason lmao
¯_(ツ)_/¯
and now what
maybe im not flushing the tlb
@wheat brook I did it. Context switching to usermode and creating user processes is FINISHED. it works.
proof that Im in user process
TIME FOR SYSCALLS BITCHES (ily all)
nice
lol
wdym by context switching to userspace
surely u context switch in-kernel and then go to userspace
Thats what I mean, i'm just going to CPL 3 using iretq
yeah
time for syscalls interface and porting musl maybeee :D
yes
thanks
mlibc is made very easy to port
oh nee user process hangs whole OS because it does no interrupts for some silly reason
ok fixed
forgot to set the rflags to 0x202
nice
I've never been that far in to OSDev man
my scheduler is asssss
MINE IS ASS TOO
lol
🤝
Y'know, my previous kernel attempts were fucking useless. But they had cool af stuff
Like.. somewhat working vfs?? and also it had PCIe
my previous iteration ran doom but it sucked asss
drawing the firmwares logo
tbf anything can run doom so its not that impressive
but now im doing minimalistic kernel, just to go to UMode
and from there begin expanding
ah
logical?
im doing the opposite pretty much
I am tryina sink as much time as possible into building everything before I go and start working on userspace and syscalls
cuz last time I built a bunch of syscalls on the most flimsy subsystems known to man
like my entire vfs was a memory leak
lmao
I only have:
GDT, IDT, page allocator, virtual mapping, heap, acpi, base vfs (only limine modules), tss (mandatory to switch to rsp0 from cpl 3), apic, scheduling
and thats it
I have multiple memory leaks in create user process in case OS runs out of memory

thats my early.c file
thats clean
its still early because theres no C++. I want C++ ONLY after heap
u dont want to see mine
eh show me
Also, where do you think I should put syscall interace?
In scheduler "module" or completely different one?
okay then syscalls "module" it is
actually, i like it
I do a lot of stuff in there that doesnt really fit anywhere else
its a massive mess tryina figure out where to put things tho ngl
there are three hardest things in programming
- Cache invalidation
- Naming things
- Off by one errors
Also, I wanna say that before user mode I was referring to myself as kernel developer because OS developer does both things Kmode and Umode
This time I may call myself OS developer
I'm currently working on syscall system
h uh
did it just fucking JUMP TO AN INSTRUCTION FUNCTION?
sooo. it returns but
it fails somewhere in the kernel
for some reason
duh
and now im getting interrupt 13
for some reason.
its about syscalls
butt the thingy is.. they all went through
and process was in a deadloop
even if one syscall fires in the process it gets int13
I need to add ubsan
I found out something interesting..
both of my timers are firing
PIT and LAPIC
im not fucking giving up till i fix this piece of shit
Syscalls work
I (r4 and nyaux helped a lot
) fixed it
Im planning to add 🐮 too
im quite proud of this. kernel doesnt crash when umode process dies and it only reschedules and destroys the user process
and also cleans up after dead process
very nice
ykw, i wanna do drivers now (not builtin but dynamically loaded from an elf file which will be position independent)
Do it, it's not too bad
I'll have time today to do stuff, last day of school
mmmm
Can someone tell me please when I remove print statement the whole program stops working and crashes because RAX becomes some kernel address but when i add this fuckass statement it works?
I see it now.
Def some undefined behavior
It might be also because my stack is bad, when I put EEs to the stack it crashes on dereferencing the RAX which has values of EEEEEEEEEEEEEEEE
which is a clear sign of "im reading stack that isnt posix compliant" or some shit
i found the issue
i was incorrectly writing to the stack
instead of writing to umode stack i was writing to kmode trashy
oh wait it didnt fix it
but stack is still at its fault
I got rid of another UB which is using sse and not saving sse states before and after scheduling
well fuck me
@fervent venture
namespace mlibc
{
void sys_libc_log(const char* message) {
SYSCALL3(kvt_write, 1, message, strlen(message));
}
volatile bool ent = false;
__attribute__((no_instrument_function))
extern "C" void __cyg_profile_func_enter(void *this_fn, void *call_site) {
if (ent) return;
ent = true;
sys_libc_log(".");
ent = false;
}
__attribute__((no_instrument_function))
extern "C" void __cyg_profile_func_exit(void *this_fn, void *call_site) {
}
// here follow stubs for the mlibc
}
and here's the generated code:
0000000000402cf9 <__cyg_profile_func_enter>:
402cf9: f3 0f 1e fa endbr64
402cfd: 55 push %rbp
402cfe: 48 89 e5 mov %rsp,%rbp
402d01: 53 push %rbx
402d02: 48 83 ec 18 sub $0x18,%rsp
402d06: 48 89 7d e8 mov %rdi,-0x18(%rbp)
402d0a: 48 89 75 e0 mov %rsi,-0x20(%rbp)
402d0e: 48 8b 45 08 mov 0x8(%rbp),%rax
402d12: 48 89 c6 mov %rax,%rsi
402d15: 48 c7 c0 f9 2c 40 00 mov $0x402cf9,%rax
402d1c: 48 89 c7 mov %rax,%rdi
402d1f: e8 d5 ff ff ff call 402cf9 <__cyg_profile_func_enter>
402d24: 48 c7 c0 28 fb 6a 00 mov $0x6afb28,%rax
402d2b: 0f b6 18 movzbl (%rax),%ebx
402d2e: 80 fb 01 cmp $0x1,%bl
402d31: 76 15 jbe 402d48 <__cyg_profile_func_enter+0x4f>
402d33: 0f b6 c3 movzbl %bl,%eax
402d36: 48 89 c6 mov %rax,%rsi
402d39: 48 8d 05 20 a3 17 00 lea 0x17a320(%rip),%rax # 57d060 <_ZTVN5mlibc8mem_fileE+0xc8>
402d40: 48 89 c7 mov %rax,%rdi
402d43: e8 a4 d1 00 00 call 40feec <__ubsan_handle_load_invalid_value>
402d48: 89 d8 mov %ebx,%eax
402d4a: 83 e0 01 and $0x1,%eax
402d4d: 84 c0 test %al,%al
402d4f: 75 11 jne 402d62 <__cyg_profile_func_enter+0x69>
402d51: 48 8d 05 90 a5 14 00 lea 0x14a590(%rip),%rax # 54d2e8 <_ZL11kvt_set_tcb+0x8>
402d58: 48 89 c7 mov %rax,%rdi
402d5b: e8 34 ff ff ff call 402c94 <_ZN5mlibc12sys_libc_logEPKc>
402d60: eb 01 jmp 402d63 <__cyg_profile_func_enter+0x6a>
402d62: 90 nop
402d63: 48 8b 45 08 mov 0x8(%rbp),%rax
402d67: 48 89 c6 mov %rax,%rsi
402d6a: 48 c7 c0 f9 2c 40 00 mov $0x402cf9,%rax
402d71: 48 89 c7 mov %rax,%rdi
402d74: e8 06 00 00 00 call 402d7f <__cyg_profile_func_exit>
402d79: 48 8b 5d f8 mov -0x8(%rbp),%rbx
402d7d: c9 leave
402d7e: c3 ret
0000000000402d7f <__cyg_profile_func_exit>:
402d7f: f3 0f 1e fa endbr64
402d83: 55 push %rbp
402d84: 48 89 e5 mov %rsp,%rbp
402d87: 48 83 ec 10 sub $0x10,%rsp
402d8b: 48 89 7d f8 mov %rdi,-0x8(%rbp)
402d8f: 48 89 75 f0 mov %rsi,-0x10(%rbp)
402d93: 48 8b 45 08 mov 0x8(%rbp),%rax
402d97: 48 89 c6 mov %rax,%rsi
402d9a: 48 c7 c0 7f 2d 40 00 mov $0x402d7f,%rax
402da1: 48 89 c7 mov %rax,%rdi
402da4: e8 50 ff ff ff call 402cf9 <__cyg_profile_func_enter>
402da9: 48 8b 45 08 mov 0x8(%rbp),%rax
402dad: 48 89 c6 mov %rax,%rsi
402db0: 48 c7 c0 7f 2d 40 00 mov $0x402d7f,%rax
402db7: 48 89 c7 mov %rax,%rdi
402dba: e8 c0 ff ff ff call 402d7f <__cyg_profile_func_exit>
402dbf: 90 nop
402dc0: c9 leave
402dc1: c3 ret
Okay, one of the issues was that I have put the attribute in wrong place
I fix it by putting after the void keyword
but instead of printing dots I get HHHHHHHH�¸[%.6f] Setting process 1 TCB to -> 0x6b0a40 HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH�¸HHHH�¸HHHH�¸[%.6f] Unknown syscall 100
printf printing formats is because i disabled SSE
i disabled printf printing time, its still the same thing
is kvt_set_tcb your code?
Yes, it is
kvt_set_tcb is a constexpr uint64_t for a syscall
that sets the fs base to argument in rdi
oh ill show you the fresh disassembly now
it doesn't look like it's calling that function
0000000000402c94 <__cyg_profile_func_enter>:
402c94: f3 0f 1e fa endbr64
402c98: 55 push %rbp
402c99: 48 89 e5 mov %rsp,%rbp
402c9c: 53 push %rbx
402c9d: 48 83 ec 18 sub $0x18,%rsp
402ca1: 48 89 7d e8 mov %rdi,-0x18(%rbp)
402ca5: 48 89 75 e0 mov %rsi,-0x20(%rbp)
402ca9: 48 c7 c0 28 fb 6a 00 mov $0x6afb28,%rax
402cb0: 0f b6 18 movzbl (%rax),%ebx
402cb3: 80 fb 01 cmp $0x1,%bl
402cb6: 76 15 jbe 402ccd <__cyg_profile_func_enter+0x39>
402cb8: 0f b6 c3 movzbl %bl,%eax
402cbb: 48 89 c6 mov %rax,%rsi
402cbe: 48 8d 05 9b a3 17 00 lea 0x17a39b(%rip),%rax # 57d060 <_ZTVN5mlibc8mem_fileE+0xc8>
402cc5: 48 89 c7 mov %rax,%rdi
402cc8: e8 d7 d1 00 00 call 40fea4 <__ubsan_handle_load_invalid_value>
402ccd: 89 d8 mov %ebx,%eax
402ccf: 83 e0 01 and $0x1,%eax
402cd2: 84 c0 test %al,%al
402cd4: 75 25 jne 402cfb <__cyg_profile_func_enter+0x67>
402cd6: 48 c7 c0 28 fb 6a 00 mov $0x6afb28,%rax
402cdd: c6 00 01 movb $0x1,(%rax)
402ce0: 48 8d 05 01 a6 14 00 lea 0x14a601(%rip),%rax # 54d2e8 <_ZL11kvt_set_tcb+0x8>
402ce7: 48 89 c7 mov %rax,%rdi
402cea: e8 26 00 00 00 call 402d15 <_ZN5mlibc12sys_libc_logEPKc>
402cef: 48 c7 c0 28 fb 6a 00 mov $0x6afb28,%rax
402cf6: c6 00 00 movb $0x0,(%rax)
402cf9: eb 01 jmp 402cfc <__cyg_profile_func_enter+0x68>
402cfb: 90 nop
402cfc: 48 8b 5d f8 mov -0x8(%rbp),%rbx
402d00: c9 leave
402d01: c3 ret
rather it looks like it's trying to pass a string to libc log and the disassembler confuses the string with kvt_set_tcb
wait what
I mean look at the lea, mov, call
why would it get an effective address of constexpr function
#include <asm/ioctls.h>
#include <bits/ensure.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <mlibc/all-sysdeps.hpp>
#include <mlibc/debug.hpp>
#include <stdint.h>
#include <stdlib.h>
#include <sys/select.h>
#include <sys/types.h>
#include "syscall.h"
extern "C" void* __dso_handle = nullptr;
constexpr uint64_t kvt_write = 1;
constexpr uint64_t kvt_exit = 100;
constexpr uint64_t kvt_set_tcb = 200;
volatile bool ent = false;
void mlibc::sys_libc_log(const char* message);
extern "C" void __attribute__((no_instrument_function)) __cyg_profile_func_enter(void *this_fn, void *call_site) {
if (ent) return;
ent = true;
mlibc::sys_libc_log(".");
ent = false;
}
extern "C" void __attribute__((no_instrument_function)) __cyg_profile_func_exit(void *this_fn, void *call_site) {
}
namespace mlibc
{
void sys_libc_log(const char* message) {
SYSCALL3(kvt_write, 1, message, strlen(message));
}
int sys_futex_wait(int *pointer, int expected, const struct timespec *time) {
sys_libc_log("sys_futex_wait is a stub.\n");
return 0;
}
int sys_futex_wake(int *pointer) {
sys_libc_log("sys_futex wake is a stub.\n");
return 0;
}
int sys_seek(int fd, off_t offset, int whence, off_t *new_offset) {
sys_libc_log("sys_seek is a stub.\n");
return -1;
}
int sys_vm_unmap(void *pointer, size_t size) {
sys_libc_log("sys_vm_unmap is a stub.\n");
return -1;
}
int sys_clock_get(int clock, time_t *secs, long *nanos) {
sys_libc_log("sys_clock_get is a stub.\n");
return ENOSYS;
}
int sys_close(int fd) {
sys_libc_log("sys_close is a stub.\n");
return EBADF;
}
int sys_write(int fd, const void *buf, size_t count, ssize_t *bytes_written) {
sys_libc_log("sys_write() has been called.\n");
*bytes_written = SYSCALL3(1, fd, buf, count);
return 0;
}
int sys_anon_allocate(size_t size, void **pointer) {
sys_libc_log("sys_anon_allocate is a stub.\n");
return -1;
}
void sys_libc_panic() {
sys_libc_log("Oh no. We're panicking..\n");
sys_exit(1);
}
void sys_exit(int status) {
sys_libc_log("sys_exit is a stub.\n");
SYSCALL1(kvt_exit, status);
}
int sys_open(const char *path, int flags, mode_t mode, int *fd) {
sys_libc_log("sys_open is a stub.\n");
return -1;
}
int sys_read(int fd, void *buf, size_t count, ssize_t *bytes_read) {
sys_libc_log("sys_read is a stub.\n");
return -1;
}
int sys_tcb_set(void *pointer) {
sys_libc_log("sys_tcb_set(ptr) has been called.\n");
SYSCALL1(kvt_set_tcb, pointer);
return 0;
}
int sys_vm_map(void *hint, size_t size, int prot, int flags, int fd,
off_t offset, void **window) {
sys_libc_log("sys_vm_map is a stub.\n");
return -1;
}
int sys_anon_free(void *pointer, size_t size) {
sys_libc_log("sys_anon_free is a stub.\n");
return -1;
}
} // namespace mlibc
after substituting for a syscall instead of sys_libc_log it now prints dots
Tomorrow I'll continue debugging but for now I have to do other things.
My idea is to read posix standard
And then do corrections
Because that's the main thing I'm suspecting
lol rip
Im continuing to write cored plugin to processes
Im still not giving up
My process has a problem that it's being interrupted and stack somehow gets fucked up by that
My process doesn't like to be step by step logged.
if I disabled step by step logging it stays quiet
My process is fine with step by step logging but doesnt like when stack is filled with EEs
I wanna do a rewrite..
