summaryrefslogtreecommitdiffhomepage
path: root/pkg/sentry/platform/ring0/kernel.go
diff options
context:
space:
mode:
authorAdin Scannell <ascannell@google.com>2018-10-31 15:58:21 -0700
committerShentubot <shentubot@google.com>2018-10-31 15:59:23 -0700
commitfb613020c7db323c705adf6ae0f954bee4ab5fec (patch)
tree3ff87b578e9739c813e71b9d38d88509c5664575 /pkg/sentry/platform/ring0/kernel.go
parentc4bbb54168a9014048d2144110e70daf5a5b8211 (diff)
kvm: simplify floating point logic.
This reduces the number of floating point save/restore cycles required (since we don't need to restore immediately following the switch, this always happens in a known context) and allows the kernel hooks to capture state. This lets us remove calls like "Current()". PiperOrigin-RevId: 219552844 Change-Id: I7676fa2f6c18b9919718458aa888b832a7db8cab
Diffstat (limited to 'pkg/sentry/platform/ring0/kernel.go')
-rw-r--r--pkg/sentry/platform/ring0/kernel.go34
1 files changed, 22 insertions, 12 deletions
diff --git a/pkg/sentry/platform/ring0/kernel.go b/pkg/sentry/platform/ring0/kernel.go
index e70eafde2..19ac6eb7c 100644
--- a/pkg/sentry/platform/ring0/kernel.go
+++ b/pkg/sentry/platform/ring0/kernel.go
@@ -26,31 +26,41 @@ func (k *Kernel) Init(opts KernelOpts) {
// Halt halts execution.
func Halt()
-// Current returns the current CPU.
+// defaultHooks implements hooks.
+type defaultHooks struct{}
+
+// KernelSyscall implements Hooks.KernelSyscall.
//
-// Its use is only legal in the KernelSyscall and KernelException contexts,
-// which must all be guarded go:nosplit.
-func Current() *CPU
+//go:nosplit
+func (defaultHooks) KernelSyscall() { Halt() }
+
+// KernelException implements Hooks.KernelException.
+//
+//go:nosplit
+func (defaultHooks) KernelException(Vector) { Halt() }
-// defaultSyscall is the default syscall hook.
+// kernelSyscall is a trampoline.
//
//go:nosplit
-func defaultSyscall() { Halt() }
+func kernelSyscall(c *CPU) { c.hooks.KernelSyscall() }
-// defaultException is the default exception hook.
+// kernelException is a trampoline.
//
//go:nosplit
-func defaultException(Vector) { Halt() }
+func kernelException(c *CPU, vector Vector) { c.hooks.KernelException(vector) }
// Init initializes a new CPU.
//
// Init allows embedding in other objects.
-func (c *CPU) Init(k *Kernel) {
+func (c *CPU) Init(k *Kernel, hooks Hooks) {
c.self = c // Set self reference.
c.kernel = k // Set kernel reference.
c.init() // Perform architectural init.
- // Defaults.
- c.KernelSyscall = defaultSyscall
- c.KernelException = defaultException
+ // Require hooks.
+ if hooks != nil {
+ c.hooks = hooks
+ } else {
+ c.hooks = defaultHooks{}
+ }
}