mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-13 01:40:36 +00:00
Add a "sleep" syscall that sleeps for N seconds.
This commit is contained in:
parent
c6f2890d8e
commit
5978185242
Notes:
sideshowbarker
2024-07-19 18:38:45 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/59781852427
11 changed files with 37 additions and 12 deletions
|
@ -24,9 +24,9 @@ bool ProcFileSystem::initialize()
|
||||||
auto stringImpl = StringImpl::createUninitialized(tasks.size() * 256, buffer);
|
auto stringImpl = StringImpl::createUninitialized(tasks.size() * 256, buffer);
|
||||||
memset(buffer, 0, stringImpl->length());
|
memset(buffer, 0, stringImpl->length());
|
||||||
char* ptr = buffer;
|
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) {
|
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->pid(),
|
||||||
task->uid(),
|
task->uid(),
|
||||||
task->gid(),
|
task->gid(),
|
||||||
|
|
|
@ -61,7 +61,6 @@ DWORD handle(DWORD function, DWORD arg1, DWORD arg2, DWORD arg3)
|
||||||
Console::the().putChar(arg1 & 0xff);
|
Console::the().putChar(arg1 & 0xff);
|
||||||
break;
|
break;
|
||||||
case Syscall::Sleep:
|
case Syscall::Sleep:
|
||||||
//kprintf("syscall: sleep(%d)\n", arg1);
|
|
||||||
current->sys$sleep(arg1);
|
current->sys$sleep(arg1);
|
||||||
break;
|
break;
|
||||||
case Syscall::Spawn:
|
case Syscall::Spawn:
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include <ELFLoader/ExecSpace.h>
|
#include <ELFLoader/ExecSpace.h>
|
||||||
#include "MemoryManager.h"
|
#include "MemoryManager.h"
|
||||||
#include "errno.h"
|
#include "errno.h"
|
||||||
|
#include "i8253.h"
|
||||||
|
|
||||||
//#define DEBUG_IO
|
//#define DEBUG_IO
|
||||||
//#define TASK_DEBUG
|
//#define TASK_DEBUG
|
||||||
|
@ -719,6 +720,14 @@ int Task::sys$kill(pid_t pid, int sig)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Task::sys$sleep(unsigned seconds)
|
||||||
|
{
|
||||||
|
if (!seconds)
|
||||||
|
return 0;
|
||||||
|
sleep(seconds * TICKS_PER_SECOND);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
uid_t Task::sys$getuid()
|
uid_t Task::sys$getuid()
|
||||||
{
|
{
|
||||||
return m_uid;
|
return m_uid;
|
||||||
|
@ -773,12 +782,6 @@ void sleep(DWORD ticks)
|
||||||
yield();
|
yield();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Task::sys$sleep(DWORD ticks)
|
|
||||||
{
|
|
||||||
ASSERT(this == current);
|
|
||||||
sleep(ticks);
|
|
||||||
}
|
|
||||||
|
|
||||||
Task* Task::kernelTask()
|
Task* Task::kernelTask()
|
||||||
{
|
{
|
||||||
ASSERT(s_kernelTask);
|
ASSERT(s_kernelTask);
|
||||||
|
|
|
@ -91,7 +91,6 @@ public:
|
||||||
int sys$seek(int fd, int offset);
|
int sys$seek(int fd, int offset);
|
||||||
int sys$kill(pid_t pid, int sig);
|
int sys$kill(pid_t pid, int sig);
|
||||||
int sys$geterror() { return m_error; }
|
int sys$geterror() { return m_error; }
|
||||||
void sys$sleep(DWORD ticks);
|
|
||||||
void sys$exit(int status);
|
void sys$exit(int status);
|
||||||
int sys$spawn(const char* path);
|
int sys$spawn(const char* path);
|
||||||
pid_t sys$waitpid(pid_t);
|
pid_t sys$waitpid(pid_t);
|
||||||
|
@ -99,6 +98,7 @@ public:
|
||||||
int sys$munmap(void*, size_t size);
|
int sys$munmap(void*, size_t size);
|
||||||
int sys$get_dir_entries(int fd, void*, size_t);
|
int sys$get_dir_entries(int fd, void*, size_t);
|
||||||
int sys$getcwd(char*, size_t);
|
int sys$getcwd(char*, size_t);
|
||||||
|
int sys$sleep(unsigned seconds);
|
||||||
|
|
||||||
static void initialize();
|
static void initialize();
|
||||||
|
|
||||||
|
|
Binary file not shown.
|
@ -5,5 +5,6 @@ cp ../Userland/id mnt/bin/id
|
||||||
cp ../Userland/ps mnt/bin/ps
|
cp ../Userland/ps mnt/bin/ps
|
||||||
cp ../Userland/ls mnt/bin/ls
|
cp ../Userland/ls mnt/bin/ls
|
||||||
cp ../Userland/pwd mnt/bin/pwd
|
cp ../Userland/pwd mnt/bin/pwd
|
||||||
|
cp ../Userland/sleep mnt/bin/sleep
|
||||||
umount mnt
|
umount mnt
|
||||||
sync
|
sync
|
||||||
|
|
|
@ -57,5 +57,10 @@ char* getcwd(char* buffer, size_t size)
|
||||||
__RETURN_WITH_ERRNO(rc, buffer, nullptr);
|
__RETURN_WITH_ERRNO(rc, buffer, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int sleep(unsigned seconds)
|
||||||
|
{
|
||||||
|
return Syscall::invoke(Syscall::Sleep, (dword)seconds);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@ int close(int fd);
|
||||||
pid_t waitpid(pid_t);
|
pid_t waitpid(pid_t);
|
||||||
char* getcwd(char* buffer, size_t size);
|
char* getcwd(char* buffer, size_t size);
|
||||||
int lstat(const char* path, stat* statbuf);
|
int lstat(const char* path, stat* statbuf);
|
||||||
|
int sleep(unsigned seconds);
|
||||||
|
|
||||||
#define S_IFMT 0170000
|
#define S_IFMT 0170000
|
||||||
#define S_IFDIR 0040000
|
#define S_IFDIR 0040000
|
||||||
|
|
1
Userland/.gitignore
vendored
1
Userland/.gitignore
vendored
|
@ -3,4 +3,5 @@ sh
|
||||||
ps
|
ps
|
||||||
ls
|
ls
|
||||||
pwd
|
pwd
|
||||||
|
sleep
|
||||||
*.o
|
*.o
|
||||||
|
|
|
@ -3,14 +3,16 @@ OBJS = \
|
||||||
sh.o \
|
sh.o \
|
||||||
ps.o \
|
ps.o \
|
||||||
ls.o \
|
ls.o \
|
||||||
pwd.o
|
pwd.o \
|
||||||
|
sleep.o
|
||||||
|
|
||||||
APPS = \
|
APPS = \
|
||||||
id \
|
id \
|
||||||
sh \
|
sh \
|
||||||
ps \
|
ps \
|
||||||
ls \
|
ls \
|
||||||
pwd
|
pwd \
|
||||||
|
sleep
|
||||||
|
|
||||||
ARCH_FLAGS =
|
ARCH_FLAGS =
|
||||||
STANDARD_FLAGS = -std=c++17 -nostdinc++ -nostdlib
|
STANDARD_FLAGS = -std=c++17 -nostdinc++ -nostdlib
|
||||||
|
@ -45,6 +47,9 @@ ls: ls.o
|
||||||
pwd: pwd.o
|
pwd: pwd.o
|
||||||
$(LD) -o $@ $(LDFLAGS) $< ../LibC/LibC.a
|
$(LD) -o $@ $(LDFLAGS) $< ../LibC/LibC.a
|
||||||
|
|
||||||
|
sleep: sleep.o
|
||||||
|
$(LD) -o $@ $(LDFLAGS) $< ../LibC/LibC.a
|
||||||
|
|
||||||
.cpp.o:
|
.cpp.o:
|
||||||
@echo "CXX $<"; $(CXX) $(CXXFLAGS) -o $@ -c $<
|
@echo "CXX $<"; $(CXX) $(CXXFLAGS) -o $@ -c $<
|
||||||
|
|
||||||
|
|
10
Userland/sleep.cpp
Normal file
10
Userland/sleep.cpp
Normal 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;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue