summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Kernel/Process.cpp1
-rw-r--r--Kernel/TTY.cpp1
-rwxr-xr-xKernel/sync.sh1
-rw-r--r--LibC/errno_numbers.h48
-rw-r--r--LibC/signal.cpp14
-rw-r--r--LibC/signal.h24
-rw-r--r--LibC/signal_numbers.h44
-rw-r--r--LibC/stat.cpp12
-rw-r--r--LibC/string.cpp18
-rw-r--r--LibC/string.h1
-rw-r--r--LibC/unistd.h6
-rw-r--r--Userland/.gitignore1
-rw-r--r--Userland/Makefile5
-rw-r--r--Userland/strsignal.cpp11
-rw-r--r--VirtualFileSystem/UnixTypes.h26
15 files changed, 153 insertions, 60 deletions
diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp
index 7ecddc2ae6..972c5611df 100644
--- a/Kernel/Process.cpp
+++ b/Kernel/Process.cpp
@@ -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
diff --git a/Kernel/TTY.cpp b/Kernel/TTY.cpp
index 9661ce9353..0161a54043 100644
--- a/Kernel/TTY.cpp
+++ b/Kernel/TTY.cpp
@@ -1,5 +1,6 @@
#include "TTY.h"
#include "Process.h"
+#include <LibC/signal_numbers.h>
TTY::TTY(unsigned major, unsigned minor)
: CharacterDevice(major, minor)
diff --git a/Kernel/sync.sh b/Kernel/sync.sh
index eed85a2a43..142e5c9a8b 100755
--- a/Kernel/sync.sh
+++ b/Kernel/sync.sh
@@ -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
diff --git a/LibC/errno_numbers.h b/LibC/errno_numbers.h
new file mode 100644
index 0000000000..89a9e582c2
--- /dev/null
+++ b/LibC/errno_numbers.h
@@ -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
+};
diff --git a/LibC/signal.cpp b/LibC/signal.cpp
index c42802df12..b348128308 100644
--- a/LibC/signal.cpp
+++ b/LibC/signal.cpp
@@ -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
+};
+
+
}
diff --git a/LibC/signal.h b/LibC/signal.h
index 03e2f03d4a..0cc5e5a142 100644
--- a/LibC/signal.h
+++ b/LibC/signal.h
@@ -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
diff --git a/LibC/signal_numbers.h b/LibC/signal_numbers.h
new file mode 100644
index 0000000000..a26beeaa15
--- /dev/null
+++ b/LibC/signal_numbers.h
@@ -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
+};
diff --git a/LibC/stat.cpp b/LibC/stat.cpp
new file mode 100644
index 0000000000..9dd53da298
--- /dev/null
+++ b/LibC/stat.cpp
@@ -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);
+}
+
+}
+
diff --git a/LibC/string.cpp b/LibC/string.cpp
index 3f5fafb1bc..e905248ed0 100644
--- a/LibC/string.cpp
+++ b/LibC/string.cpp
@@ -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];
}
+}
diff --git a/LibC/string.h b/LibC/string.h
index 2693ae19b5..cb0c9ddd9b 100644
--- a/LibC/string.h
+++ b/LibC/string.h
@@ -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
diff --git a/LibC/unistd.h b/LibC/unistd.h
index 9b388e0733..69d9e9c31c 100644
--- a/LibC/unistd.h
+++ b/LibC/unistd.h
@@ -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
diff --git a/Userland/.gitignore b/Userland/.gitignore
index 51ce12a3ca..33447cf7c0 100644
--- a/Userland/.gitignore
+++ b/Userland/.gitignore
@@ -18,3 +18,4 @@ kill
tty
ft
ft2
+strsignal
diff --git a/Userland/Makefile b/Userland/Makefile
index 91c8f308c7..fc4b9af423 100644
--- a/Userland/Makefile
+++ b/Userland/Makefile
@@ -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 $<
diff --git a/Userland/strsignal.cpp b/Userland/strsignal.cpp
new file mode 100644
index 0000000000..1adbafe4b2
--- /dev/null
+++ b/Userland/strsignal.cpp
@@ -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;
+}
diff --git a/VirtualFileSystem/UnixTypes.h b/VirtualFileSystem/UnixTypes.h
index ed29ce03b0..02f2a3962d 100644
--- a/VirtualFileSystem/UnixTypes.h
+++ b/VirtualFileSystem/UnixTypes.h
@@ -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;