Cleanup kernel options a bit

This commit is contained in:
Mark
2020-08-07 12:53:58 +03:00
parent 8a21e8bf75
commit 236f4e5bf5
9 changed files with 68 additions and 38 deletions
+2
View File
@@ -0,0 +1,2 @@
ENABLE_UNIX=0
ENABLE_NET=0
+8 -16
View File
@@ -7,6 +7,7 @@ ACPICA_OBJ=$(ACPICA_SRC:%.c=$(O)/%.o)
KERNEL_USER_HDR=$(shell find include/user -type f -name "*.h")
KERNEL_DEF=
KERNEL_OBJ=$(O)/arch/amd64/entry.o \
$(O)/arch/amd64/kernel.o \
$(O)/arch/amd64/acpi_osl_mem.o \
@@ -107,12 +108,6 @@ KERNEL_OBJ=$(O)/arch/amd64/entry.o \
$(O)/drivers/usb/device.o \
$(O)/drivers/usb/usbkbd.o \
$(O)/drivers/usb/hub.o \
$(O)/arch/amd64/hw/vesa.o \
$(O)/net/if.o \
$(O)/net/net.o \
$(O)/net/socket.o \
$(O)/net/unix.o \
$(O)/sys/sys_net.o
KERNEL_LDS=arch/amd64/link.ld
KERNEL_HDR=$(shell find include -type f -name "*.h")
@@ -133,8 +128,11 @@ DIRS+=$(O)/arch/amd64/hw \
$(O)/include \
$(ACPICA_DIR)
include etc/KernelOptions.makefile
### Compiler
KERNEL_GIT_VERSION=$(shell git describe --always --tags)
KERNEL_CFLAGS=-Iinclude \
-Iinclude/arch/amd64/acpica \
-I$(O)/include \
@@ -143,7 +141,7 @@ KERNEL_CFLAGS=-Iinclude \
-fno-plt \
-fno-pic \
-DARCH_AMD64 \
-DKERNEL_VERSION_STR=\"testing\" \
-DKERNEL_VERSION_STR=\"$(KERNEL_GIT_VERSION)\" \
-D__KERNEL__ \
-mcmodel=large \
-mno-sse \
@@ -156,13 +154,7 @@ KERNEL_CFLAGS=-Iinclude \
-Wno-unused \
-O0 \
-ggdb \
-Werror \
-DENABLE_UNIX=1 \
-DENABLE_NET=1 \
-DVESA_ENABLE=1 \
-DVESA_WIDTH=640 \
-DVESA_HEIGHT=480 \
-DVESA_DEPTH=32
-Werror $(KERNEL_DEF)
KERNEL_LDFLAGS=-nostdlib \
-fPIE \
-fno-plt \
@@ -182,11 +174,11 @@ $(O)/include/config.h: config.h.in
@echo " CONFIG $@"
@cp $< $@
$(O)/%.o: %.c $(O)/include/config.h $(KERNEL_HDR)
$(O)/%.o: %.c $(O)/include/config.h $(KERNEL_HDR) Kernel.config
@echo " CC $@"
@$(CC) $(KERNEL_CFLAGS) -c -o $@ $<
$(O)/%.o: %.S $(O)/include/config.h $(KERNEL_HDR)
$(O)/%.o: %.S $(O)/include/config.h $(KERNEL_HDR) Kernel.config
@echo " AS $@"
@$(CC) $(KERNEL_CFLAGS) -D__ASM__ -c -o $@ $<
+22
View File
@@ -0,0 +1,22 @@
include Kernel.config
ifeq ($(ENABLE_UNIX),1)
KERNEL_DEF+=-DENABLE_UNIX=1
KERNEL_OBJ+=$(O)/net/unix.o
endif
ifeq ($(ENABLE_NET),1)
KERNEL_DEF+=-DENABLE_NET=1
KERNEL_OBJ+=$(O)/net/if.o \
$(O)/net/net.o \
$(O)/net/socket.o \
$(O)/sys/sys_net.o
endif
ifeq ($(ENABLE_VESA),1)
KERNEL_DEF+=-DVESA_ENABLE=1 \
-DVESA_WIDTH=$(VESA_WIDTH) \
-DVESA_HEIGHT=$(VESA_HEIGHT) \
-DVESA_DEPTH=$(VESA_DEPTH)
KERNEL_OBJ+=$(O)/arch/amd64/hw/vesa.o
endif
+11 -8
View File
@@ -59,7 +59,7 @@ static const char *vfs_path_parent(const char *input, char *dst) {
static int vfs_opendir(struct vfs_ioctx *ctx, struct ofile *fd) {
_assert(ctx);
_assert(fd);
_assert(!(fd->flags & OF_SOCKET));
_assert(!ofile_is_socket(fd));
struct vnode *node = fd->file.vnode;
@@ -97,7 +97,7 @@ static int vfs_opendir(struct vfs_ioctx *ctx, struct ofile *fd) {
int vfs_readdir(struct vfs_ioctx *ctx, struct ofile *fd, struct dirent *ent) {
_assert(ctx);
_assert(fd);
_assert(!(fd->flags & OF_SOCKET));
_assert(!ofile_is_socket(fd));
if (!(fd->flags & OF_DIRECTORY)) {
return -ENOTDIR;
@@ -183,7 +183,10 @@ int vfs_open_vnode(struct vfs_ioctx *ctx, struct ofile *fd, struct vnode *node,
_assert(ctx);
_assert(fd);
_assert(node);
#if defined(ENABLE_NET)
// ??
fd->flags &= ~OF_SOCKET;
#endif
if (node->type == VN_SOCK) {
return -ENODEV;
@@ -480,7 +483,7 @@ int vfs_openat(struct vfs_ioctx *ctx,
void vfs_close(struct vfs_ioctx *ctx, struct ofile *fd) {
_assert(ctx);
_assert(fd);
_assert(!(fd->flags & OF_SOCKET));
_assert(!ofile_is_socket(fd));
_assert(!(fd->refcount));
_assert(fd->file.vnode);
@@ -563,7 +566,7 @@ ssize_t vfs_write(struct vfs_ioctx *ctx, struct ofile *fd, const void *buf, size
ssize_t b;
_assert(fd);
_assert(!(fd->flags & OF_SOCKET));
_assert(!ofile_is_socket(fd));
if (!(fd->flags & OF_WRITABLE) || (fd->flags & OF_DIRECTORY)) {
return -EINVAL;
@@ -601,7 +604,7 @@ ssize_t vfs_read(struct vfs_ioctx *ctx, struct ofile *fd, void *buf, size_t coun
}
_assert(fd);
_assert(!(fd->flags & OF_SOCKET));
_assert(!ofile_is_socket(fd));
node = fd->file.vnode;
@@ -635,12 +638,12 @@ ssize_t vfs_read(struct vfs_ioctx *ctx, struct ofile *fd, void *buf, size_t coun
off_t vfs_lseek(struct vfs_ioctx *ctx, struct ofile *fd, off_t offset, int whence) {
_assert(fd);
_assert(!(fd->flags & OF_SOCKET));
_assert(!ofile_is_socket(fd));
struct vnode *node = fd->file.vnode;
_assert(node);
if (node->type != VN_REG) {
return -EINVAL;
return -ESPIPE;
}
if (!node->op || !node->op->lseek) {
@@ -723,7 +726,7 @@ int vfs_chown(struct vfs_ioctx *ctx, const char *path, uid_t uid, gid_t gid) {
int vfs_ioctl(struct vfs_ioctx *ctx, struct ofile *fd, unsigned int cmd, void *arg) {
_assert(ctx);
_assert(fd);
_assert(!(fd->flags & OF_SOCKET));
_assert(!ofile_is_socket(fd));
struct vnode *node = fd->file.vnode;
_assert(node);
+10 -1
View File
@@ -9,7 +9,6 @@
#define OF_MEMDIR (1 << 3)
#define OF_MEMDIR_DOT (1 << 4)
#define OF_MEMDIR_DOTDOT (1 << 5)
#define OF_SOCKET (1 << 6)
#define OF_CLOEXEC (1 << 7)
struct vfs_ioctx;
@@ -27,6 +26,16 @@ struct ofile {
};
};
#if defined(ENABLE_NET)
#define OF_SOCKET (1 << 6)
static inline int ofile_is_socket(struct ofile *of) {
return !!(of->flags & OF_SOCKET);
}
#else
#define ofile_is_socket(of) 0
#endif
struct ofile *ofile_create(void);
struct ofile *ofile_dup(struct ofile *of);
void ofile_destroy(struct ofile *of);
-1
View File
@@ -115,7 +115,6 @@ static void pipe_vnode_close(struct ofile *of) {
}
static int pipe_vnode_open(struct ofile *of, int opt) {
_assert(!(of->flags & OF_SOCKET));
_assert(of->file.vnode);
// TODO: allow only one reader and many writers
of->file.pos = 0;
+1 -1
View File
@@ -116,7 +116,7 @@ void *sys_mmap(void *hint, size_t length, int prot, int flags, int fd, off_t off
return (void *) -EBADF;
}
if (of->flags & OF_SOCKET) {
if (ofile_is_socket(of)) {
return (void *) -EINVAL;
}
+13 -10
View File
@@ -51,7 +51,7 @@ ssize_t sys_read(int fd, void *data, size_t lim) {
return -EBADF;
}
if (of->flags & OF_SOCKET) {
if (ofile_is_socket(of)) {
kwarn("Invalid operation on socket\n");
return -EINVAL;
}
@@ -67,7 +67,7 @@ ssize_t sys_write(int fd, const void *data, size_t lim) {
return -EBADF;
}
if (of->flags & OF_SOCKET) {
if (ofile_is_socket(of)) {
kwarn("Invalid operation on socket\n");
return -EINVAL;
}
@@ -123,7 +123,7 @@ int sys_ftruncate(int fd, off_t length) {
if (!of) {
return -EBADF;
}
if (of->flags & OF_SOCKET) {
if (ofile_is_socket(of)) {
kwarn("truncate() on socket\n");
return -EINVAL;
}
@@ -197,7 +197,7 @@ int sys_openat(int dfd, const char *filename, int flags, int mode) {
// Set controlling terminal if none present and TTY is opened
// TODO: O_NOCTTY
if (!proc->ctty && !(ofile->flags & OF_SOCKET)) {
if (!proc->ctty && !ofile_is_socket(ofile)) {
struct vnode *node = ofile->file.vnode;
_assert(node);
@@ -352,7 +352,7 @@ off_t sys_lseek(int fd, off_t offset, int whence) {
return -EBADF;
}
if (ofile->flags & OF_SOCKET) {
if (ofile_is_socket(ofile)) {
kwarn("Invalid operation on socket\n");
return -EINVAL;
}
@@ -366,7 +366,7 @@ int sys_ioctl(int fd, unsigned int cmd, void *arg) {
return -EBADF;
}
if (of->flags & OF_SOCKET) {
if (ofile_is_socket(of)) {
kwarn("Invalid operation on socket\n");
return -EINVAL;
}
@@ -382,7 +382,7 @@ ssize_t sys_readdir(int fd, struct dirent *ent) {
return -EBADF;
}
if (of->flags & OF_SOCKET) {
if (ofile_is_socket(of)) {
kwarn("Invalid operation on socket\n");
return -EINVAL;
}
@@ -413,7 +413,7 @@ int sys_mknod(const char *filename, int mode, unsigned int dev) {
static int sys_select_get_ready(struct ofile *fd) {
#if defined(ENABLE_NET)
if (fd->flags & OF_SOCKET) {
if (ofile_is_socket(fd)) {
return socket_has_data(&fd->socket);
} else
#endif
@@ -440,11 +440,14 @@ static int sys_select_get_ready(struct ofile *fd) {
}
static struct io_notify *sys_select_get_wait(struct ofile *fd) {
if (fd->flags & OF_SOCKET) {
#if defined(ENABLE_NET)
if (ofile_is_socket(fd)) {
struct io_notify *res = socket_get_rx_notify(&fd->socket);
_assert(res);
return res;
} else {
} else
#endif
{
struct vnode *vn = fd->file.vnode;
_assert(vn);
+1 -1
View File
@@ -996,7 +996,7 @@ pid_t sys_setsid(void) {
if (proc->ctty) {
// Close current tty filedes
for (size_t i = 0; i < THREAD_MAX_FDS; ++i) {
if (proc->fds[i] && !(proc->fds[i]->flags & OF_SOCKET)) {
if (proc->fds[i] && !ofile_is_socket(proc->fds[i])) {
if (proc->fds[i]->file.vnode == proc->ctty) {
kdebug("setsid: detaching fd %d from #%d (%s)\n", i, proc->pid, proc->name);
ofile_close(&proc->ioctx, proc->fds[i]);