MCPcopy
hub / github.com/google/gvisor / Boot

Function Boot

pkg/sentry/fsimpl/testutil/kernel.go:53–126  ·  view source on GitHub ↗

Boot initializes a new bare bones kernel for test.

()

Source from the content-addressed store, hash-verified

51
52// Boot initializes a new bare bones kernel for test.
53func Boot() (*kernel.Kernel, error) {
54 cpuid.Initialize()
55 seccheck.Initialize()
56
57 if err := usage.Init(); err != nil {
58 return nil, fmt.Errorf("setting up memory accounting: %v", err)
59 }
60
61 platformCtr, err := platform.Lookup(*platformFlag)
62 if err != nil {
63 return nil, fmt.Errorf("platform not found: %v", err)
64 }
65 deviceFile, err := platformCtr.OpenDevice(*platformDevicePathFlag)
66 if err != nil {
67 return nil, fmt.Errorf("creating platform: %v", err)
68 }
69 plat, err := platformCtr.New(platform.Options{DeviceFile: deviceFile})
70 if err != nil {
71 return nil, fmt.Errorf("creating platform: %v", err)
72 }
73
74 k := &kernel.Kernel{
75 Platform: plat,
76 }
77
78 mf, err := createMemoryFile()
79 if err != nil {
80 return nil, err
81 }
82 k.SetMemoryFile(mf)
83
84 // Pass k as the platform since it is savable, unlike the actual platform.
85 vdso, err := loader.PrepareVDSO(k.MemoryFile())
86 if err != nil {
87 return nil, fmt.Errorf("creating vdso: %v", err)
88 }
89
90 // Create timekeeper.
91 tk := kernel.NewTimekeeper()
92 params := kernel.NewVDSOParamPage(k.MemoryFile(), vdso.ParamPage.FileRange())
93 tk.SetClocks(time.NewCalibratedClocks(), params)
94
95 creds := auth.NewRootCredentials(auth.NewRootUserNamespace())
96
97 // Initiate the Kernel object, which is required by the Context passed
98 // to createVFS in order to mount (among other things) procfs.
99 if err = k.Init(kernel.InitKernelArgs{
100 ApplicationCores: uint(runtime.GOMAXPROCS(-1)),
101 FeatureSet: cpuid.HostFeatureSet(),
102 Timekeeper: tk,
103 RootUserNamespace: creds.UserNamespace,
104 Vdso: vdso,
105 VdsoParams: params,
106 RootUTSNamespace: kernel.NewUTSNamespace("hostname", "domain", creds.UserNamespace),
107 RootIPCNamespace: kernel.NewIPCNamespace(creds.UserNamespace),
108 RootPIDNamespace: kernel.NewRootPIDNamespace(creds.UserNamespace),
109 }); err != nil {
110 return nil, fmt.Errorf("initializing kernel: %v", err)

Callers 3

newTestSystemFunction · 0.92
setupFunction · 0.92
setupWithDataFunction · 0.92

Calls 15

SetMemoryFileMethod · 0.95
MemoryFileMethod · 0.95
SetClocksMethod · 0.95
InitMethod · 0.95
VFSMethod · 0.95
NewThreadGroupMethod · 0.95
RootPIDNamespaceMethod · 0.95
TestOnlySetGlobalInitMethod · 0.95
InitializeFunction · 0.92
InitializeFunction · 0.92
InitFunction · 0.92
LookupFunction · 0.92

Tested by 3

newTestSystemFunction · 0.74
setupFunction · 0.74
setupWithDataFunction · 0.74

Used in the wild real call sites across dependent graphs

searching dependent graphs…