use bytes instead of string, switch instead of slices

This commit is contained in:
Mauri de Souza Meneguzzo
2024-09-26 21:54:52 -03:00
parent e8502b93d8
commit ed9db1a77d

View File

@@ -8,11 +8,11 @@ package main
import (
"bufio"
"bytes"
"fmt"
"os"
"os/exec"
"regexp"
"slices"
"sort"
"strconv"
"strings"
@@ -127,16 +127,17 @@ func main() {
os.Exit(1)
}
if slices.Contains([]string{"riscv64", "loong64", "arm64"}, goarch) {
// Kernel linux v6.11 removed some __NR_* constants that only
switch goarch {
case "riscv64", "loong64", "arm64":
// Kernel linux v6.11 removed some __NR_* macros that only
// existed on some architectures as an implementation detail. In
// order to keep backwards compatibility we add them back.
//
// See https://lkml.org/lkml/2024/8/5/1283
if !strings.Contains(string(cmd), "#define __NR_arch_specific_syscall") {
// See https://lkml.org/lkml/2024/8/5/1283.
if !bytes.Contains(cmd, []byte("#define __NR_arch_specific_syscall")) {
cmd = append(cmd, []byte("#define __NR_arch_specific_syscall 244\n")...)
}
if !strings.Contains(string(cmd), "#define __NR_fstatat") {
if !bytes.Contains(cmd, []byte("#define __NR_fstatat")) {
cmd = append(cmd, []byte("#define __NR_fstatat 79\n")...)
}
}