1
2
3
4
5
6
7 package unix
8
9 import (
10 "bytes"
11 "fmt"
12 "unsafe"
13 )
14
15
16 func bpxcall(plist []unsafe.Pointer, bpx_offset int64)
17
18
19 func A2e([]byte)
20
21
22 func E2a([]byte)
23
24 const (
25 BPX4STA = 192
26 BPX4FST = 104
27 BPX4LST = 132
28 BPX4OPN = 156
29 BPX4CLO = 72
30 BPX4CHR = 500
31 BPX4FCR = 504
32 BPX4LCR = 1180
33 BPX4CTW = 492
34 BPX4GTH = 1056
35 BPX4PTQ = 412
36 BPX4PTR = 320
37 )
38
39 const (
40
41
42 BPX_OPNFHIGH = 0x80
43
44 BPX_OPNFEXEC = 0x80
45
46 BPX_O_NOLARGEFILE = 0x08
47 BPX_O_LARGEFILE = 0x04
48 BPX_O_ASYNCSIG = 0x02
49 BPX_O_SYNC = 0x01
50
51 BPX_O_CREXCL = 0xc0
52 BPX_O_CREAT = 0x80
53 BPX_O_EXCL = 0x40
54 BPX_O_NOCTTY = 0x20
55 BPX_O_TRUNC = 0x10
56 BPX_O_APPEND = 0x08
57 BPX_O_NONBLOCK = 0x04
58 BPX_FNDELAY = 0x04
59 BPX_O_RDWR = 0x03
60 BPX_O_RDONLY = 0x02
61 BPX_O_WRONLY = 0x01
62 BPX_O_ACCMODE = 0x03
63 BPX_O_GETFL = 0x0f
64
65
66
67 BPX_FT_DIR = 1
68 BPX_FT_CHARSPEC = 2
69 BPX_FT_REGFILE = 3
70 BPX_FT_FIFO = 4
71 BPX_FT_SYMLINK = 5
72 BPX_FT_SOCKET = 6
73
74 BPX_S_ISUID = 0x08
75 BPX_S_ISGID = 0x04
76 BPX_S_ISVTX = 0x02
77 BPX_S_IRWXU1 = 0x01
78 BPX_S_IRUSR = 0x01
79
80 BPX_S_IRWXU2 = 0xc0
81 BPX_S_IWUSR = 0x80
82 BPX_S_IXUSR = 0x40
83 BPX_S_IRWXG = 0x38
84 BPX_S_IRGRP = 0x20
85 BPX_S_IWGRP = 0x10
86 BPX_S_IXGRP = 0x08
87 BPX_S_IRWXOX = 0x07
88 BPX_S_IROTH = 0x04
89 BPX_S_IWOTH = 0x02
90 BPX_S_IXOTH = 0x01
91
92 CW_INTRPT = 1
93 CW_CONDVAR = 32
94 CW_TIMEOUT = 64
95
96 PGTHA_NEXT = 2
97 PGTHA_CURRENT = 1
98 PGTHA_FIRST = 0
99 PGTHA_LAST = 3
100 PGTHA_PROCESS = 0x80
101 PGTHA_CONTTY = 0x40
102 PGTHA_PATH = 0x20
103 PGTHA_COMMAND = 0x10
104 PGTHA_FILEDATA = 0x08
105 PGTHA_THREAD = 0x04
106 PGTHA_PTAG = 0x02
107 PGTHA_COMMANDLONG = 0x01
108 PGTHA_THREADFAST = 0x80
109 PGTHA_FILEPATH = 0x40
110 PGTHA_THDSIGMASK = 0x20
111
112 QUIESCE_TERM int32 = 1
113 QUIESCE_FORCE int32 = 2
114 QUIESCE_QUERY int32 = 3
115 QUIESCE_FREEZE int32 = 4
116 QUIESCE_UNFREEZE int32 = 5
117 FREEZE_THIS_THREAD int32 = 6
118 FREEZE_EXIT int32 = 8
119 QUIESCE_SRB int32 = 9
120 )
121
122 type Pgtha struct {
123 Pid uint32
124 Tid0 uint32
125 Tid1 uint32
126 Accesspid byte
127 Accesstid byte
128 Accessasid uint16
129 Loginname [8]byte
130 Flag1 byte
131 Flag1b2 byte
132 }
133
134 type Bpxystat_t struct {
135 St_id [4]uint8
136 St_length uint16
137 St_version uint16
138 St_mode uint32
139 St_ino uint32
140 St_dev uint32
141 St_nlink uint32
142 St_uid uint32
143 St_gid uint32
144 St_size uint64
145 St_atime uint32
146 St_mtime uint32
147 St_ctime uint32
148 St_rdev uint32
149 St_auditoraudit uint32
150 St_useraudit uint32
151 St_blksize uint32
152 St_createtime uint32
153 St_auditid [4]uint32
154 St_res01 uint32
155 Ft_ccsid uint16
156 Ft_flags uint16
157 St_res01a [2]uint32
158 St_res02 uint32
159 St_blocks uint32
160 St_opaque [3]uint8
161 St_visible uint8
162 St_reftime uint32
163 St_fid uint64
164 St_filefmt uint8
165 St_fspflag2 uint8
166 St_res03 [2]uint8
167 St_ctimemsec uint32
168 St_seclabel [8]uint8
169 St_res04 [4]uint8
170
171 _ uint32
172 St_atime64 uint64
173 St_mtime64 uint64
174 St_ctime64 uint64
175 St_createtime64 uint64
176 St_reftime64 uint64
177 _ uint64
178 St_res05 [16]uint8
179
180 }
181
182 type BpxFilestatus struct {
183 Oflag1 byte
184 Oflag2 byte
185 Oflag3 byte
186 Oflag4 byte
187 }
188
189 type BpxMode struct {
190 Ftype byte
191 Mode1 byte
192 Mode2 byte
193 Mode3 byte
194 }
195
196
197 type Bpxyatt_t struct {
198 Att_id [4]uint8
199 Att_version uint16
200 Att_res01 [2]uint8
201 Att_setflags1 uint8
202 Att_setflags2 uint8
203 Att_setflags3 uint8
204 Att_setflags4 uint8
205 Att_mode uint32
206 Att_uid uint32
207 Att_gid uint32
208 Att_opaquemask [3]uint8
209 Att_visblmaskres uint8
210 Att_opaque [3]uint8
211 Att_visibleres uint8
212 Att_size_h uint32
213 Att_size_l uint32
214 Att_atime uint32
215 Att_mtime uint32
216 Att_auditoraudit uint32
217 Att_useraudit uint32
218 Att_ctime uint32
219 Att_reftime uint32
220
221 Att_filefmt uint8
222 Att_res02 [3]uint8
223 Att_filetag uint32
224 Att_res03 [8]uint8
225
226 Att_atime64 uint64
227 Att_mtime64 uint64
228 Att_ctime64 uint64
229 Att_reftime64 uint64
230 Att_seclabel [8]uint8
231 Att_ver3res02 [8]uint8
232
233 }
234
235 func BpxOpen(name string, options *BpxFilestatus, mode *BpxMode) (rv int32, rc int32, rn int32) {
236 if len(name) < 1024 {
237 var namebuf [1024]byte
238 sz := int32(copy(namebuf[:], name))
239 A2e(namebuf[:sz])
240 var parms [7]unsafe.Pointer
241 parms[0] = unsafe.Pointer(&sz)
242 parms[1] = unsafe.Pointer(&namebuf[0])
243 parms[2] = unsafe.Pointer(options)
244 parms[3] = unsafe.Pointer(mode)
245 parms[4] = unsafe.Pointer(&rv)
246 parms[5] = unsafe.Pointer(&rc)
247 parms[6] = unsafe.Pointer(&rn)
248 bpxcall(parms[:], BPX4OPN)
249 return rv, rc, rn
250 }
251 return -1, -1, -1
252 }
253
254 func BpxClose(fd int32) (rv int32, rc int32, rn int32) {
255 var parms [4]unsafe.Pointer
256 parms[0] = unsafe.Pointer(&fd)
257 parms[1] = unsafe.Pointer(&rv)
258 parms[2] = unsafe.Pointer(&rc)
259 parms[3] = unsafe.Pointer(&rn)
260 bpxcall(parms[:], BPX4CLO)
261 return rv, rc, rn
262 }
263
264 func BpxFileFStat(fd int32, st *Bpxystat_t) (rv int32, rc int32, rn int32) {
265 st.St_id = [4]uint8{0xe2, 0xe3, 0xc1, 0xe3}
266 st.St_version = 2
267 stat_sz := uint32(unsafe.Sizeof(*st))
268 var parms [6]unsafe.Pointer
269 parms[0] = unsafe.Pointer(&fd)
270 parms[1] = unsafe.Pointer(&stat_sz)
271 parms[2] = unsafe.Pointer(st)
272 parms[3] = unsafe.Pointer(&rv)
273 parms[4] = unsafe.Pointer(&rc)
274 parms[5] = unsafe.Pointer(&rn)
275 bpxcall(parms[:], BPX4FST)
276 return rv, rc, rn
277 }
278
279 func BpxFileStat(name string, st *Bpxystat_t) (rv int32, rc int32, rn int32) {
280 if len(name) < 1024 {
281 var namebuf [1024]byte
282 sz := int32(copy(namebuf[:], name))
283 A2e(namebuf[:sz])
284 st.St_id = [4]uint8{0xe2, 0xe3, 0xc1, 0xe3}
285 st.St_version = 2
286 stat_sz := uint32(unsafe.Sizeof(*st))
287 var parms [7]unsafe.Pointer
288 parms[0] = unsafe.Pointer(&sz)
289 parms[1] = unsafe.Pointer(&namebuf[0])
290 parms[2] = unsafe.Pointer(&stat_sz)
291 parms[3] = unsafe.Pointer(st)
292 parms[4] = unsafe.Pointer(&rv)
293 parms[5] = unsafe.Pointer(&rc)
294 parms[6] = unsafe.Pointer(&rn)
295 bpxcall(parms[:], BPX4STA)
296 return rv, rc, rn
297 }
298 return -1, -1, -1
299 }
300
301 func BpxFileLStat(name string, st *Bpxystat_t) (rv int32, rc int32, rn int32) {
302 if len(name) < 1024 {
303 var namebuf [1024]byte
304 sz := int32(copy(namebuf[:], name))
305 A2e(namebuf[:sz])
306 st.St_id = [4]uint8{0xe2, 0xe3, 0xc1, 0xe3}
307 st.St_version = 2
308 stat_sz := uint32(unsafe.Sizeof(*st))
309 var parms [7]unsafe.Pointer
310 parms[0] = unsafe.Pointer(&sz)
311 parms[1] = unsafe.Pointer(&namebuf[0])
312 parms[2] = unsafe.Pointer(&stat_sz)
313 parms[3] = unsafe.Pointer(st)
314 parms[4] = unsafe.Pointer(&rv)
315 parms[5] = unsafe.Pointer(&rc)
316 parms[6] = unsafe.Pointer(&rn)
317 bpxcall(parms[:], BPX4LST)
318 return rv, rc, rn
319 }
320 return -1, -1, -1
321 }
322
323 func BpxChattr(path string, attr *Bpxyatt_t) (rv int32, rc int32, rn int32) {
324 if len(path) >= 1024 {
325 return -1, -1, -1
326 }
327 var namebuf [1024]byte
328 sz := int32(copy(namebuf[:], path))
329 A2e(namebuf[:sz])
330 attr_sz := uint32(unsafe.Sizeof(*attr))
331 var parms [7]unsafe.Pointer
332 parms[0] = unsafe.Pointer(&sz)
333 parms[1] = unsafe.Pointer(&namebuf[0])
334 parms[2] = unsafe.Pointer(&attr_sz)
335 parms[3] = unsafe.Pointer(attr)
336 parms[4] = unsafe.Pointer(&rv)
337 parms[5] = unsafe.Pointer(&rc)
338 parms[6] = unsafe.Pointer(&rn)
339 bpxcall(parms[:], BPX4CHR)
340 return rv, rc, rn
341 }
342
343 func BpxLchattr(path string, attr *Bpxyatt_t) (rv int32, rc int32, rn int32) {
344 if len(path) >= 1024 {
345 return -1, -1, -1
346 }
347 var namebuf [1024]byte
348 sz := int32(copy(namebuf[:], path))
349 A2e(namebuf[:sz])
350 attr_sz := uint32(unsafe.Sizeof(*attr))
351 var parms [7]unsafe.Pointer
352 parms[0] = unsafe.Pointer(&sz)
353 parms[1] = unsafe.Pointer(&namebuf[0])
354 parms[2] = unsafe.Pointer(&attr_sz)
355 parms[3] = unsafe.Pointer(attr)
356 parms[4] = unsafe.Pointer(&rv)
357 parms[5] = unsafe.Pointer(&rc)
358 parms[6] = unsafe.Pointer(&rn)
359 bpxcall(parms[:], BPX4LCR)
360 return rv, rc, rn
361 }
362
363 func BpxFchattr(fd int32, attr *Bpxyatt_t) (rv int32, rc int32, rn int32) {
364 attr_sz := uint32(unsafe.Sizeof(*attr))
365 var parms [6]unsafe.Pointer
366 parms[0] = unsafe.Pointer(&fd)
367 parms[1] = unsafe.Pointer(&attr_sz)
368 parms[2] = unsafe.Pointer(attr)
369 parms[3] = unsafe.Pointer(&rv)
370 parms[4] = unsafe.Pointer(&rc)
371 parms[5] = unsafe.Pointer(&rn)
372 bpxcall(parms[:], BPX4FCR)
373 return rv, rc, rn
374 }
375
376 func BpxCondTimedWait(sec uint32, nsec uint32, events uint32, secrem *uint32, nsecrem *uint32) (rv int32, rc int32, rn int32) {
377 var parms [8]unsafe.Pointer
378 parms[0] = unsafe.Pointer(&sec)
379 parms[1] = unsafe.Pointer(&nsec)
380 parms[2] = unsafe.Pointer(&events)
381 parms[3] = unsafe.Pointer(secrem)
382 parms[4] = unsafe.Pointer(nsecrem)
383 parms[5] = unsafe.Pointer(&rv)
384 parms[6] = unsafe.Pointer(&rc)
385 parms[7] = unsafe.Pointer(&rn)
386 bpxcall(parms[:], BPX4CTW)
387 return rv, rc, rn
388 }
389 func BpxGetthent(in *Pgtha, outlen *uint32, out unsafe.Pointer) (rv int32, rc int32, rn int32) {
390 var parms [7]unsafe.Pointer
391 inlen := uint32(26)
392 parms[0] = unsafe.Pointer(&inlen)
393 parms[1] = unsafe.Pointer(&in)
394 parms[2] = unsafe.Pointer(outlen)
395 parms[3] = unsafe.Pointer(&out)
396 parms[4] = unsafe.Pointer(&rv)
397 parms[5] = unsafe.Pointer(&rc)
398 parms[6] = unsafe.Pointer(&rn)
399 bpxcall(parms[:], BPX4GTH)
400 return rv, rc, rn
401 }
402 func ZosJobname() (jobname string, err error) {
403 var pgtha Pgtha
404 pgtha.Pid = uint32(Getpid())
405 pgtha.Accesspid = PGTHA_CURRENT
406 pgtha.Flag1 = PGTHA_PROCESS
407 var out [256]byte
408 var outlen uint32
409 outlen = 256
410 rv, rc, rn := BpxGetthent(&pgtha, &outlen, unsafe.Pointer(&out[0]))
411 if rv == 0 {
412 gthc := []byte{0x87, 0xa3, 0x88, 0x83}
413 ix := bytes.Index(out[:], gthc)
414 if ix == -1 {
415 err = fmt.Errorf("BPX4GTH: gthc return data not found")
416 return
417 }
418 jn := out[ix+80 : ix+88]
419 E2a(jn)
420 jobname = string(bytes.TrimRight(jn, " "))
421
422 } else {
423 err = fmt.Errorf("BPX4GTH: rc=%d errno=%d reason=code=0x%x", rv, rc, rn)
424 }
425 return
426 }
427 func Bpx4ptq(code int32, data string) (rv int32, rc int32, rn int32) {
428 var userdata [8]byte
429 var parms [5]unsafe.Pointer
430 copy(userdata[:], data+" ")
431 A2e(userdata[:])
432 parms[0] = unsafe.Pointer(&code)
433 parms[1] = unsafe.Pointer(&userdata[0])
434 parms[2] = unsafe.Pointer(&rv)
435 parms[3] = unsafe.Pointer(&rc)
436 parms[4] = unsafe.Pointer(&rn)
437 bpxcall(parms[:], BPX4PTQ)
438 return rv, rc, rn
439 }
440
441 const (
442 PT_TRACE_ME = 0
443 PT_READ_I = 1
444 PT_READ_D = 2
445 PT_READ_U = 3
446 PT_WRITE_I = 4
447 PT_WRITE_D = 5
448 PT_CONTINUE = 7
449 PT_KILL = 8
450 PT_READ_GPR = 11
451 PT_READ_FPR = 12
452 PT_READ_VR = 13
453 PT_WRITE_GPR = 14
454 PT_WRITE_FPR = 15
455 PT_WRITE_VR = 16
456 PT_READ_BLOCK = 17
457 PT_WRITE_BLOCK = 19
458 PT_READ_GPRH = 20
459 PT_WRITE_GPRH = 21
460 PT_REGHSET = 22
461 PT_ATTACH = 30
462 PT_DETACH = 31
463 PT_REGSET = 32
464 PT_REATTACH = 33
465 PT_LDINFO = 34
466 PT_MULTI = 35
467 PT_LD64INFO = 36
468 PT_BLOCKREQ = 40
469 PT_THREAD_INFO = 60
470 PT_THREAD_MODIFY = 61
471 PT_THREAD_READ_FOCUS = 62
472 PT_THREAD_WRITE_FOCUS = 63
473 PT_THREAD_HOLD = 64
474 PT_THREAD_SIGNAL = 65
475 PT_EXPLAIN = 66
476 PT_EVENTS = 67
477 PT_THREAD_INFO_EXTENDED = 68
478 PT_REATTACH2 = 71
479 PT_CAPTURE = 72
480 PT_UNCAPTURE = 73
481 PT_GET_THREAD_TCB = 74
482 PT_GET_ALET = 75
483 PT_SWAPIN = 76
484 PT_EXTENDED_EVENT = 98
485 PT_RECOVER = 99
486 PT_GPR0 = 0
487 PT_GPR1 = 1
488 PT_GPR2 = 2
489 PT_GPR3 = 3
490 PT_GPR4 = 4
491 PT_GPR5 = 5
492 PT_GPR6 = 6
493 PT_GPR7 = 7
494 PT_GPR8 = 8
495 PT_GPR9 = 9
496 PT_GPR10 = 10
497 PT_GPR11 = 11
498 PT_GPR12 = 12
499 PT_GPR13 = 13
500 PT_GPR14 = 14
501 PT_GPR15 = 15
502 PT_FPR0 = 16
503 PT_FPR1 = 17
504 PT_FPR2 = 18
505 PT_FPR3 = 19
506 PT_FPR4 = 20
507 PT_FPR5 = 21
508 PT_FPR6 = 22
509 PT_FPR7 = 23
510 PT_FPR8 = 24
511 PT_FPR9 = 25
512 PT_FPR10 = 26
513 PT_FPR11 = 27
514 PT_FPR12 = 28
515 PT_FPR13 = 29
516 PT_FPR14 = 30
517 PT_FPR15 = 31
518 PT_FPC = 32
519 PT_PSW = 40
520 PT_PSW0 = 40
521 PT_PSW1 = 41
522 PT_CR0 = 42
523 PT_CR1 = 43
524 PT_CR2 = 44
525 PT_CR3 = 45
526 PT_CR4 = 46
527 PT_CR5 = 47
528 PT_CR6 = 48
529 PT_CR7 = 49
530 PT_CR8 = 50
531 PT_CR9 = 51
532 PT_CR10 = 52
533 PT_CR11 = 53
534 PT_CR12 = 54
535 PT_CR13 = 55
536 PT_CR14 = 56
537 PT_CR15 = 57
538 PT_GPRH0 = 58
539 PT_GPRH1 = 59
540 PT_GPRH2 = 60
541 PT_GPRH3 = 61
542 PT_GPRH4 = 62
543 PT_GPRH5 = 63
544 PT_GPRH6 = 64
545 PT_GPRH7 = 65
546 PT_GPRH8 = 66
547 PT_GPRH9 = 67
548 PT_GPRH10 = 68
549 PT_GPRH11 = 69
550 PT_GPRH12 = 70
551 PT_GPRH13 = 71
552 PT_GPRH14 = 72
553 PT_GPRH15 = 73
554 PT_VR0 = 74
555 PT_VR1 = 75
556 PT_VR2 = 76
557 PT_VR3 = 77
558 PT_VR4 = 78
559 PT_VR5 = 79
560 PT_VR6 = 80
561 PT_VR7 = 81
562 PT_VR8 = 82
563 PT_VR9 = 83
564 PT_VR10 = 84
565 PT_VR11 = 85
566 PT_VR12 = 86
567 PT_VR13 = 87
568 PT_VR14 = 88
569 PT_VR15 = 89
570 PT_VR16 = 90
571 PT_VR17 = 91
572 PT_VR18 = 92
573 PT_VR19 = 93
574 PT_VR20 = 94
575 PT_VR21 = 95
576 PT_VR22 = 96
577 PT_VR23 = 97
578 PT_VR24 = 98
579 PT_VR25 = 99
580 PT_VR26 = 100
581 PT_VR27 = 101
582 PT_VR28 = 102
583 PT_VR29 = 103
584 PT_VR30 = 104
585 PT_VR31 = 105
586 PT_PSWG = 106
587 PT_PSWG0 = 106
588 PT_PSWG1 = 107
589 PT_PSWG2 = 108
590 PT_PSWG3 = 109
591 )
592
593 func Bpx4ptr(request int32, pid int32, addr unsafe.Pointer, data unsafe.Pointer, buffer unsafe.Pointer) (rv int32, rc int32, rn int32) {
594 var parms [8]unsafe.Pointer
595 parms[0] = unsafe.Pointer(&request)
596 parms[1] = unsafe.Pointer(&pid)
597 parms[2] = unsafe.Pointer(&addr)
598 parms[3] = unsafe.Pointer(&data)
599 parms[4] = unsafe.Pointer(&buffer)
600 parms[5] = unsafe.Pointer(&rv)
601 parms[6] = unsafe.Pointer(&rc)
602 parms[7] = unsafe.Pointer(&rn)
603 bpxcall(parms[:], BPX4PTR)
604 return rv, rc, rn
605 }
606
607 func copyU8(val uint8, dest []uint8) int {
608 if len(dest) < 1 {
609 return 0
610 }
611 dest[0] = val
612 return 1
613 }
614
615 func copyU8Arr(src, dest []uint8) int {
616 if len(dest) < len(src) {
617 return 0
618 }
619 for i, v := range src {
620 dest[i] = v
621 }
622 return len(src)
623 }
624
625 func copyU16(val uint16, dest []uint16) int {
626 if len(dest) < 1 {
627 return 0
628 }
629 dest[0] = val
630 return 1
631 }
632
633 func copyU32(val uint32, dest []uint32) int {
634 if len(dest) < 1 {
635 return 0
636 }
637 dest[0] = val
638 return 1
639 }
640
641 func copyU32Arr(src, dest []uint32) int {
642 if len(dest) < len(src) {
643 return 0
644 }
645 for i, v := range src {
646 dest[i] = v
647 }
648 return len(src)
649 }
650
651 func copyU64(val uint64, dest []uint64) int {
652 if len(dest) < 1 {
653 return 0
654 }
655 dest[0] = val
656 return 1
657 }
658
View as plain text