github.com/nicocha30/gvisor-ligolo@v0.0.0-20230726075806-989fa2c0a413/pkg/sentry/strace/futex.go (about)

     1  // Copyright 2018 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  package strace
    16  
    17  import (
    18  	"github.com/nicocha30/gvisor-ligolo/pkg/abi"
    19  	"github.com/nicocha30/gvisor-ligolo/pkg/abi/linux"
    20  )
    21  
    22  // FutexCmd are the possible futex(2) commands.
    23  var FutexCmd = abi.ValueSet{
    24  	linux.FUTEX_WAIT:            "FUTEX_WAIT",
    25  	linux.FUTEX_WAKE:            "FUTEX_WAKE",
    26  	linux.FUTEX_FD:              "FUTEX_FD",
    27  	linux.FUTEX_REQUEUE:         "FUTEX_REQUEUE",
    28  	linux.FUTEX_CMP_REQUEUE:     "FUTEX_CMP_REQUEUE",
    29  	linux.FUTEX_WAKE_OP:         "FUTEX_WAKE_OP",
    30  	linux.FUTEX_LOCK_PI:         "FUTEX_LOCK_PI",
    31  	linux.FUTEX_UNLOCK_PI:       "FUTEX_UNLOCK_PI",
    32  	linux.FUTEX_TRYLOCK_PI:      "FUTEX_TRYLOCK_PI",
    33  	linux.FUTEX_WAIT_BITSET:     "FUTEX_WAIT_BITSET",
    34  	linux.FUTEX_WAKE_BITSET:     "FUTEX_WAKE_BITSET",
    35  	linux.FUTEX_WAIT_REQUEUE_PI: "FUTEX_WAIT_REQUEUE_PI",
    36  	linux.FUTEX_CMP_REQUEUE_PI:  "FUTEX_CMP_REQUEUE_PI",
    37  }
    38  
    39  func futex(op uint64) string {
    40  	cmd := op &^ (linux.FUTEX_PRIVATE_FLAG | linux.FUTEX_CLOCK_REALTIME)
    41  	clockRealtime := (op & linux.FUTEX_CLOCK_REALTIME) == linux.FUTEX_CLOCK_REALTIME
    42  	private := (op & linux.FUTEX_PRIVATE_FLAG) == linux.FUTEX_PRIVATE_FLAG
    43  
    44  	s := FutexCmd.Parse(cmd)
    45  	if clockRealtime {
    46  		s += "|FUTEX_CLOCK_REALTIME"
    47  	}
    48  	if private {
    49  		s += "|FUTEX_PRIVATE_FLAG"
    50  	}
    51  	return s
    52  }