Commit Graph

102 Commits

Author SHA1 Message Date
Ben Wiederhake
7bdf54c837 Kernel: PID/PGID typing
This compiles, and fixes two bugs:
- setpgid() confusion (see previous commit)
- tcsetpgrp() now allows to set a non-empty process group even if
  the group leader has already died. This makes Serenity slightly
  more POSIX-compatible.
2020-08-10 11:51:45 +02:00
Andreas Kling
ddab7ab693 Kernel: Store TTY's foreground process as a WeakPtr<Process>
This ensures that we don't leave a stale PGID assigned to the TTY after
the process exits, which would make PID recycling attacks possible.
2020-08-06 11:17:53 +02:00
AnotherTest
05972668d1 Kernel: Send a SIGCHLD to the parent upon suspension of a process
...that is controlling a TTY.
2020-08-06 10:35:22 +02:00
Nico Weber
ce95628b7f Unicode: Try s/codepoint/code_point/g again
This time, without trailing 's'. Ran:

    git grep -l 'codepoint' | xargs sed -ie 's/codepoint/code_point/g
2020-08-05 22:33:42 +02:00
Nico Weber
19ac1f6368 Revert "Unicode: s/codepoint/code_point/g"
This reverts commit ea9ac3155d.
It replaced "codepoint" with "code_points", not "code_point".
2020-08-05 22:33:42 +02:00
Brian Gianforcaro
946c96dd56 Kernel: Suppress remaining unobserved KResult return codes
These are all cases where there is no clear and easy fix,
I've left FIXME bread crumbs so that these can hopefully
be fixed over time.
2020-08-05 14:36:48 +02:00
Brian Gianforcaro
d67069d922 Kernel: Propagate a few KResults properly in FileSystem subsystems
Propagating un-obsevered KResults up the stack.
2020-08-05 14:36:48 +02:00
Andreas Kling
83e32788d5 Kernel: Send SIGTTIN and SIGTTOU signals on background TTY read/write
A process that is not in the foreground process group of a TTY should
not be allowed to read/write that TTY. Instead, we now send either a
SIGTTIN (on read) or SIGTTOU (on write) signal to the process, and fail
the I/O syscall with EINTR.

Fixes #205.
2020-08-04 21:25:44 +02:00
Andreas Kling
7a3ab6c517 Kernel: Make File::write() and File::read() return KResultOr<size_t>
Instead of returning a ssize_t where negative values mean error,
we now return KResultOr<size_t> and use the error state to report
errors exclusively.
2020-08-04 18:17:16 +02:00
Andreas Kling
58feebeed2 Kernel+LibC: Tidy up sys$ttyname() and sys$ptsname()
- Remove goofy _r suffix from syscall names.
- Don't take a signed buffer size.
- Use Userspace<T>.
- Make TTY::tty_name() return a String instead of a StringView.
2020-08-04 18:17:16 +02:00
Andreas Kling
ea9ac3155d Unicode: s/codepoint/code_point/g
Unicode calls them "code points" so let's follow their style.
2020-08-03 19:06:41 +02:00
Tom
538b985487 Kernel: Remove ProcessInspectionHandle and make Process RefCounted
By making the Process class RefCounted we don't really need
ProcessInspectionHandle anymore. This also fixes some race
conditions where a Process may be deleted while still being
used by ProcFS.

Also make sure to acquire the Process' lock when accessing
regions.

Last but not least, there's no reason why a thread can't be
scheduled while being inspected, though in practice it won't
happen anyway because the scheduler lock is held at the same
time.
2020-08-02 17:15:11 +02:00
Andreas Kling
292cd53192 Kernel: Remove SmapDisabler in sys$ioctl()
Use copy_{to,from}_user() in the various File::ioctl() implementations
instead of disabling SMAP wholesale in sys$ioctl().

This patch does not port IPv4Socket::ioctl() to those API's since that
will be more involved. That function now creates a local SmapDisabler.
2020-07-31 00:17:25 +02:00
Florian Angermeier
d8fa8c5f82 Kernel: Ensure there are all VirtualConsoles properly initialized
It is possible to switch to VirtualConsoles 1 to 4 via the shortcut
ALT + [1-4]. Therefor the array of VirtualConsoles should be guaranteed
to be initialized.

