diff options
Diffstat (limited to 'pkg/sentry/limits')
-rw-r--r-- | pkg/sentry/limits/BUILD | 29 | ||||
-rw-r--r-- | pkg/sentry/limits/limits_state_autogen.go | 61 | ||||
-rw-r--r-- | pkg/sentry/limits/limits_test.go | 44 |
3 files changed, 61 insertions, 73 deletions
diff --git a/pkg/sentry/limits/BUILD b/pkg/sentry/limits/BUILD deleted file mode 100644 index 21b0d1595..000000000 --- a/pkg/sentry/limits/BUILD +++ /dev/null @@ -1,29 +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", - "@org_golang_x_sys//unix:go_default_library", - ], -) - -go_test( - name = "limits_test", - size = "small", - srcs = [ - "limits_test.go", - ], - library = ":limits", - deps = ["@org_golang_x_sys//unix:go_default_library"], -) diff --git a/pkg/sentry/limits/limits_state_autogen.go b/pkg/sentry/limits/limits_state_autogen.go new file mode 100644 index 000000000..d619cabd4 --- /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 (l *Limit) StateTypeName() string { + return "pkg/sentry/limits.Limit" +} + +func (l *Limit) StateFields() []string { + return []string{ + "Cur", + "Max", + } +} + +func (l *Limit) beforeSave() {} + +func (l *Limit) StateSave(stateSinkObject state.Sink) { + l.beforeSave() + stateSinkObject.Save(0, &l.Cur) + stateSinkObject.Save(1, &l.Max) +} + +func (l *Limit) afterLoad() {} + +func (l *Limit) StateLoad(stateSourceObject state.Source) { + stateSourceObject.Load(0, &l.Cur) + stateSourceObject.Load(1, &l.Max) +} + +func (l *LimitSet) StateTypeName() string { + return "pkg/sentry/limits.LimitSet" +} + +func (l *LimitSet) StateFields() []string { + return []string{ + "data", + } +} + +func (l *LimitSet) beforeSave() {} + +func (l *LimitSet) StateSave(stateSinkObject state.Sink) { + l.beforeSave() + stateSinkObject.Save(0, &l.data) +} + +func (l *LimitSet) afterLoad() {} + +func (l *LimitSet) StateLoad(stateSourceObject state.Source) { + stateSourceObject.Load(0, &l.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 0ee877be4..000000000 --- a/pkg/sentry/limits/limits_test.go +++ /dev/null @@ -1,44 +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 ( - "testing" - - "golang.org/x/sys/unix" -) - -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: unix.EPERM}, - {limit: Limit{Cur: 60, Max: 50}, privileged: false, expectedErr: unix.EINVAL}, - {limit: Limit{Cur: 11, Max: 10}, privileged: false, expectedErr: unix.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) - } - } - -} |