The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 03:37 UTC
| 1 | // TEMPORARY one-time Node fix. Remove when fixed: https://github.com/nodejs/node/issues/67048 |
| 2 | import { describe, expect, it } from "@effect/vitest"; |
| 3 | import { assertLinuxArm64PageCompatibility } from "./linux-arm64-sea.ts"; |
| 4 | |
| 5 | function elf(loads: Array<{ offset: bigint; address: bigint; size: bigint }>) { |
| 6 | const bytes = new Uint8Array(64 + loads.length * 56); |
| 7 | const view = new DataView(bytes.buffer); |
| 8 | bytes.set([0x7f, 0x45, 0x4c, 0x46, 2, 1]); |
| 9 | view.setUint16(18, 183, true); |
| 10 | view.setBigUint64(32, 64n, true); |
| 11 | view.setUint16(54, 56, true); |
| 12 | view.setUint16(56, loads.length, true); |
| 13 | loads.forEach((load, index) => { |
| 14 | const start = 64 + index * 56; |
| 15 | view.setUint32(start, 1, true); |
| 16 | view.setBigUint64(start + 8, load.offset, true); |
| 17 | view.setBigUint64(start + 16, load.address, true); |
| 18 | view.setBigUint64(start + 40, load.size, true); |
| 19 | view.setBigUint64(start + 48, 0x1000n, true); |
| 20 | }); |
| 21 | return bytes; |
| 22 | } |
| 23 | |
| 24 | describe("Linux ARM64 SEA page compatibility", () => { |
| 25 | it("rejects the relocated SEA note from nightly 3512", () => { |
| 26 | expect(() => |
| 27 | assertLinuxArm64PageCompatibility( |
| 28 | elf([{ offset: 0x8faf000n, address: 0x1015d000n, size: 0x1003000n }]), |
| 29 | ), |
| 30 | ).toThrow(/64 KiB/); |
| 31 | }); |
| 32 | |
| 33 | it("accepts congruent offsets even with a smaller declared alignment", () => { |
| 34 | expect(() => |
| 35 | assertLinuxArm64PageCompatibility( |
| 36 | elf([ |
| 37 | { offset: 0n, address: 0x400000n, size: 0x10000n }, |
| 38 | { offset: 0x20000n, address: 0x420000n, size: 0x10000n }, |
| 39 | ]), |
| 40 | ), |
| 41 | ).not.toThrow(); |
| 42 | }); |
| 43 | |
| 44 | it("rejects segments that share a 64 KiB page", () => { |
| 45 | expect(() => |
| 46 | assertLinuxArm64PageCompatibility( |
| 47 | elf([ |
| 48 | { offset: 0n, address: 0x400000n, size: 0x11000n }, |
| 49 | { offset: 0x11000n, address: 0x411000n, size: 0x1000n }, |
| 50 | ]), |
| 51 | ), |
| 52 | ).toThrow(/overlap/); |
| 53 | }); |
| 54 | |
| 55 | it("rejects missing or malformed program headers", () => { |
| 56 | expect(() => assertLinuxArm64PageCompatibility(elf([]))).toThrow(); |
| 57 | expect(() => assertLinuxArm64PageCompatibility(new Uint8Array(64))).toThrow(); |
| 58 | expect(() => |
| 59 | assertLinuxArm64PageCompatibility( |
| 60 | elf([{ offset: 0n, address: 0x400000n, size: 1n }]).subarray(0, 70), |
| 61 | ), |
| 62 | ).toThrow(); |
| 63 | }); |
| 64 | }); |