ipccall.inc 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2001 by Free Pascal development team
  4. Linux IPC implemented with ipccall
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. ***********************************************************************}
  11. { The following definitions come from linux/ipc.h }
  12. Function ftok (Path : pchar; ID : cint) : TKey;
  13. Var Info : TStat;
  14. begin
  15. If fpstat(path,info)<0 then
  16. ftok:=-1
  17. else
  18. begin
  19. ftok:= (info.st_ino and $FFFF) or ((info.st_dev and $ff) shl 16) or (byte(ID) shl 24)
  20. end;
  21. end;
  22. {$ifdef linux_ipc32}
  23. const
  24. ipc_api_select = 0; // 16-bit gid/pid types and old structs
  25. {$else}
  26. const
  27. ipc_api_select = $100; // 32-bit gid/pid types and newer structs
  28. {$endif}
  29. Const
  30. CALL_SEMOP = 1 +ipc_api_select;
  31. CALL_SEMGET = 2 +ipc_api_select;
  32. CALL_SEMCTL = 3 +ipc_api_select;
  33. CALL_SEMTIMEDOP = 4 +ipc_api_select;
  34. CALL_MSGSND = 11+ipc_api_select;
  35. CALL_MSGRCV = 12+ipc_api_select;
  36. CALL_MSGGET = 13+ipc_api_select;
  37. CALL_MSGCTL = 14+ipc_api_select;
  38. CALL_SHMAT = 21+ipc_api_select;
  39. CALL_SHMDT = 22+ipc_api_select;
  40. CALL_SHMGET = 23+ipc_api_select;
  41. CALL_SHMCTL = 24+ipc_api_select;
  42. { generic call that handles all IPC calls }
  43. function ipccall(Call: cuint; First: cint; Second,Third : culong; P: pointer; Fifth: clong) : ptrint;
  44. begin
  45. ipccall:=do_syscall(syscall_nr_ipc,TSysParam(call),TSysParam(first),TSysParam(second),TSysParam(third),TSysParam(P),TSysParam(Fifth));
  46. end;
  47. function shmget(key: Tkey; size:size_t; flag:cint):cint;
  48. begin
  49. shmget:=ipccall (CALL_SHMGET,key,size,flag,nil,0);
  50. end;
  51. Function shmat (shmid:cint; shmaddr:pointer; shmflg:cint):pointer;
  52. Var raddr : pchar;
  53. error : ptrint;
  54. begin
  55. error:=ipccall(CALL_SHMAT,shmid,shmflg,cint(@raddr),shmaddr,0);
  56. If Error<0 then
  57. shmat:=pchar(error)
  58. else
  59. shmat:=raddr;
  60. end;
  61. function shmdt (shmaddr:pointer): cint;
  62. begin
  63. shmdt:=ipccall(CALL_SHMDT,0,0,0,shmaddr,0);
  64. end;
  65. function shmctl(shmid:cint; cmd:cint; buf: pshmid_ds): cint;
  66. begin
  67. shmctl:=ipccall(CALL_SHMCTL,shmid,cmd,0,buf,0);
  68. end;
  69. function msgget(key:Tkey; msgflg:cint):cint;
  70. begin
  71. msgget:=ipccall(CALL_MSGGET,key,msgflg,0,Nil,0);
  72. end;
  73. function msgsnd(msqid:cint; msgp: PMSGBuf; msgsz: size_t; msgflg:cint):cint;
  74. begin
  75. msgsnd:=ipccall(Call_MSGSND,msqid,msgsz,msgflg,msgp,0);
  76. end;
  77. function msgrcv(msqid:cint; msgp: PMSGBuf; msgsz: size_t; msgtyp:clong; msgflg:cint):cint;
  78. Type
  79. TIPC_Kludge = Record
  80. msgp : pmsgbuf;
  81. msgtyp : clong;
  82. end;
  83. Var
  84. tmp : TIPC_Kludge;
  85. begin
  86. tmp.msgp := msgp;
  87. tmp.msgtyp := msgtyp;
  88. msgrcv:=ipccall(CALL_MSGRCV,msqid,msgsz,msgflg,@tmp,0);
  89. end;
  90. Function msgctl(msqid:cint; cmd: cint; buf: PMSQid_ds): cint;
  91. begin
  92. msgctl:=ipccall(CALL_MSGCTL,msqid,cmd,0,buf,0);
  93. end;
  94. Function semget(key:Tkey; nsems:cint; semflg:cint): cint;
  95. begin
  96. semget:=ipccall (CALL_SEMGET,key,nsems,semflg,Nil,0);
  97. end;
  98. Function semop(semid:cint; sops: psembuf; nsops:cuint): cint;
  99. begin
  100. semop:=ipccall (CALL_SEMOP,semid,cint(nsops),0,Pointer(sops),0);
  101. end;
  102. Function semctl(semid:cint; semnum:cint; cmd:cint; var arg: tsemun): cint;
  103. begin
  104. semctl:=ipccall(CALL_SEMCTL,semid,semnum,cmd,@arg,0);
  105. end;
  106. Function semtimedop(semid:cint; sops: psembuf; nsops: cuint; timeOut: ptimespec): cint;
  107. begin
  108. semtimedop:=ipccall(CALL_SEMTIMEDOP,semid,culong(nsops),culong(0),Pointer(sops),clong(timeOut));
  109. end;