ipccall.inc 2.9 KB

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