klange / toaruos

A completely-from-scratch hobby operating system: bootloader, kernel, drivers, C library, and userspace including a composited graphical UI, dynamic linker, syntax-highlighting text editor, network stack, etc.
https://toaruos.org/
University of Illinois/NCSA Open Source License
6.09k stars 476 forks source link

Some issues #263

Open Vir-BryanQ opened 1 year ago

Vir-BryanQ commented 1 year ago
  1. If try to run these code below:

                          #include <pthread.h>
                          #include <stdio.h>
    
                          void *func(void *arg)
                          {
                              while (1)
                              {
                                  printf("A");
                              }
                              return NULL;
                          }
    
                          int main(void)
                          {
                              pthread_t thread;
                              pthread_create(&thread, NULL, func, NULL);
                              while (1)
                              {
                                  printf("M");
                              }
                              return 0;
                          }

    The segment fault will happen in less than a second. If I comment all the printf() and make every thread just run an empty loop then the code runs well.

  2. Plasma has two threads and the kernel will panic(page fault) when I run the command ‘kill -9 88’ (for example, plasma has a PID 88 and has two TIDs 88, 89). Sometimes it happens immediately and somtimes it happens when I try to run the next command.

  3. The key 'CapsLk' doesn't work. Maybe need to make a little change in the keycode translation library?

klange commented 1 year ago
  1. The libc's stdio implementation is not thread safe. This is not a bug, per se, but it is a known deficiency.
  2. This one is interesting, and I see what's happening from the backtrace; I am surprised I hadn't seen this previously...
  3. Depending on what you're running the OS in, it may be impossible to support caps lock; currently, I have not implemented support because I do almost all of my testing and development in QEMU and it doesn't even send a key press for caps lock.
klange commented 1 year ago

I have pushed a quick fix for the second issue which should more gracefully handle the situation instead of causing a kernel panic, though really there are several problems with threaded processes in the kernel that need to be addressed with more extensive changes. This is not an area I have put much work into.

klange commented 1 year ago

I have filed #264 to track the implementation of locking in the stdio implementation.

There were two old tickets for supporting caps lock, both of which were closed as part of a clean up of legacy tickets a few years ago. I may re-open one of them, probably #67.