From a14ba848b34b53beb158895cdd7ffdfd72875da3 Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Wed, 7 Aug 2024 06:35:06 +0200 Subject: [PATCH] Header guards (#pragma once) for all kernel headers --- kernel/buf.h | 6 ++++++ kernel/defs.h | 5 +++++ kernel/elf.h | 4 ++++ kernel/fcntl.h | 2 ++ kernel/file.h | 6 ++++++ kernel/fs.h | 4 ++++ kernel/memlayout.h | 2 ++ kernel/param.h | 2 ++ kernel/proc.h | 7 +++++++ kernel/riscv.h | 4 ++++ kernel/sleeplock.h | 5 +++++ kernel/spinlock.h | 4 ++++ kernel/stat.h | 4 ++++ kernel/syscall.h | 2 ++ kernel/types.h | 2 ++ kernel/virtio.h | 5 ++++- user/user.h | 5 +++++ 17 files changed, 68 insertions(+), 1 deletion(-) diff --git a/kernel/buf.h b/kernel/buf.h index 319f8e1..ad2274e 100644 --- a/kernel/buf.h +++ b/kernel/buf.h @@ -1,3 +1,9 @@ +#pragma once + +#include "types.h" +#include "sleeplock.h" +#include "fs.h" + struct buf { int valid; // has data been read from disk? int disk; // does disk "own" buf? diff --git a/kernel/defs.h b/kernel/defs.h index b7e0db8..a89c445 100644 --- a/kernel/defs.h +++ b/kernel/defs.h @@ -1,3 +1,8 @@ +#pragma once + +#include "riscv.h" +#include "types.h" + struct buf; struct context; struct file; diff --git a/kernel/elf.h b/kernel/elf.h index a779868..acaa17f 100644 --- a/kernel/elf.h +++ b/kernel/elf.h @@ -1,3 +1,7 @@ +#pragma once + +#include "types.h" + // Format of an ELF executable file #define ELF_MAGIC 0x464C457FU // "\x7FELF" in little endian diff --git a/kernel/fcntl.h b/kernel/fcntl.h index 1b57ebb..e19b010 100644 --- a/kernel/fcntl.h +++ b/kernel/fcntl.h @@ -1,3 +1,5 @@ +#pragma once + #define O_RDONLY 0x000 #define O_WRONLY 0x001 #define O_RDWR 0x002 diff --git a/kernel/file.h b/kernel/file.h index ddb6857..d52bbe0 100644 --- a/kernel/file.h +++ b/kernel/file.h @@ -1,3 +1,9 @@ +#pragma once + +#include "types.h" +#include "sleeplock.h" +#include "fs.h" + struct file { enum { FD_NONE, FD_PIPE, FD_INODE, FD_DEVICE } type; int ref; // reference count diff --git a/kernel/fs.h b/kernel/fs.h index 2a6d7bd..daea0d1 100644 --- a/kernel/fs.h +++ b/kernel/fs.h @@ -1,3 +1,7 @@ +#pragma once + +#include "types.h" + // On-disk file system format. // Both the kernel and user programs use this header file. diff --git a/kernel/memlayout.h b/kernel/memlayout.h index 59ff719..57c3839 100644 --- a/kernel/memlayout.h +++ b/kernel/memlayout.h @@ -1,3 +1,5 @@ +#pragma once + // Physical memory layout // qemu -machine virt is set up like this, diff --git a/kernel/param.h b/kernel/param.h index 25643ad..e2dc45a 100644 --- a/kernel/param.h +++ b/kernel/param.h @@ -1,3 +1,5 @@ +#pragma once + #define NPROC 64 // maximum number of processes #define NCPU 8 // maximum number of CPUs #define NOFILE 16 // open files per process diff --git a/kernel/proc.h b/kernel/proc.h index 6aed367..8ae5cf0 100644 --- a/kernel/proc.h +++ b/kernel/proc.h @@ -1,3 +1,10 @@ +#pragma once + +#include "types.h" +#include "param.h" +#include "riscv.h" +#include "spinlock.h" + // Saved registers for kernel context switches. struct context { u64 ra; diff --git a/kernel/riscv.h b/kernel/riscv.h index 21c98cd..0cde08d 100644 --- a/kernel/riscv.h +++ b/kernel/riscv.h @@ -1,3 +1,7 @@ +#pragma once + +#include "types.h" + #ifndef __ASSEMBLER__ // which hart (core) is this? diff --git a/kernel/sleeplock.h b/kernel/sleeplock.h index 7958192..b1d0267 100644 --- a/kernel/sleeplock.h +++ b/kernel/sleeplock.h @@ -1,3 +1,8 @@ +#pragma once + +#include "types.h" +#include "spinlock.h" + // Long-term locks for processes struct sleeplock { u32 locked; // Is the lock held? diff --git a/kernel/spinlock.h b/kernel/spinlock.h index ad6f660..dc21dd7 100644 --- a/kernel/spinlock.h +++ b/kernel/spinlock.h @@ -1,3 +1,7 @@ +#pragma once + +#include "types.h" + // Mutual exclusion lock. struct spinlock { u32 locked; // Is the lock held? diff --git a/kernel/stat.h b/kernel/stat.h index 9bf0083..3b959f9 100644 --- a/kernel/stat.h +++ b/kernel/stat.h @@ -1,3 +1,7 @@ +#pragma once + +#include "types.h" + #define T_DIR 1 // Directory #define T_FILE 2 // File #define T_DEVICE 3 // Device diff --git a/kernel/syscall.h b/kernel/syscall.h index a378a8a..7d671f0 100644 --- a/kernel/syscall.h +++ b/kernel/syscall.h @@ -1,3 +1,5 @@ +#pragma once + // System call numbers #define SYS_fork 1 #define SYS_exit 2 diff --git a/kernel/types.h b/kernel/types.h index 6626c5e..03410e3 100644 --- a/kernel/types.h +++ b/kernel/types.h @@ -1,3 +1,5 @@ +#pragma once + typedef unsigned char u8; typedef unsigned short u16; typedef unsigned int u32; diff --git a/kernel/virtio.h b/kernel/virtio.h index 8916e8a..c888436 100644 --- a/kernel/virtio.h +++ b/kernel/virtio.h @@ -1,4 +1,7 @@ -// +#pragma once + +#include "types.h" + // virtio device definitions. // for both the mmio interface, and virtio descriptors. // only tested with qemu. diff --git a/user/user.h b/user/user.h index a27f3f1..8b3a1b6 100644 --- a/user/user.h +++ b/user/user.h @@ -1,3 +1,7 @@ +#pragma once + +#include "../kernel/types.h" + struct stat; // system calls @@ -22,6 +26,7 @@ int getpid(void); char *sbrk(int); int sleep(int); int uptime(void); +int trace(int); // ulib.c int stat(const char *, struct stat *);