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
53 changes: 32 additions & 21 deletions PROGRESS.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,36 @@
- `help` - ヘルプ表示
- `clear` - 画面クリア
- `echo` - テキスト出力
- `ps` - プロセス一覧 (スタブ)
- `ps` - プロセス一覧
- `kill` - プロセス終了
- `spawn` - テストプロセス生成
- `ls` - ファイル一覧 (スタブ)
- `cat` - ファイル表示 (スタブ)
- `about` - システム情報
- `exit` - 終了

#### 6. GUI/ブラウザ統合
#### 6. プロセス管理
- [x] プロセステーブルの実装
- [x] プロセス制御ブロック (PCB)
- [x] 最大64プロセスのサポート
- [x] プロセス状態管理 (UNUSED, INIT, READY, RUNNING, WAITING, ZOMBIE, TERMINATED)
- [x] `posix_spawn` 実装 (fork()の代替)
- [x] プロセススケジューラー
- [x] ラウンドロビンスケジューリング
- [x] レディキュー管理
- [x] 協調的マルチタスキング (WebAssembly制約)
- [x] プロセス間通信 (IPC)
- [x] メッセージパッシング
- [x] パイプ実装
- [x] ブロッキング/ノンブロッキング操作

#### 7. GUI/ブラウザ統合
- [x] ターミナルウィンドウ UI
- [x] ウィンドウマネージャー (ドラッグ、最大化)
- [x] stdin/stdout のブラウザ統合
- [x] コマンドハンドラー経由の入力処理

#### 7. ビルドシステム
#### 8. ビルドシステム
- [x] Ninja ビルドシステム
- [x] TypeScript/JavaScript モジュール構造
- [x] CSS分離
Expand All @@ -63,54 +80,48 @@

### 高優先度

#### 1. プロセス管理
- [ ] プロセステーブルの実装
- [ ] `fork()` の代替実装 (`posix_spawn`)
- [ ] プロセススケジューラー
- [ ] プロセス間通信 (IPC)

#### 2. ファイルシステム
#### 1. ファイルシステム
- [ ] 実際のファイルシステム実装
- [ ] IndexedDB バックエンド
- [ ] ディレクトリ操作 (mkdir, rmdir)
- [ ] ファイル操作 (open, read, write, close)
- [ ] パーミッション管理

#### 3. ネットワーク
#### 2. ネットワーク
- [ ] ソケット API の実装
- [ ] WebSocket ベースのネットワーク層
- [ ] 基本的なネットワークコマンド (ping, wget 相当)

### 中優先度

#### 4. シェル拡張
#### 3. シェル拡張
- [ ] パイプ機能
- [ ] リダイレクト
- [ ] 環境変数
- [ ] ジョブコントロール
- [ ] コマンド履歴
- [ ] タブ補完

#### 5. デバイスドライバ
#### 4. デバイスドライバ
- [ ] キーボードドライバ (詳細な入力処理)
- [ ] マウスドライバ
- [ ] フレームバッファドライバ (グラフィックス)

#### 6. 標準ユーティリティ
#### 5. 標準ユーティリティ
- [ ] 基本的なUNIXコマンド群
- [ ] `cp`, `mv`, `rm`
- [ ] `grep`, `sed`, `awk`
- [ ] `vi` または `nano` エディタ

### 低優先度

#### 7. 高度な機能
#### 6. 高度な機能
- [ ] マルチスレッド (pthread)
- [ ] 共有ライブラリ
- [ ] デバッガー
- [ ] パッケージマネージャー

#### 8. パフォーマンス最適化
#### 7. パフォーマンス最適化
- [ ] メモリ管理の最適化
- [ ] ファイルシステムキャッシュ
- [ ] コンパイラ最適化
Expand All @@ -126,7 +137,6 @@
- procfs の完全な実装が必要 (`kernel/fs/vfs.c:183`)

3. **標準ライブラリ**
- 可変引数の処理が未実装 (`kernel/lib/stdio.c:95-96, 103-104`)
- 数値変換が未実装 (`kernel/drivers/console.c:111`)

4. **ドライバ**
Expand Down Expand Up @@ -154,7 +164,8 @@

## 次のステップ

