mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-10-27 12:48:22 +00:00
syscalls: isatty
This commit is contained in:
@@ -22,6 +22,7 @@ extern syscall_dup3
|
|||||||
extern syscall_fcntl
|
extern syscall_fcntl
|
||||||
extern syscall_chdir
|
extern syscall_chdir
|
||||||
extern syscall_pipe2
|
extern syscall_pipe2
|
||||||
|
extern syscall_isatty
|
||||||
syscalltab:
|
syscalltab:
|
||||||
dq syscall_print
|
dq syscall_print
|
||||||
dq syscall_mmap
|
dq syscall_mmap
|
||||||
@@ -46,7 +47,8 @@ dq syscall_dup3
|
|||||||
dq syscall_fcntl
|
dq syscall_fcntl
|
||||||
dq syscall_chdir
|
dq syscall_chdir
|
||||||
dq syscall_pipe2
|
dq syscall_pipe2
|
||||||
syscallcount equ 23
|
dq syscall_isatty
|
||||||
|
syscallcount equ 24
|
||||||
section .text
|
section .text
|
||||||
global arch_syscall_entry
|
global arch_syscall_entry
|
||||||
; on entry:
|
; on entry:
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
#include <arch/e9.h>
|
#include <arch/e9.h>
|
||||||
#include <arch/cpu.h>
|
#include <arch/cpu.h>
|
||||||
|
|
||||||
#define SYSCALL_COUNT 23
|
#define SYSCALL_COUNT 24
|
||||||
#define LOGSTR(x) arch_e9_puts(x)
|
#define LOGSTR(x) arch_e9_puts(x)
|
||||||
|
|
||||||
static char *name[] = {
|
static char *name[] = {
|
||||||
@@ -28,7 +28,8 @@ static char *name[] = {
|
|||||||
"dup3",
|
"dup3",
|
||||||
"fcntl",
|
"fcntl",
|
||||||
"chdir",
|
"chdir",
|
||||||
"pipe2"
|
"pipe2",
|
||||||
|
"isatty"
|
||||||
};
|
};
|
||||||
|
|
||||||
static char *args[] = {
|
static char *args[] = {
|
||||||
@@ -55,6 +56,7 @@ static char *args[] = {
|
|||||||
"fd %d cmd %d arg %lu", // fcntl
|
"fd %d cmd %d arg %lu", // fcntl
|
||||||
"path %s", // chdir
|
"path %s", // chdir
|
||||||
"flags %d", // pipe2
|
"flags %d", // pipe2
|
||||||
|
"fd %d", // isatty
|
||||||
};
|
};
|
||||||
|
|
||||||
__attribute__((no_caller_saved_registers)) void arch_syscall_log(int syscall, uint64_t a1, uint64_t a2, uint64_t a3, uint64_t a4, uint64_t a5, uint64_t a6) {
|
__attribute__((no_caller_saved_registers)) void arch_syscall_log(int syscall, uint64_t a1, uint64_t a2, uint64_t a3, uint64_t a4, uint64_t a5, uint64_t a6) {
|
||||||
|
|||||||
+10
-1
@@ -183,6 +183,14 @@ int devfs_access(vnode_t *node, mode_t mode, cred_t *cred) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int devfs_isatty(vnode_t *node) {
|
||||||
|
devnode_t *devnode = (devnode_t *)node;
|
||||||
|
if (devnode->master)
|
||||||
|
devnode = devnode->master;
|
||||||
|
|
||||||
|
return devnode->devops->isatty ? devnode->devops->isatty(devnode->attr.rdevminor) : ENOTTY;
|
||||||
|
}
|
||||||
|
|
||||||
int devfs_inactive(vnode_t *node) {
|
int devfs_inactive(vnode_t *node) {
|
||||||
VOP_LOCK(node);
|
VOP_LOCK(node);
|
||||||
devnode_t *devnode = (devnode_t *)node;
|
devnode_t *devnode = (devnode_t *)node;
|
||||||
@@ -304,7 +312,8 @@ static vops_t vnops = {
|
|||||||
.inactive = devfs_enodev,
|
.inactive = devfs_enodev,
|
||||||
.mmap = devfs_mmap,
|
.mmap = devfs_mmap,
|
||||||
.munmap = devfs_munmap,
|
.munmap = devfs_munmap,
|
||||||
.getdents = devfs_getdents
|
.getdents = devfs_getdents,
|
||||||
|
.isatty = devfs_isatty
|
||||||
};
|
};
|
||||||
|
|
||||||
static void ctor(scache_t *cache, void *obj) {
|
static void ctor(scache_t *cache, void *obj) {
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ typedef struct {
|
|||||||
int (*poll)(int minor, int events);
|
int (*poll)(int minor, int events);
|
||||||
int (*mmap)(int minor, void *addr, uintmax_t offset, int flags);
|
int (*mmap)(int minor, void *addr, uintmax_t offset, int flags);
|
||||||
int (*munmap)(int minor, void *addr, uintmax_t offset, int flags);
|
int (*munmap)(int minor, void *addr, uintmax_t offset, int flags);
|
||||||
|
int (*isatty)(int minor);
|
||||||
} devops_t;
|
} devops_t;
|
||||||
|
|
||||||
typedef struct devnode_t {
|
typedef struct devnode_t {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <kernel/abi.h>
|
#include <kernel/abi.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uid_t uid;
|
uid_t uid;
|
||||||
@@ -90,6 +91,7 @@ typedef struct vops_t {
|
|||||||
int (*mmap)(vnode_t *node, void *addr, uintmax_t offset, int flags, cred_t *cred);
|
int (*mmap)(vnode_t *node, void *addr, uintmax_t offset, int flags, cred_t *cred);
|
||||||
int (*munmap)(vnode_t *node, void *addr, uintmax_t offset, int flags, cred_t *cred);
|
int (*munmap)(vnode_t *node, void *addr, uintmax_t offset, int flags, cred_t *cred);
|
||||||
int (*getdents)(vnode_t *node, dent_t *buffer, size_t count, uintmax_t offset, size_t *readcount);
|
int (*getdents)(vnode_t *node, dent_t *buffer, size_t count, uintmax_t offset, size_t *readcount);
|
||||||
|
int (*isatty)(vnode_t *node);
|
||||||
} vops_t;
|
} vops_t;
|
||||||
|
|
||||||
#define VFS_MOUNT(vfs, mp, b, d) (vfs)->ops->mount(vfs, mp, b, d)
|
#define VFS_MOUNT(vfs, mp, b, d) (vfs)->ops->mount(vfs, mp, b, d)
|
||||||
@@ -116,7 +118,8 @@ typedef struct vops_t {
|
|||||||
#define VOP_MMAP(v, a, o, f, c) (v)->ops->mmap(v, a, o, f, c)
|
#define VOP_MMAP(v, a, o, f, c) (v)->ops->mmap(v, a, o, f, c)
|
||||||
#define VOP_MUNMAP(v, a, o, f, c) (v)->ops->munmap(v, a, o, f, c)
|
#define VOP_MUNMAP(v, a, o, f, c) (v)->ops->munmap(v, a, o, f, c)
|
||||||
#define VOP_GETDENTS(v, b, c, o, rc) (v)->ops->getdents(v, b, c, o, rc)
|
#define VOP_GETDENTS(v, b, c, o, rc) (v)->ops->getdents(v, b, c, o, rc)
|
||||||
#define VOP_POLL(v, p) (v)->ops->poll(v, p);
|
#define VOP_POLL(v, p) (v)->ops->poll(v, p)
|
||||||
|
#define VOP_ISATTY(v) ((v)->ops->isatty ? (v)->ops->isatty(v) : ENOTTY)
|
||||||
#define VOP_HOLD(v) __atomic_add_fetch(&(v)->refcount, 1, __ATOMIC_SEQ_CST)
|
#define VOP_HOLD(v) __atomic_add_fetch(&(v)->refcount, 1, __ATOMIC_SEQ_CST)
|
||||||
#define VOP_RELEASE(v) {\
|
#define VOP_RELEASE(v) {\
|
||||||
if (__atomic_sub_fetch(&(v)->refcount, 1, __ATOMIC_SEQ_CST) == 0) {\
|
if (__atomic_sub_fetch(&(v)->refcount, 1, __ATOMIC_SEQ_CST) == 0) {\
|
||||||
|
|||||||
@@ -153,9 +153,14 @@ static int write(int minor, void *buffer, size_t size, uintmax_t offset, int fla
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int isatty(int minor) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static devops_t devops = {
|
static devops_t devops = {
|
||||||
.write = write,
|
.write = write,
|
||||||
.read = read
|
.read = read,
|
||||||
|
.isatty = isatty
|
||||||
};
|
};
|
||||||
|
|
||||||
void console_init() {
|
void console_init() {
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
#include <kernel/syscalls.h>
|
||||||
|
#include <kernel/vfs.h>
|
||||||
|
#include <kernel/file.h>
|
||||||
|
|
||||||
|
syscallret_t syscall_isatty(context_t *context, int fd) {
|
||||||
|
syscallret_t ret = {
|
||||||
|
.ret = -1
|
||||||
|
};
|
||||||
|
|
||||||
|
file_t *file = fd_get(fd);
|
||||||
|
if (file == NULL) {
|
||||||
|
ret.errno = EBADF;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
// mlibc expects isatty to return 1 if a terminal and 0 if not.
|
||||||
|
int e = VOP_ISATTY(file->vnode);
|
||||||
|
|
||||||
|
ret.errno = e;
|
||||||
|
ret.ret = e ? 0 : 1;
|
||||||
|
|
||||||
|
fd_release(file);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
@@ -133,7 +133,7 @@ index 0000000..e5b087a
|
|||||||
+
|
+
|
||||||
diff --git mlibc-workdir/sysdeps/astral/generic/generic.cpp mlibc-workdir/sysdeps/astral/generic/generic.cpp
|
diff --git mlibc-workdir/sysdeps/astral/generic/generic.cpp mlibc-workdir/sysdeps/astral/generic/generic.cpp
|
||||||
new file mode 100644
|
new file mode 100644
|
||||||
index 0000000..e76adfd
|
index 0000000..6b6d167
|
||||||
--- /dev/null
|
--- /dev/null
|
||||||
+++ mlibc-workdir/sysdeps/astral/generic/generic.cpp
|
+++ mlibc-workdir/sysdeps/astral/generic/generic.cpp
|
||||||
@@ -0,0 +1,246 @@
|
@@ -0,0 +1,246 @@
|
||||||
@@ -372,8 +372,8 @@ index 0000000..e76adfd
|
|||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
+ int sys_isatty(int fd) {
|
+ int sys_isatty(int fd) {
|
||||||
+ // TODO UNSTUB
|
+ long ret;
|
||||||
+ return 0;
|
+ return syscall(SYSCALL_ISATTY, &ret, fd);
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
+ int sys_clock_get(int clock, time_t *secs, long *nanos) {
|
+ int sys_clock_get(int clock, time_t *secs, long *nanos) {
|
||||||
@@ -402,10 +402,10 @@ index 0000000..990eca0
|
|||||||
+#endif
|
+#endif
|
||||||
diff --git mlibc-workdir/sysdeps/astral/include/astral/syscall.h mlibc-workdir/sysdeps/astral/include/astral/syscall.h
|
diff --git mlibc-workdir/sysdeps/astral/include/astral/syscall.h mlibc-workdir/sysdeps/astral/include/astral/syscall.h
|
||||||
new file mode 100644
|
new file mode 100644
|
||||||
index 0000000..e432092
|
index 0000000..09c7dd4
|
||||||
--- /dev/null
|
--- /dev/null
|
||||||
+++ mlibc-workdir/sysdeps/astral/include/astral/syscall.h
|
+++ mlibc-workdir/sysdeps/astral/include/astral/syscall.h
|
||||||
@@ -0,0 +1,46 @@
|
@@ -0,0 +1,47 @@
|
||||||
+#ifndef _SYSCALL_H_INCLUDE
|
+#ifndef _SYSCALL_H_INCLUDE
|
||||||
+#define _SYSCALL_H_INCLUDE
|
+#define _SYSCALL_H_INCLUDE
|
||||||
+
|
+
|
||||||
@@ -432,6 +432,7 @@ index 0000000..e432092
|
|||||||
+#define SYSCALL_FCNTL 20
|
+#define SYSCALL_FCNTL 20
|
||||||
+#define SYSCALL_CHDIR 21
|
+#define SYSCALL_CHDIR 21
|
||||||
+#define SYSCALL_PIPE2 22
|
+#define SYSCALL_PIPE2 22
|
||||||
|
+#define SYSCALL_ISATTY 23
|
||||||
+
|
+
|
||||||
+#include <stddef.h>
|
+#include <stddef.h>
|
||||||
+#include <stdint.h>
|
+#include <stdint.h>
|
||||||
|
|||||||
Reference in New Issue
Block a user