gvisor.dev/gvisor@v0.0.0-20240520182842-f9d4d51c7e0f/test/trace/trace_amd64_test.go (about)

     1  // Copyright 2022 The gVisor Authors.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  //go:build amd64
    16  // +build amd64
    17  
    18  package trace
    19  
    20  import (
    21  	"fmt"
    22  	"testing"
    23  
    24  	"golang.org/x/sys/unix"
    25  	"google.golang.org/protobuf/proto"
    26  	pb "gvisor.dev/gvisor/pkg/sentry/seccheck/points/points_go_proto"
    27  	"gvisor.dev/gvisor/pkg/sentry/seccheck/sinks/remote/test"
    28  )
    29  
    30  func extraMatchers(t *testing.T, msgs []test.Message, matchers map[pb.MessageType]*checkers) {
    31  	// Register functions that verify each available point specific to amd64 architecture.
    32  	matchers[pb.MessageType_MESSAGE_SYSCALL_FORK] = &checkers{checker: checkSyscallFork}
    33  }
    34  
    35  func checkSyscallSignalfdFlags(flags int32) error {
    36  	if flags != 0 && flags != (unix.SFD_CLOEXEC|unix.SFD_NONBLOCK) {
    37  		return fmt.Errorf("invalid flag got: %v", flags)
    38  	}
    39  	return nil
    40  }
    41  
    42  func checkSyscallFork(msg test.Message) error {
    43  	p := pb.Fork{}
    44  	if err := proto.Unmarshal(msg.Msg, &p); err != nil {
    45  		return err
    46  	}
    47  	if err := checkContextData(p.ContextData); err != nil {
    48  		return err
    49  	}
    50  	return nil
    51  }