Commit Graph

53 Commits

Author SHA1 Message Date
Jamie Liu 964fb3ca76 Use go:build directives in generated files.
Build constraints are now inferred from go:build directives rather than +build
directives. +build directives are still emitted in generated files as required
in Go 1.16 and earlier.

Note that go/build/constraint was added in Go 1.16, so gVisor now requires Go
1.16.

PiperOrigin-RevId: 387240779
2021-07-27 18:14:05 -07:00
Zach Koopmans e3fdd15932 [syserror] Update syserror to linuxerr for more errors.
Update the following from syserror to the linuxerr equivalent:
EEXIST
EFAULT
ENOTDIR
ENOTTY
EOPNOTSUPP
ERANGE
ESRCH

PiperOrigin-RevId: 384329869
2021-07-12 15:26:20 -07:00
Kevin Krakauer 45884ba639 Internal change
PiperOrigin-RevId: 372166050
2021-05-05 11:15:26 -07:00
Rahat Mahmood 5960674c8f Document how to handle build failures from go-marshal verbosity.
With debugging enabled, go-marshal can generate too much output for
bazel under default configurations, which can cause builds to
fail. The limit defaults to 1 MB.

PiperOrigin-RevId: 372030402
2021-05-04 17:40:08 -07:00
Ayush Ranjan ee45334f14 [lisa] Make go_marshal pass correctly sized buffers to safecopy.
gohacks.Memmove() takes in the number of bytes to move. The current generated
code passes len(src) and len(dst) as the number of bytes to move.

However, the marshal.Marshallable interface allows passing in larger buffers.
The stated precondition is that the buffer should be "at least" SizeBytes()
in length but it is allowed to be larger.

This change now correctly calls Memmove with the argument for the number of
bytes to move as type.SizeBytes(). This was caught when I made lisafs use the
Unsafe marshalling API and got a lot of memory violations.

PiperOrigin-RevId: 368952642
2021-04-16 17:51:52 -07:00
Zach Koopmans 5c1052b6bb [syserror] Remove syserror from go_marshal
PiperOrigin-RevId: 368470656
2021-04-14 11:28:49 -07:00
Zach Koopmans 8a2f7e716d [syserror] Split usermem package
Split usermem package to help remove syserror dependency in go_marshal.
New hostarch package contains code not dependent on syserror.

PiperOrigin-RevId: 365651233
2021-03-29 13:30:21 -07:00
Ayush Ranjan c0bd71c5a5 [lisa] Support dynamic types for all types.
We were only supporting dynamic struct types. With this change, users can make
any type dynamic. The tool (correctly) blindly just generates the remaining
methods needed to implement Marshallable using the 3 methods defined by the
user on the dynamic type.

This is helpful in situations like:
type StringArray []string

Added a test for such a use case.

PiperOrigin-RevId: 364463164
2021-03-22 19:17:49 -07:00
Rahat Mahmood 6bd2c6ce73 Emit comment about build tags in gomarshal generated files.
This may be useful for tracking down where build tags come from and
understanding tag import issues in generated files.

PiperOrigin-RevId: 364374931
2021-03-22 12:02:03 -07:00
Ayush Ranjan 333e489763 [lisa] Do not generate any tests for dynamic types.
The dynamic type user defines the marshalling logic, so we don't need to test
for things like alignment, absence of slices, etc.

For dynamic types, the go_marshal generator just generates the missing methods
required to implement marshal.Marshallable.

PiperOrigin-RevId: 361676311
2021-03-08 15:51:47 -08:00
Ayush Ranjan cfa4633c3d [go-marshal] Add dynamic tag in go_marshal.
This makes it easier to implement dynamically sized types in go-marshal. You
really only need to implement MarshalBytes, UnmarshalBytes and SizeBytes to
implement the entire interface.

By using the `dynamic` tag, the autogenerator will generate the rest of the
methods for us.

This change also simplifies how KernelIPTGetEntries implements Marshallable
using the newly added utility.

PiperOrigin-RevId: 356397114
2021-02-08 18:08:29 -08:00
Adin Scannell 4e03e87547 Fix simple mistakes identified by goreportcard.
These are primarily simplification and lint mistakes. However, minor
fixes are also included and tests added where appropriate.

PiperOrigin-RevId: 351425971
2021-01-12 12:38:22 -08:00
Adin Scannell 0fb5de1154 Use a stable ordering for generated types.
Otherwise this pollutes the 'go' branch and doesn't conform to standards
for generate bazel files.

PiperOrigin-RevId: 349605037
2020-12-30 14:53:03 -08:00
Adin Scannell 4cba3904f4 Remove existing nogo exceptions.
PiperOrigin-RevId: 347047550
2020-12-11 12:06:49 -08:00
Ting-Yu Wang 1cfa8d58f6 Fix more nogo tests
PiperOrigin-RevId: 340536306
2020-11-03 15:23:32 -08:00
Adin Scannell a55bd73d48 Add staticcheck and staticstyle analyzers.
This change also adds support to go_stateify for detecting an appropriate
receiver name, avoiding a large number of false positives.

