Commit graph

407 commits

Author SHA1 Message Date
Ali Mohammad Pur
d704b61066 LibCore+LibTLS: Add an API for connect()'ing 'with hostname
This just unifies the API for all three sockets (UDP, TCP and TLS)
2024-11-20 21:37:58 +01:00
stasoid
dabf3da7e5 LibCore: Fix bug in CreateFileMapping call
Some checks are pending
CI / Lagom (false, FUZZ, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (false, NO_FUZZ, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (false, NO_FUZZ, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (true, NO_FUZZ, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (macos-14, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (ubuntu-24.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Push notes / build (push) Waiting to run
size >> 31 >> 1 is used instead of size >> 32 to support 32-bit Windows
(size_t is 32 bit there, and you cannot shift 32-bit value by 32 bits
on x86)
This is equivalent to sizeof(size) == 4 ? 0 : size >> 32
2024-11-19 22:07:01 -07:00
stasoid
11460b3daa LibCore: Fix ConfigFile.cpp compilation on Windows 2024-11-19 22:07:01 -07:00
stasoid
43056a8684 LibCore: Port Directory to Windows 2024-11-19 22:07:01 -07:00
stasoid
77d205571d LibCore/System: Add mkdir, openat (stub), fstatat (stub) for Windows
Also support directories in open().
2024-11-19 22:07:01 -07:00
stasoid
866609c682 LibCore: Make Process::wait_for_termination return exit code
Some checks are pending
CI / Lagom (false, NO_FUZZ, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (false, FUZZ, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (false, NO_FUZZ, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (true, NO_FUZZ, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (macos-14, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (ubuntu-24.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Push notes / build (push) Waiting to run
2024-11-19 14:40:03 -07:00
stasoid
3468a83e45 LibCore: Port Process to Windows
Windows doesn't have a concept of zombie children, hence:
* `disown` not needed
* we need a process handle because otherwise if the process have ended
  by the time `wait_for_termination` is called
  its pid may be reassigned to other process
2024-11-19 14:40:03 -07:00
stasoid
4a731b3858 LibCore/Process: Make all spawn overloads return ErrorOr<Process> 2024-11-19 14:40:03 -07:00
stasoid
61d52c8a3f LibCore: Remove Process::spawn(StringView, ReadonlySpan<char const*>) 2024-11-19 14:40:03 -07:00
stasoid
a828a0e158 LibCore/System: Port getcwd, stat, rmdir, unlink to Windows 2024-11-19 14:35:52 -07:00
Aliaksandr Kalenik
71eded0471 LibCore: Recognize .xht as XHTML in MIME parser for file names
Fixes a bug when https://wpt.live/css/CSS2/positioning/abspos-001.xht
saved as file fails because we incorrectly recognized its MIME type
as HTML, leading to incorrect self-closing tag handling and thus
incorrect rendering.
2024-11-15 18:50:38 +01:00
stasoid
1c77135948 LibCore: Port EventLoop to Windows 2024-11-14 11:18:38 -07:00
Andreas Kling
8c809fa5ee LibCore: Don't reserve 2 KiB of stack memory when processing event queue
The inline capacity on ThreadEventQueue::Private::queued_events caused
us to reserve (and importantly, not initialize!) 2 KiB of stack memory
when entering ThreadEventQueue::process().

This was causing any leftover pointers to GC-allocated objects within
that memory range to keep those objects alive, even when all other
references were gone.
2024-11-10 19:12:59 +01:00
Timothy Flynn
93712b24bf Everywhere: Hoist the Libraries folder to the top-level 2024-11-10 12:50:45 +01:00
Andreas Kling
13d7c09125 Libraries: Move to Userland/Libraries/ 2021-01-12 12:17:46 +01:00
Lenny Maiorani
e6f907a155 AK: Simplify constructors and conversions from nullptr_t
Problem:
- Many constructors are defined as `{}` rather than using the ` =
  default` compiler-provided constructor.
- Some types provide an implicit conversion operator from `nullptr_t`
  instead of requiring the caller to default construct. This violates
  the C++ Core Guidelines suggestion to declare single-argument
  constructors explicit
  (https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#c46-by-default-declare-single-argument-constructors-explicit).

Solution:
- Change default constructors to use the compiler-provided default
  constructor.
- Remove implicit conversion operators from `nullptr_t` and change
  usage to enforce type consistency without conversion.
2021-01-12 09:11:45 +01:00
asynts
a410bb8fd5 Everywhere: Replace a bundle of dbg with dbgln.
These changes are arbitrarily divided into multiple commits to make it
easier to find potentially introduced bugs with git bisect.
2021-01-11 21:49:29 +01:00
AnotherTest
711ced80c0 LibCore: Add line iterators to IODevice 2021-01-11 21:09:36 +01:00
Lenny Maiorani
f99d1d3bd7 Vector: Implement find, find_if, find_first_matching in terms of AK::find*
Problem:
- The implementation of `find` is coupled to the implementation of `Vector`.
- `Vector::find` takes the predicate by value which might be expensive.

Solution:
- Decouple the implementation of `find` from `Vector` by using a
  generic `find` algorithm.
- Change the name of `find` with a predicate to `find_if` so that a
  binding reference can be used and the predicate can be forwarded to
  avoid copies.
- Change all the `find(pred)` call sites to use `find_if`.
2021-01-11 19:45:05 +01:00
Andreas Kling
70fce5c4c7 LibCore: Use OSError in get_password() return type 2021-01-10 16:48:43 +01:00
Emanuele Torre
91222a67c8 LibCore: get_password() now removes the trailing '\n' read by getline()
This avoids unintentionally adding a newline character at the end of
user passwords when they are set using passwd(1).

I also fixed these two issues:

- The return value of getline() was being saved in an `int` variable
instead of in a `ssize_t` variable; I replaced the `int` keyword with
`auto` to fix this issue.

- Prior to this patch, get_password() could potentially return
tcsetattr()'s errno instead of getline()'s errno in case of an error.
We now make sure it always returns the right errno in case of an error.
2021-01-10 16:40:05 +01:00
Andreas Kling
f152b6f7ed LibCore: Don't try to unlink stale sockets in /tmp/rpc/
This was very obviously racy and would only succeed if we already own
the socket anyway. (And if we do, we can bind to it without unlinking!)

Work towards #4876.
2021-01-10 11:25:59 +01:00
Andreas Kling
d38b9916c9 SystemServer+LibCore: Move /tmp/rpc/ directory creation to SystemServer
This doesn't solve half of the problems with /tmp/rpc, but this way we
can at least make it sticky instead of having it fully world-writable
and owned by whoever was the first to bind an RPC socket.
2021-01-10 10:34:45 +01:00
Andreas Kling
f35a723f61 Everywhere: Convert a bunch of dbgprintf() to dbgln() 2021-01-10 10:02:20 +01:00
Tom
21e6f5176c LibCore: Harden signal handling code to be called in global destrcutors
Move some more complex globals into a Singleton, which allows it being
used from global destructors. It solves problems where some global
variables, such as HashMaps may already be deleted, triggering crashes
trying to use them.
2021-01-09 21:12:31 +01:00
Tom
8548ec357c LibCore: Allow adding/removing signal handlers while handling signals
This allows adding and removing of asynchronous signal handlers while
executing signal handlers, even if it is for the same signal that is
being handled right now.
2021-01-09 21:12:31 +01:00
asynts
938e5c7719 Everywhere: Replace a bundle of dbg with dbgln.
These changes are arbitrarily divided into multiple commits to make it
easier to find potentially introduced bugs with git bisect.Everything:

The modifications in this commit were automatically made using the
following command:

    find . -name '*.cpp' -exec sed -i -E 's/dbg\(\) << ("[^"{]*");/dbgln\(\1\);/' {} \;
2021-01-09 21:11:09 +01:00
asynts
1160817a9e AK: Add Formatter<FormatString> as helper class. 2021-01-09 21:11:09 +01:00
Andreas Kling
9a688af4b1 LibCore+passwd+su+Base: Add /etc/shadow to hide hashes from users :^)
This patch moves the user account password hashes from /etc/passwd,
where they were world-readable, to /etc/shadow, where only root can
access them.

The Core::Account class is extended to support both authentication
against, and modification of /etc/shadow.

The default password for "anon" as of this commit is "foo" :^)
2021-01-09 19:41:12 +01:00
Andreas Kling
dbd090fd95 LibCore: Don't auto-accept events that hit bubbling limit
We were using the "accept" flag on the event to break out of the
bubbling loop, but this had lasting consequences since all events that
bubbled too far came out looking as if someone had accepted them.

If an event is ignored by everyone, it should appear ignored.
2021-01-09 12:02:07 +01:00
Andreas Kling
6041e48eaa LibCore: Make Core::Object::property() const 2021-01-04 13:41:13 +01:00
Tom
bc3c0fa936 LibCore: Allow caching and reusing the ProcFS file descriptors
Because ProcFS will refresh the data upon seek to 0, we can re-use
the same file descriptor. This saves us from having to open it every
time, but it also reduces the odds that we are unable to open a new
file descriptor due to low memory conditions.
2021-01-03 22:12:19 +01:00
Tom
cf89180c35 LibCore: Report error condition when reading process statistics failed 2021-01-03 22:12:19 +01:00
AnotherTest
2b38b2f83b LibCore: Add a way to check if a property is readonly 2021-01-03 10:47:29 +01:00
Andreas Kling
7841528cd4 LibCore: Remove Core::Object::is_widget() in favor of RTTI 2021-01-01 16:08:49 +01:00
Andreas Kling
42179715c3 LibCore: Remove some hand-rolled type information from Core::Object
Both is_action() and is_window() can be answered by RTTI.
2021-01-01 16:08:49 +01:00
Andrew Kaster
5b03a0867f LibCore: Add typed find_child and find_descendant helpers to Object
These look a lot like the parallel functionality in GUI::Widget :).
These use dynamic_cast now, to make use of that RTTI we just added.
2021-01-01 14:45:09 +01:00
asynts
7e62ffbc6e AK+Format: Remove TypeErasedFormatParams& from format function. 2020-12-30 20:33:53 +01:00
AnotherTest
4a2da10e38 ProtocolServer: Stream the downloaded data if possible
This patchset makes ProtocolServer stream the downloads to its client
(LibProtocol), and as such changes the download API; a possible
download lifecycle could be as such:
notation = client->server:'>', server->client:'<', pipe activity:'*'
```
> StartDownload(GET, url, headers, {})
< Response(0, fd 8)
* {data, 1024b}
< HeadersBecameAvailable(0, response_headers, 200)
< DownloadProgress(0, 4K, 1024)
* {data, 1024b}
* {data, 1024b}
< DownloadProgress(0, 4K, 2048)
* {data, 1024b}
< DownloadProgress(0, 4K, 1024)
< DownloadFinished(0, true, 4K)
```

Since managing the received file descriptor is a pain, LibProtocol
implements `Download::stream_into(OutputStream)`, which can be used to
stream the download into any given output stream (be it a file, or
memory, or writing stuff with a delay, etc.).
Also, as some of the users of this API require all the downloaded data
upfront, LibProtocol also implements `set_should_buffer_all_input()`,
which causes the download instance to buffer all the data until the
download is complete, and to call the `on_buffered_download_finish`
hook.
2020-12-30 13:31:55 +01:00
AnotherTest
90aeacbb58 LibGUI: Register a whole bunch of properties in various widgets 2020-12-30 12:53:39 +01:00
Andreas Kling
0f3b0b65ae LibGUI+LibCore: Remove the GUI::SizePolicy enum 2020-12-30 01:38:29 +01:00
Linus Groh
1e70986d19 LibCore: Add REGISTER_TEXT_ALIGNMENT_PROPERTY macro 2020-12-29 15:42:30 +01:00
Linus Groh
6c0fa6ad93 LibCore: Add REGISTER_ENUM_PROPERTY macro
This can be used to register a property that maps enum values to certain
strings, e.g.

    REGISTER_ENUM_PROPERTY(
        property_name, getter, setter, Enum,
        { Enum::Foo, "Foo" },
        { Enum::Bar, "Bar" });

Also use it for REGISTER_SIZE_POLICY_PROPERTY :^)
2020-12-29 15:42:30 +01:00
Andreas Kling
add01b304b LibCore: Make Core::Timer::create_single_shot() create a stopped timer
None of the code using this actually expected the timer to fire right
away, but they would instead call start() on it once they were ready to
accept a timer fire.

Let's make the API behave the way its clients believed it did. :^)
2020-12-28 21:28:40 +01:00
Linus Groh
e955c024b2 LibCore: Add Object::remove_all_children() 2020-12-27 18:36:43 +01:00
Andreas Kling
0e2b7f9c9a Kernel: Remove the per-process icon_id and sys$set_process_icon()
This was a goofy kernel API where you could assign an icon_id (int) to
a process which referred to a global shbuf with a 16x16 icon bitmap
inside it.

Instead of this, programs that want to display a process icon now
retrieve it from the process executable instead.
2020-12-27 01:16:56 +01:00
Andreas Kling
21ccbc2167 Kernel: Expose process executable paths in /proc/all 2020-12-27 01:16:56 +01:00
Andreas Kling
5f182746b6 LibCore: Stop logging that a Core::Socket has disconnected in receive()
This is perfectly normal and nothing we need to inform about.
2020-12-23 15:45:59 +01:00
Érico Nogueira Rolim
a8f0e489a4
LibCore: Rename identifiers that can clash with libc macros (#4127)
POSIX allows the default streams (stdin, stdout and stderr) to be
macros, which means that on such systems (musl libc is one) building
Lagom will fail due to the File::std*() names.

Also fix any files that use these identifiers.
2020-12-22 23:37:11 +01:00
Tom
5f51d85184 Kernel: Improve time keeping and dramatically reduce interrupt load
This implements a number of changes related to time:
* If a HPET is present, it is now used only as a system timer, unless
  the Local APIC timer is used (in which case the HPET timer will not
  trigger any interrupts at all).
* If a HPET is present, the current time can now be as accurate as the
  chip can be, independently from the system timer. We now query the
  HPET main counter for the current time in CPU #0's system timer
  interrupt, and use that as a base line. If a high precision time is
  queried, that base line is used in combination with quering the HPET
  timer directly, which should give a much more accurate time stamp at
  the expense of more overhead. For faster time stamps, the more coarse
  value based on the last interrupt will be returned. This also means
  that any missed interrupts should not cause the time to drift.
* The default system interrupt rate is reduced to about 250 per second.
* Fix calculation of Thread CPU usage by using the amount of ticks they
  used rather than the number of times a context switch happened.
* Implement CLOCK_REALTIME_COARSE and CLOCK_MONOTONIC_COARSE and use it
  for most cases where precise timestamps are not needed.
2020-12-21 18:26:12 +01:00