diff --git a/apps/src/init.c b/apps/src/init.c index 1f6816fd..4e448b51 100644 --- a/apps/src/init.c +++ b/apps/src/init.c @@ -42,9 +42,9 @@ int print_version() int main() { - if (gettid() == 0) // why are we the idle task? + if (getpid() != 1) { - fprintf(stderr, "SHENANIGANS! init is tid 0 (which is reserved for the idle task)\n"); + fprintf(stderr, "init should be started as PID 1\n"); return 1; } @@ -67,7 +67,7 @@ int main() printf("Welcome to Luna!\n"); - printf("Running as PID %ld\n\n", gettid()); + printf("Running as PID %ld\n\n", getpid()); sleep(1); diff --git a/kernel/include/sys/Syscall.h b/kernel/include/sys/Syscall.h index 6974dcb9..b27d2294 100644 --- a/kernel/include/sys/Syscall.h +++ b/kernel/include/sys/Syscall.h @@ -7,7 +7,7 @@ #define SYS_sleep 2 #define SYS_write 3 #define SYS_paint 4 -#define SYS_gettid 5 +#define SYS_getpid 5 #define SYS_mmap 6 #define SYS_munmap 7 #define SYS_open 8 @@ -33,7 +33,7 @@ void sys_yield(Context* context); void sys_sleep(Context* context, uint64_t ms); void sys_write(Context* context, int fd, size_t size, const char* addr); void sys_paint(Context* context, uint64_t x, uint64_t y, uint64_t w, uint64_t h, uint64_t col); -void sys_gettid(Context* context); +void sys_getpid(Context* context); void sys_mmap(Context* context, void* address, size_t size, int prot); void sys_munmap(Context* context, void* address, size_t size); void sys_open(Context* context, const char* filename, int flags); diff --git a/kernel/src/sys/Syscall.cpp b/kernel/src/sys/Syscall.cpp index eba6416d..1ba62e76 100644 --- a/kernel/src/sys/Syscall.cpp +++ b/kernel/src/sys/Syscall.cpp @@ -16,7 +16,7 @@ void Syscall::entry(Context* context) case SYS_sleep: sys_sleep(context, context->rdi); break; case SYS_write: sys_write(context, (int)context->rdi, context->rsi, (const char*)context->rdx); break; case SYS_paint: sys_paint(context, context->rdi, context->rsi, context->rdx, context->r10, context->r8); break; - case SYS_gettid: sys_gettid(context); break; + case SYS_getpid: sys_getpid(context); break; case SYS_mmap: sys_mmap(context, (void*)context->rdi, context->rsi, (int)context->rdx); break; case SYS_munmap: sys_munmap(context, (void*)context->rdi, context->rsi); break; case SYS_open: sys_open(context, (const char*)context->rdi, (int)context->rsi); break; diff --git a/kernel/src/sys/sched.cpp b/kernel/src/sys/sched.cpp index 952ead52..c641a3d5 100644 --- a/kernel/src/sys/sched.cpp +++ b/kernel/src/sys/sched.cpp @@ -20,7 +20,7 @@ void sys_sleep(Context* context, uint64_t ms) Scheduler::task_yield(context); } -void sys_gettid(Context* context) +void sys_getpid(Context* context) { context->rax = Scheduler::current_task()->id; } \ No newline at end of file diff --git a/libs/libc/include/luna.h b/libs/libc/include/luna.h index cfcfafb4..468b0e05 100644 --- a/libs/libc/include/luna.h +++ b/libs/libc/include/luna.h @@ -9,9 +9,6 @@ extern "C" { #endif - /* Returns the current program's thread identifier. */ - pid_t gettid(void); - /* Sleeps for ms milliseconds. */ unsigned int msleep(unsigned int ms); diff --git a/libs/libc/include/luna/syscall.h b/libs/libc/include/luna/syscall.h index a15caf98..9f6147fe 100644 --- a/libs/libc/include/luna/syscall.h +++ b/libs/libc/include/luna/syscall.h @@ -6,7 +6,7 @@ #define SYS_sleep 2 #define SYS_write 3 #define SYS_paint 4 -#define SYS_gettid 5 +#define SYS_getpid 5 #define SYS_mmap 6 #define SYS_munmap 7 #define SYS_open 8 diff --git a/libs/libc/include/unistd.h b/libs/libc/include/unistd.h index deb3c3cc..286d3e3c 100644 --- a/libs/libc/include/unistd.h +++ b/libs/libc/include/unistd.h @@ -27,6 +27,9 @@ extern "C" * the parent. */ pid_t fork(void); + /* Returns the current process's process ID. */ + pid_t getpid(void); + /* Terminates the program with the status code status. */ __lc_noreturn void _exit(int status); diff --git a/libs/libc/src/luna.cpp b/libs/libc/src/luna.cpp index 7c7af050..e5c66f5a 100644 --- a/libs/libc/src/luna.cpp +++ b/libs/libc/src/luna.cpp @@ -7,11 +7,6 @@ extern "C" { - pid_t gettid() - { - return syscall(SYS_gettid); - } - unsigned int msleep(unsigned int ms) { return (unsigned int)syscall(SYS_sleep, ms); diff --git a/libs/libc/src/unistd.cpp b/libs/libc/src/unistd.cpp index 7836038b..1f51c213 100644 --- a/libs/libc/src/unistd.cpp +++ b/libs/libc/src/unistd.cpp @@ -25,6 +25,11 @@ extern "C" return syscall(SYS_fork); } + pid_t getpid(void) + { + return syscall(SYS_getpid); + } + long syscall(long number, ...) { typedef unsigned long int arg; @@ -36,7 +41,7 @@ extern "C" case SYS_clock: case SYS_yield: case SYS_fork: - case SYS_gettid: result = __luna_syscall0(number); break; + case SYS_getpid: result = __luna_syscall0(number); break; case SYS_exit: case SYS_close: case SYS_exec: