This commit is contained in:
2026-08-18 18:11:28 -04:00
parent 0e9a650fa2
commit bbaf47028f
259 changed files with 0 additions and 0 deletions
@@ -0,0 +1,74 @@
/**
* Logical FD registry, sigaction, and snapshot-handle methods on kernel `ctx`.
*/
import {
bareOsIsPosixSignalName,
bareOsNormalizeSignalName
} from './bare-os-posix-signals.js'
export function createBareOsLogicalFdMethods() {
return {
/**
* @param {number} fd
* @param {string} target
*/
bareOsRegisterLogicalFd(fd, target) {
const n = Number(fd)
if (!Number.isFinite(n) || n < 0 || n > 65535) return
const k = String(n >>> 0)
if (k === '0' || k === '1' || k === '2') return
this.bareOsLogicalFds[k] = String(target || '')
},
/** @param {number} fd */
bareOsUnregisterLogicalFd(fd) {
const k = String(Number(fd) >>> 0)
if (this.bareOsLogicalFds && typeof this.bareOsLogicalFds === 'object') {
delete this.bareOsLogicalFds[k]
}
if (
this.bareOsLogicalFdFlags &&
typeof this.bareOsLogicalFdFlags === 'object'
) {
delete this.bareOsLogicalFdFlags[k]
}
},
/**
* Logical `sigaction`: `IGNORE` suppresses synthetic delivery for this signal.
* @param {string} signal
* @param {'IGNORE' | 'DEFAULT' | 'IGN' | 'DEF'} mode
*/
bareOsSigaction(signal, mode) {
const s = bareOsNormalizeSignalName(signal)
if (!bareOsIsPosixSignalName(signal) || s === '0') {
throw new Error('bareOsSigaction: unsupported signal')
}
const m = String(mode || 'DEFAULT')
.toUpperCase()
.replace(/^SIG/i, '')
if (m === 'DEFAULT' || m === 'DEF') {
if (this.bareOsLogicalSigaction) delete this.bareOsLogicalSigaction[s]
return { ok: true, signal: s, mode: 'DEFAULT' }
}
if (m === 'IGNORE' || m === 'IGN') {
if (!this.bareOsLogicalSigaction) {
throw new Error('bareOsSigaction: internal state missing')
}
this.bareOsLogicalSigaction[s] = 'IGNORE'
return { ok: true, signal: s, mode: 'IGNORE' }
}
throw new Error('bareOsSigaction: mode must be IGNORE or DEFAULT')
},
/** @param {Record<string, unknown>} desc */
bareOsRegisterSnapshotHandle(desc) {
if (!desc || typeof desc !== 'object') return
if (!Array.isArray(this.bareOsSnapshotHandles)) {
this.bareOsSnapshotHandles = []
}
const id =
typeof desc.id === 'string' && desc.id.trim()
? desc.id.trim().slice(0, 128)
: `snap-${this.bareOsSnapshotHandles.length}`
this.bareOsSnapshotHandles.push({ ...desc, id, atMs: Date.now() })
}
}
}