Networking - Reworked route table management
[tpg/acess2.git] / Kernel / include / acess.h
index a956d14..1c645c2 100644 (file)
@@ -4,29 +4,45 @@
  */
 #ifndef _ACESS_H
 #define _ACESS_H
+/**
+ * \file acess.h
+ * \brief Acess2 Kernel API Core
+ */
 
+//! NULL Pointer
 #define NULL   ((void*)0)
+//! Pack a structure
 #define PACKED __attribute__((packed))
+//! Mark a function as not returning
 #define NORETURN       __attribute__((noreturn))
+//! Mark a parameter as unused
 #define UNUSED(x)      UNUSED_##x __attribute__((unused))
+//! Get the offset of a member in a structure
 #define offsetof(st, m) ((Uint)((char *)&((st *)(0))->m - (char *)0 ))
 
+/**
+ * \name Boolean constants
+ * \{
+ */
 #define TRUE   1
 #define FALSE  0
+/**
+ * \}
+ */
 
 #include <arch.h>
 #include <stdarg.h>
 #include "errno.h"
 
 // --- Types ---
-typedef  int   tPID;
-typedef  int   tTID;
-typedef Uint   tUID;
-typedef Uint   tGID;
-typedef Sint64 tTimestamp;
-typedef Sint64 tTime;
-typedef struct sShortSpinlock  tShortSpinlock;
-typedef int    bool;
+typedef Uint32 tPID;   //!< Process ID type
+typedef Uint32 tTID;   //!< Thread ID Type
+typedef Uint32 tUID;   //!< User ID Type
+typedef Uint32 tGID;   //!< Group ID Type
+typedef Sint64 tTimestamp;     //!< Timestamp (miliseconds since 00:00 1 Jan 1970)
+typedef Sint64 tTime;  //!< Same again
+typedef struct sShortSpinlock  tShortSpinlock; //!< Opaque (kinda) spinlock
+typedef int    bool;   //!< Boolean type
 
 // --- Helper Macros ---
 /**
@@ -47,30 +63,8 @@ extern const char gsGitHash[];
  * \}
  */
 
-/**
- * \name Per-Thread Configuration Settings
- * \{
- */
-enum eConfigTypes {
-       CFGT_NULL,
-       CFGT_INT,
-       CFGT_HEAPSTR,
-       CFGT_PTR
-};
-enum eConfigs {
-       CFG_VFS_CWD,
-       CFG_VFS_MAXFILES,
-       CFG_VFS_CHROOT,
-       CFG_ERRNO,
-       NUM_CFG_ENTRIES
-};
-#define CFGINT(id)     (*Threads_GetCfgPtr(id))
-#define CFGPTR(id)     (*(void**)Threads_GetCfgPtr(id))
-
-#define errno  (CFGINT(CFG_ERRNO))
-/**
- * \}
- */
+//! \brief Error number
+#define errno  (*Threads_GetErrno())
 
 // === CONSTANTS ===
 // --- Memory Flags --
@@ -88,22 +82,42 @@ enum eConfigs {
  * \}
  */
 // --- Interface Flags & Macros
+/**
+ * \name Flags for Proc_Clone
+ * \{
+ */
+//! Clone the entire process
 #define CLONE_VM       0x10
+//! Don't copy user pages
+#define CLONE_NOUSER   0x20
+/**
+ * \}
+ */
 
 // === Types ===
+/**
+ * \brief Thread root function
+ * 
+ * Function pointer prototype of a thread entrypoint. When it
+ * returns, Threads_Exit is called
+ */
 typedef void (*tThreadFunction)(void*);
 
 // === Kernel Export Macros ===
 /**
- * \name Kernel Function 
+ * \name Kernel exports
  * \{
  */
+//! Kernel symbol definition
 typedef struct sKernelSymbol {
-       const char      *Name;
-       tVAddr  Value;
+       const char      *Name;  //!< Symbolic name
+       tVAddr  Value;  //!< Value of the symbol
 } tKernelSymbol;
+//! Export a pointer symbol (function/array)
 #define        EXPORT(_name)   tKernelSymbol _kexp_##_name __attribute__((section ("KEXPORT"),unused))={#_name, (tVAddr)_name}
+//! Export a variable
 #define        EXPORTV(_name)  tKernelSymbol _kexp_##_name __attribute__((section ("KEXPORT"),unused))={#_name, (tVAddr)&_name}
+//! Export a symbol under another name
 #define        EXPORTAS(_sym,_name)    tKernelSymbol _kexp_##_name __attribute__((section ("KEXPORT"),unused))={#_name, (tVAddr)_sym}
 /**
  * \}
@@ -111,10 +125,21 @@ typedef struct sKernelSymbol {
 
 // === FUNCTIONS ===
 // --- IRQs ---
+/**
+ * \name IRQ hander registration
+ * \{
+ */
 extern int     IRQ_AddHandler(int Num, void (*Callback)(int, void*), void *Ptr);
 extern void    IRQ_RemHandler(int Handle);
