mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 07:57:46 +00:00
Add strsignal() and improve sharing signal numbers between LibC and kernel.
This commit is contained in:
parent
8d1f8b2518
commit
7c3746592b
15 changed files with 153 additions and 60 deletions
48
LibC/errno_numbers.h
Normal file
48
LibC/errno_numbers.h
Normal file
|
@ -0,0 +1,48 @@
|
|||
#pragma once
|
||||
|
||||
#define __ENUMERATE_ALL_ERRORS \
|
||||
__ERROR(EPERM, "Operation not permitted") \
|
||||
__ERROR(ENOENT, "No such file or directory") \
|
||||
__ERROR(ESRCH, "No such process") \
|
||||
__ERROR(EINTR, "Interrupted syscall") \
|
||||
__ERROR(EIO, "I/O error") \
|
||||
__ERROR(ENXIO, "No such device or address") \
|
||||
__ERROR(E2BIG, "Argument list too long") \
|
||||
__ERROR(ENOEXEC, "Exec format error") \
|
||||
__ERROR(EBADF, "Bad fd number") \
|
||||
__ERROR(ECHILD, "No child processes") \
|
||||
__ERROR(EAGAIN, "Try again") \
|
||||
__ERROR(ENOMEM, "Out of memory") \
|
||||
__ERROR(EACCES, "Permission denied") \
|
||||
__ERROR(EFAULT, "Bad address") \
|
||||
__ERROR(ENOTBLK, "Block device required") \
|
||||
__ERROR(EBUSY, "Device or resource busy") \
|
||||
__ERROR(EEXIST, "File already exists") \
|
||||
__ERROR(EXDEV, "Cross-device link") \
|
||||
__ERROR(ENODEV, "No such device") \
|
||||
__ERROR(ENOTDIR, "Not a directory") \
|
||||
__ERROR(EISDIR, "Is a directory") \
|
||||
__ERROR(EINVAL, "Invalid argument") \
|
||||
__ERROR(ENFILE, "File table overflow") \
|
||||
__ERROR(EMFILE, "Too many open files") \
|
||||
__ERROR(ENOTTY, "Not a TTY") \
|
||||
__ERROR(ETXTBSY, "Text file busy") \
|
||||
__ERROR(EFBIG, "File too large") \
|
||||
__ERROR(ENOSPC, "No space left on device") \
|
||||
__ERROR(ESPIPE, "Illegal seek") \
|
||||
__ERROR(EROFS, "Read-only filesystem") \
|
||||
__ERROR(EMLINK, "Too many links") \
|
||||
__ERROR(EPIPE, "Broken pipe") \
|
||||
__ERROR(ERANGE, "Range error") \
|
||||
__ERROR(ENAMETOOLONG, "Name too long") \
|
||||
__ERROR(ELOOP, "Too many symlinks") \
|
||||
__ERROR(EOVERFLOW, "Overflow") \
|
||||
__ERROR(ENOTIMPL, "Not implemented") \
|
||||
|
||||
enum __errno_values {
|
||||
#undef __ERROR
|
||||
#define __ERROR(a, b) a,
|
||||
__ENUMERATE_ALL_ERRORS
|
||||
#undef __ERROR
|
||||
__errno_count
|
||||
};
|
|
@ -46,7 +46,7 @@ int sigaddset(sigset_t* set, int sig)
|
|||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
*set |= 1 << (sig - 1);
|
||||
*set |= 1 << (sig);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -56,7 +56,7 @@ int sigdelset(sigset_t* set, int sig)
|
|||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
*set &= ~(1 << (sig - 1));
|
||||
*set &= ~(1 << (sig));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -66,9 +66,17 @@ int sigismember(const sigset_t* set, int sig)
|
|||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
if (*set & (1 << (sig - 1)))
|
||||
if (*set & (1 << (sig)))
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char* sys_siglist[NSIG] = {
|
||||
#undef __SIGNAL
|
||||
#define __SIGNAL(a, b) b,
|
||||
__ENUMERATE_ALL_SIGNALS
|
||||
#undef __SIGNAL
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <signal_numbers.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
|
@ -29,6 +30,9 @@ int sigaddset(sigset_t*, int sig);
|
|||
int sigdelset(sigset_t*, int sig);
|
||||
int sigismember(const sigset_t*, int sig);
|
||||
|
||||
#define NSIG 32
|
||||
extern const char* sys_siglist[NSIG];
|
||||
|
||||
#define SIG_DFL ((__sighandler_t)0)
|
||||
#define SIG_ERR ((__sighandler_t)-1)
|
||||
#define SIG_IGN ((__sighandler_t)1)
|
||||
|
@ -41,25 +45,5 @@ int sigismember(const sigset_t*, int sig);
|
|||
#define SIG_UNBLOCK 1
|
||||
#define SIG_SETMASK 2
|
||||
|
||||
#define SIGHUP 1
|
||||
#define SIGINT 2
|
||||
#define SIGQUIT 3
|
||||
#define SIGILL 4
|
||||
#define SIGTRAP 5
|
||||
#define SIGABRT 6
|
||||
#define SIGBUS 7
|
||||
#define SIGFPE 8
|
||||
#define SIGKILL 9
|
||||
#define SIGUSR1 10
|
||||
#define SIGSEGV 11
|
||||
#define SIGUSR2 12
|
||||
#define SIGPIPE 13
|
||||
#define SIGALRM 14
|
||||
#define SIGTERM 15
|
||||
#define SIGCONT 18
|
||||
#define SIGTSTP 20
|
||||
#define SIGTTIN 21
|
||||
#define SIGTTOU 22
|
||||
|
||||
__END_DECLS
|
||||
|
||||
|
|
44
LibC/signal_numbers.h
Normal file
44
LibC/signal_numbers.h
Normal file
|
@ -0,0 +1,44 @@
|
|||
#pragma once
|
||||
|
||||
#define __ENUMERATE_ALL_SIGNALS \
|
||||
__SIGNAL(SIGINVAL, "Invalid signal number") \
|
||||
__SIGNAL(SIGHUP, "Hangup") \
|
||||
__SIGNAL(SIGINT, "Interrupt") \
|
||||
__SIGNAL(SIGQUIT, "Quit") \
|
||||
__SIGNAL(SIGILL, "Illegal instruction") \
|
||||
__SIGNAL(SIGTRAP, "Trap") \
|
||||
__SIGNAL(SIGABRT, "Aborted") \
|
||||
__SIGNAL(SIGBUS, "Bus error") \
|
||||
__SIGNAL(SIGFPE, "FP exception") \
|
||||
__SIGNAL(SIGKILL, "Killed") \
|
||||
__SIGNAL(SIGUSR1, "User signal 1") \
|
||||
__SIGNAL(SIGSEGV, "Segmentation violation") \
|
||||
__SIGNAL(SIGUSR2, "User signal 2") \
|
||||
__SIGNAL(SIGPIPE, "Broken pipe") \
|
||||
__SIGNAL(SIGALRM, "Alarm clock") \
|
||||
__SIGNAL(SIGTERM, "Terminated") \
|
||||
__SIGNAL(SIGSTKFLT, "Stack fault") \
|
||||
__SIGNAL(SIGCHLD, "Child exited") \
|
||||
__SIGNAL(SIGCONT, "Continued") \
|
||||
__SIGNAL(SIGSTOP, "Stopped (signal)") \
|
||||
__SIGNAL(SIGTSTP, "Stopped") \
|
||||
__SIGNAL(SIGTTIN, "Stopped (tty input)") \
|
||||
__SIGNAL(SIGTTOU, "Stopped (tty output)") \
|
||||
__SIGNAL(SIGURG, "Urgent I/O condition)") \
|
||||
__SIGNAL(SIGXCPU, "CPU limit exceeded") \
|
||||
__SIGNAL(SIGXFSZ, "File size limit exceeded") \
|
||||
__SIGNAL(SIGVTALRM, "Virtual timer expired") \
|
||||
__SIGNAL(SIGPROF, "Profiling timer expired") \
|
||||
__SIGNAL(SIGWINCH, "Window changed") \
|
||||
__SIGNAL(SIGIO, "I/O possible") \
|
||||
__SIGNAL(SIGPWR, "Power failure") \
|
||||
__SIGNAL(SIGSYS, "Bad system call") \
|
||||
|
||||
|
||||
enum __signal_numbers {
|
||||
#undef __SIGNAL
|
||||
#define __SIGNAL(a, b) a,
|
||||
__ENUMERATE_ALL_SIGNALS
|
||||
#undef __SIGNAL
|
||||
__signal_count
|
||||
};
|
12
LibC/stat.cpp
Normal file
12
LibC/stat.cpp
Normal file
|
@ -0,0 +1,12 @@
|
|||
#include <sys/stat.h>
|
||||
#include <Kernel/Syscall.h>
|
||||
|
||||
extern "C" {
|
||||
|
||||
mode_t umask(mode_t mask)
|
||||
{
|
||||
return Syscall::invoke(Syscall::SC_umask, (dword)mask);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
#include "string.h"
|
||||
#include "errno.h"
|
||||
#include "stdio.h"
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
|
||||
extern "C" {
|
||||
|
||||
|
@ -157,7 +158,7 @@ char* strncat(char *dest, const char *src, size_t n)
|
|||
|
||||
const char* sys_errlist[] = {
|
||||
#undef __ERROR
|
||||
#define __ERROR(a, b) #b,
|
||||
#define __ERROR(a, b) b,
|
||||
__ENUMERATE_ALL_ERRORS
|
||||
#undef __ERROR
|
||||
};
|
||||
|
@ -170,8 +171,15 @@ char* strerror(int errnum)
|
|||
return "Unknown error";
|
||||
}
|
||||
return (char*)sys_errlist[errnum];
|
||||
}
|
||||
|
||||
char* strsignal(int signum)
|
||||
{
|
||||
if (signum >= __signal_count) {
|
||||
printf("strsignal() missing string for signum=%d\n", signum);
|
||||
return "Unknown signal";
|
||||
}
|
||||
return (char*)sys_siglist[signum];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ char* strncat(char *dest, const char *src, size_t);
|
|||
size_t strspn(const char*, const char* accept);
|
||||
size_t strcspn(const char*, const char* reject);
|
||||
char* strerror(int errnum);
|
||||
char* strsignal(int signum);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
|
|
|
@ -48,12 +48,6 @@ int dup2(int old_fd, int new_fd);
|
|||
#define WIFEXITED(status) (WTERMSIG(status) == 0)
|
||||
#define WIFSIGNALED(status) (((char) (((status) & 0x7f) + 1) >> 1) > 0)
|
||||
|
||||
#define SIGINT 2
|
||||
#define SIGKILL 9
|
||||
#define SIGSEGV 11
|
||||
#define SIGTERM 15
|
||||
#define SIGCHLD 17
|
||||
|
||||
#define HOST_NAME_MAX 64
|
||||
|
||||
#define S_IFMT 0170000
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue