mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-02 20:58:15 +00:00
sys/linux: Unify IPC_Flags and IPC_Mode bitsets
In #5399 it was noticed, that IPC_Mode isn't being used within SystemV IPC procedures, even though it was designed this way, which lead to a weird API where in order to call SystemV IPC procedures multiple transmutes and a bitwise-OR are needed. This unifies IPC_Mode and IPC_Flags bitsets, making it possible to call the SystemV IPC procedures without extra casts, and rearranges the flags in a way that hopefully makes it easier to see when they are not colliding and should not be mixed. The explanation, explaining this arrangement of the enum was added. The IPC_Perm structure is modified, so that the flags can be re-used between the calls. It's probably not as good as keeping them separate, but should work... hopefully. Kept the "old" style of documentation for consistency. Signed-off-by: Sunagatov Denis <thebumboni@gmail.com>
This commit is contained in:
+18
-15
@@ -1618,36 +1618,39 @@ PER_HPUX :: 0x0010
|
|||||||
PER_MASK :: 0x00ff
|
PER_MASK :: 0x00ff
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Bits for access modes for shared memory
|
Bits for SystemV IPC flags.
|
||||||
|
|
||||||
|
In this enum, access modes are common for any shared memory. Prefixed
|
||||||
|
entries (i.e. `IPC_` or `SHM_`) denote flags, where `IPC_` are common flags
|
||||||
|
for all SystemV IPC primitives, and `SHM_`, `SEM_` and `MSG_` are specific
|
||||||
|
to shared memory segments, semaphores and message queues respectively.
|
||||||
|
|
||||||
|
These bits overlap, because they are meant to be used within the
|
||||||
|
context of specific procedures. Creation flags, used for `*get` procedures,
|
||||||
|
and usage flags used by all other IPC procedures. Do not mix creation and
|
||||||
|
usage flags, as well as flags prefixed differently (excluding `IPC_`
|
||||||
|
prefix).
|
||||||
*/
|
*/
|
||||||
IPC_Mode_Bits :: enum {
|
IPC_Flags_Bits :: enum {
|
||||||
|
// Access modes for shared memory.
|
||||||
WROTH = 1,
|
WROTH = 1,
|
||||||
RDOTH = 2,
|
RDOTH = 2,
|
||||||
WRGRP = 4,
|
WRGRP = 4,
|
||||||
RDGRP = 5,
|
RDGRP = 5,
|
||||||
WRUSR = 7,
|
WRUSR = 7,
|
||||||
RDUSR = 8,
|
RDUSR = 8,
|
||||||
DEST = 9,
|
// Creation flags for shared memory.
|
||||||
LOCKED = 10,
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
Shared memory flags bits
|
|
||||||
*/
|
|
||||||
IPC_Flags_Bits :: enum {
|
|
||||||
IPC_CREAT = 9,
|
IPC_CREAT = 9,
|
||||||
IPC_EXCL = 10,
|
IPC_EXCL = 10,
|
||||||
IPC_NOWAIT = 11,
|
|
||||||
// Semaphore
|
|
||||||
SEM_UNDO = 9,
|
|
||||||
// Shared memory
|
|
||||||
SHM_HUGETLB = 11,
|
SHM_HUGETLB = 11,
|
||||||
SHM_NORESERVE = 12,
|
SHM_NORESERVE = 12,
|
||||||
|
// Usage flags for shared memory.
|
||||||
|
IPC_NOWAIT = 11,
|
||||||
|
SEM_UNDO = 9,
|
||||||
SHM_RDONLY = 12,
|
SHM_RDONLY = 12,
|
||||||
SHM_RND = 13,
|
SHM_RND = 13,
|
||||||
SHM_REMAP = 14,
|
SHM_REMAP = 14,
|
||||||
SHM_EXEC = 15,
|
SHM_EXEC = 15,
|
||||||
// Message queue
|
|
||||||
MSG_NOERROR = 12,
|
MSG_NOERROR = 12,
|
||||||
MSG_EXCEPT = 13,
|
MSG_EXCEPT = 13,
|
||||||
MSG_COPY = 14,
|
MSG_COPY = 14,
|
||||||
|
|||||||
@@ -937,17 +937,12 @@ IO_Vec :: struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Access mode for shared memory
|
Access modes and flags used by SystemV IPC procedures.
|
||||||
*/
|
|
||||||
IPC_Mode :: bit_set[IPC_Mode_Bits; u32]
|
|
||||||
|
|
||||||
/*
|
|
||||||
Flags used by IPC objects
|
|
||||||
*/
|
*/
|
||||||
IPC_Flags :: bit_set[IPC_Flags_Bits; i16]
|
IPC_Flags :: bit_set[IPC_Flags_Bits; i16]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Permissions for IPC objects
|
Permissions for SystemV IPC primitives.
|
||||||
*/
|
*/
|
||||||
IPC_Perm :: struct {
|
IPC_Perm :: struct {
|
||||||
key: Key,
|
key: Key,
|
||||||
@@ -955,7 +950,7 @@ IPC_Perm :: struct {
|
|||||||
gid: u32,
|
gid: u32,
|
||||||
cuid: u32,
|
cuid: u32,
|
||||||
cgid: u32,
|
cgid: u32,
|
||||||
mode: IPC_Mode,
|
mode: IPC_Flags, // Only contains mode flags.
|
||||||
seq: u16,
|
seq: u16,
|
||||||
_: [2 + 2*size_of(int)]u8,
|
_: [2 + 2*size_of(int)]u8,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user