ipccall.inc 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. Const
  23. CALL_SEMOP = 1;
  24. CALL_SEMGET = 2;
  25. CALL_SEMCTL = 3;
  26. CALL_MSGSND = 11;
  27. CALL_MSGRCV = 12;
  28. CALL_MSGGET = 13;
  29. CALL_MSGCTL = 14;
  30. CALL_SHMAT = 21;
  31. CALL_SHMDT = 22;
  32. CALL_SHMGET = 23;
  33. CALL_SHMCTL = 24;
  34. { generic call that handles all IPC calls }
  35. function ipccall(Call,First,Second,Third : cint; P : Pointer) : ptrint;
  36. begin
  37. ipccall:=do_syscall(syscall_nr_ipc,call,first,second,third,ptrint(P));
  38. // ipcerror:=fpgetErrno;
  39. end;
  40. function shmget(key: Tkey; size:size_t; flag:cint):cint;
  41. begin
  42. shmget:=ipccall (CALL_SHMGET,key,size,flag,nil);
  43. end;
  44. Function shmat (shmid:cint; shmaddr:pointer; shmflg:cint):pointer;
  45. Var raddr : pchar;
  46. error : ptrint;
  47. begin
  48. error:=ipccall(CALL_SHMAT,shmid,shmflg,cint(@raddr),shmaddr);
  49. If Error<0 then
  50. shmat:=pchar(error)
  51. else
  52. shmat:=raddr;
  53. end;
  54. function shmdt (shmaddr:pointer): cint;
  55. begin
  56. shmdt:=ipccall(CALL_SHMDT,0,0,0,shmaddr);
  57. end;
  58. function shmctl(shmid:cint; cmd:cint; buf: pshmid_ds): cint;
  59. begin
  60. shmctl:=ipccall(CALL_SHMCTL,shmid,cmd,0,buf);
  61. end;
  62. function msgget(key:Tkey; msgflg:cint):cint;
  63. begin
  64. msgget:=ipccall(CALL_MSGGET,key,msgflg,0,Nil);
  65. end;
  66. function msgsnd(msqid:cint; msgp: PMSGBuf; msgsz: size_t; msgflg:cint):cint;
  67. begin
  68. msgsnd:=ipccall(Call_MSGSND,msqid,msgsz,msgflg,msgp);
  69. end;
  70. function msgrcv(msqid:cint; msgp: PMSGBuf; msgsz: size_t; msgtyp:cint; msgflg:cint):cint;
  71. Type
  72. TIPC_Kludge = Record
  73. msgp : pmsgbuf;
  74. msgtyp : cint;
  75. end;
  76. Var
  77. tmp : TIPC_Kludge;
  78. begin
  79. tmp.msgp := msgp;
  80. tmp.msgtyp := msgtyp;
  81. msgrcv:=ipccall(CALL_MSGRCV,msqid,msgsz,msgflg,@tmp);
  82. end;
  83. Function msgctl(msqid:cint; cmd: cint; buf: PMSQid_ds): cint;
  84. begin
  85. msgctl:=ipccall(CALL_MSGCTL,msqid,cmd,0,buf);
  86. end;
  87. Function semget(key:Tkey; nsems:cint; semflg:cint): cint;
  88. begin
  89. semget:=ipccall (CALL_SEMGET,key,nsems,semflg,Nil);
  90. end;
  91. Function semop(semid:cint; sops: psembuf; nsops:cuint): cint;
  92. begin
  93. semop:=ipccall (CALL_SEMOP,semid,cint(nsops),0,Pointer(sops));
  94. end;
  95. Function semctl(semid:cint; semnum:cint; cmd:cint; var arg: tsemun): cint;
  96. begin
  97. semctl:=ipccall(CALL_SEMCTL,semid,semnum,cmd,@arg);
  98. end;