Kernel, libc: Rename gettid() to getpid() and move it to unistd.h

This commit is contained in:
apio 2022-10-17 20:08:44 +02:00
parent 87ef210759
commit 8b17065718
9 changed files with 17 additions and 17 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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