diff --git a/go.mod b/go.mod index 543bc6b8a..3eb6d297f 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/spidernet-io/egressgateway go 1.22.5 require ( - github.com/agiledragon/gomonkey/v2 v2.12.0 + github.com/agiledragon/gomonkey/v2 v2.13.0 github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 github.com/cilium/ipam v0.0.0-20220824141044-46ef3d556735 github.com/go-faker/faker/v4 v4.4.2 diff --git a/go.sum b/go.sum index d7cdb3833..d585a214d 100644 --- a/go.sum +++ b/go.sum @@ -55,8 +55,8 @@ github.com/Masterminds/sprig/v3 v3.2.3/go.mod h1:rXcFaZ2zZbLRJv/xSysmlgIM1u11eBa github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46/go.mod h1:3wb06e3pkSAbeQ52E9H9iFoQsEEwGN64994WTCIhntQ= github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE= -github.com/agiledragon/gomonkey/v2 v2.12.0 h1:ek0dYu9K1rSV+TgkW5LvNNPRWyDZVIxGMCFI6Pz9o38= -github.com/agiledragon/gomonkey/v2 v2.12.0/go.mod h1:ap1AmDzcVOAz1YpeJ3TCzIgstoaWLA6jbbgxfB4w2iY= +github.com/agiledragon/gomonkey/v2 v2.13.0 h1:B24Jg6wBI1iB8EFR1c+/aoTg7QN/Cum7YffG8KMIyYo= +github.com/agiledragon/gomonkey/v2 v2.13.0/go.mod h1:ap1AmDzcVOAz1YpeJ3TCzIgstoaWLA6jbbgxfB4w2iY= github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY= github.com/asaskevich/govalidator v0.0.0-20200907205600-7a23bdc65eef/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw= github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 h1:DklsrG3dyBCFEj5IhUbnKptjxatkF07cF2ak3yi77so= diff --git a/vendor/github.com/agiledragon/gomonkey/v2/README.md b/vendor/github.com/agiledragon/gomonkey/v2/README.md index 44bcd58e9..6b63c4ff2 100644 --- a/vendor/github.com/agiledragon/gomonkey/v2/README.md +++ b/vendor/github.com/agiledragon/gomonkey/v2/README.md @@ -26,6 +26,7 @@ gomonkey is a library to make monkey patching in unit tests easy, and the core i - arm64 - 386 - loong64 + - riscv64 - OS - Linux diff --git a/vendor/github.com/agiledragon/gomonkey/v2/jmp_riscv64.go b/vendor/github.com/agiledragon/gomonkey/v2/jmp_riscv64.go new file mode 100644 index 000000000..a2f1ea9e0 --- /dev/null +++ b/vendor/github.com/agiledragon/gomonkey/v2/jmp_riscv64.go @@ -0,0 +1,105 @@ +package gomonkey + +import ( + "encoding/binary" +) + +// buildJmpDirective 为 riscv64 架构生成一段跳转指令, +// 将传入的 64 位地址加载到寄存器 x6(t1)中, +// 然后执行 JALR x0, 0(x6) 实现无条件跳转。 +func buildJmpDirective(double uintptr) []byte { + var res []byte + // 将地址转换为 64 位无符号整数 + d := uint64(double) + // 将 64 位地址拆分成若干部分: + // imm0: 位 [7:0] + // imm1: 位 [19:8] (12 位) + // imm2: 位 [31:20] (12 位) + // imm3: 位 [43:32] (12 位) + // imm4: 位 [63:44] (20 位) + imm0 := d & 0xff + imm1 := (d >> 8) & 0xfff + imm2 := (d >> 20) & 0xfff + imm3 := (d >> 32) & 0xfff + imm4 := (d >> 44) & 0xfffff + + // 依次生成指令: + // 1. LUI x6, imm4 // 将最高 20 位加载到 x6 + res = append(res, encodeLUI(6, uint32(imm4))...) + // 2. ADDI x6, x6, imm3 // 加载接下来的 12 位 + res = append(res, encodeADDI(6, 6, int32(imm3))...) + // 3. SLLI x6, x6, 12 // 左移 12 位 + res = append(res, encodeSLLI(6, 6, 12)...) + // 4. ADDI x6, x6, imm2 // 加载接下来的 12 位 + res = append(res, encodeADDI(6, 6, int32(imm2))...) + // 5. SLLI x6, x6, 12 // 再次左移 12 位 + res = append(res, encodeSLLI(6, 6, 12)...) + // 6. ADDI x6, x6, imm1 // 加载接下来的 12 位 + res = append(res, encodeADDI(6, 6, int32(imm1))...) + // 7. SLLI x6, x6, 8 // 左移 8 位 + res = append(res, encodeSLLI(6, 6, 8)...) + // 8. ORI x6, x6, imm0 // 最后加载最低 8 位 + res = append(res, encodeORI(6, 6, int32(imm0))...) + // 9. JALR x0, 0(x6) // 跳转到 x6 指定的地址 + res = append(res, encodeJALR(0, 6, 0)...) + + return res +} + +// 以下辅助函数生成各条指令的机器码,均返回 4 字节小端表示。 + +// LUI 指令格式: +// 31 12 11 7 6 0 +// [ imm[31:12] ] [ rd ] [ opcode ] +// opcode LUI 为 0x37。 +func encodeLUI(rd int, imm20 uint32) []byte { + inst := (imm20 << 12) | (uint32(rd) << 7) | 0x37 + res := make([]byte, 4) + binary.LittleEndian.PutUint32(res, inst) + return res +} + +// ADDI 指令格式(用于加载 12 位立即数): +// 31 20 19 15 14 12 11 7 6 0 +// [ imm[11:0] ] [ rs1 ] [funct3] [ rd ] [ opcode ] +// opcode ADDI 为 0x13,funct3 为 0。 +func encodeADDI(rd, rs1 int, imm int32) []byte { + inst := ((uint32(imm) & 0xfff) << 20) | (uint32(rs1) << 15) | (uint32(rd) << 7) | 0x13 + res := make([]byte, 4) + binary.LittleEndian.PutUint32(res, inst) + return res +} + +// SLLI 指令格式: +// 31 26 25 20 19 15 14 12 11 7 6 0 +// [ 0 ] [ shamt ] [ rs1 ] [funct3] [ rd ] [ opcode ] +// opcode 为 0x13,funct3 为 1。 +func encodeSLLI(rd, rs1, shamt int) []byte { + inst := (uint32(shamt) << 20) | (uint32(rs1) << 15) | (1 << 12) | (uint32(rd) << 7) | 0x13 + res := make([]byte, 4) + binary.LittleEndian.PutUint32(res, inst) + return res +} + +// ORI 指令格式: +// 31 20 19 15 14 12 11 7 6 0 +// [ imm[11:0] ] [ rs1 ] [funct3] [ rd ] [ opcode ] +// opcode 为 0x13,funct3 为 6。 +func encodeORI(rd, rs1 int, imm int32) []byte { + inst := ((uint32(imm) & 0xfff) << 20) | (uint32(rs1) << 15) | (6 << 12) | (uint32(rd) << 7) | 0x13 + res := make([]byte, 4) + binary.LittleEndian.PutUint32(res, inst) + return res +} + +// JALR 指令格式: +// 31 20 19 15 14 12 11 7 6 0 +// [ imm[11:0] ] [ rs1 ] [funct3] [ rd ] [ opcode ] +// opcode 为 0x67,funct3 为 0。 +// JALR x0, 0(x6) 用于无条件跳转。 +func encodeJALR(rd, rs1 int, imm int32) []byte { + inst := ((uint32(imm) & 0xfff) << 20) | (uint32(rs1) << 15) | (uint32(rd) << 7) | 0x67 + res := make([]byte, 4) + binary.LittleEndian.PutUint32(res, inst) + return res +} diff --git a/vendor/modules.txt b/vendor/modules.txt index bcf5632aa..03654398c 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -7,7 +7,7 @@ github.com/Masterminds/semver/v3 # github.com/Masterminds/sprig/v3 v3.2.3 ## explicit; go 1.13 github.com/Masterminds/sprig/v3 -# github.com/agiledragon/gomonkey/v2 v2.12.0 +# github.com/agiledragon/gomonkey/v2 v2.13.0 ## explicit; go 1.14 github.com/agiledragon/gomonkey/v2 github.com/agiledragon/gomonkey/v2/creflect