@@ -163,6 +163,14 @@ func (l *LinuxOS) PollOpen(fd int, desc syscallabi.ValueView[syscallabi.PollDesc
163
163
return 0
164
164
}
165
165
166
+ func (customSyscallLogger ) LogEntryPollOpen (fd int , desc * syscallabi.PollDesc , syscall * syscallabi.Syscall ) {
167
+ // logSyscallEntry("PollOpen", syscall, "fd", fd)
168
+ }
169
+
170
+ func (customSyscallLogger ) LogExitPollOpen (fd int , desc * syscallabi.PollDesc , syscall * syscallabi.Syscall , code int ) {
171
+ // logSyscallExit("PollOpen", syscall, "code", code)
172
+ }
173
+
166
174
func (l * LinuxOS ) PollClose (fd int , desc syscallabi.ValueView [syscallabi.PollDesc ], invocation * syscallabi.Syscall ) int {
167
175
l .mu .Lock ()
168
176
defer l .mu .Unlock ()
@@ -183,6 +191,14 @@ func (l *LinuxOS) PollClose(fd int, desc syscallabi.ValueView[syscallabi.PollDes
183
191
return 0
184
192
}
185
193
194
+ func (customSyscallLogger ) LogEntryPollClose (fd int , desc * syscallabi.PollDesc , syscall * syscallabi.Syscall ) {
195
+ // logSyscallEntry("PollClose", syscall, "fd", fd)
196
+ }
197
+
198
+ func (customSyscallLogger ) LogExitPollClose (fd int , desc * syscallabi.PollDesc , syscall * syscallabi.Syscall , code int ) {
199
+ // logSyscallExit("PollClose", syscall, "code", code)
200
+ }
201
+
186
202
type (
187
203
RawSockaddrAny = syscall.RawSockaddrAny
188
204
Utsname = syscall.Utsname
@@ -265,9 +281,6 @@ func (l *LinuxOS) SysOpenat(dirfd int, path string, flags int, mode uint32, invo
265
281
// just get rid of this
266
282
flags &= ^ syscall .O_CLOEXEC
267
283
268
- // logf("openat %d %s %d %d", dirfd, path, flags, mode)
269
- // l.logfFor(invocation, "openat %d %s %d %d", dirfd, path, flags, mode)
270
-
271
284
// TODO: some rules about paths; component length; total length; allow characters?
272
285
// TODO: check mode
273
286
@@ -462,13 +475,52 @@ func (l *LinuxOS) SysGetdents64(fd int, data syscallabi.ByteSliceView, invocatio
462
475
retn += reclen
463
476
}
464
477
465
- l .logfFor (invocation , "getdents64 %d %d" , fd , data .Len () /*, data*/ )
466
-
467
478
f .didReaddir = true
468
479
469
480
return retn , nil
470
481
}
471
482
483
+ func (customSyscallLogger ) LogEntrySysGetdents64 (fd int , buf []byte , syscall * syscallabi.Syscall ) {
484
+ logSyscallEntry ("SysGetdents64" , syscall , "fd" , fd , "len(buf)" , len (buf ))
485
+ }
486
+
487
+ type Dentry struct {
488
+ Inode uint64
489
+ Offset uint64
490
+ Reclen uint16
491
+ Type string
492
+ Name string
493
+ }
494
+
495
+ var dtType = & gosimlog.BitflagFormatter {
496
+ Choices : []gosimlog.BitflagChoice {
497
+ {
498
+ Mask : 0xf ,
499
+ Values : map [int ]string {
500
+ syscall .DT_REG : "DT_REG" ,
501
+ syscall .DT_DIR : "DT_DIR" ,
502
+ },
503
+ },
504
+ },
505
+ }
506
+
507
+ func (customSyscallLogger ) LogExitSysGetdents64 (fd int , buf []byte , syscall * syscallabi.Syscall , n int , err error ) {
508
+ var entries []* Dentry
509
+ buf = buf [:n ]
510
+ for len (buf ) > 19 {
511
+ var entry Dentry
512
+ entry .Inode = binary .LittleEndian .Uint64 (buf [0 :8 ])
513
+ entry .Offset = binary .LittleEndian .Uint64 (buf [8 :16 ])
514
+ entry .Reclen = binary .LittleEndian .Uint16 (buf [16 :18 ])
515
+ entry .Type = dtType .Format (int (buf [18 ]))
516
+ nameLen := entry .Reclen - 19 - 1
517
+ entry .Name = string (buf [19 : 19 + nameLen ])
518
+ entries = append (entries , & entry )
519
+ buf = buf [entry .Reclen :]
520
+ }
521
+ logSyscallExit ("SysGetdents64" , syscall , "n" , n , "err" , err , "entries" , entries )
522
+ }
523
+
472
524
func (l * LinuxOS ) SysWrite (fd int , data syscallabi.ByteSliceView , invocation * syscallabi.Syscall ) (int , error ) {
473
525
l .mu .Lock ()
474
526
defer l .mu .Unlock ()
@@ -513,7 +565,6 @@ func (l *LinuxOS) SysWrite(fd int, data syscallabi.ByteSliceView, invocation *sy
513
565
retn := l .machine .filesystem .Write (f .inode , f .pos , data )
514
566
f .pos += int64 (retn )
515
567
516
- l .logfFor (invocation , "write %d %d %q" , fd , data .Len (), data )
517
568
return retn , nil
518
569
519
570
case * Socket :
@@ -532,14 +583,22 @@ func (l *LinuxOS) SysWrite(fd int, data syscallabi.ByteSliceView, invocation *sy
532
583
return retn , syscall .EBADFD
533
584
}
534
585
535
- l .logfFor (invocation , "write %d %d %q" , fd , data .Len (), data )
536
586
return retn , nil
537
587
538
588
default :
539
589
return 0 , syscall .EBADFD
540
590
}
541
591
}
542
592
593
+ func (customSyscallLogger ) LogEntrySysWrite (fd int , p []byte , syscall * syscallabi.Syscall ) {
594
+ // TODO: format these []byte attrs nicer: handle both ascii and binary gracefully
595
+ logSyscallEntry ("SysWrite" , syscall , "fd" , fd , "p" , string (p ))
596
+ }
597
+
598
+ func (customSyscallLogger ) LogExitSysWrite (fd int , p []byte , syscall * syscallabi.Syscall , n int , err error ) {
599
+ logSyscallExit ("SysWrite" , syscall , "n" , n , "err" , err )
600
+ }
601
+
543
602
func (l * LinuxOS ) SysRead (fd int , data syscallabi.ByteSliceView , invocation * syscallabi.Syscall ) (int , error ) {
544
603
l .mu .Lock ()
545
604
defer l .mu .Unlock ()
@@ -561,8 +620,6 @@ func (l *LinuxOS) SysRead(fd int, data syscallabi.ByteSliceView, invocation *sys
561
620
retn := l .machine .filesystem .Read (f .inode , f .pos , data )
562
621
f .pos += int64 (retn )
563
622
564
- l .logfFor (invocation , "read %d %d" , fd , data .Len () /*, data[:retn]*/ )
565
-
566
623
return retn , nil
567
624
568
625
case * Socket :
@@ -581,15 +638,21 @@ func (l *LinuxOS) SysRead(fd int, data syscallabi.ByteSliceView, invocation *sys
581
638
return 0 , syscall .EBADFD
582
639
}
583
640
584
- l .logfFor (invocation , "read %d %d" , fd , data .Len () /*, data[:retn]*/ )
585
-
586
641
return retn , nil
587
642
588
643
default :
589
644
return 0 , syscall .EBADFD
590
645
}
591
646
}
592
647
648
+ func (customSyscallLogger ) LogEntrySysRead (fd int , p []byte , syscall * syscallabi.Syscall ) {
649
+ logSyscallEntry ("SysRead" , syscall , "fd" , fd , "len(p)" , len (p ))
650
+ }
651
+
652
+ func (customSyscallLogger ) LogExitSysRead (fd int , p []byte , syscall * syscallabi.Syscall , n int , err error ) {
653
+ logSyscallExit ("SysRead" , syscall , "n" , n , "err" , err , "p[:n]" , string (p [:n ]))
654
+ }
655
+
593
656
func (l * LinuxOS ) SysFallocate (fd int , mode uint32 , off int64 , len int64 , invocation * syscallabi.Syscall ) (err error ) {
594
657
l .mu .Lock ()
595
658
defer l .mu .Unlock ()
@@ -723,6 +786,14 @@ func (l *LinuxOS) SysPwrite64(fd int, data syscallabi.ByteSliceView, offset int6
723
786
return retn , nil
724
787
}
725
788
789
+ func (customSyscallLogger ) LogEntrySysPwrite64 (fd int , p []byte , offset int64 , syscall * syscallabi.Syscall ) {
790
+ logSyscallEntry ("SysPwrite64" , syscall , "fd" , fd , "offset" , offset , "p" , string (p ))
791
+ }
792
+
793
+ func (customSyscallLogger ) LogExitSysPwrite64 (fd int , p []byte , offset int64 , syscall * syscallabi.Syscall , n int , err error ) {
794
+ logSyscallExit ("SysPwrite64" , syscall , "n" , n , "err" , err )
795
+ }
796
+
726
797
func (l * LinuxOS ) SysPread64 (fd int , data syscallabi.ByteSliceView , offset int64 , invocation * syscallabi.Syscall ) (int , error ) {
727
798
l .mu .Lock ()
728
799
defer l .mu .Unlock ()
@@ -751,6 +822,14 @@ func (l *LinuxOS) SysPread64(fd int, data syscallabi.ByteSliceView, offset int64
751
822
return retn , nil
752
823
}
753
824
825
+ func (customSyscallLogger ) LogEntrySysPread64 (fd int , p []byte , offset int64 , syscall * syscallabi.Syscall ) {
826
+ logSyscallEntry ("SysPread64" , syscall , "fd" , fd , "offset" , offset , "len(p)" , len (p ))
827
+ }
828
+
829
+ func (customSyscallLogger ) LogExitSysPread64 (fd int , p []byte , offset int64 , syscall * syscallabi.Syscall , n int , err error ) {
830
+ logSyscallExit ("SysPread64" , syscall , "n" , n , "err" , err , "p[:n]" , string (p [:n ]))
831
+ }
832
+
754
833
func (l * LinuxOS ) SysFsync (fd int , invocation * syscallabi.Syscall ) error {
755
834
// XXX: janky way to crash on sync
756
835
l .machine .sometimesCrashOnSyncMu .Lock ()
@@ -1491,8 +1570,6 @@ func (l *LinuxOS) SysGetpeername(fd int, rsa syscallabi.ValueView[RawSockaddrAny
1491
1570
return syscall .EINVAL
1492
1571
}
1493
1572
1494
- l .logfFor (invocation , "getpeername %d %d" , fd , len .Get ())
1495
-
1496
1573
fdInternal , ok := l .files [fd ]
1497
1574
if ! ok {
1498
1575
return syscall .EBADFD
@@ -1514,6 +1591,14 @@ func (l *LinuxOS) SysGetpeername(fd int, rsa syscallabi.ValueView[RawSockaddrAny
1514
1591
return nil
1515
1592
}
1516
1593
1594
+ func (customSyscallLogger ) LogEntrySysGetpeername (fd int , rsa * RawSockaddrAny , addrlen * Socklen , syscall * syscallabi.Syscall ) {
1595
+ logSyscallEntry ("SysGetpeername" , syscall , "fd" , fd )
1596
+ }
1597
+
1598
+ func (customSyscallLogger ) LogExitSysGetpeername (fd int , rsa * RawSockaddrAny , addrlen * Socklen , syscall * syscallabi.Syscall , err error ) {
1599
+ logSyscallExit ("SysGetpeername" , syscall , addrAttr (unsafe .Pointer (rsa ), * addrlen ), "err" , err )
1600
+ }
1601
+
1517
1602
func (l * LinuxOS ) SysFcntl (fd int , cmd int , arg int , invocation * syscallabi.Syscall ) (val int , err error ) {
1518
1603
l .mu .Lock ()
1519
1604
defer l .mu .Unlock ()
@@ -1622,6 +1707,14 @@ func (l *LinuxOS) SysGetpid(invocation *syscallabi.Syscall) int {
1622
1707
return 42
1623
1708
}
1624
1709
1710
+ func (customSyscallLogger ) LogEntrySysGetpid (syscall * syscallabi.Syscall ) {
1711
+ logSyscallEntry ("SysGetpid" , syscall )
1712
+ }
1713
+
1714
+ func (customSyscallLogger ) LogExitSysGetpid (syscall * syscallabi.Syscall , pid int ) {
1715
+ logSyscallExit ("SysGetpid" , syscall , "pid" , pid )
1716
+ }
1717
+
1625
1718
func (l * LinuxOS ) SysUname (buf syscallabi.ValueView [Utsname ], invocation * syscallabi.Syscall ) (err error ) {
1626
1719
ptr := (* Utsname )(buf .UnsafePointer ())
1627
1720
name := syscallabi .NewSliceView (& ptr .Nodename [0 ], uintptr (len (ptr .Nodename )))
@@ -1635,6 +1728,29 @@ func (l *LinuxOS) SysUname(buf syscallabi.ValueView[Utsname], invocation *syscal
1635
1728
return nil
1636
1729
}
1637
1730
1731
+ func int8ArrayToString (key string , value []int8 ) slog.Attr {
1732
+ n := 0
1733
+ for i , c := range value {
1734
+ if c == 0 {
1735
+ n = i
1736
+ break
1737
+ }
1738
+ }
1739
+ b := make ([]byte , n )
1740
+ for i := range n {
1741
+ b [i ] = byte (value [i ])
1742
+ }
1743
+ return slog .String (key , string (b ))
1744
+ }
1745
+
1746
+ func (customSyscallLogger ) LogEntrySysUname (buf * Utsname , syscall * syscallabi.Syscall ) {
1747
+ logSyscallEntry ("SysUname" , syscall )
1748
+ }
1749
+
1750
+ func (customSyscallLogger ) LogExitSysUname (buf * Utsname , syscall * syscallabi.Syscall , err error ) {
1751
+ logSyscallExit ("SysUname" , syscall , slog .Group ("buf" , int8ArrayToString ("nodename" , buf .Nodename [:])), "err" , err )
1752
+ }
1753
+
1638
1754
func (l * LinuxOS ) SysMadvise (b syscallabi.SliceView [byte ], advice int , invocation * syscallabi.Syscall ) (err error ) {
1639
1755
l .logfFor (invocation , "madvise %d %d %d" , uintptr (unsafe .Pointer (unsafe .SliceData (b .Ptr ))), b .Len (), advice )
1640
1756
// ignore? check args for some sanity?
0 commit comments