Skip to content

Commit 49d1583

Browse files
committed
使得 xinit 可以连接到 Xorg 并进入黑屏
1 parent c79f337 commit 49d1583

File tree

25 files changed

+1173
-874
lines changed

25 files changed

+1173
-874
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,6 @@ assets/*.elf
3737
# AI Agent Cache
3838
.codex
3939
AGENTS.md
40+
41+
# Log files
42+
*.log

libs/liballoc-x86_64.a

15.7 KB
Binary file not shown.

module/squashfs/squashfs.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ static errno_t squashfs_id = -1;
55
static sqfs_u64 squashfs_mount_dev = 1;
66
errno_t errno = EOK;
77

8-
#define SQUASHFS_IMAGE_CACHE_SIZE 262144ULL
8+
#define SQUASHFS_IMAGE_CACHE_SIZE 262144ULL
99
#define SQUASHFS_IMAGE_CACHE_ALIGN 4096ULL
1010

1111
typedef struct {
@@ -25,8 +25,9 @@ typedef struct {
2525
} squashfs_compressor_stub_t;
2626

2727
static void squashfs_open(void *parent, const char *name, vfs_node_t node);
28-
static squashfs_handle_t *
29-
squashfs_handle_create(squashfs_mount_t *mount, sqfs_inode_generic_t *inode, const sqfs_u64 inode_ref);
28+
static squashfs_handle_t *squashfs_handle_create(
29+
squashfs_mount_t *mount, sqfs_inode_generic_t *inode, const sqfs_u64 inode_ref
30+
);
3031

3132
static void squashfs_handle_release(squashfs_handle_t *handle) {
3233
if (handle == NULL) {
@@ -446,7 +447,7 @@ int squashfs_populate_dir(const vfs_node_t node, const squashfs_handle_t *handle
446447
return 0;
447448
}
448449

449-
mount = handle->mount;
450+
mount = handle->mount;
450451
dir_reader = squashfs_create_directory_reader(mount);
451452
if (dir_reader == NULL) {
452453
return SQFS_ERROR_ALLOC;
@@ -731,13 +732,12 @@ static size_t squashfs_read(void *file, void *addr, size_t offset, size_t size)
731732
squashfs_handle_t *handle = file;
732733
sqfs_s32 ret;
733734

734-
spin_lock(handle->lock);
735-
736735
if (handle == NULL || addr == NULL) {
737-
spin_unlock(handle->lock);
738736
return (size_t)-1;
739737
}
740738

739+
spin_lock(handle->lock);
740+
741741
if (handle->inode->base.type != SQFS_INODE_FILE
742742
&& handle->inode->base.type != SQFS_INODE_EXT_FILE) {
743743
spin_unlock(handle->lock);

src/arch/x86_64/task/prsys_x64.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,9 @@ shebang_retry:;
483483
action->sa_restorer = NULL;
484484
}
485485
}
486-
current->signal = 0; // clear pending signals
486+
current->signal = 0; // clear pending signals
487+
current->pending_siginfo_mask = 0;
488+
memset(current->pending_siginfo, 0, sizeof(current->pending_siginfo));
487489
}
488490

489491
// 根据 POSIX 的 execve 规范定义, 内核对象不变, 故懒分配器, IPC等不动

src/driver/tty.c

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,45 @@ static struct llist_header tty_session_list;
1717
static tty_t *kernel_session = NULL; // 内核会话
1818
static tty_t *current_session = NULL; // 当前会话
1919

20+
static void tty_session_node_name(const tty_t *session, char *buf, size_t buf_len) {
21+
if (!buf || buf_len == 0) {
22+
return;
23+
}
24+
25+
buf[0] = '\0';
26+
if (!session || !session->device) {
27+
return;
28+
}
29+
30+
int graphics_idx = 1;
31+
int serial_idx = 1;
32+
tty_t *pos = NULL;
33+
tty_t *n = NULL;
34+
llist_for_each(pos, n, &tty_session_list, list_node) {
35+
if (!pos || !pos->device) {
36+
continue;
37+
}
38+
39+
if (pos->device->type == TTY_DEVICE_SERIAL) {
40+
if (pos == session) {
41+
snprintf(buf, buf_len, "ttyS%d", serial_idx);
42+
return;
43+
}
44+
serial_idx++;
45+
continue;
46+
}
47+
48+
if (pos == session) {
49+
snprintf(buf, buf_len, "tty%d", graphics_idx);
50+
return;
51+
}
52+
graphics_idx++;
53+
}
54+
55+
strncpy(buf, session->device->name, buf_len - 1);
56+
buf[buf_len - 1] = '\0';
57+
}
58+
2059
tty_t *get_kernel_session() {
2160
return kernel_session;
2261
}
@@ -257,9 +296,11 @@ static errno_t tty_ioctl(tty_t *session, const size_t req, void *arg) {
257296
if (proc->ctty_path) {
258297
free(proc->ctty_path);
259298
}
260-
char buf[64];
261-
snprintf(buf, sizeof(buf), "/dev/%s", session->device ? session->device->name : "tty0");
262-
proc->ctty_path = strdup(buf);
299+
char tty_name[32];
300+
char path[64];
301+
tty_session_node_name(session, tty_name, sizeof(tty_name));
302+
snprintf(path, sizeof(path), "/dev/%s", tty_name[0] ? tty_name : "tty1");
303+
proc->ctty_path = strdup(path);
263304
session->fgproc = proc->pgid;
264305
break;
265306
}
@@ -606,16 +647,16 @@ void init_tty_session() {
606647

607648
void init_console_symlink() {
608649
const char *console = boot_get_cmdline_param("console");
609-
if (console == NULL) {
610-
console = "tty0";
611-
}
612-
613650
char buf[50];
614-
sprintf(buf, "/dev/%s", console);
651+
if (console == NULL || streq(console, "tty0")) {
652+
strcpy(buf, "/dev/tty1");
653+
} else {
654+
sprintf(buf, "/dev/%s", console);
655+
}
615656

616657
const vfs_node_t console_node = vfs_open(buf);
617658
if (console_node == NULL) {
618-
strcpy(buf, "/dev/tty0");
659+
strcpy(buf, "/dev/tty1");
619660
} else {
620661
vfs_close(console_node);
621662
}

src/fs/devtmpfs.c

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,34 +16,16 @@ int dev_tmpfs_id = 0;
1616
static _Atomic volatile size_t dev_id_now = 0;
1717

1818
static void load_tty_device(vfs_node_t node) {
19-
int tty_id = 1;
20-
21-
tty_t *kernel_session = get_kernel_session();
22-
create_device_node(
23-
node,
24-
"tty0",
25-
device_stream,
26-
kernel_session,
27-
0,
28-
(void *)kernel_session->ops.ioctl,
29-
(void *)kernel_session->ops.read,
30-
(void *)kernel_session->ops.write,
31-
(void *)kernel_session->ops.poll,
32-
NULL,
33-
(void *)kernel_session->ops.size_t
34-
);
35-
36-
tty_t *pos = NULL;
37-
tty_t *n = NULL;
19+
int graphics_id = 1;
20+
int serial_id = 1;
21+
tty_t *pos = NULL;
22+
tty_t *n = NULL;
3823
llist_for_each(pos, n, get_tty_session_list(), list_node) {
39-
if (pos == kernel_session) {
40-
continue;
41-
}
4224
char name[10];
4325
if (pos->device->type == TTY_DEVICE_SERIAL) {
44-
sprintf(name, "ttyS%d", tty_id++);
26+
sprintf(name, "ttyS%d", serial_id++);
4527
} else {
46-
sprintf(name, "tty%d", tty_id++);
28+
sprintf(name, "tty%d", graphics_id++);
4729
}
4830

4931
create_device_node(
@@ -60,6 +42,10 @@ static void load_tty_device(vfs_node_t node) {
6042
(void *)pos->ops.size_t
6143
);
6244
}
45+
46+
if (graphics_id > 1) {
47+
vfs_symlink("/dev/tty0", "/dev/tty1");
48+
}
6349
}
6450

6551
static void load_blk_device(vfs_node_t node) {

0 commit comments

Comments
 (0)