Add a "sleep" syscall that sleeps for N seconds.

This commit is contained in:
Andreas Kling 2018-10-25 13:53:49 +02:00
parent c6f2890d8e
commit 5978185242
Notes: sideshowbarker 2024-07-19 18:38:45 +09:00
11 changed files with 37 additions and 12 deletions

View file

@ -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(),

View file

@ -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:

View file

@ -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);

View file

@ -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();

Binary file not shown.

View file

@ -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

View file

@ -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);
}
}

View file

@ -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

1
Userland/.gitignore vendored
View file

@ -3,4 +3,5 @@ sh
ps
ls
pwd
sleep
*.o

View file

@ -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 $<

10
Userland/sleep.cpp Normal file
View file

@ -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;
}