1. プロセス管理の基本実装を開始
2. 実際のファイルシステムの実装
3. より多くのシェルコマンドの追加
4. テストスイートの作成
1. 実際のファイルシステムの実装 (IndexedDB バックエンド)
2. プロセス管理の高度な機能 (シグナル、wait/waitpid)
3. シェルのパイプとリダイレクト機能
4. より多くのUNIXコマンドの実装
5. テストスイートの作成
7 changes: 6 additions & 1 deletion build.ninja
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,14 @@ build build/kernel/lib/stdio.o: CC kernel/lib/stdio.c
build build/kernel/lib/wasi_wrapper.o: CC kernel/lib/wasi_wrapper.c
build build/kernel/shell/shell.o: CC kernel/shell/shell.c
build build/kernel/shell/shell_api.o: CC kernel/shell/shell_api.c
build build/kernel/process/process.o: CC kernel/process/process.c
build build/kernel/process/scheduler.o: CC kernel/process/scheduler.c
build build/kernel/process/spawn.o: CC kernel/process/spawn.c
build build/kernel/ipc/ipc.o: CC kernel/ipc/ipc.c
build build/kernel/ipc/pipe.o: CC kernel/ipc/pipe.c

# カーネルリンク
build build/kernel.wasm: LD build/kernel/init/main.o build/kernel/mm/memory.o build/kernel/fs/vfs.o build/kernel/drivers/console.o build/kernel/drivers/drivers.o build/kernel/lib/string.o build/kernel/lib/stdio.o build/kernel/lib/wasi_wrapper.o build/kernel/shell/shell.o build/kernel/shell/shell_api.o
build build/kernel.wasm: LD build/kernel/init/main.o build/kernel/mm/memory.o build/kernel/fs/vfs.o build/kernel/drivers/console.o build/kernel/drivers/drivers.o build/kernel/lib/string.o build/kernel/lib/stdio.o build/kernel/lib/wasi_wrapper.o build/kernel/shell/shell.o build/kernel/shell/shell_api.o build/kernel/process/process.o build/kernel/process/scheduler.o build/kernel/process/spawn.o build/kernel/ipc/ipc.o build/kernel/ipc/pipe.o

# GUI とシステムライブラリ
build build/index.html: COPY gui/index.html
Expand Down
3 changes: 3 additions & 0 deletions kernel/include/init.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
int mm_init(void); /* メモリ管理初期化 */
int fs_init(void); /* ファイルシステム初期化 */
int drivers_init(void); /* デバイスドライバ初期化 */
int process_init(void); /* プロセス管理初期化 */
void scheduler_init(void); /* スケジューラ初期化 */
int ipc_init(void); /* IPC初期化 */

/* 初期化順序定義 */
#define INIT_LEVEL_EARLY 0
Expand Down
87 changes: 87 additions & 0 deletions kernel/include/ipc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* WebVM プロセス間通信 (IPC) ヘッダ
*/

#ifndef __WEBVM_IPC_H__
#define __WEBVM_IPC_H__

#include <stdint.h>
#include <stddef.h>
#include "process.h"

/* IPC定数 */
#define MAX_MESSAGE_SIZE 1024
#define MAX_MESSAGES_PER_PROCESS 16

/* メッセージタイプ */
typedef enum {
MSG_TYPE_DATA = 0, /* データメッセージ */
MSG_TYPE_SIGNAL, /* シグナル */
MSG_TYPE_PIPE, /* パイプデータ */
MSG_TYPE_SHARED_MEM /* 共有メモリ通知 */
} message_type_t;

/* メッセージ構造体 */
struct ipc_message {
pid_t sender_pid; /* 送信者PID */
pid_t receiver_pid; /* 受信者PID */
message_type_t type; /* メッセージタイプ */
size_t size; /* データサイズ */
void *data; /* データポインタ */
uint64_t timestamp; /* タイムスタンプ */
struct ipc_message *next; /* 次のメッセージ */
};

/* メッセージキュー */
struct message_queue {
struct ipc_message *head;
struct ipc_message *tail;
uint32_t count;
uint32_t max_messages;
};

/* パイプ構造体 */
struct pipe {
char *buffer; /* バッファ */
size_t size; /* バッファサイズ */
size_t read_pos; /* 読み込み位置 */
size_t write_pos; /* 書き込み位置 */
pid_t reader_pid; /* 読み込みプロセス */
pid_t writer_pid; /* 書き込みプロセス */
bool closed_read; /* 読み込み側クローズ */
bool closed_write; /* 書き込み側クローズ */
};

/* 共有メモリセグメント */
struct shared_memory {
void *address; /* メモリアドレス */
size_t size; /* サイズ */
uint32_t ref_count; /* 参照カウント */
pid_t owner_pid; /* 所有者PID */
uint32_t flags; /* フラグ */
};

