Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions Documentation/locale/en/LC_MESSAGES/userspace-api/abi.po
Original file line number Diff line number Diff line change
Expand Up @@ -1076,3 +1076,23 @@ msgstr ""
"skipped when AVX is disabled. Applications and glibc versions outside "
"this coverage still require individual validation. VMware validation is "
"incomplete, and physical hardware has not been validated."

msgid "广播进程信号"
msgstr "Broadcast process signals"

msgid ""
"``kill(-1, sig)`` 按 Linux 语义遍历每个用户进程一次。PID 1 和调用者的整个线程组 跳过,其他进程分别检查 "
"UID、目标用户空间的 ``CAP_KILL`` 以及同会话 ``SIGCONT`` 权限。信号 0 只作探测。信号携带 "
"``SI_USER``、发送进程 ID 和按接收者用户空间 映射的发送者真实 UID。没有候选进程时返回 ``ESRCH``。"
msgstr "``kill(-1, sig)`` visits each userspace process once using Linux semantics. PID 1 and the caller's entire thread group are skipped. Each remaining process is checked against UID permissions, ``CAP_KILL`` in its user namespace, and the same-session rule for ``SIGCONT``. Signal 0 is a probe. Signals carry ``SI_USER``, the sender's process ID, and the sender's real UID mapped into the recipient's user namespace. If there are no candidates, the call returns ``ESRCH``."

msgid "ext 文件系统 ACL"
msgstr "ACLs on ext filesystems"

msgid ""
"ext2、ext3 和 ext4 支持 ``system.posix_acl_access`` 与 "
"``system.posix_acl_default``。路径和描述符的 xattr 调用使用 Linux ACL 编码。 "
"文件所有者或具有相应权限的进程可以设置和删除 ACL。访问检查应用命名用户、 命名组、补充组和 ACL 掩码。``chmod`` 同步调整访问 "
"ACL 的权限类别。 新 inode 从父目录继承默认 ACL,并按请求的模式限制权限。父目录没有默认 ACL 时,inode 创建使用调用者的 "
"``umask``。新目录同时继承默认 ACL。"
msgstr "ext2, ext3, and ext4 support ``system.posix_acl_access`` and ``system.posix_acl_default``. Path- and descriptor-based xattr calls use Linux ACL encoding. The inode owner or a privileged caller can set and remove ACLs. Access checks apply named users, named groups, supplementary groups, and the ACL mask. ``chmod`` updates the access ACL's permission classes. A new inode inherits its parent's default ACL with permissions limited by the requested mode. Without a default ACL, inode creation applies the caller's ``umask``. New directories also inherit the default ACL."
Original file line number Diff line number Diff line change
Expand Up @@ -377,3 +377,19 @@ msgstr "Opening a writable control checks permissions on its exact inode; a succ

msgid "文本虚拟终端的 ``K_XLATE`` 和 ``K_UNICODE`` 键盘模式均支持 ``Ctrl+Alt+F1`` 至 ``Ctrl+Alt+F6`` 切换,遵循既有终端交接流程。Unicode 模式保留 UTF-8 输入。"
msgstr "Text virtual terminals support switching with ``Ctrl+Alt+F1`` through ``Ctrl+Alt+F6`` in both ``K_XLATE`` and ``K_UNICODE`` keyboard modes, using the existing terminal handoff protocol. Unicode mode preserves UTF-8 input."

msgid "内核日志设备"
msgstr "Kernel log device"

msgid ""
"``/dev/kmsg`` 以 Linux 的字符设备号 ``1:11`` 提供内核日志。每次打开独立记录 读取位置,``dup`` 和 "
"``fork`` 共享打开描述的游标。每次读取返回一条包含优先级、 序号和启动后微秒时间的完整记录。缓冲区无新记录时,阻塞读取可被信号中断, "
"非阻塞读取返回 ``EAGAIN``。读取落后于日志环时返回 ``EPIPE`` 并定位到最旧 的可读记录。poll 和 epoll "
"可等待新记录并报告溢出。"
msgstr "``/dev/kmsg`` exposes the kernel log through Linux character device number ``1:11``. Each open has an independent read position. Descriptors inherited through ``dup`` or ``fork`` share the cursor of the open file description. Each read returns one record containing its priority, sequence, and time in microseconds since boot. When no record is available, blocking reads can be interrupted by a signal and nonblocking reads return ``EAGAIN``. A reader overtaken by the ring returns ``EPIPE`` and advances to the oldest readable record. poll and epoll wait for new records and report overruns."

