libc: Adapt libc to getprocid() + add getppid()

This commit is contained in:
apio 2022-10-18 17:36:33 +02:00
parent 52d391507d
commit 01564cb905
7 changed files with 31 additions and 7 deletions

View File

@ -64,7 +64,7 @@ int main()
printf("Welcome to Luna!\n");
printf("Running as PID %ld\n\n", getpid());
printf("Running as PID %ld, PPID %ld\n\n", getpid(), getppid());
sleep(1);
@ -163,7 +163,7 @@ int main()
if (child == 0)
{
msleep(500);
printf("I am the child, who is my parent?\n");
printf("I am the child (PID %ld), my parent is PID %ld!!\n", getpid(), getppid());
execv("/bin/sym", NULL);
perror("execv");
return 1;

View File

@ -0,0 +1,7 @@
#ifndef _BITS_GETPROCID_H
#define _BITS_GETPROCID_H
#define ID_PID 0
#define ID_PPID 1
#endif

View File

@ -1,6 +1,7 @@
#ifndef _LUNA_H
#define _LUNA_H
#include <bits/getprocid.h>
#include <bits/macros.h>
#include <sys/types.h>
@ -9,6 +10,9 @@ extern "C"
{
#endif
/* Returns a numeric identifier associated with the current process, depending on field. */
long getprocid(int field);
/* 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_getpid 5
#define SYS_getprocid 5
#define SYS_mmap 6
#define SYS_munmap 7
#define SYS_open 8

View File

@ -27,9 +27,12 @@ extern "C"
* the parent. */
pid_t fork(void);
/* Returns the current process's process ID. */
/* Returns the current process' process ID. */
pid_t getpid(void);
/* Returns the current process' parent's process ID. */
pid_t getppid(void);
/* Terminates the program with the status code status. */
__lc_noreturn void _exit(int status);

View File

@ -7,6 +7,11 @@
extern "C"
{
long getprocid(int field)
{
return syscall(SYS_getprocid, field);
}
unsigned int msleep(unsigned int ms)
{
return (unsigned int)syscall(SYS_sleep, ms);

View File

@ -27,7 +27,12 @@ extern "C"
pid_t getpid(void)
{
return syscall(SYS_getpid);
return getprocid(ID_PID);
}
pid_t getppid(void)
{
return getprocid(ID_PPID);
}
long syscall(long number, ...)
@ -40,9 +45,9 @@ extern "C"
{
case SYS_clock:
case SYS_yield:
case SYS_fork:
case SYS_getpid: result = __luna_syscall0(number); break;
case SYS_fork: result = __luna_syscall0(number); break;
case SYS_exit:
case SYS_getprocid:
case SYS_close:
case SYS_exec:
case SYS_mkdir: