Fix up documentation
This commit is contained in:
parent
a71bebe92e
commit
631603cab3
@ -34,7 +34,7 @@ DEFINE_SLAB(BufCacheEntry, &cacheEntrySlab);
|
|||||||
/**
|
/**
|
||||||
* BufCache_Init --
|
* BufCache_Init --
|
||||||
*
|
*
|
||||||
* Initialize the system buffer cache.
|
* Initialize the system buffer cache.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
BufCache_Init()
|
BufCache_Init()
|
||||||
@ -83,14 +83,15 @@ BufCache_Init()
|
|||||||
/**
|
/**
|
||||||
* BufCacheLookup --
|
* BufCacheLookup --
|
||||||
*
|
*
|
||||||
* Looks up a buffer cache entry that can be used by BufCache_Alloc or
|
* Looks up a buffer cache entry that can be used by BufCache_Alloc or
|
||||||
* BufCache_Read to allocate the underlying buffer.
|
* BufCache_Read to allocate the underlying buffer.
|
||||||
*
|
*
|
||||||
* @param [in] disk Disk object
|
* @param [in] disk Disk object
|
||||||
* @param [in] diskOffset Block offset within the disk
|
* @param [in] diskOffset Block offset within the disk
|
||||||
* @param [out] entry If successful, this contains the buffer cache entry.
|
* @param [out] entry If successful, this contains the buffer cache entry.
|
||||||
* @retval 0 if successful
|
*
|
||||||
* @return ENOENT if not present.
|
* @retval 0 if successful
|
||||||
|
* @return ENOENT if not present.
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
BufCacheLookup(Disk *disk, uint64_t diskOffset, BufCacheEntry **entry)
|
BufCacheLookup(Disk *disk, uint64_t diskOffset, BufCacheEntry **entry)
|
||||||
@ -118,14 +119,15 @@ BufCacheLookup(Disk *disk, uint64_t diskOffset, BufCacheEntry **entry)
|
|||||||
/**
|
/**
|
||||||
* BufCacheAlloc --
|
* BufCacheAlloc --
|
||||||
*
|
*
|
||||||
* Allocates a buffer cache entry that can be used by BufCache_Alloc or
|
* Allocates a buffer cache entry that can be used by BufCache_Alloc or
|
||||||
* BufCache_Read to allocate the underlying buffer..
|
* BufCache_Read to allocate the underlying buffer..
|
||||||
*
|
*
|
||||||
* @param [in] disk Disk object
|
* @param [in] disk Disk object
|
||||||
* @param [in] diskOffset Block offset within the disk
|
* @param [in] diskOffset Block offset within the disk
|
||||||
* @param [out] entry If successful, this contains the buffer cache entry.
|
* @param [out] entry If successful, this contains the buffer cache entry.
|
||||||
* @retval 0 if successful.
|
*
|
||||||
* @return ENOMEM if there's no buffer cache entries free.
|
* @retval 0 if successful.
|
||||||
|
* @return ENOMEM if there's no buffer cache entries free.
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
BufCacheAlloc(Disk *disk, uint64_t diskOffset, BufCacheEntry **entry)
|
BufCacheAlloc(Disk *disk, uint64_t diskOffset, BufCacheEntry **entry)
|
||||||
@ -163,13 +165,14 @@ BufCacheAlloc(Disk *disk, uint64_t diskOffset, BufCacheEntry **entry)
|
|||||||
/**
|
/**
|
||||||
* BufCache_Alloc --
|
* BufCache_Alloc --
|
||||||
*
|
*
|
||||||
* Allocate a buffer cache entry to allow writing new data to disk.
|
* Allocate a buffer cache entry to allow writing new data to disk.
|
||||||
*
|
*
|
||||||
* @param [in] disk Disk object
|
* @param [in] disk Disk object
|
||||||
* @param [in] diskOffset Block offset within the disk
|
* @param [in] diskOffset Block offset within the disk
|
||||||
* @param [out] entry If successful, this contains the buffer cache entry.
|
* @param [out] entry If successful, this contains the buffer cache entry.
|
||||||
* @retval 0 if successful
|
*
|
||||||
* @return Otherwise returns an error code.
|
* @retval 0 if successful
|
||||||
|
* @return Otherwise returns an error code.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
BufCache_Alloc(Disk *disk, uint64_t diskOffset, BufCacheEntry **entry)
|
BufCache_Alloc(Disk *disk, uint64_t diskOffset, BufCacheEntry **entry)
|
||||||
@ -193,10 +196,10 @@ BufCache_Alloc(Disk *disk, uint64_t diskOffset, BufCacheEntry **entry)
|
|||||||
/**
|
/**
|
||||||
* BufCache_Release --
|
* BufCache_Release --
|
||||||
*
|
*
|
||||||
* Release a buffer cache entry. If no other references are held the
|
* Release a buffer cache entry. If no other references are held the
|
||||||
* buffer cache entry is placed on the LRU list.
|
* buffer cache entry is placed on the LRU list.
|
||||||
*
|
*
|
||||||
* @param [in] entry Buffer cache entry.
|
* @param [in] entry Buffer cache entry.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
BufCache_Release(BufCacheEntry *entry)
|
BufCache_Release(BufCacheEntry *entry)
|
||||||
@ -214,13 +217,13 @@ BufCache_Release(BufCacheEntry *entry)
|
|||||||
/**
|
/**
|
||||||
* BufCache_Read --
|
* BufCache_Read --
|
||||||
*
|
*
|
||||||
* Read block from disk into the buffer cache.
|
* Read block from disk into the buffer cache.
|
||||||
*
|
*
|
||||||
* @param [in] disk Disk object
|
* @param [in] disk Disk object
|
||||||
* @param [in] diskOffset Block offset within the disk
|
* @param [in] diskOffset Block offset within the disk
|
||||||
* @param [out] entry If successful, this contains the buffer cache entry.
|
* @param [out] entry If successful, this contains the buffer cache entry.
|
||||||
* @retval 0 if successful
|
* @retval 0 if successful
|
||||||
* @return Otherwise returns an error code.
|
* @return Otherwise returns an error code.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
BufCache_Read(Disk *disk, uint64_t diskOffset, BufCacheEntry **entry)
|
BufCache_Read(Disk *disk, uint64_t diskOffset, BufCacheEntry **entry)
|
||||||
@ -261,10 +264,10 @@ BufCache_Read(Disk *disk, uint64_t diskOffset, BufCacheEntry **entry)
|
|||||||
/**
|
/**
|
||||||
* BufCache_Write --
|
* BufCache_Write --
|
||||||
*
|
*
|
||||||
* Write a buffer cache entry to disk.
|
* Write a buffer cache entry to disk.
|
||||||
*
|
*
|
||||||
* @retval 0 if successful
|
* @retval 0 if successful
|
||||||
* @return Otherwise an error code is returned.
|
* @return Otherwise an error code is returned.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
BufCache_Write(BufCacheEntry *entry)
|
BufCache_Write(BufCacheEntry *entry)
|
||||||
|
@ -17,16 +17,18 @@ extern int copystr_unsafe(void *to_addr, void *from_addr, uintptr_t len);
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Copy_In --
|
* Copy_In --
|
||||||
* Safely copy memory from userspace. Prevents userspace pointers from
|
|
||||||
* reading kernel memory.
|
|
||||||
*
|
*
|
||||||
* @param [in] fromuser User address to copy from.
|
* Safely copy memory from userspace. Prevents userspace pointers from
|
||||||
* @param [in] tokernel Kernel address to copy to.
|
* reading kernel memory.
|
||||||
* @param [in] len Length of the data to copy.
|
|
||||||
* @retval EFAULT if the address is invalid or causes a fault.
|
|
||||||
*
|
*
|
||||||
* Side effects:
|
* Side effects:
|
||||||
* Kernel page fault may have occurred.
|
* Kernel page fault may have occurred.
|
||||||
|
*
|
||||||
|
* @param [in] fromuser User address to copy from.
|
||||||
|
* @param [in] tokernel Kernel address to copy to.
|
||||||
|
* @param [in] len Length of the data to copy.
|
||||||
|
*
|
||||||
|
* @retval EFAULT if the address is invalid or causes a fault.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
Copy_In(uintptr_t fromuser, void *tokernel, uintptr_t len)
|
Copy_In(uintptr_t fromuser, void *tokernel, uintptr_t len)
|
||||||
@ -51,16 +53,18 @@ Copy_In(uintptr_t fromuser, void *tokernel, uintptr_t len)
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Copy_Out --
|
* Copy_Out --
|
||||||
* Safely copy memory to userspace. Prevents userspace pointers from
|
|
||||||
* writing kernel memory.
|
|
||||||
*
|
*
|
||||||
* @param [in] fromkernel Kernel address to copy from.
|
* Safely copy memory to userspace. Prevents userspace pointers from
|
||||||
* @param [in] touser User address to copy to.
|
* writing kernel memory.
|
||||||
* @param [in] len Length of the data to copy.
|
|
||||||
* @retval EFAULT if the address is invalid or causes a fault.
|
|
||||||
*
|
*
|
||||||
* Side effects:
|
* Side effects:
|
||||||
* Kernel page fault may have occurred.
|
* Kernel page fault may have occurred.
|
||||||
|
*
|
||||||
|
* @param [in] fromkernel Kernel address to copy from.
|
||||||
|
* @param [in] touser User address to copy to.
|
||||||
|
* @param [in] len Length of the data to copy.
|
||||||
|
*
|
||||||
|
* @retval EFAULT if the address is invalid or causes a fault.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
Copy_Out(void *fromkernel, uintptr_t touser, uintptr_t len)
|
Copy_Out(void *fromkernel, uintptr_t touser, uintptr_t len)
|
||||||
@ -86,16 +90,17 @@ Copy_Out(void *fromkernel, uintptr_t touser, uintptr_t len)
|
|||||||
/**
|
/**
|
||||||
* Copy_StrIn --
|
* Copy_StrIn --
|
||||||
*
|
*
|
||||||
* Safely copy a string from userspace. Prevents userspace pointers from
|
* Safely copy a string from userspace. Prevents userspace pointers from
|
||||||
* reading kernel memory.
|
* reading kernel memory.
|
||||||
*
|
|
||||||
* @param [in] fromuser User address to copy from.
|
|
||||||
* @param [in] tokernel Kernel address to copy to.
|
|
||||||
* @param [in] len Maximum string length.
|
|
||||||
* @retval EFAULT if the address is invalid or causes a fault.
|
|
||||||
*
|
*
|
||||||
* Side effects:
|
* Side effects:
|
||||||
* Kernel page fault may have occurred.
|
* Kernel page fault may have occurred.
|
||||||
|
*
|
||||||
|
* @param [in] fromuser User address to copy from.
|
||||||
|
* @param [in] tokernel Kernel address to copy to.
|
||||||
|
* @param [in] len Maximum string length.
|
||||||
|
*
|
||||||
|
* @retval EFAULT if the address is invalid or causes a fault.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
Copy_StrIn(uintptr_t fromuser, void *tokernel, uintptr_t len)
|
Copy_StrIn(uintptr_t fromuser, void *tokernel, uintptr_t len)
|
||||||
@ -120,16 +125,18 @@ Copy_StrIn(uintptr_t fromuser, void *tokernel, uintptr_t len)
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Copy_StrOut --
|
* Copy_StrOut --
|
||||||
* Safely copy a string to userspace. Prevents userspace pointers from
|
|
||||||
* writing kernel memory.
|
|
||||||
*
|
*
|
||||||
* @param [in] fromkernel Kernel address to copy from.
|
* Safely copy a string to userspace. Prevents userspace pointers from
|
||||||
* @param [in] touser User address to copy to.
|
* writing kernel memory.
|
||||||
* @param [in] len Maximum string length.
|
|
||||||
* @retval EFAULT if the address is invalid or causes a fault.
|
|
||||||
*
|
*
|
||||||
* Side effects:
|
* Side effects:
|
||||||
* Kernel page fault may have occurred.
|
* Kernel page fault may have occurred.
|
||||||
|
*
|
||||||
|
* @param [in] fromkernel Kernel address to copy from.
|
||||||
|
* @param [in] touser User address to copy to.
|
||||||
|
* @param [in] len Maximum string length.
|
||||||
|
*
|
||||||
|
* @retval EFAULT if the address is invalid or causes a fault.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
Copy_StrOut(void *fromkernel, uintptr_t touser, uintptr_t len)
|
Copy_StrOut(void *fromkernel, uintptr_t touser, uintptr_t len)
|
||||||
|
@ -40,7 +40,7 @@ CV_Destroy(CV *cv)
|
|||||||
/**
|
/**
|
||||||
* CV_Wait --
|
* CV_Wait --
|
||||||
*
|
*
|
||||||
* Wait to be woken up on a condition.
|
* Wait to be woken up on a condition.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
CV_Wait(CV *cv, Mutex *mtx)
|
CV_Wait(CV *cv, Mutex *mtx)
|
||||||
@ -59,7 +59,7 @@ CV_Wait(CV *cv, Mutex *mtx)
|
|||||||
/**
|
/**
|
||||||
* CV_Signal --
|
* CV_Signal --
|
||||||
*
|
*
|
||||||
* Wake a single thread waiting on the condition.
|
* Wake a single thread waiting on the condition.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
CV_Signal(CV *cv)
|
CV_Signal(CV *cv)
|
||||||
@ -72,7 +72,7 @@ CV_Signal(CV *cv)
|
|||||||
/**
|
/**
|
||||||
* CV_WakeAll --
|
* CV_WakeAll --
|
||||||
*
|
*
|
||||||
* Wake all threads waiting on the condition.
|
* Wake all threads waiting on the condition.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
CV_WakeAll(CV *cv)
|
CV_WakeAll(CV *cv)
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2013-2023 Ali Mashtizadeh
|
||||||
|
* All rights reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2006-2023 Ali Mashtizadeh
|
||||||
|
* All rights reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
@ -21,10 +25,10 @@
|
|||||||
|
|
||||||
extern Handle *Console_OpenHandle();
|
extern Handle *Console_OpenHandle();
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* Loader_CheckHeader --
|
* Loader_CheckHeader --
|
||||||
*
|
*
|
||||||
* Check that the program has a valid ELF header.
|
* Check that the program has a valid ELF header.
|
||||||
*/
|
*/
|
||||||
bool
|
bool
|
||||||
Loader_CheckHeader(const Elf64_Ehdr *ehdr)
|
Loader_CheckHeader(const Elf64_Ehdr *ehdr)
|
||||||
@ -46,12 +50,12 @@ Loader_CheckHeader(const Elf64_Ehdr *ehdr)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* LoaderLoadSegment --
|
* LoaderLoadSegment --
|
||||||
*
|
*
|
||||||
* Loads a single segment into the target address space. This function
|
* Loads a single segment into the target address space. This function loads a
|
||||||
* loads a single page at a time because it has to lookup the address
|
* single page at a time because it has to lookup the address mappings through
|
||||||
* mappings through the page tables.
|
* the page tables.
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
LoaderLoadSegment(AS *as, VNode *vn, uintptr_t vaddr,
|
LoaderLoadSegment(AS *as, VNode *vn, uintptr_t vaddr,
|
||||||
@ -84,11 +88,11 @@ LoaderLoadSegment(AS *as, VNode *vn, uintptr_t vaddr,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* LoaderZeroSegment --
|
* LoaderZeroSegment --
|
||||||
*
|
*
|
||||||
* Zeroes a segment of memory in the target address space. This is done
|
* Zeroes a segment of memory in the target address space. This is done one
|
||||||
* one page a time while translating the virtual address to physical.
|
* page a time while translating the virtual address to physical.
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
LoaderZeroSegment(AS *as, uintptr_t vaddr, uintptr_t len)
|
LoaderZeroSegment(AS *as, uintptr_t vaddr, uintptr_t len)
|
||||||
@ -118,10 +122,10 @@ LoaderZeroSegment(AS *as, uintptr_t vaddr, uintptr_t len)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* Loader_Load --
|
* Loader_Load --
|
||||||
*
|
*
|
||||||
* Load the ELF binary into the process belonging to the thread.
|
* Load the ELF binary into the process belonging to the thread.
|
||||||
*/
|
*/
|
||||||
bool
|
bool
|
||||||
Loader_Load(Thread *thr, VNode *vn, void *buf, uint64_t len)
|
Loader_Load(Thread *thr, VNode *vn, void *buf, uint64_t len)
|
||||||
@ -184,12 +188,12 @@ Loader_Load(Thread *thr, VNode *vn, void *buf, uint64_t len)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* Loader_LoadInit --
|
* Loader_LoadInit --
|
||||||
*
|
*
|
||||||
* The init process is created from the execution kernel thread that
|
* The init process is created from the execution kernel thread that
|
||||||
* initializes the system. This function initializes the thread and
|
* initializes the system. This function initializes the thread and process
|
||||||
* process state then loads the init binary.
|
* state then loads the init binary.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
Loader_LoadInit()
|
Loader_LoadInit()
|
||||||
|
@ -46,7 +46,7 @@ Mutex_Destroy(Mutex *mtx)
|
|||||||
/**
|
/**
|
||||||
* Mutex_Lock --
|
* Mutex_Lock --
|
||||||
*
|
*
|
||||||
* Acquires the mutex.
|
* Acquires the mutex.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
Mutex_Lock(Mutex *mtx)
|
Mutex_Lock(Mutex *mtx)
|
||||||
@ -74,8 +74,8 @@ Mutex_Lock(Mutex *mtx)
|
|||||||
/**
|
/**
|
||||||
* Mutex_TryLock --
|
* Mutex_TryLock --
|
||||||
*
|
*
|
||||||
* Attempts to acquire the user mutex. Returns EBUSY if the lock is
|
* Attempts to acquire the user mutex. Returns EBUSY if the lock is already
|
||||||
* already taken, otherwise 0 on success.
|
* taken, otherwise 0 on success.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
Mutex_TryLock(Mutex *mtx)
|
Mutex_TryLock(Mutex *mtx)
|
||||||
@ -95,7 +95,7 @@ Mutex_TryLock(Mutex *mtx)
|
|||||||
/**
|
/**
|
||||||
* Mutex_Unlock --
|
* Mutex_Unlock --
|
||||||
*
|
*
|
||||||
* Releases the user mutex.
|
* Releases the user mutex.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
Mutex_Unlock(Mutex *mtx)
|
Mutex_Unlock(Mutex *mtx)
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2013-2023 Ali Mashtizadeh
|
||||||
|
* All rights reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
@ -63,9 +63,9 @@ PAlloc_Init()
|
|||||||
/**
|
/**
|
||||||
* PAlloc_LateInit --
|
* PAlloc_LateInit --
|
||||||
*
|
*
|
||||||
* The late init call is made after the page tables are initialized using
|
* The late init call is made after the page tables are initialized using a
|
||||||
* a small boot memory region (2nd 16MBs). This is where initialize the
|
* small boot memory region (2nd 16MBs). This is where initialize the XMem
|
||||||
* XMem region that represents the PageInfo array, and map memory into it.
|
* region that represents the PageInfo array, and map memory into it.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
PAlloc_LateInit()
|
PAlloc_LateInit()
|
||||||
@ -86,7 +86,7 @@ PAlloc_LateInit()
|
|||||||
/**
|
/**
|
||||||
* PAlloc_AddRegion --
|
* PAlloc_AddRegion --
|
||||||
*
|
*
|
||||||
* Add a physical memory region to the page allocator.
|
* Add a physical memory region to the page allocator.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
PAlloc_AddRegion(uintptr_t start, uintptr_t len)
|
PAlloc_AddRegion(uintptr_t start, uintptr_t len)
|
||||||
@ -166,7 +166,7 @@ PAlloc_AddRegion(uintptr_t start, uintptr_t len)
|
|||||||
/**
|
/**
|
||||||
* PAllocGetInfo --
|
* PAllocGetInfo --
|
||||||
*
|
*
|
||||||
* Lookup the PageInfo structure for a given physical address.
|
* Lookup the PageInfo structure for a given physical address.
|
||||||
*/
|
*/
|
||||||
static inline PageInfo *
|
static inline PageInfo *
|
||||||
PAllocGetInfo(void *pg)
|
PAllocGetInfo(void *pg)
|
||||||
@ -178,11 +178,11 @@ PAllocGetInfo(void *pg)
|
|||||||
/**
|
/**
|
||||||
* PAlloc_AllocPage --
|
* PAlloc_AllocPage --
|
||||||
*
|
*
|
||||||
* Allocate a physical page and return the page's address in the Kernel's
|
* Allocate a physical page and return the page's address in the Kernel's ident
|
||||||
* ident mapped memory region.
|
* mapped memory region.
|
||||||
*
|
*
|
||||||
* @retval NULL if no memory is available.
|
* @retval NULL if no memory is available.
|
||||||
* @return Newly allocated physical page.
|
* @return Newly allocated physical page.
|
||||||
*/
|
*/
|
||||||
void *
|
void *
|
||||||
PAlloc_AllocPage()
|
PAlloc_AllocPage()
|
||||||
@ -215,7 +215,7 @@ PAlloc_AllocPage()
|
|||||||
/**
|
/**
|
||||||
* PAllocFreePage --
|
* PAllocFreePage --
|
||||||
*
|
*
|
||||||
* Free a page.
|
* Free a page.
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
PAllocFreePage(void *region)
|
PAllocFreePage(void *region)
|
||||||
@ -242,7 +242,7 @@ PAllocFreePage(void *region)
|
|||||||
/**
|
/**
|
||||||
* PAlloc_Retain --
|
* PAlloc_Retain --
|
||||||
*
|
*
|
||||||
* Increment the reference count for a physical page.
|
* Increment the reference count for a physical page.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
PAlloc_Retain(void *pg)
|
PAlloc_Retain(void *pg)
|
||||||
@ -258,8 +258,8 @@ PAlloc_Retain(void *pg)
|
|||||||
/**
|
/**
|
||||||
* PAlloc_Release --
|
* PAlloc_Release --
|
||||||
*
|
*
|
||||||
* Deccrement the reference count for a physical page. If the reference
|
* Deccrement the reference count for a physical page. If the reference count
|
||||||
* count is zero the page will be freed.
|
* is zero the page will be freed.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
PAlloc_Release(void *pg)
|
PAlloc_Release(void *pg)
|
||||||
|
@ -39,11 +39,12 @@ Slab processSlab;
|
|||||||
/**
|
/**
|
||||||
* Process_Create --
|
* Process_Create --
|
||||||
*
|
*
|
||||||
* Create a process.
|
* Create a process.
|
||||||
*
|
*
|
||||||
* @param [in] parent Parent process.
|
* @param [in] parent Parent process.
|
||||||
* @param [in] title Process title.
|
* @param [in] title Process title.
|
||||||
* @return The newly created process.
|
*
|
||||||
|
* @return The newly created process.
|
||||||
*/
|
*/
|
||||||
Process *
|
Process *
|
||||||
Process_Create(Process *parent, const char *title)
|
Process_Create(Process *parent, const char *title)
|
||||||
@ -103,10 +104,10 @@ Process_Create(Process *parent, const char *title)
|
|||||||
/**
|
/**
|
||||||
* Process_Destroy --
|
* Process_Destroy --
|
||||||
*
|
*
|
||||||
* Destroy a process. This should not be called direct, but rather by
|
* Destroy a process. This should not be called direct, but rather by
|
||||||
* Process_Release.
|
* Process_Release.
|
||||||
*
|
*
|
||||||
* @param [in] proc Process to destroy.
|
* @param [in] proc Process to destroy.
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
Process_Destroy(Process *proc)
|
Process_Destroy(Process *proc)
|
||||||
@ -133,11 +134,12 @@ Process_Destroy(Process *proc)
|
|||||||
/**
|
/**
|
||||||
* Process_Lookup --
|
* Process_Lookup --
|
||||||
*
|
*
|
||||||
* Lookup a process by PID and increment its reference count.
|
* Lookup a process by PID and increment its reference count.
|
||||||
* @param [in] pid Process ID to search for.
|
|
||||||
*
|
*
|
||||||
* @retval NULL No such process.
|
* @param [in] pid Process ID to search for.
|
||||||
* @return Process that corresponds to the pid.
|
*
|
||||||
|
* @retval NULL No such process.
|
||||||
|
* @return Process that corresponds to the pid.
|
||||||
*/
|
*/
|
||||||
Process *
|
Process *
|
||||||
Process_Lookup(uint64_t pid)
|
Process_Lookup(uint64_t pid)
|
||||||
@ -161,9 +163,9 @@ Process_Lookup(uint64_t pid)
|
|||||||
/**
|
/**
|
||||||
* Process_Retain --
|
* Process_Retain --
|
||||||
*
|
*
|
||||||
* Increment the reference count for a given process.
|
* Increment the reference count for a given process.
|
||||||
*
|
*
|
||||||
* @param proc Process to retain a reference to.
|
* @param proc Process to retain a reference to.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
Process_Retain(Process *proc)
|
Process_Retain(Process *proc)
|
||||||
@ -175,9 +177,9 @@ Process_Retain(Process *proc)
|
|||||||
/**
|
/**
|
||||||
* Process_Release --
|
* Process_Release --
|
||||||
*
|
*
|
||||||
* Decrement the reference count for a given process.
|
* Decrement the reference count for a given process.
|
||||||
*
|
*
|
||||||
* @param proc Process to release a reference of.
|
* @param proc Process to release a reference of.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
Process_Release(Process *proc)
|
Process_Release(Process *proc)
|
||||||
@ -191,14 +193,14 @@ Process_Release(Process *proc)
|
|||||||
/**
|
/**
|
||||||
* Process_Wait --
|
* Process_Wait --
|
||||||
*
|
*
|
||||||
* Wait for a process to exit and then cleanup it's references. If the
|
* Wait for a process to exit and then cleanup it's references. If the pid ==
|
||||||
* pid == 0, we wait for any process, otherwise we wait for a specific
|
* 0, we wait for any process, otherwise we wait for a specific process.
|
||||||
* process.
|
|
||||||
*
|
*
|
||||||
* @param [in] proc Parent process.
|
* @param [in] proc Parent process.
|
||||||
* @param [in] pid Optionally specify the pid of the process to wait on.
|
* @param [in] pid Optionally specify the pid of the process to wait on.
|
||||||
* @retval ENOENT Process ID doesn't exist.
|
*
|
||||||
* @return Exit status of the process that exited or crashed.
|
* @retval ENOENT Process ID doesn't exist.
|
||||||
|
* @return Exit status of the process that exited or crashed.
|
||||||
*/
|
*/
|
||||||
uint64_t
|
uint64_t
|
||||||
Process_Wait(Process *proc, uint64_t pid)
|
Process_Wait(Process *proc, uint64_t pid)
|
||||||
|
@ -47,10 +47,10 @@ Thread *curProc[MAX_CPUS];
|
|||||||
/**
|
/**
|
||||||
* Sched_Current() --
|
* Sched_Current() --
|
||||||
*
|
*
|
||||||
* Get the currently executing thread. This function retains a reference
|
* Get the currently executing thread. This function retains a reference count
|
||||||
* count and you must release the reference by calling Thread_Release.
|
* and you must release the reference by calling Thread_Release.
|
||||||
*
|
*
|
||||||
* @return Returns the current thread.
|
* @return Returns the current thread.
|
||||||
*/
|
*/
|
||||||
Thread *
|
Thread *
|
||||||
Sched_Current()
|
Sched_Current()
|
||||||
@ -68,10 +68,10 @@ Sched_Current()
|
|||||||
/**
|
/**
|
||||||
* Sched_SetRunnable --
|
* Sched_SetRunnable --
|
||||||
*
|
*
|
||||||
* Set the thread to the runnable state and move it from the wait queue if
|
* Set the thread to the runnable state and move it from the wait queue if
|
||||||
* necessary to the runnable queue.
|
* necessary to the runnable queue.
|
||||||
*
|
*
|
||||||
* @param [in] thr Thread to be set as runnable.
|
* @param [in] thr Thread to be set as runnable.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
Sched_SetRunnable(Thread *thr)
|
Sched_SetRunnable(Thread *thr)
|
||||||
@ -95,10 +95,10 @@ Sched_SetRunnable(Thread *thr)
|
|||||||
/**
|
/**
|
||||||
* Sched_SetWaiting --
|
* Sched_SetWaiting --
|
||||||
*
|
*
|
||||||
* Set the thread to the waiting state and move it to the wait queue. The
|
* Set the thread to the waiting state and move it to the wait queue. The
|
||||||
* thread should be currently running.
|
* thread should be currently running.
|
||||||
*
|
*
|
||||||
* @param [in] thr Thread to be set as waiting.
|
* @param [in] thr Thread to be set as waiting.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
Sched_SetWaiting(Thread *thr)
|
Sched_SetWaiting(Thread *thr)
|
||||||
@ -117,11 +117,10 @@ Sched_SetWaiting(Thread *thr)
|
|||||||
/**
|
/**
|
||||||
* Sched_SetZombie --
|
* Sched_SetZombie --
|
||||||
*
|
*
|
||||||
* Set the thread to the zombie state and move it to the parent
|
* Set the thread to the zombie state and move it to the parent processes's
|
||||||
* processes's zombie process queue. The thread should be currently
|
* zombie process queue. The thread should be currently running.
|
||||||
* running.
|
|
||||||
*
|
*
|
||||||
* @param [in] thr Thread to be set as zombie.
|
* @param [in] thr Thread to be set as zombie.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
Sched_SetZombie(Thread *thr)
|
Sched_SetZombie(Thread *thr)
|
||||||
@ -165,13 +164,12 @@ Sched_SetZombie(Thread *thr)
|
|||||||
/**
|
/**
|
||||||
* Sched_Switch --
|
* Sched_Switch --
|
||||||
*
|
*
|
||||||
* Switch between threads. During the creation of kernel threads (and by
|
* Switch between threads. During the creation of kernel threads (and by proxy
|
||||||
* proxy user threads) we may not return through this code path and thus
|
* user threads) we may not return through this code path and thus the kernel
|
||||||
* the kernel thread initialization function must release the scheduler
|
* thread initialization function must release the scheduler lock.
|
||||||
* lock.
|
|
||||||
*
|
*
|
||||||
* @param [in] oldthr Current thread we are switching from.
|
* @param [in] oldthr Current thread we are switching from.
|
||||||
* @param [in] newthr Thread to switch to.
|
* @param [in] newthr Thread to switch to.
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
Sched_Switch(Thread *oldthr, Thread *newthr)
|
Sched_Switch(Thread *oldthr, Thread *newthr)
|
||||||
@ -185,7 +183,7 @@ Sched_Switch(Thread *oldthr, Thread *newthr)
|
|||||||
/**
|
/**
|
||||||
* Sched_Scheduler --
|
* Sched_Scheduler --
|
||||||
*
|
*
|
||||||
* Run our round robin scheduler to find the process and switch to it.
|
* Run our round robin scheduler to find the process and switch to it.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
Sched_Scheduler()
|
Sched_Scheduler()
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2013-2023 Ali Mashtizadeh
|
||||||
|
* All rights reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
@ -68,8 +68,8 @@ Spinlock_Destroy(Spinlock *lock)
|
|||||||
/**
|
/**
|
||||||
* Spinlock_Lock --
|
* Spinlock_Lock --
|
||||||
*
|
*
|
||||||
* Spin until we acquire the spinlock. This will also disable interrupts
|
* Spin until we acquire the spinlock. This will also disable interrupts to
|
||||||
* to prevent deadlocking with interrupt handlers.
|
* prevent deadlocking with interrupt handlers.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
Spinlock_Lock(Spinlock *lock) __NO_LOCK_ANALYSIS
|
Spinlock_Lock(Spinlock *lock) __NO_LOCK_ANALYSIS
|
||||||
@ -103,7 +103,7 @@ Spinlock_Lock(Spinlock *lock) __NO_LOCK_ANALYSIS
|
|||||||
/**
|
/**
|
||||||
* Spinlock_Unlock --
|
* Spinlock_Unlock --
|
||||||
*
|
*
|
||||||
* Release the spinlock. This will re-enable interrupts.
|
* Release the spinlock. This will re-enable interrupts.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
Spinlock_Unlock(Spinlock *lock) __NO_LOCK_ANALYSIS
|
Spinlock_Unlock(Spinlock *lock) __NO_LOCK_ANALYSIS
|
||||||
|
@ -218,11 +218,12 @@ Thread_Destroy(Thread *thr)
|
|||||||
/**
|
/**
|
||||||
* Thread_Lookup --
|
* Thread_Lookup --
|
||||||
*
|
*
|
||||||
* Lookup a thread by TID and increment its reference count.
|
* Lookup a thread by TID and increment its reference count.
|
||||||
*
|
*
|
||||||
* @param [in] proc Process within which to find a specific thread.
|
* @param [in] proc Process within which to find a specific thread.
|
||||||
* @param [in] tid Thread ID of the thread to find.
|
* @param [in] tid Thread ID of the thread to find.
|
||||||
* @retval NULL if the thread isn't found.
|
*
|
||||||
|
* @retval NULL if the thread isn't found.
|
||||||
*/
|
*/
|
||||||
Thread *
|
Thread *
|
||||||
Thread_Lookup(Process *proc, uint64_t tid)
|
Thread_Lookup(Process *proc, uint64_t tid)
|
||||||
@ -246,7 +247,7 @@ Thread_Lookup(Process *proc, uint64_t tid)
|
|||||||
/**
|
/**
|
||||||
* Thread_Retain --
|
* Thread_Retain --
|
||||||
*
|
*
|
||||||
* Increment the reference count for a given thread.
|
* Increment the reference count for a given thread.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
Thread_Retain(Thread *thr)
|
Thread_Retain(Thread *thr)
|
||||||
@ -258,7 +259,7 @@ Thread_Retain(Thread *thr)
|
|||||||
/**
|
/**
|
||||||
* Thread_Release --
|
* Thread_Release --
|
||||||
*
|
*
|
||||||
* Decrement the reference count for a given thread.
|
* Decrement the reference count for a given thread.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
Thread_Release(Thread *thr)
|
Thread_Release(Thread *thr)
|
||||||
@ -272,7 +273,7 @@ Thread_Release(Thread *thr)
|
|||||||
/**
|
/**
|
||||||
* Thread_Wait --
|
* Thread_Wait --
|
||||||
*
|
*
|
||||||
* Wait for any thread (tid == TID_ANY) or a specific thread.
|
* Wait for any thread (tid == TID_ANY) or a specific thread.
|
||||||
*/
|
*/
|
||||||
uint64_t
|
uint64_t
|
||||||
Thread_Wait(Thread *thr, uint64_t tid)
|
Thread_Wait(Thread *thr, uint64_t tid)
|
||||||
|
@ -30,7 +30,7 @@ DEFINE_SLAB(VNode, &vnodeSlab);
|
|||||||
/**
|
/**
|
||||||
* VFS_MountRoot --
|
* VFS_MountRoot --
|
||||||
*
|
*
|
||||||
* Mount the root file system from a specific disk.
|
* Mount the root file system from a specific disk.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
VFS_MountRoot(Disk *rootDisk)
|
VFS_MountRoot(Disk *rootDisk)
|
||||||
@ -56,9 +56,8 @@ VFS_MountRoot(Disk *rootDisk)
|
|||||||
/**
|
/**
|
||||||
* VFS_Lookup --
|
* VFS_Lookup --
|
||||||
*
|
*
|
||||||
* Lookup a VNode by a path. This function recursively searches the
|
* Lookup a VNode by a path. This function recursively searches the directory
|
||||||
* directory heirarchy until the given path is found otherwise returns
|
* heirarchy until the given path is found otherwise returns NULL if not found.
|
||||||
* NULL if not found.
|
|
||||||
*/
|
*/
|
||||||
VNode *
|
VNode *
|
||||||
VFS_Lookup(const char *path)
|
VFS_Lookup(const char *path)
|
||||||
@ -118,8 +117,8 @@ VFS_Lookup(const char *path)
|
|||||||
/**
|
/**
|
||||||
* VFS_Stat --
|
* VFS_Stat --
|
||||||
*
|
*
|
||||||
* Return the struct stat that contains the file and directory information
|
* Return the struct stat that contains the file and directory information for
|
||||||
* for a given VNode.
|
* a given VNode.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
VFS_Stat(const char *path, struct stat *sb)
|
VFS_Stat(const char *path, struct stat *sb)
|
||||||
@ -138,10 +137,11 @@ VFS_Stat(const char *path, struct stat *sb)
|
|||||||
/**
|
/**
|
||||||
* VFS_Open --
|
* VFS_Open --
|
||||||
*
|
*
|
||||||
* Open a vnode for reading and writing.
|
* Open a vnode for reading and writing.
|
||||||
*
|
*
|
||||||
* @param [in] fn VNode to open.
|
* @param [in] fn VNode to open.
|
||||||
* @return Return status
|
*
|
||||||
|
* @return Return status
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
VFS_Open(VNode *fn)
|
VFS_Open(VNode *fn)
|
||||||
@ -152,10 +152,11 @@ VFS_Open(VNode *fn)
|
|||||||
/**
|
/**
|
||||||
* VFS_Close --
|
* VFS_Close --
|
||||||
*
|
*
|
||||||
* Close a vnode.
|
* Close a vnode.
|
||||||
*
|
*
|
||||||
* @param [in] fn VNode to close.
|
* @param [in] fn VNode to close.
|
||||||
* @return Return status
|
*
|
||||||
|
* @return Return status
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
VFS_Close(VNode *fn)
|
VFS_Close(VNode *fn)
|
||||||
@ -166,13 +167,14 @@ VFS_Close(VNode *fn)
|
|||||||
/**
|
/**
|
||||||
* VFS_Read --
|
* VFS_Read --
|
||||||
*
|
*
|
||||||
* Read from a vnode.
|
* Read from a vnode.
|
||||||
*
|
*
|
||||||
* @param [in] fn VNode to read from.
|
* @param [in] fn VNode to read from.
|
||||||
* @param [in] buf Buffer to write the data to.
|
* @param [in] buf Buffer to write the data to.
|
||||||
* @param [in] off File offset in bytes.
|
* @param [in] off File offset in bytes.
|
||||||
* @param [in] len Length to read in bytes.
|
* @param [in] len Length to read in bytes.
|
||||||
* @return Return status
|
*
|
||||||
|
* @return Return status
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
VFS_Read(VNode *fn, void *buf, uint64_t off, uint64_t len)
|
VFS_Read(VNode *fn, void *buf, uint64_t off, uint64_t len)
|
||||||
@ -183,13 +185,14 @@ VFS_Read(VNode *fn, void *buf, uint64_t off, uint64_t len)
|
|||||||
/**
|
/**
|
||||||
* VFS_Write --
|
* VFS_Write --
|
||||||
*
|
*
|
||||||
* Write from a vnode.
|
* Write from a vnode.
|
||||||
*
|
*
|
||||||
* @param [in] fn VNode to write to.
|
* @param [in] fn VNode to write to.
|
||||||
* @param [in] buf Buffer to read the data from.
|
* @param [in] buf Buffer to read the data from.
|
||||||
* @param [in] off File offset in bytes.
|
* @param [in] off File offset in bytes.
|
||||||
* @param [in] len Length to read in bytes.
|
* @param [in] len Length to read in bytes.
|
||||||
* @return Return status
|
*
|
||||||
|
* @return Return status
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
VFS_Write(VNode *fn, void *buf, uint64_t off, uint64_t len)
|
VFS_Write(VNode *fn, void *buf, uint64_t off, uint64_t len)
|
||||||
@ -200,13 +203,14 @@ VFS_Write(VNode *fn, void *buf, uint64_t off, uint64_t len)
|
|||||||
/**
|
/**
|
||||||
* VFS_ReadDir --
|
* VFS_ReadDir --
|
||||||
*
|
*
|
||||||
* Read a directory entry from a vnode.
|
* Read a directory entry from a vnode.
|
||||||
*
|
*
|
||||||
* @param [in] fn VNode to read from.
|
* @param [in] fn VNode to read from.
|
||||||
* @param [in] buf Buffer to write the data to.
|
* @param [in] buf Buffer to write the data to.
|
||||||
* @param [in] off Directory offset in bytes.
|
* @param [in] off Directory offset in bytes.
|
||||||
* @param [in] len Length to read in bytes.
|
* @param [in] len Length to read in bytes.
|
||||||
* @return Return status
|
*
|
||||||
|
* @return Return status
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
VFS_ReadDir(VNode *fn, void *buf, uint64_t len, uint64_t *off)
|
VFS_ReadDir(VNode *fn, void *buf, uint64_t len, uint64_t *off)
|
||||||
|
Loading…
Reference in New Issue
Block a user