msgid ""
"``lseek(fd, 0, SEEK_SET)`` 定位到最旧记录,``SEEK_END`` 定位到当前末尾, ``SEEK_DATA`` "
"定位到初始序号。用户态每次 ``write`` 或 ``writev`` 写入一条 记录,可带 syslog 的 ``<优先级>`` "
"前缀。用户态记录使用非内核 facility。"
msgstr "``lseek(fd, 0, SEEK_SET)`` selects the oldest record, ``SEEK_END`` selects the current tail, and ``SEEK_DATA`` selects the initial sequence. Each userspace ``write`` or ``writev`` appends one record and may supply a syslog ``<priority>`` prefix. Userspace records use a nonkernel facility."
20 changes: 20 additions & 0 deletions Documentation/locale/ja/LC_MESSAGES/userspace-api/abi.po
Original file line number Diff line number Diff line change
Expand Up @@ -903,3 +903,23 @@ msgstr ""
"ELF、pthread/TLS、``posix_spawn``、``dlopen/dlsym``、localhost NSS、通常の robust"
" ミューテックスも実行しました。AVX が無効な場合は AVX 固有の検査をスキップします。この範囲外のアプリケーションと glibc "
"バージョンは個別の検証が必要です。VMware での検証は未完了で、実機ハードウェアは未検証です。"

msgid "广播进程信号"
msgstr "プロセスへのシグナルの一斉送信"

msgid ""
"``kill(-1, sig)`` 按 Linux 语义遍历每个用户进程一次。PID 1 和调用者的整个线程组 跳过,其他进程分别检查 "
"UID、目标用户空间的 ``CAP_KILL`` 以及同会话 ``SIGCONT`` 权限。信号 0 只作探测。信号携带 "
"``SI_USER``、发送进程 ID 和按接收者用户空间 映射的发送者真实 UID。没有候选进程时返回 ``ESRCH``。"
msgstr "``kill(-1, sig)`` は Linux の動作に従い、各ユーザープロセスを一度ずつ処理します。PID 1 と呼び出し元のスレッドグループ全体を除外します。残りの各プロセスについて UID、対象のユーザー名前空間の ``CAP_KILL``、および ``SIGCONT`` の同一セッション条件を確認します。シグナル 0 は確認にのみ使います。シグナルには ``SI_USER``、送信元のプロセス ID、受信側のユーザー名前空間にマップされた送信元の実 UID を含めます。候補がなければ ``ESRCH`` を返します。"

msgid "ext 文件系统 ACL"
msgstr "ext ファイルシステムの ACL"

msgid ""
"ext2、ext3 和 ext4 支持 ``system.posix_acl_access`` 与 "
"``system.posix_acl_default``。路径和描述符的 xattr 调用使用 Linux ACL 编码。 "
"文件所有者或具有相应权限的进程可以设置和删除 ACL。访问检查应用命名用户、 命名组、补充组和 ACL 掩码。``chmod`` 同步调整访问 "
"ACL 的权限类别。 新 inode 从父目录继承默认 ACL,并按请求的模式限制权限。父目录没有默认 ACL 时,inode 创建使用调用者的 "
"``umask``。新目录同时继承默认 ACL。"
msgstr "ext2、ext3、ext4 は ``system.posix_acl_access`` と ``system.posix_acl_default`` をサポートします。パスやファイル記述子を指定する xattr 呼び出しは Linux の ACL 形式を使用します。inode の所有者または権限のある呼び出し元が ACL を設定、削除できます。アクセス判定には名前付きユーザー、名前付きグループ、補助グループ、ACL マスクが適用されます。``chmod`` はアクセス ACL の権限クラスも更新します。新しい inode は親ディレクトリのデフォルト ACL を継承し、要求されたモードで権限を制限します。デフォルト ACL がない場合は、呼び出し元の ``umask`` を適用します。新しいディレクトリにはデフォルト ACL 自体も継承されます。"
Original file line number Diff line number Diff line change
Expand Up @@ -334,3 +334,19 @@ msgstr "書き込み可能な制御ファイルを開くと、対象 inode の

