summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2018-10-25 13:53:49 +0200
committerAndreas Kling <awesomekling@gmail.com>2018-10-25 13:56:03 +0200
commit597818524277bf24a2d6b10f540cbf2c34c2bb34 (patch)
tree04c49c5219ac2f658681763b3d2b7de1ed1fa7ed
parentc6f2890d8e4620e85d6320a9ed121b640dded80e (diff)
downloadserenity-597818524277bf24a2d6b10f540cbf2c34c2bb34.zip
Add a "sleep" syscall that sleeps for N seconds.
-rw-r--r--Kernel/ProcFileSystem.cpp4
-rw-r--r--Kernel/Syscall.cpp1
-rw-r--r--Kernel/Task.cpp15
-rw-r--r--Kernel/Task.h2
-rw-r--r--Kernel/_fs_contentsbin1024000 -> 1024000 bytes
-rwxr-xr-xKernel/sync-sh1
-rw-r--r--LibC/unistd.cpp5
-rw-r--r--LibC/unistd.h1
-rw-r--r--Userland/.gitignore1
-rw-r--r--Userland/Makefile9
-rw-r--r--Userland/sleep.cpp10
11 files changed, 37 insertions, 12 deletions
diff --git a/Kernel/ProcFileSystem.cpp b/Kernel/ProcFileSystem.cpp
index 5942e8559c..d6aa99bbc2 100644
--- a/Kernel/ProcFileSystem.cpp
+++ b/Kernel/ProcFileSystem.cpp
@@ -24,9 +24,9 @@ bool ProcFileSystem::initialize()
auto stringImpl = StringImpl::createUninitialized(tasks.size() * 256, buffer);
memset(buffer, 0, stringImpl->length());
char* ptr = buffer;
- ptr += ksprintf(ptr, "PID OWNER STATE PPID NSCHED FDS NAME\n");
+ ptr += ksprintf(ptr, "PID OWNER STATE PPID NSCHED FDS NAME\n");
for (auto* task : tasks) {
- ptr += ksprintf(ptr, "%w %w:%w %b %w %w %w %s\n",
+ ptr += ksprintf(ptr, "%w %w:%w %b %w %x %w %s\n",
task->pid(),
task->uid(),
task->gid(),
diff --git a/Kernel/Syscall.cpp b/Kernel/Syscall.cpp
index 538b635d15..762008e84f 100644
--- a/Kernel/Syscall.cpp
+++ b/Kernel/Syscall.cpp
@@ -61,7 +61,6 @@ DWORD handle(DWORD function, DWORD arg1, DWORD arg2, DWORD arg3)
Console::the().putChar(arg1 & 0xff);
break;
case Syscall::Sleep:
- //kprintf("syscall: sleep(%d)\n", arg1);
current->sys$sleep(arg1);
break;
case Syscall::Spawn:
diff --git a/Kernel/Task.cpp b/Kernel/Task.cpp
index 44240a77e5..9612a24cb9 100644
--- a/Kernel/Task.cpp
+++ b/Kernel/Task.cpp
@@ -10,6 +10,7 @@
#include <ELFLoader/ExecSpace.h>
#include "MemoryManager.h"
#include "errno.h"
+#include "i8253.h"
//#define DEBUG_IO
//#define TASK_DEBUG
@@ -719,6 +720,14 @@ int Task::sys$kill(pid_t pid, int sig)
return -1;
}
+int Task::sys$sleep(unsigned seconds)
+{
+ if (!seconds)
+ return 0;
+ sleep(seconds * TICKS_PER_SECOND);
+ return 0;
+}
+
uid_t Task::sys$getuid()
{
return m_uid;
@@ -773,12 +782,6 @@ void sleep(DWORD ticks)
yield();
}
-void Task::sys$sleep(DWORD ticks)
-{
- ASSERT(this == current);
- sleep(ticks);
-}
-
Task* Task::kernelTask()
{
ASSERT(s_kernelTask);
diff --git a/Kernel/Task.h b/Kernel/Task.h
index 9d84877f89..13435fc528 100644
--- a/Kernel/Task.h
+++ b/Kernel/Task.h
@@ -91,7 +91,6 @@ public:
int sys$seek(int fd, int offset);
int sys$kill(pid_t pid, int sig);
int sys$geterror() { return m_error; }
- void sys$sleep(DWORD ticks);
void sys$exit(int status);
int sys$spawn(const char* path);
pid_t sys$waitpid(pid_t);
@@ -99,6 +98,7 @@ public:
int sys$munmap(void*, size_t size);
int sys$get_dir_entries(int fd, void*, size_t);
int sys$getcwd(char*, size_t);
+ int sys$sleep(unsigned seconds);
static void initialize();
diff --git a/Kernel/_fs_contents b/Kernel/_fs_contents
index 182fabbb3f..da330ef7e3 100644
--- a/Kernel/_fs_contents
+++ b/Kernel/_fs_contents
Binary files differ
diff --git a/Kernel/sync-sh b/Kernel/sync-sh
index e2d1e6cd2a..b19da4ba8f 100755
--- a/Kernel/sync-sh
+++ b/Kernel/sync-sh
@@ -5,5 +5,6 @@ cp ../Userland/id mnt/bin/id
cp ../Userland/ps mnt/bin/ps
cp ../Userland/ls mnt/bin/ls
cp ../Userland/pwd mnt/bin/pwd
+cp ../Userland/sleep mnt/bin/sleep
umount mnt
sync
diff --git a/LibC/unistd.cpp b/LibC/unistd.cpp
index 335645e91b..82077c5a52 100644
--- a/LibC/unistd.cpp
+++ b/LibC/unistd.cpp
@@ -57,5 +57,10 @@ char* getcwd(char* buffer, size_t size)
__RETURN_WITH_ERRNO(rc, buffer, nullptr);
}
+int sleep(unsigned seconds)
+{
+ return Syscall::invoke(Syscall::Sleep, (dword)seconds);
+}
+
}
diff --git a/LibC/unistd.h b/LibC/unistd.h
index 96603a6795..2f8f1b5c4e 100644
--- a/LibC/unistd.h
+++ b/LibC/unistd.h
@@ -13,6 +13,7 @@ int close(int fd);
pid_t waitpid(pid_t);
char* getcwd(char* buffer, size_t size);
int lstat(const char* path, stat* statbuf);
+int sleep(unsigned seconds);
#define S_IFMT 0170000
#define S_IFDIR 0040000
diff --git a/Userland/.gitignore b/Userland/.gitignore
index ed1a6797f5..9effb83fcc 100644
--- a/Userland/.gitignore
+++ b/Userland/.gitignore
@@ -3,4 +3,5 @@ sh
ps
ls
pwd
+sleep
*.o
diff --git a/Userland/Makefile b/Userland/Makefile
index 2a866fcc04..20e729d999 100644
--- a/Userland/Makefile
+++ b/Userland/Makefile
@@ -3,14 +3,16 @@ OBJS = \
sh.o \
ps.o \
ls.o \
- pwd.o
+ pwd.o \
+ sleep.o
APPS = \
id \
sh \
ps \
ls \
- pwd
+ pwd \
+ sleep
ARCH_FLAGS =
STANDARD_FLAGS = -std=c++17 -nostdinc++ -nostdlib
@@ -45,6 +47,9 @@ ls: ls.o
pwd: pwd.o
$(LD) -o $@ $(LDFLAGS) $< ../LibC/LibC.a
+sleep: sleep.o
+ $(LD) -o $@ $(LDFLAGS) $< ../LibC/LibC.a
+
.cpp.o:
@echo "CXX $<"; $(CXX) $(CXXFLAGS) -o $@ -c $<
diff --git a/Userland/sleep.cpp b/Userland/sleep.cpp
new file mode 100644
index 0000000000..c0e7c44eea
--- /dev/null
+++ b/Userland/sleep.cpp
@@ -0,0 +1,10 @@
+#include <LibC/unistd.h>
+#include <LibC/stdio.h>
+
+int main(int c, char** v)
+{
+ unsigned secs = 10;
+ sleep(secs);
+ return 0;
+}
+