/* IPC初期化 */
int ipc_init(void);

/* メッセージ送受信 */
int ipc_send_message(pid_t to_pid, const void *data, size_t size, message_type_t type);
int ipc_receive_message(struct ipc_message **msg, bool blocking);
void ipc_free_message(struct ipc_message *msg);

/* パイプ操作 */
int ipc_create_pipe(int *read_fd, int *write_fd);
int ipc_pipe_read(int fd, void *buf, size_t count);
int ipc_pipe_write(int fd, const void *buf, size_t count);
int ipc_pipe_close(int fd);

/* 共有メモリ */
void *ipc_create_shared_memory(size_t size);
void *ipc_attach_shared_memory(int shmid);
int ipc_detach_shared_memory(void *addr);
int ipc_destroy_shared_memory(int shmid);

/* デバッグ */
void ipc_dump_queues(void);

#endif /* __WEBVM_IPC_H__ */
115 changes: 115 additions & 0 deletions kernel/include/process.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/*
* WebVM プロセス管理ヘッダ
*/

#ifndef __WEBVM_PROCESS_H__
#define __WEBVM_PROCESS_H__

#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>

/* プロセス定数 */
#define MAX_PROCESSES 64
#define MAX_PROCESS_NAME 32
#define PROCESS_STACK_SIZE (64 * 1024) /* 64KB スタック */

/* プロセス状態 */
typedef enum {
PROCESS_STATE_UNUSED = 0,
PROCESS_STATE_INIT,
PROCESS_STATE_READY,
PROCESS_STATE_RUNNING,
PROCESS_STATE_WAITING,
PROCESS_STATE_ZOMBIE,
PROCESS_STATE_TERMINATED
} process_state_t;

/* プロセスID型 */
typedef int32_t pid_t;

/* プロセスコンテキスト (WebAssembly制約下での簡易版) */
struct process_context {
void *stack_ptr; /* スタックポインタ */
void *pc; /* プログラムカウンタ (関数ポインタ) */
uint32_t flags; /* フラグ */
};

/* プロセス制御ブロック (PCB) */
struct process {
pid_t pid; /* プロセスID */
pid_t ppid; /* 親プロセスID */
char name[MAX_PROCESS_NAME]; /* プロセス名 */
process_state_t state; /* プロセス状態 */

/* メモリ管理 */
void *stack_base; /* スタックベースアドレス */
size_t stack_size; /* スタックサイズ */
void *heap_base; /* ヒープベースアドレス */
size_t heap_size; /* ヒープサイズ */

/* コンテキスト */
struct process_context context; /* プロセスコンテキスト */

/* エントリポイント */
int (*entry)(int argc, char **argv); /* プロセスエントリポイント */
int argc; /* 引数カウント */
char **argv; /* 引数配列 */

/* 終了情報 */
int exit_code; /* 終了コード */

/* 統計情報 */
uint64_t start_time; /* 開始時刻 */
uint64_t cpu_time; /* CPU使用時間 */

/* リンクリスト */
struct process *next; /* 次のプロセス */
struct process *prev; /* 前のプロセス */
};

/* プロセステーブル */
struct process_table {
struct process processes[MAX_PROCESSES];
struct process *current; /* 現在実行中のプロセス */
struct process *ready_list; /* 実行可能プロセスリスト */
pid_t next_pid; /* 次のPID */
uint32_t process_count; /* プロセス数 */
};

/* プロセス管理関数 */
int process_init(void);
pid_t process_create(const char *name, int (*entry)(int, char**), int argc, char **argv);
int process_exit(int exit_code);
int process_wait(pid_t pid);
int process_kill(pid_t pid, int signal);
struct process *process_get_current(void);
struct process *process_find(pid_t pid);

/* スケジューラ関数 */
void scheduler_init(void);
void scheduler_tick(void);
void scheduler_yield(void);
void scheduler_add_ready(struct process *proc);
void scheduler_remove_ready(struct process *proc);

/* POSIX spawn API */
typedef struct {
int flags;
/* 将来的な拡張用 */
} posix_spawnattr_t;

typedef struct {
char **argv;
char **envp;
} posix_spawn_file_actions_t;

int posix_spawn(pid_t *pid, const char *path,
const posix_spawn_file_actions_t *file_actions,
const posix_spawnattr_t *attrp,
char *const argv[], char *const envp[]);

/* デバッグ関数 */
void process_dump_table(void);

#endif /* __WEBVM_PROCESS_H__ */
Loading