PiperOrigin-RevId: 335994587
2020-10-07 18:29:05 -07:00
Rahat Mahmood fee2c07728 go-marshal tests should respect build tags.
Previously, the go-marshal-generated tests did not respect build
tags. This can cause the test to unbuildable under some build
configurations, as the original types the tests refer to may not be
defined.

This CL copies the build tags from the input files to the test,
similar to the generated library; however test packages have an
additional constraint. A test package cannot be totally empty
(i.e. have no test/example/benchmark defined), otherwise the go
compiler returns an error. To ensure the generated test package always
contains a testable entity under all build configurations, we now emit
an extra test file with no build tags that contains a single no-op
example.

PiperOrigin-RevId: 334496821
2020-09-29 17:29:08 -07:00
Rahat Mahmood 44c7d55074 Support embedded fields in go-marshal.
PiperOrigin-RevId: 334437990
2020-09-29 12:34:30 -07:00
gVisor bot d00207ff48 Internal change.
PiperOrigin-RevId: 333287864
2020-09-23 07:29:31 -07:00
Rahat Mahmood 9ef1c79922 Rename marshal.Task to marshal.CopyContext.
CopyContext is a better name for the interface because from
go-marshal's perspective, the interface has nothing to do with a
task. A kernel.Task happens to implement the interface, but so can
other things like MemoryManager and IO sequences.

PiperOrigin-RevId: 331959678
2020-09-16 02:10:12 -07:00
Rahat Mahmood d201feb8c5 Enable automated marshalling for the syscall package.
PiperOrigin-RevId: 331940975
2020-09-15 23:38:57 -07:00
Rahat Mahmood 3ca73841d7 Move the 'marshal' and 'primitive' packages to the 'pkg' directory.
PiperOrigin-RevId: 331256608
2020-09-11 17:42:49 -07:00
Adin Scannell 101c97d6f8 Change nogo failures to test failures, instead of build failures.
PiperOrigin-RevId: 329408633
2020-08-31 17:09:20 -07:00
Adin Scannell 983a55aa06 Support stdlib analyzers with nogo.
This immediately revealed an escape analysis violation (!), where
the sync.Map was being used in a context that escapes were not
allowed. This is a relatively minor fix and is included.

PiperOrigin-RevId: 328611237
2020-08-26 14:42:35 -07:00
Ayush Ranjan 46485f9d47 [go-marshal] Support marshalling for structs with names starting with W.
Due to how marshallable interface implementation was generated, we could not
marshal a struct whose named started with W because there was a naming
collision with parameter (w io.Writer) and type (w *StuctName).

Used "writer" as parameter name to avoid collision.

PiperOrigin-RevId: 328343930
2020-08-25 09:23:41 -07:00
gVisor bot 977618c8e1 Merge pull request #3520 from boyuan-he:marshal-impl
PiperOrigin-RevId: 325546935
2020-08-07 18:43:12 -07:00
Boyuan He 92c0643587 add stub go marshallable implementation 2020-08-07 00:29:07 +00:00
Adin Scannell 90021e775a Add bzl_library rules for .bzl files without one.
PiperOrigin-RevId: 325280924
2020-08-06 12:10:49 -07:00
Ayush Ranjan c59b792f53 [go-marshal] Update API
- All Marshal* and Unmarshal* methods now require buffers to be correctly sized
- Only the Copy{In/Out} variants can handle smaller buffers (or address spaces)

PiperOrigin-RevId: 322953881
2020-07-24 01:19:34 -07:00
Ayush Ranjan 6f7f739967 Marshallable socket opitons.
Socket option values are now required to implement marshal.Marshallable.

Co-authored-by: Rahat Mahmood <rahat@google.com>
PiperOrigin-RevId: 322831612
2020-07-23 11:45:10 -07:00
gVisor bot c81ac8ec3b Merge pull request #2672 from amscanne:shim-integrated
PiperOrigin-RevId: 321053634
2020-07-13 16:10:58 -07:00
Adin Scannell c615aafa21 Add internal nogo analysis & checkescape tool.
See tools/nogo/README.md.

The checkescape tool is able to perform recursive escape analysis, using the
actual generated binary to confirm the results produced by the compiler itself.

As an initial use case, this replaces the manual escape analysis tests used for
go_marshal, and validates that the CopyIn and CopyOut paths will not require
any allocation or stack splits.

Updates #2243

PiperOrigin-RevId: 307532986
2020-04-20 20:58:20 -07:00
Rahat Mahmood 1561ae3037 go-marshal: Allow array lens to be consts and simple expressions.
Previously, go-marshal only allowed literals for array
lengths. However, it's very common for ABI structs to have a fix-sized
array whose length is defined by a constant; for example PATH_MAX.
Having to convert all such arrays to have literal lengths is too
awkward.

PiperOrigin-RevId: 304289345
2020-04-01 16:51:28 -07:00
Rahat Mahmood 507f997213 go-marshal: Improve collision detection of import statments.
Previously, the import statement collision detection mechanism aborted
go-marshal whenever it detected two imports in any package that has
the same local name. Consider this trivial package, defined by the the
following two source files:

