Skip to content

Commit

Permalink
Merge branch 'release/v0.8.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Galfurian committed Oct 4, 2024
2 parents 3add75d + e24709d commit d03f1d8
Show file tree
Hide file tree
Showing 86 changed files with 6,525 additions and 2,472 deletions.
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,24 @@ Follows the list of implemented features:
**Filesystem**
- [x] Virtual Filesystem (VFS);
- [x] Initramfs;
- [x] EXT2;
- [x] Second Extended File System (EXT2);
- [x] Procfs;

**Input/Output**
- [x] Programmable Interrupt Controller (PIC) drivers;
- [x] PS/2 drivers;
- [x] Advanced Technology Attachment (ATA) drivers;
- [x] Real Time Clock (RTC) drivers;
- [x] Keyboard drivers (IT/ENG layouts);
- [x] Video drivers;
- [ ] VGA drivers;

**Inter-Process Communication (IPC)**
- [X] Semaphore
- [ ] Message queue
- [ ] Shared memory
- [ ] Named pipe
- [X] Message queue
- [X] Shared memory
- [ ] PIPE
- [ ] Named PIPE

I will try to keep it updated...

Expand Down
3 changes: 3 additions & 0 deletions doc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ if (DOXYGEN_FOUND)
${CMAKE_SOURCE_DIR}/mentos/inc/version.h

${CMAKE_SOURCE_DIR}/mentos/src/boot.c
${CMAKE_SOURCE_DIR}/mentos/src/crypt/sha256.c
${CMAKE_SOURCE_DIR}/mentos/src/descriptor_tables/exception.c
${CMAKE_SOURCE_DIR}/mentos/src/descriptor_tables/gdt.c
${CMAKE_SOURCE_DIR}/mentos/src/descriptor_tables/idt.c
Expand Down Expand Up @@ -193,6 +194,7 @@ if (DOXYGEN_FOUND)
${CMAKE_SOURCE_DIR}/libc/inc/bits/ioctls.h
${CMAKE_SOURCE_DIR}/libc/inc/bits/stat.h
${CMAKE_SOURCE_DIR}/libc/inc/bits/termios-struct.h
${CMAKE_SOURCE_DIR}/libc/inc/crypt/sha256.h
${CMAKE_SOURCE_DIR}/libc/inc/ctype.h
${CMAKE_SOURCE_DIR}/libc/inc/fcntl.h
${CMAKE_SOURCE_DIR}/libc/inc/fcvt.h
Expand Down Expand Up @@ -259,6 +261,7 @@ if (DOXYGEN_FOUND)
${CMAKE_SOURCE_DIR}/libc/src/sys/utsname.c
${CMAKE_SOURCE_DIR}/libc/src/termios.c
${CMAKE_SOURCE_DIR}/libc/src/time.c
${CMAKE_SOURCE_DIR}/libc/src/crypt/sha256.c
${CMAKE_SOURCE_DIR}/libc/src/unistd/chdir.c
${CMAKE_SOURCE_DIR}/libc/src/unistd/close.c
${CMAKE_SOURCE_DIR}/libc/src/unistd/creat.c
Expand Down
2 changes: 1 addition & 1 deletion libc/inc/bits/stat.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "time.h"

