-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathsyscall_zos_s390x.go
3213 lines (2844 loc) · 86.7 KB
/
syscall_zos_s390x.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright 2020 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build zos && s390x
// Many of the following syscalls are not available on all versions of z/OS.
// Some missing calls have legacy implementations/simulations but others
// will be missing completely. To achieve consistent failing behaviour on
// legacy systems, we first test the function pointer via a safeloading
// mechanism to see if the function exists on a given system. Then execution
// is branched to either continue the function call, or return an error.
package unix
import (
"bytes"
"fmt"
"os"
"reflect"
"regexp"
"runtime"
"sort"
"strings"
"sync"
"syscall"
"unsafe"
)
//go:noescape
func initZosLibVec()
//go:noescape
func GetZosLibVec() uintptr
func init() {
initZosLibVec()
r0, _, _ := CallLeFuncWithPtrReturn(GetZosLibVec()+SYS_____GETENV_A<<4, uintptr(unsafe.Pointer(&([]byte("__ZOS_XSYSTRACE\x00"))[0])))
if r0 != 0 {
n, _, _ := CallLeFuncWithPtrReturn(GetZosLibVec()+SYS___ATOI_A<<4, r0)
ZosTraceLevel = int(n)
r0, _, _ := CallLeFuncWithPtrReturn(GetZosLibVec()+SYS_____GETENV_A<<4, uintptr(unsafe.Pointer(&([]byte("__ZOS_XSYSTRACEFD\x00"))[0])))
if r0 != 0 {
fd, _, _ := CallLeFuncWithPtrReturn(GetZosLibVec()+SYS___ATOI_A<<4, r0)
f := os.NewFile(fd, "zostracefile")
if f != nil {
ZosTracefile = f
}
}
}
}
//go:noescape
func CallLeFuncWithErr(funcdesc uintptr, parms ...uintptr) (ret, errno2 uintptr, err Errno)
//go:noescape
func CallLeFuncWithPtrReturn(funcdesc uintptr, parms ...uintptr) (ret, errno2 uintptr, err Errno)
// -------------------------------
// pointer validity test
// good pointer returns 0
// bad pointer returns 1
//
//go:nosplit
func ptrtest(uintptr) uint64
// Load memory at ptr location with error handling if the location is invalid
//
//go:noescape
func safeload(ptr uintptr) (value uintptr, error uintptr)
const (
entrypointLocationOffset = 8 // From function descriptor
xplinkEyecatcher = 0x00c300c500c500f1 // ".C.E.E.1"
eyecatcherOffset = 16 // From function entrypoint (negative)
ppa1LocationOffset = 8 // From function entrypoint (negative)
nameLenOffset = 0x14 // From PPA1 start
nameOffset = 0x16 // From PPA1 start
)
func getPpaOffset(funcptr uintptr) int64 {
entrypoint, err := safeload(funcptr + entrypointLocationOffset)
if err != 0 {
return -1
}
// XPLink functions have ".C.E.E.1" as the first 8 bytes (EBCDIC)
val, err := safeload(entrypoint - eyecatcherOffset)
if err != 0 {
return -1
}
if val != xplinkEyecatcher {
return -1
}
ppaoff, err := safeload(entrypoint - ppa1LocationOffset)
if err != 0 {
return -1
}
ppaoff >>= 32
return int64(ppaoff)
}
//-------------------------------
// function descriptor pointer validity test
// good pointer returns 0
// bad pointer returns 1
// TODO: currently mksyscall_zos_s390x.go generate empty string for funcName
// have correct funcName pass to the funcptrtest function
func funcptrtest(funcptr uintptr, funcName string) uint64 {
entrypoint, err := safeload(funcptr + entrypointLocationOffset)
if err != 0 {
return 1
}
ppaoff := getPpaOffset(funcptr)
if ppaoff == -1 {
return 1
}
// PPA1 offset value is from the start of the entire function block, not the entrypoint
ppa1 := (entrypoint - eyecatcherOffset) + uintptr(ppaoff)
nameLen, err := safeload(ppa1 + nameLenOffset)
if err != 0 {
return 1
}
nameLen >>= 48
if nameLen > 128 {
return 1
}
// no function name input to argument end here
if funcName == "" {
return 0
}
var funcname [128]byte
for i := 0; i < int(nameLen); i += 8 {
v, err := safeload(ppa1 + nameOffset + uintptr(i))
if err != 0 {
return 1
}
funcname[i] = byte(v >> 56)
funcname[i+1] = byte(v >> 48)
funcname[i+2] = byte(v >> 40)
funcname[i+3] = byte(v >> 32)
funcname[i+4] = byte(v >> 24)
funcname[i+5] = byte(v >> 16)
funcname[i+6] = byte(v >> 8)
funcname[i+7] = byte(v)
}
runtime.CallLeFuncByPtr(runtime.XplinkLibvec+SYS___E2A_L<<4, // __e2a_l
[]uintptr{uintptr(unsafe.Pointer(&funcname[0])), nameLen})
name := string(funcname[:nameLen])
if name != funcName {
return 1
}
return 0
}
// For detection of capabilities on a system.
// Is function descriptor f a valid function?
func isValidLeFunc(f uintptr) error {
ret := funcptrtest(f, "")
if ret != 0 {
return fmt.Errorf("Bad pointer, not an LE function ")
}
return nil
}
// Retrieve function name from descriptor
func getLeFuncName(f uintptr) (string, error) {
// assume it has been checked, only check ppa1 validity here
entry := ((*[2]uintptr)(unsafe.Pointer(f)))[1]
preamp := ((*[4]uint32)(unsafe.Pointer(entry - eyecatcherOffset)))
offsetPpa1 := preamp[2]
if offsetPpa1 > 0x0ffff {
return "", fmt.Errorf("PPA1 offset seems too big 0x%x\n", offsetPpa1)
}
ppa1 := uintptr(unsafe.Pointer(preamp)) + uintptr(offsetPpa1)
res := ptrtest(ppa1)
if res != 0 {
return "", fmt.Errorf("PPA1 address not valid")
}
size := *(*uint16)(unsafe.Pointer(ppa1 + nameLenOffset))
if size > 128 {
return "", fmt.Errorf("Function name seems too long, length=%d\n", size)
}
var name [128]byte
funcname := (*[128]byte)(unsafe.Pointer(ppa1 + nameOffset))
copy(name[0:size], funcname[0:size])
runtime.CallLeFuncByPtr(runtime.XplinkLibvec+SYS___E2A_L<<4, // __e2a_l
[]uintptr{uintptr(unsafe.Pointer(&name[0])), uintptr(size)})
return string(name[:size]), nil
}
// Check z/OS version
func zosLeVersion() (version, release uint32) {
p1 := (*(*uintptr)(unsafe.Pointer(uintptr(1208)))) >> 32
p1 = *(*uintptr)(unsafe.Pointer(uintptr(p1 + 88)))
p1 = *(*uintptr)(unsafe.Pointer(uintptr(p1 + 8)))
p1 = *(*uintptr)(unsafe.Pointer(uintptr(p1 + 984)))
vrm := *(*uint32)(unsafe.Pointer(p1 + 80))
version = (vrm & 0x00ff0000) >> 16
release = (vrm & 0x0000ff00) >> 8
return
}
// returns a zos C FILE * for stdio fd 0, 1, 2
func ZosStdioFilep(fd int32) uintptr {
return uintptr(*(*uint64)(unsafe.Pointer(uintptr(*(*uint64)(unsafe.Pointer(uintptr(*(*uint64)(unsafe.Pointer(uintptr(uint64(*(*uint32)(unsafe.Pointer(uintptr(1208)))) + 80))) + uint64((fd+2)<<3))))))))
}
func copyStat(stat *Stat_t, statLE *Stat_LE_t) {
stat.Dev = uint64(statLE.Dev)
stat.Ino = uint64(statLE.Ino)
stat.Nlink = uint64(statLE.Nlink)
stat.Mode = uint32(statLE.Mode)
stat.Uid = uint32(statLE.Uid)
stat.Gid = uint32(statLE.Gid)
stat.Rdev = uint64(statLE.Rdev)
stat.Size = statLE.Size
stat.Atim.Sec = int64(statLE.Atim)
stat.Atim.Nsec = 0 //zos doesn't return nanoseconds
stat.Mtim.Sec = int64(statLE.Mtim)
stat.Mtim.Nsec = 0 //zos doesn't return nanoseconds
stat.Ctim.Sec = int64(statLE.Ctim)
stat.Ctim.Nsec = 0 //zos doesn't return nanoseconds
stat.Blksize = int64(statLE.Blksize)
stat.Blocks = statLE.Blocks
}
func svcCall(fnptr unsafe.Pointer, argv *unsafe.Pointer, dsa *uint64)
func svcLoad(name *byte) unsafe.Pointer
func svcUnload(name *byte, fnptr unsafe.Pointer) int64
func (d *Dirent) NameString() string {
if d == nil {
return ""
}
s := string(d.Name[:])
idx := strings.IndexByte(s, 0)
if idx == -1 {
return s
} else {
return s[:idx]
}
}
func DecodeData(dest []byte, sz int, val uint64) {
for i := 0; i < sz; i++ {
dest[sz-1-i] = byte((val >> (uint64(i * 8))) & 0xff)
}
}
func EncodeData(data []byte) uint64 {
var value uint64
sz := len(data)
for i := 0; i < sz; i++ {
value |= uint64(data[i]) << uint64(((sz - i - 1) * 8))
}
return value
}
func (sa *SockaddrInet4) sockaddr() (unsafe.Pointer, _Socklen, error) {
if sa.Port < 0 || sa.Port > 0xFFFF {
return nil, 0, EINVAL
}
sa.raw.Len = SizeofSockaddrInet4
sa.raw.Family = AF_INET
p := (*[2]byte)(unsafe.Pointer(&sa.raw.Port))
p[0] = byte(sa.Port >> 8)
p[1] = byte(sa.Port)
for i := 0; i < len(sa.Addr); i++ {
sa.raw.Addr[i] = sa.Addr[i]
}
return unsafe.Pointer(&sa.raw), _Socklen(sa.raw.Len), nil
}
func (sa *SockaddrInet6) sockaddr() (unsafe.Pointer, _Socklen, error) {
if sa.Port < 0 || sa.Port > 0xFFFF {
return nil, 0, EINVAL
}
sa.raw.Len = SizeofSockaddrInet6
sa.raw.Family = AF_INET6
p := (*[2]byte)(unsafe.Pointer(&sa.raw.Port))
p[0] = byte(sa.Port >> 8)
p[1] = byte(sa.Port)
sa.raw.Scope_id = sa.ZoneId
for i := 0; i < len(sa.Addr); i++ {
sa.raw.Addr[i] = sa.Addr[i]
}
return unsafe.Pointer(&sa.raw), _Socklen(sa.raw.Len), nil
}
func (sa *SockaddrUnix) sockaddr() (unsafe.Pointer, _Socklen, error) {
name := sa.Name
n := len(name)
if n >= len(sa.raw.Path) || n == 0 {
return nil, 0, EINVAL
}
sa.raw.Len = byte(3 + n) // 2 for Family, Len; 1 for NUL
sa.raw.Family = AF_UNIX
for i := 0; i < n; i++ {
sa.raw.Path[i] = int8(name[i])
}
return unsafe.Pointer(&sa.raw), _Socklen(sa.raw.Len), nil
}
func anyToSockaddr(_ int, rsa *RawSockaddrAny) (Sockaddr, error) {
// TODO(neeilan): Implement use of first param (fd)
switch rsa.Addr.Family {
case AF_UNIX:
pp := (*RawSockaddrUnix)(unsafe.Pointer(rsa))
sa := new(SockaddrUnix)
// For z/OS, only replace NUL with @ when the
// length is not zero.
if pp.Len != 0 && pp.Path[0] == 0 {
// "Abstract" Unix domain socket.
// Rewrite leading NUL as @ for textual display.
// (This is the standard convention.)
// Not friendly to overwrite in place,
// but the callers below don't care.
pp.Path[0] = '@'
}
// Assume path ends at NUL.
//
// For z/OS, the length of the name is a field
// in the structure. To be on the safe side, we
// will still scan the name for a NUL but only
// to the length provided in the structure.
//
// This is not technically the Linux semantics for
// abstract Unix domain sockets--they are supposed
// to be uninterpreted fixed-size binary blobs--but
// everyone uses this convention.
n := 0
for n < int(pp.Len) && pp.Path[n] != 0 {
n++
}
sa.Name = string(unsafe.Slice((*byte)(unsafe.Pointer(&pp.Path[0])), n))
return sa, nil
case AF_INET:
pp := (*RawSockaddrInet4)(unsafe.Pointer(rsa))
sa := new(SockaddrInet4)
p := (*[2]byte)(unsafe.Pointer(&pp.Port))
sa.Port = int(p[0])<<8 + int(p[1])
for i := 0; i < len(sa.Addr); i++ {
sa.Addr[i] = pp.Addr[i]
}
return sa, nil
case AF_INET6:
pp := (*RawSockaddrInet6)(unsafe.Pointer(rsa))
sa := new(SockaddrInet6)
p := (*[2]byte)(unsafe.Pointer(&pp.Port))
sa.Port = int(p[0])<<8 + int(p[1])
sa.ZoneId = pp.Scope_id
for i := 0; i < len(sa.Addr); i++ {
sa.Addr[i] = pp.Addr[i]
}
return sa, nil
}
return nil, EAFNOSUPPORT
}
func Accept(fd int) (nfd int, sa Sockaddr, err error) {
var rsa RawSockaddrAny
var len _Socklen = SizeofSockaddrAny
nfd, err = accept(fd, &rsa, &len)
if err != nil {
return
}
// TODO(neeilan): Remove 0 in call
sa, err = anyToSockaddr(0, &rsa)
if err != nil {
Close(nfd)
nfd = 0
}
return
}
func Accept4(fd int, flags int) (nfd int, sa Sockaddr, err error) {
var rsa RawSockaddrAny
var len _Socklen = SizeofSockaddrAny
nfd, err = accept4(fd, &rsa, &len, flags)
if err != nil {
return
}
if len > SizeofSockaddrAny {
panic("RawSockaddrAny too small")
}
// TODO(neeilan): Remove 0 in call
sa, err = anyToSockaddr(0, &rsa)
if err != nil {
Close(nfd)
nfd = 0
}
return
}
func Ctermid() (tty string, err error) {
var termdev [1025]byte
runtime.EnterSyscall()
r0, err2, err1 := CallLeFuncWithPtrReturn(GetZosLibVec()+SYS___CTERMID_A<<4, uintptr(unsafe.Pointer(&termdev[0])))
runtime.ExitSyscall()
if r0 == 0 {
return "", fmt.Errorf("%s (errno2=0x%x)\n", err1.Error(), err2)
}
s := string(termdev[:])
idx := strings.Index(s, string(rune(0)))
if idx == -1 {
tty = s
} else {
tty = s[:idx]
}
return
}
func (iov *Iovec) SetLen(length int) {
iov.Len = uint64(length)
}
func (msghdr *Msghdr) SetControllen(length int) {
msghdr.Controllen = int32(length)
}
func (cmsg *Cmsghdr) SetLen(length int) {
cmsg.Len = int32(length)
}
//sys fcntl(fd int, cmd int, arg int) (val int, err error)
//sys Flistxattr(fd int, dest []byte) (sz int, err error) = SYS___FLISTXATTR_A
//sys Fremovexattr(fd int, attr string) (err error) = SYS___FREMOVEXATTR_A
//sys read(fd int, p []byte) (n int, err error)
//sys write(fd int, p []byte) (n int, err error)
//sys Fgetxattr(fd int, attr string, dest []byte) (sz int, err error) = SYS___FGETXATTR_A
//sys Fsetxattr(fd int, attr string, data []byte, flag int) (err error) = SYS___FSETXATTR_A
//sys accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error) = SYS___ACCEPT_A
//sys accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error) = SYS___ACCEPT4_A
//sys bind(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) = SYS___BIND_A
//sys connect(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) = SYS___CONNECT_A
//sysnb getgroups(n int, list *_Gid_t) (nn int, err error)
//sysnb setgroups(n int, list *_Gid_t) (err error)
//sys getsockopt(s int, level int, name int, val unsafe.Pointer, vallen *_Socklen) (err error)
//sys setsockopt(s int, level int, name int, val unsafe.Pointer, vallen uintptr) (err error)
//sysnb socket(domain int, typ int, proto int) (fd int, err error)
//sysnb socketpair(domain int, typ int, proto int, fd *[2]int32) (err error)
//sysnb getpeername(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error) = SYS___GETPEERNAME_A
//sysnb getsockname(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error) = SYS___GETSOCKNAME_A
//sys Removexattr(path string, attr string) (err error) = SYS___REMOVEXATTR_A
//sys recvfrom(fd int, p []byte, flags int, from *RawSockaddrAny, fromlen *_Socklen) (n int, err error) = SYS___RECVFROM_A
//sys sendto(s int, buf []byte, flags int, to unsafe.Pointer, addrlen _Socklen) (err error) = SYS___SENDTO_A
//sys recvmsg(s int, msg *Msghdr, flags int) (n int, err error) = SYS___RECVMSG_A
//sys sendmsg(s int, msg *Msghdr, flags int) (n int, err error) = SYS___SENDMSG_A
//sys mmap(addr uintptr, length uintptr, prot int, flag int, fd int, pos int64) (ret uintptr, err error) = SYS_MMAP
//sys munmap(addr uintptr, length uintptr) (err error) = SYS_MUNMAP
//sys ioctl(fd int, req int, arg uintptr) (err error) = SYS_IOCTL
//sys ioctlPtr(fd int, req int, arg unsafe.Pointer) (err error) = SYS_IOCTL
//sys shmat(id int, addr uintptr, flag int) (ret uintptr, err error) = SYS_SHMAT
//sys shmctl(id int, cmd int, buf *SysvShmDesc) (result int, err error) = SYS_SHMCTL64
//sys shmdt(addr uintptr) (err error) = SYS_SHMDT
//sys shmget(key int, size int, flag int) (id int, err error) = SYS_SHMGET
//sys Access(path string, mode uint32) (err error) = SYS___ACCESS_A
//sys Chdir(path string) (err error) = SYS___CHDIR_A
//sys Chown(path string, uid int, gid int) (err error) = SYS___CHOWN_A
//sys Chmod(path string, mode uint32) (err error) = SYS___CHMOD_A
//sys Creat(path string, mode uint32) (fd int, err error) = SYS___CREAT_A
//sys Dup(oldfd int) (fd int, err error)
//sys Dup2(oldfd int, newfd int) (err error)
//sys Dup3(oldfd int, newfd int, flags int) (err error) = SYS_DUP3
//sys Dirfd(dirp uintptr) (fd int, err error) = SYS_DIRFD
//sys EpollCreate(size int) (fd int, err error) = SYS_EPOLL_CREATE
//sys EpollCreate1(flags int) (fd int, err error) = SYS_EPOLL_CREATE1
//sys EpollCtl(epfd int, op int, fd int, event *EpollEvent) (err error) = SYS_EPOLL_CTL
//sys EpollPwait(epfd int, events []EpollEvent, msec int, sigmask *int) (n int, err error) = SYS_EPOLL_PWAIT
//sys EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error) = SYS_EPOLL_WAIT
//sys Errno2() (er2 int) = SYS___ERRNO2
//sys Eventfd(initval uint, flags int) (fd int, err error) = SYS_EVENTFD
//sys Exit(code int)
//sys Faccessat(dirfd int, path string, mode uint32, flags int) (err error) = SYS___FACCESSAT_A
func Faccessat2(dirfd int, path string, mode uint32, flags int) (err error) {
return Faccessat(dirfd, path, mode, flags)
}
//sys Fchdir(fd int) (err error)
//sys Fchmod(fd int, mode uint32) (err error)
//sys Fchmodat(dirfd int, path string, mode uint32, flags int) (err error) = SYS___FCHMODAT_A
//sys Fchown(fd int, uid int, gid int) (err error)
//sys Fchownat(fd int, path string, uid int, gid int, flags int) (err error) = SYS___FCHOWNAT_A
//sys FcntlInt(fd uintptr, cmd int, arg int) (retval int, err error) = SYS_FCNTL
//sys Fdatasync(fd int) (err error) = SYS_FDATASYNC
//sys fstat(fd int, stat *Stat_LE_t) (err error)
//sys fstatat(dirfd int, path string, stat *Stat_LE_t, flags int) (err error) = SYS___FSTATAT_A
func Fstat(fd int, stat *Stat_t) (err error) {
var statLE Stat_LE_t
err = fstat(fd, &statLE)
copyStat(stat, &statLE)
return
}
func Fstatat(dirfd int, path string, stat *Stat_t, flags int) (err error) {
var statLE Stat_LE_t
err = fstatat(dirfd, path, &statLE, flags)
copyStat(stat, &statLE)
return
}
func impl_Getxattr(path string, attr string, dest []byte) (sz int, err error) {
var _p0 *byte
_p0, err = BytePtrFromString(path)
if err != nil {
return
}
var _p1 *byte
_p1, err = BytePtrFromString(attr)
if err != nil {
return
}
var _p2 unsafe.Pointer
if len(dest) > 0 {
_p2 = unsafe.Pointer(&dest[0])
} else {
_p2 = unsafe.Pointer(&_zero)
}
r0, e2, e1 := CallLeFuncWithErr(GetZosLibVec()+SYS___GETXATTR_A<<4, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), uintptr(_p2), uintptr(len(dest)))
sz = int(r0)
if int64(r0) == -1 {
err = errnoErr2(e1, e2)
}
return
}
//go:nosplit
func get_GetxattrAddr() *(func(path string, attr string, dest []byte) (sz int, err error))
var Getxattr = enter_Getxattr
func enter_Getxattr(path string, attr string, dest []byte) (sz int, err error) {
funcref := get_GetxattrAddr()
if validGetxattr() {
*funcref = impl_Getxattr
} else {
*funcref = error_Getxattr
}
return (*funcref)(path, attr, dest)
}
func error_Getxattr(path string, attr string, dest []byte) (sz int, err error) {
return -1, ENOSYS
}
func validGetxattr() bool {
if funcptrtest(GetZosLibVec()+SYS___GETXATTR_A<<4, "") == 0 {
if name, err := getLeFuncName(GetZosLibVec() + SYS___GETXATTR_A<<4); err == nil {
return name == "__getxattr_a"
}
}
return false
}
//sys Lgetxattr(link string, attr string, dest []byte) (sz int, err error) = SYS___LGETXATTR_A
//sys Lsetxattr(path string, attr string, data []byte, flags int) (err error) = SYS___LSETXATTR_A
func impl_Setxattr(path string, attr string, data []byte, flags int) (err error) {
var _p0 *byte
_p0, err = BytePtrFromString(path)
if err != nil {
return
}
var _p1 *byte
_p1, err = BytePtrFromString(attr)
if err != nil {
return
}
var _p2 unsafe.Pointer
if len(data) > 0 {
_p2 = unsafe.Pointer(&data[0])
} else {
_p2 = unsafe.Pointer(&_zero)
}
r0, e2, e1 := CallLeFuncWithErr(GetZosLibVec()+SYS___SETXATTR_A<<4, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), uintptr(_p2), uintptr(len(data)), uintptr(flags))
if int64(r0) == -1 {
err = errnoErr2(e1, e2)
}
return
}
//go:nosplit
func get_SetxattrAddr() *(func(path string, attr string, data []byte, flags int) (err error))
var Setxattr = enter_Setxattr
func enter_Setxattr(path string, attr string, data []byte, flags int) (err error) {
funcref := get_SetxattrAddr()
if validSetxattr() {
*funcref = impl_Setxattr
} else {
*funcref = error_Setxattr
}
return (*funcref)(path, attr, data, flags)
}
func error_Setxattr(path string, attr string, data []byte, flags int) (err error) {
return ENOSYS
}
func validSetxattr() bool {
if funcptrtest(GetZosLibVec()+SYS___SETXATTR_A<<4, "") == 0 {
if name, err := getLeFuncName(GetZosLibVec() + SYS___SETXATTR_A<<4); err == nil {
return name == "__setxattr_a"
}
}
return false
}
//sys Fstatfs(fd int, buf *Statfs_t) (err error) = SYS_FSTATFS
//sys Fstatvfs(fd int, stat *Statvfs_t) (err error) = SYS_FSTATVFS
//sys Fsync(fd int) (err error)
//sys Futimes(fd int, tv []Timeval) (err error) = SYS_FUTIMES
//sys Futimesat(dirfd int, path string, tv []Timeval) (err error) = SYS___FUTIMESAT_A
//sys Ftruncate(fd int, length int64) (err error)
//sys Getrandom(buf []byte, flags int) (n int, err error) = SYS_GETRANDOM
//sys InotifyInit() (fd int, err error) = SYS_INOTIFY_INIT
//sys InotifyInit1(flags int) (fd int, err error) = SYS_INOTIFY_INIT1
//sys InotifyAddWatch(fd int, pathname string, mask uint32) (watchdesc int, err error) = SYS___INOTIFY_ADD_WATCH_A
//sys InotifyRmWatch(fd int, watchdesc uint32) (success int, err error) = SYS_INOTIFY_RM_WATCH
//sys Listxattr(path string, dest []byte) (sz int, err error) = SYS___LISTXATTR_A
//sys Llistxattr(path string, dest []byte) (sz int, err error) = SYS___LLISTXATTR_A
//sys Lremovexattr(path string, attr string) (err error) = SYS___LREMOVEXATTR_A
//sys Lutimes(path string, tv []Timeval) (err error) = SYS___LUTIMES_A
//sys Mprotect(b []byte, prot int) (err error) = SYS_MPROTECT
//sys Msync(b []byte, flags int) (err error) = SYS_MSYNC
//sys Console2(cmsg *ConsMsg2, modstr *byte, concmd *uint32) (err error) = SYS___CONSOLE2
// Pipe2 begin
//go:nosplit
func getPipe2Addr() *(func([]int, int) error)
var Pipe2 = pipe2Enter
func pipe2Enter(p []int, flags int) (err error) {
if funcptrtest(GetZosLibVec()+SYS_PIPE2<<4, "") == 0 {
*getPipe2Addr() = pipe2Impl
} else {
*getPipe2Addr() = pipe2Error
}
return (*getPipe2Addr())(p, flags)
}
func pipe2Impl(p []int, flags int) (err error) {
var pp [2]_C_int
r0, e2, e1 := CallLeFuncWithErr(GetZosLibVec()+SYS_PIPE2<<4, uintptr(unsafe.Pointer(&pp[0])), uintptr(flags))
if int64(r0) == -1 {
err = errnoErr2(e1, e2)
} else {
p[0] = int(pp[0])
p[1] = int(pp[1])
}
return
}
func pipe2Error(p []int, flags int) (err error) {
return fmt.Errorf("Pipe2 is not available on this system")
}
// Pipe2 end
//sys Poll(fds []PollFd, timeout int) (n int, err error) = SYS_POLL
func Readdir(dir uintptr) (dirent *Dirent, err error) {
runtime.EnterSyscall()
r0, e2, e1 := CallLeFuncWithErr(GetZosLibVec()+SYS___READDIR_A<<4, uintptr(dir))
runtime.ExitSyscall()
dirent = (*Dirent)(unsafe.Pointer(r0))
if int64(r0) == -1 {
err = errnoErr2(e1, e2)
}
return
}
//sys Readdir_r(dirp uintptr, entry *direntLE, result **direntLE) (err error) = SYS___READDIR_R_A
//sys Statfs(path string, buf *Statfs_t) (err error) = SYS___STATFS_A
//sys Syncfs(fd int) (err error) = SYS_SYNCFS
//sys Times(tms *Tms) (ticks uintptr, err error) = SYS_TIMES
//sys W_Getmntent(buff *byte, size int) (lastsys int, err error) = SYS_W_GETMNTENT
//sys W_Getmntent_A(buff *byte, size int) (lastsys int, err error) = SYS___W_GETMNTENT_A
//sys mount_LE(path string, filesystem string, fstype string, mtm uint32, parmlen int32, parm string) (err error) = SYS___MOUNT_A
//sys unmount_LE(filesystem string, mtm int) (err error) = SYS___UMOUNT_A
//sys Chroot(path string) (err error) = SYS___CHROOT_A
//sys Select(nmsgsfds int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (ret int, err error) = SYS_SELECT
//sysnb Uname(buf *Utsname) (err error) = SYS_____OSNAME_A
//sys Unshare(flags int) (err error) = SYS_UNSHARE
func Ptsname(fd int) (name string, err error) {
runtime.EnterSyscall()
r0, e2, e1 := CallLeFuncWithPtrReturn(GetZosLibVec()+SYS___PTSNAME_A<<4, uintptr(fd))
runtime.ExitSyscall()
if r0 == 0 {
err = errnoErr2(e1, e2)
} else {
name = u2s(unsafe.Pointer(r0))
}
return
}
func u2s(cstr unsafe.Pointer) string {
str := (*[1024]uint8)(cstr)
i := 0
for str[i] != 0 {
i++
}
return string(str[:i])
}
func Close(fd int) (err error) {
runtime.EnterSyscall()
r0, e2, e1 := CallLeFuncWithErr(GetZosLibVec()+SYS_CLOSE<<4, uintptr(fd))
runtime.ExitSyscall()
for i := 0; e1 == EAGAIN && i < 10; i++ {
runtime.EnterSyscall()
CallLeFuncWithErr(GetZosLibVec()+SYS_USLEEP<<4, uintptr(10))
runtime.ExitSyscall()
runtime.EnterSyscall()
r0, e2, e1 = CallLeFuncWithErr(GetZosLibVec()+SYS_CLOSE<<4, uintptr(fd))
runtime.ExitSyscall()
}
if r0 != 0 {
err = errnoErr2(e1, e2)
}
return
}
// Dummy function: there are no semantics for Madvise on z/OS
func Madvise(b []byte, advice int) (err error) {
return
}
func Mmap(fd int, offset int64, length int, prot int, flags int) (data []byte, err error) {
return mapper.Mmap(fd, offset, length, prot, flags)
}
func Munmap(b []byte) (err error) {
return mapper.Munmap(b)
}
func MmapPtr(fd int, offset int64, addr unsafe.Pointer, length uintptr, prot int, flags int) (ret unsafe.Pointer, err error) {
xaddr, err := mapper.mmap(uintptr(addr), length, prot, flags, fd, offset)
return unsafe.Pointer(xaddr), err
}
func MunmapPtr(addr unsafe.Pointer, length uintptr) (err error) {
return mapper.munmap(uintptr(addr), length)
}
//sys Gethostname(buf []byte) (err error) = SYS___GETHOSTNAME_A
//sysnb Getgid() (gid int)
//sysnb Getpid() (pid int)
//sysnb Getpgid(pid int) (pgid int, err error) = SYS_GETPGID
func Getpgrp() (pid int) {
pid, _ = Getpgid(0)
return
}
//sysnb Getppid() (pid int)
//sys Getpriority(which int, who int) (prio int, err error)
//sysnb Getrlimit(resource int, rlim *Rlimit) (err error) = SYS_GETRLIMIT
//sysnb getrusage(who int, rusage *rusage_zos) (err error) = SYS_GETRUSAGE
func Getrusage(who int, rusage *Rusage) (err error) {
var ruz rusage_zos
err = getrusage(who, &ruz)
//Only the first two fields of Rusage are set
rusage.Utime.Sec = ruz.Utime.Sec
rusage.Utime.Usec = int64(ruz.Utime.Usec)
rusage.Stime.Sec = ruz.Stime.Sec
rusage.Stime.Usec = int64(ruz.Stime.Usec)
return
}
//sys Getegid() (egid int) = SYS_GETEGID
//sys Geteuid() (euid int) = SYS_GETEUID
//sysnb Getsid(pid int) (sid int, err error) = SYS_GETSID
//sysnb Getuid() (uid int)
//sysnb Kill(pid int, sig Signal) (err error)
//sys Lchown(path string, uid int, gid int) (err error) = SYS___LCHOWN_A
//sys Link(path string, link string) (err error) = SYS___LINK_A
//sys Linkat(oldDirFd int, oldPath string, newDirFd int, newPath string, flags int) (err error) = SYS___LINKAT_A
//sys Listen(s int, n int) (err error)
//sys lstat(path string, stat *Stat_LE_t) (err error) = SYS___LSTAT_A
func Lstat(path string, stat *Stat_t) (err error) {
var statLE Stat_LE_t
err = lstat(path, &statLE)
copyStat(stat, &statLE)
return
}
// for checking symlinks begins with $VERSION/ $SYSNAME/ $SYSSYMR/ $SYSSYMA/
func isSpecialPath(path []byte) (v bool) {
var special = [4][8]byte{
{'V', 'E', 'R', 'S', 'I', 'O', 'N', '/'},
{'S', 'Y', 'S', 'N', 'A', 'M', 'E', '/'},
{'S', 'Y', 'S', 'S', 'Y', 'M', 'R', '/'},
{'S', 'Y', 'S', 'S', 'Y', 'M', 'A', '/'}}
var i, j int
for i = 0; i < len(special); i++ {
for j = 0; j < len(special[i]); j++ {
if path[j] != special[i][j] {
break
}
}
if j == len(special[i]) {
return true
}
}
return false
}
func realpath(srcpath string, abspath []byte) (pathlen int, errno int) {
var source [1024]byte
copy(source[:], srcpath)
source[len(srcpath)] = 0
ret := runtime.CallLeFuncByPtr(runtime.XplinkLibvec+SYS___REALPATH_A<<4, //__realpath_a()
[]uintptr{uintptr(unsafe.Pointer(&source[0])),
uintptr(unsafe.Pointer(&abspath[0]))})
if ret != 0 {
index := bytes.IndexByte(abspath[:], byte(0))
if index != -1 {
return index, 0
}
} else {
errptr := (*int)(unsafe.Pointer(runtime.CallLeFuncByPtr(runtime.XplinkLibvec+SYS___ERRNO<<4, []uintptr{}))) //__errno()
return 0, *errptr
}
return 0, 245 // EBADDATA 245
}
func Readlink(path string, buf []byte) (n int, err error) {
var _p0 *byte
_p0, err = BytePtrFromString(path)
if err != nil {
return
}
var _p1 unsafe.Pointer
if len(buf) > 0 {
_p1 = unsafe.Pointer(&buf[0])
} else {
_p1 = unsafe.Pointer(&_zero)
}
n = int(runtime.CallLeFuncByPtr(runtime.XplinkLibvec+SYS___READLINK_A<<4,
[]uintptr{uintptr(unsafe.Pointer(_p0)), uintptr(_p1), uintptr(len(buf))}))
runtime.KeepAlive(unsafe.Pointer(_p0))
if n == -1 {
value := *(*int32)(unsafe.Pointer(runtime.CallLeFuncByPtr(runtime.XplinkLibvec+SYS___ERRNO<<4, []uintptr{})))
err = errnoErr(Errno(value))
} else {
if buf[0] == '$' {
if isSpecialPath(buf[1:9]) {
cnt, err1 := realpath(path, buf)
if err1 == 0 {
n = cnt
}
}
}
}
return
}
func impl_Readlinkat(dirfd int, path string, buf []byte) (n int, err error) {
var _p0 *byte
_p0, err = BytePtrFromString(path)
if err != nil {
return
}
var _p1 unsafe.Pointer
if len(buf) > 0 {
_p1 = unsafe.Pointer(&buf[0])
} else {
_p1 = unsafe.Pointer(&_zero)
}
runtime.EnterSyscall()
r0, e2, e1 := CallLeFuncWithErr(GetZosLibVec()+SYS___READLINKAT_A<<4, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(_p1), uintptr(len(buf)))
runtime.ExitSyscall()
n = int(r0)
if int64(r0) == -1 {
err = errnoErr2(e1, e2)
return n, err
} else {
if buf[0] == '$' {
if isSpecialPath(buf[1:9]) {
cnt, err1 := realpath(path, buf)
if err1 == 0 {
n = cnt
}
}
}
}
return
}
//go:nosplit
func get_ReadlinkatAddr() *(func(dirfd int, path string, buf []byte) (n int, err error))
var Readlinkat = enter_Readlinkat
func enter_Readlinkat(dirfd int, path string, buf []byte) (n int, err error) {
funcref := get_ReadlinkatAddr()
if funcptrtest(GetZosLibVec()+SYS___READLINKAT_A<<4, "") == 0 {
*funcref = impl_Readlinkat
} else {
*funcref = error_Readlinkat
}
return (*funcref)(dirfd, path, buf)
}
func error_Readlinkat(dirfd int, path string, buf []byte) (n int, err error) {
n = -1
err = ENOSYS
return
}
//sys Mkdir(path string, mode uint32) (err error) = SYS___MKDIR_A
//sys Mkdirat(dirfd int, path string, mode uint32) (err error) = SYS___MKDIRAT_A
//sys Mkfifo(path string, mode uint32) (err error) = SYS___MKFIFO_A
//sys Mknod(path string, mode uint32, dev int) (err error) = SYS___MKNOD_A
//sys Mknodat(dirfd int, path string, mode uint32, dev int) (err error) = SYS___MKNODAT_A
//sys PivotRoot(newroot string, oldroot string) (err error) = SYS___PIVOT_ROOT_A
//sys Pread(fd int, p []byte, offset int64) (n int, err error)
//sys Pwrite(fd int, p []byte, offset int64) (n int, err error)
//sys Prctl(option int, arg2 uintptr, arg3 uintptr, arg4 uintptr, arg5 uintptr) (err error) = SYS___PRCTL_A
//sysnb Prlimit(pid int, resource int, newlimit *Rlimit, old *Rlimit) (err error) = SYS_PRLIMIT
//sys Rename(from string, to string) (err error) = SYS___RENAME_A
//sys Renameat(olddirfd int, oldpath string, newdirfd int, newpath string) (err error) = SYS___RENAMEAT_A
//sys Renameat2(olddirfd int, oldpath string, newdirfd int, newpath string, flags uint) (err error) = SYS___RENAMEAT2_A
//sys Rmdir(path string) (err error) = SYS___RMDIR_A
//sys Seek(fd int, offset int64, whence int) (off int64, err error) = SYS_LSEEK
//sys Setegid(egid int) (err error) = SYS_SETEGID
//sys Seteuid(euid int) (err error) = SYS_SETEUID
//sys Sethostname(p []byte) (err error) = SYS___SETHOSTNAME_A
//sys Setns(fd int, nstype int) (err error) = SYS_SETNS
//sys Setpriority(which int, who int, prio int) (err error)
//sysnb Setpgid(pid int, pgid int) (err error) = SYS_SETPGID
//sysnb Setrlimit(resource int, lim *Rlimit) (err error)
//sysnb Setregid(rgid int, egid int) (err error) = SYS_SETREGID
//sysnb Setreuid(ruid int, euid int) (err error) = SYS_SETREUID
//sysnb Setsid() (pid int, err error) = SYS_SETSID
//sys Setuid(uid int) (err error) = SYS_SETUID
//sys Setgid(uid int) (err error) = SYS_SETGID
//sys Shutdown(fd int, how int) (err error)
//sys stat(path string, statLE *Stat_LE_t) (err error) = SYS___STAT_A
func Stat(path string, sta *Stat_t) (err error) {
var statLE Stat_LE_t
err = stat(path, &statLE)
copyStat(sta, &statLE)
return
}
//sys Symlink(path string, link string) (err error) = SYS___SYMLINK_A
//sys Symlinkat(oldPath string, dirfd int, newPath string) (err error) = SYS___SYMLINKAT_A
//sys Sync() = SYS_SYNC
//sys Truncate(path string, length int64) (err error) = SYS___TRUNCATE_A
//sys Tcgetattr(fildes int, termptr *Termios) (err error) = SYS_TCGETATTR
//sys Tcsetattr(fildes int, when int, termptr *Termios) (err error) = SYS_TCSETATTR
//sys Umask(mask int) (oldmask int)
//sys Unlink(path string) (err error) = SYS___UNLINK_A
//sys Unlinkat(dirfd int, path string, flags int) (err error) = SYS___UNLINKAT_A
//sys Utime(path string, utim *Utimbuf) (err error) = SYS___UTIME_A
//sys open(path string, mode int, perm uint32) (fd int, err error) = SYS___OPEN_A
func Open(path string, mode int, perm uint32) (fd int, err error) {