From 20840bfec087d45853e81d1ac34940f3b2fb920a Mon Sep 17 00:00:00 2001 From: Brad Burlage Date: Mon, 10 Feb 2020 11:57:31 -0800 Subject: Move x86 state definition to its own file. PiperOrigin-RevId: 294271541 --- pkg/sentry/arch/BUILD | 1 + pkg/sentry/arch/arch_state_x86.go | 4 ++-- pkg/sentry/arch/arch_x86.go | 15 -------------- pkg/sentry/arch/arch_x86_impl.go | 43 +++++++++++++++++++++++++++++++++++++++ tools/build/tags.bzl | 24 +++++++++++----------- 5 files changed, 58 insertions(+), 29 deletions(-) create mode 100644 pkg/sentry/arch/arch_x86_impl.go diff --git a/pkg/sentry/arch/BUILD b/pkg/sentry/arch/BUILD index 34c0a867d..e27f21e5e 100644 --- a/pkg/sentry/arch/BUILD +++ b/pkg/sentry/arch/BUILD @@ -14,6 +14,7 @@ go_library( "arch_state_aarch64.go", "arch_state_x86.go", "arch_x86.go", + "arch_x86_impl.go", "auxv.go", "signal.go", "signal_act.go", diff --git a/pkg/sentry/arch/arch_state_x86.go b/pkg/sentry/arch/arch_state_x86.go index d388ee9cf..e35c9214a 100644 --- a/pkg/sentry/arch/arch_state_x86.go +++ b/pkg/sentry/arch/arch_state_x86.go @@ -43,8 +43,8 @@ func (e ErrFloatingPoint) Error() string { // and SSE state, so this is the equivalent XSTATE_BV value. const fxsaveBV uint64 = cpuid.XSAVEFeatureX87 | cpuid.XSAVEFeatureSSE -// afterLoad is invoked by stateify. -func (s *State) afterLoad() { +// afterLoadFPState is invoked by afterLoad. +func (s *State) afterLoadFPState() { old := s.x86FPState // Recreate the slice. This is done to ensure that it is aligned diff --git a/pkg/sentry/arch/arch_x86.go b/pkg/sentry/arch/arch_x86.go index 3db8bd34b..88b40a9d1 100644 --- a/pkg/sentry/arch/arch_x86.go +++ b/pkg/sentry/arch/arch_x86.go @@ -155,21 +155,6 @@ func NewFloatingPointData() *FloatingPointData { return (*FloatingPointData)(&(newX86FPState()[0])) } -// State contains the common architecture bits for X86 (the build tag of this -// file ensures it's only built on x86). -// -// +stateify savable -type State struct { - // The system registers. - Regs syscall.PtraceRegs `state:".(syscallPtraceRegs)"` - - // Our floating point state. - x86FPState `state:"wait"` - - // FeatureSet is a pointer to the currently active feature set. - FeatureSet *cpuid.FeatureSet -} - // Proto returns a protobuf representation of the system registers in State. func (s State) Proto() *rpb.Registers { regs := &rpb.AMD64Registers{ diff --git a/pkg/sentry/arch/arch_x86_impl.go b/pkg/sentry/arch/arch_x86_impl.go new file mode 100644 index 000000000..04ac283c6 --- /dev/null +++ b/pkg/sentry/arch/arch_x86_impl.go @@ -0,0 +1,43 @@ +// Copyright 2020 The gVisor Authors. +// +// 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. + +// +build amd64 i386 + +package arch + +import ( + "syscall" + + "gvisor.dev/gvisor/pkg/cpuid" +) + +// State contains the common architecture bits for X86 (the build tag of this +// file ensures it's only built on x86). +// +// +stateify savable +type State struct { + // The system registers. + Regs syscall.PtraceRegs `state:".(syscallPtraceRegs)"` + + // Our floating point state. + x86FPState `state:"wait"` + + // FeatureSet is a pointer to the currently active feature set. + FeatureSet *cpuid.FeatureSet +} + +// afterLoad is invoked by stateify. +func (s *State) afterLoad() { + s.afterLoadFPState() +} diff --git a/tools/build/tags.bzl b/tools/build/tags.bzl index a6db44e47..558fb53ae 100644 --- a/tools/build/tags.bzl +++ b/tools/build/tags.bzl @@ -3,22 +3,28 @@ go_suffixes = [ "_386", "_386_unsafe", - "_amd64", - "_amd64_unsafe", "_aarch64", "_aarch64_unsafe", + "_amd64", + "_amd64_unsafe", "_arm", - "_arm_unsafe", "_arm64", "_arm64_unsafe", + "_arm_unsafe", + "_impl", + "_impl_unsafe", + "_linux", + "_linux_unsafe", "_mips", - "_mips_unsafe", - "_mipsle", - "_mipsle_unsafe", "_mips64", "_mips64_unsafe", "_mips64le", "_mips64le_unsafe", + "_mips_unsafe", + "_mipsle", + "_mipsle_unsafe", + "_opts", + "_opts_unsafe", "_ppc64", "_ppc64_unsafe", "_ppc64le", @@ -31,10 +37,4 @@ go_suffixes = [ "_sparc64_unsafe", "_wasm", "_wasm_unsafe", - "_linux", - "_linux_unsafe", - "_opts", - "_opts_unsafe", - "_impl", - "_impl_unsafe", ] -- cgit v1.2.3