@koromix/koffi-linux-ppc64 3.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,6 @@
1
+ # @koromix/koffi-linux-ppc64
2
+
3
+ This contains the linux-ppc64 binaries for [Koffi](https://koffi.dev), a fast and and easy-to-use dynamic C FFI (foreign function interface) module for Node.js.
4
+
5
+ > [!NOTE]
6
+ > Do not install this package directly, use `npm install koffi` instead.
package/index.js ADDED
@@ -0,0 +1,165 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __copyProps = (to, from, except, desc) => {
8
+ if (from && typeof from === "object" || typeof from === "function") {
9
+ for (let key of __getOwnPropNames(from))
10
+ if (!__hasOwnProp.call(to, key) && key !== except)
11
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
12
+ }
13
+ return to;
14
+ };
15
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
16
+ // If the importer is in node compatibility mode or this is not an ESM
17
+ // file that has been converted to a CommonJS file using a Babel-
18
+ // compatible transform (i.e. "__esModule" has not been set), then set
19
+ // "default" to the CommonJS "module.exports" for node compatibility.
20
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
+ mod
22
+ ));
23
+
24
+ // ../cnoke/src/abi.js
25
+ var import_node_fs = __toESM(require("node:fs"), 1);
26
+ function determineAbi() {
27
+ let abi = process.arch.toString();
28
+ if (abi == "riscv32" || abi == "riscv64") {
29
+ let file = openFile(process.execPath, "r");
30
+ try {
31
+ let header = readElfHeader(file);
32
+ let float_abi = header.e_flags & 6;
33
+ switch (float_abi) {
34
+ case 0:
35
+ {
36
+ }
37
+ break;
38
+ case 2:
39
+ {
40
+ abi += "f";
41
+ }
42
+ break;
43
+ case 4:
44
+ {
45
+ abi += "d";
46
+ }
47
+ break;
48
+ case 6:
49
+ {
50
+ abi += "q";
51
+ }
52
+ break;
53
+ }
54
+ } finally {
55
+ file.close();
56
+ }
57
+ } else if (abi == "arm") {
58
+ let file = openFile(process.execPath, "r");
59
+ try {
60
+ let header = readElfHeader(file);
61
+ if (header.e_flags & 1024) {
62
+ abi += "hf";
63
+ } else if (header.e_flags & 512) {
64
+ abi += "sf";
65
+ } else {
66
+ throw new Error("Unknown ARM floating-point ABI");
67
+ }
68
+ } finally {
69
+ file.close();
70
+ }
71
+ } else if (abi == "ppc64") {
72
+ let file = openFile(process.execPath, "r");
73
+ try {
74
+ let header = readElfHeader(file);
75
+ switch (header.ei_data) {
76
+ case 1:
77
+ {
78
+ abi += "le";
79
+ }
80
+ break;
81
+ case 2:
82
+ {
83
+ abi += "be";
84
+ }
85
+ break;
86
+ default:
87
+ throw new Error("Invalid ELF endianness value");
88
+ }
89
+ } finally {
90
+ file.close();
91
+ }
92
+ }
93
+ return abi;
94
+ }
95
+ function readElfHeader(file, offset = 0) {
96
+ let buf = file.read(offset, 512);
97
+ if (buf.length < 16)
98
+ throw new Error("Truncated header");
99
+ if (buf[0] != 127 || buf[1] != 69 || buf[2] != 76 || buf[3] != 70)
100
+ throw new Error("Invalid magic number");
101
+ if (buf[6] != 1)
102
+ throw new Error("Invalid ELF version");
103
+ if (buf[5] != 1)
104
+ throw new Error("Big-endian architectures are not supported");
105
+ switch (buf[4]) {
106
+ case 1:
107
+ {
108
+ if (buf.length < 68)
109
+ throw new Error("Truncated ELF header");
110
+ return {
111
+ ei_class: 32,
112
+ ei_data: buf[5],
113
+ e_machine: buf.readUInt16LE(18),
114
+ e_flags: buf.readUInt32LE(36),
115
+ e_phoff: buf.readUInt32LE(28),
116
+ e_phentsize: buf.readUInt16LE(42),
117
+ e_phnum: buf.readUInt16LE(44)
118
+ };
119
+ }
120
+ break;
121
+ case 2:
122
+ {
123
+ if (buf.length < 120)
124
+ throw new Error("Truncated ELF header");
125
+ return {
126
+ ei_class: 64,
127
+ ei_data: buf[5],
128
+ e_machine: buf.readUInt16LE(18),
129
+ e_flags: buf.readUInt32LE(48),
130
+ e_phoff: buf.readBigUInt64LE(32),
131
+ e_phentsize: buf.readUInt16LE(54),
132
+ e_phnum: buf.readUInt16LE(56)
133
+ };
134
+ }
135
+ break;
136
+ default:
137
+ throw new Error("Invalid ELF class");
138
+ }
139
+ }
140
+ function openFile(filename2, flags) {
141
+ let fd = import_node_fs.default.openSync(filename2, flags);
142
+ return new FileHandle(fd);
143
+ }
144
+ var FileHandle = class {
145
+ constructor(fd) {
146
+ this.fd = fd;
147
+ }
148
+ close() {
149
+ import_node_fs.default.closeSync(this.fd);
150
+ }
151
+ [Symbol.dispose]() {
152
+ import_node_fs.default.closeSync(this.fd);
153
+ }
154
+ read(offset, len) {
155
+ let buf = Buffer.allocUnsafe(len);
156
+ let read = import_node_fs.default.readSync(this.fd, buf, 0, len, offset);
157
+ return buf.subarray(0, read);
158
+ }
159
+ };
160
+
161
+ // tools/loaders/ppc64.js
162
+ if (determineAbi() != "ppc64le")
163
+ throw new Error("The PowerPC64 prebuild only supports ELFv2 Little-Endian systems");
164
+ var filename = "./linux_ppc64le/koffi.node";
165
+ module.exports = require(filename);
Binary file
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "@koromix/koffi-linux-ppc64",
3
+ "version": "3.3.0",
4
+ "description": "Fast and easy-to-use dynamic C FFI (foreign function interface) for Node.js (@koromix/koffi-linux-ppc64)",
5
+ "author": {
6
+ "name": "Niels Martignène",
7
+ "email": "niels.martignene@protonmail.com",
8
+ "url": "https://koromix.dev/"
9
+ },
10
+ "homepage": "https://koffi.dev/",
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "https://github.com/Koromix/koffi"
14
+ },
15
+ "license": "MIT",
16
+ "funding": "https://liberapay.com/Koromix",
17
+ "main": "./index.js",
18
+ "os": [
19
+ "linux"
20
+ ],
21
+ "cpu": [
22
+ "ppc64"
23
+ ]
24
+ }