1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-29 07:47:35 +00:00

Kernel+Userland: Replace the beep syscall with the new /dev/beep device

There's no need to have separate syscall for this kind of functionality,
as we can just have a device node in /dev, called "beep", that allows
writing tone generation packets to emulate the same behavior.

In addition to that, we remove LibC sysbeep function, as this function
was never being used by any C program nor it was standardized in any
way.
Instead, we move the userspace implementation to LibCore.
This commit is contained in:
Liav A 2023-08-25 19:48:46 +03:00 committed by Tim Schumacher
parent ac70abcb73
commit 1b00618fd9
16 changed files with 128 additions and 58 deletions

View file

@ -145,7 +145,6 @@ private:
int virt$accept4(FlatPtr);
u32 virt$allocate_tls(FlatPtr, size_t);
int virt$anon_create(size_t, int);
int virt$beep();
int virt$bind(int sockfd, FlatPtr address, socklen_t address_length);
u32 virt$bindmount(u32 params_addr);
int virt$chdir(FlatPtr, size_t);

View file

@ -47,8 +47,6 @@ u32 Emulator::virt_syscall(u32 function, u32 arg1, u32 arg2, u32 arg3)
return virt$anon_create(arg1, arg2);
case SC_annotate_mapping:
return virt$annotate_mapping(arg1);
case SC_beep:
return virt$beep();
case SC_bind:
return virt$bind(arg1, arg2, arg3);
case SC_bindmount:
@ -1606,11 +1604,6 @@ u32 Emulator::virt$allocate_tls(FlatPtr initial_data, size_t size)
return tls_base;
}
int Emulator::virt$beep()
{
return syscall(SC_beep);
}
u32 Emulator::virt$sysconf(u32 name)
{
return syscall(SC_sysconf, name);

View file

@ -925,12 +925,6 @@ int gettid()
return cached_tid;
}
int sysbeep(int tone)
{
int rc = syscall(SC_beep, tone);
__RETURN_WITH_ERRNO(rc, rc, -1);
}
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/fsync.html
int fsync(int fd)
{

View file

@ -36,7 +36,6 @@ int get_process_name(char* buffer, int buffer_size);
int set_process_name(char const* name, size_t name_length);
void dump_backtrace(void);
int fsync(int fd);
int sysbeep(int tone);
int gettid(void);
int getpagesize(void);
pid_t fork(void);

View file

@ -9,10 +9,12 @@
#include <AK/DeprecatedString.h>
#include <AK/FixedArray.h>
#include <AK/ScopeGuard.h>
#include <AK/ScopedValueRollback.h>
#include <AK/StdLibExtras.h>
#include <AK/String.h>
#include <AK/Vector.h>
#include <Kernel/API/BeepInstruction.h>
#include <LibCore/SessionManagement.h>
#include <LibCore/System.h>
#include <limits.h>
@ -147,11 +149,13 @@ namespace Core::System {
#ifdef AK_OS_SERENITY
ErrorOr<void> beep(Optional<size_t> tone)
ErrorOr<void> beep(u16 tone)
{
auto rc = ::sysbeep(tone.value_or(440));
if (rc < 0)
return Error::from_syscall("beep"sv, -errno);
static Optional<int> beep_fd;
if (!beep_fd.has_value())
beep_fd = TRY(Core::System::open("/dev/beep"sv, O_RDWR));
BeepInstruction instruction { tone };
TRY(Core::System::write(beep_fd.value(), Span<u8 const>(&instruction, sizeof(BeepInstruction))));
return {};
}

View file

@ -51,7 +51,7 @@
namespace Core::System {
#ifdef AK_OS_SERENITY
ErrorOr<void> beep(Optional<size_t> tone);
ErrorOr<void> beep(u16 tone = 440);
ErrorOr<void> pledge(StringView promises, StringView execpromises = {});
ErrorOr<void> unveil(StringView path, StringView permissions);
ErrorOr<void> unveil_after_exec(StringView path, StringView permissions);

View file

@ -1069,7 +1069,7 @@ void TerminalWidget::beep()
return;
}
if (m_bell_mode == BellMode::AudibleBeep) {
sysbeep(440);
[[maybe_unused]] auto ret_val = Core::System::beep();
return;
}
m_visual_beep_timer->restart(200);

View file

@ -194,6 +194,7 @@ struct PluggableOnceCharacterDeviceNodeMatch {
};
static constexpr PluggableOnceCharacterDeviceNodeMatch s_simple_matchers[] = {
{ "/dev/beep"sv, 0666, 1, 10 },
{ "/dev/kcov"sv, 0666, 30, 0 },
};

View file

@ -14,6 +14,6 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
Core::ArgsParser args_parser;
args_parser.add_option(tone, "Beep tone", "beep-tone", 'f', "Beep tone (frequency in Hz)");
args_parser.parse(arguments);
TRY(Core::System::beep(tone));
TRY(Core::System::beep(tone.value_or(440)));
return 0;
}