Skip to content

Commit 6a4e0be

Browse files
authored
feat(syscall): add msgget, msgsnd, msgrcv, and msgctl (#57)
1 parent 97d7c9d commit 6a4e0be

File tree

5 files changed

+960
-23
lines changed

5 files changed

+960
-23
lines changed

api/src/syscall/ipc/mod.rs

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,48 @@
11
use core::sync::atomic::{AtomicI32, Ordering};
22

3+
use starry_core::shm::IpcPerm;
4+
35
static IPC_ID: AtomicI32 = AtomicI32::new(0);
46

57
fn next_ipc_id() -> i32 {
68
IPC_ID.fetch_add(1, Ordering::Relaxed)
79
}
810

11+
mod msg;
912
mod shm;
13+
pub use self::{msg::*, shm::*};
14+
15+
// IPC command constants
16+
const IPC_PRIVATE: i32 = 0;
17+
const IPC_CREAT: i32 = 0o1000;
18+
const IPC_EXCL: i32 = 0o2000;
19+
const IPC_RMID: i32 = 0;
20+
const IPC_SET: i32 = 1;
21+
const IPC_STAT: i32 = 2;
22+
const IPC_INFO: i32 = 3;
23+
const MSG_STAT: i32 = 11;
24+
const MSG_INFO: i32 = 12;
25+
26+
// Permission bits
27+
const USER_READ: u32 = 0o400;
28+
const USER_WRITE: u32 = 0o200;
29+
const GROUP_READ: u32 = 0o040;
30+
const GROUP_WRITE: u32 = 0o020;
31+
const OTHER_READ: u32 = 0o004;
32+
const OTHER_WRITE: u32 = 0o002;
1033

11-
pub use self::shm::*;
34+
// add a helper function to check IPC permissions
35+
fn has_ipc_permission(perm: &IpcPerm, current_uid: u32, current_gid: u32, is_write: bool) -> bool {
36+
// root user has all permissions
37+
if current_uid == 0 {
38+
return true;
39+
}
40+
41+
if perm.uid == current_uid {
42+
(perm.mode & if is_write { USER_WRITE } else { USER_READ }) != 0
43+
} else if perm.gid == current_gid {
44+
(perm.mode & if is_write { GROUP_WRITE } else { GROUP_READ }) != 0
45+
} else {
46+
(perm.mode & if is_write { OTHER_WRITE } else { OTHER_READ }) != 0
47+
}
48+
}

0 commit comments

Comments
 (0)