@@ -800,6 +800,116 @@ pub fn munmap(address: [*]const u8, length: usize) usize {
800
800
return syscall2 (.munmap , @intFromPtr (address ), length );
801
801
}
802
802
803
+ pub const key_t = i32 ;
804
+ pub const IPC = struct {
805
+ pub const PRIVATE = 0 ;
806
+
807
+ /// create key if key does not exist
808
+ pub const CREAT = 0x200 ;
809
+
810
+ /// fail if key exists
811
+ pub const EXCL = 0x400 ;
812
+
813
+ /// return error on wait
814
+ pub const NOWAIT = 0x800 ;
815
+
816
+ /// remove identifier
817
+ pub const RMID = 0 ;
818
+
819
+ /// set 'ipc_perm' options
820
+ pub const SET = 1 ;
821
+
822
+ /// get 'ipc_perm' options
823
+ pub const STAT = 2 ;
824
+
825
+ /// get info about shared memory limits and parameters
826
+ pub const INFO = 3 ;
827
+ };
828
+
829
+ pub const SHM = struct {
830
+ /// segment will be destroyed on last detach
831
+ pub const DEST = 0x200 ;
832
+
833
+ /// segment will not be swapped
834
+ pub const LOCKED = 0x400 ;
835
+
836
+ /// segment will use huge TLB pages
837
+ pub const HUGETLB = 0x800 ;
838
+
839
+ pub const HUGE_SHIFT = 26 ;
840
+ pub const HUGE_2MB = 21 << HUGE_SHIFT ;
841
+ pub const HUGE_1GB = 30 << HUGE_SHIFT ;
842
+
843
+ /// don't check for reservations
844
+ pub const NORESERVE = 0x1000 ;
845
+
846
+ /// attach read-only else read-write
847
+ pub const RDONLY = 0x1000 ;
848
+
849
+ /// round attach address to SHMLBA
850
+ pub const RND = 0x2000 ;
851
+
852
+ /// take-over region on attach
853
+ pub const REMAP = 0x4000 ;
854
+
855
+ /// execution access
856
+ pub const EXEC = 0x8000 ;
857
+
858
+ /// lock segment
859
+ pub const LOCK = 11 ;
860
+
861
+ /// unlock segment
862
+ pub const UNLOCK = 12 ;
863
+
864
+ /// get 'ipc_perm' options from kernel index
865
+ pub const STAT = 13 ;
866
+
867
+ /// get info about about system resources consumed by shared memory
868
+ pub const INFO = 14 ;
869
+
870
+ /// get 'ipc_perm' options from kernel index without checking read access
871
+ pub const STAT_ANY = 15 ;
872
+ };
873
+
874
+ pub const ipc_perm = extern struct {
875
+ key : c_int ,
876
+ uid : uid_t ,
877
+ gid : gid_t ,
878
+ cuid : uid_t ,
879
+ cgid : gid_t ,
880
+ mode : mode_t ,
881
+ seq : c_ushort ,
882
+ };
883
+
884
+ pub const shmid_ds = extern struct {
885
+ shm_perm : ipc_perm ,
886
+ shm_segsz : usize ,
887
+ shm_atime : time_t ,
888
+ shm_dtime : time_t ,
889
+ shm_ctime : time_t ,
890
+ shm_cpid : pid_t ,
891
+ shm_lpid : pid_t ,
892
+ shm_nattch : c_ulong ,
893
+ __pad1 : c_ulong ,
894
+ __pad2 : c_ulong ,
895
+ };
896
+
897
+ pub fn shmget (key : key_t , size : usize , shmflg : u32 ) usize {
898
+ return syscall3 (.shmget , @intCast (key ), size , shmflg );
899
+ }
900
+
901
+ pub fn shmat (shmid : u32 , shmaddr : ? [* ]align (std.mem.page_size ) u8 , shmflg : u32 ) usize {
902
+ return syscall3 (.shmat , shmid , @intFromPtr (shmaddr ), shmflg );
903
+ }
904
+
905
+ pub fn shmctl (shmid : u32 , cmd : i32 , ds : ? * shmid_ds ) usize {
906
+ return syscall3 (.shmctl , shmid , @intCast (cmd ), @intFromPtr (ds ));
907
+ }
908
+
909
+ pub fn shmdt (shmaddr : * const anyopaque ) usize {
910
+ return syscall1 (.shmdt , @intFromPtr (shmaddr ));
911
+ }
912
+
803
913
pub fn poll (fds : [* ]pollfd , n : nfds_t , timeout : i32 ) usize {
804
914
if (@hasField (SYS , "poll" )) {
805
915
return syscall3 (.poll , @intFromPtr (fds ), n , @as (u32 , @bitCast (timeout )));
0 commit comments