diff --git a/CMakeLists.txt b/CMakeLists.txt index c5838b12..a2db508e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,8 +5,7 @@ project(nightingale C ASM CXX) unset(CMAKE_SYSROOT) set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/sysroot) set(CMAKE_SYSROOT ${CMAKE_BINARY_DIR}/sysroot) -set(CMAKE_C_STANDARD 11) -set(CMAKE_CXX_STANDARD 23) +set(CMAKE_C_STANDARD 23) execute_process( COMMAND git describe --tags @@ -54,8 +53,6 @@ add_compile_options( -Wno-sign-compare -Wno-address-of-packed-member -Wno-deprecated-non-prototype - $<$:-fno-exceptions> - $<$:-fno-rtti> ) if ($ENV{ENABLE_WERROR}) diff --git a/include/arpa/inet.h b/include/arpa/inet.h index 23769e6a..0e40155b 100644 --- a/include/arpa/inet.h +++ b/include/arpa/inet.h @@ -24,4 +24,3 @@ static inline uint16_t ntohs(uint16_t netshort) { } END_DECLS - diff --git a/include/assert.h b/include/assert.h index b94f9bc6..237cd7f8 100644 --- a/include/assert.h +++ b/include/assert.h @@ -32,4 +32,3 @@ #define assert(...) #define _UNREACHABLE() #endif // NDEBUG - diff --git a/include/ctype.h b/include/ctype.h index 6f6bb462..d07e0275 100644 --- a/include/ctype.h +++ b/include/ctype.h @@ -20,4 +20,3 @@ int toupper(int c); int tolower(int c); END_DECLS - diff --git a/include/dirent.h b/include/dirent.h index 39d1169b..f0fdd356 100644 --- a/include/dirent.h +++ b/include/dirent.h @@ -22,4 +22,3 @@ ssize_t readdir(int fd, struct dirent *buf, size_t size); #endif END_DECLS - diff --git a/include/dlfcn.h b/include/dlfcn.h index 45dcbb04..6f70f09b 100644 --- a/include/dlfcn.h +++ b/include/dlfcn.h @@ -1,3 +1 @@ #pragma once - - diff --git a/include/elf.h b/include/elf.h index d1f9fe49..12c351e7 100644 --- a/include/elf.h +++ b/include/elf.h @@ -296,4 +296,3 @@ void limine_load_kernel_elf(void *ptr, size_t len); #endif END_DECLS - diff --git a/include/endian.h b/include/endian.h index 88f14a1a..fc295e1d 100644 --- a/include/endian.h +++ b/include/endian.h @@ -3,4 +3,3 @@ #define BIG_ENDIAN 1 #define LITTLE_ENDIAN 2 #define BYTE_ORDER LITTLE_ENDIAN - diff --git a/include/errno.h b/include/errno.h index 00a36c40..06a46eae 100644 --- a/include/errno.h +++ b/include/errno.h @@ -17,4 +17,3 @@ char *strerror(int errno); #endif // __kernel__ END_DECLS - diff --git a/include/fcntl.h b/include/fcntl.h index 7ff8dbbe..88857dbc 100644 --- a/include/fcntl.h +++ b/include/fcntl.h @@ -98,4 +98,3 @@ int openat(int atfd, const char *filename, int flags, ...); // int open(const char *filename, int flags, int mode); END_DECLS - diff --git a/include/internals/math.h b/include/internals/math.h index 2ab3c656..7bc349c0 100644 --- a/include/internals/math.h +++ b/include/internals/math.h @@ -71,4 +71,3 @@ typedef long double __double_t; #endif #endif - diff --git a/include/internals/types.h b/include/internals/types.h index 492c59a9..ad633ca5 100644 --- a/include/internals/types.h +++ b/include/internals/types.h @@ -11,4 +11,3 @@ typedef int8_t __int8_t; typedef int16_t __int16_t; typedef int32_t __int32_t; typedef int64_t __int64_t; - diff --git a/include/inttypes.h b/include/inttypes.h index 705ca6dc..17563562 100644 --- a/include/inttypes.h +++ b/include/inttypes.h @@ -43,4 +43,3 @@ #define PRIo64 "%lo" #define PRIoMAX "%zo" #define PRIoPTR "%zo" - diff --git a/include/limine.h b/include/limine.h index 7d4eb02e..05dc137c 100644 --- a/include/limine.h +++ b/include/limine.h @@ -513,4 +513,3 @@ struct limine_dtb_request { #endif #endif - diff --git a/include/list.h b/include/list.h index 12cae511..5ede5c6b 100644 --- a/include/list.h +++ b/include/list.h @@ -90,4 +90,3 @@ static inline list_node *list_pop_front(list_node *head) { } END_DECLS - diff --git a/include/locale.h b/include/locale.h index 66a0049a..8366bb44 100644 --- a/include/locale.h +++ b/include/locale.h @@ -43,4 +43,3 @@ struct lconv *localeconv(void); char *setlocale(int category, const char *locale); END_DECLS - diff --git a/include/net/eth.h b/include/net/eth.h index 60c14400..0e33a9af 100644 --- a/include/net/eth.h +++ b/include/net/eth.h @@ -16,4 +16,3 @@ struct eth_hdr { #define ETH_TYPE_IP 0x0800 END_DECLS - diff --git a/include/net/ip4.h b/include/net/ip4.h index 40a2a900..ce55b7a0 100644 --- a/include/net/ip4.h +++ b/include/net/ip4.h @@ -25,4 +25,3 @@ struct ip4_hdr { #define IP4_PROTOCOL_UDP 17 END_DECLS - diff --git a/include/net/udp.h b/include/net/udp.h index b58ebb03..b0f319d7 100644 --- a/include/net/udp.h +++ b/include/net/udp.h @@ -13,4 +13,3 @@ struct udp_hdr { }; END_DECLS - diff --git a/include/ng/arch.h b/include/ng/arch.h index 38664393..0b03824c 100644 --- a/include/ng/arch.h +++ b/include/ng/arch.h @@ -11,4 +11,3 @@ void arch_ap_setup(int cpu); void arch_ap_init(void); END_DECLS - diff --git a/include/ng/commandline.h b/include/ng/commandline.h index 7ee4633e..9332887d 100644 --- a/include/ng/commandline.h +++ b/include/ng/commandline.h @@ -8,4 +8,3 @@ void init_command_line(void); const char *get_kernel_argument(const char *key); END_DECLS - diff --git a/include/ng/common.h b/include/ng/common.h index 33068eb2..2d3234d2 100644 --- a/include/ng/common.h +++ b/include/ng/common.h @@ -39,4 +39,3 @@ __auto_type _p = (place); \ (_v + _p - 1) & ~(_p - 1); \ }) - diff --git a/include/ng/cpu.h b/include/ng/cpu.h index d03b2fec..56600601 100644 --- a/include/ng/cpu.h +++ b/include/ng/cpu.h @@ -7,4 +7,3 @@ #endif #include - diff --git a/include/ng/debug.h b/include/ng/debug.h index 9da3068d..62d3a855 100644 --- a/include/ng/debug.h +++ b/include/ng/debug.h @@ -46,4 +46,3 @@ void hexdump(const void *data, size_t len, uintptr_t base_address); __NOINLINE void break_point(void); END_DECLS - diff --git a/include/ng/dmgr.h b/include/ng/dmgr.h index f942d1d4..6bb7c468 100644 --- a/include/ng/dmgr.h +++ b/include/ng/dmgr.h @@ -19,4 +19,3 @@ void *dmgr_set(struct dmgr *d, int handle, void *newptr); void *dmgr_drop(struct dmgr *d, int handle); END_DECLS - diff --git a/include/ng/drv/pci_device.h b/include/ng/drv/pci_device.h index 60a8622b..34f1814b 100644 --- a/include/ng/drv/pci_device.h +++ b/include/ng/drv/pci_device.h @@ -104,4 +104,3 @@ class pci_device { nx::optional pci_find_device( uint16_t vendor_id, uint16_t device_id); - diff --git a/include/ng/drv/rtl8139.h b/include/ng/drv/rtl8139.h index 5a0c04c5..d888db0a 100644 --- a/include/ng/drv/rtl8139.h +++ b/include/ng/drv/rtl8139.h @@ -20,4 +20,3 @@ class rtl8139 : public pci_device { void send_packet(const void *data, size_t len); void recv_packet(void *data, size_t len); }; - diff --git a/include/ng/event_log.h b/include/ng/event_log.h index c376ecc3..90f845cd 100644 --- a/include/ng/event_log.h +++ b/include/ng/event_log.h @@ -22,4 +22,3 @@ void log_event(enum event_type type, const char *message, ...); #endif END_DECLS - diff --git a/include/ng/fs.h b/include/ng/fs.h index fcfaa743..eedcd6ae 100644 --- a/include/ng/fs.h +++ b/include/ng/fs.h @@ -6,8 +6,8 @@ #include #include #include -#include #include +#include #include #include #include @@ -20,4 +20,3 @@ #include #include #include - diff --git a/include/ng/fs/char_dev.h b/include/ng/fs/char_dev.h index c77ff6e7..6ef1640c 100644 --- a/include/ng/fs/char_dev.h +++ b/include/ng/fs/char_dev.h @@ -12,6 +12,6 @@ enum simple_char_devices { FS_DEV_INC, }; -extern struct file_operations *char_drivers[256]; +extern struct file_ops *char_drivers[256]; END_DECLS diff --git a/include/ng/fs/dentry.h b/include/ng/fs/dentry.h index 2f50a52f..70cbaed1 100644 --- a/include/ng/fs/dentry.h +++ b/include/ng/fs/dentry.h @@ -8,7 +8,7 @@ BEGIN_DECLS -struct dentry_operations { +struct dentry_ops { char unused; }; @@ -17,8 +17,8 @@ enum dentry_flags { }; struct dentry { - const struct dentry_operations *ops; - struct inode *inode; + const struct dentry_ops *ops; + struct vnode *vnode; struct dentry *parent; const char *name; enum dentry_flags flags; @@ -35,11 +35,11 @@ struct dentry { extern struct dentry *global_root_dentry; -inline struct inode *dentry_inode(struct dentry *dentry) { +inline struct vnode *dentry_vnode(struct dentry *dentry) { if (dentry->mounted_file_system) { - return dentry->mounted_file_system->root->inode; + return dentry->mounted_file_system->root->vnode; } else { - return dentry->inode; + return dentry->vnode; } } @@ -54,11 +54,11 @@ inline struct file_system *dentry_file_system(struct dentry *dentry) { struct dentry *new_dentry(); struct dentry *add_child( - struct dentry *dentry, const char *name, struct inode *inode); + struct dentry *dentry, const char *name, struct vnode *vnode); struct dentry *find_child(struct dentry *, const char *); struct dentry *unlink_dentry(struct dentry *dentry); -int attach_inode(struct dentry *, struct inode *); -void detach_inode(struct dentry *); +int attach_vnode(struct dentry *, struct vnode *); +void detach_vnode(struct dentry *); void maybe_delete_dentry(struct dentry *); struct dentry *resolve_path(const char *path); @@ -69,4 +69,3 @@ struct dentry *resolve_path_from( int pathname(struct dentry *dentry, char *buffer, size_t len); END_DECLS - diff --git a/include/ng/fs/file.h b/include/ng/fs/file.h index c517861c..0cf0b700 100644 --- a/include/ng/fs/file.h +++ b/include/ng/fs/file.h @@ -9,7 +9,7 @@ BEGIN_DECLS -struct file_operations { +struct file_ops { ssize_t (*read)(struct file *, char *buffer, size_t len); ssize_t (*write)(struct file *, const char *buffer, size_t len); int (*ioctl)(struct file *, int request, void *argp); @@ -17,14 +17,14 @@ struct file_operations { ssize_t (*getdents)(struct file *, struct dirent *, size_t); }; -extern struct file_operations default_file_ops; +extern struct file_ops default_file_ops; struct file { #define FILE_MAGIC 47841728 long magic; struct dentry *dentry; - struct inode *inode; - const struct file_operations *ops; + struct vnode *vnode; + const struct file_ops *ops; enum open_flags flags; off_t offset; @@ -44,17 +44,17 @@ ssize_t default_write(struct file *, const char *, size_t); bool read_mode(struct file *file); bool write_mode(struct file *file); -bool has_permission(struct inode *inode, int flags); -bool read_permission(struct inode *inode); -bool write_permission(struct inode *inode); -bool execute_permission(struct inode *inode); +bool has_permission(struct vnode *vnode, int flags); +bool read_permission(struct vnode *vnode); +bool write_permission(struct vnode *vnode); +bool execute_permission(struct vnode *vnode); ssize_t read_file(struct file *file, char *buffer, size_t len); ssize_t write_file(struct file *file, const char *buffer, size_t len); int ioctl_file(struct file *file, int request, void *argp); off_t seek_file(struct file *file, off_t offset, int whence); ssize_t getdents_file(struct file *file, struct dirent *buf, size_t len); -ssize_t readlink_inode(struct inode *inode, char *buffer, size_t len); +ssize_t readlink_vnode(struct vnode *vnode, char *buffer, size_t len); struct process; struct file *clone_file(struct file *file); diff --git a/include/ng/fs/file_system.h b/include/ng/fs/file_system.h index 4eea1d62..918a2bb0 100644 --- a/include/ng/fs/file_system.h +++ b/include/ng/fs/file_system.h @@ -9,39 +9,38 @@ BEGIN_DECLS extern struct file_system *initfs_file_system; extern struct file_system *proc_file_system; extern list mounted_file_systems; -extern struct file_system_operations default_file_system_ops; +extern struct file_system_ops default_file_system_ops; -struct file_system_operations { - struct inode *(*new_inode)(struct file_system *); - struct inode *(*get_inode)(struct file_system *, long); - void (*destroy_inode)(struct inode *); +struct file_system_ops { + struct vnode *(*new_vnode)(struct file_system *); + struct vnode *(*get_vnode)(struct file_system *, long); + void (*destroy_vnode)(struct vnode *); int (*mount)(struct file_system *, struct dentry *); }; struct file_system_type { - struct file_system_operations *ops; + struct file_system_ops *ops; }; struct file_system { - struct file_system_operations *ops; + struct file_system_ops *ops; struct dentry *root; - int next_inode_number; // for in-memory filesystems + int next_vnode_number; // for in-memory filesystems list_node node; // mounted_file_systems-> - list inodes; // inode->fs_inode + list vnodes; // vnode->fs_vnode }; -// The _notime version of new_inode is intended for file systems that -// save the mtime, atime, and ctime seperately. By default, new_inode +// The _notime version of new_vnode is intended for file systems that +// save the mtime, atime, and ctime seperately. By default, new_vnode // populates these with the current time, so if that's not needed, // _notime is an optimization. -struct inode *new_inode_notime(struct file_system *file_system, int mode); -struct inode *new_inode(struct file_system *, int mode); -// void destroy_inode(struct inode *); +struct vnode *new_vnode_notime(struct file_system *file_system, int mode); +struct vnode *new_vnode(struct file_system *, int mode); +// void destroy_vnode(struct vnode *); // void mount(struct file_system *, struct dentry *); void mount_file_system(struct file_system *file_system, struct dentry *dentry); END_DECLS - diff --git a/include/ng/fs/init.h b/include/ng/fs/init.h index 378fcdf0..1899bed5 100644 --- a/include/ng/fs/init.h +++ b/include/ng/fs/init.h @@ -8,4 +8,3 @@ void fs_init(void *); void load_initfs(void *); END_DECLS - diff --git a/include/ng/fs/pipe.h b/include/ng/fs/pipe.h index 06b66507..389dec26 100644 --- a/include/ng/fs/pipe.h +++ b/include/ng/fs/pipe.h @@ -5,7 +5,6 @@ BEGIN_DECLS -struct inode *new_pipe(void); +struct vnode *new_pipe(void); END_DECLS - diff --git a/include/ng/fs/proc.h b/include/ng/fs/proc.h index 9592621c..e60f0015 100644 --- a/include/ng/fs/proc.h +++ b/include/ng/fs/proc.h @@ -8,10 +8,9 @@ BEGIN_DECLS void make_proc_file( const char *name, void (*generate)(struct file *, void *arg), void *arg); -struct inode *new_proc_inode( +struct vnode *new_proc_vnode( int mode, void (*generate)(struct file *, void *arg), void *arg); void proc_sprintf(struct file *, const char *fmt, ...) __PRINTF(2, 3); END_DECLS - diff --git a/include/ng/fs/socket.h b/include/ng/fs/socket.h index bb973790..faf35cf5 100644 --- a/include/ng/fs/socket.h +++ b/include/ng/fs/socket.h @@ -7,17 +7,17 @@ BEGIN_DECLS -struct socket_operations { - int (*bind)(struct inode *inode, struct sockaddr *addr, socklen_t addrlen); - int (*listen)(struct inode *inode, int backlog); +struct socket_ops { + int (*bind)(struct vnode *vnode, struct sockaddr *addr, socklen_t addrlen); + int (*listen)(struct vnode *vnode, int backlog); int (*accept)( - struct inode *inode, struct sockaddr *addr, socklen_t *addrlen); + struct vnode *vnode, struct sockaddr *addr, socklen_t *addrlen); int (*connect)( - struct inode *inode, struct sockaddr *addr, socklen_t addrlen); - int (*send)(struct inode *inode, const void *buf, size_t len, int flags); - int (*recv)(struct inode *inode, void *buf, size_t len, int flags); + struct vnode *vnode, struct sockaddr *addr, socklen_t addrlen); + int (*send)(struct vnode *vnode, const void *buf, size_t len, int flags); + int (*recv)(struct vnode *vnode, void *buf, size_t len, int flags); }; -struct inode *new_socket(void); +struct vnode *new_socket(void); END_DECLS diff --git a/include/ng/fs/tmpfs.h b/include/ng/fs/tmpfs.h index 57963297..2654feaa 100644 --- a/include/ng/fs/tmpfs.h +++ b/include/ng/fs/tmpfs.h @@ -8,4 +8,3 @@ BEGIN_DECLS struct file_system *new_tmpfs_file_system(void); END_DECLS - diff --git a/include/ng/fs/types.h b/include/ng/fs/types.h index 62b4b4a6..78256a42 100644 --- a/include/ng/fs/types.h +++ b/include/ng/fs/types.h @@ -4,14 +4,13 @@ struct file_system_type; struct file_system; -struct file_system_operations; +struct file_system_ops; -struct inode; -struct inode_operations; +struct vnode; +struct vnode_ops; struct file; -struct file_operations; +struct file_ops; struct dentry; -struct dentry_operations; - +struct dentry_ops; diff --git a/include/ng/fs/inode.h b/include/ng/fs/vnode.h similarity index 54% rename from include/ng/fs/inode.h rename to include/ng/fs/vnode.h index d6c3bf99..b5e5f8c3 100644 --- a/include/ng/fs/inode.h +++ b/include/ng/fs/vnode.h @@ -11,25 +11,25 @@ BEGIN_DECLS -struct inode_operations { - int (*open)(struct inode *, struct file *); - int (*close)(struct inode *, struct file *); +struct vnode_ops { + int (*open)(struct vnode *, struct file *); + int (*close)(struct vnode *, struct file *); - // struct dentry *(*readlink)(struct inode *); - ssize_t (*readlink)(struct inode *, char *, size_t); + // struct dentry *(*readlink)(struct vnode *); + ssize_t (*readlink)(struct vnode *, char *, size_t); struct dentry *(*lookup)(struct dentry *, const char *); }; -extern struct inode_operations default_ops; +extern struct vnode_ops default_ops; -enum inode_flags { +enum vnode_flags { INODE_UNUSED, }; -struct inode { - enum inode_flags flags; +struct vnode { + enum vnode_flags flags; enum file_type type; - int inode_number; + int vnode_number; struct file_system *file_system; int mode; int uid; @@ -37,7 +37,7 @@ struct inode { int device_major; int device_minor; - // Incremented by attach_inode + // Incremented by attach_vnode atomic_int dentry_refcnt; // Incremented by open_file @@ -45,8 +45,8 @@ struct inode { atomic_int read_refcnt; atomic_int write_refcnt; - const struct inode_operations *ops; - const struct file_operations *file_ops; + const struct vnode_ops *ops; + const struct file_ops *file_ops; waitqueue_t read_queue; waitqueue_t write_queue; @@ -59,7 +59,7 @@ struct inode { void *data; void *extra; const char *symlink_destination; - list_node fs_inodes; // file_system->inodes + list_node fs_vnodes; // file_system->vnodes bool is_anon_pipe; }; @@ -67,10 +67,10 @@ struct inode { int open_file(struct file *file); int open_file_clone(struct file *file); int close_file(struct file *file); -void maybe_delete_inode(struct inode *inode); +void maybe_delete_vnode(struct vnode *vnode); -inline void access_inode(struct inode *i) { i->atime = time_now(); } -inline void modify_inode(struct inode *i) { i->mtime = time_now(); } -inline void change_inode(struct inode *i) { i->ctime = time_now(); } +inline void access_vnode(struct vnode *i) { i->atime = time_now(); } +inline void modify_vnode(struct vnode *i) { i->mtime = time_now(); } +inline void change_vnode(struct vnode *i) { i->ctime = time_now(); } END_DECLS diff --git a/include/ng/irq.h b/include/ng/irq.h index 6ff8287c..69be5064 100644 --- a/include/ng/irq.h +++ b/include/ng/irq.h @@ -16,4 +16,3 @@ void irq_install(int irq, void (*fn)(interrupt_frame *, void *), void *); void irq_handler(interrupt_frame *); END_DECLS - diff --git a/include/ng/limine.h b/include/ng/limine.h index 3844d5bf..00020608 100644 --- a/include/ng/limine.h +++ b/include/ng/limine.h @@ -24,4 +24,3 @@ void limine_framebuffer(uint32_t *width, uint32_t *height, uint32_t *bpp, uint32_t *pitch, void **address); END_DECLS - diff --git a/include/ng/memmap.h b/include/ng/memmap.h index 624f580e..cb597e22 100644 --- a/include/ng/memmap.h +++ b/include/ng/memmap.h @@ -7,4 +7,3 @@ #define USER_ARGV 0x7FFFFF001000 // to 11000, 16x4K #define USER_STACK 0x7FFFFF000000 // 0000 - 0FFF is guard #define USER_MMAP_BASE 0x100000000000 - diff --git a/include/ng/mman.h b/include/ng/mman.h index 31702920..4820187c 100644 --- a/include/ng/mman.h +++ b/include/ng/mman.h @@ -21,4 +21,3 @@ enum { MAP_ANONYMOUS = 8, // others }; - diff --git a/include/ng/mod.h b/include/ng/mod.h index e8529172..e6e076db 100644 --- a/include/ng/mod.h +++ b/include/ng/mod.h @@ -41,4 +41,3 @@ struct mod_sym { struct mod_sym elf_find_symbol_by_address(uintptr_t address); END_DECLS - diff --git a/include/ng/mutex.h b/include/ng/mutex.h index d4aa0a9e..b5327186 100644 --- a/include/ng/mutex.h +++ b/include/ng/mutex.h @@ -31,4 +31,3 @@ void wake_awaiting_thread(mutex_t *mutex); void wake_all_awaiting_threads(mutex_t *mutex); END_DECLS - diff --git a/include/ng/panic.h b/include/ng/panic.h index fed45dd1..50602269 100644 --- a/include/ng/panic.h +++ b/include/ng/panic.h @@ -30,4 +30,3 @@ void backtrace_all(void); } while (0) END_DECLS - diff --git a/include/ng/pci.h b/include/ng/pci.h index f926156b..a5ec2f9c 100644 --- a/include/ng/pci.h +++ b/include/ng/pci.h @@ -72,4 +72,3 @@ const char *pci_device_type( unsigned char cls, unsigned char subcls, unsigned char prog_if); END_DECLS - diff --git a/include/ng/pmm.h b/include/ng/pmm.h index 4e89d4d6..9138041d 100644 --- a/include/ng/pmm.h +++ b/include/ng/pmm.h @@ -23,4 +23,3 @@ struct open_file; int pm_avail(void); END_DECLS - diff --git a/include/ng/proc_files.h b/include/ng/proc_files.h index 2b455199..c6711f32 100644 --- a/include/ng/proc_files.h +++ b/include/ng/proc_files.h @@ -7,4 +7,3 @@ BEGIN_DECLS void procfs_init(void); END_DECLS - diff --git a/include/ng/ringbuf.h b/include/ng/ringbuf.h index 199a8801..5e7b102c 100644 --- a/include/ng/ringbuf.h +++ b/include/ng/ringbuf.h @@ -23,4 +23,3 @@ size_t ring_read(struct ringbuf *, void *data, size_t len); size_t ring_data_len(struct ringbuf *r); END_DECLS - diff --git a/include/ng/serial.h b/include/ng/serial.h index 3f00f441..0ab8a331 100644 --- a/include/ng/serial.h +++ b/include/ng/serial.h @@ -28,4 +28,3 @@ void serial_write_str(struct serial_device *, const char *buf, size_t len); char serial_read(struct serial_device *); END_DECLS - diff --git a/include/ng/signal.h b/include/ng/signal.h index 486bc162..2d3b7d8d 100644 --- a/include/ng/signal.h +++ b/include/ng/signal.h @@ -28,4 +28,3 @@ void handle_signal(int signal, sighandler_t); void do_signal_call(int signal, sighandler_t); END_DECLS - diff --git a/include/ng/spalloc.h b/include/ng/spalloc.h index 7c61afb4..1b2712d8 100644 --- a/include/ng/spalloc.h +++ b/include/ng/spalloc.h @@ -31,4 +31,3 @@ void *sp_alloc(struct spalloc *sp); void sp_free(struct spalloc *sp, void *allocation); END_DECLS - diff --git a/include/ng/string.h b/include/ng/string.h index a7bd8d8d..34b019e1 100644 --- a/include/ng/string.h +++ b/include/ng/string.h @@ -27,4 +27,3 @@ char *strcncpy(char *dest, const char *src, int c, size_t len); int strccmp(const char *a, const char *b, int c); END_DECLS - diff --git a/include/ng/sync.h b/include/ng/sync.h index fdf545d6..4c12a3ec 100644 --- a/include/ng/sync.h +++ b/include/ng/sync.h @@ -43,4 +43,3 @@ typedef mutex_t condvar_t; #define with_lock(l) BRACKET(mutex_lock(l), mutex_unlock(l)) END_DECLS - diff --git a/include/ng/syscall_consts.h b/include/ng/syscall_consts.h index eecd2036..ee2234fb 100644 --- a/include/ng/syscall_consts.h +++ b/include/ng/syscall_consts.h @@ -7,4 +7,3 @@ BEGIN_DECLS #include "autogenerated_syscall_consts.h" END_DECLS - diff --git a/include/ng/syscalls.h b/include/ng/syscalls.h index bb570ff5..f5f9ca66 100644 --- a/include/ng/syscalls.h +++ b/include/ng/syscalls.h @@ -25,4 +25,3 @@ BEGIN_DECLS #include "autogenerated_syscalls_kernel.h" END_DECLS - diff --git a/include/ng/tarfs.h b/include/ng/tarfs.h index 08a9f747..370aa61f 100644 --- a/include/ng/tarfs.h +++ b/include/ng/tarfs.h @@ -13,4 +13,3 @@ void *tarfs_get_file(struct tar_header *tar, const char *filename); size_t tarfs_get_len(struct tar_header *tar, const char *filename); END_DECLS - diff --git a/include/ng/tests.h b/include/ng/tests.h index 604fb592..266cd7ac 100644 --- a/include/ng/tests.h +++ b/include/ng/tests.h @@ -7,4 +7,3 @@ BEGIN_DECLS void run_all_tests(void); END_DECLS - diff --git a/include/ng/thread.h b/include/ng/thread.h index cdaf2192..16567812 100644 --- a/include/ng/thread.h +++ b/include/ng/thread.h @@ -45,7 +45,7 @@ struct mm_region { uintptr_t base; uintptr_t top; enum mm_flags flags; - struct inode *inode; + struct vnode *vnode; }; #define NREGIONS 32 @@ -235,4 +235,3 @@ bool user_map(virt_addr_t base, virt_addr_t top); void print_cpu_info(void); END_DECLS - diff --git a/include/ng/time.h b/include/ng/time.h index 8519284b..f0583895 100644 --- a/include/ng/time.h +++ b/include/ng/time.h @@ -8,4 +8,3 @@ BEGIN_DECLS time_t time_now(void); END_DECLS - diff --git a/include/ng/timer.h b/include/ng/timer.h index 12df4db9..d3ecea1b 100644 --- a/include/ng/timer.h +++ b/include/ng/timer.h @@ -31,4 +31,3 @@ void timer_handler(interrupt_frame *, void *); #endif // __kernel__ END_DECLS - diff --git a/include/ng/trace.h b/include/ng/trace.h index e5f13642..5d97e5b2 100644 --- a/include/ng/trace.h +++ b/include/ng/trace.h @@ -55,4 +55,3 @@ void trace_report_trap(int interrupt); #endif END_DECLS - diff --git a/include/ng/tty.h b/include/ng/tty.h index c3f86792..a8cfb056 100644 --- a/include/ng/tty.h +++ b/include/ng/tty.h @@ -37,4 +37,3 @@ extern struct tty *global_ttys[32]; int tty_push_byte(struct tty *tty, char c); END_DECLS - diff --git a/include/ng/vmm.h b/include/ng/vmm.h index 389e68fb..4bbce4b8 100644 --- a/include/ng/vmm.h +++ b/include/ng/vmm.h @@ -22,4 +22,3 @@ uintptr_t vmm_mapobj_iwi(uintptr_t, size_t); void *high_vmm_reserve(size_t); END_DECLS - diff --git a/include/ng/x86/acpi.h b/include/ng/x86/acpi.h index 2024475a..cdd9b1b5 100644 --- a/include/ng/x86/acpi.h +++ b/include/ng/x86/acpi.h @@ -106,4 +106,3 @@ void acpi_print_header(acpi_header_t *header); void acpi_print_table(acpi_header_t *table); END_DECLS - diff --git a/include/ng/x86/apic.h b/include/ng/x86/apic.h index 21a929bd..b5e06495 100644 --- a/include/ng/x86/apic.h +++ b/include/ng/x86/apic.h @@ -51,4 +51,3 @@ void lapic_send_ipi(int type, int vector, int destination_processor); void ioapic_init(acpi_madt_t *); END_DECLS - diff --git a/include/ng/x86/cpu.h b/include/ng/x86/cpu.h index e78953d5..eabf6c02 100644 --- a/include/ng/x86/cpu.h +++ b/include/ng/x86/cpu.h @@ -179,4 +179,3 @@ inline uintptr_t dr6(void) { } END_DECLS - diff --git a/include/ng/x86/gdt.h b/include/ng/x86/gdt.h index 0eb735c4..c7e9d73d 100644 --- a/include/ng/x86/gdt.h +++ b/include/ng/x86/gdt.h @@ -56,4 +56,3 @@ void gdt_cpu_setup(int id); void gdt_cpu_load(); void gdt_set_cpu_rsp0(uint64_t rsp0); void gdt_set_cpu_ist1(uint64_t ist1); - diff --git a/include/ng/x86/interrupt.h b/include/ng/x86/interrupt.h index 755a7294..9e3f9d28 100644 --- a/include/ng/x86/interrupt.h +++ b/include/ng/x86/interrupt.h @@ -21,4 +21,3 @@ void generic_exception(interrupt_frame *r); void syscall_handler(interrupt_frame *r); END_DECLS - diff --git a/include/ng/x86/pic.h b/include/ng/x86/pic.h index 824f798c..8b16b72f 100644 --- a/include/ng/x86/pic.h +++ b/include/ng/x86/pic.h @@ -25,4 +25,3 @@ void pic_irq_unmask(int irq); void pic_irq_mask(int irq); END_DECLS - diff --git a/include/ng/x86/pit.h b/include/ng/x86/pit.h index d065dc32..26e49522 100644 --- a/include/ng/x86/pit.h +++ b/include/ng/x86/pit.h @@ -12,4 +12,3 @@ int pit_create_oneshot(int nanoseconds); int pit_ignore(void); END_DECLS - diff --git a/include/ng/x86/rtc.h b/include/ng/x86/rtc.h index 94c61c22..16f706c0 100644 --- a/include/ng/x86/rtc.h +++ b/include/ng/x86/rtc.h @@ -7,4 +7,3 @@ BEGIN_DECLS struct tm rtc_now(void); END_DECLS - diff --git a/include/ng/x86/uart.h b/include/ng/x86/uart.h index 1e3e5934..bd7a8b66 100644 --- a/include/ng/x86/uart.h +++ b/include/ng/x86/uart.h @@ -11,4 +11,3 @@ extern struct serial_device *x86_com[2]; void x86_uart_init(void); END_DECLS - diff --git a/include/ng/x86/vmm.h b/include/ng/x86/vmm.h index 9eddaedf..b09f147b 100644 --- a/include/ng/x86/vmm.h +++ b/include/ng/x86/vmm.h @@ -75,4 +75,3 @@ enum fault_result vmm_do_page_fault( virt_addr_t fault_addr, enum x86_fault reason); END_DECLS - diff --git a/include/nightingale.h b/include/nightingale.h index 7d7e43bd..2f5ef7e9 100644 --- a/include/nightingale.h +++ b/include/nightingale.h @@ -24,4 +24,3 @@ int sleepms(int milliseconds); void redirect_output_to(char *const argv[]); END_DECLS - diff --git a/include/poll.h b/include/poll.h index e7a35fb1..fd8719c8 100644 --- a/include/poll.h +++ b/include/poll.h @@ -19,4 +19,3 @@ typedef int nfds_t; int poll(struct pollfd *pollfds, nfds_t nfds, int timeout); END_DECLS - diff --git a/include/rbtree.h b/include/rbtree.h index db7f1947..61d093b5 100644 --- a/include/rbtree.h +++ b/include/rbtree.h @@ -26,4 +26,3 @@ struct rbnode *rbtree_successor(struct rbnode *node); struct rbnode *rbtree_predecessor(struct rbnode *node); struct rbnode *rbtree_search_ge(struct rbtree *tree, void *key); struct rbnode *rbtree_search_le(struct rbtree *tree, void *key); - diff --git a/include/sched.h b/include/sched.h index 2ed86192..97c9beec 100644 --- a/include/sched.h +++ b/include/sched.h @@ -7,4 +7,3 @@ BEGIN_DECLS int yield(void); END_DECLS - diff --git a/include/setjmp.h b/include/setjmp.h index 78e05d45..adcc29aa 100644 --- a/include/setjmp.h +++ b/include/setjmp.h @@ -29,4 +29,3 @@ _Noreturn void longjmp(jmp_buf, int); _Noreturn void _longjmp(jmp_buf, int); END_DECLS - diff --git a/include/signal.h b/include/signal.h index f472f055..08f5f942 100644 --- a/include/signal.h +++ b/include/signal.h @@ -48,7 +48,7 @@ typedef uint32_t sigset_t; typedef void (*sighandler_t)(int); typedef atomic_int sig_atomic_t; -// sigset operations +// sigset ops int sigemptyset(sigset_t *set); int sigfillset(sigset_t *set); int sigaddset(sigset_t *set, int signum); @@ -66,4 +66,3 @@ int raise(int signal); #endif // __kernel__ END_DECLS - diff --git a/include/stdint.h b/include/stdint.h index 44eea179..6d65cb56 100644 --- a/include/stdint.h +++ b/include/stdint.h @@ -493,4 +493,3 @@ typedef unsigned long uintptr_t; #endif #endif /* _STDINT_H */ - diff --git a/include/stdio.h b/include/stdio.h index a689055f..8ed98843 100644 --- a/include/stdio.h +++ b/include/stdio.h @@ -112,4 +112,3 @@ int sscanf(const char *s, const char *format, ...); #endif // ifndef __kernel__ END_DECLS - diff --git a/include/stdlib.h b/include/stdlib.h index 2c15a001..4377cbf9 100644 --- a/include/stdlib.h +++ b/include/stdlib.h @@ -102,4 +102,3 @@ int mkstemp(char *name); #endif // !__kernel__ END_DECLS - diff --git a/include/string.h b/include/string.h index 45d117bc..de2eb65d 100644 --- a/include/string.h +++ b/include/string.h @@ -38,4 +38,3 @@ size_t strcspn(const char *s, const char *reject); int strcoll(const char *s1, const char *s2); END_DECLS - diff --git a/include/sys/cdefs.h b/include/sys/cdefs.h index 3f356fc0..a4540e0e 100644 --- a/include/sys/cdefs.h +++ b/include/sys/cdefs.h @@ -24,4 +24,3 @@ #define END_DECLS #define static_assert(A) _Static_assert(A, #A) #endif // __cplusplus - diff --git a/include/sys/ioctl.h b/include/sys/ioctl.h index 0e346820..a9a1dc83 100644 --- a/include/sys/ioctl.h +++ b/include/sys/ioctl.h @@ -17,4 +17,3 @@ int ioctl(int fd, int request, ...); #endif END_DECLS - diff --git a/include/sys/mman.h b/include/sys/mman.h index 1cf424ce..1888fa83 100644 --- a/include/sys/mman.h +++ b/include/sys/mman.h @@ -28,4 +28,3 @@ void *mmap(void *addr, size_t len, int prot, int flags, int fd, off_t off); int munmap(void *addr, size_t len); END_DECLS - diff --git a/include/sys/mount.h b/include/sys/mount.h index 865cd197..d4ba346d 100644 --- a/include/sys/mount.h +++ b/include/sys/mount.h @@ -12,4 +12,3 @@ int mount(const char *target, int type, const char *source); int mountat(int fd, const char *target, int type, int sfd, const char *source); END_DECLS - diff --git a/include/sys/socket.h b/include/sys/socket.h index 92b687ec..00b21cac 100644 --- a/include/sys/socket.h +++ b/include/sys/socket.h @@ -49,4 +49,3 @@ ssize_t recvfrom(int sock, void *buf, size_t len, int flags, #endif // ifndef __kernel__ END_DECLS - diff --git a/include/sys/stat.h b/include/sys/stat.h index 3c00ad4b..22b55cbf 100644 --- a/include/sys/stat.h +++ b/include/sys/stat.h @@ -39,4 +39,3 @@ int mkfifo(const char *path, mode_t mode); int mkfifoat(int atfd, const char *path, mode_t mode); END_DECLS - diff --git a/include/sys/time.h b/include/sys/time.h index 3900ca31..e4886ebb 100644 --- a/include/sys/time.h +++ b/include/sys/time.h @@ -17,4 +17,3 @@ int gettimeofday(struct timeval *, void *); // int utimes(const char *, const struct timeval[2]); END_DECLS - diff --git a/include/sys/trace.h b/include/sys/trace.h index fa3d818c..dc47cc37 100644 --- a/include/sys/trace.h +++ b/include/sys/trace.h @@ -10,4 +10,3 @@ BEGIN_DECLS int trace(enum trace_command cmd, pid_t pid, void *addr, void *data); END_DECLS - diff --git a/include/sys/ttyctl.h b/include/sys/ttyctl.h index 2a1b79e0..dc0ecd78 100644 --- a/include/sys/ttyctl.h +++ b/include/sys/ttyctl.h @@ -8,4 +8,3 @@ BEGIN_DECLS int ttyctl(int fd, enum tty_ioctls cmd, int arg); END_DECLS - diff --git a/include/sys/types.h b/include/sys/types.h index 68df61fb..83202a44 100644 --- a/include/sys/types.h +++ b/include/sys/types.h @@ -24,4 +24,3 @@ typedef size_t socklen_t; typedef int nfds_t; typedef int clone_fn(void *); - diff --git a/include/sys/un.h b/include/sys/un.h index 9bf567f6..0636d475 100644 --- a/include/sys/un.h +++ b/include/sys/un.h @@ -6,4 +6,3 @@ struct sockaddr_un { sa_family_t sun_family; char sun_path[108]; }; - diff --git a/include/sys/utsname.h b/include/sys/utsname.h index 1cd72c64..30b2d37e 100644 --- a/include/sys/utsname.h +++ b/include/sys/utsname.h @@ -17,4 +17,3 @@ struct utsname { int uname(struct utsname *); END_DECLS - diff --git a/include/sys/wait.h b/include/sys/wait.h index 2d6d0da2..6b86566b 100644 --- a/include/sys/wait.h +++ b/include/sys/wait.h @@ -17,4 +17,3 @@ pid_t waitpid(pid_t pid, int *status, enum wait_options options); pid_t wait(int *status); END_DECLS - diff --git a/include/syscall.h b/include/syscall.h index 69587677..8f2c540a 100644 --- a/include/syscall.h +++ b/include/syscall.h @@ -131,4 +131,3 @@ intptr_t __syscall6(int syscall_num, intptr_t arg1, intptr_t arg2, END_DECLS #endif - diff --git a/include/syscall_types.h b/include/syscall_types.h index c030c047..88204507 100644 --- a/include/syscall_types.h +++ b/include/syscall_types.h @@ -9,4 +9,3 @@ enum fault_type { NULL_DEREF, ASSERT, }; - diff --git a/include/tar.h b/include/tar.h index 72277625..be516444 100644 --- a/include/tar.h +++ b/include/tar.h @@ -21,4 +21,3 @@ enum tar_typeflag { FIFOTYPE = '6', XATTR = 'x', }; - diff --git a/include/time.h b/include/time.h index dc7332f2..7f243709 100644 --- a/include/time.h +++ b/include/time.h @@ -41,4 +41,3 @@ time_t mktime(struct tm *tm); double difftime(time_t time1, time_t time0); END_DECLS - diff --git a/include/unistd.h b/include/unistd.h index a4868bd7..f007dba3 100644 --- a/include/unistd.h +++ b/include/unistd.h @@ -65,4 +65,3 @@ unsigned int alarm(unsigned int seconds); END_DECLS #endif // ifndef __kernel__ - diff --git a/include/vec.h b/include/vec.h index ab63669a..080cd9d5 100644 --- a/include/vec.h +++ b/include/vec.h @@ -13,7 +13,7 @@ #define vec_free(v) \ do { \ free((v)->data); \ - (v)->data = NULL; \ + (v)->data = nullptr; \ (v)->size = 0; \ (v)->capacity = 0; \ } while (0) @@ -77,4 +77,3 @@ #define vec_foreach(v) \ for (typeof((v)->data) it = vec_begin(v); it != vec_end(v); it++) - diff --git a/include/vector.h b/include/vector.h index ceb35fca..9a5956d9 100644 --- a/include/vector.h +++ b/include/vector.h @@ -31,4 +31,3 @@ void vec_free(struct vector *); void print_vector(struct vector *); END_DECLS - diff --git a/interface/SYSCALLS b/interface/SYSCALLS index 3327da3a..ab41e53f 100644 --- a/interface/SYSCALLS +++ b/interface/SYSCALLS @@ -1,26 +1,13 @@ 2 _exit { int exit_code } void noreturn - - - - 6 fork { } pid_t + 6 fork frame { } pid_t 7 top { int show_threads } int 8 getpid { } pid_t 9 gettid { } pid_t 10 execve frame { const char* program, args argv, args envp } int - 15 syscall_trace { pid_t pid, int state } int - - - - - - 22 waitpid { pid_t pid, int* exit_code, enum wait_options options } int - 24 uname { struct utsname* uname } int 25 yield { } int - - 28 mmap { void* addr, size_t len, int prot, int flags, int fd, off_t offset } void* 29 munmap { void* addr, size_t len } int 31 setpgid { pid_t pid, pid_t pgid } int @@ -28,32 +15,19 @@ 33 clone0 frame { clone_fn* fn, void* new_stack, int flags, void* arg } pid_t 34 loadmod { int fd } int 35 haltvm { int exit_code } int noreturn - 37 execveat frame { int fd, const char* program, args argv, args envp } int - - - 41 sigaction { int sig, sighandler_t handler, int flags } sighandler_t 42 sigreturn { int code } int noreturn 43 kill { pid_t pid, int dig } int 44 sleepms { int ms } int - 46 xtime { } long 47 create { const char* executable } pid_t 48 procstate { pid_t pid, enum procstate flags } int 49 fault { enum fault_type fault } int 50 trace { enum trace_command cmd, pid_t pid, void* addr, void* data } int 51 sigprocmask { int op, const sigset_t* new, sigset_t* old } int - - - - - - 58 exit_thread { int exit_code } void noreturn - 60 btime { time_t* time, struct tm* tm } int - 61 openat { int fd, const char* path, int flags, int mode } int 62 mkdirat { int fd, const char* path, int mode } int 63 close { int fd } int diff --git a/interface/gen.c b/interface/gen.c index ef8cdc6d..05e6a534 100644 --- a/interface/gen.c +++ b/interface/gen.c @@ -151,20 +151,20 @@ enum { }; int arg_is_pointer(const struct arg *arg) { - return strchr(arg->type, '*') != NULL; + return strchr(arg->type, '*') != nullptr; } const char *get_format(const struct arg *arg) { if (arg_is_pointer(arg)) { return "%p"; } - if (strstr(arg->type, "sighandler_t") != NULL) { + if (strstr(arg->type, "sighandler_t") != nullptr) { return "%p"; } - if (strstr(arg->type, "clone_fn") != NULL) { + if (strstr(arg->type, "clone_fn") != nullptr) { return "%p"; } - if (strstr(arg->type, "enum") != NULL) { + if (strstr(arg->type, "enum") != nullptr) { return "%i"; } @@ -333,9 +333,9 @@ void print_user_stubs(FILE *file) { fprintf(file, ");\n"); fprintf(file, "\tif (ret < 0 && ret > -4096) {\n"); fprintf(file, "\t\terrno = -ret;\n"); - if (strchr(syscalls[i].return_type, '*') != NULL) { - fprintf(file, "\t\treturn NULL;\n"); - } else if (strstr(syscalls[i].return_type, "void") != NULL) { + if (strchr(syscalls[i].return_type, '*') != nullptr) { + fprintf(file, "\t\treturn nullptr;\n"); + } else if (strstr(syscalls[i].return_type, "void") != nullptr) { fprintf(file, "\t\treturn;\n"); } else { fprintf(file, "\t\treturn (%s)-1;\n", syscalls[i].return_type); @@ -379,22 +379,22 @@ int main() { } FILE *kernel_header = fopen("ng_intf_k.h", "w"); - if (kernel_header == NULL) { + if (kernel_header == nullptr) { perror("fopen"); return 1; } FILE *user_header = fopen("ng_intf_u.h", "w"); - if (user_header == NULL) { + if (user_header == nullptr) { perror("fopen"); return 1; } FILE *kernel_c = fopen("ng_intf_k.c", "w"); - if (kernel_c == NULL) { + if (kernel_c == nullptr) { perror("fopen"); return 1; } FILE *user_c = fopen("ng_intf_u.c", "w"); - if (user_c == NULL) { + if (user_c == nullptr) { perror("fopen"); return 1; } diff --git a/kernel/CMakeLists.txt b/kernel/CMakeLists.txt index 8aa0554b..6c4f71bc 100644 --- a/kernel/CMakeLists.txt +++ b/kernel/CMakeLists.txt @@ -36,7 +36,6 @@ add_executable(nightingale_kernel fs/file_system.c fs/init.c fs/initfs.c - fs/inode.c fs/pipe.c fs/proc.c fs/proc_files.c @@ -44,6 +43,7 @@ add_executable(nightingale_kernel fs/tarfs.c fs/tmpfs.c fs/tty.c + fs/vnode.c lib/limine.c main.c mem/dmgr.c diff --git a/kernel/arch/x86/acpi.c b/kernel/arch/x86/acpi.c index 14d3ee00..f8431e6f 100644 --- a/kernel/arch/x86/acpi.c +++ b/kernel/arch/x86/acpi.c @@ -36,7 +36,7 @@ void *acpi_get_table(const char *table_id) { return header; } } - return NULL; + return nullptr; } void acpi_print_rsdp(acpi_rsdp_t *rsdp) { diff --git a/kernel/arch/x86/interrupt.c b/kernel/arch/x86/interrupt.c index 5a39f8ab..e714250d 100644 --- a/kernel/arch/x86/interrupt.c +++ b/kernel/arch/x86/interrupt.c @@ -199,7 +199,7 @@ void page_fault(interrupt_frame *r) { printf(sentence, rw, type, fault_addr, reason, mode); if (fault_addr < 0x1000) - printf("NULL pointer access?\n"); + printf("nullptr pointer access?\n"); break_point(); print_error_dump(r); if (code & F_USERMODE) diff --git a/kernel/arch/x86/vmm.c b/kernel/arch/x86/vmm.c index 7b07f753..6fa5dddb 100644 --- a/kernel/arch/x86/vmm.c +++ b/kernel/arch/x86/vmm.c @@ -46,7 +46,7 @@ static uintptr_t *vmm_pte_ptr_int( if (create) { pte = make_next_table_int(pte_ptr, vma > 0xFFFF000000000000); } else { - return NULL; + return nullptr; } } assert(!(pte & PAGE_ISHUGE)); // no support at this time diff --git a/kernel/fs/char_dev.c b/kernel/fs/char_dev.c index 749cd2bf..1aa9f3bc 100644 --- a/kernel/fs/char_dev.c +++ b/kernel/fs/char_dev.c @@ -1,12 +1,12 @@ #include #include -#include +#include #include #include ssize_t basic_char_dev_read(struct file *file, char *buffer, size_t len) { size_t i; - switch (file->inode->device_minor) { + switch (file->vnode->device_minor) { case FS_DEV_NULL: return 0; case FS_DEV_ZERO: @@ -26,7 +26,7 @@ ssize_t basic_char_dev_read(struct file *file, char *buffer, size_t len) { ssize_t basic_char_dev_write( struct file *file, const char *buffer, size_t len) { - switch (file->inode->device_minor) { + switch (file->vnode->device_minor) { case FS_DEV_NULL: return len; case FS_DEV_ZERO: @@ -41,14 +41,14 @@ ssize_t basic_char_dev_write( } } -struct file_operations basic_char_dev_ops = { +struct file_ops basic_char_dev_ops = { .read = basic_char_dev_read, .write = basic_char_dev_write, }; -extern struct file_operations tty_ops; +extern struct file_ops tty_ops; -struct file_operations *char_drivers[256] = { +struct file_ops *char_drivers[256] = { [0] = &basic_char_dev_ops, [1] = &tty_ops, }; diff --git a/kernel/fs/dentry.c b/kernel/fs/dentry.c index 300527a3..620f34fb 100644 --- a/kernel/fs/dentry.c +++ b/kernel/fs/dentry.c @@ -4,7 +4,7 @@ #include #include #include -#include +#include #include #include #include @@ -12,7 +12,7 @@ struct dentry *global_root_dentry; -extern inline struct inode *dentry_inode(struct dentry *dentry); +extern inline struct vnode *dentry_vnode(struct dentry *dentry); extern inline struct file_system *dentry_file_system(struct dentry *dentry); struct dentry *new_dentry() { @@ -29,8 +29,8 @@ void maybe_delete_dentry(struct dentry *dentry) { if (dentry->parent) return; - if (dentry->inode) - detach_inode(dentry); + if (dentry->vnode) + detach_vnode(dentry); if (dentry->name) free((void *)dentry->name); free(dentry); @@ -39,12 +39,12 @@ void maybe_delete_dentry(struct dentry *dentry) { // Cache child Create/Find/Remove struct dentry *add_child( - struct dentry *dentry, const char *name, struct inode *inode) { - if (inode == NULL) { + struct dentry *dentry, const char *name, struct vnode *vnode) { + if (vnode == nullptr) { struct dentry *new = new_dentry(); new->name = strdup(name); new->parent = dentry; - new->inode = NULL; + new->vnode = nullptr; if (dentry->mounted_file_system) new->file_system = dentry->mounted_file_system; else @@ -53,24 +53,24 @@ struct dentry *add_child( return new; } struct dentry *child = find_child(dentry, name); - if (child->inode) { + if (child->vnode) { // it already existed. return TO_ERROR(-EEXIST); } - attach_inode(child, inode); + attach_vnode(child, vnode); return child; } struct dentry *find_child(struct dentry *dentry, const char *name) { - struct dentry *found = NULL; - struct inode *inode = dentry_inode(dentry); - if (!inode) + struct dentry *found = nullptr; + struct vnode *vnode = dentry_vnode(dentry); + if (!vnode) return TO_ERROR(-ENOENT); - if (inode->type != FT_DIRECTORY) + if (vnode->type != FT_DIRECTORY) return TO_ERROR(-ENOTDIR); - if (inode->ops->lookup) - return inode->ops->lookup(dentry, name); + if (vnode->ops->lookup) + return vnode->ops->lookup(dentry, name); list_for_each_safe (&dentry->children) { struct dentry *d = container_of(struct dentry, children_node, it); @@ -86,38 +86,38 @@ struct dentry *find_child(struct dentry *dentry, const char *name) { return found; } - return add_child(dentry, name, NULL); + return add_child(dentry, name, nullptr); } struct dentry *unlink_dentry(struct dentry *dentry) { list_remove(&dentry->children_node); - dentry->parent = NULL; + dentry->parent = nullptr; maybe_delete_dentry(dentry); return dentry; } void destroy_dentry_tree(struct dentry *dentry) { } -int attach_inode(struct dentry *dentry, struct inode *inode) { - if (dentry_inode(dentry)) +int attach_vnode(struct dentry *dentry, struct vnode *vnode) { + if (dentry_vnode(dentry)) return -EEXIST; - dentry->inode = inode; - atomic_fetch_add(&inode->dentry_refcnt, 1); + dentry->vnode = vnode; + atomic_fetch_add(&vnode->dentry_refcnt, 1); return 0; } -void detach_inode(struct dentry *dentry) { - assert(dentry->inode); - atomic_fetch_sub(&dentry->inode->dentry_refcnt, 1); - maybe_delete_inode(dentry->inode); - dentry->inode = NULL; +void detach_vnode(struct dentry *dentry) { + assert(dentry->vnode); + atomic_fetch_sub(&dentry->vnode->dentry_refcnt, 1); + maybe_delete_vnode(dentry->vnode); + dentry->vnode = nullptr; } // Path resolution struct dentry *resolve_path_from_loopck( struct dentry *cursor, const char *path, bool follow, int n_symlinks) { - struct inode *inode; + struct vnode *vnode; char buffer[128] = { 0 }; if (n_symlinks > 8) @@ -149,17 +149,17 @@ struct dentry *resolve_path_from_loopck( cursor = find_child(cursor, buffer); } - while (follow && !IS_ERROR(cursor) && (inode = dentry_inode(cursor)) - && inode->type == FT_SYMLINK) { + while (follow && !IS_ERROR(cursor) && (vnode = dentry_vnode(cursor)) + && vnode->type == FT_SYMLINK) { char link_buffer[64] = { 0 }; const char *dest; - if (inode->ops->readlink) { - ssize_t err = inode->ops->readlink(inode, link_buffer, 64); + if (vnode->ops->readlink) { + ssize_t err = vnode->ops->readlink(vnode, link_buffer, 64); if (err < 0) return TO_ERROR(err); dest = link_buffer; } else { - dest = inode->symlink_destination; + dest = vnode->symlink_destination; } cursor = resolve_path_from_loopck( @@ -168,7 +168,7 @@ struct dentry *resolve_path_from_loopck( if (IS_ERROR(cursor)) return cursor; } - } while (path[0] && (cursor->inode || cursor->mounted_file_system)); + } while (path[0] && (cursor->vnode || cursor->mounted_file_system)); if (path[0] || !cursor) return TO_ERROR(-ENOENT); diff --git a/kernel/fs/file.c b/kernel/fs/file.c index 3ec1b8d1..6c971eb9 100644 --- a/kernel/fs/file.c +++ b/kernel/fs/file.c @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include #include #include @@ -14,30 +14,30 @@ struct file *get_file(int fd); struct file *get_file_from_process(int fd, struct process *process); ssize_t default_read(struct file *file, char *buffer, size_t len) { - if (file->offset > file->inode->len) + if (file->offset > file->vnode->len) return 0; - size_t to_read = MIN(len, file->inode->len - file->offset); - memcpy(buffer, PTR_ADD(file->inode->data, file->offset), to_read); + size_t to_read = MIN(len, file->vnode->len - file->offset); + memcpy(buffer, PTR_ADD(file->vnode->data, file->offset), to_read); file->offset += to_read; return to_read; } ssize_t default_write(struct file *file, const char *buffer, size_t len) { - if (!file->inode->data) { - file->inode->data = malloc(1024); - file->inode->capacity = 1024; + if (!file->vnode->data) { + file->vnode->data = malloc(1024); + file->vnode->capacity = 1024; } size_t final_len = file->offset + len; - if (file->offset + len > file->inode->capacity) { + if (file->offset + len > file->vnode->capacity) { size_t resized_len = final_len * 3 / 2; - file->inode->data = realloc(file->inode->data, resized_len); - file->inode->capacity = resized_len; + file->vnode->data = realloc(file->vnode->data, resized_len); + file->vnode->capacity = resized_len; } - memcpy(PTR_ADD(file->inode->data, file->offset), buffer, len); + memcpy(PTR_ADD(file->vnode->data, file->offset), buffer, len); file->offset += len; - file->inode->len = MAX(file->inode->len, final_len); + file->vnode->len = MAX(file->vnode->len, final_len); return len; } @@ -52,7 +52,7 @@ off_t default_seek(struct file *file, off_t offset, int whence) { new_offset += offset; break; case SEEK_END: - new_offset = file->inode->len + offset; + new_offset = file->vnode->len + offset; break; default: return -EINVAL; @@ -65,13 +65,13 @@ off_t default_seek(struct file *file, off_t offset, int whence) { return new_offset; } -struct file_operations default_file_ops = { 0 }; +struct file_ops default_file_ops = { 0 }; bool read_mode(struct file *file) { return file->flags & O_RDONLY; } bool write_mode(struct file *file) { return file->flags & O_WRONLY; } -bool has_permission(struct inode *inode, int flags) { +bool has_permission(struct vnode *vnode, int flags) { // bootleg implies, truth table: // mode flags allowed // 0 0 1 @@ -79,17 +79,17 @@ bool has_permission(struct inode *inode, int flags) { // 1 0 1 // 1 1 1 - return (inode->mode & USR_READ || !(flags & O_RDONLY)) - && (inode->mode & USR_WRITE || !(flags & O_WRONLY)); + return (vnode->mode & USR_READ || !(flags & O_RDONLY)) + && (vnode->mode & USR_WRITE || !(flags & O_WRONLY)); } -bool write_permission(struct inode *i) { return !!(i->mode & USR_WRITE); } -bool read_permission(struct inode *i) { return !!(i->mode & USR_READ); } -bool execute_permission(struct inode *i) { return !!(i->mode & USR_EXEC); } +bool write_permission(struct vnode *i) { return !!(i->mode & USR_WRITE); } +bool read_permission(struct vnode *i) { return !!(i->mode & USR_READ); } +bool execute_permission(struct vnode *i) { return !!(i->mode & USR_EXEC); } struct file *get_file(int fd) { if (fd > running_process->n_files || fd < 0) { - return NULL; + return nullptr; } if (running_process->files[fd]) assert(running_process->files[fd]->magic == FILE_MAGIC); @@ -146,7 +146,7 @@ int add_file_at(struct file *file, int at) { struct file *p_remove_file(struct process *proc, int fd) { if (fd > proc->n_files || fd < 0) - return NULL; + return nullptr; struct file **fds = proc->files; @@ -192,7 +192,7 @@ struct file **clone_all_files(struct process *proc) { size_t n_fds = proc->n_files; if (n_fds == 0 || n_fds > 1000000) { printf("process %i has %li fds\n", proc->pid, n_fds); - return NULL; + return nullptr; } struct file **newfds = calloc(n_fds, sizeof(struct file *)); for (int i = 0; i < n_fds; i++) { @@ -206,10 +206,10 @@ ssize_t read_file(struct file *file, char *buffer, size_t len) { assert(file->magic == FILE_MAGIC); if (!read_mode(file)) return -EPERM; - if (file->inode->type == FT_DIRECTORY) + if (file->vnode->type == FT_DIRECTORY) return -EISDIR; - access_inode(file->inode); + access_vnode(file->vnode); if (file->ops->read) return file->ops->read(file, buffer, len); @@ -221,10 +221,10 @@ ssize_t write_file(struct file *file, const char *buffer, size_t len) { assert(file->magic == FILE_MAGIC); if (!write_mode(file)) return -EPERM; - if (file->inode->type == FT_DIRECTORY) + if (file->vnode->type == FT_DIRECTORY) return -EISDIR; - modify_inode(file->inode); + modify_vnode(file->vnode); if (file->ops->write) return file->ops->write(file, buffer, len); @@ -234,7 +234,7 @@ ssize_t write_file(struct file *file, const char *buffer, size_t len) { int ioctl_file(struct file *file, int request, void *argp) { assert(file->magic == FILE_MAGIC); - modify_inode(file->inode); + modify_vnode(file->vnode); if (file->ops->ioctl) return file->ops->ioctl(file, request, argp); @@ -255,7 +255,7 @@ off_t seek_file(struct file *file, off_t offset, int whence) { ssize_t getdents_file(struct file *file, struct dirent *buf, size_t len) { assert(file->magic == FILE_MAGIC); - access_inode(file->inode); + access_vnode(file->vnode); if (file->ops->getdents) { return file->ops->getdents(file, buf, len); @@ -269,7 +269,7 @@ ssize_t getdents_file(struct file *file, struct dirent *buf, size_t len) { continue; } struct dirent *dent = PTR_ADD(buf, offset); - if (!d->inode) { + if (!d->vnode) { continue; } size_t max_copy = MIN(256, len - sizeof(struct dirent) - offset); @@ -278,14 +278,14 @@ ssize_t getdents_file(struct file *file, struct dirent *buf, size_t len) { if (will_copy < str_len) break; strncpy(dent->d_name, d->name, max_copy); - dent->d_type = d->inode->type; - dent->d_mode = (unsigned short)d->inode->mode; + dent->d_type = d->vnode->type; + dent->d_mode = (unsigned short)d->vnode->mode; size_t reclen = sizeof(struct dirent) - 256 + ROUND_UP(will_copy + 1, 8); dent->d_reclen = reclen; - dent->d_ino = d->inode->inode_number; - dent->d_off = d->inode->len; + dent->d_ino = d->vnode->vnode_number; + dent->d_off = d->vnode->len; offset += reclen; index += 1; @@ -295,12 +295,12 @@ ssize_t getdents_file(struct file *file, struct dirent *buf, size_t len) { } } -ssize_t readlink_inode(struct inode *inode, char *buffer, size_t len) { - if (inode->ops->readlink) - return inode->ops->readlink(inode, buffer, len); - else if (inode->symlink_destination) { - size_t str_len = strlen(inode->symlink_destination); - strncpy(buffer, inode->symlink_destination, len); +ssize_t readlink_vnode(struct vnode *vnode, char *buffer, size_t len) { + if (vnode->ops->readlink) + return vnode->ops->readlink(vnode, buffer, len); + else if (vnode->symlink_destination) { + size_t str_len = strlen(vnode->symlink_destination); + strncpy(buffer, vnode->symlink_destination, len); if (str_len > len) return -ENAMETOOLONG; return str_len; diff --git a/kernel/fs/file_system.c b/kernel/fs/file_system.c index aabcd457..3784a55b 100644 --- a/kernel/fs/file_system.c +++ b/kernel/fs/file_system.c @@ -2,42 +2,42 @@ #include #include #include -#include +#include #include #include -struct file_system_operations default_file_system_ops = { 0 }; +struct file_system_ops default_file_system_ops = { 0 }; struct file_system *initfs_file_system; struct file_system *proc_file_system; -struct inode *new_inode_notime(struct file_system *file_system, int mode) { - struct inode *inode; - if (file_system->ops->new_inode) { - inode = file_system->ops->new_inode(file_system); +struct vnode *new_vnode_notime(struct file_system *file_system, int mode) { + struct vnode *vnode; + if (file_system->ops->new_vnode) { + vnode = file_system->ops->new_vnode(file_system); } else { - inode = calloc(1, sizeof(struct inode)); + vnode = calloc(1, sizeof(struct vnode)); } - inode->file_system = file_system; - inode->mode = mode; - inode->ops = &default_ops; - inode->file_ops = &default_file_ops; - inode->inode_number = file_system->next_inode_number++; + vnode->file_system = file_system; + vnode->mode = mode; + vnode->ops = &default_ops; + vnode->file_ops = &default_file_ops; + vnode->vnode_number = file_system->next_vnode_number++; - inode->type = mode >> 16 ? mode >> 16 : FT_NORMAL; + vnode->type = mode >> 16 ? mode >> 16 : FT_NORMAL; - wq_init(&inode->read_queue); - wq_init(&inode->write_queue); + wq_init(&vnode->read_queue); + wq_init(&vnode->write_queue); - list_append(&file_system->inodes, &inode->fs_inodes); + list_append(&file_system->vnodes, &vnode->fs_vnodes); - return inode; + return vnode; } -struct inode *new_inode(struct file_system *file_system, int mode) { - struct inode *inode = new_inode_notime(file_system, mode); - inode->atime = inode->mtime = inode->ctime = time_now(); - return inode; +struct vnode *new_vnode(struct file_system *file_system, int mode) { + struct vnode *vnode = new_vnode_notime(file_system, mode); + vnode->atime = vnode->mtime = vnode->ctime = time_now(); + return vnode; } void mount_file_system(struct file_system *file_system, struct dentry *dentry) { diff --git a/kernel/fs/init.c b/kernel/fs/init.c index 55390ec3..d7daf988 100644 --- a/kernel/fs/init.c +++ b/kernel/fs/init.c @@ -2,8 +2,8 @@ #include #include #include -#include #include +#include #include void fs_init(void *initfs) { diff --git a/kernel/fs/initfs.c b/kernel/fs/initfs.c index 25d0c11a..5b813010 100644 --- a/kernel/fs/initfs.c +++ b/kernel/fs/initfs.c @@ -2,7 +2,7 @@ #include #include #include -#include +#include #include #include @@ -10,12 +10,12 @@ static uint64_t tar_convert_number(char *num); void make_tar_file( struct dentry *dentry, int mode, size_t len, time_t mtime, void *content) { - struct inode *inode = new_inode_notime(dentry->file_system, mode); - inode->data = content; - inode->len = len; - inode->capacity = len; - inode->atime = inode->mtime = inode->ctime = mtime; - attach_inode(dentry, inode); + struct vnode *vnode = new_vnode_notime(dentry->file_system, mode); + vnode->data = content; + vnode->len = len; + vnode->capacity = len; + vnode->atime = vnode->mtime = vnode->ctime = mtime; + attach_vnode(dentry, vnode); } void load_initfs(void *initfs) { @@ -40,7 +40,7 @@ void load_initfs(void *initfs) { if (tar->typeflag == REGTYPE || tar->typeflag == AREGTYPE) { make_tar_file(dentry, mode, len, mtime, content); } else if (tar->typeflag == DIRTYPE) { - make_tar_file(dentry, _NG_DIR | mode | 0200, 0, mtime, NULL); + make_tar_file(dentry, _NG_DIR | mode | 0200, 0, mtime, nullptr); } else if (tar->typeflag == XATTR) { // ignore POSIX extended attributes } else { diff --git a/kernel/fs/pipe.c b/kernel/fs/pipe.c index 51f0ddec..fe119863 100644 --- a/kernel/fs/pipe.c +++ b/kernel/fs/pipe.c @@ -2,8 +2,8 @@ #include #include #include -#include #include +#include #include #include #include @@ -12,20 +12,20 @@ #define wait_on wq_block_on #define wake_from wq_notify_all -struct inode_operations pipe_ops; -struct file_operations pipe_file_ops; - -struct inode *new_pipe(void) { - struct inode *inode = new_inode(initfs_file_system, S_IFIFO | 0777); - inode->capacity = 16384; - inode->data = malloc(inode->capacity); - inode->ops = &pipe_ops; - inode->file_ops = &pipe_file_ops; - inode->type = FT_PIPE; - return inode; +struct vnode_ops pipe_ops; +struct file_ops pipe_file_ops; + +struct vnode *new_pipe(void) { + struct vnode *vnode = new_vnode(initfs_file_system, S_IFIFO | 0777); + vnode->capacity = 16384; + vnode->data = malloc(vnode->capacity); + vnode->ops = &pipe_ops; + vnode->file_ops = &pipe_file_ops; + vnode->type = FT_PIPE; + return vnode; } -int pipe_open(struct inode *pipe, struct file *file) { +int pipe_open(struct vnode *pipe, struct file *file) { if (pipe->is_anon_pipe) return 0; @@ -47,7 +47,7 @@ int pipe_open(struct inode *pipe, struct file *file) { return 0; } -int pipe_close(struct inode *pipe, struct file *file) { +int pipe_close(struct vnode *pipe, struct file *file) { if (pipe->write_refcnt == 0) wake_from(&pipe->read_queue); if (pipe->read_refcnt == 0) @@ -55,48 +55,48 @@ int pipe_close(struct inode *pipe, struct file *file) { return 0; } -struct inode_operations pipe_ops = { +struct vnode_ops pipe_ops = { .open = pipe_open, .close = pipe_close, }; ssize_t pipe_read(struct file *file, char *buffer, size_t len) { - struct inode *inode = file->inode; - while (inode->len == 0 && inode->write_refcnt) - wait_on(&inode->read_queue); - - size_t to_read = MIN(len, inode->len); - memcpy(buffer, inode->data, to_read); - memmove(inode->data, PTR_ADD(inode->data, to_read), inode->len - to_read); - inode->len -= to_read; - wake_from(&inode->write_queue); + struct vnode *vnode = file->vnode; + while (vnode->len == 0 && vnode->write_refcnt) + wait_on(&vnode->read_queue); + + size_t to_read = MIN(len, vnode->len); + memcpy(buffer, vnode->data, to_read); + memmove(vnode->data, PTR_ADD(vnode->data, to_read), vnode->len - to_read); + vnode->len -= to_read; + wake_from(&vnode->write_queue); return to_read; } ssize_t pipe_write(struct file *file, const char *buffer, size_t len) { - struct inode *inode = file->inode; + struct vnode *vnode = file->vnode; - if (!inode->read_refcnt) { + if (!vnode->read_refcnt) { signal_self(SIGPIPE); return 0; } - while (inode->len == inode->capacity && inode->read_refcnt) - wait_on(&inode->write_queue); + while (vnode->len == vnode->capacity && vnode->read_refcnt) + wait_on(&vnode->write_queue); - if (!inode->read_refcnt) { + if (!vnode->read_refcnt) { signal_self(SIGPIPE); return 0; } - size_t to_write = MIN(len, inode->capacity - inode->len); - memcpy(PTR_ADD(inode->data, inode->len), buffer, to_write); - inode->len += to_write; - wake_from(&inode->read_queue); + size_t to_write = MIN(len, vnode->capacity - vnode->len); + memcpy(PTR_ADD(vnode->data, vnode->len), buffer, to_write); + vnode->len += to_write; + wake_from(&vnode->read_queue); return to_write; } -struct file_operations pipe_file_ops = { +struct file_ops pipe_file_ops = { .read = pipe_read, .write = pipe_write, }; diff --git a/kernel/fs/proc.c b/kernel/fs/proc.c index f0f3db95..7fc31119 100644 --- a/kernel/fs/proc.c +++ b/kernel/fs/proc.c @@ -2,37 +2,37 @@ #include #include #include -#include #include +#include #include #include #include extern struct file_system *proc_file_system; -struct file_operations proc_file_ops; -struct inode_operations proc_inode_ops; +struct file_ops proc_file_ops; +struct vnode_ops proc_vnode_ops; -struct inode *new_proc_inode( +struct vnode *new_proc_vnode( int mode, void (*generate)(struct file *, void *arg), void *arg) { - struct inode *inode = new_inode(proc_file_system, _NG_PROC | mode); - inode->ops = &proc_inode_ops; - inode->file_ops = &proc_file_ops; - inode->extra = generate; - inode->data = arg; - return inode; + struct vnode *vnode = new_vnode(proc_file_system, _NG_PROC | mode); + vnode->ops = &proc_vnode_ops; + vnode->file_ops = &proc_file_ops; + vnode->extra = generate; + vnode->data = arg; + return vnode; } void make_proc_file( const char *name, void (*generate)(struct file *, void *arg), void *arg) { struct dentry *root = proc_file_system->root; - struct inode *inode = new_proc_inode(0444, generate, arg); + struct vnode *vnode = new_proc_vnode(0444, generate, arg); struct dentry *dentry = resolve_path_from(root, name, true); - if (dentry->inode) { + if (dentry->vnode) { printf("proc file '%s' already exists\n", name); - maybe_delete_inode(inode); + maybe_delete_vnode(vnode); return; } - attach_inode(dentry, inode); + attach_vnode(dentry, vnode); } ssize_t proc_file_read(struct file *file, char *buffer, size_t len) { @@ -58,7 +58,7 @@ off_t proc_file_seek(struct file *file, off_t offset, int whence) { break; case SEEK_END: // The only difference between this and default_seek is that - // this uses file->len for SEEK_END because the inode has no + // this uses file->len for SEEK_END because the vnode has no // len of its own. new_offset = file->len + offset; break; @@ -73,29 +73,29 @@ off_t proc_file_seek(struct file *file, off_t offset, int whence) { return new_offset; } -int proc_file_open(struct inode *inode, struct file *file) { +int proc_file_open(struct vnode *vnode, struct file *file) { void (*generate)(struct file *, void *arg); file->extra = malloc(4096 * 4); file->size = 4096 * 4; file->len = 0; - generate = inode->extra; - generate(file, inode->data); + generate = vnode->extra; + generate(file, vnode->data); return 0; } -int proc_file_close(struct inode *inode, struct file *file) { +int proc_file_close(struct vnode *vnode, struct file *file) { if (file->extra) free(file->extra); return 0; } -struct file_operations proc_file_ops = { +struct file_ops proc_file_ops = { .read = proc_file_read, .write = proc_file_write, .seek = proc_file_seek, }; -struct inode_operations proc_inode_ops = { +struct vnode_ops proc_vnode_ops = { .open = proc_file_open, .close = proc_file_close, }; diff --git a/kernel/fs/proc_files.c b/kernel/fs/proc_files.c index 55660c22..f1c4e87d 100644 --- a/kernel/fs/proc_files.c +++ b/kernel/fs/proc_files.c @@ -1,7 +1,7 @@ #include #include -static void proc_test(struct file *ofd, void *_) { +static void proc_test(struct file *ofd, void *) { proc_sprintf(ofd, "Hello World\n"); } @@ -10,18 +10,18 @@ void procfs_init(void) { extern void proc_syscalls(struct file *, void *); extern void proc_mods(struct file *, void *); extern void pm_summary(struct file *, void *); - extern void proc_heap(struct file * file, void *_); + extern void proc_heap(struct file * file, void *); - make_proc_file("test", proc_test, NULL); - make_proc_file("timer", timer_procfile, NULL); - make_proc_file("mem", pm_summary, NULL); - make_proc_file("syscalls", proc_syscalls, NULL); - make_proc_file("mods", proc_mods, NULL); - make_proc_file("heap", proc_heap, NULL); + make_proc_file("test", proc_test, nullptr); + make_proc_file("timer", timer_procfile, nullptr); + make_proc_file("mem", pm_summary, nullptr); + make_proc_file("syscalls", proc_syscalls, nullptr); + make_proc_file("mods", proc_mods, nullptr); + make_proc_file("heap", proc_heap, nullptr); struct dentry *ddir = proc_file_system->root; - extern struct inode_operations proc_self_ops; - struct inode *inode = new_inode(proc_file_system, _NG_SYMLINK | 0444); - inode->ops = &proc_self_ops; - add_child(ddir, "self", inode); + extern struct vnode_ops proc_self_ops; + struct vnode *vnode = new_vnode(proc_file_system, _NG_SYMLINK | 0444); + vnode->ops = &proc_self_ops; + add_child(ddir, "self", vnode); } diff --git a/kernel/fs/syscalls.c b/kernel/fs/syscalls.c index 11a1e77a..5b3c57d4 100644 --- a/kernel/fs/syscalls.c +++ b/kernel/fs/syscalls.c @@ -6,8 +6,8 @@ #include #include #include -#include #include +#include #include #include #include @@ -15,12 +15,12 @@ #include #include -// associate inode with NEGATIVE dentry -struct file *create_file(struct dentry *dentry, struct inode *inode, int flags); -// open existing inode +// associate vnode with NEGATIVE dentry +struct file *create_file(struct dentry *dentry, struct vnode *vnode, int flags); +// open existing vnode struct file *new_file(struct dentry *dentry, int flags); -// Create a file for an inode that has NO dentry (i.e. pipe) -struct file *no_d_file(struct inode *inode, int flags); +// Create a file for an vnode that has NO dentry (i.e. pipe) +struct file *no_d_file(struct vnode *vnode, int flags); // truncate file void truncate(struct file *file); // set to append, move cursor @@ -30,24 +30,24 @@ sysret do_open(struct dentry *cwd, const char *path, int flags, int mode) { struct dentry *dentry = resolve_path_from(cwd, path, true); if (IS_ERROR(dentry)) return ERROR(dentry); - struct inode *inode = dentry_inode(dentry); - if (!inode && !(flags & O_CREAT)) + struct vnode *vnode = dentry_vnode(dentry); + if (!vnode && !(flags & O_CREAT)) return -ENOENT; - if (dentry && inode && flags & O_CREAT && flags & O_EXCL) + if (dentry && vnode && flags & O_CREAT && flags & O_EXCL) return -EEXIST; struct file_system *file_system = dentry_file_system(dentry); struct file *file; - if (inode && !has_permission(inode, flags)) + if (vnode && !has_permission(vnode, flags)) return -EPERM; - else if (!inode - && !has_permission(dentry_inode(dentry->parent), flags | O_WRONLY)) + else if (!vnode + && !has_permission(dentry_vnode(dentry->parent), flags | O_WRONLY)) return -EPERM; - if (!inode && flags & O_CREAT) { - inode = new_inode(file_system, mode); - file = create_file(dentry, inode, flags); + if (!vnode && flags & O_CREAT) { + vnode = new_vnode(file_system, mode); + file = create_file(dentry, vnode, flags); } else { file = new_file(dentry, flags); } @@ -74,20 +74,20 @@ sysret do_touch(struct dentry *cwd, const char *path, int flags, int mode) { struct dentry *dentry = resolve_path_from(cwd, path, true); if (IS_ERROR(dentry)) return ERROR(dentry); - struct inode *inode = dentry_inode(dentry); + struct vnode *vnode = dentry_vnode(dentry); assert(flags & O_CREAT && flags & O_EXCL); - if (dentry && inode) + if (dentry && vnode) return -EEXIST; struct file_system *file_system = dentry_file_system(dentry); - if (!has_permission(dentry_inode(dentry->parent), flags | O_WRONLY)) + if (!has_permission(dentry_vnode(dentry->parent), flags | O_WRONLY)) return -EPERM; - inode = new_inode(file_system, mode); - attach_inode(dentry, inode); + vnode = new_vnode(file_system, mode); + attach_vnode(dentry, vnode); return 0; } @@ -112,15 +112,15 @@ sysret sys_getdents(int fd, struct dirent *buf, size_t len) { struct file *directory = get_file(fd); if (!directory) return -EBADF; - struct inode *inode = directory->inode; - if (!inode) + struct vnode *vnode = directory->vnode; + if (!vnode) return -ENOENT; - if (inode->type != FT_DIRECTORY) + if (vnode->type != FT_DIRECTORY) return -ENOTDIR; - if (!execute_permission(inode)) + if (!execute_permission(vnode)) return -EPERM; - access_inode(inode); + access_vnode(vnode); return getdents_file(directory, buf, len); } @@ -146,7 +146,7 @@ sysret sys_chdirat(int atfd, const char *path) { struct dentry *dentry = resolve_atpath(atfd, path, true); if (IS_ERROR(dentry)) return ERROR(dentry); - if (!dentry_inode(dentry)) + if (!dentry_vnode(dentry)) return -ENOENT; // FIXME: reference count this! @@ -186,21 +186,21 @@ sysret sys_lseek(int fd, off_t offset, int whence) { return seek_file(file, offset, whence); } -sysret stat_inode(struct inode *inode, struct stat *stat) { +sysret stat_vnode(struct vnode *vnode, struct stat *stat) { *stat = (struct stat) { - .st_dev = (dev_t)(intptr_t)inode->file_system, - .st_ino = inode->inode_number, - .st_mode = (inode->mode & 0xFFFF) + (inode->type << 16), - .st_nlink = inode->dentry_refcnt, - .st_uid = inode->uid, - .st_gid = inode->gid, - .st_rdev = (inode->device_major << 16) + inode->device_minor, - .st_size = inode->len, + .st_dev = (dev_t)(intptr_t)vnode->file_system, + .st_ino = vnode->vnode_number, + .st_mode = (vnode->mode & 0xFFFF) + (vnode->type << 16), + .st_nlink = vnode->dentry_refcnt, + .st_uid = vnode->uid, + .st_gid = vnode->gid, + .st_rdev = (vnode->device_major << 16) + vnode->device_minor, + .st_size = vnode->len, .st_blksize = 1024, // FIXME - .st_blocks = ROUND_UP(inode->len, 1024) / 1024, // FIXME - .st_atime = inode->atime, - .st_mtime = inode->mtime, - .st_ctime = inode->ctime, + .st_blocks = ROUND_UP(vnode->len, 1024) / 1024, // FIXME + .st_atime = vnode->atime, + .st_mtime = vnode->mtime, + .st_ctime = vnode->ctime, }; return 0; } @@ -210,8 +210,8 @@ sysret sys_fstat(int fd, struct stat *stat) { if (!file) return -EBADF; - struct inode *inode = file->inode; - return stat_inode(inode, stat); + struct vnode *vnode = file->vnode; + return stat_vnode(vnode, stat); } sysret sys_statat(int atfd, const char *path, struct stat *stat) { @@ -219,10 +219,10 @@ sysret sys_statat(int atfd, const char *path, struct stat *stat) { if (IS_ERROR(dentry)) return ERROR(dentry); - struct inode *inode = dentry_inode(dentry); - if (!inode) + struct vnode *vnode = dentry_vnode(dentry); + if (!vnode) return -ENOENT; - return stat_inode(inode, stat); + return stat_vnode(vnode, stat); } sysret sys_linkat( @@ -231,23 +231,23 @@ sysret sys_linkat( if (IS_ERROR(olddentry)) return ERROR(olddentry); - if (!dentry_inode(olddentry)) + if (!dentry_vnode(olddentry)) return -ENOENT; - if (dentry_inode(olddentry)->type == FT_DIRECTORY) + if (dentry_vnode(olddentry)->type == FT_DIRECTORY) return -EISDIR; struct dentry *newdentry = resolve_atpath(newfdat, newpath, true); if (IS_ERROR(newdentry)) return ERROR(newdentry); - if (dentry_inode(newdentry)) + if (dentry_vnode(newdentry)) return -EEXIST; if (newdentry->file_system != olddentry->file_system) return -EXDEV; - attach_inode(newdentry, olddentry->inode); + attach_vnode(newdentry, olddentry->vnode); return 0; } @@ -256,12 +256,12 @@ sysret sys_symlinkat(const char *topath, int newfdat, const char *newpath) { if (IS_ERROR(dentry)) return ERROR(dentry); - if (dentry_inode(dentry)) + if (dentry_vnode(dentry)) return -EEXIST; - struct inode *inode = new_inode(dentry->file_system, _NG_SYMLINK | 0777); - inode->symlink_destination = strdup(topath); - attach_inode(dentry, inode); + struct vnode *vnode = new_vnode(dentry->file_system, _NG_SYMLINK | 0777); + vnode->symlink_destination = strdup(topath); + attach_vnode(dentry, vnode); return 0; } @@ -269,13 +269,13 @@ sysret sys_readlinkat(int atfd, const char *path, char *buffer, size_t len) { struct dentry *dentry = resolve_atpath(atfd, path, false); if (IS_ERROR(dentry)) return ERROR(dentry); - struct inode *inode = dentry_inode(dentry); - if (!inode) + struct vnode *vnode = dentry_vnode(dentry); + if (!vnode) return -ENOENT; - if (inode->type != FT_SYMLINK) + if (vnode->type != FT_SYMLINK) return -EINVAL; - readlink_inode(inode, buffer, len); + readlink_vnode(vnode, buffer, len); // These can be dynamically generated, check if we don't need it // anymore @@ -288,28 +288,28 @@ sysret sys_mknodat(int atfd, const char *path, mode_t mode, dev_t device) { struct dentry *dentry = resolve_atpath(atfd, path, true); if (IS_ERROR(dentry)) return ERROR(dentry); - if (dentry_inode(dentry)) + if (dentry_vnode(dentry)) return -EEXIST; struct file_system *file_system = dentry_file_system(dentry); - struct inode *inode = new_inode(file_system, mode); + struct vnode *vnode = new_vnode(file_system, mode); int device_major = device >> 16; int device_minor = device & 0xFFFF; - struct file_operations *drv_ops = char_drivers[device_major]; + struct file_ops *drv_ops = char_drivers[device_major]; if (!drv_ops) return -ENODEV; - inode->device_major = device_major; - inode->device_minor = device_minor; - inode->file_ops = drv_ops; - inode->type = FT_CHAR_DEV; + vnode->device_major = device_major; + vnode->device_minor = device_minor; + vnode->file_ops = drv_ops; + vnode->type = FT_CHAR_DEV; - attach_inode(dentry, inode); + attach_vnode(dentry, vnode); return 0; } sysret sys_pipe(int pipefds[static 2]) { - struct inode *pipe = new_pipe(); + struct vnode *pipe = new_pipe(); pipe->is_anon_pipe = true; struct file *read_end = no_d_file(pipe, O_RDONLY); struct file *write_end = no_d_file(pipe, O_WRONLY); @@ -322,14 +322,14 @@ sysret sys_mkpipeat(int atfd, const char *path, mode_t mode) { struct dentry *dentry = resolve_atpath(atfd, path, true); if (IS_ERROR(dentry)) return ERROR(dentry); - if (dentry_inode(dentry)) + if (dentry_vnode(dentry)) return -EEXIST; - struct inode *pipe = new_pipe(); + struct vnode *pipe = new_pipe(); pipe->is_anon_pipe = false; pipe->mode = mode; - attach_inode(dentry, pipe); + attach_vnode(dentry, pipe); return 0; } @@ -338,10 +338,10 @@ sysret sys_mountat( struct dentry *tdentry = resolve_atpath(atfd, target, true); if (IS_ERROR(tdentry)) return ERROR(tdentry); - struct inode *tinode = dentry_inode(tdentry); - if (!tinode) + struct vnode *tvnode = dentry_vnode(tdentry); + if (!tvnode) return -ENOENT; - if (tinode->type != FT_DIRECTORY) + if (tvnode->type != FT_DIRECTORY) return -ENOTDIR; struct file_system *file_system; @@ -384,8 +384,8 @@ sysret sys_fchmod(int fd, int mode) { return -EBADF; if (!write_mode(file)) return -EPERM; - struct inode *inode = file->inode; - inode->mode = (inode->mode & ~0xFFFF) | (mode & 0xFFFF); + struct vnode *vnode = file->vnode; + vnode->mode = (vnode->mode & ~0xFFFF) | (mode & 0xFFFF); return 0; } @@ -393,11 +393,11 @@ sysret sys_chmodat(int atfd, const char *path, int mode) { struct dentry *dentry = resolve_atpath(atfd, path, true); if (IS_ERROR(dentry)) return ERROR(dentry); - struct inode *inode = dentry_inode(dentry); - if (!inode) + struct vnode *vnode = dentry_vnode(dentry); + if (!vnode) return -ENOENT; - inode->mode = (inode->mode & ~0xFFFF) | (mode & 0xFFFF); + vnode->mode = (vnode->mode & ~0xFFFF) | (mode & 0xFFFF); return 0; } @@ -405,31 +405,31 @@ sysret sys_unlinkat(int atfd, const char *path, int mode) { struct dentry *dentry = resolve_atpath(atfd, path, true); if (IS_ERROR(dentry)) return ERROR(dentry); - struct inode *inode = dentry_inode(dentry); - if (!inode) + struct vnode *vnode = dentry_vnode(dentry); + if (!vnode) return -ENOENT; - if (!write_permission(inode)) + if (!write_permission(vnode)) return -EPERM; - if (inode->type == FT_DIRECTORY) + if (vnode->type == FT_DIRECTORY) return -EISDIR; unlink_dentry(dentry); - detach_inode(dentry); + detach_vnode(dentry); free(dentry); return 0; } -// Given a POSITIVE dentry (extant inode), create a `struct file` to +// Given a POSITIVE dentry (extant vnode), create a `struct file` to // open it and return the new "file" object. struct file *new_file(struct dentry *dentry, int flags) { int err; struct file *file = malloc(sizeof(struct file)); - struct inode *inode = dentry_inode(dentry); + struct vnode *vnode = dentry_vnode(dentry); *file = (struct file) { - .inode = inode, + .vnode = vnode, .dentry = dentry, .flags = flags, // validate? - .ops = inode->file_ops, + .ops = vnode->file_ops, }; err = open_file(file); @@ -442,22 +442,22 @@ struct file *new_file(struct dentry *dentry, int flags) { return file; } -// Given a NEGATIVE dentry and an inode, associate the inode with the +// Given a NEGATIVE dentry and an vnode, associate the vnode with the // dentry, then open the file and return it. struct file *create_file( - struct dentry *dentry, struct inode *inode, int flags) { - attach_inode(dentry, inode); + struct dentry *dentry, struct vnode *vnode, int flags) { + attach_vnode(dentry, vnode); return new_file(dentry, flags); } -// Create a file for an inode that has NO dentry (i.e. pipe) -struct file *no_d_file(struct inode *inode, int flags) { +// Create a file for an vnode that has NO dentry (i.e. pipe) +struct file *no_d_file(struct vnode *vnode, int flags) { int err; struct file *file = malloc(sizeof(struct file)); *file = (struct file) { - .inode = inode, + .vnode = vnode, .flags = flags, // validate? - .ops = inode->file_ops, + .ops = vnode->file_ops, }; err = open_file(file); @@ -471,7 +471,7 @@ struct file *no_d_file(struct inode *inode, int flags) { } // truncate file -void truncate(struct file *file) { file->inode->len = 0; } +void truncate(struct file *file) { file->vnode->len = 0; } // set to append, move cursor -void append(struct file *file) { file->offset = file->inode->len; } +void append(struct file *file) { file->offset = file->vnode->len; } diff --git a/kernel/fs/tarfs.c b/kernel/fs/tarfs.c index e2bf5744..ebfff6bf 100644 --- a/kernel/fs/tarfs.c +++ b/kernel/fs/tarfs.c @@ -51,7 +51,7 @@ void *tarfs_get_file(struct tar_header *tar, const char *filename) { tar = (struct tar_header *)next_tar; } - return NULL; + return nullptr; } size_t tarfs_get_len(struct tar_header *tar, const char *filename) { diff --git a/kernel/fs/tmpfs.c b/kernel/fs/tmpfs.c index 4218919a..db3741a8 100644 --- a/kernel/fs/tmpfs.c +++ b/kernel/fs/tmpfs.c @@ -1,20 +1,20 @@ #include #include -#include #include +#include #include struct file_system *new_tmpfs_file_system(void) { struct file_system *file_system = zmalloc(sizeof(struct file_system)); file_system->ops = &default_file_system_ops; - file_system->next_inode_number = 2; - list_init(&file_system->inodes); + file_system->next_vnode_number = 2; + list_init(&file_system->vnodes); - struct inode *root_inode = new_inode(file_system, _NG_DIR | 0755); + struct vnode *root_vnode = new_vnode(file_system, _NG_DIR | 0755); struct dentry *root = new_dentry(); root->parent = root; root->file_system = file_system; - attach_inode(root, root_inode); + attach_vnode(root, root_vnode); file_system->root = root; return file_system; diff --git a/kernel/fs/tty.c b/kernel/fs/tty.c index aa2990ed..dda10fac 100644 --- a/kernel/fs/tty.c +++ b/kernel/fs/tty.c @@ -1,6 +1,6 @@ #include #include -#include +#include #include #include @@ -8,7 +8,7 @@ // #define wake_from wq_notify_all static struct tty *file_tty(struct file *file) { - int minor = file->inode->device_minor; + int minor = file->vnode->device_minor; if (minor > 32 || minor < 0) return TO_ERROR(-ENODEV); struct tty *tty = global_ttys[minor]; @@ -75,7 +75,7 @@ int tty_ioctl(struct file *file, int request, void *argp) { return -EINVAL; } -struct file_operations tty_ops = { +struct file_ops tty_ops = { .read = tty_read, .write = tty_write, .ioctl = tty_ioctl, diff --git a/kernel/fs/inode.c b/kernel/fs/vnode.c similarity index 50% rename from kernel/fs/inode.c rename to kernel/fs/vnode.c index d1ca294a..a00233f8 100644 --- a/kernel/fs/inode.c +++ b/kernel/fs/vnode.c @@ -1,21 +1,21 @@ #include #include -#include +#include #include -struct inode_operations default_ops = { 0 }; +struct vnode_ops default_ops = { 0 }; static int close_file_refcounts(struct file *file); static int open_file_refcounts(struct file *file) { - // TODO: should the dentry refcounts be managed by inode.c? + // TODO: should the dentry refcounts be managed by vnode.c? if (file->dentry) atomic_fetch_add(&file->dentry->file_refcnt, 1); if (file->flags & O_RDONLY) - atomic_fetch_add(&file->inode->read_refcnt, 1); + atomic_fetch_add(&file->vnode->read_refcnt, 1); if (file->flags & O_WRONLY) - atomic_fetch_add(&file->inode->write_refcnt, 1); + atomic_fetch_add(&file->vnode->write_refcnt, 1); return 0; } @@ -25,10 +25,10 @@ int open_file(struct file *file) { int err = 0; open_file_refcounts(file); - if (file->inode->ops->open) - err = file->inode->ops->open(file->inode, file); + if (file->vnode->ops->open) + err = file->vnode->ops->open(file->vnode, file); - access_inode(file->inode); + access_vnode(file->vnode); // What should the "open fails" pattern be? // if (IS_ERROR(err)) @@ -38,14 +38,14 @@ int open_file(struct file *file) { } static int close_file_refcounts(struct file *file) { - // TODO: should the dentry refcounts be managed by inode.c? + // TODO: should the dentry refcounts be managed by vnode.c? if (file->dentry) atomic_fetch_sub(&file->dentry->file_refcnt, 1); if (file->flags & O_RDONLY) - atomic_fetch_sub(&file->inode->read_refcnt, 1); + atomic_fetch_sub(&file->vnode->read_refcnt, 1); if (file->flags & O_WRONLY) - atomic_fetch_sub(&file->inode->write_refcnt, 1); + atomic_fetch_sub(&file->vnode->write_refcnt, 1); return 0; } @@ -54,31 +54,31 @@ int close_file(struct file *file) { int err = 0; close_file_refcounts(file); - if (file->inode->ops->close) - err = file->inode->ops->close(file->inode, file); + if (file->vnode->ops->close) + err = file->vnode->ops->close(file->vnode, file); if (file->dentry) maybe_delete_dentry(file->dentry); else - maybe_delete_inode(file->inode); + maybe_delete_vnode(file->vnode); return err; } -void maybe_delete_inode(struct inode *inode) { - if (inode->dentry_refcnt) +void maybe_delete_vnode(struct vnode *vnode) { + if (vnode->dentry_refcnt) return; - if (inode->read_refcnt) + if (vnode->read_refcnt) return; - if (inode->write_refcnt) + if (vnode->write_refcnt) return; - // inode->delete() that writes back to disk etc.? + // vnode->delete() that writes back to disk etc.? - if (inode->symlink_destination) - free((void *)inode->symlink_destination); - list_remove(&inode->fs_inodes); + if (vnode->symlink_destination) + free((void *)vnode->symlink_destination); + list_remove(&vnode->fs_vnodes); // #include - // printf("inode (%c) freed\n", __filetype_sigils[inode->type]); - free(inode); + // printf("vnode (%c) freed\n", __filetype_sigils[vnode->type]); + free(vnode); } diff --git a/kernel/lib/commandline.c b/kernel/lib/commandline.c index 4bfe735a..4ffce18e 100644 --- a/kernel/lib/commandline.c +++ b/kernel/lib/commandline.c @@ -35,5 +35,5 @@ const char *get_kernel_argument(const char *key) { cursor = strchr(cursor, 0) + 1; } - return NULL; + return nullptr; } diff --git a/kernel/lib/mod.c b/kernel/lib/mod.c index 9e106fac..419d21c6 100644 --- a/kernel/lib/mod.c +++ b/kernel/lib/mod.c @@ -8,7 +8,7 @@ struct list loaded_mods = LIST_INIT(loaded_mods); struct mod_sym elf_find_symbol_by_address(uintptr_t address) { - struct mod *in_mod = NULL; + struct mod *in_mod = nullptr; elf_md *in_elf = &elf_ngk_md; list_for_each_safe (&loaded_mods) { struct mod *mod = container_of(struct mod, node, it); @@ -29,20 +29,20 @@ struct mod_sym elf_find_symbol_by_address(uintptr_t address) { } } -elf_md *elf_mod_load(struct inode *); +elf_md *elf_mod_load(struct vnode *); sysret sys_loadmod(int fd) { int perm = USR_READ; struct file *ofd = get_file(fd); - if (ofd == NULL) + if (ofd == nullptr) return -EBADF; if (!read_mode(ofd)) return -EPERM; - struct inode *inode = ofd->inode; - if (inode->type != FT_NORMAL) + struct vnode *vnode = ofd->vnode; + if (vnode->type != FT_NORMAL) return -ENOEXEC; - elf_md *e = elf_mod_load(inode); + elf_md *e = elf_mod_load(vnode); if (!e) return -ENOEXEC; @@ -67,7 +67,7 @@ sysret sys_loadmod(int fd) { return 0; } -void proc_mods(struct file *ofd, void *_) { +void proc_mods(struct file *ofd, void *) { proc_sprintf(ofd, "name start end\n"); list_for_each_safe (&loaded_mods) { struct mod *mod = container_of(struct mod, node, it); diff --git a/kernel/lib/string.c b/kernel/lib/string.c index 2ddde455..148c9fe7 100644 --- a/kernel/lib/string.c +++ b/kernel/lib/string.c @@ -16,7 +16,7 @@ int chr_in(char chr, const char *options) { */ const char *str_until(const char *source, char *tok, const char *delims) { size_t i; - const char *rest = NULL; + const char *rest = nullptr; for (i = 0; source[i]; i++) { if (chr_in(source[i], delims)) diff --git a/kernel/lib/trace.c b/kernel/lib/trace.c index d43e5ae0..9b7d9bdc 100644 --- a/kernel/lib/trace.c +++ b/kernel/lib/trace.c @@ -85,7 +85,7 @@ static sysret trace_detach(struct thread *th) { if (!th) return -ESRCH; list_remove(&th->trace_node); - th->tracer = NULL; + th->tracer = nullptr; return trace_start(th, TRACE_RUNNING, 0); } diff --git a/kernel/lib/ubsan.c b/kernel/lib/ubsan.c index b8a88046..c01cb604 100644 --- a/kernel/lib/ubsan.c +++ b/kernel/lib/ubsan.c @@ -169,13 +169,14 @@ void __ubsan_handle_out_of_bounds() { } void __ubsan_handle_nonnull_arg(struct nonnull_arg_info *info) { - printf("ubsan: NULL passed to function argument marked nonnull\n"); + printf("ubsan: nullptr passed to function argument marked nonnull\n"); printf(" argument %i\n", info->arg_index); print_sloc(&info->loc); panic_bt("ubsan"); } void __ubsan_handle_function_type_mismatch() { + return; // disabled! printf("ubsan: function type mismatch detected\n"); printf("INFO TODO\n"); panic_bt("ubsan"); diff --git a/kernel/mem/dmgr.c b/kernel/mem/dmgr.c index f2cb6bd5..e354b1ba 100644 --- a/kernel/mem/dmgr.c +++ b/kernel/mem/dmgr.c @@ -40,7 +40,7 @@ int dmgr_insert(struct dmgr *d, void *ptr) { void *dmgr_get(struct dmgr *d, int handle) { if (handle > d->cap) - return NULL; + return nullptr; return d->data[handle]; } diff --git a/kernel/mem/mman.c b/kernel/mem/mman.c index 5cf016f7..fd76405f 100644 --- a/kernel/mem/mman.c +++ b/kernel/mem/mman.c @@ -67,7 +67,7 @@ sysret sys_mmap( // // It doesn't do a lot of mmap things at all. - if (addr != NULL) + if (addr != nullptr) return -ETODO; if (!(flags & MAP_PRIVATE)) return -ETODO; @@ -80,11 +80,11 @@ sysret sys_mmap( struct file *ofd = get_file(fd); if (!ofd) return -EBADF; - struct inode *inode = ofd->inode; - if (inode->type != FT_NORMAL) + struct vnode *vnode = ofd->vnode; + if (vnode->type != FT_NORMAL) return -ENODEV; - size_t to_copy = MIN(len, inode->len); - memcpy((void *)new_alloc, inode->data, to_copy); + size_t to_copy = MIN(len, vnode->len); + memcpy((void *)new_alloc, vnode->data, to_copy); } return new_alloc; diff --git a/kernel/mem/pmm.c b/kernel/mem/pmm.c index e9153b33..4ddeaf94 100644 --- a/kernel/mem/pmm.c +++ b/kernel/mem/pmm.c @@ -181,7 +181,7 @@ static const char *type(int disp) { } } -void pm_summary(struct file *ofd, void *_) { +void pm_summary(struct file *ofd, void *) { /* last: * 0: PM_NOMEM * 1: PM_LEAK diff --git a/kernel/mem/spalloc.c b/kernel/mem/spalloc.c index 88c05ea7..aa46a1c5 100644 --- a/kernel/mem/spalloc.c +++ b/kernel/mem/spalloc.c @@ -10,7 +10,7 @@ void _internal_sp_init(struct spalloc *sp, ssize_t object_size, sp->object_size = object_size >= sizeof(void *) ? object_size : sizeof(void *); sp->region = vmm_reserve(capacity * object_size); - sp->first_free = NULL; + sp->first_free = nullptr; sp->bump_free = sp->region; sp->count = 0; sp->capacity = capacity; diff --git a/kernel/modules/bss.c b/kernel/modules/bss.c index dffcc97b..b291cf4d 100644 --- a/kernel/modules/bss.c +++ b/kernel/modules/bss.c @@ -25,7 +25,7 @@ int n[100] __attribute__((aligned(64))) = { 0 }; int o[100] = { 1 }; int p[100] __attribute__((aligned(64))) = { 1 }; -int init_mod() { +int init_mod(struct mod *) { printf("ints: %p %p %p %p %p %p %p %p\n" "arrays: %p %p %p %p %p %p %p %p\n", (void *)&a, (void *)&b, (void *)&c, (void *)&d, (void *)&e, (void *)&f, diff --git a/kernel/modules/file.c b/kernel/modules/file.c index bbb468b0..81f49af3 100644 --- a/kernel/modules/file.c +++ b/kernel/modules/file.c @@ -10,7 +10,7 @@ ssize_t my_file_read(struct file *ofd, char *buf, size_t len) { return (ssize_t)len; } -struct file_operations my_file_ops = { +struct file_ops my_file_ops = { .read = my_file_read, }; @@ -20,19 +20,19 @@ int make_my_file(const char *name) { printf("error %li creating %s\n", -ERROR(path), name); return MODINIT_FAILURE; } - if (dentry_inode(path)) { + if (dentry_vnode(path)) { printf("error creating %s: already exists\n", name); return MODINIT_FAILURE; } - struct inode *inode = new_inode(path->file_system, 0444); - inode->type = FT_CHAR_DEV; - inode->file_ops = &my_file_ops; - attach_inode(path, inode); + struct vnode *vnode = new_vnode(path->file_system, 0444); + vnode->type = FT_CHAR_DEV; + vnode->file_ops = &my_file_ops; + attach_vnode(path, vnode); return MODINIT_SUCCESS; } -int init(struct mod *_) { +int init(struct mod *) { printf("Hello World from this kernel module!\n"); return make_my_file("/dev/modfile"); } diff --git a/kernel/modules/procmod.c b/kernel/modules/procmod.c index dc2f7d46..e2d4673e 100644 --- a/kernel/modules/procmod.c +++ b/kernel/modules/procmod.c @@ -2,12 +2,12 @@ #include #include -void module_procfile(struct file *ofd, void *_) { +void module_procfile(struct file *ofd, void *) { proc_sprintf(ofd, "Hello World from a kernel module\n"); } -int modinit(struct mod *_) { - make_proc_file("mod", module_procfile, NULL); +int modinit(struct mod *) { + make_proc_file("mod", module_procfile, nullptr); return MODINIT_SUCCESS; } diff --git a/kernel/modules/syscall.c b/kernel/modules/syscall.c index 74384aa9..52374baf 100644 --- a/kernel/modules/syscall.c +++ b/kernel/modules/syscall.c @@ -11,7 +11,7 @@ sysret sys_module_syscall(void) { return 0; } -int init_mod() { +int init_mod(struct mod *) { int num = syscall_register( 101, "module_syscall", sys_module_syscall, "module_syscall()", 0); printf("syscall registered\n"); diff --git a/kernel/modules/thread.c b/kernel/modules/thread.c index b99d149d..7ffc2e05 100644 --- a/kernel/modules/thread.c +++ b/kernel/modules/thread.c @@ -3,16 +3,16 @@ #include #include -void mod_kthread() { +void mod_kthread(void *) { printf("This is the thread!\n"); while (true) sleep_thread(seconds(1)); } -int init_mod(struct mod *_) { +int init_mod(struct mod *) { printf("Hello World from this kernel module!\n"); printf("Imma make a thread now!\n"); - kthread_create(mod_kthread, NULL); + kthread_create(mod_kthread, nullptr); return MODINIT_SUCCESS; } diff --git a/kernel/mt/exec.c b/kernel/mt/exec.c index fdc17ce8..b2a8cdac 100644 --- a/kernel/mt/exec.c +++ b/kernel/mt/exec.c @@ -55,7 +55,7 @@ char *const *exec_concat_args(char *const a1[], char *const a2[]) { char *const *exec_copy_args(char **out, char *const args[]) { if (!args) - return NULL; + return nullptr; struct args_size size = size_args(args); if (!out) out = malloc((size.count + 1) * sizeof(char *) + size.strlen); @@ -100,12 +100,12 @@ size_t argc(char *const args[]) { // loading ---------------------------------------------------------------- -elf_md *exec_open_elf(struct inode *inode) { - if (inode->type != FT_NORMAL) - return NULL; - void *buffer = inode->data; +elf_md *exec_open_elf(struct vnode *vnode) { + if (vnode->type != FT_NORMAL) + return nullptr; + void *buffer = vnode->data; - elf_md *e = elf_parse(buffer, inode->len); + elf_md *e = elf_parse(buffer, vnode->len); return e; } @@ -126,20 +126,20 @@ void exec_memory_setup(void) { user_map(USER_ENVP, USER_ENVP + 0x2000); } -const char *exec_shebang(struct inode *inode) { - if (inode->type != FT_NORMAL) - return false; - char *buffer = inode->data; - if (inode->len > 2 && buffer[0] == '#' && buffer[1] == '!') { +const char *exec_shebang(struct vnode *vnode) { + if (vnode->type != FT_NORMAL) + return nullptr; + char *buffer = vnode->data; + if (vnode->len > 2 && buffer[0] == '#' && buffer[1] == '!') { return buffer + 2; } - return NULL; + return nullptr; } const char *exec_interp(elf_md *e) { const Elf_Phdr *interp = elf_find_phdr(e, PT_INTERP); if (!interp) - return NULL; + return nullptr; return (char *)e->buffer + interp->p_offset; } @@ -166,19 +166,19 @@ sysret do_execve(struct dentry *dentry, struct interrupt_frame *frame, return -EINVAL; } - struct inode *inode = dentry_inode(dentry), *interp = NULL; + struct vnode *vnode = dentry_vnode(dentry), *interp = nullptr; // copy args to kernel space so they survive if they point to the old args const char *path_tmp; char *const *stored_args = { 0 }; char interp_buf[256] = { 0 }; - if (!(inode->mode & USR_EXEC)) + if (!(vnode->mode & USR_EXEC)) return -ENOEXEC; exec_memory_setup(); strncpy(running_process->comm, dentry->name, COMM_SIZE); - if ((path_tmp = exec_shebang(inode))) { + if ((path_tmp = exec_shebang(vnode))) { /* Script: * #!/bin/a b c * @@ -196,14 +196,14 @@ sysret do_execve(struct dentry *dentry, struct interrupt_frame *frame, dentry = resolve_path(interp_args[0]); if (IS_ERROR(dentry)) return ERROR(dentry); - inode = dentry_inode(dentry); - if (!inode) + vnode = dentry_vnode(dentry); + if (!vnode) return -ENOENT; } else { - stored_args = exec_copy_args(NULL, argv); + stored_args = exec_copy_args(nullptr, argv); } - elf_md *e = exec_open_elf(inode); + elf_md *e = exec_open_elf(vnode); if (!e) return -ENOEXEC; if (running_process->elf_metadata) @@ -218,8 +218,8 @@ sysret do_execve(struct dentry *dentry, struct interrupt_frame *frame, dentry = resolve_path(path_tmp); if (IS_ERROR(dentry)) return ERROR(dentry); - interp = dentry_inode(dentry); - if (!inode) + interp = dentry_vnode(dentry); + if (!vnode) return -ENOENT; elf_md *interp_md = exec_open_elf(interp); @@ -259,8 +259,8 @@ sysret sys_execveat(struct interrupt_frame *frame, int dir_fd, char *filename, if (IS_ERROR(dentry)) return ERROR(dentry); - struct inode *inode = dentry_inode(dentry); - if (!inode) + struct vnode *vnode = dentry_vnode(dentry); + if (!vnode) return -ENOENT; return do_execve(dentry, frame, filename, argv, envp); diff --git a/kernel/mt/mutex.c b/kernel/mt/mutex.c index 0d6aa838..1db86e47 100644 --- a/kernel/mt/mutex.c +++ b/kernel/mt/mutex.c @@ -50,7 +50,7 @@ void wait_on_mutex_cv(mutex_t *condvar, mutex_t *mutex) { mutex_lock(mutex); } -void wait_on_mutex(mutex_t *mutex) { wait_on_mutex_cv(mutex, NULL); } +void wait_on_mutex(mutex_t *mutex) { wait_on_mutex_cv(mutex, nullptr); } int mutex_lock(mutex_t *mutex) { while (!mutex_trylock(mutex)) { @@ -67,7 +67,7 @@ void wake_awaiting_thread(mutex_t *mutex) { return; int n_awaiting = 0; int best_deli_ticket = INT_MAX; - struct thread *winning_thread = NULL; + struct thread *winning_thread = nullptr; list_for_each (&all_threads) { struct thread *th = container_of(struct thread, all_threads, it); if (th->state != TS_BLOCKED) diff --git a/kernel/mt/sync_testbed.c b/kernel/mt/sync_testbed.c index 9fe92d8b..ca7e4a1f 100644 --- a/kernel/mt/sync_testbed.c +++ b/kernel/mt/sync_testbed.c @@ -4,7 +4,7 @@ void sync_test_controller(void *); -void run_sync_tests(void) { kthread_create(sync_test_controller, NULL); } +void run_sync_tests(void) { kthread_create(sync_test_controller, nullptr); } mutex_t join_mutex; mutex_t new_m; @@ -19,7 +19,7 @@ const long print = loops / 10; void sync_thread(void *); -void sync_test_controller(void *_) { +void sync_test_controller(void *) { mutex_init(&new_m); mutex_init(&join_mutex); cv_init(&join_cv); @@ -27,7 +27,7 @@ void sync_test_controller(void *_) { int n = 3; atomic_store(&n_threads, n); for (int i = 0; i < n; i++) - kthread_create(sync_thread, NULL); + kthread_create(sync_thread, nullptr); while (atomic_load(&n_threads) > 0) { mutex_lock(&join_mutex); @@ -42,7 +42,7 @@ void sync_test_controller(void *_) { kthread_exit(); } -void sync_thread(void *_) { +void sync_thread(void *) { for (int i = 0; i < loops; i++) unsynchronized++; diff --git a/kernel/mt/thread.c b/kernel/mt/thread.c index 31bd82fb..114fadc3 100644 --- a/kernel/mt/thread.c +++ b/kernel/mt/thread.c @@ -30,7 +30,7 @@ LIST_DEFINE(all_threads); LIST_DEFINE(runnable_thread_queue); spinlock_t runnable_lock; LIST_DEFINE(freeable_thread_queue); -struct thread *finalizer = NULL; +struct thread *finalizer = nullptr; extern struct tar_header *initfs; @@ -61,7 +61,7 @@ struct process proc_zero = { .magic = PROC_MAGIC, .comm = "", .vm_root = -1, // this is reset in arch_init - .parent = NULL, + .parent = nullptr, .children = LIST_INIT(proc_zero.children), .threads = LIST_INIT(proc_zero.threads), }; @@ -121,13 +121,13 @@ void threads_init() { list_append(&all_threads, &thread_zero.all_threads); list_append(&proc_zero.threads, &thread_zero.process_threads); - make_proc_file("threads", proc_threads, NULL); - make_proc_file("threads2", proc_threads_detail, NULL); - make_proc_file("zombies", proc_zombies, NULL); - make_proc_file("thread_cpus", proc_cpus, NULL); + make_proc_file("threads", proc_threads, nullptr); + make_proc_file("threads2", proc_threads_detail, nullptr); + make_proc_file("zombies", proc_zombies, nullptr); + make_proc_file("thread_cpus", proc_cpus, nullptr); - finalizer = kthread_create(finalizer_kthread, NULL); - insert_timer_event(milliseconds(10), thread_timer, NULL); + finalizer = kthread_create(finalizer_kthread, nullptr); + insert_timer_event(milliseconds(10), thread_timer, nullptr); } static struct process *new_process_slot() { @@ -149,8 +149,8 @@ struct thread *thread_by_id(pid_t tid) { return dmgr_get(&threads, tid); } struct process *process_by_id(pid_t pid) { struct thread *th = thread_by_id(pid); - if (th == NULL) - return NULL; + if (th == nullptr) + return nullptr; if (th == ZOMBIE) return ZOMBIE; return th->proc; @@ -158,7 +158,7 @@ struct process *process_by_id(pid_t pid) { static void make_freeable(struct thread *defunct) { assert(defunct->state == TS_DEAD); - assert(defunct->freeable.next == NULL); + assert(defunct->freeable.next == nullptr); DEBUG_PRINTF("freeable(%i)\n", defunct->tid); list_append(&freeable_thread_queue, &defunct->freeable); thread_enqueue(finalizer); @@ -303,7 +303,7 @@ static void fxrstor(fp_ctx *fpctx) { static struct thread *next_runnable_thread() { if (list_empty(&runnable_thread_queue)) - return NULL; + return nullptr; struct thread *rt; spin_lock(&runnable_lock); list_node *it = list_pop_front(&runnable_thread_queue); @@ -533,7 +533,7 @@ static struct process *new_process(struct thread *th) { static void new_userspace_entry(void *filename) { interrupt_frame *frame = (void *)(USER_STACK - 16 - sizeof(interrupt_frame)); - sysret err = sys_execve(frame, filename, NULL, NULL); + sysret err = sys_execve(frame, filename, nullptr, nullptr); assert(err == 0 && "BOOTSTRAP ERROR"); asm volatile("mov %0, %%rsp \n\t" @@ -604,7 +604,7 @@ sysret sys_procstate(pid_t destination, enum procstate flags) { return 0; } -noreturn static void finalizer_kthread(void *_) { +noreturn static void finalizer_kthread(void *) { while (true) { struct thread *th; @@ -822,7 +822,7 @@ static void destroy_child_process(struct process *proc) { vmm_destroy_tree(proc->vm_root); if (proc->elf_metadata) free(proc->elf_metadata); - proc->elf_metadata = NULL; + proc->elf_metadata = nullptr; free_process_slot(proc); } @@ -830,7 +830,7 @@ static void destroy_child_process(struct process *proc) { // interrupts disabled. destroy_child_process will re-enable them. static struct process *find_dead_child(pid_t query) { if (list_empty(&running_process->children)) - return NULL; + return nullptr; list_for_each (&running_process->children) { struct process *child = container_of(struct process, siblings, it); if (!process_matches(query, child)) @@ -838,12 +838,12 @@ static struct process *find_dead_child(pid_t query) { if (child->exit_status > 0) return child; } - return NULL; + return nullptr; } static struct thread *find_waiting_tracee(pid_t query) { if (list_empty(&running_addr()->tracees)) - return NULL; + return nullptr; list_for_each (&running_addr()->tracees) { struct thread *th = container_of(struct thread, trace_node, it); if (query != 0 && query != th->tid) @@ -851,7 +851,7 @@ static struct thread *find_waiting_tracee(pid_t query) { if (th->state == TS_TRWAIT) return th; } - return NULL; + return nullptr; } static void wait_for(pid_t pid) { @@ -1061,7 +1061,7 @@ sysret sys_top(int show_threads) { } void unsleep_thread(struct thread *t) { - t->wait_event = NULL; + t->wait_event = nullptr; t->state = TS_RUNNING; thread_enqueue(t); } @@ -1083,13 +1083,13 @@ sysret sys_sleepms(int ms) { return 0; } -void thread_timer(void *_) { - insert_timer_event(THREAD_TIME, thread_timer, NULL); +void thread_timer(void *) { + insert_timer_event(THREAD_TIME, thread_timer, nullptr); thread_yield(); } bool user_map(virt_addr_t base, virt_addr_t top) { - struct mm_region *slot = NULL, *test; + struct mm_region *slot = nullptr, *test; for (int i = 0; i < NREGIONS; i++) { test = &running_process->mm_regions[i]; if (test->base == 0) { @@ -1103,13 +1103,13 @@ bool user_map(virt_addr_t base, virt_addr_t top) { slot->base = base; slot->top = top; slot->flags = 0; - slot->inode = 0; + slot->vnode = 0; vmm_create_unbacked_range(base, top - base, PAGE_WRITEABLE | PAGE_USERMODE); return true; } -void proc_threads(struct file *ofd, void *_) { +void proc_threads(struct file *ofd, void *) { proc_sprintf(ofd, "tid pid ppid comm\n"); list_for_each (&all_threads) { struct thread *th = container_of(struct thread, all_threads, it); @@ -1120,7 +1120,7 @@ void proc_threads(struct file *ofd, void *_) { } } -void proc_threads_detail(struct file *ofd, void *_) { +void proc_threads_detail(struct file *ofd, void *) { proc_sprintf(ofd, "%15s %5s %5s %5s %7s %7s %15s %7s\n", "comm", "tid", "pid", "ppid", "n_sched", "time", "tsc", "tsc/1B"); list_for_each (&all_threads) { @@ -1134,7 +1134,7 @@ void proc_threads_detail(struct file *ofd, void *_) { } } -void proc_zombies(struct file *ofd, void *_) { +void proc_zombies(struct file *ofd, void *) { void **th; int i = 0; for (th = threads.data; i < threads.cap; th++, i++) { @@ -1154,11 +1154,11 @@ void proc_fds(struct file *file, void *arg); ssize_t proc_fds_getdents(struct file *file, struct dirent *buf, size_t len); struct dentry *proc_fds_lookup(struct dentry *dentry, const char *child); -struct file_operations proc_fds_ops = { +struct file_ops proc_fds_ops = { .getdents = proc_fds_getdents, }; -struct inode_operations proc_fds_inode_ops = { +struct vnode_ops proc_fds_vnode_ops = { .lookup = proc_fds_lookup, }; @@ -1172,7 +1172,7 @@ struct proc_spec { }; void make_proc_directory(struct thread *thread) { - struct inode *dir = new_inode(proc_file_system, _NG_DIR | 0555); + struct vnode *dir = new_vnode(proc_file_system, _NG_DIR | 0555); struct dentry *ddir = proc_file_system->root; char name[32]; sprintf(name, "%i", thread->tid); @@ -1182,16 +1182,16 @@ void make_proc_directory(struct thread *thread) { for (int i = 0; i < ARRAY_LEN(proc_spec); i++) { struct proc_spec *spec = &proc_spec[i]; - struct inode *inode = new_proc_inode(spec->mode, spec->func, thread); - add_child(ddir, spec->name, inode); + struct vnode *vnode = new_proc_vnode(spec->mode, spec->func, thread); + add_child(ddir, spec->name, vnode); } - struct inode *inode = new_inode(proc_file_system, _NG_DIR | 0555); - extern struct file_operations proc_dir_file_ops; - inode->file_ops = &proc_fds_ops; - inode->ops = &proc_fds_inode_ops; - inode->data = thread; - add_child(ddir, "fds2", inode); + struct vnode *vnode = new_vnode(proc_file_system, _NG_DIR | 0555); + extern struct file_ops proc_dir_file_ops; + vnode->file_ops = &proc_fds_ops; + vnode->ops = &proc_fds_vnode_ops; + vnode->data = thread; + add_child(ddir, "fds2", vnode); thread->proc_dir = ddir; } @@ -1220,10 +1220,10 @@ void proc_fds(struct file *file, void *arg) { if (!f) continue; struct dentry *d = f->dentry; - struct inode *n = f->inode; + struct vnode *n = f->vnode; if (!d) { proc_sprintf(file, "%i %c@%i\n", i, __filetype_sigils[n->type], - n->inode_number); + n->vnode_number); } else { pathname(d, buffer, 128); proc_sprintf(file, "%i %s\n", i, buffer); @@ -1241,7 +1241,7 @@ mode_t proc_fd_mode(struct file *file) { } ssize_t proc_fds_getdents(struct file *file, struct dirent *buf, size_t len) { - struct thread *thread = file->inode->data; + struct thread *thread = file->vnode->data; struct file **files = thread->proc->files; size_t offset = 0; for (int i = 0; i < thread->proc->n_files; i++) { @@ -1261,14 +1261,14 @@ ssize_t proc_fds_getdents(struct file *file, struct dirent *buf, size_t len) { return offset; } -ssize_t proc_fd_readlink(struct inode *inode, char *buffer, size_t len); +ssize_t proc_fd_readlink(struct vnode *vnode, char *buffer, size_t len); -struct inode_operations proc_fd_ops = { +struct vnode_ops proc_fd_ops = { .readlink = proc_fd_readlink, }; struct dentry *proc_fds_lookup(struct dentry *dentry, const char *child) { - struct thread *thread = dentry->inode->data; + struct thread *thread = dentry->vnode->data; struct file **files = thread->proc->files; char *end; int fd = strtol(child, &end, 10); @@ -1278,33 +1278,33 @@ struct dentry *proc_fds_lookup(struct dentry *dentry, const char *child) { return TO_ERROR(-ENOENT); if (!files[fd]) return TO_ERROR(-ENOENT); - struct inode *inode - = new_inode(proc_file_system, _NG_SYMLINK | proc_fd_mode(files[fd])); - inode->ops = &proc_fd_ops; - inode->extra = files[fd]; + struct vnode *vnode + = new_vnode(proc_file_system, _NG_SYMLINK | proc_fd_mode(files[fd])); + vnode->ops = &proc_fd_ops; + vnode->extra = files[fd]; struct dentry *ndentry = new_dentry(); - attach_inode(ndentry, inode); + attach_vnode(ndentry, vnode); ndentry->name = strdup(child); return ndentry; } -ssize_t proc_fd_readlink(struct inode *inode, char *buffer, size_t len) { - struct file *file = inode->extra; +ssize_t proc_fd_readlink(struct vnode *vnode, char *buffer, size_t len) { + struct file *file = vnode->extra; if (file->dentry) { memset(buffer, 0, len); return pathname(file->dentry, buffer, len); } else { - const char *type = __filetype_names[file->inode->type]; + const char *type = __filetype_names[file->vnode->type]; return snprintf( - buffer, len, "%s:[%i]", type, file->inode->inode_number); + buffer, len, "%s:[%i]", type, file->vnode->vnode_number); } } -ssize_t proc_self_readlink(struct inode *inode, char *buffer, size_t len) { +ssize_t proc_self_readlink(struct vnode *vnode, char *buffer, size_t len) { return snprintf(buffer, len, "%i", running_thread->tid); } -struct inode_operations proc_self_ops = { +struct vnode_ops proc_self_ops = { .readlink = proc_self_readlink, }; diff --git a/kernel/syscall.c b/kernel/syscall.c index e6554924..04b8b410 100644 --- a/kernel/syscall.c +++ b/kernel/syscall.c @@ -62,6 +62,12 @@ enum ptr_status check_ptr(unsigned enable, uintptr_t ptr) { } } +typedef sysret (*frame_syscall_fn)(interrupt_frame *frame, uintptr_t arg1, + uintptr_t arg2, uintptr_t arg3, uintptr_t arg4, uintptr_t arg5, + uintptr_t arg6); +typedef sysret (*syscall_fn)(uintptr_t arg1, uintptr_t arg2, uintptr_t arg3, + uintptr_t arg4, uintptr_t arg5, uintptr_t arg6); + sysret call_syscall(enum ng_syscall syscall_num, interrupt_frame *frame, uintptr_t arg1, uintptr_t arg2, uintptr_t arg3, uintptr_t arg4, uintptr_t arg5, uintptr_t arg6) { @@ -70,8 +76,8 @@ sysret call_syscall(enum ng_syscall syscall_num, interrupt_frame *frame, if (syscall_num >= SYSCALL_TABLE_SIZE || syscall_num <= 0) { return -ENOSYS; } - sysret (*syscall)() = syscall_table[syscall_num]; - if (!syscall) + void *syscall_ptr = syscall_table[syscall_num]; + if (!syscall_ptr) return -ENOSYS; if (running_thread->flags & TF_SYSCALL_TRACE) { @@ -92,9 +98,11 @@ sysret call_syscall(enum ng_syscall syscall_num, interrupt_frame *frame, syscall_num, arg1, arg2, arg3, arg4, arg5, arg6); if (syscall_num == NG_EXECVE || syscall_num == NG_FORK - || syscall_num == NG_CLONE0) { + || syscall_num == NG_CLONE0 || syscall_num == NG_EXECVEAT) { + frame_syscall_fn syscall = (frame_syscall_fn)syscall_ptr; ret = syscall(frame, arg1, arg2, arg3, arg4, arg5, arg6); } else { + syscall_fn syscall = (syscall_fn)syscall_ptr; ret = syscall(arg1, arg2, arg3, arg4, arg5, arg6); } @@ -146,7 +154,7 @@ sysret do_syscall(interrupt_frame *frame) { sysret do_syscall_from_submission(struct submission *sub) { if (running_thread->flags & TF_SYSCALL_TRACE) printf(" "); - return call_syscall(sub->syscall_num, NULL, sub->args[0], sub->args[1], + return call_syscall(sub->syscall_num, nullptr, sub->args[0], sub->args[1], sub->args[2], sub->args[3], sub->args[4], sub->args[5]); } diff --git a/kernel/timer.c b/kernel/timer.c index 192ce5d5..4ee9e6ec 100644 --- a/kernel/timer.c +++ b/kernel/timer.c @@ -38,7 +38,7 @@ struct timer_event { void timer_init() { sp_init(&timer_pool, struct timer_event); - irq_install(0, timer_handler, NULL); + irq_install(0, timer_handler, nullptr); } void assert_consistency(struct timer_event *t) { @@ -83,7 +83,7 @@ void drop_timer_event(struct timer_event *te) { sp_free(&timer_pool, te); } -void timer_procfile(struct file *ofd, void *_) { +void timer_procfile(struct file *ofd, void *) { proc_sprintf(ofd, "The time is: %lu\n", kernel_timer); proc_sprintf(ofd, "Pending events:\n"); spin_lock(&timer_q_lock); diff --git a/libc/fstdio.c b/libc/fstdio.c index 70231b34..e0166c13 100644 --- a/libc/fstdio.c +++ b/libc/fstdio.c @@ -243,7 +243,7 @@ char *fgets(char *s, int size, FILE *stream) { if (copy_line(s, stream, size)) { return s; } else { - return NULL; + return nullptr; } } @@ -326,7 +326,7 @@ static FILE *_fopen_to(const char *filename, const char *mode, FILE *f) { int fd = open(filename, _oflags(mode)); if (fd < 0) - return NULL; + return nullptr; f->mode = _smode(mode); f->buffer_size = BUFSIZ; @@ -352,7 +352,7 @@ FILE *fopen(const char *filename, const char *mode) { FILE *ret = _fopen_to(filename, mode, f); if (!ret) { _delete_file(f); - return NULL; + return nullptr; } return ret; } @@ -365,7 +365,7 @@ FILE *freopen(const char *filename, const char *mode, FILE *stream) { // which (if any) mode changes are allowed. I currently define // the set to be empty. fclose(stream); - return NULL; + return nullptr; } close(stream->fd); stream = _fopen_to(filename, mode, stream); @@ -471,7 +471,7 @@ void setbuffer(FILE *stream, char *buf, size_t size) { setvbuf(stream, buf, buf ? _IOFBF : _IONBF, size); } -void setlinebuf(FILE *stream) { setvbuf(stream, NULL, _IOLBF, BUFSIZ); } +void setlinebuf(FILE *stream) { setvbuf(stream, nullptr, _IOLBF, BUFSIZ); } int setvbuf(FILE *stream, char *buf, int mode, size_t size) { stream->buffer_data = buf; @@ -483,11 +483,11 @@ int setvbuf(FILE *stream, char *buf, int mode, size_t size) { void __nc_f_init(void) { list_init(&__all_files); stdin = fdopen(0, "r"); - setvbuf(stdin, NULL, _IOLBF, 0); + setvbuf(stdin, nullptr, _IOLBF, 0); stdout = fdopen(1, "w"); - setvbuf(stdout, NULL, _IOLBF, 0); + setvbuf(stdout, nullptr, _IOLBF, 0); stderr = fdopen(2, "w"); - setvbuf(stderr, NULL, _IONBF, 0); + setvbuf(stderr, nullptr, _IONBF, 0); } void __nc_f_fini(void) { diff --git a/libc/getopt.c b/libc/getopt.c index 8109a5a5..7761a3f7 100644 --- a/libc/getopt.c +++ b/libc/getopt.c @@ -22,7 +22,7 @@ static void consume_argument(char *const argv[], const char *flag) { if (flag[1]) { // option is rest of this argument optind += 1; - nextchar = NULL; // don't keep scanning this argv, move to next + nextchar = nullptr; // don't keep scanning this argv, move to next optarg = &flag[1]; return; } @@ -74,15 +74,15 @@ static const char *next_flag_character(int argc, char *const argv[]) { if (nextchar) { // We were scanning a flag argument, but we hit the end. Move along. optind += 1; - nextchar = NULL; + nextchar = nullptr; } if (optind > argc || argv[optind] == 0) { // We're at the end of the tracks - return NULL; + return nullptr; } if (argv[optind][0] != '-') { // This argiment is not an option, so we're done parsing - return NULL; + return nullptr; } if (argv[optind][1] && argv[optind][1] != '-') { // This is an argument string, -[^-].* @@ -92,7 +92,7 @@ static const char *next_flag_character(int argc, char *const argv[]) { // This should only be hit by '-' and '--.*', let's check that assumption assert( strcmp(argv[optind], "-") == 0 || strncmp(argv[optind], "--", 2) == 0); - return NULL; + return nullptr; } int getopt(int argc, char *const argv[], const char *optstring) { diff --git a/libc/malloc.c b/libc/malloc.c index 9fc066f5..d0fc1648 100644 --- a/libc/malloc.c +++ b/libc/malloc.c @@ -99,7 +99,7 @@ static void *heap_get_memory(size_t length) { #ifdef __kernel__ void *mem = (void *)vmm_reserve(length); #else - void *mem = mmap(NULL, length, PROT_READ | PROT_WRITE, + void *mem = mmap(nullptr, length, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (mem == MAP_FAILED) { // woops, and we can't printf yet either @@ -186,7 +186,7 @@ static struct free_mregion *mregion_split( size_t new_len = len - real_split - sizeof(mregion); if (new_len < __HEAP_MINIMUM_BLOCK || new_len > 0xFFFFFFFF) - return NULL; + return nullptr; void *alloc_ptr = mregion_ptr((struct mregion *)fmr); struct free_mregion *new_region = PTR_ADD(alloc_ptr, real_split); @@ -206,7 +206,7 @@ static struct free_mregion *mregion_merge( struct __mheap *heap, struct free_mregion *b, struct free_mregion *a) { assert(mregion_validate(&a->m, false) && mregion_validate(&b->m, false)); if (free_mregion_next(b) != a) - return NULL; + return nullptr; b->m.length += sizeof(mregion); b->m.length += a->m.length; @@ -220,12 +220,12 @@ static struct free_mregion *mregion_merge( // Heap allocation functions void *heap_malloc(struct __mheap *heap, size_t len) { - struct free_mregion *bestfit = NULL; + struct free_mregion *bestfit = nullptr; bool found_any = false; assert(heap->is_init); if (len == 0) - return NULL; + return nullptr; spin_lock(&heap->lock); @@ -294,7 +294,7 @@ void heap_free(struct __mheap *heap, void *allocation) { memset(allocation, FREE_POISON, mr->length); struct free_mregion *fmr = (struct free_mregion *)mr; - struct free_mregion *before = NULL; + struct free_mregion *before = nullptr; // Keep the free list sorted topologically list_for_each_safe (&heap->free_list) { @@ -328,7 +328,7 @@ void *heap_realloc(struct __mheap *heap, void *allocation, size_t desired) { struct mregion *mr = mregion_of(allocation); if (!mregion_validate(mr, true)) { error_printf("invalid realloc of %p\n", allocation); - return NULL; + return nullptr; } size_t to_copy = MIN(mr->length, desired); @@ -349,7 +349,7 @@ void *heap_zrealloc(struct __mheap *heap, void *allocation, size_t desired) { struct mregion *mr = mregion_of(allocation); if (!mregion_validate(mr, true)) { error_printf("invalid realloc of %p\n", allocation); - return NULL; + return nullptr; } void *new = heap_malloc(heap, desired); @@ -387,7 +387,7 @@ void *zrealloc(void *allocation, size_t desired) { } #ifdef __kernel__ -void proc_heap(struct file *file, void *_) { +void proc_heap(struct file *file, void *) { proc_sprintf(file, "struct __mheap {\n"); proc_sprintf( file, "\t.allocations = %li,\n", __global_heap_ptr->allocations); diff --git a/libc/nightingale.c b/libc/nightingale.c index 44cbf8c6..eb874125 100644 --- a/libc/nightingale.c +++ b/libc/nightingale.c @@ -10,7 +10,7 @@ ssize_t readdir(int fd, struct dirent *buf, size_t count); static pid_t redirect_child = 0; static void wait_on_redirect_child(void) { fflush(stdout); - waitpid(redirect_child, NULL, 0); + waitpid(redirect_child, nullptr, 0); } /* * Spawns a new process based on the argument list provided. @@ -34,7 +34,7 @@ void redirect_output_to(char *const argv[]) { dup2(pipefds[1], STDOUT_FILENO); close(pipefds[0]); close(pipefds[1]); - setvbuf(stdout, NULL, _IOFBF, 0); + setvbuf(stdout, nullptr, _IOFBF, 0); redirect_child = child; atexit(wait_on_redirect_child); } diff --git a/libc/printf.c b/libc/printf.c index 1ff5df2f..badcf3fb 100644 --- a/libc/printf.c +++ b/libc/printf.c @@ -7,7 +7,7 @@ #ifdef __kernel__ #include #include -#define stdout NULL +#define stdout nullptr #endif #include @@ -67,7 +67,7 @@ static size_t format_int(char *buf, uint64_t raw_value, Format_Info fmt) { const char *charset = __lower_hex_charset; if (raw_value == 0 && fmt.format == POINTER) { - const char *null_print = "(NULL)"; + const char *null_print = "(nullptr)"; int len = strlen(null_print); memcpy(buf, null_print, len); return len; @@ -541,7 +541,7 @@ int vprintf(const char *format, va_list args) { char buf[PRINTF_BUFSZ] = { 0 }; int cnt = vsprintf(buf, format, args); - __raw_print(NULL, buf, cnt); + __raw_print(nullptr, buf, cnt); return cnt; #else return vfprintf(stdout, format, args); diff --git a/libc/rbtree.c b/libc/rbtree.c index 1b071c90..b71812df 100644 --- a/libc/rbtree.c +++ b/libc/rbtree.c @@ -10,7 +10,7 @@ static void rbtree_left_rotate(struct rbtree *tree, struct rbnode *node); static void rbtree_right_rotate(struct rbtree *tree, struct rbnode *node); void rbtree_insert(struct rbtree *tree, struct rbnode *node) { - struct rbnode *parent = NULL; + struct rbnode *parent = nullptr; struct rbnode *current = tree->root; while (current) { parent = current; @@ -28,8 +28,8 @@ void rbtree_insert(struct rbtree *tree, struct rbnode *node) { } else { parent->right = node; } - node->left = NULL; - node->right = NULL; + node->left = nullptr; + node->right = nullptr; node->color = RB_RED; rbtree_insert_fixup(tree, node); } @@ -121,7 +121,7 @@ struct rbnode *rbtree_search(struct rbtree *tree, void *key) { current = current->right; } } - return NULL; + return nullptr; } struct rbnode *rbtree_min(struct rbtree *tree) { @@ -174,7 +174,7 @@ struct rbnode *rbtree_predecessor(struct rbnode *node) { struct rbnode *rbtree_search_ge(struct rbtree *tree, void *key) { struct rbnode *current = tree->root; - struct rbnode *ge = NULL; + struct rbnode *ge = nullptr; while (current) { int cmp = tree->compare(key, current->key); if (cmp == 0) { @@ -191,7 +191,7 @@ struct rbnode *rbtree_search_ge(struct rbtree *tree, void *key) { struct rbnode *rbtree_search_le(struct rbtree *tree, void *key) { struct rbnode *current = tree->root; - struct rbnode *le = NULL; + struct rbnode *le = nullptr; while (current) { int cmp = tree->compare(key, current->key); if (cmp == 0) { diff --git a/libc/signal.c b/libc/signal.c index 596be15f..24b18900 100644 --- a/libc/signal.c +++ b/libc/signal.c @@ -48,7 +48,7 @@ static bool __is_function(sighandler_t handler) { sighandler_t signal(int signum, sighandler_t handler) { sighandler_t original = 0, kernel_original = 0; - if (handler == NULL || __is_function(handler)) { + if (handler == nullptr || __is_function(handler)) { original = __signal_handlers[signum]; __signal_handlers[signum] = handler; kernel_original = __ng_sigaction(signum, __handle_signal, 0); diff --git a/libc/stdlib.c b/libc/stdlib.c index 3b966a10..93dab234 100644 --- a/libc/stdlib.c +++ b/libc/stdlib.c @@ -129,8 +129,8 @@ unsigned long long strtoull(const char *nptr, char **endptr, int base) { return strtoul(nptr, endptr, base); } -int atoi(const char *nptr) { return strtol(nptr, NULL, 10); } +int atoi(const char *nptr) { return strtol(nptr, nullptr, 10); } -long atol(const char *nptr) { return strtol(nptr, NULL, 10); } +long atol(const char *nptr) { return strtol(nptr, nullptr, 10); } -long long atoll(const char *nptr) { return strtoll(nptr, NULL, 10); } +long long atoll(const char *nptr) { return strtoll(nptr, nullptr, 10); } diff --git a/libc/string.c b/libc/string.c index 67d90c1a..a736220e 100644 --- a/libc/string.c +++ b/libc/string.c @@ -64,7 +64,7 @@ char *strrchr(const char *s, int c) { if (s[i] == c) return (char *)s + i; } - return NULL; + return nullptr; } char *strpbrk(const char *s, const char *accept) { @@ -77,14 +77,14 @@ char *strpbrk(const char *s, const char *accept) { } char *strstr(const char *s, const char *subs) { - const char *found = NULL; + const char *found = nullptr; while (1) { const char *ss = subs; if (*ss == 0) { return (char *)found; } else if (*s == 0) { - return NULL; + return nullptr; } else if (*s == *ss) { s += 1; ss += 1; @@ -102,7 +102,7 @@ void *memchr(const void *pm, int v, size_t count) { if (mem[i] == v) return (void *)(mem + i); } - return NULL; + return nullptr; } int memcmp(const void *pa, const void *pb, size_t count) { @@ -187,7 +187,7 @@ size_t strspn(const char *str, const char *accept) { size_t slen = strlen(str); size_t i; for (i = 0; i < slen; i++) { - if (strchr(accept, str[i]) == NULL) + if (strchr(accept, str[i]) == nullptr) break; } return i; @@ -231,5 +231,5 @@ void *memccpy(void *restrict dest, const void *restrict src, int c, size_t n) { return &d[i + 1]; d[i] = s[i]; } - return NULL; + return nullptr; } diff --git a/libc/timeconv.c b/libc/timeconv.c index 4048bdf7..f94d70ce 100644 --- a/libc/timeconv.c +++ b/libc/timeconv.c @@ -77,7 +77,7 @@ time_t mktime(struct tm *tm) { #ifndef __kernel__ time_t time(time_t *time) { time_t val; - btime(&val, NULL); + btime(&val, nullptr); if (time) *time = val; return val; diff --git a/libc/unistd.c b/libc/unistd.c index 81cd4ae3..6e95319a 100644 --- a/libc/unistd.c +++ b/libc/unistd.c @@ -11,7 +11,7 @@ int isatty(int fd) { return ttyctl(fd, TTY_ISTTY, 0); } int execvp(const char *path, char *const argv[]) { - return execve(path, argv, NULL); + return execve(path, argv, nullptr); } off_t lseek(int fd, off_t offset, int whence) { @@ -36,7 +36,7 @@ ssize_t __ng_getcwd(char *, size_t); char *getcwd(char *buffer, size_t len) { int err = __ng_getcwd(buffer, len); if (err < 0) - return NULL; + return nullptr; return buffer; } diff --git a/libc/vector.c b/libc/vector.c index 08f2cb2c..3b14aafd 100644 --- a/libc/vector.c +++ b/libc/vector.c @@ -28,7 +28,7 @@ size_t vec_expand(struct vector *vec, size_t new_len) { char *new_data; new_data = realloc(vec->data, new_len * vec->delta); - assert(new_data != NULL); // "Reallocating to up buffer failed"); + assert(new_data != nullptr); // "Reallocating to up buffer failed"); vec->total_size = new_len; vec->data = new_data; @@ -97,5 +97,5 @@ void vec_free(struct vector *vec) { vec->total_size = 0; vec->delta = 0; free(vec->data); - vec->data = NULL; + vec->data = nullptr; } diff --git a/linker/elf-ng.c b/linker/elf-ng.c index eafee1c5..20b43190 100644 --- a/linker/elf-ng.c +++ b/linker/elf-ng.c @@ -42,32 +42,32 @@ int elf_verify(const Elf_Ehdr *elf) { */ const Elf_Phdr *elf_find_phdr(const elf_md *e, int p_type) { if (!e->program_headers) - return NULL; + return nullptr; for (int i = 0; i < e->imm_header->e_phnum; i++) { const Elf_Phdr *hdr = e->program_headers + i; if (hdr->p_type == p_type) return hdr; } - return NULL; + return nullptr; } const Elf_Dyn *elf_find_dyn(const elf_md *e, int d_tag) { const Elf_Dyn *d = e->dynamic_table; if (!d) - return NULL; + return nullptr; for (; d->d_tag != DT_NULL; d++) { if (d->d_tag == d_tag) return d; } - return NULL; + return nullptr; } const Elf_Shdr *elf_find_section(const elf_md *e, const char *name) { const Elf_Shdr *shdr_table = e->section_headers; if (!shdr_table) - return NULL; + return nullptr; for (int i = 0; i < e->section_header_count; i++) { const Elf_Shdr *shdr = shdr_table + i; @@ -75,13 +75,13 @@ const Elf_Shdr *elf_find_section(const elf_md *e, const char *name) { if (strcmp(sh_name, name) == 0) return shdr; } - return NULL; + return nullptr; } Elf_Shdr *elf_find_section_mut(const elf_md *e, const char *name) { Elf_Shdr *shdr_table = e->mut_section_headers; if (!shdr_table) - return NULL; + return nullptr; for (int i = 0; i < e->section_header_count; i++) { Elf_Shdr *shdr = shdr_table + i; @@ -89,7 +89,7 @@ Elf_Shdr *elf_find_section_mut(const elf_md *e, const char *name) { if (strcmp(sh_name, name) == 0) return shdr; } - return NULL; + return nullptr; } const char *elf_symbol_name(const elf_md *e, const Elf_Sym *sym) { @@ -112,7 +112,7 @@ const Elf_Sym *elf_find_symbol(const elf_md *e, const char *name) { if (strcmp(name, symbol_name) == 0) return symbol; } - return NULL; + return nullptr; } const Elf_Sym *elf_symbol_by_address(const elf_md *e, uintptr_t address) { @@ -125,7 +125,7 @@ const Elf_Sym *elf_symbol_by_address(const elf_md *e, uintptr_t address) { } uintptr_t addr_match = 0; - const Elf_Sym *best_match = NULL; + const Elf_Sym *best_match = nullptr; for (size_t i = 0; i < nsymbols; i++) { const Elf_Sym *sym = symtab + i; @@ -152,12 +152,12 @@ const Elf_Sym *elf_find_dynsym(const elf_md *e, const char *name) { if (strcmp(name, sym_name) == 0) return sym; } - return NULL; + return nullptr; } elf_md *elf_parse(const void *buffer, size_t buffer_len) { if (!elf_verify(buffer)) - return NULL; + return nullptr; elf_md *e = calloc(1, sizeof(*e)); const Elf_Ehdr *elf = buffer; diff --git a/linker/modld.c b/linker/modld.c index fddd3354..8acc0752 100644 --- a/linker/modld.c +++ b/linker/modld.c @@ -66,11 +66,11 @@ elf_md *elf_relo_load(elf_md *relo) { assert(relo_needed_virtual_size > 0); if (relo->imm_header->e_type != ET_REL) - return NULL; + return nullptr; if (!relo->symbol_table) - return NULL; + return nullptr; if (!relo->string_table) - return NULL; + return nullptr; const Elf_Shdr *o_bss = elf_find_section(relo, ".bss"); @@ -206,14 +206,14 @@ void limine_load_kernel_elf(void *ptr, size_t len) { free(tmp); } -elf_md *elf_mod_load(struct inode *elf_inode) { - if (elf_inode->type != FT_NORMAL) - return NULL; - elf_md *mod = elf_parse(elf_inode->data, elf_inode->len); +elf_md *elf_mod_load(struct vnode *elf_vnode) { + if (elf_vnode->type != FT_NORMAL) + return nullptr; + elf_md *mod = elf_parse(elf_vnode->data, elf_vnode->len); mod = elf_relo_load(mod); if (!mod) - return NULL; + return nullptr; for (int i = 0; i < mod->symbol_count; i++) { const Elf_Sym *sym = mod->mut_symbol_table + i; diff --git a/script/generate_syscalls.rb b/script/generate_syscalls.rb index 37c2eed3..ce42bdc7 100755 --- a/script/generate_syscalls.rb +++ b/script/generate_syscalls.rb @@ -126,7 +126,7 @@ def debuginfo def kernel_header if needs_frame? - "sysret #{function}(interrupt_frame *frame, #{args.join(", ")});" + "sysret #{function}(#{["interrupt_frame *frame", *args].join(", ")});" else "sysret #{function}(#{args.join(", ")});" end @@ -289,7 +289,7 @@ def header_guard(filename, &block) end write("#{output_dir}/autogenerated_syscalls_kernel.c") do |f| - f.puts "sysret (*syscall_table[SYSCALL_TABLE_SIZE])() = {" + f.puts "void *syscall_table[SYSCALL_TABLE_SIZE] = {" syscalls.map(&:map).each { |s| f.puts s } f.puts "};" f.puts "const char *syscall_debuginfos[SYSCALL_TABLE_SIZE] = {" diff --git a/user/bf2.c b/user/bf2.c index 39cd0377..811efed8 100644 --- a/user/bf2.c +++ b/user/bf2.c @@ -150,7 +150,7 @@ int main(int argc, const char *argv[]) { FILE *fp; if (argc == 1) { fp = stdin; - } else if (argc != 2 || (fp = fopen(argv[1], "r")) == NULL) { + } else if (argc != 2 || (fp = fopen(argv[1], "r")) == nullptr) { fprintf(stderr, "Usage: %s filename\n", argv[0]); return FAILURE; } diff --git a/user/cat.c b/user/cat.c index 44ac9497..beafdb33 100644 --- a/user/cat.c +++ b/user/cat.c @@ -4,8 +4,8 @@ #include void copy(FILE *out, FILE *in) { - setvbuf(out, NULL, _IONBF, 0); - setvbuf(in, NULL, _IONBF, 0); + setvbuf(out, nullptr, _IONBF, 0); + setvbuf(in, nullptr, _IONBF, 0); #define BUFSZ 4096 int count; diff --git a/user/cforks.c b/user/cforks.c index 9f016f3c..a512fd41 100644 --- a/user/cforks.c +++ b/user/cforks.c @@ -26,7 +26,7 @@ int thread_func(void *_arg) { int main() { for (int i = 0; i < 10; i++) { char *new_stack = malloc(STACK_SIZE); - clone(thread_func, new_stack + STACK_SIZE, 0, NULL); + clone(thread_func, new_stack + STACK_SIZE, 0, nullptr); } while (true) diff --git a/user/clone.c b/user/clone.c index 5804396c..4ad3b627 100644 --- a/user/clone.c +++ b/user/clone.c @@ -39,7 +39,7 @@ int thread_func(void *_arg) { int main() { for (int i = 0; i < 10; i++) { char *new_stack = malloc(STACK_SIZE); - clone(thread_func, new_stack + STACK_SIZE, 0, NULL); + clone(thread_func, new_stack + STACK_SIZE, 0, nullptr); } while (atomic_load(&threads_done) < 10) diff --git a/user/column.c b/user/column.c index 96b88caf..aa0d152c 100644 --- a/user/column.c +++ b/user/column.c @@ -32,7 +32,7 @@ int main(int argc, char **argv) { while (!feof(stdin)) { struct str *str = zmalloc(sizeof(struct str)); char *err = fgets(str->string, MAX_LENGTH, stdin); - if (err == NULL && !feof(stdin)) { + if (err == nullptr && !feof(stdin)) { perror("fgets"); exit(1); } diff --git a/user/cpuid.c b/user/cpuid.c index 013ef50c..e46050ce 100644 --- a/user/cpuid.c +++ b/user/cpuid.c @@ -7,9 +7,9 @@ int main(int argc, char **argv) { int sub = 0; if (argc >= 2) - request = strtol(argv[1], NULL, 10); + request = strtol(argv[1], nullptr, 10); if (argc >= 3) - request = strtol(argv[2], NULL, 10); + request = strtol(argv[2], nullptr, 10); unsigned id[4]; cpuid(request, sub, id); diff --git a/user/crash.c b/user/crash.c index 535c7b4d..0ee779db 100644 --- a/user/crash.c +++ b/user/crash.c @@ -6,7 +6,7 @@ #include #include -volatile int *x = NULL; +volatile int *x = nullptr; void usage() { printf("usage: crash [option]\n"); diff --git a/user/create.c b/user/create.c index caa5fa25..8eccbe8e 100644 --- a/user/create.c +++ b/user/create.c @@ -13,7 +13,7 @@ int main(int argc, char **argv) { pid_t pid = create(argv[1]); procstate(pid, PS_COPYFDS); procstate(pid, PS_SETRUN); - waitpid(pid, NULL, 0); + waitpid(pid, nullptr, 0); return 0; } diff --git a/user/head.c b/user/head.c index 1a9e39fc..eda12050 100644 --- a/user/head.c +++ b/user/head.c @@ -29,8 +29,8 @@ void copy_n_lines(FILE *out, FILE *in, int lines) { } void copy_n_characters(FILE *out, FILE *in, int chars) { - setvbuf(out, NULL, _IOFBF, 0); - setvbuf(in, NULL, _IOFBF, 0); + setvbuf(out, nullptr, _IOFBF, 0); + setvbuf(in, nullptr, _IOFBF, 0); int n = 0; int c; while (n++ < chars && (c = getc(in)) != EOF) { diff --git a/user/hexdump.c b/user/hexdump.c index cc1903cd..908b2e4d 100644 --- a/user/hexdump.c +++ b/user/hexdump.c @@ -45,7 +45,7 @@ int main() { size_t carryover = 0; uintptr_t total = 0; - setvbuf(stdin, NULL, _IOFBF, 0); + setvbuf(stdin, nullptr, _IOFBF, 0); while ((n = fread(buffer + carryover, 1, BUFFER_SIZE - carryover, stdin)) > 0) { n += carryover; diff --git a/user/init.c b/user/init.c index 802fc924..3c7d91e4 100644 --- a/user/init.c +++ b/user/init.c @@ -39,7 +39,7 @@ int exec(const char *stdio_file, char **argv) { } printf("Welcome to Nightingale\n"); - execve(argv[0], argv, NULL); + execve(argv[0], argv, nullptr); printf("init failed to run sh\n"); perror("execve"); @@ -67,7 +67,7 @@ int wait_for(pid_t pid) { _Noreturn void run_sh_forever(const char *stdio_file) { while (true) { - int child = exec(stdio_file, (char *[]) { "/bin/sh", NULL }); + int child = exec(stdio_file, (char *[]) { "/bin/sh", nullptr }); wait_for(child); } } @@ -102,6 +102,6 @@ int main() { if (fork()) run_sh_forever("/dev/serial2"); - run_sh_forever(NULL); + run_sh_forever(nullptr); assert(0); } diff --git a/user/ls.c b/user/ls.c index b7a8edf8..62fe30ff 100644 --- a/user/ls.c +++ b/user/ls.c @@ -114,7 +114,7 @@ int main(int argc, char **argv) { qsort(dirent_ptrs, n_dirents, sizeof(struct dirent *), compare_dirent_ptrs); if (!long_) { - redirect_output_to((char *[]) { "/bin/column", NULL }); + redirect_output_to((char *[]) { "/bin/column", nullptr }); } char buffer[256] = { 0 }; diff --git a/user/mmap.c b/user/mmap.c index 4990682b..6150ca78 100644 --- a/user/mmap.c +++ b/user/mmap.c @@ -10,7 +10,7 @@ int main() { perror("open"); return 1; } - void *addr = mmap(NULL, 4096, PROT_READ, MAP_PRIVATE, fd, 0); + void *addr = mmap(nullptr, 4096, PROT_READ, MAP_PRIVATE, fd, 0); if (addr == MAP_FAILED) { perror("mmap"); return 1; diff --git a/user/rot13.c b/user/rot13.c index 1269f5d0..0e573a30 100644 --- a/user/rot13.c +++ b/user/rot13.c @@ -19,7 +19,7 @@ int main(int argc, char **argv) { while ((c = getopt(argc, argv, "n:")) != -1) { switch (c) { case 'n': - n = strtol(optarg, NULL, 10); + n = strtol(optarg, nullptr, 10); break; case '?': fprintf(stderr, "usage: rot13 [-n rot]\n"); diff --git a/user/sh/eval.c b/user/sh/eval.c index 10d9fc56..cd944209 100644 --- a/user/sh/eval.c +++ b/user/sh/eval.c @@ -106,7 +106,7 @@ int eval_pipeline(struct pipeline *pipeline) { else snprintf(command, 127, "/bin/%s", c->argv[0]); - int err = execve(cmd, c->argv, NULL); + int err = execve(cmd, c->argv, nullptr); if (err < 0 && errno == ENOENT) fprintf(stderr, "%s: command not found\n", c->argv[0]); else if (err < 0) diff --git a/user/sh/parse.c b/user/sh/parse.c index b7d59f19..23300486 100644 --- a/user/sh/parse.c +++ b/user/sh/parse.c @@ -192,8 +192,8 @@ static struct node *parse_pipeline(list *tokens) { struct node *parse_paren(list *tokens) { struct token *t = container_of(struct token, node, list_head(tokens)); - struct token *open_paren = NULL; - struct node *n = NULL, *new_root = NULL; + struct token *open_paren = nullptr; + struct node *n = nullptr, *new_root = nullptr; while (!list_empty(tokens)) { t = container_of(struct token, node, list_head(tokens)); @@ -201,19 +201,19 @@ struct node *parse_paren(list *tokens) { case TOKEN_OPAREN: if (n) { unexpected_token(t); - return NULL; + return nullptr; } open_paren = t; eat(tokens); n = parse_paren(tokens); if (list_empty(tokens)) { unclosed_paren(open_paren); - return NULL; + return nullptr; } t = container_of(struct token, node, list_head(tokens)); if (t->type != TOKEN_CPAREN) { unclosed_paren(open_paren); - return NULL; + return nullptr; } eat(tokens); break; @@ -233,7 +233,7 @@ struct node *parse_paren(list *tokens) { if (!n) { unexpected_token(t); // TODO either handle error or do cleanup - return NULL; + return nullptr; } eat(tokens); new_root = calloc(1, sizeof(struct node)); @@ -247,7 +247,7 @@ struct node *parse_paren(list *tokens) { if (!n) { unexpected_token(t); // TODO either handle error or do cleanup - return NULL; + return nullptr; } eat(tokens); new_root = calloc(1, sizeof(struct node)); @@ -270,7 +270,7 @@ struct node *parse_paren(list *tokens) { default: unexpected_token(t); // TODO either handle error or do cleanup - return NULL; + return nullptr; } } out: diff --git a/user/sh/parse.h b/user/sh/parse.h index e58a8c0b..161a1aac 100644 --- a/user/sh/parse.h +++ b/user/sh/parse.h @@ -62,4 +62,3 @@ struct command { struct node *parse(list *tokens); void node_print(struct node *); void node_fprint(FILE *, struct node *); - diff --git a/user/sh/readline.c b/user/sh/readline.c index 356788eb..f8d614ef 100644 --- a/user/sh/readline.c +++ b/user/sh/readline.c @@ -162,7 +162,7 @@ void store_history_line(char *line_to_store, long len) { node->history_line = strdup(line_to_store); node->previous = history_top; - node->next = NULL; + node->next = nullptr; history_top->next = node; history_top = node; } @@ -324,7 +324,7 @@ long read_line_simple(FILE *file, char *buf, size_t limit) { return -1; char *v = fgets(buf, limit, file); - if (v == NULL) + if (v == nullptr) return -1; int ix = strlen(buf); diff --git a/user/sh/readline.h b/user/sh/readline.h index 7387b0f5..c772da14 100644 --- a/user/sh/readline.h +++ b/user/sh/readline.h @@ -18,4 +18,3 @@ struct line_state load_history_line( char *buf, struct line_state state, struct history_item *current); long read_line_interactive(char *buf, size_t max_len); long read_line_simple(FILE *file, char *buf, size_t limit); - diff --git a/user/sh/sh.c b/user/sh/sh.c index 17ce9e8a..7a2c263b 100644 --- a/user/sh/sh.c +++ b/user/sh/sh.c @@ -30,7 +30,7 @@ int handle_one_line() { ttyctl(STDIN_FILENO, TTY_SETBUFFER, 0); ttyctl(STDIN_FILENO, TTY_SETECHO, 0); ttyctl(STDIN_FILENO, TTY_SETPGRP, getpid()); - setvbuf(stdout, NULL, _IONBF, 0); + setvbuf(stdout, nullptr, _IONBF, 0); if (read_line_interactive(buffer, 256) == -1) return 2; } else { @@ -38,7 +38,7 @@ int handle_one_line() { ttyctl(STDIN_FILENO, TTY_SETBUFFER, 1); ttyctl(STDIN_FILENO, TTY_SETECHO, 1); ttyctl(STDIN_FILENO, TTY_SETPGRP, getpid()); - setvbuf(stdout, NULL, _IOLBF, 0); + setvbuf(stdout, nullptr, _IOLBF, 0); } if (read_line_simple(input_file, buffer, 256) == -1) return 2; diff --git a/user/sh/token.c b/user/sh/token.c index b401205d..6a526f57 100644 --- a/user/sh/token.c +++ b/user/sh/token.c @@ -101,7 +101,7 @@ bool tokenize(const char *string, list *out) { struct token *t; while (*cursor) { - t = NULL; + t = nullptr; if (isspace(*cursor)) skip_whitespace(&cursor); diff --git a/user/sh/token.h b/user/sh/token.h index 7cca3643..731a9351 100644 --- a/user/sh/token.h +++ b/user/sh/token.h @@ -39,4 +39,3 @@ void token_fprint(FILE *, struct token *t); bool tokenize(const char *string, list *out); char *token_strdup(struct token *t); char *token_strcpy(char *dest, struct token *t); - diff --git a/user/step.c b/user/step.c index a5f283de..5bd2cae0 100644 --- a/user/step.c +++ b/user/step.c @@ -20,10 +20,10 @@ int exec(char **args) { return child; // strace(1); - trace(TR_TRACEME, 0, NULL, NULL); + trace(TR_TRACEME, 0, nullptr, nullptr); raise(SIGSTOP); - return execve(args[0], args, NULL); + return execve(args[0], args, nullptr); } noreturn void fail(const char *str) { @@ -53,7 +53,7 @@ int main(int argc, char **argv) { off_t child_buf_len = child_exec_stat.st_size; void *child_buf - = mmap(NULL, child_buf_len, PROT_READ, MAP_PRIVATE, child_exec, 0); + = mmap(nullptr, child_buf_len, PROT_READ, MAP_PRIVATE, child_exec, 0); elf_md *child_elf = elf_parse(child_buf, child_buf_len); interrupt_frame r; @@ -61,7 +61,7 @@ int main(int argc, char **argv) { int status; wait(&status); - trace(TR_SINGLESTEP, child, NULL, NULL); + trace(TR_SINGLESTEP, child, nullptr, nullptr); while (true) { wait(&status); @@ -74,7 +74,7 @@ int main(int argc, char **argv) { int syscall = status & 0xFFFF; intptr_t signal = 0; - trace(TR_GETREGS, child, NULL, &r); + trace(TR_GETREGS, child, nullptr, &r); if (event == TRACE_SYSCALL_ENTRY) { printf("syscall_enter: %s\n", syscall_names[syscall]); @@ -96,6 +96,6 @@ int main(int argc, char **argv) { printf("step: %#10zx (%s)\n", r.ip, sym_name); } - trace(TR_SINGLESTEP, child, NULL, (void *)signal); + trace(TR_SINGLESTEP, child, nullptr, (void *)signal); } } diff --git a/user/strace.c b/user/strace.c index 11b9a297..1d6a69f3 100644 --- a/user/strace.c +++ b/user/strace.c @@ -44,6 +44,6 @@ int main(int argc, char **argv) { syscall_trace(pid, state); if (pid == 0) - execve(argv[optind], argv + optind, NULL); + execve(argv[optind], argv + optind, nullptr); return 0; } diff --git a/user/test.c b/user/test.c index 60858b2c..c6090ffc 100644 --- a/user/test.c +++ b/user/test.c @@ -138,7 +138,7 @@ int main() { raise(SIGUSR1); TEST(signal_test_value == 1); - clone(thread_test, malloc(4096) + 4096, 0, NULL); + clone(thread_test, malloc(4096) + 4096, 0, nullptr); for (; thread_test_value == 0;) { } TEST(thread_test_value == 1); diff --git a/user/thread_local.c b/user/thread_local.c index 3a5deaa3..602f2b1b 100644 --- a/user/thread_local.c +++ b/user/thread_local.c @@ -26,7 +26,7 @@ int thread(void *arg) { int main() { alloc_tcb(); - clone(thread, stack + 8192, 0, NULL); + clone(thread, stack + 8192, 0, nullptr); use_tls(); sleepms(30); diff --git a/user/threads.c b/user/threads.c index 69dbf39d..f9922213 100644 --- a/user/threads.c +++ b/user/threads.c @@ -45,7 +45,7 @@ int main(int argc, char **argv) { go_slow = false; break; case 'n': - nthreads = strtol(optarg, NULL, 10); + nthreads = strtol(optarg, nullptr, 10); break; case 'w': wait_each = true; diff --git a/user/time.c b/user/time.c index 1e1619dc..c6453dff 100644 --- a/user/time.c +++ b/user/time.c @@ -16,7 +16,7 @@ int main(int argc, char **argv) { int child = fork(); int exit_status; if (child == 0) { - int e = execve(argv[1], argv + 1, NULL); + int e = execve(argv[1], argv + 1, nullptr); perror("errno()"); exit(1); } else { diff --git a/user/trace.c b/user/trace.c index f06d1e25..4cd6045e 100644 --- a/user/trace.c +++ b/user/trace.c @@ -16,10 +16,10 @@ int exec(char **args) { return child; // strace(1); - trace(TR_TRACEME, 0, NULL, NULL); + trace(TR_TRACEME, 0, nullptr, nullptr); raise(SIGSTOP); - return execve(args[0], args, NULL); + return execve(args[0], args, nullptr); } noreturn void fail(const char *str) { @@ -40,7 +40,7 @@ int main(int argc, char **argv) { int status; wait(&status); - trace(TR_SYSCALL, child, NULL, NULL); + trace(TR_SYSCALL, child, nullptr, nullptr); while (true) { wait(&status); @@ -52,7 +52,7 @@ int main(int argc, char **argv) { int event = status & ~0xFFFF; int syscall = status & 0xFFFF; - trace(TR_GETREGS, child, NULL, &r); + trace(TR_GETREGS, child, nullptr, &r); if (event == TRACE_SYSCALL_ENTRY) { fprintf(stderr, "syscall_enter: %s\n", syscall_names[syscall]); @@ -65,9 +65,9 @@ int main(int argc, char **argv) { if (event == TRACE_SIGNAL) { fprintf(stderr, "signal: %i\n", syscall); - trace(TR_SYSCALL, child, NULL, (void *)(intptr_t)syscall); + trace(TR_SYSCALL, child, nullptr, (void *)(intptr_t)syscall); } else { - trace(TR_SYSCALL, child, NULL, NULL); + trace(TR_SYSCALL, child, nullptr, nullptr); } } } diff --git a/user/traceback.c b/user/traceback.c index 2577671b..5dab80d4 100644 --- a/user/traceback.c +++ b/user/traceback.c @@ -16,7 +16,7 @@ int main(int argc, char **argv) { fprintf(stderr, "An argument is required - traceback [pid]\n"); return 1; } - pid_t tid = strtol(argv[1], NULL, 10); + pid_t tid = strtol(argv[1], nullptr, 10); snprintf(path, 256, "/proc/%i/stack", tid); int fd = open(path, O_RDONLY); diff --git a/user/uthread.c b/user/uthread.c index a4d76c57..eec9a330 100644 --- a/user/uthread.c +++ b/user/uthread.c @@ -32,7 +32,7 @@ void uthread_join(struct uthread *th); #define MAX_UTHREADS 1024 struct uthread *active_threads[MAX_UTHREADS] = { 0 }; -struct uthread *running_uthread = NULL; +struct uthread *running_uthread = nullptr; struct uthread thread_one = { 0 }; void uthread_init() { @@ -45,7 +45,7 @@ void uthread_init() { int uthread_create(struct uthread *thread, void (*func)(int), int arg) { int use_slot = MAX_UTHREADS; for (int i = 0; i < MAX_UTHREADS; i++) { - if (active_threads[i] == NULL) { + if (active_threads[i] == nullptr) { use_slot = i; break; } @@ -92,7 +92,7 @@ void uthread_yield() { if (DEBUG) printf("yield %d\n", running_uthread->tid); - struct uthread *volatile return_to = NULL; + struct uthread *volatile return_to = nullptr; if (setjmp(running_uthread->execution_state)) { if (DEBUG)