small random housekeeping stuff i found

This commit is contained in:
IoIxD 2026-01-22 10:08:44 -07:00
commit d94875c788
5 changed files with 144 additions and 412 deletions

View file

@ -11,7 +11,7 @@ MSH_ENTRY_POINT {
while (1) { while (1) {
int out; int out;
char *buf = msh_callocate(512, sizeof(char)); char *buf = msh_callocate(513, sizeof(char));
int i = 0, n = 0, last = 0; int i = 0, n = 0, last = 0;
SIZE_TYPE sz = 0, leftoff = 0; SIZE_TYPE sz = 0, leftoff = 0;

View file

@ -30,7 +30,7 @@ static msh_linux_block *find_block(msh_linux_block **last, SIZE_TYPE size) {
return b; return b;
} }
static msh_linux_block *extend_heap(msh_linux_block *last, SIZE_TYPE size) { static msh_linux_block *extend_heap(msh_linux_block *last, SIZE_TYPE size) {
msh_linux_block *sb = (msh_linux_block *)SYSCALL(brk, 0); msh_linux_block *sb = (msh_linux_block *)SYSCALL_0(brk);
if (SYSCALL(brk, sb + (MSH_BLOCK_SIZE) + size) < 0) { if (SYSCALL(brk, sb + (MSH_BLOCK_SIZE) + size) < 0) {
return (void *)0; return (void *)0;

View file

@ -3,403 +3,147 @@
#include <sys/errno.h> #include <sys/errno.h>
#undef errno #undef errno
static const char *error_table[] = {
"Operation not permitted",
"No such file or directory",
"No such process",
"Interrupted system call",
"Input/output error",
"No such device or address",
"Argument list too long",
"Exec format error",
"Bad file descriptor",
"No child processes",
"Resource temporarily unavailable",
"Cannot allocate memory",
"Permission denied",
"Bad address",
"Block device required",
"Device or resource busy",
"File exists",
"Invalid cross-device link",
"No such device",
"Not a directory",
"Is a directory",
"Invalid argument",
"Too many open files in system",
"Too many open files",
"Inappropriate ioctl for device",
"Text file busy",
"File too large",
"No space left on device",
"Illegal seek",
"Read-only file system",
"Too many links",
"Broken pipe",
"Numerical argument out of domain",
"Numerical result out of range",
"Resource deadlock avoided",
"File name too long",
"No locks available",
"Function not implemented",
"Directory not empty",
"Too many levels of symbolic links",
"No message of desired type",
"Identifier removed",
"Channel number out of range",
"Level 2 not synchronized",
"Level 3 halted",
"Level 3 reset",
"Link number out of range",
"Protocol driver not attached",
"No CSI structure available",
"Level 2 halted",
"Invalid exchange",
"Invalid request descriptor",
"Exchange full",
"No anode",
"Invalid request code",
"Invalid slot",
"Bad font file format",
"Device not a stream",
"No data available",
"Timer expired",
"Out of streams resources",
"Machine is not on the network",
"Package not installed",
"Object is remote",
"Link has been severed",
"Advertise error",
"Srmount error",
"Communication error on send",
"Protocol error",
"Multihop attempted",
"RFS specific error",
"Bad message",
"Value too large for defined data type",
"Name not unique on network",
"File descriptor in bad state",
"Remote address changed",
"Can not access a needed shared library",
"Accessing a corrupted shared library",
".lib section in a.out corrupted",
"Attempting to link in too many shared libraries",
"Cannot exec a shared library directly",
"Invalid or incomplete multibyte or wide character",
"Interrupted system call should be restarted",
"Streams pipe error",
"Too many users",
"Socket operation on non-socket",
"Destination address required",
"Message too long",
"Protocol wrong type for socket",
"Protocol not available",
"Protocol not supported",
"Socket type not supported",
"Operation not supported",
"Protocol family not supported",
"Address family not supported by protocol",
"Address already in use",
"Cannot assign requested address",
"Network is down",
"Network is unreachable",
"Network dropped connection on reset",
"Software caused connection abort",
"Connection reset by peer",
"No buffer space available",
"Transport endpoint is already connected",
"Transport endpoint is not connected",
"Cannot send after transport endpoint shutdown",
"Too many references: cannot splice",
"Connection timed out",
"Connection refused",
"Host is down",
"No route to host",
"Operation already in progress",
"Operation now in progress",
"Stale file handle",
"Structure needs cleaning",
"Not a XENIX named type file",
"No XENIX semaphores available",
"Is a named type file",
"Remote I/O error",
"Disk quota exceeded",
"No medium found",
"Wrong medium type",
"Operation canceled",
"Required key not available",
"Key has expired",
"Key has been revoked",
"Key was rejected by service",
"Owner died",
"State not recoverable",
"Operation not possible due to RF-kill",
"Memory page has hardware error"};
void msh_linux_print_errno(int errno) { void msh_linux_print_errno(int errno) {
switch (errno) { char *errno_num_str = msh_allocate(64);
case EPERM: itoa(errno, errno_num_str, 10);
msh_print_string("Operation not permitted"); if (errno - 1 >= sizeof(error_table)) {
break; msh_print_strings("Unknown error (errno ", errno_num_str, ")", 0);
case ENOENT: } else {
msh_print_string("No such file or directory"); msh_print_strings("Error ", errno_num_str, " (", error_table[errno - 1],
break; ")", 0);
case ESRCH:
msh_print_string("No such process");
break;
case EINTR:
msh_print_string("Interrupted system call");
break;
case EIO:
msh_print_string("Input/output error");
break;
case ENXIO:
msh_print_string("No such device or address");
break;
case E2BIG:
msh_print_string("Argument list too long");
break;
case ENOEXEC:
msh_print_string("Exec format error");
break;
case EBADF:
msh_print_string("Bad file descriptor");
break;
case ECHILD:
msh_print_string("No child processes");
break;
case EAGAIN:
msh_print_string("Resource temporarily unavailable");
break;
case ENOMEM:
msh_print_string("Cannot allocate memory");
break;
case EACCES:
msh_print_string("Permission denied");
break;
case EFAULT:
msh_print_string("Bad address");
break;
case ENOTBLK:
msh_print_string("Block device required");
break;
case EBUSY:
msh_print_string("Device or resource busy");
break;
case EEXIST:
msh_print_string("File exists");
break;
case EXDEV:
msh_print_string("Invalid cross-device link");
break;
case ENODEV:
msh_print_string("No such device");
break;
case ENOTDIR:
msh_print_string("Not a directory");
break;
case EISDIR:
msh_print_string("Is a directory");
break;
case EINVAL:
msh_print_string("Invalid argument");
break;
case ENFILE:
msh_print_string("Too many open files in system");
break;
case EMFILE:
msh_print_string("Too many open files");
break;
case ENOTTY:
msh_print_string("Inappropriate ioctl for device");
break;
case ETXTBSY:
msh_print_string("Text file busy");
break;
case EFBIG:
msh_print_string("File too large");
break;
case ENOSPC:
msh_print_string("No space left on device");
break;
case ESPIPE:
msh_print_string("Illegal seek");
break;
case EROFS:
msh_print_string("Read-only file system");
break;
case EMLINK:
msh_print_string("Too many links");
break;
case EPIPE:
msh_print_string("Broken pipe");
break;
case EDOM:
msh_print_string("Numerical argument out of domain");
break;
case ERANGE:
msh_print_string("Numerical result out of range");
break;
case EDEADLK:
msh_print_string("Resource deadlock avoided");
break;
case ENAMETOOLONG:
msh_print_string("File name too long");
break;
case ENOLCK:
msh_print_string("No locks available");
break;
case ENOSYS:
msh_print_string("Function not implemented");
break;
case ENOTEMPTY:
msh_print_string("Directory not empty");
break;
case ELOOP:
msh_print_string("Too many levels of symbolic links");
break;
case ENOMSG:
msh_print_string("No message of desired type");
break;
case EIDRM:
msh_print_string("Identifier removed");
break;
case ECHRNG:
msh_print_string("Channel number out of range");
break;
case EL2NSYNC:
msh_print_string("Level 2 not synchronized");
break;
case EL3HLT:
msh_print_string("Level 3 halted");
break;
case EL3RST:
msh_print_string("Level 3 reset");
break;
case ELNRNG:
msh_print_string("Link number out of range");
break;
case EUNATCH:
msh_print_string("Protocol driver not attached");
break;
case ENOCSI:
msh_print_string("No CSI structure available");
break;
case EL2HLT:
msh_print_string("Level 2 halted");
break;
case EBADE:
msh_print_string("Invalid exchange");
break;
case EBADR:
msh_print_string("Invalid request descriptor");
break;
case EXFULL:
msh_print_string("Exchange full");
break;
case ENOANO:
msh_print_string("No anode");
break;
case EBADRQC:
msh_print_string("Invalid request code");
break;
case EBADSLT:
msh_print_string("Invalid slot");
break;
case EBFONT:
msh_print_string("Bad font file format");
break;
case ENOSTR:
msh_print_string("Device not a stream");
break;
case ENODATA:
msh_print_string("No data available");
break;
case ETIME:
msh_print_string("Timer expired");
break;
case ENOSR:
msh_print_string("Out of streams resources");
break;
case ENONET:
msh_print_string("Machine is not on the network");
break;
case ENOPKG:
msh_print_string("Package not installed");
break;
case EREMOTE:
msh_print_string("Object is remote");
break;
case ENOLINK:
msh_print_string("Link has been severed");
break;
case EADV:
msh_print_string("Advertise error");
break;
case ESRMNT:
msh_print_string("Srmount error");
break;
case ECOMM:
msh_print_string("Communication error on send");
break;
case EPROTO:
msh_print_string("Protocol error");
break;
case EMULTIHOP:
msh_print_string("Multihop attempted");
break;
case EDOTDOT:
msh_print_string("RFS specific error");
break;
case EBADMSG:
msh_print_string("Bad message");
break;
case EOVERFLOW:
msh_print_string("Value too large for defined data type");
break;
case ENOTUNIQ:
msh_print_string("Name not unique on network");
break;
case EBADFD:
msh_print_string("File descriptor in bad state");
break;
case EREMCHG:
msh_print_string("Remote address changed");
break;
case ELIBACC:
msh_print_string("Can not access a needed shared library");
break;
case ELIBBAD:
msh_print_string("Accessing a corrupted shared library");
break;
case ELIBSCN:
msh_print_string(".lib section in a.out corrupted");
break;
case ELIBMAX:
msh_print_string("Attempting to link in too many shared libraries");
break;
case ELIBEXEC:
msh_print_string("Cannot exec a shared library directly");
break;
case EILSEQ:
msh_print_string("Invalid or incomplete multibyte or wide character");
break;
case ERESTART:
msh_print_string("Interrupted system call should be restarted");
break;
case ESTRPIPE:
msh_print_string("Streams pipe error");
break;
case EUSERS:
msh_print_string("Too many users");
break;
case ENOTSOCK:
msh_print_string("Socket operation on non-socket");
break;
case EDESTADDRREQ:
msh_print_string("Destination address required");
break;
case EMSGSIZE:
msh_print_string("Message too long");
break;
case EPROTOTYPE:
msh_print_string("Protocol wrong type for socket");
break;
case ENOPROTOOPT:
msh_print_string("Protocol not available");
break;
case EPROTONOSUPPORT:
msh_print_string("Protocol not supported");
break;
case ESOCKTNOSUPPORT:
msh_print_string("Socket type not supported");
break;
case EOPNOTSUPP:
msh_print_string("Operation not supported");
break;
case EPFNOSUPPORT:
msh_print_string("Protocol family not supported");
break;
case EAFNOSUPPORT:
msh_print_string("Address family not supported by protocol");
break;
case EADDRINUSE:
msh_print_string("Address already in use");
break;
case EADDRNOTAVAIL:
msh_print_string("Cannot assign requested address");
break;
case ENETDOWN:
msh_print_string("Network is down");
break;
case ENETUNREACH:
msh_print_string("Network is unreachable");
break;
case ENETRESET:
msh_print_string("Network dropped connection on reset");
break;
case ECONNABORTED:
msh_print_string("Software caused connection abort");
break;
case ECONNRESET:
msh_print_string("Connection reset by peer");
break;
case ENOBUFS:
msh_print_string("No buffer space available");
break;
case EISCONN:
msh_print_string("Transport endpoint is already connected");
break;
case ENOTCONN:
msh_print_string("Transport endpoint is not connected");
break;
case ESHUTDOWN:
msh_print_string("Cannot send after transport endpoint shutdown");
break;
case ETOOMANYREFS:
msh_print_string("Too many references: cannot splice");
break;
case ETIMEDOUT:
msh_print_string("Connection timed out");
break;
case ECONNREFUSED:
msh_print_string("Connection refused");
break;
case EHOSTDOWN:
msh_print_string("Host is down");
break;
case EHOSTUNREACH:
msh_print_string("No route to host");
break;
case EALREADY:
msh_print_string("Operation already in progress");
break;
case EINPROGRESS:
msh_print_string("Operation now in progress");
break;
case ESTALE:
msh_print_string("Stale file handle");
break;
case EUCLEAN:
msh_print_string("Structure needs cleaning");
break;
case ENOTNAM:
msh_print_string("Not a XENIX named type file");
break;
case ENAVAIL:
msh_print_string("No XENIX semaphores available");
break;
case EISNAM:
msh_print_string("Is a named type file");
break;
case EREMOTEIO:
msh_print_string("Remote I/O error");
break;
case EDQUOT:
msh_print_string("Disk quota exceeded");
break;
case ENOMEDIUM:
msh_print_string("No medium found");
break;
case EMEDIUMTYPE:
msh_print_string("Wrong medium type");
break;
case ECANCELED:
msh_print_string("Operation canceled");
break;
case ENOKEY:
msh_print_string("Required key not available");
break;
case EKEYEXPIRED:
msh_print_string("Key has expired");
break;
case EKEYREVOKED:
msh_print_string("Key has been revoked");
break;
case EKEYREJECTED:
msh_print_string("Key was rejected by service");
break;
case EOWNERDEAD:
msh_print_string("Owner died");
break;
case ENOTRECOVERABLE:
msh_print_string("State not recoverable");
break;
case ERFKILL:
msh_print_string("Operation not possible due to RF-kill");
break;
case EHWPOISON:
msh_print_string("Memory page has hardware error");
break;
default:
msh_print_string("Unknown");
break;
} }
msh_deallocate(errno_num_str);
} }

View file

@ -128,11 +128,6 @@ int msh_execute(char *cmd, char **args) {
ret = (SIZE_TYPE)SYSCALL(waitid, P_ALL, fork, &status, WEXITED, &ru); ret = (SIZE_TYPE)SYSCALL(waitid, P_ALL, fork, &status, WEXITED, &ru);
/*status_str = msh_allocate(64);
itoa(status.si_code, status_str, 10);
msh_print_strings("Status ", status_str, "\n", 0);
msh_deallocate(status_str);*/
SYSCALL(kill, fork, SIGKILL); SYSCALL(kill, fork, SIGKILL);
SYSCALL(write, 1, "\r", 2); SYSCALL(write, 1, "\r", 2);

View file

@ -9,13 +9,6 @@
#define INIT_SIGNAL(x) SYSCALL(rt_sigaction, x, &sigact, 0, sizeof(sigset_t)); #define INIT_SIGNAL(x) SYSCALL(rt_sigaction, x, &sigact, 0, sizeof(sigset_t));
static void signal_handler(int sig) {
/*char *status_str = msh_allocate(64);
itoa(sig, status_str, 10);
msh_print_strings("\nsignal ", status_str, "\n\n", 0);
msh_deallocate(status_str);*/
}
static void signal_restorer(void) { SYSCALL_0(rt_sigreturn); } static void signal_restorer(void) { SYSCALL_0(rt_sigreturn); }
void msh_linux_setup_signals() { void msh_linux_setup_signals() {
@ -23,7 +16,7 @@ void msh_linux_setup_signals() {
memset(&sigact, 0, sizeof(sigact)); memset(&sigact, 0, sizeof(sigact));
sigact.sa_handler = signal_handler; sigact.sa_handler = SIG_IGN;
sigact.sa_restorer = signal_restorer; sigact.sa_restorer = signal_restorer;
sigact.sa_flags = SA_RESTORER | SA_RESTART; sigact.sa_flags = SA_RESTORER | SA_RESTART;