| 1 |
|
| /******************************************************************************* |
| 2 |
|
| * |
| 3 |
|
| * Version 2.x, Copyright (C) 2007-2013, Marcus Holland-Moritz <mhx@cpan.org>. |
| 4 |
|
| * Version 1.x, Copyright (C) 1999, Graham Barr <gbarr@pobox.com>. |
| 5 |
|
| * |
| 6 |
|
| * This program is free software; you can redistribute it and/or |
| 7 |
|
| * modify it under the same terms as Perl itself. |
| 8 |
|
| * |
| 9 |
|
| *******************************************************************************/ |
| 10 |
|
| |
| 11 |
|
| #include "EXTERN.h" |
| 12 |
|
| #include "perl.h" |
| 13 |
|
| #include "XSUB.h" |
| 14 |
|
| |
| 15 |
|
| #ifndef NO_PPPORT_H |
| 16 |
|
| # define NEED_sv_2pv_flags |
| 17 |
|
| # define NEED_sv_pvn_force_flags |
| 18 |
|
| # include "ppport.h" |
| 19 |
|
| #endif |
| 20 |
|
| |
| 21 |
|
| #include <sys/types.h> |
| 22 |
|
| |
| 23 |
|
| #if defined(HAS_MSG) || defined(HAS_SEM) || defined(HAS_SHM) |
| 24 |
|
| # ifndef HAS_SEM |
| 25 |
|
| # include <sys/ipc.h> |
| 26 |
|
| # endif |
| 27 |
|
| # ifdef HAS_MSG |
| 28 |
|
| # include <sys/msg.h> |
| 29 |
|
| # endif |
| 30 |
|
| # ifdef HAS_SHM |
| 31 |
|
| # if defined(PERL_SCO) || defined(PERL_ISC) |
| 32 |
|
| # include <sys/sysmacros.h> /* SHMLBA */ |
| 33 |
|
| # endif |
| 34 |
|
| # include <sys/shm.h> |
| 35 |
|
| # ifndef HAS_SHMAT_PROTOTYPE |
| 36 |
|
| extern Shmat_t shmat(int, char *, int); |
| 37 |
|
| # endif |
| 38 |
|
| # if defined(HAS_SYSCONF) && defined(_SC_PAGESIZE) |
| 39 |
|
| # undef SHMLBA /* not static: determined at boot time */ |
| 40 |
|
| # define SHMLBA sysconf(_SC_PAGESIZE) |
| 41 |
|
| # elif defined(HAS_GETPAGESIZE) |
| 42 |
|
| # undef SHMLBA /* not static: determined at boot time */ |
| 43 |
|
| # define SHMLBA getpagesize() |
| 44 |
|
| # endif |
| 45 |
|
| # endif |
| 46 |
|
| #endif |
| 47 |
|
| |
| 48 |
|
| /* Required to get 'struct pte' for SHMLBA on ULTRIX. */ |
| 49 |
|
| #if defined(__ultrix) || defined(__ultrix__) || defined(ultrix) |
| 50 |
|
| #include <machine/pte.h> |
| 51 |
|
| #endif |
| 52 |
|
| |
| 53 |
|
| /* Required in BSDI to get PAGE_SIZE definition for SHMLBA. |
| 54 |
|
| * Ugly. More beautiful solutions welcome. |
| 55 |
|
| * Shouting at BSDI sounds quite beautiful. */ |
| 56 |
|
| #ifdef __bsdi__ |
| 57 |
|
| # include <vm/vm_param.h> /* move upwards under HAS_SHM? */ |
| 58 |
|
| #endif |
| 59 |
|
| |
| 60 |
|
| #ifndef S_IRWXU |
| 61 |
|
| # ifdef S_IRUSR |
| 62 |
|
| # define S_IRWXU (S_IRUSR|S_IWUSR|S_IXUSR) |
| 63 |
|
| # define S_IRWXG (S_IRGRP|S_IWGRP|S_IXGRP) |
| 64 |
|
| # define S_IRWXO (S_IROTH|S_IWOTH|S_IXOTH) |
| 65 |
|
| # else |
| 66 |
|
| # define S_IRWXU 0700 |
| 67 |
|
| # define S_IRWXG 0070 |
| 68 |
|
| # define S_IRWXO 0007 |
| 69 |
|
| # endif |
| 70 |
|
| #endif |
| 71 |
|
| |
| 72 |
|
| #define AV_FETCH_IV(ident, av, index) \ |
| 73 |
|
| STMT_START { \ |
| 74 |
|
| SV **svp; \ |
| 75 |
|
| if ((svp = av_fetch((av), (index), FALSE)) != NULL) \ |
| 76 |
|
| ident = SvIV(*svp); \ |
| 77 |
|
| } STMT_END |
| 78 |
|
| |
| 79 |
|
| #define AV_STORE_IV(ident, av, index) \ |
| 80 |
|
| av_store((av), (index), newSViv(ident)) |
| 81 |
|
| |
| 82 |
|
| static const char *s_fmt_not_isa = "Method %s not called a %s object"; |
| 83 |
|
| static const char *s_bad_length = "Bad arg length for %s, length is %d, should be %d"; |
| 84 |
|
| static const char *s_sysv_unimpl PERL_UNUSED_DECL |
| 85 |
|
| = "System V %sxxx is not implemented on this machine"; |
| 86 |
|
| |
| 87 |
|
| static const char *s_pkg_msg = "IPC::Msg::stat"; |
| 88 |
|
| static const char *s_pkg_sem = "IPC::Semaphore::stat"; |
| 89 |
|
| static const char *s_pkg_shm = "IPC::SharedMem::stat"; |
| 90 |
|
| |
| 91 |
9 |
| static void *sv2addr(SV *sv) |
| 92 |
|
| { |
| 93 |
9 |
▶ | if (SvPOK(sv) && SvCUR(sv) == sizeof(void *)) |
Branch: 2 branches
| Branch | True | False | Total |
| if (SvPOK(sv) && SvCUR(sv) == sizeof(void *)) |
9 |
0 |
9 |
| if (SvPOK(sv) && SvCUR(sv) == sizeof(void *)) |
9 |
0 |
9 |
|
| 94 |
|
| { |
| 95 |
9 |
| return *((void **) SvPVX(sv)); |
| 96 |
|
| } |
| 97 |
|
| |
| 98 |
0 |
| croak("invalid address value"); |
| 99 |
|
| |
| 100 |
|
| return 0; |
| 101 |
|
| } |
| 102 |
|
| |
| 103 |
5 |
| static void assert_sv_isa(SV *sv, const char *name, const char *method) |
| 104 |
|
| { |
| 105 |
5 |
▶ | if (!sv_isa(sv, name)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!sv_isa(sv, name)) |
0 |
5 |
5 |
|
| 106 |
|
| { |
| 107 |
0 |
| croak(s_fmt_not_isa, method, name); |
| 108 |
|
| } |
| 109 |
5 |
| } |
| 110 |
|
| |
| 111 |
5 |
| static void assert_data_length(const char *name, int got, int expected) |
| 112 |
|
| { |
| 113 |
5 |
▶ | if (got != expected) |
Branch: 1 branch
| Branch | True | False | Total |
| if (got != expected) |
0 |
5 |
5 |
|
| 114 |
|
| { |
| 115 |
0 |
| croak(s_bad_length, name, got, expected); |
| 116 |
|
| } |
| 117 |
5 |
| } |
| 118 |
|
| |
| 119 |
|
| #include "const-c.inc" |
| 120 |
|
| |
| 121 |
|
| |
| 122 |
|
| MODULE=IPC::SysV PACKAGE=IPC::Msg::stat |
| 123 |
|
| |
| 124 |
|
| PROTOTYPES: ENABLE |
| 125 |
|
| |
| 126 |
|
| void |
| 127 |
|
| pack(obj) |
| 128 |
|
| SV * obj |
| 129 |
|
| PPCODE: |
| 130 |
|
| { |
| 131 |
|
| #ifdef HAS_MSG |
| 132 |
0 |
| AV *list = (AV*) SvRV(obj); |
| 133 |
|
| struct msqid_ds ds; |
| 134 |
0 |
| assert_sv_isa(obj, s_pkg_msg, "pack"); |
| 135 |
0 |
▶ | AV_FETCH_IV(ds.msg_perm.uid , list, 0); |
Branch: 1 branch
| Branch | True | False | Total |
| AV_FETCH_IV(ds.msg_perm.uid , list, 0); |
0 |
0 |
0 |
|
| 136 |
0 |
▶ | AV_FETCH_IV(ds.msg_perm.gid , list, 1); |
Branch: 1 branch
| Branch | True | False | Total |
| AV_FETCH_IV(ds.msg_perm.gid , list, 1); |
0 |
0 |
0 |
|
| 137 |
0 |
▶ | AV_FETCH_IV(ds.msg_perm.cuid, list, 2); |
Branch: 1 branch
| Branch | True | False | Total |
| AV_FETCH_IV(ds.msg_perm.cuid, list, 2); |
0 |
0 |
0 |
|
| 138 |
0 |
▶ | AV_FETCH_IV(ds.msg_perm.cgid, list, 3); |
Branch: 1 branch
| Branch | True | False | Total |
| AV_FETCH_IV(ds.msg_perm.cgid, list, 3); |
0 |
0 |
0 |
|
| 139 |
0 |
▶ | AV_FETCH_IV(ds.msg_perm.mode, list, 4); |
Branch: 1 branch
| Branch | True | False | Total |
| AV_FETCH_IV(ds.msg_perm.mode, list, 4); |
0 |
0 |
0 |
|
| 140 |
0 |
▶ | AV_FETCH_IV(ds.msg_qnum , list, 5); |
Branch: 1 branch
| Branch | True | False | Total |
| AV_FETCH_IV(ds.msg_qnum , list, 5); |
0 |
0 |
0 |
|
| 141 |
0 |
▶ | AV_FETCH_IV(ds.msg_qbytes , list, 6); |
Branch: 1 branch
| Branch | True | False | Total |
| AV_FETCH_IV(ds.msg_qbytes , list, 6); |
0 |
0 |
0 |
|
| 142 |
0 |
▶ | AV_FETCH_IV(ds.msg_lspid , list, 7); |
Branch: 1 branch
| Branch | True | False | Total |
| AV_FETCH_IV(ds.msg_lspid , list, 7); |
0 |
0 |
0 |
|
| 143 |
0 |
▶ | AV_FETCH_IV(ds.msg_lrpid , list, 8); |
Branch: 1 branch
| Branch | True | False | Total |
| AV_FETCH_IV(ds.msg_lrpid , list, 8); |
0 |
0 |
0 |
|
| 144 |
0 |
▶ | AV_FETCH_IV(ds.msg_stime , list, 9); |
Branch: 1 branch
| Branch | True | False | Total |
| AV_FETCH_IV(ds.msg_stime , list, 9); |
0 |
0 |
0 |
|
| 145 |
0 |
▶ | AV_FETCH_IV(ds.msg_rtime , list, 10); |
Branch: 1 branch
| Branch | True | False | Total |
| AV_FETCH_IV(ds.msg_rtime , list, 10); |
0 |
0 |
0 |
|
| 146 |
0 |
▶ | AV_FETCH_IV(ds.msg_ctime , list, 11); |
Branch: 1 branch
| Branch | True | False | Total |
| AV_FETCH_IV(ds.msg_ctime , list, 11); |
0 |
0 |
0 |
|
| 147 |
0 |
| ST(0) = sv_2mortal(newSVpvn((char *) &ds, sizeof(ds))); |
| 148 |
0 |
| XSRETURN(1); |
| 149 |
|
| #else |
| 150 |
|
| croak(s_sysv_unimpl, "msg"); |
| 151 |
|
| #endif |
| 152 |
|
| } |
| 153 |
|
| |
| 154 |
|
| void |
| 155 |
|
| unpack(obj, ds) |
| 156 |
|
| SV * obj |
| 157 |
|
| SV * ds |
| 158 |
|
| PPCODE: |
| 159 |
|
| { |
| 160 |
|
| #ifdef HAS_MSG |
| 161 |
2 |
| AV *list = (AV*) SvRV(obj); |
| 162 |
|
| STRLEN len; |
| 163 |
2 |
| const struct msqid_ds *data = (struct msqid_ds *) SvPV_const(ds, len); |
| 164 |
2 |
| assert_sv_isa(obj, s_pkg_msg, "unpack"); |
| 165 |
2 |
| assert_data_length(s_pkg_msg, len, sizeof(*data)); |
| 166 |
2 |
| AV_STORE_IV(data->msg_perm.uid , list, 0); |
| 167 |
2 |
| AV_STORE_IV(data->msg_perm.gid , list, 1); |
| 168 |
2 |
| AV_STORE_IV(data->msg_perm.cuid, list, 2); |
| 169 |
2 |
| AV_STORE_IV(data->msg_perm.cgid, list, 3); |
| 170 |
2 |
| AV_STORE_IV(data->msg_perm.mode, list, 4); |
| 171 |
2 |
| AV_STORE_IV(data->msg_qnum , list, 5); |
| 172 |
2 |
| AV_STORE_IV(data->msg_qbytes , list, 6); |
| 173 |
2 |
| AV_STORE_IV(data->msg_lspid , list, 7); |
| 174 |
2 |
| AV_STORE_IV(data->msg_lrpid , list, 8); |
| 175 |
2 |
| AV_STORE_IV(data->msg_stime , list, 9); |
| 176 |
2 |
| AV_STORE_IV(data->msg_rtime , list, 10); |
| 177 |
2 |
| AV_STORE_IV(data->msg_ctime , list, 11); |
| 178 |
2 |
| XSRETURN(1); |
| 179 |
|
| #else |
| 180 |
|
| croak(s_sysv_unimpl, "msg"); |
| 181 |
|
| #endif |
| 182 |
|
| } |
| 183 |
|
| |
| 184 |
|
| |
| 185 |
|
| MODULE=IPC::SysV PACKAGE=IPC::Semaphore::stat |
| 186 |
|
| |
| 187 |
|
| PROTOTYPES: ENABLE |
| 188 |
|
| |
| 189 |
|
| void |
| 190 |
|
| pack(obj) |
| 191 |
|
| SV * obj |
| 192 |
|
| PPCODE: |
| 193 |
|
| { |
| 194 |
|
| #ifdef HAS_SEM |
| 195 |
0 |
| AV *list = (AV*) SvRV(obj); |
| 196 |
|
| struct semid_ds ds; |
| 197 |
0 |
| assert_sv_isa(obj, s_pkg_sem, "pack"); |
| 198 |
0 |
▶ | AV_FETCH_IV(ds.sem_perm.uid , list, 0); |
Branch: 1 branch
| Branch | True | False | Total |
| AV_FETCH_IV(ds.sem_perm.uid , list, 0); |
0 |
0 |
0 |
|
| 199 |
0 |
▶ | AV_FETCH_IV(ds.sem_perm.gid , list, 1); |
Branch: 1 branch
| Branch | True | False | Total |
| AV_FETCH_IV(ds.sem_perm.gid , list, 1); |
0 |
0 |
0 |
|
| 200 |
0 |
▶ | AV_FETCH_IV(ds.sem_perm.cuid, list, 2); |
Branch: 1 branch
| Branch | True | False | Total |
| AV_FETCH_IV(ds.sem_perm.cuid, list, 2); |
0 |
0 |
0 |
|
| 201 |
0 |
▶ | AV_FETCH_IV(ds.sem_perm.cgid, list, 3); |
Branch: 1 branch
| Branch | True | False | Total |
| AV_FETCH_IV(ds.sem_perm.cgid, list, 3); |
0 |
0 |
0 |
|
| 202 |
0 |
▶ | AV_FETCH_IV(ds.sem_perm.mode, list, 4); |
Branch: 1 branch
| Branch | True | False | Total |
| AV_FETCH_IV(ds.sem_perm.mode, list, 4); |
0 |
0 |
0 |
|
| 203 |
0 |
▶ | AV_FETCH_IV(ds.sem_ctime , list, 5); |
Branch: 1 branch
| Branch | True | False | Total |
| AV_FETCH_IV(ds.sem_ctime , list, 5); |
0 |
0 |
0 |
|
| 204 |
0 |
▶ | AV_FETCH_IV(ds.sem_otime , list, 6); |
Branch: 1 branch
| Branch | True | False | Total |
| AV_FETCH_IV(ds.sem_otime , list, 6); |
0 |
0 |
0 |
|
| 205 |
0 |
▶ | AV_FETCH_IV(ds.sem_nsems , list, 7); |
Branch: 1 branch
| Branch | True | False | Total |
| AV_FETCH_IV(ds.sem_nsems , list, 7); |
0 |
0 |
0 |
|
| 206 |
0 |
| ST(0) = sv_2mortal(newSVpvn((char *) &ds, sizeof(ds))); |
| 207 |
0 |
| XSRETURN(1); |
| 208 |
|
| #else |
| 209 |
|
| croak(s_sysv_unimpl, "sem"); |
| 210 |
|
| #endif |
| 211 |
|
| } |
| 212 |
|
| |
| 213 |
|
| void |
| 214 |
|
| unpack(obj, ds) |
| 215 |
|
| SV * obj |
| 216 |
|
| SV * ds |
| 217 |
|
| PPCODE: |
| 218 |
|
| { |
| 219 |
|
| #ifdef HAS_SEM |
| 220 |
1 |
| AV *list = (AV*) SvRV(obj); |
| 221 |
|
| STRLEN len; |
| 222 |
1 |
| const struct semid_ds *data = (struct semid_ds *) SvPV_const(ds, len); |
| 223 |
1 |
| assert_sv_isa(obj, s_pkg_sem, "unpack"); |
| 224 |
1 |
| assert_data_length(s_pkg_sem, len, sizeof(*data)); |
| 225 |
1 |
| AV_STORE_IV(data->sem_perm.uid , list, 0); |
| 226 |
1 |
| AV_STORE_IV(data->sem_perm.gid , list, 1); |
| 227 |
1 |
| AV_STORE_IV(data->sem_perm.cuid, list, 2); |
| 228 |
1 |
| AV_STORE_IV(data->sem_perm.cgid, list, 3); |
| 229 |
1 |
| AV_STORE_IV(data->sem_perm.mode, list, 4); |
| 230 |
1 |
| AV_STORE_IV(data->sem_ctime , list, 5); |
| 231 |
1 |
| AV_STORE_IV(data->sem_otime , list, 6); |
| 232 |
1 |
| AV_STORE_IV(data->sem_nsems , list, 7); |
| 233 |
1 |
| XSRETURN(1); |
| 234 |
|
| #else |
| 235 |
|
| croak(s_sysv_unimpl, "sem"); |
| 236 |
|
| #endif |
| 237 |
|
| } |
| 238 |
|
| |
| 239 |
|
| |
| 240 |
|
| MODULE=IPC::SysV PACKAGE=IPC::SharedMem::stat |
| 241 |
|
| |
| 242 |
|
| PROTOTYPES: ENABLE |
| 243 |
|
| |
| 244 |
|
| void |
| 245 |
|
| pack(obj) |
| 246 |
|
| SV * obj |
| 247 |
|
| PPCODE: |
| 248 |
|
| { |
| 249 |
|
| #ifdef HAS_SHM |
| 250 |
0 |
| AV *list = (AV*) SvRV(obj); |
| 251 |
|
| struct shmid_ds ds; |
| 252 |
0 |
| assert_sv_isa(obj, s_pkg_shm, "pack"); |
| 253 |
0 |
▶ | AV_FETCH_IV(ds.shm_perm.uid , list, 0); |
Branch: 1 branch
| Branch | True | False | Total |
| AV_FETCH_IV(ds.shm_perm.uid , list, 0); |
0 |
0 |
0 |
|
| 254 |
0 |
▶ | AV_FETCH_IV(ds.shm_perm.gid , list, 1); |
Branch: 1 branch
| Branch | True | False | Total |
| AV_FETCH_IV(ds.shm_perm.gid , list, 1); |
0 |
0 |
0 |
|
| 255 |
0 |
▶ | AV_FETCH_IV(ds.shm_perm.cuid, list, 2); |
Branch: 1 branch
| Branch | True | False | Total |
| AV_FETCH_IV(ds.shm_perm.cuid, list, 2); |
0 |
0 |
0 |
|
| 256 |
0 |
▶ | AV_FETCH_IV(ds.shm_perm.cgid, list, 3); |
Branch: 1 branch
| Branch | True | False | Total |
| AV_FETCH_IV(ds.shm_perm.cgid, list, 3); |
0 |
0 |
0 |
|
| 257 |
0 |
▶ | AV_FETCH_IV(ds.shm_perm.mode, list, 4); |
Branch: 1 branch
| Branch | True | False | Total |
| AV_FETCH_IV(ds.shm_perm.mode, list, 4); |
0 |
0 |
0 |
|
| 258 |
0 |
▶ | AV_FETCH_IV(ds.shm_segsz , list, 5); |
Branch: 1 branch
| Branch | True | False | Total |
| AV_FETCH_IV(ds.shm_segsz , list, 5); |
0 |
0 |
0 |
|
| 259 |
0 |
▶ | AV_FETCH_IV(ds.shm_lpid , list, 6); |
Branch: 1 branch
| Branch | True | False | Total |
| AV_FETCH_IV(ds.shm_lpid , list, 6); |
0 |
0 |
0 |
|
| 260 |
0 |
▶ | AV_FETCH_IV(ds.shm_cpid , list, 7); |
Branch: 1 branch
| Branch | True | False | Total |
| AV_FETCH_IV(ds.shm_cpid , list, 7); |
0 |
0 |
0 |
|
| 261 |
0 |
▶ | AV_FETCH_IV(ds.shm_nattch , list, 8); |
Branch: 1 branch
| Branch | True | False | Total |
| AV_FETCH_IV(ds.shm_nattch , list, 8); |
0 |
0 |
0 |
|
| 262 |
0 |
▶ | AV_FETCH_IV(ds.shm_atime , list, 9); |
Branch: 1 branch
| Branch | True | False | Total |
| AV_FETCH_IV(ds.shm_atime , list, 9); |
0 |
0 |
0 |
|
| 263 |
0 |
▶ | AV_FETCH_IV(ds.shm_dtime , list, 10); |
Branch: 1 branch
| Branch | True | False | Total |
| AV_FETCH_IV(ds.shm_dtime , list, 10); |
0 |
0 |
0 |
|
| 264 |
0 |
▶ | AV_FETCH_IV(ds.shm_ctime , list, 11); |
Branch: 1 branch
| Branch | True | False | Total |
| AV_FETCH_IV(ds.shm_ctime , list, 11); |
0 |
0 |
0 |
|
| 265 |
0 |
| ST(0) = sv_2mortal(newSVpvn((char *) &ds, sizeof(ds))); |
| 266 |
0 |
| XSRETURN(1); |
| 267 |
|
| #else |
| 268 |
|
| croak(s_sysv_unimpl, "shm"); |
| 269 |
|
| #endif |
| 270 |
|
| } |
| 271 |
|
| |
| 272 |
|
| void |
| 273 |
|
| unpack(obj, ds) |
| 274 |
|
| SV * obj |
| 275 |
|
| SV * ds |
| 276 |
|
| PPCODE: |
| 277 |
|
| { |
| 278 |
|
| #ifdef HAS_SHM |
| 279 |
2 |
| AV *list = (AV*) SvRV(obj); |
| 280 |
|
| STRLEN len; |
| 281 |
2 |
| const struct shmid_ds *data = (struct shmid_ds *) SvPV_const(ds, len); |
| 282 |
2 |
| assert_sv_isa(obj, s_pkg_shm, "unpack"); |
| 283 |
2 |
| assert_data_length(s_pkg_shm, len, sizeof(*data)); |
| 284 |
2 |
| AV_STORE_IV(data->shm_perm.uid , list, 0); |
| 285 |
2 |
| AV_STORE_IV(data->shm_perm.gid , list, 1); |
| 286 |
2 |
| AV_STORE_IV(data->shm_perm.cuid, list, 2); |
| 287 |
2 |
| AV_STORE_IV(data->shm_perm.cgid, list, 3); |
| 288 |
2 |
| AV_STORE_IV(data->shm_perm.mode, list, 4); |
| 289 |
2 |
| AV_STORE_IV(data->shm_segsz , list, 5); |
| 290 |
2 |
| AV_STORE_IV(data->shm_lpid , list, 6); |
| 291 |
2 |
| AV_STORE_IV(data->shm_cpid , list, 7); |
| 292 |
2 |
| AV_STORE_IV(data->shm_nattch , list, 8); |
| 293 |
2 |
| AV_STORE_IV(data->shm_atime , list, 9); |
| 294 |
2 |
| AV_STORE_IV(data->shm_dtime , list, 10); |
| 295 |
2 |
| AV_STORE_IV(data->shm_ctime , list, 11); |
| 296 |
2 |
| XSRETURN(1); |
| 297 |
|
| #else |
| 298 |
|
| croak(s_sysv_unimpl, "shm"); |
| 299 |
|
| #endif |
| 300 |
|
| } |
| 301 |
|
| |
| 302 |
|
| |
| 303 |
|
| MODULE=IPC::SysV PACKAGE=IPC::SysV |
| 304 |
|
| |
| 305 |
|
| PROTOTYPES: ENABLE |
| 306 |
|
| |
| 307 |
|
| void |
| 308 |
|
| ftok(path, id = &PL_sv_undef) |
| 309 |
|
| const char *path |
| 310 |
|
| SV *id |
| 311 |
|
| PREINIT: |
| 312 |
10 |
▶ | int proj_id = 1; |
Branch: 1 branch
| Branch | True | False | Total |
| int proj_id = 1; |
1 |
9 |
10 |
|
| 313 |
|
| key_t k; |
| 314 |
|
| CODE: |
| 315 |
|
| #if defined(HAS_SEM) || defined(HAS_SHM) |
| 316 |
10 |
▶ | if (SvOK(id)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvOK(id)) |
9 |
1 |
10 |
|
| 317 |
|
| { |
| 318 |
9 |
▶ | if (SvIOK(id)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvIOK(id)) |
5 |
4 |
9 |
|
| 319 |
|
| { |
| 320 |
5 |
| proj_id = (int) SvIVX(id); |
| 321 |
|
| } |
| 322 |
4 |
▶ | else if (SvPOK(id) && SvCUR(id) == sizeof(char)) |
Branch: 2 branches
| Branch | True | False | Total |
| else if (SvPOK(id) && SvCUR(id) == sizeof(char)) |
3 |
1 |
4 |
| else if (SvPOK(id) && SvCUR(id) == sizeof(char)) |
2 |
1 |
3 |
|
| 323 |
|
| { |
| 324 |
2 |
| proj_id = (int) *SvPVX(id); |
| 325 |
|
| } |
| 326 |
|
| else |
| 327 |
|
| { |
| 328 |
2 |
| croak("invalid project id"); |
| 329 |
|
| } |
| 330 |
|
| } |
| 331 |
|
| /* Including <sys/types.h> before <sys/ipc.h> makes Tru64 |
| 332 |
|
| * to see the obsolete prototype of ftok() first, grumble. */ |
| 333 |
|
| # ifdef __osf__ |
| 334 |
|
| # define Ftok_t char* |
| 335 |
|
| /* Configure TODO Ftok_t */ |
| 336 |
|
| # endif |
| 337 |
|
| # ifndef Ftok_t |
| 338 |
|
| # define Ftok_t const char* |
| 339 |
|
| # endif |
| 340 |
8 |
| k = ftok((Ftok_t)path, proj_id); |
| 341 |
8 |
▶ | ST(0) = k == (key_t) -1 ? &PL_sv_undef : sv_2mortal(newSViv(k)); |
Branch: 1 branch
| Branch | True | False | Total |
| ST(0) = k == (key_t) -1 ? &PL_sv_undef : sv_2mortal(newSViv(k)); |
8 |
0 |
8 |
|
| 342 |
8 |
| XSRETURN(1); |
| 343 |
|
| #else |
| 344 |
|
| Perl_die(aTHX_ PL_no_func, "ftok"); return; |
| 345 |
|
| #endif |
| 346 |
|
| |
| 347 |
|
| void |
| 348 |
|
| memread(addr, sv, pos, size) |
| 349 |
|
| SV *addr |
| 350 |
|
| SV *sv |
| 351 |
|
| UV pos |
| 352 |
|
| UV size |
| 353 |
|
| CODE: |
| 354 |
4 |
| char *caddr = (char *) sv2addr(addr); |
| 355 |
|
| char *dst; |
| 356 |
4 |
▶ | if (!SvOK(sv)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!SvOK(sv)) |
0 |
4 |
4 |
|
| 357 |
|
| { |
| 358 |
0 |
| sv_setpvn(sv, "", 0); |
| 359 |
|
| } |
| 360 |
|
| SvPV_force_nolen(sv); |
| 361 |
4 |
▶ | dst = SvGROW(sv, (STRLEN) size + 1); |
Branch: 2 branches
| Branch | True | False | Total |
| dst = SvGROW(sv, (STRLEN) size + 1); |
4 |
0 |
4 |
| dst = SvGROW(sv, (STRLEN) size + 1); |
0 |
4 |
4 |
|
| 362 |
4 |
| Copy(caddr + pos, dst, size, char); |
| 363 |
4 |
| SvCUR_set(sv, size); |
| 364 |
4 |
| *SvEND(sv) = '\0'; |
| 365 |
4 |
▶ | SvSETMAGIC(sv); |
Branch: 1 branch
| Branch | True | False | Total |
| SvSETMAGIC(sv); |
0 |
4 |
4 |
|
| 366 |
|
| #ifndef INCOMPLETE_TAINTS |
| 367 |
|
| /* who knows who has been playing with this memory? */ |
| 368 |
4 |
▶ | SvTAINTED_on(sv); |
Branch: 1 branch
| Branch | True | False | Total |
| SvTAINTED_on(sv); |
0 |
4 |
4 |
|
| 369 |
|
| #endif |
| 370 |
4 |
| XSRETURN_YES; |
| 371 |
|
| |
| 372 |
|
| void |
| 373 |
|
| memwrite(addr, sv, pos, size) |
| 374 |
|
| SV *addr |
| 375 |
|
| SV *sv |
| 376 |
|
| UV pos |
| 377 |
|
| UV size |
| 378 |
|
| CODE: |
| 379 |
3 |
| char *caddr = (char *) sv2addr(addr); |
| 380 |
|
| STRLEN len; |
| 381 |
3 |
| const char *src = SvPV_const(sv, len); |
| 382 |
3 |
| unsigned int n = ((unsigned int) len > size) ? size : (unsigned int) len; |
| 383 |
3 |
| Copy(src, caddr + pos, n, char); |
| 384 |
3 |
▶ | if (n < size) |
Branch: 1 branch
| Branch | True | False | Total |
| if (n < size) |
0 |
3 |
3 |
|
| 385 |
|
| { |
| 386 |
0 |
| memzero(caddr + pos + n, size - n); |
| 387 |
|
| } |
| 388 |
3 |
| XSRETURN_YES; |
| 389 |
|
| |
| 390 |
|
| void |
| 391 |
|
| shmat(id, addr, flag) |
| 392 |
|
| int id |
| 393 |
|
| SV *addr |
| 394 |
|
| int flag |
| 395 |
|
| CODE: |
| 396 |
|
| #ifdef HAS_SHM |
| 397 |
3 |
▶ | if (id >= 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (id >= 0) { |
2 |
1 |
3 |
|
| 398 |
2 |
▶ | void *caddr = SvOK(addr) ? sv2addr(addr) : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| void *caddr = SvOK(addr) ? sv2addr(addr) : NULL; |
0 |
2 |
2 |
|
| 399 |
2 |
| void *shm = (void *) shmat(id, caddr, flag); |
| 400 |
2 |
| ST(0) = shm == (void *) -1 ? &PL_sv_undef |
| 401 |
2 |
▶ | : sv_2mortal(newSVpvn((char *) &shm, sizeof(void *))); |
Branch: 1 branch
| Branch | True | False | Total |
| : sv_2mortal(newSVpvn((char *) &shm, sizeof(void *))); |
2 |
0 |
2 |
|
| 402 |
|
| } else { |
| 403 |
1 |
| SETERRNO(EINVAL,LIB_INVARG); |
| 404 |
1 |
| ST(0) = &PL_sv_undef; |
| 405 |
|
| } |
| 406 |
3 |
| XSRETURN(1); |
| 407 |
|
| #else |
| 408 |
|
| Perl_die(aTHX_ PL_no_func, "shmat"); return; |
| 409 |
|
| #endif |
| 410 |
|
| |
| 411 |
|
| void |
| 412 |
|
| shmdt(addr) |
| 413 |
|
| SV *addr |
| 414 |
|
| CODE: |
| 415 |
|
| #ifdef HAS_SHM |
| 416 |
2 |
| void *caddr = sv2addr(addr); |
| 417 |
2 |
| int rv = shmdt((Shmat_t)caddr); |
| 418 |
2 |
▶ | ST(0) = rv == -1 ? &PL_sv_undef : sv_2mortal(newSViv(rv)); |
Branch: 1 branch
| Branch | True | False | Total |
| ST(0) = rv == -1 ? &PL_sv_undef : sv_2mortal(newSViv(rv)); |
2 |
0 |
2 |
|
| 419 |
2 |
| XSRETURN(1); |
| 420 |
|
| #else |
| 421 |
|
| Perl_die(aTHX_ PL_no_func, "shmdt"); return; |
| 422 |
|
| #endif |
| 423 |
|
| |
| 424 |
|
| INCLUDE: const-xs.inc |
| 425 |
|
| |