mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-04 20:58:23 +03:00
Add strsignal() and improve sharing signal numbers between LibC and kernel.
This commit is contained in:
parent
8d1f8b2518
commit
7c3746592b
Notes:
sideshowbarker
2024-07-19 18:33:00 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/7c3746592bf
@ -14,6 +14,7 @@
|
||||
#include "RTC.h"
|
||||
#include "ProcFileSystem.h"
|
||||
#include <AK/StdLib.h>
|
||||
#include <LibC/signal_numbers.h>
|
||||
|
||||
//#define DEBUG_IO
|
||||
//#define TASK_DEBUG
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include "TTY.h"
|
||||
#include "Process.h"
|
||||
#include <LibC/signal_numbers.h>
|
||||
|
||||
TTY::TTY(unsigned major, unsigned minor)
|
||||
: CharacterDevice(major, minor)
|
||||
|
@ -23,6 +23,7 @@ cp ../Userland/ft2 mnt/bin/ft2
|
||||
cp ../Userland/mm mnt/bin/mm
|
||||
cp ../Userland/kill mnt/bin/kill
|
||||
cp ../Userland/tty mnt/bin/tty
|
||||
cp ../Userland/strsignal mnt/bin/strsignal
|
||||
sh sync-local.sh
|
||||
cp kernel.map mnt/
|
||||
umount mnt
|
||||
|
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
|
||||
|
1
Userland/.gitignore
vendored
1
Userland/.gitignore
vendored
@ -18,3 +18,4 @@ kill
|
||||
tty
|
||||
ft
|
||||
ft2
|
||||
strsignal
|
||||
|
@ -15,6 +15,7 @@ OBJS = \
|
||||
mm.o \
|
||||
kill.o \
|
||||
ft.o \
|
||||
strsignal.o \
|
||||
tty.o
|
||||
|
||||
APPS = \
|
||||
@ -34,6 +35,7 @@ APPS = \
|
||||
mm \
|
||||
kill \
|
||||
ft \
|
||||
strsignal \
|
||||
tty
|
||||
|
||||
ARCH_FLAGS =
|
||||
@ -105,6 +107,9 @@ kill: kill.o
|
||||
tty: tty.o
|
||||
$(LD) -o $@ $(LDFLAGS) $< ../LibC/LibC.a
|
||||
|
||||
strsignal: strsignal.o
|
||||
$(LD) -o $@ $(LDFLAGS) $< ../LibC/LibC.a
|
||||
|
||||
.cpp.o:
|
||||
@echo "CXX $<"; $(CXX) $(CXXFLAGS) -o $@ -c $<
|
||||
|
||||
|
11
Userland/strsignal.cpp
Normal file
11
Userland/strsignal.cpp
Normal file
@ -0,0 +1,11 @@
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
for (int i = 1; i < 32; ++i) {
|
||||
printf("%d: '%s'\n", i, strsignal(i));
|
||||
}
|
||||
return 0;
|
||||
}
|
@ -8,11 +8,6 @@ namespace Unix {
|
||||
#define SEEK_CUR 1
|
||||
#define SEEK_END 2
|
||||
|
||||
#define SIGINT 2
|
||||
#define SIGKILL 9
|
||||
#define SIGSEGV 11
|
||||
#define SIGTERM 15
|
||||
|
||||
typedef dword dev_t;
|
||||
typedef dword ino_t;
|
||||
typedef dword mode_t;
|
||||
@ -45,29 +40,8 @@ struct sigaction {
|
||||
#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
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef SERENITY
|
||||
// FIXME: Support 64-bit offsets!
|
||||
typedef signed_dword off_t;
|
||||
|
Loading…
Reference in New Issue
Block a user