/// @brief Data structure which contains information about a file.
typedef struct stat_t {
typedef struct stat {
/// ID of device containing file.
dev_t st_dev;
/// File serial number.
Expand Down
32 changes: 25 additions & 7 deletions libc/inc/crypt/sha256.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
/// @file sha256.c
/// @author Enrico Fraccaroli ([email protected])
/// @file sha256.h
/// @brief Implementation of the SHA-256 hashing algorithm.
/// @details The original code was written by Brad Conte, and is available at:
/// https://github.com/B-Con/crypto-algorithms
///
///
/// SHA-256 is one of the three algorithms in the SHA2
/// specification. The others, SHA-384 and SHA-512, are not
/// offered in this implementation.
Expand All @@ -19,14 +18,33 @@
/// @brief SHA256 outputs a 32 byte digest.
#define SHA256_BLOCK_SIZE 32

/// @brief Structure that holds context information for SHA-256 operations.
typedef struct {
uint8_t data[64];
uint32_t datalen;
unsigned long long bitlen;
uint32_t state[8];
uint8_t data[64]; ///< Input data block being processed (512 bits / 64 bytes).
uint32_t datalen; ///< Length of the current data in the buffer (in bytes).
unsigned long long bitlen; ///< Total length of the input in bits (for padding).
uint32_t state[8]; ///< Current hash state (256 bits / 8 * 32-bit words).
} SHA256_ctx_t;

/// @brief Initializes the SHA-256 context.
/// @param ctx Pointer to the SHA-256 context to initialize.
void sha256_init(SHA256_ctx_t *ctx);

/// @brief Adds data to the SHA-256 context for hashing.
/// @param ctx Pointer to the SHA-256 context.
/// @param data Pointer to the data to be hashed.
/// @param len Length of the data to hash, in bytes.
void sha256_update(SHA256_ctx_t *ctx, const uint8_t data[], size_t len);

/// @brief Finalizes the hashing and produces the final SHA-256 digest.
/// @param ctx Pointer to the SHA-256 context.
/// @param hash Pointer to a buffer where the final hash will be stored (must be at least 32 bytes long).
void sha256_final(SHA256_ctx_t *ctx, uint8_t hash[]);

/// @brief Converts a byte array to its hexadecimal string representation.
/// @param src Pointer to the source byte array.
/// @param src_length Length of the source byte array.
/// @param out Pointer to the output buffer for the hexadecimal string.
/// @param out_length Length of the output buffer (must be at least 2 * src_length + 1).
/// @details The output string will be null-terminated if the buffer is large enough.
void sha256_bytes_to_hex(uint8_t *src, size_t src_length, char *out, size_t out_length);
14 changes: 8 additions & 6 deletions libc/inc/readline.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@

#include "stddef.h"

/// @brief Reads a line from the file.
/// @param fd the file descriptor.
/// @param buffer the buffer where we place the line.
/// @param buflen the length of the buffer.
/// @param readlen the amount we read, if negative, we did not encounter a newline.
/// @return 0 if we are done reading, 1 if we encountered a newline, -1 if otherwise.
/// @brief Reads a line from the given file descriptor into the buffer.
/// @param fd The file descriptor to read from.
/// @param buffer The buffer where the read line will be stored. Must not be NULL.
/// @param buflen The size of the buffer.
/// @param read_len A pointer to store the length of the read line. Can be NULL if not needed.
/// @return 1 if a newline was found and the line was read successfully,
/// 0 if the end of the file was reached,
/// -1 if no newline was found and partial data was read.
int readline(int fd, char *buffer, size_t buflen, ssize_t *read_len);
2 changes: 1 addition & 1 deletion libc/inc/sched.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "stdbool.h"

/// @brief Structure that describes scheduling parameters.
typedef struct sched_param_t {
typedef struct sched_param {
/// Static execution priority.
int sched_priority;
/// Expected period of the task
Expand Down
7 changes: 4 additions & 3 deletions libc/inc/signal.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#pragma once

#include "sys/types.h"
#include "stddef.h"

/// @brief List of signals.
typedef enum {
Expand Down Expand Up @@ -161,13 +162,13 @@ typedef void (*sighandler_t)(int);
/// Signals are divided into two cathegories, identified by the two unsigned longs:
/// [ 1, 31] corresponds to normal signals;
/// [32, 64] corresponds to real-time signals.
typedef struct sigset_t {
typedef struct sigset {
/// Signals divided into two cathegories.
unsigned long sig[2];
} sigset_t;

/// @brief Holds the information on how to handle a specific signal.
typedef struct sigaction_t {
typedef struct sigaction {
/// This field specifies the type of action to be performed; its value can be a pointer
/// to the signal handler, SIG_DFL (that is, the value 0) to specify that the default
/// action is performed, or SIG_IGN (that is, the value 1) to specify that the signal is
Expand All @@ -186,7 +187,7 @@ typedef union sigval {
} sigval_t;

/// @brief Stores information about an occurrence of a specific signal.
typedef struct siginfo_t {
typedef struct siginfo {
/// The signal number.
int si_signo;
/// A code identifying who raised the signal (see signal_sender_code_t).
Expand Down
52 changes: 35 additions & 17 deletions libc/inc/sys/list_head.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@

/// @brief Structure used to implement the list_head data structure.
typedef struct list_head {
/// @brief The previous element.
struct list_head *prev;
/// @brief The subsequent element.
struct list_head *next;
struct list_head *prev; ///< The previous element.
struct list_head *next; ///< The subsequent element.
} list_head;

/// @brief Get the struct for this entry.
Expand Down Expand Up @@ -66,6 +64,7 @@ typedef struct list_head {
/// @param head The head of your list.
static inline void list_head_init(list_head *head)
{
assert(head && "Variable head is NULL."); // Ensure head is not NULL
head->next = head->prev = head;
}

Expand All @@ -74,7 +73,7 @@ static inline void list_head_init(list_head *head)
/// @return 1 if empty, 0 otherwise.
static inline int list_head_empty(const list_head *head)
{
assert(head && "Variable head is NULL.");
assert(head && "Variable head is NULL."); // Ensure head is not NULL
return head->next == head;
}

Expand All @@ -83,6 +82,8 @@ static inline int list_head_empty(const list_head *head)
/// @return the size of the list.
static inline unsigned list_head_size(const list_head *head)
{
assert(head && "Variable head is NULL."); // Ensure head is not NULL

unsigned size = 0;
if (!list_head_empty(head)) {
list_for_each_decl(it, head) size += 1;
Expand All @@ -91,12 +92,15 @@ static inline unsigned list_head_size(const list_head *head)
}

/// @brief Insert the new entry after the given location.
/// @param new_entry the new element we want to insert.
/// @param location the element after which we insert.
/// @param new_entry The new element we want to insert.
/// @param location The element after which we insert.
static inline void list_head_insert_after(list_head *new_entry, list_head *location)
{
assert(new_entry && "Variable new_entry is NULL.");
assert(location && "Variable location is NULL.");
assert(new_entry && "Variable new_entry is NULL."); // Check for NULL new_entry
assert(location && "Variable location is NULL."); // Check for NULL location
assert(location->prev && "Variable location->prev is NULL."); // Check location is valid
assert(location->next && "Variable location->next is NULL."); // Check location is valid

// We store the old `next` element.
list_head *old_next = location->next;
// We insert our element.
Expand Down Expand Up @@ -132,10 +136,12 @@ static inline void list_head_insert_before(list_head *new_entry, list_head *loca
/// @param entry the entry we want to remove.
static inline void list_head_remove(list_head *entry)
{
assert(entry && "Variable entry is NULL."); // Check for NULL entry
assert(entry->prev && "Attribute entry->prev is NULL."); // Check previous pointer
assert(entry->next && "Attribute entry->next is NULL."); // Check next pointer

// Check if the element is actually in a list.
if (!list_head_empty(entry)) {
assert(entry->prev && "Attribute entry->prev is NULL.");
assert(entry->next && "Attribute entry->next is NULL.");
// We link the `previous` element to the `next` one.
entry->prev->next = entry->next;
// We link the `next` element to the `previous` one.
Expand All @@ -151,6 +157,8 @@ static inline void list_head_remove(list_head *entry)
/// @return a list_head pointing to the element we removed, NULL on failure.
static inline list_head *list_head_pop(list_head *head)
{
assert(head && "Variable head is NULL."); // Check for NULL head

// Check if the list is not empty.
if (!list_head_empty(head)) {
// Store the pointer.
Expand All @@ -168,11 +176,14 @@ static inline list_head *list_head_pop(list_head *head)
/// @param secondary the secondary list, which gets appended, and re-initialized as empty.
static inline void list_head_append(list_head *main, list_head *secondary)
{
assert(main && "Variable main is NULL."); // Check for NULL main
assert(secondary && "Variable secondary is NULL."); // Check for NULL secondary

// Check that both lists are actually filled with entries.
if (!list_head_empty(main) && !list_head_empty(secondary)) {
assert(main->prev && "Attribute main->prev is NULL.");
assert(secondary->next && "Attribute secondary->next is NULL.");
assert(secondary->prev && "Attribute secondary->prev is NULL.");
assert(main->prev && "Attribute main->prev is NULL."); // Check main's previous pointer
assert(secondary->next && "Attribute secondary->next is NULL."); // Check secondary's next pointer
assert(secondary->prev && "Attribute secondary->prev is NULL."); // Check secondary's previous pointer
// Connect the last element of the main list to the first one of the secondary list.
main->prev->next = secondary->next;
// Connect the first element of the secondary list to the last one of the main list.
Expand All @@ -191,11 +202,15 @@ static inline void list_head_append(list_head *main, list_head *secondary)
/// @param entry2 the second entry which will take the place of the first entry.
static inline void list_head_replace(list_head *entry1, list_head *entry2)
{
assert(entry1 && "Variable entry1 is NULL."); // Check for NULL entry1
assert(entry2 && "Variable entry2 is NULL."); // Check for NULL entry2

// First we need to remove the second entry.
list_head_remove(entry2);
assert(entry2->next && "Attribute entry2->next is NULL.");
assert(entry2->prev && "Attribute entry2->prev is NULL.");
// Then, we can place second entry where the first entry is.
assert(entry2->next && "Attribute entry2->next is NULL."); // Check entry2's next pointer
assert(entry2->prev && "Attribute entry2->prev is NULL."); // Check entry2's previous pointer

// Then, we can place the second entry where the first entry is.
entry2->next = entry1->next;
entry2->next->prev = entry2;
entry2->prev = entry1->prev;
Expand All @@ -209,6 +224,9 @@ static inline void list_head_replace(list_head *entry1, list_head *entry2)
/// @param entry2 the second entry.
static inline void list_head_swap(list_head *entry1, list_head *entry2)
{
assert(entry1 && "Variable entry1 is NULL."); // Check for NULL entry1
assert(entry2 && "Variable entry2 is NULL."); // Check for NULL entry2

list_head *pos = entry2->prev;
list_head_replace(entry1, entry2);
if (pos == entry1) {
Expand Down
1 change: 0 additions & 1 deletion libc/inc/sys/list_head_algorithm.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/// @file list_head_algorithm.h
/// @author Enrico Fraccaroli ([email protected])
/// @brief Some general algorithm that might come in handy while using list_head.
/// @copyright (c) 2014-2024 This file is distributed under the MIT License.
/// See LICENSE.md for details.
Expand Down
1 change: 0 additions & 1 deletion libc/inc/sys/mman.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/// @file mman.h
/// @author Enrico Fraccaroli ([email protected])
/// @brief Functions for managing mappings in virtual address space.
/// @copyright (c) 2014-2024 This file is distributed under the MIT License.
/// See LICENSE.md for details.
Expand Down
18 changes: 10 additions & 8 deletions libc/inc/sys/stat.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
/// See LICENSE.md for details.

#pragma once

/// Prevents the error when inlcuding <bits/stat.h>.
#define __SYS_STAT_H

#include "bits/stat.h"
Expand All @@ -26,14 +28,14 @@
/// @defgroup FileTypeTest File Type Test Macros
/// @brief These macros allows to easily identify file types.
/// @{
#define S_ISTYPE(mode, mask) (((mode) & S_IFMT) == (mask))
#define S_ISSOCK(mode) (S_ISTYPE(mode, S_IFSOCK)) ///< Check if a socket.
#define S_ISLNK(mode) (S_ISTYPE(mode, S_IFLNK)) ///< Check if a symbolic link.
#define S_ISREG(mode) (S_ISTYPE(mode, S_IFREG)) ///< Check if a regular file.
#define S_ISBLK(mode) (S_ISTYPE(mode, S_IFBLK)) ///< Check if a block special.
#define S_ISDIR(mode) (S_ISTYPE(mode, S_IFDIR)) ///< Check if a directory.
#define S_ISCHR(mode) (S_ISTYPE(mode, S_IFCHR)) ///< Check if a char special.
#define S_ISFIFO(mode) (S_ISTYPE(mode, S_IFIFO)) ///< Check if a fifo.
#define S_ISTYPE(mode, mask) (((mode) & S_IFMT) == (mask)) ///< Easy macro for checking the type.
#define S_ISSOCK(mode) (S_ISTYPE(mode, S_IFSOCK)) ///< Check if a socket.
#define S_ISLNK(mode) (S_ISTYPE(mode, S_IFLNK)) ///< Check if a symbolic link.
#define S_ISREG(mode) (S_ISTYPE(mode, S_IFREG)) ///< Check if a regular file.
#define S_ISBLK(mode) (S_ISTYPE(mode, S_IFBLK)) ///< Check if a block special.
#define S_ISDIR(mode) (S_ISTYPE(mode, S_IFDIR)) ///< Check if a directory.
#define S_ISCHR(mode) (S_ISTYPE(mode, S_IFCHR)) ///< Check if a char special.
#define S_ISFIFO(mode) (S_ISTYPE(mode, S_IFIFO)) ///< Check if a fifo.
/// @}

/// @defgroup ModeBitsAccessPermission Mode Bits for Access Permission
Expand Down
18 changes: 11 additions & 7 deletions libc/inc/sys/unistd.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@
#include "stddef.h"
#include "sys/dirent.h"

#define STDIN_FILENO 0 ///< Standard input.
#define STDOUT_FILENO 1 ///< Standard output.
#define STDERR_FILENO 2 ///< Standard error output.
#define STDIN_FILENO 0 ///< Standard input file descriptor.
#define STDOUT_FILENO 1 ///< Standard output file descriptor.
#define STDERR_FILENO 2 ///< Standard error file descriptor.

#define stdin STDIN_FILENO ///< Standard input file descriptor.
#define stdout STDOUT_FILENO ///< Standard output file descriptor.
#define stderr STDERR_FILENO ///< Standard error file descriptor.

/// @brief Read data from a file descriptor.
/// @param fd The file descriptor.
Expand Down Expand Up @@ -80,7 +84,7 @@ extern pid_t getpid(void);
/// If pid != 0 return the SID corresponding to the process having identifier == pid
///@param pid process identifier from wich we want the SID
///@return On success return SID of the session
/// Otherwise return -1 with errno set on: EPERM or ESRCH
/// Otherwise return -1 with errno set on: EPERM or ESRCH
extern pid_t getsid(pid_t pid);

///@brief creates a new session if the calling process is not a
Expand All @@ -90,7 +94,7 @@ extern pid_t getsid(pid_t pid);
/// of a new process group in the session (i.e., its process group ID
/// is made the same as its process ID).
///@return On success return SID of the session just created
/// Otherwise return -1 with errno : EPERM
/// Otherwise return -1 with errno : EPERM
extern pid_t setsid(void);

///@brief returns the Process Group ID (PGID) of the process specified by pid.
Expand All @@ -117,7 +121,7 @@ extern gid_t getegid(void);
///@brief sets the group IDs of the calling process.
///@param gid the Group ID to set
///@return On success, zero is returned.
/// Otherwise returns -1 with errno set to :EINVAL or EPERM
/// Otherwise returns -1 with errno set to :EINVAL or EPERM
extern int setgid(gid_t gid);

///@brief sets the real and effective group IDs of the calling process.
Expand All @@ -138,7 +142,7 @@ extern uid_t geteuid(void);
///@brief Sets the User IDs of the calling process.
///@param uid the new User ID.
///@return On success, zero is returned.
/// Otherwise returns -1 with errno set to :EINVAL or EPERM
/// Otherwise returns -1 with errno set to :EINVAL or EPERM
extern int setuid(uid_t uid);

///@brief Sets the effective and real User IDs of the calling process.
Expand Down
Loading

0 comments on commit d03f1d8

Please sign in to comment.