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