+/**
+ * \}
+ */
 
 // --- Logging ---
+/**
+ * \name Logging to kernel ring buffer
+ * \{
+ */
 extern void    Log_KernelPanic(const char *Ident, const char *Message, ...);
 extern void    Log_Panic(const char *Ident, const char *Message, ...);
 extern void    Log_Error(const char *Ident, const char *Message, ...);
@@ -122,6 +147,9 @@ extern void Log_Warning(const char *Ident, const char *Message, ...);
 extern void    Log_Notice(const char *Ident, const char *Message, ...);
 extern void    Log_Log(const char *Ident, const char *Message, ...);
 extern void    Log_Debug(const char *Ident, const char *Message, ...);
+/**
+ * \}
+ */
 
 // --- Debug ---
 /**
@@ -164,7 +192,7 @@ extern void Debug_HexDump(const char *Header, const void *Data, Uint Length);
 
 // --- IO ---
 #if NO_IO_BUS
-#define inb(a) (Log_Panic("Arch", "ARMv7 does not support in*/out* (%s:%i)", __FILE__, __LINE__),0)
+#define inb(a) (Log_Panic("Arch", STR(ARCHDIR)" does not support in*/out* (%s:%i)", __FILE__, __LINE__),0)
 #define inw(a) inb(a)
 #define ind(a) inb(a)
 #define inq(a) inb(a)
@@ -389,22 +417,40 @@ extern int        strpos(const char *Str, char Ch);
 extern int     strpos8(const char *str, Uint32 search);
 extern void    itoa(char *buf, Uint64 num, int base, int minLength, char pad);
 extern int     atoi(const char *string);
+extern int     ParseInt(const char *string, int *Val);
 extern int     ReadUTF8(const Uint8 *str, Uint32 *Val);
 extern int     WriteUTF8(Uint8 *str, Uint32 Val);
 extern int     ModUtil_SetIdent(char *Dest, const char *Value);
 extern int     ModUtil_LookupString(const char **Array, const char *Needle);
 
 extern Uint8   ByteSum(const void *Ptr, int Size);
+extern int     Hex(char *Dest, size_t Size, const Uint8 *SourceData);
 extern int     UnHex(Uint8 *Dest, size_t DestSize, const char *SourceString);
 /**
  * \}
  */
 
+/**
+ * \brief Get a random number
+ * \return Random number
+ * \note Current implementation is a linear congruency
+ */
 extern int     rand(void);
+/**
+ * \brief Call a function with a variable number of arguments
+ * \param Function     Function address
+ * \param NArgs        Number of entries in \a Args
+ * \param Args Array of arguments
+ * \return Integer from called Function
+ */
 extern int     CallWithArgArray(void *Function, int NArgs, Uint *Args);
 
 // --- Heap ---
 #include <heap.h>
+/**
+ * \brief Magic heap allocation function
+ */
+extern void    *alloca(size_t Size);
 
 // --- Modules ---
 /**
@@ -460,6 +506,8 @@ extern void Time_Delay(int Delay);
  */
 extern int     Proc_SpawnWorker(void (*Fcn)(void*), void *Data);
 extern int     Proc_Spawn(const char *Path);
+extern int     Proc_SysSpawn(const char *Binary, const char **ArgV, const char **EnvP, int nFD, int *FDs);
+extern int     Proc_Execve(const char *File, const char **ArgV, const char **EnvP, int DataSize);
 extern void    Threads_Exit(int TID, int Status);
 extern void    Threads_Yield(void);
 extern void    Threads_Sleep(void);
@@ -469,16 +517,21 @@ extern tTID       Threads_GetTID(void);
 extern tUID    Threads_GetUID(void);
 extern tGID    Threads_GetGID(void);
 extern int     SpawnTask(tThreadFunction Function, void *Arg);
-extern Uint    *Threads_GetCfgPtr(int Id);
+extern int     *Threads_GetErrno(void);
 extern int     Threads_SetName(const char *NewName);
 /**
  * \}
  */
 
 // --- Simple Math ---
+//! Divide and round up
 extern int     DivUp(int num, int dem);
+//! Divide and Modulo 64-bit unsigned integer
 extern Uint64  DivMod64U(Uint64 Num, Uint64 Den, Uint64 *Rem);
 
+static inline int MIN(int a, int b) { return a < b ? a : b; }
+static inline int MAX(int a, int b) { return a > b ? a : b; }
+
 #include <binary_ext.h>
 #include <vfs_ext.h>
 #include <mutex.h>

UCC git Repository :: git.ucc.asn.au