select() syscall for character device reads

This commit is contained in:
Mark
2020-01-17 12:53:56 +02:00
parent 4584b22585
commit c1bd980264
8 changed files with 125 additions and 6 deletions
+8
View File
@@ -2,6 +2,9 @@
#include "sys/types.h"
#include "sys/fs/dirent.h"
#include "sys/stat.h"
#include "sys/select.h"
struct timeval;
ssize_t sys_read(int fd, void *buf, size_t lim);
ssize_t sys_write(int fd, const void *buf, size_t lim);
@@ -20,6 +23,11 @@ int sys_rmdir(const char *pathname);
int sys_stat(const char *filename, struct stat *st);
int sys_access(const char *path, int mode);
// XXX: Except timeout is const, as I don't want to modify it
// No one cares about how much time is remaining once
// select() returns, right?
int sys_select(int nfds, fd_set *rd, fd_set *wr, fd_set *exc, struct timeval *timeout);
// TODO: const struct termios *termp, const struct winsize *winp
int sys_openpty(int *master, int *slave);
+2
View File
@@ -1,8 +1,10 @@
#pragma once
#include "sys/types.h"
#include "sys/ring.h"
struct chrdev {
void *dev_data;
struct ring buffer;
ssize_t (*write) (struct chrdev *chr, const void *buf, size_t pos, size_t lim);
ssize_t (*read) (struct chrdev *chr, void *buf, size_t pos, size_t lim);
+30
View File
@@ -0,0 +1,30 @@
#pragma once
struct timeval;
// 64 bits
typedef long int __fd_mask;
#define __NFDBITS (8 * (int) sizeof(__fd_mask))
// TODO: Guess this should be the same as the maximum
// per-process filedes count
#define __FD_SETSIZE 64
typedef struct {
__fd_mask fds_bits[__FD_SETSIZE / __NFDBITS];
} fd_set;
#define FD_SET(fd, fds) \
(fds)->fds_bits[(fd) / __NFDBITS] |= (1ULL << ((fd) % __NFDBITS))
#define FD_ISSET(fd, fds) \
(!!((fds)->fds_bits[(fd) / __NFDBITS] & (1ULL << ((fd) % __NFDBITS))))
#define FD_ZERO(fds) \
for (int __i = 0; __i < (__FD_SETSIZE / __NFDBITS); ++__i) \
(fds)->fds_bits[__i] = 0
#if !defined(__KERNEL__)
// Implemented by libc
int select(int nfds, fd_set *rd, fd_set *wr, fd_set *exc, struct timeval *tv);
#endif
+1
View File
@@ -7,6 +7,7 @@
#define SYSCALL_NR_STAT 4
#define SYSCALL_NR_LSEEK 8
#define SYSCALL_NR_ACCESS 21
#define SYSCALL_NR_SELECT 23
#define SYSCALL_NR_GETCWD 79
#define SYSCALL_NR_CHDIR 80
#define SYSCALL_NR_MKDIR 83