summaryrefslogtreecommitdiffhomepage
path: root/runsc/boot/compat_amd64.go
diff options
context:
space:
mode:
authorFabricio Voznika <fvoznika@google.com>2018-10-20 11:12:26 -0700
committerShentubot <shentubot@google.com>2018-10-20 11:14:23 -0700
commitb2068cf5a5d43f3898cf389ab2d6151cf61908ac (patch)
tree71ec95233e3c3cfa32757ecb4b01aa73ee9adb1b /runsc/boot/compat_amd64.go
parent8fce67af24945f82378b4c2731cca1788936d074 (diff)
Add more unimplemented syscall events
Added events for *ctl syscalls that may have multiple different commands. For runsc, each syscall event is only logged once. For *ctl syscalls, use the cmd as identifier, not only the syscall number. PiperOrigin-RevId: 218015941 Change-Id: Ie3c19131ae36124861e9b492a7dbe1765d9e5e59
Diffstat (limited to 'runsc/boot/compat_amd64.go')
-rw-r--r--runsc/boot/compat_amd64.go54
1 files changed, 54 insertions, 0 deletions
diff --git a/runsc/boot/compat_amd64.go b/runsc/boot/compat_amd64.go
new file mode 100644
index 000000000..2bb769a49
--- /dev/null
+++ b/runsc/boot/compat_amd64.go
@@ -0,0 +1,54 @@
+// Copyright 2018 Google LLC
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package boot
+
+import (
+ "fmt"
+
+ rpb "gvisor.googlesource.com/gvisor/pkg/sentry/arch/registers_go_proto"
+)
+
+// cmdTracker reports only a single time for each different command argument in
+// the syscall. It's used for generic syscalls like ioctl to report once per
+// 'cmd'
+type cmdTracker struct {
+ // argIdx is the syscall argument index where the command is located.
+ argIdx int
+ cmds map[uint32]struct{}
+}
+
+func newCmdTracker(argIdx int) *cmdTracker {
+ return &cmdTracker{argIdx: argIdx, cmds: make(map[uint32]struct{})}
+}
+
+// cmd returns the command based on the syscall argument index.
+func (c *cmdTracker) cmd(regs *rpb.AMD64Registers) uint32 {
+ switch c.argIdx {
+ case 0:
+ return uint32(regs.Rdi)
+ case 1:
+ return uint32(regs.Rsi)
+ }
+ panic(fmt.Sprintf("unsupported syscall argument index %d", c.argIdx))
+}
+
+func (c *cmdTracker) shouldReport(regs *rpb.AMD64Registers) bool {
+ _, ok := c.cmds[c.cmd(regs)]
+ return !ok
+}
+
+func (c *cmdTracker) onReported(regs *rpb.AMD64Registers) {
+ c.cmds[c.cmd(regs)] = struct{}{}
+}