msgid "文本虚拟终端的 ``K_XLATE`` 和 ``K_UNICODE`` 键盘模式均支持 ``Ctrl+Alt+F1`` 至 ``Ctrl+Alt+F6`` 切换,遵循既有终端交接流程。Unicode 模式保留 UTF-8 输入。"
msgstr "テキスト仮想端末は ``K_XLATE`` と ``K_UNICODE`` の両キーボードモードで、既存の端末引き渡し手順に従い ``Ctrl+Alt+F1`` から ``Ctrl+Alt+F6`` による切り替えに対応します。Unicode モードでは UTF-8 入力を維持します。"

msgid "内核日志设备"
msgstr "カーネルログデバイス"

msgid ""
"``/dev/kmsg`` 以 Linux 的字符设备号 ``1:11`` 提供内核日志。每次打开独立记录 读取位置,``dup`` 和 "
"``fork`` 共享打开描述的游标。每次读取返回一条包含优先级、 序号和启动后微秒时间的完整记录。缓冲区无新记录时,阻塞读取可被信号中断, "
"非阻塞读取返回 ``EAGAIN``。读取落后于日志环时返回 ``EPIPE`` 并定位到最旧 的可读记录。poll 和 epoll "
"可等待新记录并报告溢出。"
msgstr "``/dev/kmsg`` は Linux のキャラクターデバイス番号 ``1:11`` でカーネルログを公開します。開くたびに独立した読み取り位置が割り当てられ、``dup`` または ``fork`` で共有されたファイル記述は同じ位置を使います。読み取りは優先度、シーケンス番号、起動からのマイクロ秒を含むレコードを一件ずつ返します。新しい記録がない場合、ブロッキング読み取りはシグナルで中断でき、非ブロッキング読み取りは ``EAGAIN`` を返します。読み取りがリングの上書きに追い越されると ``EPIPE`` を返し、読み取れる最も古い記録へ進みます。poll と epoll で新しい記録やオーバーランを待機できます。"

msgid ""
"``lseek(fd, 0, SEEK_SET)`` 定位到最旧记录,``SEEK_END`` 定位到当前末尾, ``SEEK_DATA`` "
"定位到初始序号。用户态每次 ``write`` 或 ``writev`` 写入一条 记录,可带 syslog 的 ``<优先级>`` "
"前缀。用户态记录使用非内核 facility。"
msgstr "``lseek(fd, 0, SEEK_SET)`` は最も古い記録を、``SEEK_END`` は現在の末尾を、``SEEK_DATA`` は初期シーケンスを選びます。ユーザー空間の ``write`` または ``writev`` は一件の記録を追加し、syslog の ``<優先度>`` プレフィックスを指定できます。ユーザー空間の記録にはカーネル用以外のファシリティを使います。"
18 changes: 18 additions & 0 deletions Documentation/userspace-api/abi.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,24 @@ fork、vfork、clone 复制调用任务的选择,exec 保留选择。已经存
没有这种祖先则回退到 PID 1。新父进程可等待被接管的子进程,并按 SIGCHLD 规则
接收退出通知。当前不提供独立的 PID 命名空间。

广播进程信号
============

``kill(-1, sig)`` 按 Linux 语义遍历每个用户进程一次。PID 1 和调用者的整个线程组
跳过,其他进程分别检查 UID、目标用户空间的 ``CAP_KILL`` 以及同会话 ``SIGCONT``
权限。信号 0 只作探测。信号携带 ``SI_USER``、发送进程 ID 和按接收者用户空间
映射的发送者真实 UID。没有候选进程时返回 ``ESRCH``。

ext 文件系统 ACL
================

ext2、ext3 和 ext4 支持 ``system.posix_acl_access`` 与
``system.posix_acl_default``。路径和描述符的 xattr 调用使用 Linux ACL 编码。
文件所有者或具有相应权限的进程可以设置和删除 ACL。访问检查应用命名用户、
命名组、补充组和 ACL 掩码。``chmod`` 同步调整访问 ACL 的权限类别。
新 inode 从父目录继承默认 ACL,并按请求的模式限制权限。父目录没有默认 ACL
时,inode 创建使用调用者的 ``umask``。新目录同时继承默认 ACL。

创建挂载命名空间
================

Expand Down
13 changes: 13 additions & 0 deletions Documentation/userspace-api/device-filesystems.rst
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,19 @@ devpts 挂载选项
权限决定是否可打开。找不到有效的 devpts 多路复用器时沿用启动阶段的旧 PTY
分配;其他查找错误则返回调用方。

