@ebowwa/bun-native-page 0.2.1 → 0.2.3
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/dist/index.ts +20 -20
- package/package.json +1 -1
package/dist/index.ts
CHANGED
|
@@ -223,14 +223,14 @@ export function allocPageAligned(
|
|
|
223
223
|
let freed = false;
|
|
224
224
|
|
|
225
225
|
return {
|
|
226
|
-
ptr: BigInt(actualPtr
|
|
226
|
+
ptr: BigInt(ptr(actualPtr)),
|
|
227
227
|
size,
|
|
228
228
|
allocatedSize: actualSize,
|
|
229
229
|
get buffer() {
|
|
230
230
|
if (freed) {
|
|
231
231
|
throw new PageSizeError('Cannot access freed buffer');
|
|
232
232
|
}
|
|
233
|
-
return toArrayBuffer(actualPtr
|
|
233
|
+
return toArrayBuffer(actualPtr, 0, actualSize);
|
|
234
234
|
},
|
|
235
235
|
free() {
|
|
236
236
|
if (!freed) {
|
|
@@ -273,13 +273,13 @@ export function mmapAnonymous(
|
|
|
273
273
|
let unmapped = false;
|
|
274
274
|
|
|
275
275
|
return {
|
|
276
|
-
ptr: BigInt(actualPtr
|
|
276
|
+
ptr: BigInt(ptr(actualPtr)),
|
|
277
277
|
size: actualSize,
|
|
278
278
|
get buffer() {
|
|
279
279
|
if (unmapped) {
|
|
280
280
|
throw new PageSizeError('Cannot access unmapped region');
|
|
281
281
|
}
|
|
282
|
-
return toArrayBuffer(actualPtr
|
|
282
|
+
return toArrayBuffer(actualPtr, 0, actualSize);
|
|
283
283
|
},
|
|
284
284
|
unmap() {
|
|
285
285
|
if (!unmapped) {
|
|
@@ -292,23 +292,23 @@ export function mmapAnonymous(
|
|
|
292
292
|
},
|
|
293
293
|
protect(prot: MemoryProtection) {
|
|
294
294
|
const protValue = PROTECTION_MAP[prot];
|
|
295
|
-
const result = ffi.mprotect(actualPtr
|
|
295
|
+
const result = ffi.mprotect(ptr(actualPtr), BigInt(actualSize), protValue);
|
|
296
296
|
if (result !== 0) {
|
|
297
297
|
throw new ProtectionError(`mprotect failed with code ${result}`);
|
|
298
298
|
}
|
|
299
299
|
},
|
|
300
300
|
advise(advice: MemoryAdvice) {
|
|
301
301
|
const adviceValue = ADVICE_MAP[advice];
|
|
302
|
-
ffi.madvise(actualPtr
|
|
302
|
+
ffi.madvise(ptr(actualPtr), BigInt(actualSize), adviceValue);
|
|
303
303
|
},
|
|
304
304
|
lock() {
|
|
305
|
-
const result = ffi.mlock(actualPtr
|
|
305
|
+
const result = ffi.mlock(ptr(actualPtr), BigInt(actualSize));
|
|
306
306
|
if (result !== 0) {
|
|
307
307
|
throw new LockError(`mlock failed with code ${result}`);
|
|
308
308
|
}
|
|
309
309
|
},
|
|
310
310
|
unlock() {
|
|
311
|
-
const result = ffi.munlock(actualPtr
|
|
311
|
+
const result = ffi.munlock(ptr(actualPtr), BigInt(actualSize));
|
|
312
312
|
if (result !== 0) {
|
|
313
313
|
throw new LockError(`munlock failed with code ${result}`);
|
|
314
314
|
}
|
|
@@ -346,13 +346,13 @@ export function mmapFile(
|
|
|
346
346
|
let unmapped = false;
|
|
347
347
|
|
|
348
348
|
return {
|
|
349
|
-
ptr: BigInt(actualPtr
|
|
349
|
+
ptr: BigInt(ptr(actualPtr)),
|
|
350
350
|
size: actualSize,
|
|
351
351
|
get buffer() {
|
|
352
352
|
if (unmapped) {
|
|
353
353
|
throw new PageSizeError('Cannot access unmapped region');
|
|
354
354
|
}
|
|
355
|
-
return toArrayBuffer(actualPtr
|
|
355
|
+
return toArrayBuffer(actualPtr, 0, actualSize);
|
|
356
356
|
},
|
|
357
357
|
unmap() {
|
|
358
358
|
if (!unmapped) {
|
|
@@ -362,17 +362,17 @@ export function mmapFile(
|
|
|
362
362
|
},
|
|
363
363
|
protect(prot: MemoryProtection) {
|
|
364
364
|
const protValue = PROTECTION_MAP[prot];
|
|
365
|
-
ffi.mprotect(actualPtr
|
|
365
|
+
ffi.mprotect(ptr(actualPtr), BigInt(actualSize), protValue);
|
|
366
366
|
},
|
|
367
367
|
advise(advice: MemoryAdvice) {
|
|
368
368
|
const adviceValue = ADVICE_MAP[advice];
|
|
369
|
-
ffi.madvise(actualPtr
|
|
369
|
+
ffi.madvise(ptr(actualPtr), BigInt(actualSize), adviceValue);
|
|
370
370
|
},
|
|
371
371
|
lock() {
|
|
372
|
-
ffi.mlock(actualPtr
|
|
372
|
+
ffi.mlock(ptr(actualPtr), BigInt(actualSize));
|
|
373
373
|
},
|
|
374
374
|
unlock() {
|
|
375
|
-
ffi.munlock(actualPtr
|
|
375
|
+
ffi.munlock(ptr(actualPtr), BigInt(actualSize));
|
|
376
376
|
},
|
|
377
377
|
};
|
|
378
378
|
}
|
|
@@ -401,13 +401,13 @@ export function mmapHuge(size: number): MappedRegion | null {
|
|
|
401
401
|
let unmapped = false;
|
|
402
402
|
|
|
403
403
|
return {
|
|
404
|
-
ptr: BigInt(actualPtr
|
|
404
|
+
ptr: BigInt(ptr(actualPtr)),
|
|
405
405
|
size: actualSize,
|
|
406
406
|
get buffer() {
|
|
407
407
|
if (unmapped) {
|
|
408
408
|
throw new PageSizeError('Cannot access unmapped region');
|
|
409
409
|
}
|
|
410
|
-
return toArrayBuffer(actualPtr
|
|
410
|
+
return toArrayBuffer(actualPtr, 0, actualSize);
|
|
411
411
|
},
|
|
412
412
|
unmap() {
|
|
413
413
|
if (!unmapped) {
|
|
@@ -417,17 +417,17 @@ export function mmapHuge(size: number): MappedRegion | null {
|
|
|
417
417
|
},
|
|
418
418
|
protect(prot: MemoryProtection) {
|
|
419
419
|
const protValue = PROTECTION_MAP[prot];
|
|
420
|
-
ffi.mprotect(actualPtr
|
|
420
|
+
ffi.mprotect(ptr(actualPtr), BigInt(actualSize), protValue);
|
|
421
421
|
},
|
|
422
422
|
advise(advice: MemoryAdvice) {
|
|
423
423
|
const adviceValue = ADVICE_MAP[advice];
|
|
424
|
-
ffi.madvise(actualPtr
|
|
424
|
+
ffi.madvise(ptr(actualPtr), BigInt(actualSize), adviceValue);
|
|
425
425
|
},
|
|
426
426
|
lock() {
|
|
427
|
-
ffi.mlock(actualPtr
|
|
427
|
+
ffi.mlock(ptr(actualPtr), BigInt(actualSize));
|
|
428
428
|
},
|
|
429
429
|
unlock() {
|
|
430
|
-
ffi.munlock(actualPtr
|
|
430
|
+
ffi.munlock(ptr(actualPtr), BigInt(actualSize));
|
|
431
431
|
},
|
|
432
432
|
};
|
|
433
433
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ebowwa/bun-native-page",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "Cross-platform page-size aware memory operations for Bun - BufferPool, PageArena, mmap/munmap, mlock, mprotect, Windows file mapping",
|
|
5
5
|
"main": "dist/index.ts",
|
|
6
6
|
"exports": {
|