Files
bare-operating-system/packages/bare-os-booter/lib/posix/bare-os-posix-signals.js
T
2026-08-18 18:11:28 -04:00

89 lines
1.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* POSIX.1 Issue 7 signal names accepted by synthetic `kill` / `ctx.bareOsSendSignal`
* (delivery is logical; many only update guest state without host semantics).
*/
export const BARE_OS_POSIX_SIGNAL_NAMES = Object.freeze([
'HUP',
'INT',
'QUIT',
'ILL',
'TRAP',
'ABRT',
'BUS',
'FPE',
'KILL',
'USR1',
'SEGV',
'USR2',
'PIPE',
'ALRM',
'TERM',
'STKFLT',
'CHLD',
'CONT',
'STOP',
'TSTP',
'TTIN',
'TTOU',
'URG',
'XCPU',
'XFSZ',
'VTALRM',
'PROF',
'WINCH',
'IO',
'SYS'
])
/** @type {ReadonlySet<string>} */
const SET = new Set(BARE_OS_POSIX_SIGNAL_NAMES)
/**
* @param {string} signal
*/
export function bareOsNormalizeSignalName(signal) {
return String(signal || 'TERM')
.replace(/^SIG/i, '')
.toUpperCase()
}
/**
* @param {string} signal
*/
export function bareOsIsPosixSignalName(signal) {
const s = bareOsNormalizeSignalName(signal)
return SET.has(s) || s === '0'
}
/** POSIX-ish default exit status when that signal terminates a session. */
export const BARE_OS_SIGNAL_EXIT = Object.freeze({
HUP: 1,
INT: 2,
QUIT: 3,
ABRT: 6,
KILL: 9,
SEGV: 11,
ALRM: 14,
TERM: 15,
XCPU: 24,
XFSZ: 25,
VTALRM: 26,
PROF: 27
})
/** Signals that end the Bare OS session when delivered to pids 13. */
export const BARE_OS_SESSION_EXIT_SIGNALS = new Set([
'HUP',
'INT',
'QUIT',
'ABRT',
'KILL',
'TERM',
'SEGV',
'XCPU',
'XFSZ',
'ALRM',
'VTALRM',
'PROF'
])