Also add an constant for the maximum number of VirtualConsoles to
guarantee consistency.
2020-07-17 00:36:50 +02:00
Florian Angermeier
971a42a816 Kernel: Make the VirtualConsole index const unsigned instead of unsigned
const:
The index should not be modified in the constructor to avoid unexpected
behavior
2020-07-17 00:36:50 +02:00
Peter Elliott
7a27fa3df8 LibC: Implement tcflush(3) 2020-07-11 11:33:33 +02:00
Tom
bc107d0b33 Kernel: Add SMP IPI support
We can now properly initialize all processors without
crashing by sending SMP IPI messages to synchronize memory
between processors.

We now initialize the APs once we have the scheduler running.
This is so that we can process IPI messages from the other
cores.

Also rework interrupt handling a bit so that it's more of a
1:1 mapping. We need to allocate non-sharable interrupts for
IPIs.

This also fixes the occasional hang/crash because all
CPUs now synchronize memory with each other.
2020-07-06 17:07:44 +02:00
Tom
16783bd14d Kernel: Turn Thread::current and Process::current into functions
This allows us to query the current thread and process on a
per processor basis
2020-07-01 12:07:01 +02:00
Hüseyin ASLITÜRK
00edc89288 Kernel: TTY:VirtualConsole, replace character attribute with code_point 2020-06-16 13:15:17 +02:00
Sergey Bugaev
1b4e88fb59 Kernel: Allow File::close() to fail
And pass the result through to sys$close() return value.

Fixes https://github.com/SerenityOS/serenity/issues/427
2020-06-02 21:49:47 +02:00
Andreas Kling
165f69023b LibVT: Allow updating the window progress via an escape sequence
You can now request an update of the terminal's window progress by
sending this escape sequence:

<esc>]9;<value>;<max_value>;<escape><backslash>

I'm sure we can find many interesting uses for this! :^)
2020-05-30 23:00:35 +02:00
Sergey Bugaev
f11270e7ce Kernel: Port VirtualConsole to LibVT :^)
Unfortunately this drops the feature of preserving VGA buffer contents.

Resolves https://github.com/SerenityOS/serenity/issues/2399
2020-05-27 11:19:38 +02:00
Andreas Kling
b3736c1b1e Kernel: Use a FlatPtr for the "argument" to ioctl()
Since it's often used to pass pointers, it should really be a FlatPtr.
2020-05-23 15:25:43 +02:00
Andreas Kling
21d5f4ada1 Kernel: Absorb LibBareMetal back into the kernel
This was supposed to be the foundation for some kind of pre-kernel
environment, but nobody is working on it right now, so let's move
everything back into the kernel and remove all the confusion.
2020-05-16 12:00:04 +02:00
Sergey Bugaev
450a2a0f9c Build: Switch to CMake :^)
Closes https://github.com/SerenityOS/serenity/issues/2080
2020-05-14 20:15:18 +02:00
Andreas Kling
9c927538ad Kernel: ioctl(TCSETSF) on a TTY should flush input
This is where we end up when calling tcsetattr() with TCSAFLUSH.
This fixes vttest not accepting the first keystroke as input.
2020-05-09 12:30:51 +02:00
Conrad Pankoff
a3edeb5868 Kernel: Add explicit offset parameter to File::read etc 2020-04-10 11:59:30 +02:00
Andreas Kling
f3c245fb96 Kernel: Make ^W and ^U actually erase characters
This is quite hackish but it makes using the js REPL a lot nicer. :^)
2020-03-26 08:18:47 +01:00
Liav A
1f13f51ebd SlavePTY: Use dbg() instead of dbgprintf() 2020-02-27 13:05:12 +01:00
Liav A
63a27992e8 MasterPTY: Use dbg() instead of dbgprintf() 2020-02-27 13:05:12 +01:00
Liav A
ac9a001b92 PTYMultiplexer: Use dbg() instead of dbgprintf() 2020-02-27 13:05:12 +01:00
Liav A
8a22e93ebb VirtualConsole: Use dbg() instead of dbgprintf() 2020-02-27 13:05:12 +01:00
Liav A
309593d5bd TTY: Use dbg() instead of dbgprintf() 2020-02-27 13:05:12 +01:00
Andreas Kling
4e394862ce Kernel: Disallow assigning a TTY to an arbitrary process group ID
It was possible to send signals to processes that you were normally not
allowed to send signals to, by calling ioctl(tty, TIOCSPGRP, targetpid)
and then generating one of the TTY-related signals on the calling
process's TTY (e.g by pressing ^C, ^Z, etc.)
2020-02-26 21:33:14 +01:00
Andreas Kling
7592f9afd5 AK: Use size_t for CircularQueue and CircularDeque 2020-02-20 13:20:34 +01:00
Jesse Buhagiar
35ba4bf005 TTY: Reset VGA start row when setting graphical TTY
This was causing the screen (on a real machine) to be split in half.
2020-02-18 12:55:31 +01:00
Andreas Kling
48f7c28a5c Kernel: Replace "current" with Thread::current and Process::current
Suggested by Sergey. The currently running Thread and Process are now
Thread::current and Process::current respectively. :^)
2020-02-17 15:04:27 +01:00
Andreas Kling
a356e48150 Kernel: Move all code into the Kernel namespace 2020-02-16 01:27:42 +01:00
Liav A
e559af2008 Kernel: Apply changes to use LibBareMetal definitions 2020-02-09 19:38:17 +01:00
Andreas Kling
bd059e32e1 Kernel: Tweak some include statements 2020-01-28 20:42:27 +01:00
Andreas Kling
edbe7d3769 Kernel: Unbreak canonical mode TTY erase after LibVT changes
Now that LibVT's backspace character (8) is non-destructive, the kernel
line editing code has to take care of erasing manually.
2020-01-25 20:44:33 +01:00
Andreas Kling
f4f958f99f Kernel: Make DoubleBuffer use a KBuffer instead of kmalloc()ing
Background: DoubleBuffer is a handy buffer class in the kernel that
allows you to keep writing to it from the "outside" while the "inside"
reads from it. It's used for things like LocalSocket and TTY's.
Internally, it has a read buffer and a write buffer, but the two will
swap places when the read buffer is exhausted (by reading from it.)

