diff options
Diffstat (limited to 'pkg/sentry/limits')
-rw-r--r-- | pkg/sentry/limits/BUILD | 27 | ||||
-rw-r--r-- | pkg/sentry/limits/limits_state_autogen.go | 61 | ||||
-rw-r--r-- | pkg/sentry/limits/limits_test.go | 43 |
3 files changed, 61 insertions, 70 deletions
diff --git a/pkg/sentry/limits/BUILD b/pkg/sentry/limits/BUILD deleted file mode 100644 index cf591c4c1..000000000 --- a/pkg/sentry/limits/BUILD +++ /dev/null @@ -1,27 +0,0 @@ -load("//tools:defs.bzl", "go_library", "go_test") - -package(licenses = ["notice"]) - -go_library( - name = "limits", - srcs = [ - "context.go", - "limits.go", - "linux.go", - ], - visibility = ["//:sandbox"], - deps = [ - "//pkg/abi/linux", - "//pkg/context", - "//pkg/sync", - ], -) - -go_test( - name = "limits_test", - size = "small", - srcs = [ - "limits_test.go", - ], - library = ":limits", -) diff --git a/pkg/sentry/limits/limits_state_autogen.go b/pkg/sentry/limits/limits_state_autogen.go new file mode 100644 index 000000000..72503d1d7 --- /dev/null +++ b/pkg/sentry/limits/limits_state_autogen.go @@ -0,0 +1,61 @@ +// automatically generated by stateify. + +package limits + +import ( + "gvisor.dev/gvisor/pkg/state" +) + +func (x *Limit) StateTypeName() string { + return "pkg/sentry/limits.Limit" +} + +func (x *Limit) StateFields() []string { + return []string{ + "Cur", + "Max", + } +} + +func (x *Limit) beforeSave() {} + +func (x *Limit) StateSave(m state.Sink) { + x.beforeSave() + m.Save(0, &x.Cur) + m.Save(1, &x.Max) +} + +func (x *Limit) afterLoad() {} + +func (x *Limit) StateLoad(m state.Source) { + m.Load(0, &x.Cur) + m.Load(1, &x.Max) +} + +func (x *LimitSet) StateTypeName() string { + return "pkg/sentry/limits.LimitSet" +} + +func (x *LimitSet) StateFields() []string { + return []string{ + "data", + } +} + +func (x *LimitSet) beforeSave() {} + +func (x *LimitSet) StateSave(m state.Sink) { + x.beforeSave() + m.Save(0, &x.data) +} + +func (x *LimitSet) afterLoad() {} + +func (x *LimitSet) StateLoad(m state.Source) { + m.Load(0, &x.data) +} + +func init() { + state.Register((*Limit)(nil)) + state.Register((*LimitSet)(nil)) +} diff --git a/pkg/sentry/limits/limits_test.go b/pkg/sentry/limits/limits_test.go deleted file mode 100644 index 658a20f56..000000000 --- a/pkg/sentry/limits/limits_test.go +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright 2018 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. - -package limits - -import ( - "syscall" - "testing" -) - -func TestSet(t *testing.T) { - testCases := []struct { - limit Limit - privileged bool - expectedErr error - }{ - {limit: Limit{Cur: 50, Max: 50}, privileged: false, expectedErr: nil}, - {limit: Limit{Cur: 20, Max: 50}, privileged: false, expectedErr: nil}, - {limit: Limit{Cur: 20, Max: 60}, privileged: false, expectedErr: syscall.EPERM}, - {limit: Limit{Cur: 60, Max: 50}, privileged: false, expectedErr: syscall.EINVAL}, - {limit: Limit{Cur: 11, Max: 10}, privileged: false, expectedErr: syscall.EINVAL}, - {limit: Limit{Cur: 20, Max: 60}, privileged: true, expectedErr: nil}, - } - - ls := NewLimitSet() - for _, tc := range testCases { - if _, err := ls.Set(1, tc.limit, tc.privileged); err != tc.expectedErr { - t.Fatalf("Tried to set Limit to %+v and privilege %t: got %v, wanted %v", tc.limit, tc.privileged, err, tc.expectedErr) - } - } - -} |