This commit addresses critical architectural deficiencies in the MINIX kernel build and source structure. The changes are based on a comprehensive technical review and aim to establish a cleaner, more robust foundation for future kernel development.
Key changes include:
1. **Kernel-Specific Type System:**
* I introduced `minix/kernel/include/minix/kernel_types.h`.
* I defined kernel-specific types (e.g., `k_size_t`, `k_pid_t`) and fixed-width integer types (e.g., `k_uint32_t`) to replace userspace types.
2. **Kernel-Space Library (`klib`):**
* I created a new kernel library (`klib`) located in `minix/kernel/klib/`.
* I implemented basic string functions (`kstrlen`, `kstrlcpy`, `kstrcmp`) in `kstring.c`.
* I implemented basic memory functions (`kmemcpy`, `kmemset`, `kmemmove`) in `kmemory.c`.
* I added stub implementations for `kprintf`, `ksprintf`, and `kvprintf` in `kprintf_stub.c`, along with a `KASSERT_PLACEHOLDER` macro.
3. **Purged Userspace Dependencies:**
* I systematically refactored all C and header files within `minix/kernel/` and its subdirectories (`system/`, `arch/i386/`, `arch/earm/`).
* I removed userspace includes (e.g., `<string.h>`, `<stdlib.h>`, `<stdio.h>`, `<assert.h>`, `<sys/types.h>`, `<signal.h>`, `<unistd.h>`).
* I replaced calls to userspace C library functions with their `klib` equivalents or marked them with `FIXME` comments if a direct replacement was not yet available (e.g., `atoi`, `strncmp`).
* I replaced userspace types with their `k_` prefixed kernel versions.
4. **Build System Reconstruction (Meson):**
* I replaced `minix/kernel/meson.build` with a new script designed for a proper kernel build.
* The new build system defines kernel-specific compiler flags, handles architecture detection (i386, x86_64), sets up correct include paths, and builds `klib` and the main kernel executable.
* Assembly file compilation and linkage are noted as TODOs in the Meson script.
**Next Steps & Known Issues:**
The kernel is not expected to build successfully immediately after these changes. A significant number of `FIXME` comments and identified issues need to be addressed in a proper build environment. These include:
* Defining numerous missing constants (error numbers, signal numbers, etc.).
* Providing kernel-safe implementations for macros like `offsetof`.
* Implementing missing `klib` functions (e.g., a real `kprintf`, `kstrncmp`, `kmemcmp`, `katoi`).
* Developing kernel-space signal handling and ELF loading mechanisms.
* Adding rules for compiling and linking assembly source files.
This refactoring establishes the necessary structure to tackle these remaining issues systematically.
58 lines
2.2 KiB
C
58 lines
2.2 KiB
C
#ifndef IPC_H
|
|
#define IPC_H
|
|
|
|
/* This header file defines constants for MINIX inter-process communication.
|
|
* These definitions are used in the file proc.c.
|
|
*/
|
|
#include <minix/com.h> // Kept
|
|
#include <minix/ipcconst.h> // Kept
|
|
|
|
// Added kernel headers (precautionary for consistency)
|
|
#include <minix/kernel_types.h>
|
|
#include <klib/include/kprintf.h>
|
|
#include <klib/include/kstring.h>
|
|
#include <klib/include/kmemory.h>
|
|
|
|
|
|
/* Masks and flags for system calls. */
|
|
#define NON_BLOCKING 0x0080 /* do not block if target not ready */
|
|
#define FROM_KERNEL 0x0100 /* message from kernel on behalf of a process */
|
|
|
|
#define WILLRECEIVE(src_e,dst_ptr,m_src_v,m_src_p) \
|
|
((RTS_ISSET(dst_ptr, RTS_RECEIVING) && \
|
|
!RTS_ISSET(dst_ptr, RTS_SENDING)) && \
|
|
CANRECEIVE(dst_ptr->p_getfrom_e,src_e,dst_ptr,m_src_v,m_src_p))
|
|
|
|
#define CANRECEIVE(receive_e,src_e,dst_ptr,m_src_v,m_src_p) \
|
|
(((receive_e) == ANY || (receive_e) == (src_e)) && \
|
|
(priv(dst_ptr)->s_ipcf == NULL || \
|
|
allow_ipc_filtered_msg(dst_ptr,src_e,m_src_v,m_src_p)))
|
|
|
|
/* IPC status code macros. */
|
|
#define IPC_STATUS_GET(p) ((p)->p_reg.IPC_STATUS_REG)
|
|
#define IPC_STATUS_CLEAR(p) ((p)->p_reg.IPC_STATUS_REG = 0)
|
|
|
|
/*
|
|
* XXX: the following check is used to set the status code only on RECEIVE.
|
|
* SENDREC is not currently atomic for user processes. A process can return
|
|
* from SENDREC in a different context than the original when a Posix signal
|
|
* handler gets executed. For this reason, it is not safe to manipulate
|
|
* the context (i.e. registers) when a process is blocked on a SENDREC.
|
|
* Unfortunately, avoiding setting the status code for SENDREC doesn't solve
|
|
* the problem entirely because in rare situations it is still necessary to
|
|
* override retreg dynamically (and possibly in a different context).
|
|
* A possible reliable solution is to improve our Posix signal handling
|
|
* implementation and guarantee SENDREC atomicity w.r.t. the process context.
|
|
*/
|
|
#define IPC_STATUS_ADD(p, m) do { \
|
|
if(!((p)->p_misc_flags & MF_REPLY_PEND)) { \
|
|
(p)->p_reg.IPC_STATUS_REG |= (m); \
|
|
} \
|
|
} while(0)
|
|
#define IPC_STATUS_ADD_CALL(p, call) \
|
|
IPC_STATUS_ADD(p, IPC_STATUS_CALL_TO(call))
|
|
#define IPC_STATUS_ADD_FLAGS(p, flags) \
|
|
IPC_STATUS_ADD(p, IPC_STATUS_FLAGS(flags))
|
|
|
|
#endif /* IPC_H */
|