Before this patch, it was internally implemented as two Vector<u8>
that we would swap between when the reader side had exhausted the data
in the read buffer. Now instead we preallocate a large KBuffer (64KB*2)
on DoubleBuffer construction and use that throughout its lifetime.

This removes all the kmalloc heap traffic caused by DoubleBuffers :^)
2020-01-20 16:08:49 +01:00
Sergey Bugaev
d0d13e2bf5 Kernel: Move setting file flags and r/w mode to VFS::open()
Previously, VFS::open() would only use the passed flags for permission checking
purposes, and Process::sys$open() would set them on the created FileDescription
explicitly. Now, they should be set by VFS::open() on any files being opened,
including files that the kernel opens internally.

This also lets us get rid of the explicit check for whether or not the returned
FileDescription was a preopen fd, and in fact, fixes a bug where a read-only
preopen fd without any other flags would be considered freshly opened (due to
O_RDONLY being indistinguishable from 0) and granted a new set of flags.
2020-01-18 23:51:22 +01:00
Andreas Kling
94ca55cefd Meta: Add license header to source files
As suggested by Joshua, this commit adds the 2-clause BSD license as a
comment block to the top of every source file.

For the first pass, I've just added myself for simplicity. I encourage
everyone to add themselves as copyright holders of any file they've
added or modified in some significant way. If I've added myself in
error somewhere, feel free to replace it with the appropriate copyright
holder instead.

Going forward, all new source files should include a license header.
2020-01-18 09:45:54 +01:00
Andreas Kling
e362b56b4f Kernel: Move kernel above the 3GB virtual address mark
The kernel and its static data structures are no longer identity-mapped
in the bottom 8MB of the address space, but instead move above 3GB.

The first 8MB above 3GB are pseudo-identity-mapped to the bottom 8MB of
the physical address space. But things don't have to stay this way!

Thanks to Jesse who made an earlier attempt at this, it was really easy
to get device drivers working once the page tables were in place! :^)

Fixes #734.
2020-01-17 22:34:26 +01:00
Andreas Kling
62a191b59a Kernel: Require "tty" for ioctl() on TTY and MasterPTY
SystemServer now pledges "tty" since it's used when spawning services.
2020-01-12 13:29:51 +01:00
Andreas Kling
4edbcebeb4 Kernel: Put termios debug spam behind TTY_DEBUG 2020-01-12 10:02:02 +01:00
Andreas Kling
b5da0b78eb Kernel: File::open() should apply r/w mode from the provided options
This has been a FIXME for a long time. We now apply the provided
read/write permissions to the constructed FileDescription when opening
a File object via File::open().
2020-01-04 12:30:55 +01:00
joshua stein
0a10462896 VirtualConsole: use memmove for an overlapping copy 2019-12-20 20:02:45 +01:00
Andreas Kling
e9dda8d592 Kernel: Give PTY's *actually* unique major ID's
Okay, one "dunce hat" point for me. The new PTY majors conflicted with
PATAChannel. Now they are 200 for master and 201 for slave, not used
by anything else.. I hope!
2019-12-09 21:03:39 +01:00