file1.go:

package example
import (
        path/a/to/foo
)
...

file2.go:

package example
import (
       another/package/with/final/component/foo
)
...

Go-marshal previously couldn't handle generating code for the the
above package, even if none of the types marked for marshalling used
either of the imported foo packages. This turns out to be too
restrictive as we run into this a lot in practice. Examples include
"encoding/binary" vs "gvisor/pkg/binary/binary", and "sync" vs
"gvisor/pkg/sync/sync".

This change allows go-marshal to proceed with marshalling, and only
abort if the code generated by go-marshal references any such
ambiguous import names.

PiperOrigin-RevId: 304131190
2020-04-01 00:43:55 -07:00
Rahat Mahmood 840980aeba Implement automated marshalling for slices of Marshallable types.
PiperOrigin-RevId: 304119255
2020-03-31 22:56:09 -07:00
Adin Scannell d440fe0613 Fix go_marshal Example name.
There is a canonical naming convention for Examples, which are checked
by analyzers. This must be fixed since adding exceptions for generated
code will be more challenging.
2020-03-25 16:18:05 -07:00
Rahat Mahmood aa9f8abaef Implement automated marshalling for newtypes on arrays.
PiperOrigin-RevId: 297693838
2020-02-27 14:52:26 -08:00
gVisor bot f1b72752e5 Implement automated marshalling for newtypes on primitives.
PiperOrigin-RevId: 296322954
2020-02-20 16:23:56 -08:00
gVisor bot d90d71474f Remove bytes read/written from marshal.Marshallable API.
Users of the API only care about whether the copy in/out succeeds in
their entirety, which is already signalled by the returned error.

PiperOrigin-RevId: 296297843
2020-02-20 14:29:26 -08:00
gVisor bot 660cfdff3f Handle situations where go-marshal generates an empty test file.
This can happen due to conditional compilation, where a subset of the
source files contain no marshallable types. go-marshal is still
required to write an output file in these cases, since bazel defines
the output package before calling go-marshal.

PiperOrigin-RevId: 296074321
2020-02-19 15:42:19 -08:00
gVisor bot 737a3d072e go-marshal: Stop complaining about files with no +marshal types.
Since we tag entire packages as marshallable, due to conditional
compiling for different architectures we can end up with sets of
source files that don't contain any marshallable types. It's safe to
silently ignore this scenario.

PiperOrigin-RevId: 295831871
2020-02-18 15:09:17 -08:00
gVisor bot 5cc0bbbafb Ensure Marshallable.SizeBytes() always works on a typed nil pointer.
This lets go-marshal replace various calls to binary.Size() throughout
the sentry without requiring concrete objects.

PiperOrigin-RevId: 295299965
2020-02-15 00:01:02 -08:00
gVisor bot 3d32ad1367 Generate implementation of io.WriterTo via go-marshal.
PiperOrigin-RevId: 295269654
2020-02-14 18:32:49 -08:00
gVisor bot 48d9aa7ab3 Add a minimal binary target for escape analysis on go-marshal.
Note that this is not an automated test.

PiperOrigin-RevId: 295238672
2020-02-14 15:21:03 -08:00
gVisor bot b2e86906ea Fix various issues related to enabling go-marshal.
- Add missing build tags to files in the abi package.

- Add the marshal package as a sentry dependency, allowed by deps_test.

- Fix an issue with our top-level go_library BUILD rule, which
  incorrectly shadows the variable containing the input set of source
  files. This caused the expansion for the go_marshal clause to
  silently omit input files.

- Fix formatting when copying build tags to gomarshal-generated files.

- Fix a bug with import statement collision detection in go-marshal.

PiperOrigin-RevId: 295112284
2020-02-14 03:27:34 -08:00
gVisor bot 336f758d59 Ensure the marshalled object doesn't escape.
Add new Marshallable interface methods CopyIn/CopyOut, which can be directly
called on the marshalled object, avoiding an interface indirection. Such
indirections are problematic because they always cause the marshalled object to
escape.

PiperOrigin-RevId: 295028010
2020-02-13 16:32:23 -08:00
Adin Scannell 95ce8bb4c7 Automatically propagate tags for stateify and marshal.
Note that files will need to be appropriately segmented in order for the
mechanism to work, in suffixes implying special tags. This only needs to happen
for cases where marshal or state structures are defined, which should be rare
and mostly architecture specific.

PiperOrigin-RevId: 293231579
2020-02-04 14:37:39 -08:00
Adin Scannell 0e2f1b7abd Update package locations.
Because the abi will depend on the core types for marshalling (usermem,
context, safemem, safecopy), these need to be flattened from the sentry
directory. These packages contain no sentry-specific details.

PiperOrigin-RevId: 291811289
2020-01-27 15:31:32 -08:00
Adin Scannell 90ec596166 Fix licenses.
The preferred Copyright holder is "The gVisor Authors".

PiperOrigin-RevId: 291786657
2020-01-27 13:23:57 -08:00
Adin Scannell d29e59af9f Standardize on tools directory.
PiperOrigin-RevId: 291745021
2020-01-27 12:21:00 -08:00