Finish v0.3.0
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
/// MentOS, The Mentoring Operating system project
|
||||
/// @file dirent.h
|
||||
/// @brief Functions used to manage directories.
|
||||
/// @copyright (c) 2019 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "stddef.h"
|
||||
|
||||
/// The maximum length for a name.
|
||||
#define NAME_MAX 30
|
||||
|
||||
/// @brief Contains the entries of a directory.
|
||||
typedef struct dirent_t
|
||||
{
|
||||
/// The inode of the entry.
|
||||
ino_t d_ino;
|
||||
|
||||
/// The type of the entry.
|
||||
int d_type;
|
||||
|
||||
/// The nam of the entry.
|
||||
char d_name[NAME_MAX + 1];
|
||||
} dirent_t;
|
||||
|
||||
/// @brief Contains information concerning a directory.
|
||||
typedef struct DIR
|
||||
{
|
||||
/// Filesystem directory handle.
|
||||
int handle;
|
||||
|
||||
/// The currently opened entry.
|
||||
ino_t cur_entry;
|
||||
|
||||
/// Path to the directory.
|
||||
char path[NAME_MAX + 1];
|
||||
|
||||
/// Next directory item.
|
||||
dirent_t entry;
|
||||
} DIR;
|
||||
|
||||
/// @brief Opens a directory and returns a handler to it.
|
||||
/// @param path The path of the directory.
|
||||
/// @return Pointer to the directory. Otherwise, NULL.
|
||||
DIR *opendir(const char *path);
|
||||
|
||||
/// @brief Given a pointer to a directory, it closes it.
|
||||
int closedir(DIR *dirp);
|
||||
|
||||
/// @brief At each call of this function, it returns a pointer to the next
|
||||
/// element inside the directory.
|
||||
/// @return A pointer to the next element. If there are no more elments, it
|
||||
/// returns NULL.
|
||||
dirent_t *readdir(DIR *dirp);
|
||||
@@ -0,0 +1,383 @@
|
||||
/// MentOS, The Mentoring Operating system project
|
||||
/// @file process.c
|
||||
/// @brief System call errors definition.
|
||||
/// @copyright (c) 2019 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#pragma once
|
||||
|
||||
extern int *__geterrno();
|
||||
|
||||
#define errno (*__geterrno())
|
||||
|
||||
/// Operation not permitted.
|
||||
#define EPERM 1
|
||||
|
||||
/// No such file or directory.
|
||||
#define ENOENT 2
|
||||
|
||||
/// No such process.
|
||||
#define ESRCH 3
|
||||
|
||||
/// Interrupted system call.
|
||||
#define EINTR 4
|
||||
|
||||
///I/O error.
|
||||
#define EIO 5
|
||||
|
||||
/// No such device or address.
|
||||
#define ENXIO 6
|
||||
|
||||
/// Arg list too long.
|
||||
#define E2BIG 7
|
||||
|
||||
/// Exec format error.
|
||||
#define ENOEXEC 8
|
||||
|
||||
/// Bad file number.
|
||||
#define EBADF 9
|
||||
|
||||
/// No child processes.
|
||||
#define ECHILD 10
|
||||
|
||||
/// Try again.
|
||||
#define EAGAIN 11
|
||||
|
||||
/// Out of memory.
|
||||
#define ENOMEM 12
|
||||
|
||||
/// Permission denied.
|
||||
#define EACCES 13
|
||||
|
||||
/// Bad address.
|
||||
#define EFAULT 14
|
||||
|
||||
/// Block device required.
|
||||
#define ENOTBLK 15
|
||||
|
||||
/// Device or resource busy.
|
||||
#define EBUSY 16
|
||||
|
||||
/// File exists.
|
||||
#define EEXIST 17
|
||||
|
||||
/// Cross-device link.
|
||||
#define EXDEV 18
|
||||
|
||||
/// No such device.
|
||||
#define ENODEV 19
|
||||
|
||||
/// Not a directory.
|
||||
#define ENOTDIR 20
|
||||
|
||||
/// Is a directory.
|
||||
#define EISDIR 21
|
||||
|
||||
/// Invalid argument.
|
||||
#define EINVAL 22
|
||||
|
||||
/// File table overflow.
|
||||
#define ENFILE 23
|
||||
|
||||
/// Too many open files.
|
||||
#define EMFILE 24
|
||||
|
||||
/// Not a typewriter.
|
||||
#define ENOTTY 25
|
||||
|
||||
/// Text file busy.
|
||||
#define ETXTBSY 26
|
||||
|
||||
/// File too large.
|
||||
#define EFBIG 27
|
||||
|
||||
/// No space left on device.
|
||||
#define ENOSPC 28
|
||||
|
||||
/// Illegal seek.
|
||||
#define ESPIPE 29
|
||||
|
||||
/// Read-only file system.
|
||||
#define EROFS 30
|
||||
|
||||
/// Too many links.
|
||||
#define EMLINK 31
|
||||
|
||||
/// Broken pipe.
|
||||
#define EPIPE 32
|
||||
|
||||
/// Math argument out of domain of func.
|
||||
#define EDOM 33
|
||||
|
||||
/// Math result not representable.
|
||||
#define ERANGE 34
|
||||
|
||||
/// Resource deadlock would occur.
|
||||
#define EDEADLK 35
|
||||
|
||||
/// File name too long.
|
||||
#define ENAMETOOLONG 36
|
||||
|
||||
/// No record locks available.
|
||||
#define ENOLCK 37
|
||||
|
||||
/// Function not implemented.
|
||||
#define ENOSYS 38
|
||||
|
||||
/// Directory not empty.
|
||||
#define ENOTEMPTY 39
|
||||
|
||||
/// Too many symbolic links encountered.
|
||||
#define ELOOP 40
|
||||
|
||||
/// Operation would block.
|
||||
#define EWOULDBLOCK EAGAIN
|
||||
|
||||
/// No message of desired type.
|
||||
#define ENOMSG 42
|
||||
|
||||
/// Identifier removed.
|
||||
#define EIDRM 43
|
||||
|
||||
/// Channel number out of range.
|
||||
#define ECHRNG 44
|
||||
|
||||
/// Level 2 not synchronized.
|
||||
#define EL2NSYNC 45
|
||||
|
||||
/// Level 3 halted.
|
||||
#define EL3HLT 46
|
||||
|
||||
/// Level 3 reset.
|
||||
#define EL3RST 47
|
||||
|
||||
/// Link number out of range.
|
||||
#define ELNRNG 48
|
||||
|
||||
/// Protocol driver not attached.
|
||||
#define EUNATCH 49
|
||||
|
||||
/// No CSI structure available.
|
||||
#define ENOCSI 50
|
||||
|
||||
/// Level 2 halted.
|
||||
#define EL2HLT 51
|
||||
|
||||
/// Invalid exchange.
|
||||
#define EBADE 52
|
||||
|
||||
/// Invalid request descriptor.
|
||||
#define EBADR 53
|
||||
|
||||
/// Exchange full.
|
||||
#define EXFULL 54
|
||||
|
||||
/// No anode.
|
||||
#define ENOANO 55
|
||||
|
||||
/// Invalid request code.
|
||||
#define EBADRQC 56
|
||||
|
||||
/// Invalid slot.
|
||||
#define EBADSLT 57
|
||||
|
||||
// TODO: doxygen comment.
|
||||
#define EDEADLOCK EDEADLK
|
||||
|
||||
/// Bad font file format.
|
||||
#define EBFONT 59
|
||||
|
||||
/// Device not a stream.
|
||||
#define ENOSTR 60
|
||||
|
||||
/// No data available.
|
||||
#define ENODATA 61
|
||||
|
||||
/// Timer expired.
|
||||
#define ETIME 62
|
||||
|
||||
/// Out of streams resources.
|
||||
#define ENOSR 63
|
||||
|
||||
/// Machine is not on the network.
|
||||
#define ENONET 64
|
||||
|
||||
/// Package not installed.
|
||||
#define ENOPKG 65
|
||||
|
||||
/// Object is remote.
|
||||
#define EREMOTE 66
|
||||
|
||||
/// Link has been severed.
|
||||
#define ENOLINK 67
|
||||
|
||||
/// Advertise error.
|
||||
#define EADV 68
|
||||
|
||||
/// Srmount error.
|
||||
#define ESRMNT 69
|
||||
|
||||
/// Communication error on send.
|
||||
#define ECOMM 70
|
||||
|
||||
/// Protocol error.
|
||||
#define EPROTO 71
|
||||
|
||||
/// Multihop attempted.
|
||||
#define EMULTIHOP 72
|
||||
|
||||
/// RFS specific error.
|
||||
#define EDOTDOT 73
|
||||
|
||||
/// Not a data message.
|
||||
#define EBADMSG 74
|
||||
|
||||
/// Value too large for defined data type.
|
||||
#define EOVERFLOW 75
|
||||
|
||||
/// Name not unique on network.
|
||||
#define ENOTUNIQ 76
|
||||
|
||||
/// File descriptor in bad state.
|
||||
#define EBADFD 77
|
||||
|
||||
/// Remote address changed.
|
||||
#define EREMCHG 78
|
||||
|
||||
/// Can not access a needed shared library.
|
||||
#define ELIBACC 79
|
||||
|
||||
/// Accessing a corrupted shared library.
|
||||
#define ELIBBAD 80
|
||||
|
||||
/// .lib section in a.out corrupted.
|
||||
#define ELIBSCN 81
|
||||
|
||||
/// Attempting to link in too many shared libraries.
|
||||
#define ELIBMAX 82
|
||||
|
||||
/// Cannot exec a shared library directly.
|
||||
#define ELIBEXEC 83
|
||||
|
||||
/// Illegal byte sequence.
|
||||
#define EILSEQ 84
|
||||
|
||||
/// Interrupted system call should be restarted.
|
||||
#define ERESTART 85
|
||||
|
||||
/// Streams pipe error.
|
||||
#define ESTRPIPE 86
|
||||
|
||||
/// Too many users.
|
||||
#define EUSERS 87
|
||||
|
||||
///Socket operation on non-socket.
|
||||
#define ENOTSOCK 88
|
||||
|
||||
/// Destination address required.
|
||||
#define EDESTADDRREQ 89
|
||||
|
||||
/// Message too long.
|
||||
#define EMSGSIZE 90
|
||||
|
||||
/// Protocol wrong type for socket.
|
||||
#define EPROTOTYPE 91
|
||||
|
||||
/// Protocol not available.
|
||||
#define ENOPROTOOPT 92
|
||||
|
||||
/// Protocol not supported.
|
||||
#define EPROTONOSUPPORT 93
|
||||
|
||||
/// Socket type not supported.
|
||||
#define ESOCKTNOSUPPORT 94
|
||||
|
||||
/// Operation not supported on transport endpoint.
|
||||
#define EOPNOTSUPP 95
|
||||
|
||||
/// Protocol family not supported.
|
||||
#define EPFNOSUPPORT 96
|
||||
|
||||
/// Address family not supported by protocol.
|
||||
#define EAFNOSUPPORT 97
|
||||
|
||||
/// Address already in use.
|
||||
#define EADDRINUSE 98
|
||||
|
||||
/// Cannot assign requested address.
|
||||
#define EADDRNOTAVAIL 99
|
||||
|
||||
/// Network is down.
|
||||
#define ENETDOWN 100
|
||||
|
||||
/// Network is unreachable.
|
||||
#define ENETUNREACH 101
|
||||
|
||||
/// Network dropped connection because of reset.
|
||||
#define ENETRESET 102
|
||||
|
||||
/// Software caused connection abort.
|
||||
#define ECONNABORTED 103
|
||||
|
||||
/// Connection reset by peer.
|
||||
#define ECONNRESET 104
|
||||
|
||||
/// No buffer space available.
|
||||
#define ENOBUFS 105
|
||||
|
||||
/// Transport endpoint is already connected.
|
||||
#define EISCONN 106
|
||||
|
||||
/// Transport endpoint is not connected.
|
||||
#define ENOTCONN 107
|
||||
|
||||
/// Cannot send after transport endpoint shutdown.
|
||||
#define ESHUTDOWN 108
|
||||
|
||||
/// Too many references: cannot splice.
|
||||
#define ETOOMANYREFS 109
|
||||
|
||||
/// Connection timed out.
|
||||
#define ETIMEDOUT 110
|
||||
|
||||
/// Connection refused.
|
||||
#define ECONNREFUSED 111
|
||||
|
||||
/// Host is down.
|
||||
#define EHOSTDOWN 112
|
||||
|
||||
/// No route to host.
|
||||
#define EHOSTUNREACH 113
|
||||
|
||||
///Operation already in progress.
|
||||
#define EALREADY 114
|
||||
|
||||
/// Operation now in progress.
|
||||
#define EINPROGRESS 115
|
||||
|
||||
/// Stale NFS file handle.
|
||||
#define ESTALE 116
|
||||
|
||||
/// Structure needs cleaning.
|
||||
#define EUCLEAN 117
|
||||
|
||||
/// Not a XENIX named type file.
|
||||
#define ENOTNAM 118
|
||||
|
||||
/// No XENIX semaphores available.
|
||||
#define ENAVAIL 119
|
||||
|
||||
/// Is a named type file.
|
||||
#define EISNAM 120
|
||||
|
||||
/// Remote I/O error.
|
||||
#define EREMOTEIO 121
|
||||
|
||||
/// Quota exceeded.
|
||||
#define EDQUOT 122
|
||||
|
||||
/// No medium found.
|
||||
#define ENOMEDIUM 123
|
||||
|
||||
/// Wrong medium type.
|
||||
#define EMEDIUMTYPE 124
|
||||
@@ -0,0 +1,53 @@
|
||||
/// MentOS, The Mentoring Operating system project
|
||||
/// @file ipc.h
|
||||
/// @brief
|
||||
/// @copyright (c) 2019 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "stddef.h"
|
||||
|
||||
/// Create key if key does not exist.
|
||||
#define IPC_CREAT 01000
|
||||
|
||||
/// Fail if key exists.
|
||||
#define IPC_EXCL 02000
|
||||
|
||||
/// Return error on wait.
|
||||
#define IPC_NOWAIT 04000
|
||||
|
||||
/// Remove identifier.
|
||||
#define IPC_RMID 0
|
||||
|
||||
/// Set `ipc_perm' options.
|
||||
#define IPC_SET 1
|
||||
|
||||
/// Get `ipc_perm' options.
|
||||
#define IPC_STAT 2
|
||||
|
||||
/// See ipcs.
|
||||
#define IPC_INFO 3
|
||||
|
||||
struct ipc_perm {
|
||||
/// Creator user id.
|
||||
uid_t cuid;
|
||||
|
||||
/// Creator group id.
|
||||
gid_t cgid;
|
||||
|
||||
/// User id.
|
||||
uid_t uid;
|
||||
|
||||
/// Group id.
|
||||
gid_t gid;
|
||||
|
||||
/// r/w permission.
|
||||
ushort mode;
|
||||
|
||||
/// Sequence # (to generate unique msg/sem/shm id).
|
||||
ushort seq;
|
||||
|
||||
/// User specified msg/sem/shm key.
|
||||
key_t key;
|
||||
};
|
||||
@@ -0,0 +1,7 @@
|
||||
/// MentOS, The Mentoring Operating system project
|
||||
/// @file module.h
|
||||
/// @brief
|
||||
/// @copyright (c) 2019 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#pragma once
|
||||
@@ -0,0 +1,43 @@
|
||||
/// MentOS, The Mentoring Operating system project
|
||||
/// @file reboot.h
|
||||
/// @brief
|
||||
/// @copyright (c) 2019 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#pragma once
|
||||
|
||||
// Magic values required to use _reboot() system call.
|
||||
#define LINUX_REBOOT_MAGIC1 0xfee1dead
|
||||
|
||||
#define LINUX_REBOOT_MAGIC2 672274793
|
||||
|
||||
#define LINUX_REBOOT_MAGIC2A 85072278
|
||||
|
||||
#define LINUX_REBOOT_MAGIC2B 369367448
|
||||
|
||||
#define LINUX_REBOOT_MAGIC2C 537993216
|
||||
|
||||
// Commands accepted by the _reboot() system call.
|
||||
/// Restart system using default command and mode.
|
||||
#define LINUX_REBOOT_CMD_RESTART 0x01234567
|
||||
|
||||
/// Stop OS and give system control to ROM monitor, if any.
|
||||
#define LINUX_REBOOT_CMD_HALT 0xCDEF0123
|
||||
|
||||
/// Ctrl-Alt-Del sequence causes RESTART command.
|
||||
#define LINUX_REBOOT_CMD_CAD_ON 0x89ABCDEF
|
||||
|
||||
/// Ctrl-Alt-Del sequence sends SIGINT to init task.
|
||||
#define LINUX_REBOOT_CMD_CAD_OFF 0x00000000
|
||||
|
||||
/// Stop OS and remove all power from system, if possible.
|
||||
#define LINUX_REBOOT_CMD_POWER_OFF 0x4321FEDC
|
||||
|
||||
/// Restart system using given command string.
|
||||
#define LINUX_REBOOT_CMD_RESTART2 0xA1B2C3D4
|
||||
|
||||
/// Suspend system using software suspend if compiled in.
|
||||
#define LINUX_REBOOT_CMD_SW_SUSPEND 0xD000FCE2
|
||||
|
||||
/// Restart system using a previously loaded Linux kernel
|
||||
#define LINUX_REBOOT_CMD_KEXEC 0x45584543
|
||||
@@ -0,0 +1,132 @@
|
||||
/// MentOS, The Mentoring Operating system project
|
||||
/// @file shm.h
|
||||
/// @brief
|
||||
/// @copyright (c) 2019 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ipc.h"
|
||||
#include "debug.h"
|
||||
#include "clock.h"
|
||||
#include "kheap.h"
|
||||
#include "stddef.h"
|
||||
#include "paging.h"
|
||||
#include "syscall.h"
|
||||
#include "scheduler.h"
|
||||
|
||||
//======== Permission flag for shmget ==========================================
|
||||
// or S_IRUGO from <linux/stat.h>.
|
||||
#define SHM_R 0400
|
||||
|
||||
// or S_IWUGO from <linux/stat.h>.
|
||||
#define SHM_W 0200
|
||||
//==============================================================================
|
||||
|
||||
//======== Flags for shmat =====================================================
|
||||
// Attach read-only else read-write.
|
||||
#define SHM_RDONLY 010000
|
||||
|
||||
// Round attach address to SHMLBA.
|
||||
#define SHM_RND 020000
|
||||
|
||||
// Take-over region on attach.
|
||||
#define SHM_REMAP 040000
|
||||
|
||||
// Execution access.
|
||||
#define SHM_EXEC 0100000
|
||||
//==============================================================================
|
||||
|
||||
//======== Commands for shmctl =================================================
|
||||
// Lock segment (root only).
|
||||
#define SHM_LOCK 11
|
||||
|
||||
// Unlock segment (root only).
|
||||
#define SHM_UNLOCK 12
|
||||
//==============================================================================
|
||||
|
||||
// Ipcs ctl commands.
|
||||
#define SHM_STAT 13
|
||||
|
||||
#define SHM_INFO 14
|
||||
|
||||
#define SHM_STAT_ANY 15
|
||||
|
||||
//======== shm_mode upper byte flags ===========================================
|
||||
// segment will be destroyed on last detach.
|
||||
#define SHM_DEST 01000
|
||||
|
||||
// Segment will not be swapped.
|
||||
#define SHM_LOCKED 02000
|
||||
|
||||
// Segment is mapped via hugetlb.
|
||||
#define SHM_HUGETLB 04000
|
||||
|
||||
// Don't check for reservations.
|
||||
#define SHM_NORESERVE 010000
|
||||
|
||||
typedef unsigned long shmatt_t;
|
||||
|
||||
struct shmid_ds {
|
||||
// Operation permission struct.
|
||||
struct ipc_perm shm_perm;
|
||||
|
||||
// Size of segment in bytes.
|
||||
size_t shm_segsz;
|
||||
|
||||
// Time of last shmat().
|
||||
time_t shm_atime;
|
||||
|
||||
// Time of last shmdt().
|
||||
time_t shm_dtime;
|
||||
|
||||
// Time of last change by shmctl().
|
||||
time_t shm_ctime;
|
||||
|
||||
// Pid of creator.
|
||||
pid_t shm_cpid;
|
||||
|
||||
// Pid of last shmop.
|
||||
pid_t shm_lpid;
|
||||
|
||||
// Number of current attaches.
|
||||
shmatt_t shm_nattch;
|
||||
|
||||
struct shmid_ds *next;
|
||||
|
||||
// Where shm created is memorized, should be a file.
|
||||
void *shm_location;
|
||||
};
|
||||
|
||||
/// @@brief Syscall Service Routine: Shared memory control operation.
|
||||
int syscall_shmctl(int *args);
|
||||
|
||||
/// @@brief Syscall Service Routine: Get shared memory segment.
|
||||
int syscall_shmget(int *args);
|
||||
|
||||
/// @@brief Syscall Service Routine: Attach shared memory segment.
|
||||
void *syscall_shmat(int *args);
|
||||
|
||||
/// @@brief Syscall Service Routine: Detach shared memory segment.
|
||||
int syscall_shmdt(int *args);
|
||||
|
||||
/// @@brief User Wrapper: Shared memory control operation.
|
||||
int shmctl(int shmid, int cmd, struct shmid_ds *buf);
|
||||
|
||||
/// @@brief User Wrapper: Get shared memory segment.
|
||||
int shmget(key_t key, size_t size, int flags);
|
||||
|
||||
/// @@brief User Wrapper: Attach shared memory segment.
|
||||
void *shmat(int shmid, void *shmaddr, int flag);
|
||||
|
||||
/// @@brief User Wrapper: Detach shared memory segment.
|
||||
int shmdt(void *shmaddr);
|
||||
|
||||
/// @@brief Find shmid_ds on list.
|
||||
struct shmid_ds *find_shm_fromid(int shmid);
|
||||
|
||||
/// @@brief Find shmid_ds on list.
|
||||
struct shmid_ds *find_shm_fromkey(key_t key);
|
||||
|
||||
/// @@brief shmid_ds on list.
|
||||
struct shmid_ds *find_shm_fromvaddr(void *shmvaddr);
|
||||
@@ -0,0 +1,42 @@
|
||||
/// MentOS, The Mentoring Operating system project
|
||||
/// @file stat.h
|
||||
/// @brief Stat functions.
|
||||
/// @copyright (c) 2019 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "clock.h"
|
||||
#include "stddef.h"
|
||||
|
||||
/// @brief Data structure which contains information about a file.
|
||||
typedef struct stat_t
|
||||
{
|
||||
/// ID of device containing file.
|
||||
dev_t st_dev;
|
||||
/// Fle serial number.
|
||||
ino_t st_ino;
|
||||
/// Mode of file.
|
||||
mode_t st_mode;
|
||||
/// User id del file.
|
||||
uid_t st_uid;
|
||||
/// Group id del file.
|
||||
gid_t st_gid;
|
||||
/// Dimensione del file.
|
||||
off_t st_size;
|
||||
/// Time of last access.
|
||||
time_t st_atime;
|
||||
/// Time of last data modification.
|
||||
time_t st_mtime;
|
||||
/// Time of last status change.
|
||||
time_t st_ctime;
|
||||
} stat_t;
|
||||
|
||||
/// @brief Retrieves information about the file at the given location.
|
||||
/// @param path The file descriptor of the file that is being inquired.
|
||||
/// @param buf A structure where data about the file will be stored.
|
||||
/// @return Returns a negative value on failure.
|
||||
int stat(const char *path, stat_t *buf);
|
||||
|
||||
// TODO: doxygen comment.
|
||||
int mkdir(const char *path, mode_t mode);
|
||||
@@ -0,0 +1,67 @@
|
||||
/// MentOS, The Mentoring Operating system project
|
||||
/// @file types.h
|
||||
/// @brief Collection of Kernel datatype
|
||||
/// @copyright (c) 2019 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#pragma once
|
||||
|
||||
/// The type of process id.
|
||||
typedef signed int pid_t;
|
||||
|
||||
/// The type of process user variable.
|
||||
typedef unsigned int user_t;
|
||||
|
||||
/// The type of process status.
|
||||
typedef unsigned int status_t;
|
||||
|
||||
/// Defines the list of flags of a process.
|
||||
typedef enum eflags_list {
|
||||
/// Carry flag.
|
||||
EFLAG_CF = (1 << 0),
|
||||
|
||||
/// Parity flag.
|
||||
EFLAG_PF = (1 << 2),
|
||||
|
||||
/// Auxiliary carry flag.
|
||||
EFLAG_AF = (1 << 4),
|
||||
|
||||
/// Zero flag.
|
||||
EFLAG_ZF = (1 << 6),
|
||||
|
||||
/// Sign flag.
|
||||
EFLAG_SF = (1 << 7),
|
||||
|
||||
/// Trap flag.
|
||||
EFLAG_TF = (1 << 8),
|
||||
|
||||
/// Interrupt enable flag.
|
||||
EFLAG_IF = (1 << 9),
|
||||
|
||||
/// Direction flag.
|
||||
EFLAG_DF = (1 << 10),
|
||||
|
||||
/// Overflow flag.
|
||||
EFLAG_OF = (1 << 11),
|
||||
|
||||
/// Nested task flag.
|
||||
EFLAG_NT = (1 << 14),
|
||||
|
||||
/// Resume flag.
|
||||
EFLAG_RF = (1 << 16),
|
||||
|
||||
/// Virtual 8086 mode flag.
|
||||
EFLAG_VM = (1 << 17),
|
||||
|
||||
/// Alignment check flag (486+).
|
||||
EFLAG_AC = (1 << 18),
|
||||
|
||||
/// Virutal interrupt flag.
|
||||
EFLAG_VIF = (1 << 19),
|
||||
|
||||
/// Virtual interrupt pending flag.
|
||||
EFLAG_VIP = (1 << 20),
|
||||
|
||||
/// ID flag.
|
||||
EFLAG_ID = (1 << 21),
|
||||
} eflags_list;
|
||||
@@ -0,0 +1,95 @@
|
||||
/// MentOS, The Mentoring Operating system project
|
||||
/// @file unistd.h
|
||||
/// @brief Functions used to manage files.
|
||||
/// @copyright (c) 2019 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "types.h"
|
||||
#include "stddef.h"
|
||||
|
||||
//======== Standard file descriptors ===========================================
|
||||
/// Standard input.
|
||||
#define STDIN_FILENO -3
|
||||
|
||||
/// Standard output.
|
||||
#define STDOUT_FILENO -2
|
||||
|
||||
/// Standard error output.
|
||||
#define STDERR_FILENO -1
|
||||
//==============================================================================
|
||||
|
||||
/// Maximum number of opened file.
|
||||
#define MAX_OPEN_FD 4
|
||||
|
||||
/// @brief Read data from a file descriptor.
|
||||
/// @param fd The file descriptor.
|
||||
/// @param buf The buffer.
|
||||
/// @param nbytes The number of bytes to read.
|
||||
/// @return The number of read characters.
|
||||
ssize_t read(int fd, void *buf, size_t nbytes);
|
||||
|
||||
/// @brief Write data into a file descriptor.
|
||||
/// @param fd The file descriptor.
|
||||
/// @param buf The buffer collecting data to written.
|
||||
/// @param nbytes The number of bytes to write.
|
||||
/// @return The number of written bytes.
|
||||
ssize_t write(int fd, void *buf, size_t nbytes);
|
||||
|
||||
/// @brief Opens the file specified by pathname.
|
||||
/// @param pathname A pathname for a file.
|
||||
/// @param flags Used to set the file status flags and file access modes
|
||||
/// of the open file description.
|
||||
/// @param mode Specifies the file mode bits be applied when a new file
|
||||
/// is created.
|
||||
/// @return Returns a file descriptor, a small, nonnegative integer for
|
||||
/// use in subsequent system calls.
|
||||
int open(const char *pathname, int flags, mode_t mode);
|
||||
|
||||
/// @brief Close a file descriptor.
|
||||
/// @param fildes The file descriptor.
|
||||
/// @return The result of the operation.
|
||||
int close(int fildes);
|
||||
|
||||
/// @brief Removes the given directory.
|
||||
/// @param path The path to the directory to remove.
|
||||
/// @return
|
||||
int rmdir(const char *path);
|
||||
|
||||
/// @brief Wrapper for exit system call.
|
||||
extern void exit(int status);
|
||||
|
||||
/// @brief Return the process identifier of the calling process.
|
||||
/// @return pid_t process identifier.
|
||||
extern pid_t getpid();
|
||||
|
||||
/// @brief Clone the calling process, but without copying the whole address space.
|
||||
/// The calling process is suspended until the new process exits or is
|
||||
/// replaced by a call to `execve'. Return -1 for errors, 0 to the new
|
||||
/// process, and the process ID of the new process to the old process.
|
||||
/// @return
|
||||
extern pid_t vfork();
|
||||
|
||||
/// @brief Replaces the current process image with a new process image.
|
||||
/// @param path The path to the binary file to execute.
|
||||
/// @param argv The list of arguments.
|
||||
/// @param envp
|
||||
/// @return
|
||||
extern int execve(const char *path, char *const argv[], char *const envp[]);
|
||||
|
||||
/// @brief Adds inc to the nice value for the calling thread.
|
||||
/// @param inc The value to add to the nice.
|
||||
/// @return On success, the new nice value is returned. On error, -1 is
|
||||
/// returned, and errno is set appropriately.
|
||||
int nice(int inc);
|
||||
|
||||
/// @brief Reboot system call.
|
||||
/// @param cmd
|
||||
/// @param arg
|
||||
/// @return
|
||||
int reboot(int magic1, int magic2, unsigned int cmd, void *arg);
|
||||
|
||||
void getcwd(char *path, size_t size);
|
||||
|
||||
void chdir(char const *path);
|
||||
@@ -0,0 +1,29 @@
|
||||
/// MentOS, The Mentoring Operating system project
|
||||
/// @file utsname.h
|
||||
/// @brief Functions used to provide information about the machine & OS.
|
||||
/// @copyright (c) 2019 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#pragma once
|
||||
|
||||
/// Maximum length of the string used by utsname.
|
||||
#define SYS_LEN 257
|
||||
|
||||
/// @brief Holds information concerning the machine and the os.
|
||||
typedef struct utsname_t
|
||||
{
|
||||
/// The name of the system.
|
||||
char sysname[SYS_LEN];
|
||||
|
||||
/// The name of the node.
|
||||
char nodename[SYS_LEN];
|
||||
|
||||
/// The version of the OS.
|
||||
char version[SYS_LEN];
|
||||
|
||||
/// The name of the machine.
|
||||
char machine[SYS_LEN];
|
||||
} utsname_t;
|
||||
|
||||
/// @brief Sets the values of os_infos.
|
||||
int uname(utsname_t *os_infos);
|
||||
@@ -0,0 +1,60 @@
|
||||
/// MentOS, The Mentoring Operating system project
|
||||
/// @file wait.h
|
||||
/// @brief
|
||||
/// @copyright (c) 2019 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "types.h"
|
||||
|
||||
/// @brief Return immediately if no child is there to be waited for.
|
||||
#define WNOHANG 0x00000001
|
||||
|
||||
/// @brief Return for children that are stopped, and whose status has not
|
||||
/// been reported.
|
||||
#define WUNTRACED 0x00000002
|
||||
|
||||
/// @brief returns true if the child process exited because of a signal that
|
||||
/// was not caught.
|
||||
#define WIFSIGNALED(status) (!WIFSTOPPED(status) && !WIFEXITED(status))
|
||||
|
||||
/// @brief returns true if the child process that caused the return is
|
||||
/// currently stopped; this is only possible if the call was done using
|
||||
/// WUNTRACED().
|
||||
#define WIFSTOPPED(status) (((status)&0xff) == 0x7f)
|
||||
|
||||
/// @brief evaluates to the least significant eight bits of the return code
|
||||
/// of the child that terminated, which may have been set as the argument
|
||||
/// to a call to exit() or as the argument for a return statement in the
|
||||
/// main program. This macro can only be evaluated if WIFEXITED()
|
||||
/// returned nonzero.
|
||||
#define WEXITSTATUS(status) (((status)&0xff00) >> 8)
|
||||
|
||||
/// @brief returns the number of the signal that caused the child process to
|
||||
/// terminate. This macro can only be evaluated if WIFSIGNALED() returned
|
||||
/// nonzero.
|
||||
#define WTERMSIG(status) ((status)&0x7f)
|
||||
|
||||
/// @brief Is nonzero if the child exited normally.
|
||||
#define WIFEXITED(status) (WTERMSIG(status) == 0)
|
||||
|
||||
/// @brief returns the number of the signal that caused the child to stop.
|
||||
/// This macro can only be evaluated if WIFSTOPPED() returned nonzero.
|
||||
#define WSTOPSIG(status) (WEXITSTATUS(status))
|
||||
|
||||
extern pid_t wait(int *status);
|
||||
|
||||
/// @brief Suspends the execution of the calling thread until a child
|
||||
/// specified by pid argument has changed state.
|
||||
/// @details
|
||||
/// By default, waitpid() waits only for terminated children, but this
|
||||
/// behavior is modifiable via the options argument, as described below.
|
||||
/// The value of pid can be:
|
||||
/// - 1 meaning wait for any child process.
|
||||
/// 0 meaning wait for any child process whose process group ID is
|
||||
/// equal to that of the calling process.
|
||||
/// > 0 meaning wait for the child whose process ID is equal to the
|
||||
/// value of pid.
|
||||
/// @return On error, -1 is returned.
|
||||
extern pid_t waitpid(pid_t pid, int *status, int options);
|
||||
Reference in New Issue
Block a user