| 1 |
|
| #ifdef __cplusplus |
| 2 |
|
| extern "C" { |
| 3 |
|
| #endif |
| 4 |
|
| #include "EXTERN.h" |
| 5 |
|
| #include "perl.h" |
| 6 |
|
| #include "XSUB.h" |
| 7 |
|
| #ifdef __cplusplus |
| 8 |
|
| } |
| 9 |
|
| #endif |
| 10 |
|
| #include <sys/shm.h> |
| 11 |
|
| #include <sys/sem.h> |
| 12 |
|
| #include <sys/ipc.h> |
| 13 |
|
| #include "sharestuff.h" |
| 14 |
|
| /* |
| 15 |
|
| * Some perl version compatibility stuff. |
| 16 |
|
| * Taken from HTML::Parser |
| 17 |
|
| */ |
| 18 |
|
| #include "patchlevel.h" |
| 19 |
|
| #if PATCHLEVEL <= 4 /* perl5.004_XX */ |
| 20 |
|
| #ifndef PL_sv_undef |
| 21 |
|
| #define PL_sv_undef sv_undef |
| 22 |
|
| #define PL_sv_yes sv_yes |
| 23 |
|
| #endif |
| 24 |
|
| #ifndef PL_hexdigit |
| 25 |
|
| #define PL_hexdigit hexdigit |
| 26 |
|
| #endif |
| 27 |
|
| #if (PATCHLEVEL == 4 && SUBVERSION <= 4) |
| 28 |
|
| /* The newSVpvn function was introduced in perl5.004_05 */ static SV * |
| 29 |
|
| newSVpvn( char *s, STRLEN len ) { |
| 30 |
|
| register SV *sv = newSV( 0 ); |
| 31 |
|
| sv_setpvn( sv, s, len ); |
| 32 |
|
| return sv; |
| 33 |
|
| } |
| 34 |
|
| #endif /* not perl5.004_05 */ |
| 35 |
|
| #endif /* perl5.004_XX */ |
| 36 |
|
| |
| 37 |
|
| static double |
| 38 |
4 |
| constant( char *name, int arg ) { |
| 39 |
4 |
| errno = 0; |
| 40 |
4 |
| switch ( *name ) { |
| 41 |
0 |
| case 'A': |
| 42 |
0 |
| break; |
| 43 |
0 |
| case 'B': |
| 44 |
0 |
| break; |
| 45 |
0 |
| case 'C': |
| 46 |
0 |
| break; |
| 47 |
0 |
| case 'D': |
| 48 |
0 |
| break; |
| 49 |
0 |
| case 'E': |
| 50 |
0 |
| break; |
| 51 |
0 |
| case 'F': |
| 52 |
0 |
| break; |
| 53 |
0 |
| case 'G': |
| 54 |
0 |
▶ | if ( strEQ( name, "GETALL" ) ) |
Branch: 1 branch
| Branch | True | False | Total |
| if ( strEQ( name, "GETALL" ) ) |
0 |
0 |
0 |
|
| 55 |
|
| #ifdef GETALL |
| 56 |
0 |
| return GETALL; |
| 57 |
|
| #else |
| 58 |
|
| goto not_there; |
| 59 |
|
| #endif |
| 60 |
0 |
▶ | if ( strEQ( name, "GETNCNT" ) ) |
Branch: 1 branch
| Branch | True | False | Total |
| if ( strEQ( name, "GETNCNT" ) ) |
0 |
0 |
0 |
|
| 61 |
|
| #ifdef GETNCNT |
| 62 |
0 |
| return GETNCNT; |
| 63 |
|
| #else |
| 64 |
|
| goto not_there; |
| 65 |
|
| #endif |
| 66 |
0 |
▶ | if ( strEQ( name, "GETPID" ) ) |
Branch: 1 branch
| Branch | True | False | Total |
| if ( strEQ( name, "GETPID" ) ) |
0 |
0 |
0 |
|
| 67 |
|
| #ifdef GETPID |
| 68 |
0 |
| return GETPID; |
| 69 |
|
| #else |
| 70 |
|
| goto not_there; |
| 71 |
|
| #endif |
| 72 |
0 |
▶ | if ( strEQ( name, "GETVAL" ) ) |
Branch: 1 branch
| Branch | True | False | Total |
| if ( strEQ( name, "GETVAL" ) ) |
0 |
0 |
0 |
|
| 73 |
|
| #ifdef GETVAL |
| 74 |
0 |
| return GETVAL; |
| 75 |
|
| #else |
| 76 |
|
| goto not_there; |
| 77 |
|
| #endif |
| 78 |
0 |
▶ | if ( strEQ( name, "GETZCNT" ) ) |
Branch: 1 branch
| Branch | True | False | Total |
| if ( strEQ( name, "GETZCNT" ) ) |
0 |
0 |
0 |
|
| 79 |
|
| #ifdef GETZCNT |
| 80 |
0 |
| return GETZCNT; |
| 81 |
|
| #else |
| 82 |
|
| goto not_there; |
| 83 |
|
| #endif |
| 84 |
0 |
| break; |
| 85 |
0 |
| case 'H': |
| 86 |
0 |
| break; |
| 87 |
2 |
| case 'I': |
| 88 |
2 |
▶ | if ( strEQ( name, "IPC_ALLOC" ) ) |
Branch: 1 branch
| Branch | True | False | Total |
| if ( strEQ( name, "IPC_ALLOC" ) ) |
0 |
2 |
2 |
|
| 89 |
|
| #ifdef IPC_ALLOC |
| 90 |
|
| return IPC_ALLOC; |
| 91 |
|
| #else |
| 92 |
0 |
| goto not_there; |
| 93 |
|
| #endif |
| 94 |
2 |
▶ | if ( strEQ( name, "IPC_CREAT" ) ) |
Branch: 1 branch
| Branch | True | False | Total |
| if ( strEQ( name, "IPC_CREAT" ) ) |
2 |
0 |
2 |
|
| 95 |
|
| #ifdef IPC_CREAT |
| 96 |
2 |
| return IPC_CREAT; |
| 97 |
|
| #else |
| 98 |
|
| goto not_there; |
| 99 |
|
| #endif |
| 100 |
0 |
▶ | if ( strEQ( name, "IPC_EXCL" ) ) |
Branch: 1 branch
| Branch | True | False | Total |
| if ( strEQ( name, "IPC_EXCL" ) ) |
0 |
0 |
0 |
|
| 101 |
|
| #ifdef IPC_EXCL |
| 102 |
0 |
| return IPC_EXCL; |
| 103 |
|
| #else |
| 104 |
|
| goto not_there; |
| 105 |
|
| #endif |
| 106 |
0 |
▶ | if ( strEQ( name, "IPC_NOWAIT" ) ) |
Branch: 1 branch
| Branch | True | False | Total |
| if ( strEQ( name, "IPC_NOWAIT" ) ) |
0 |
0 |
0 |
|
| 107 |
|
| #ifdef IPC_NOWAIT |
| 108 |
0 |
| return IPC_NOWAIT; |
| 109 |
|
| #else |
| 110 |
|
| goto not_there; |
| 111 |
|
| #endif |
| 112 |
0 |
▶ | if ( strEQ( name, "IPC_O_RMID" ) ) |
Branch: 1 branch
| Branch | True | False | Total |
| if ( strEQ( name, "IPC_O_RMID" ) ) |
0 |
0 |
0 |
|
| 113 |
|
| #ifdef IPC_O_RMID |
| 114 |
|
| return IPC_O_RMID; |
| 115 |
|
| #else |
| 116 |
0 |
| goto not_there; |
| 117 |
|
| #endif |
| 118 |
0 |
▶ | if ( strEQ( name, "IPC_O_SET" ) ) |
Branch: 1 branch
| Branch | True | False | Total |
| if ( strEQ( name, "IPC_O_SET" ) ) |
0 |
0 |
0 |
|
| 119 |
|
| #ifdef IPC_O_SET |
| 120 |
|
| return IPC_O_SET; |
| 121 |
|
| #else |
| 122 |
0 |
| goto not_there; |
| 123 |
|
| #endif |
| 124 |
0 |
▶ | if ( strEQ( name, "IPC_O_STAT" ) ) |
Branch: 1 branch
| Branch | True | False | Total |
| if ( strEQ( name, "IPC_O_STAT" ) ) |
0 |
0 |
0 |
|
| 125 |
|
| #ifdef IPC_O_STAT |
| 126 |
|
| return IPC_O_STAT; |
| 127 |
|
| #else |
| 128 |
0 |
| goto not_there; |
| 129 |
|
| #endif |
| 130 |
0 |
▶ | if ( strEQ( name, "IPC_PRIVATE" ) ) |
Branch: 1 branch
| Branch | True | False | Total |
| if ( strEQ( name, "IPC_PRIVATE" ) ) |
0 |
0 |
0 |
|
| 131 |
|
| #ifdef IPC_PRIVATE |
| 132 |
0 |
| return IPC_PRIVATE; |
| 133 |
|
| #else |
| 134 |
|
| goto not_there; |
| 135 |
|
| #endif |
| 136 |
0 |
▶ | if ( strEQ( name, "IPC_RMID" ) ) |
Branch: 1 branch
| Branch | True | False | Total |
| if ( strEQ( name, "IPC_RMID" ) ) |
0 |
0 |
0 |
|
| 137 |
|
| #ifdef IPC_RMID |
| 138 |
0 |
| return IPC_RMID; |
| 139 |
|
| #else |
| 140 |
|
| goto not_there; |
| 141 |
|
| #endif |
| 142 |
0 |
▶ | if ( strEQ( name, "IPC_SET" ) ) |
Branch: 1 branch
| Branch | True | False | Total |
| if ( strEQ( name, "IPC_SET" ) ) |
0 |
0 |
0 |
|
| 143 |
|
| #ifdef IPC_SET |
| 144 |
0 |
| return IPC_SET; |
| 145 |
|
| #else |
| 146 |
|
| goto not_there; |
| 147 |
|
| #endif |
| 148 |
0 |
▶ | if ( strEQ( name, "IPC_STAT" ) ) |
Branch: 1 branch
| Branch | True | False | Total |
| if ( strEQ( name, "IPC_STAT" ) ) |
0 |
0 |
0 |
|
| 149 |
|
| #ifdef IPC_STAT |
| 150 |
0 |
| return IPC_STAT; |
| 151 |
|
| #else |
| 152 |
|
| goto not_there; |
| 153 |
|
| #endif |
| 154 |
0 |
| break; |
| 155 |
0 |
| case 'J': |
| 156 |
0 |
| break; |
| 157 |
0 |
| case 'K': |
| 158 |
0 |
| break; |
| 159 |
2 |
| case 'L': |
| 160 |
2 |
▶ | if ( strEQ( name, "LOCK_EX" ) ) |
Branch: 1 branch
| Branch | True | False | Total |
| if ( strEQ( name, "LOCK_EX" ) ) |
2 |
0 |
2 |
|
| 161 |
|
| #ifdef LOCK_EX |
| 162 |
2 |
| return LOCK_EX; |
| 163 |
|
| #else |
| 164 |
|
| goto not_there; |
| 165 |
|
| #endif |
| 166 |
0 |
▶ | if ( strEQ( name, "LOCK_SH" ) ) |
Branch: 1 branch
| Branch | True | False | Total |
| if ( strEQ( name, "LOCK_SH" ) ) |
0 |
0 |
0 |
|
| 167 |
|
| #ifdef LOCK_SH |
| 168 |
0 |
| return LOCK_SH; |
| 169 |
|
| #else |
| 170 |
|
| goto not_there; |
| 171 |
|
| #endif |
| 172 |
0 |
▶ | if ( strEQ( name, "LOCK_NB" ) ) |
Branch: 1 branch
| Branch | True | False | Total |
| if ( strEQ( name, "LOCK_NB" ) ) |
0 |
0 |
0 |
|
| 173 |
|
| #ifdef LOCK_NB |
| 174 |
0 |
| return LOCK_NB; |
| 175 |
|
| #else |
| 176 |
|
| goto not_there; |
| 177 |
|
| #endif |
| 178 |
0 |
▶ | if ( strEQ( name, "LOCK_UN" ) ) |
Branch: 1 branch
| Branch | True | False | Total |
| if ( strEQ( name, "LOCK_UN" ) ) |
0 |
0 |
0 |
|
| 179 |
|
| #ifdef LOCK_UN |
| 180 |
0 |
| return LOCK_UN; |
| 181 |
|
| #else |
| 182 |
|
| goto not_there; |
| 183 |
|
| #endif |
| 184 |
0 |
| break; |
| 185 |
0 |
| case 'M': |
| 186 |
0 |
| break; |
| 187 |
0 |
| case 'N': |
| 188 |
0 |
| break; |
| 189 |
0 |
| case 'O': |
| 190 |
0 |
| break; |
| 191 |
0 |
| case 'P': |
| 192 |
0 |
| break; |
| 193 |
0 |
| case 'Q': |
| 194 |
0 |
| break; |
| 195 |
0 |
| case 'R': |
| 196 |
0 |
| break; |
| 197 |
0 |
| case 'S': |
| 198 |
0 |
▶ | if ( strEQ( name, "SEM_A" ) ) |
Branch: 1 branch
| Branch | True | False | Total |
| if ( strEQ( name, "SEM_A" ) ) |
0 |
0 |
0 |
|
| 199 |
|
| #ifdef SEM_A |
| 200 |
|
| return SEM_A; |
| 201 |
|
| #else |
| 202 |
0 |
| goto not_there; |
| 203 |
|
| #endif |
| 204 |
0 |
▶ | if ( strEQ( name, "SEM_R" ) ) |
Branch: 1 branch
| Branch | True | False | Total |
| if ( strEQ( name, "SEM_R" ) ) |
0 |
0 |
0 |
|
| 205 |
|
| #ifdef SEM_R |
| 206 |
|
| return SEM_R; |
| 207 |
|
| #else |
| 208 |
0 |
| goto not_there; |
| 209 |
|
| #endif |
| 210 |
0 |
▶ | if ( strEQ( name, "SEM_UNDO" ) ) |
Branch: 1 branch
| Branch | True | False | Total |
| if ( strEQ( name, "SEM_UNDO" ) ) |
0 |
0 |
0 |
|
| 211 |
|
| #ifdef SEM_UNDO |
| 212 |
0 |
| return SEM_UNDO; |
| 213 |
|
| #else |
| 214 |
|
| goto not_there; |
| 215 |
|
| #endif |
| 216 |
0 |
▶ | if ( strEQ( name, "SETALL" ) ) |
Branch: 1 branch
| Branch | True | False | Total |
| if ( strEQ( name, "SETALL" ) ) |
0 |
0 |
0 |
|
| 217 |
|
| #ifdef SETALL |
| 218 |
0 |
| return SETALL; |
| 219 |
|
| #else |
| 220 |
|
| goto not_there; |
| 221 |
|
| #endif |
| 222 |
0 |
▶ | if ( strEQ( name, "SETVAL" ) ) |
Branch: 1 branch
| Branch | True | False | Total |
| if ( strEQ( name, "SETVAL" ) ) |
0 |
0 |
0 |
|
| 223 |
|
| #ifdef SETVAL |
| 224 |
0 |
| return SETVAL; |
| 225 |
|
| #else |
| 226 |
|
| goto not_there; |
| 227 |
|
| #endif |
| 228 |
0 |
▶ | if ( strEQ( name, "SHM_LOCK" ) ) |
Branch: 1 branch
| Branch | True | False | Total |
| if ( strEQ( name, "SHM_LOCK" ) ) |
0 |
0 |
0 |
|
| 229 |
|
| #ifdef SHM_LOCK |
| 230 |
0 |
| return SHM_LOCK; |
| 231 |
|
| #else |
| 232 |
|
| goto not_there; |
| 233 |
|
| #endif |
| 234 |
0 |
▶ | if ( strEQ( name, "SHM_R" ) ) |
Branch: 1 branch
| Branch | True | False | Total |
| if ( strEQ( name, "SHM_R" ) ) |
0 |
0 |
0 |
|
| 235 |
|
| #ifdef SHM_R |
| 236 |
0 |
| return SHM_R; |
| 237 |
|
| #else |
| 238 |
|
| goto not_there; |
| 239 |
|
| #endif |
| 240 |
0 |
▶ | if ( strEQ( name, "SHM_RDONLY" ) ) |
Branch: 1 branch
| Branch | True | False | Total |
| if ( strEQ( name, "SHM_RDONLY" ) ) |
0 |
0 |
0 |
|
| 241 |
|
| #ifdef SHM_RDONLY |
| 242 |
0 |
| return SHM_RDONLY; |
| 243 |
|
| #else |
| 244 |
|
| goto not_there; |
| 245 |
|
| #endif |
| 246 |
0 |
▶ | if ( strEQ( name, "SHM_RND" ) ) |
Branch: 1 branch
| Branch | True | False | Total |
| if ( strEQ( name, "SHM_RND" ) ) |
0 |
0 |
0 |
|
| 247 |
|
| #ifdef SHM_RND |
| 248 |
0 |
| return SHM_RND; |
| 249 |
|
| #else |
| 250 |
|
| goto not_there; |
| 251 |
|
| #endif |
| 252 |
0 |
▶ | if ( strEQ( name, "SHM_SHARE_MMU" ) ) |
Branch: 1 branch
| Branch | True | False | Total |
| if ( strEQ( name, "SHM_SHARE_MMU" ) ) |
0 |
0 |
0 |
|
| 253 |
|
| #ifdef SHM_SHARE_MMU |
| 254 |
|
| return SHM_SHARE_MMU; |
| 255 |
|
| #else |
| 256 |
0 |
| goto not_there; |
| 257 |
|
| #endif |
| 258 |
0 |
▶ | if ( strEQ( name, "SHM_UNLOCK" ) ) |
Branch: 1 branch
| Branch | True | False | Total |
| if ( strEQ( name, "SHM_UNLOCK" ) ) |
0 |
0 |
0 |
|
| 259 |
|
| #ifdef SHM_UNLOCK |
| 260 |
0 |
| return SHM_UNLOCK; |
| 261 |
|
| #else |
| 262 |
|
| goto not_there; |
| 263 |
|
| #endif |
| 264 |
0 |
▶ | if ( strEQ( name, "SHM_W" ) ) |
Branch: 1 branch
| Branch | True | False | Total |
| if ( strEQ( name, "SHM_W" ) ) |
0 |
0 |
0 |
|
| 265 |
|
| #ifdef SHM_W |
| 266 |
0 |
| return SHM_W; |
| 267 |
|
| #else |
| 268 |
|
| goto not_there; |
| 269 |
|
| #endif |
| 270 |
0 |
| break; |
| 271 |
0 |
| case 'T': |
| 272 |
0 |
| break; |
| 273 |
0 |
| case 'U': |
| 274 |
0 |
| break; |
| 275 |
0 |
| case 'V': |
| 276 |
0 |
| break; |
| 277 |
0 |
| case 'W': |
| 278 |
0 |
| break; |
| 279 |
0 |
| case 'X': |
| 280 |
0 |
| break; |
| 281 |
0 |
| case 'Y': |
| 282 |
0 |
| break; |
| 283 |
0 |
| case 'Z': |
| 284 |
0 |
| break; |
| 285 |
|
| } |
| 286 |
0 |
| errno = EINVAL; |
| 287 |
0 |
| return 0; |
| 288 |
|
| |
| 289 |
0 |
| not_there: |
| 290 |
0 |
| errno = ENOENT; |
| 291 |
0 |
| return 0; |
| 292 |
|
| } |
| 293 |
|
| |
| 294 |
|
| /* *INDENT-OFF* */ |
| 295 |
|
| |
| 296 |
|
| MODULE = IPC::ShareLite PACKAGE = IPC::ShareLite |
| 297 |
|
| |
| 298 |
|
| PROTOTYPES: DISABLE |
| 299 |
|
| |
| 300 |
|
| double |
| 301 |
|
| constant( char *name, int arg) |
| 302 |
|
| |
| 303 |
|
| Share* |
| 304 |
|
| new_share(key_t key, int segment_size, int flags) |
| 305 |
|
| |
| 306 |
|
| int |
| 307 |
|
| write_share(Share *share, char *data, int length) |
| 308 |
|
| |
| 309 |
|
| char* |
| 310 |
|
| read_share(Share *share) |
| 311 |
|
| PREINIT: |
| 312 |
|
| char* data; |
| 313 |
|
| int length; |
| 314 |
|
| CODE: |
| 315 |
2005 |
| length = read_share(share, &data); |
| 316 |
2005 |
| ST(0) = sv_newmortal(); |
| 317 |
2005 |
▶ | if (length >= 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (length >= 0) { |
2005 |
0 |
2005 |
|
| 318 |
|
| #ifdef sv_usepvn_flags |
| 319 |
2005 |
| sv_usepvn_flags((SV*)ST(0), data, length, SV_HAS_TRAILING_NUL); |
| 320 |
|
| #else |
| 321 |
|
| sv_usepvn((SV*)ST(0), data, length); |
| 322 |
|
| #endif |
| 323 |
|
| } else { |
| 324 |
0 |
| sv_setsv(ST(0), &PL_sv_undef); |
| 325 |
|
| } |
| 326 |
|
| |
| 327 |
|
| int |
| 328 |
|
| destroy_share(Share *share, int rmid) |
| 329 |
|
| |
| 330 |
|
| int |
| 331 |
|
| sharelite_lock(Share *share, int flags) |
| 332 |
|
| |
| 333 |
|
| int |
| 334 |
|
| sharelite_unlock(Share *share) |
| 335 |
|
| |
| 336 |
|
| unsigned int |
| 337 |
|
| sharelite_version(Share *share) |
| 338 |
|
| |
| 339 |
|
| int |
| 340 |
|
| sharelite_num_segments(Share *share) |