内核日志设备
============

``/dev/kmsg`` 以 Linux 的字符设备号 ``1:11`` 提供内核日志。每次打开独立记录
读取位置,``dup`` 和 ``fork`` 共享打开描述的游标。每次读取返回一条包含优先级、
序号和启动后微秒时间的完整记录。缓冲区无新记录时,阻塞读取可被信号中断,
非阻塞读取返回 ``EAGAIN``。读取落后于日志环时返回 ``EPIPE`` 并定位到最旧
的可读记录。poll 和 epoll 可等待新记录并报告溢出。

``lseek(fd, 0, SEEK_SET)`` 定位到最旧记录,``SEEK_END`` 定位到当前末尾,
``SEEK_DATA`` 定位到初始序号。用户态每次 ``write`` 或 ``writev`` 写入一条
记录,可带 syslog 的 ``<优先级>`` 前缀。用户态记录使用非内核 facility。

前台虚拟终端
============

Expand Down
2 changes: 2 additions & 0 deletions arch/x86_64/interrupt/irq.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Routes timer, input, storage, and device interrupts to kernel subsystems.
*/
#include <reliefnt/console.h>
#include <reliefnt/kmsg.h>
#include <reliefnt/proc_stats.h>
#include <reliefnt/apic.h>
#include <reliefnt/driver_manager.h>
Expand Down Expand Up @@ -201,6 +202,7 @@ struct task *irq_dispatch(struct trap_frame *frame)
if (vector == 0x20) {
time_on_tick();
serial_tx_tick();
kmsg_notify_readers();
if (from_user) {
uint8_t byte;
if (keyboard_led_next(&keyboard_led, input_caps_lock_active() ? 4U : 0U,
Expand Down
2 changes: 1 addition & 1 deletion drivers/console/Kbuild
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-License-Identifier: Apache-2.0
obj-y := ansi.o core.o log.o panic.o render.o vt.o vga_console.o vga_terminal.o vga_ansi.o
obj-y := ansi.o core.o kmsg.o log.o panic.o render.o vt.o vga_console.o vga_terminal.o vga_ansi.o

include $(srctree)/scripts/Makefile.module
176 changes: 176 additions & 0 deletions drivers/console/kmsg.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
/* SPDX-License-Identifier: Apache-2.0 */
#include <reliefnt/console.h>
#include <reliefnt/kmsg.h>
#include <reliefnt/lock.h>
#include <reliefnt/time.h>
#include <reliefnt/wait.h>
#include <linux/errno.h>
#include <linux/poll.h>

#define KMSG_RECORDS 512u

struct kmsg_record {
uint64_t timestamp;
uint16_t length;
uint16_t priority;
char text[KMSG_MESSAGE_MAX];
};

static struct kmsg_record records[KMSG_RECORDS];
static struct kernel_spinlock ring_lock = KERNEL_SPINLOCK_INIT;
static uint64_t next_sequence;
static uint64_t notified_sequence;

/** @brief Compute the oldest live record from a single sequence snapshot. */
static uint64_t oldest(uint64_t next)
{
return next > KMSG_RECORDS ? next - KMSG_RECORDS : 0;
}

/** @copydoc kmsg_append */
void kmsg_append(unsigned priority, uint64_t timestamp, const char *text, size_t length)
{
uint64_t flags;
kernel_spin_lock_irqsave(&ring_lock, &flags);
uint64_t next = __atomic_load_n(&next_sequence, __ATOMIC_RELAXED);
struct kmsg_record *record = &records[next % KMSG_RECORDS];
if (next && timestamp < records[(next - 1) % KMSG_RECORDS].timestamp)
timestamp = records[(next - 1) % KMSG_RECORDS].timestamp;
if (length > sizeof(record->text)) length = sizeof(record->text);
record->timestamp = timestamp;
record->length = (uint16_t)length;
record->priority = (uint16_t)priority;
__builtin_memcpy(record->text, text, length);
__atomic_store_n(&next_sequence, next + 1, __ATOMIC_RELEASE);
kernel_spin_unlock_irqrestore(&ring_lock, flags);
}

/** @copydoc kmsg_next_sequence */
uint64_t kmsg_next_sequence(void)
{
return __atomic_load_n(&next_sequence, __ATOMIC_ACQUIRE);
}

/** @copydoc kmsg_first_sequence */
uint64_t kmsg_first_sequence(void)
{
return oldest(kmsg_next_sequence());
}

/** @copydoc kmsg_readiness */
short kmsg_readiness(uint64_t sequence)
{
uint64_t next = kmsg_next_sequence();
if (sequence >= next) return 0;
return POLLIN | POLLRDNORM | (sequence < oldest(next) ? POLLERR | POLLPRI : 0);
}

/** @brief Write a decimal field and its separator into the bounded header.
* @param cursor Next output byte, with room for a uint64_t and a comma.
* @param value Field value. @return Position immediately after the comma.
*/
static char *decimal_field(char *cursor, uint64_t value)
{
char digits[20];
size_t count = 0;
do {
digits[count++] = (char)('0' + value % 10);
value /= 10;
} while (value);
while (count) *cursor++ = digits[--count];
*cursor++ = ',';
return cursor;
}

/** @brief Determine whether the kmsg record format escapes this byte. */
static bool escape_byte(unsigned char ch)
{
return ch < 32 || ch >= 127 || ch == '\\';
}

/** @copydoc kmsg_read_record */
int kmsg_read_record(uint64_t *sequence, char *buffer, size_t capacity)
{
uint64_t flags, cursor = *sequence;
struct kmsg_record record;
kernel_spin_lock_irqsave(&ring_lock, &flags);
uint64_t next = __atomic_load_n(&next_sequence, __ATOMIC_RELAXED);
uint64_t first = oldest(next);
if (cursor < first) {
*sequence = first;
kernel_spin_unlock_irqrestore(&ring_lock, flags);
return -EPIPE;
}
if (cursor >= next) {
kernel_spin_unlock_irqrestore(&ring_lock, flags);
return -EAGAIN;
}
record = records[cursor % KMSG_RECORDS];
*sequence = cursor + 1;
kernel_spin_unlock_irqrestore(&ring_lock, flags);

char header[64];
char *end = decimal_field(header, record.priority);
end = decimal_field(end, cursor);
end = decimal_field(end, record.timestamp);
*end++ = '-';
*end++ = ';';
size_t header_length = (size_t)(end - header);
size_t length = header_length + 1; /* Final newline. */
for (size_t i = 0; i < record.length; ++i)
length += escape_byte((unsigned char)record.text[i]) ? 4u : 1u;
if (length > capacity) return -EINVAL;
__builtin_memcpy(buffer, header, header_length);
end = buffer + header_length;
static const char hex[] = "0123456789abcdef";
for (size_t i = 0; i < record.length; ++i) {
unsigned char ch = (unsigned char)record.text[i];
if (escape_byte(ch)) {
*end++ = '\\';
*end++ = 'x';
*end++ = hex[ch >> 4];
*end++ = hex[ch & 15u];
} else {
*end++ = (char)ch;
}
}
*end = '\n';
return (int)length;
}

/** @copydoc kmsg_write_record */
int kmsg_write_record(const char *buffer, size_t length)
{
if (length > KMSG_MESSAGE_MAX) return -EINVAL;
if (!length) return 0;
char text[KMSG_MESSAGE_MAX];
__builtin_memcpy(text, buffer, length);
size_t end = 0, start = 0;
while (end < length && text[end]) ++end;
uint32_t priority = 12; /* LOG_USER | LOG_WARNING. */
if (end > 1 && text[0] == '<') {
size_t i = 1;
uint32_t prefix = 0;
while (i < end && text[i] >= '0' && text[i] <= '9')
prefix = prefix * 10u + (unsigned)(text[i++] - '0');
if (i < end && text[i] == '>') {
priority = prefix & 0x7ffu;
if (!(priority >> 3)) priority |= 8u;
start = i + 1;
}
}
if (end > start && text[end - 1] == '\n') --end;
kmsg_append(priority, time_uptime_us(), text + start, end - start);
if ((priority & 7u) != 7u) console_write_len(text + start, end - start);
return (int)length;
}

/** @copydoc kmsg_notify_readers */
void kmsg_notify_readers(void)
{
uint64_t next = kmsg_next_sequence();
if (next != notified_sequence) {
notified_sequence = next;
kernel_poll_readiness_notify();
}
}
Loading
Loading