platform: fix minor linting issue (#1471)

Signed-off-by: Edoardo Vacchi <evacchi@users.noreply.github.com>
Signed-off-by: Adrian Cole <adrian@tetrate.io>
Co-authored-by: Adrian Cole <adrian@tetrate.io>
This commit is contained in:
Edoardo Vacchi
2023-05-16 06:06:29 +02:00
committed by GitHub
parent 11b346ed75
commit cb06b7b779

View File

@@ -8,16 +8,31 @@ func remapCodeSegmentAMD64(code []byte, size int) ([]byte, error) {
return nil, err
}
copy(b, code)
munmapCodeSegment(code)
mustMunmapCodeSegment(code)
return b, nil
}
// mustMunmapCodeSegment panics instead of returning an error to the
// application.
//
// # Why panic?
//
// It is less disruptive to the application to leak the previous block if it
// could be unmapped than to leak the new block and return an error.
// Realistically, either scenarios are pretty hard to debug, so we panic. There
// is less as the dominant runtime.GOOS (linux) doesn't use this anyway.
func mustMunmapCodeSegment(code []byte) {
if err := munmapCodeSegment(code); err != nil {
panic(err)
}
}
func remapCodeSegmentARM64(code []byte, size int) ([]byte, error) {
b, err := mmapCodeSegmentARM64(size)
if err != nil {
return nil, err
}
copy(b, code)
munmapCodeSegment(code)
mustMunmapCodeSegment(code)
return b, nil
}