summaryrefslogtreecommitdiff
path: root/Kernel/TTY/TTY.h
AgeCommit message (Collapse)Author
2021-12-23Kernel: Make major and minor numbers to be DistinctNumericsLiav A
This helps avoid confusion in general, and make constructors, methods and code patterns much more clean and understandable.
2021-11-14Kernel: Resolve clang-tidy readability-implicit-bool-conversion warningsAndrew Kaster
... In files included from Kernel/Process.cpp and Kernel/Thread.cpp
2021-11-08Kernel: Replace KResult and KResultOr<T> with Error and ErrorOr<T>Andreas Kling
We now use AK::Error and AK::ErrorOr<T> in both kernel and userspace! This was a slightly tedious refactoring that took a long time, so it's not unlikely that some bugs crept in. Nevertheless, it does pass basic functionality testing, and it's just real nice to finally see the same pattern in all contexts. :^)
2021-11-02Kernel: Move TTY subsystem to use KString instead of `AK::String`Brian Gianforcaro
This is minor progress on removing the `AK::String` API from the Kernel in the interest of improving OOM safety.
2021-10-31Kernel: Clarify ambiguous {File,Description}::absolute_pathBen Wiederhake
Found due to smelly code in InodeFile::absolute_path. In particular, this replaces the following misleading methods: File::absolute_path This method *never* returns an actual path, and if called on an InodeFile (which is impossible), it would VERIFY_NOT_REACHED(). OpenFileDescription::try_serialize_absolute_path OpenFileDescription::absolute_path These methods do not guarantee to return an actual path (just like the other method), and just like Custody::absolute_path they do not guarantee accuracy. In particular, just renaming the method made a TOCTOU bug obvious. The new method signatures use KResultOr, just like try_serialize_absolute_path() already did.
2021-09-08Kernel/Devices: Remove required_mode and device_name methodsLiav A
These methods are no longer needed because SystemServer is able to populate the DevFS on its own. Device absolute_path no longer assume a path to the /dev location, because it really should not assume any path to a Device node. Because StorageManagement still needs to know the storage name, we declare a virtual method only for StorageDevices to override, but this technique should really be removed later on.
2021-09-07Kernel: Rename FileDescription => OpenFileDescriptionAndreas Kling
Dr. POSIX really calls these "open file description", not just "file description", so let's call them exactly that. :^)
2021-07-27Kernel: Modify the IOCTL API to return KResultBrian Gianforcaro
The kernel has been gradually moving towards KResult from just bare int's, this change migrates the IOCTL paths.
2021-07-27Kernel: Utilize AK::Userspace<T> in the ioctl interfaceBrian Gianforcaro
It's easy to forget the responsibility of validating and safely copying kernel parameters in code that is far away from syscalls. ioctl's are one such example, and bugs there are just as dangerous as at the root syscall level. To avoid this case, utilize the AK::Userspace<T> template in the ioctl kernel interface so that implementors have no choice but to properly validate and copy ioctl pointer arguments.
2021-06-16Kernel: Use KResultOr<size_t> throughout the TTY subsystemGunnar Beutner
Previously the VirtualConsole::on_tty_write() method would return an incorrect value when an error had occurred. This prompted me to update the TTY subsystem to use KResultOr<size_t> everywhere.
2021-06-10LibVT+Kernel: Clean up scroll APIDaniel Bertalan
This commit cleans up some of the `#ifdef`-ed code smell in `Terminal`, by extending the scroll APIs to take a range of lines as a parameter. This makes it possible to use the same code for `IL`/`DL` as for scrolling. Note that the current scrolling implementation is very naive, and does many insertions/deletions in the middle of arrays, whereas swaps should be enough. This optimization will come in a later commit. The `linefeed` override was removed from `VirtualConsole`. Previously, it exhibited incorrect behavior by moving to column 0. Now that we use the method defined in `Terminal`, code which relied on this behavior stopped working. We go instead go through the TTY layer which handles the various output flags. Passing the input character-by-character seems a bit excessive, so a fix for it will come in another PR.
2021-06-05Kernel: Perform output processing on echoDaniel Bertalan
Previously, we would echo characters back just as they were passed to us, even in canonical mode. This caused newlines to not work correctly in some programs. Fixes #7802
2021-05-24Kernel: Signal EOF/EOL characters properly in `TTY`Daniel Bertalan
I introduced a regression in #7184 where `TTY` would report 1 byte read in canonical mode even if we had no more characters left. This was caused by counting the '\0' that denotes EOF into the number of characters that were read. The fix was simple: exclude the EOF character from the number of bytes. This still wouldn't be correct by itself, as the EOF and EOL control characters could change between when the data was written to the TTY and when it is read. We fix this by signaling out-of-band whether something is a special character. End-of-file markers have a value of zero and have their special bits set. Any other bytes with a special flag are treated as line endings. This is possible, as POSIX doesn't allow special characters to be 0. Fixes #7419
2021-05-17Kernel+LibC: Support more `termios` settings in TTYDaniel Bertalan
This commit adds support for the various ECHO* lflags and fixes some POSIX conformance issues around newline handling. Also included are error messages when setting not implemented settings.
2021-05-13Kernel: Avoid unnecessary allocations for TTY::tty_name()Gunnar Beutner
2021-04-22Everything: Move to SPDX license identifiers in all files.Brian Gianforcaro
SPDX License Identifiers are a more compact / standardized way of representing file license information. See: https://spdx.dev/resources/use/#identifiers This was done with the `ambr` search and replace tool. ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-03-17Kernel: Refactor storage stack with u64 as file operations offsetJean-Baptiste Boric
2020-12-27Kernel: Add a method to determine the desired permissions of a DeviceLiav A
This method will be used later in DevFS, to set the appropriate permissions for each device node.
2020-11-30Kernel: Move block condition evaluation out of the SchedulerTom
This makes the Scheduler a lot leaner by not having to evaluate block conditions every time it is invoked. Instead evaluate them as the states change, and unblock threads at that point. This also implements some more waitid/waitpid/wait features and behavior. For example, WUNTRACED and WNOWAIT are now supported. And wait will now not return EINTR when SIGCHLD is delivered at the same time.
2020-11-10AK: Make RefPtr, NonnullRefPtr, WeakPtr thread safeTom
This makes most operations thread safe, especially so that they can safely be used in the Kernel. This includes obtaining a strong reference from a weak reference, which now requires an explicit call to WeakPtr::strong_ref(). Another major change is that Weakable::make_weak_ref() may require the explicit target type. Previously we used reinterpret_cast in WeakPtr, assuming that it can be properly converted. But WeakPtr does not necessarily have the knowledge to be able to do this. Instead, we now ask the class itself to deliver a WeakPtr to the type that we want. Also, WeakLink is no longer specific to a target type. The reason for this is that we want to be able to safely convert e.g. WeakPtr<T> to WeakPtr<U>, and before this we just reinterpret_cast the internal WeakLink<T> to WeakLink<U>, which is a bold assumption that it would actually produce the correct code. Instead, WeakLink now operates on just a raw pointer and we only make those constructors/operators available if we can verify that it can be safely cast. In order to guarantee thread safety, we now use the least significant bit in the pointer for locking purposes. This also means that only properly aligned pointers can be used.
2020-09-13Kernel: Make copy_to/from_user safe and remove unnecessary checksTom
Since the CPU already does almost all necessary validation steps for us, we don't really need to attempt to do this. Doing it ourselves doesn't really work very reliably, because we'd have to account for other processors modifying virtual memory, and we'd have to account for e.g. pages not being able to be allocated due to insufficient resources. So change the copy_to/from_user (and associated helper functions) to use the new safe_memcpy, which will return whether it succeeded or not. The only manual validation step needed (which the CPU can't perform for us) is making sure the pointers provided by user mode aren't pointing to kernel mappings. To make it easier to read/write from/to either kernel or user mode data add the UserOrKernelBuffer helper class, which will internally either use copy_from/to_user or directly memcpy, or pass the data through directly using a temporary buffer on the stack. Last but not least we need to keep syscall params trivial as we need to copy them from/to user mode using copy_from/to_user.
2020-08-19Kernel: Distinguish between new and old process groups with equal pgidsAnotherTest
This does not add any behaviour change to the processes, but it ties a TTY to an active process group via TIOCSPGRP, and returns the TTY to the kernel when all processes in the process group die. Also makes the TTY keep a link to the original controlling process' parent (for SIGCHLD) instead of the process itself.
2020-08-10Kernel: PID/PGID typingBen Wiederhake
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-06Kernel: Store TTY's foreground process as a WeakPtr<Process>Andreas Kling
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-04Kernel: Make File::write() and File::read() return KResultOr<size_t>Andreas Kling
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-04Kernel+LibC: Tidy up sys$ttyname() and sys$ptsname()Andreas Kling
- 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-05-23Kernel: Use a FlatPtr for the "argument" to ioctl()Andreas Kling
Since it's often used to pass pointers, it should really be a FlatPtr.
2020-04-10Kernel: Add explicit offset parameter to File::read etcConrad Pankoff
2020-03-26Kernel: Make ^W and ^U actually erase charactersAndreas Kling
This is quite hackish but it makes using the js REPL a lot nicer. :^)
2020-02-16Kernel: Move all code into the Kernel namespaceAndreas Kling
2020-01-28Kernel: Tweak some include statementsAndreas Kling
2020-01-18Meta: Add license header to source filesAndreas Kling
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.
2019-11-04Kernel: Make File's can_read/can_write take a const FileDescription&Andreas Kling
Asking a File if we could possibly read or write it will never mutate the asking FileDescription&, so it should be const.
2019-11-01TTY: Flush input on signal character.Drew Stratford
We now flush the input when we recieve a signal character. This can be disabled using the newly implemented NOFLSH attribute.
2019-10-20TTY: Implement Canonical mode and basic echoing.Drew Stratford
The TTY driver now respects the ICANON flag, enabling basic line editing like VKILL, VERASE, VEOF and VWERASE. Additionally, ICANON is now set by default. Basic echoing has can now be enabled via the ECHO flag, though more complicated echoing like ECHOCTL or ECHONL has not been implemented.
2019-10-18Kernel: Keep TTY names in character buffers instead of StringsAndreas Kling
Just going over some little unnecessary little kmalloc allocations.
2019-08-23Kernel: Give each TTY 1 KB of input bufferAndreas Kling
This papers over an immediate issue where pseudoterminals would choke on more than 16 characters of pasted input in the GUI terminal. Longer-term we should find a more elegant solution than using a static size CircularQueue for this.
2019-08-12Kernel: Use a CircularQueue for input rather than a DoubleBufferConrad Pankoff
TTY::emit is called from an IRQ handler, and is used to push input data into a buffer for later retrieval. Previously this was using DoubleBuffer, but that class wants to take a lock. Our lock code wants to make sure interrupts are enabled, but they're disabled while an IRQ handler is running. This made the kernel sad, but this CircularQueue cheers it up by avoiding the lock requirement completely.
2019-07-03AK: Rename the common integer typedefs to make it obvious what they are.Andreas Kling
These types can be picked up by including <AK/Types.h>: * u8, u16, u32, u64 (unsigned) * i8, i16, i32, i64 (signed)
2019-06-07Kernel: Rename FileDescriptor to FileDescription.Andreas Kling
After reading a bunch of POSIX specs, I've learned that a file descriptor is the number that refers to a file description, not the description itself. So this patch renames FileDescriptor to FileDescription, and Process now has FileDescription* file_description(int fd).
2019-06-01Kernel: Make File::absolute_path() const.Andreas Kling
2019-05-28Add clang-format fileRobin Burchell
Also run it across the whole tree to get everything using the One True Style. We don't yet run this in an automated fashion as it's a little slow, but there is a snippet to do so in makeall.sh.
2019-05-03Kernel: Make Socket inherit from File.Andreas Kling
2019-04-29Kernel: Have File virtuals take a FileDescriptor& rather than a Process&.Andreas Kling
This will allow us to implement different behaviors depending on the role of the descriptor a File is being accessed through.
2019-04-28FileDescriptor: Let TTY handle its own absolute_path().Andreas Kling
2019-04-03Kernel: Move devices into Kernel/Devices/.Andreas Kling
2019-04-03Kernel: Move TTY-related files into Kernel/TTY/.Andreas Kling