feat: add is_terminal_attached syscall
This commit is contained in:
@@ -32,6 +32,7 @@ void exit(int code); // Terminate process (nore
|
||||
void yield(); // Yield CPU to scheduler
|
||||
void sleep_ms(uint64_t ms); // Sleep for milliseconds
|
||||
int getpid(); // Get current process ID
|
||||
bool terminal_attached(); // Whether stdout is connected to a userspace terminal
|
||||
int spawn(const char* path, const char* args); // Spawn child, inheriting environment
|
||||
int waitpid(int pid); // Wait for process to exit
|
||||
int kill(int pid); // Kill a process
|
||||
|
||||
@@ -240,6 +240,7 @@ namespace montauk::abi {
|
||||
static constexpr uint64_t SYS_SPAWN_ENV = 173;
|
||||
|
||||
static constexpr uint64_t SYS_LOG_WRITE = 176; // (logMessage) -> 0
|
||||
static constexpr uint64_t SYS_TERMINAL_ATTACHED = 177; // () -> 1 when connected to a userspace terminal
|
||||
|
||||
// Tunable parameters (for SYS_SDR_SETPARAM / SYS_SDR_GETPARAM).
|
||||
static constexpr int SDR_PARAM_FREQ = 0; // center frequency, Hz
|
||||
|
||||
@@ -69,7 +69,7 @@ extern "C" {
|
||||
#define MTK_SYS_TERMSCALE 43
|
||||
#define MTK_SYS_RESOLVE 44
|
||||
#define MTK_SYS_GETRANDOM 45
|
||||
#define MTK_SYS_LOG 46
|
||||
#define MTK_SYS_LOG 46
|
||||
#define MTK_SYS_MOUSESTATE 47
|
||||
#define MTK_SYS_SETMOUSEBOUNDS 48
|
||||
#define MTK_SYS_SPAWN_REDIR 49
|
||||
@@ -200,6 +200,7 @@ extern "C" {
|
||||
#define MTK_SYS_SETSESSION 174
|
||||
#define MTK_SYS_KILLSESSION 175
|
||||
#define MTK_SYS_LOG_WRITE 176
|
||||
#define MTK_SYS_TERMINAL_ATTACHED 177
|
||||
/* @SYSCALLS-END */
|
||||
|
||||
#define MTK_SOCK_TCP 1
|
||||
@@ -419,6 +420,10 @@ static inline int mtk_getpid(void) {
|
||||
return (int)_mtk_syscall0(MTK_SYS_GETPID);
|
||||
}
|
||||
|
||||
static inline int mtk_terminal_attached(void) {
|
||||
return (int)_mtk_syscall0(MTK_SYS_TERMINAL_ATTACHED) != 0;
|
||||
}
|
||||
|
||||
static inline int mtk_spawn(const char *path, const char *args) {
|
||||
return (int)_mtk_syscall2(MTK_SYS_SPAWN, (long)path, (long)args);
|
||||
}
|
||||
|
||||
@@ -438,6 +438,11 @@ namespace montauk {
|
||||
return syscall1(montauk::abi::SYS_LOG_WRITE, (uint64_t)logMessage);
|
||||
}
|
||||
|
||||
// True when stdout is connected to a redirected userspace terminal.
|
||||
inline bool terminal_attached() {
|
||||
return syscall0(montauk::abi::SYS_TERMINAL_ATTACHED) != 0;
|
||||
}
|
||||
|
||||
// I/O redirection
|
||||
inline int spawn_redir(const char* path, const char* args = nullptr) {
|
||||
return (int)syscall2(montauk::abi::SYS_SPAWN_REDIR, (uint64_t)path, (uint64_t)args);
|
||||
|
||||
Reference in New Issue
Block a user