summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/libc/include/unistd.h3
-rw-r--r--lib/libc/src/unistd/getpid.c43
-rw-r--r--sys/arch/aarch64/aarch64/machdep.c11
-rw-r--r--sys/arch/amd64/isa/i8042.c2
-rw-r--r--sys/arch/amd64/isa/mc1468.c2
-rw-r--r--sys/arch/amd64/isa/spkr.c2
-rw-r--r--sys/dev/dmi/dmi.c2
-rw-r--r--sys/dev/ic/ahci.c2
-rw-r--r--sys/dev/ic/nvme.c2
-rw-r--r--sys/dev/phy/e1000.c2
-rw-r--r--sys/dev/phy/rtl.c2
-rw-r--r--sys/dev/usb/xhci.c2
-rw-r--r--sys/dev/video/fbdev.c2
-rw-r--r--sys/include/arch/aarch64/board.h51
-rw-r--r--sys/include/sys/driver.h19
-rw-r--r--sys/include/sys/proc.h6
-rw-r--r--sys/include/sys/syscall.h2
-rw-r--r--sys/kern/driver_blacklist.c170
-rw-r--r--sys/kern/driver_subr.c10
-rw-r--r--sys/kern/kern_proc.c74
-rw-r--r--sys/kern/kern_syscall.c2
21 files changed, 397 insertions, 14 deletions
diff --git a/lib/libc/include/unistd.h b/lib/libc/include/unistd.h
index 8c82eb8..01c4abc 100644
--- a/lib/libc/include/unistd.h
+++ b/lib/libc/include/unistd.h
@@ -52,6 +52,9 @@ int close(int fd);
int access(const char *path, int mode);
off_t lseek(int fildes, off_t offset, int whence);
+pid_t getpid(void);
+pid_t getppid(void);
+
__END_DECLS
#endif /* !_UNISTD_H */
diff --git a/lib/libc/src/unistd/getpid.c b/lib/libc/src/unistd/getpid.c
new file mode 100644
index 0000000..5770495
--- /dev/null
+++ b/lib/libc/src/unistd/getpid.c
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Hyra nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/syscall.h>
+#include <unistd.h>
+
+pid_t
+getpid(void)
+{
+ return syscall(SYS_getpid);
+}
+
+pid_t
+getppid(void)
+{
+ return syscall(SYS_getppid);
+}
diff --git a/sys/arch/aarch64/aarch64/machdep.c b/sys/arch/aarch64/aarch64/machdep.c
index 33d7c42..9a96cbb 100644
--- a/sys/arch/aarch64/aarch64/machdep.c
+++ b/sys/arch/aarch64/aarch64/machdep.c
@@ -31,6 +31,7 @@
#include <sys/panic.h>
#include <machine/cpu.h>
#include <machine/sync.h>
+#include <machine/board.h>
struct cpu_info g_bsp_ci = {0};
@@ -98,3 +99,13 @@ cpu_startup(struct cpu_info *ci)
__ASMV("msr tpidr_el1, %0" :: "r" (ci));
md_cpu_init();
}
+
+void
+md_get_board(struct board_info *res)
+{
+ uint64_t midr_el1;
+
+ __ASMV("mrs %0, midr_el1" : "=r" (midr_el1));
+ res->partno = (midr_el1 >> 4) & 0xFFF;
+ res->implementer = (midr_el1 >> 24) & 0xFF;
+}
diff --git a/sys/arch/amd64/isa/i8042.c b/sys/arch/amd64/isa/i8042.c
index eb8960c..69d9f92 100644
--- a/sys/arch/amd64/isa/i8042.c
+++ b/sys/arch/amd64/isa/i8042.c
@@ -435,4 +435,4 @@ i8042_init(void)
return 0;
}
-DRIVER_EXPORT(i8042_init);
+DRIVER_EXPORT(i8042_init, "i8042");
diff --git a/sys/arch/amd64/isa/mc1468.c b/sys/arch/amd64/isa/mc1468.c
index bbaa3d1..1f3ae1d 100644
--- a/sys/arch/amd64/isa/mc1468.c
+++ b/sys/arch/amd64/isa/mc1468.c
@@ -278,4 +278,4 @@ static struct cdevsw mc1468_cdevsw = {
.write = mc1468_dev_write,
};
-DRIVER_EXPORT(mc1468_init);
+DRIVER_EXPORT(mc1468_init, "mc1468");
diff --git a/sys/arch/amd64/isa/spkr.c b/sys/arch/amd64/isa/spkr.c
index b2f63b0..c96e5f9 100644
--- a/sys/arch/amd64/isa/spkr.c
+++ b/sys/arch/amd64/isa/spkr.c
@@ -119,4 +119,4 @@ static struct cdevsw beep_cdevsw = {
.write = dev_write
};
-DRIVER_EXPORT(beep_init);
+DRIVER_EXPORT(beep_init, "pcspkr");
diff --git a/sys/dev/dmi/dmi.c b/sys/dev/dmi/dmi.c
index 8c7f21c..59946ad 100644
--- a/sys/dev/dmi/dmi.c
+++ b/sys/dev/dmi/dmi.c
@@ -248,4 +248,4 @@ dmi_init(void)
return 0;
}
-DRIVER_EXPORT(dmi_init);
+DRIVER_EXPORT(dmi_init, "dmi");
diff --git a/sys/dev/ic/ahci.c b/sys/dev/ic/ahci.c
index 5dbf4a7..d17c6a3 100644
--- a/sys/dev/ic/ahci.c
+++ b/sys/dev/ic/ahci.c
@@ -1040,4 +1040,4 @@ static struct bdevsw ahci_bdevsw = {
.bsize = ahci_dev_bsize
};
-DRIVER_DEFER(ahci_init);
+DRIVER_DEFER(ahci_init, "ahci");
diff --git a/sys/dev/ic/nvme.c b/sys/dev/ic/nvme.c
index 822b085..147ab4f 100644
--- a/sys/dev/ic/nvme.c
+++ b/sys/dev/ic/nvme.c
@@ -662,4 +662,4 @@ static struct bdevsw nvme_bdevsw = {
.write = nowrite
};
-DRIVER_DEFER(nvme_init);
+DRIVER_DEFER(nvme_init, "nvme");
diff --git a/sys/dev/phy/e1000.c b/sys/dev/phy/e1000.c
index 95efe6d..41a2a27 100644
--- a/sys/dev/phy/e1000.c
+++ b/sys/dev/phy/e1000.c
@@ -355,4 +355,4 @@ e1000_init(void)
return 0;
}
-DRIVER_EXPORT(e1000_init);
+DRIVER_EXPORT(e1000_init, "e1000");
diff --git a/sys/dev/phy/rtl.c b/sys/dev/phy/rtl.c
index 691f767..d096d1a 100644
--- a/sys/dev/phy/rtl.c
+++ b/sys/dev/phy/rtl.c
@@ -440,4 +440,4 @@ rt81xx_init(void)
return rt_init_mac();
}
-DRIVER_DEFER(rt81xx_init);
+DRIVER_DEFER(rt81xx_init, "rtl81xx");
diff --git a/sys/dev/usb/xhci.c b/sys/dev/usb/xhci.c
index 46ec4af..0ccb7a0 100644
--- a/sys/dev/usb/xhci.c
+++ b/sys/dev/usb/xhci.c
@@ -545,4 +545,4 @@ xhci_init(void)
return xhci_init_hc(&xhc);
}
-DRIVER_EXPORT(xhci_init);
+DRIVER_EXPORT(xhci_init, "xhci");
diff --git a/sys/dev/video/fbdev.c b/sys/dev/video/fbdev.c
index 8a2499d..6b1c6c8 100644
--- a/sys/dev/video/fbdev.c
+++ b/sys/dev/video/fbdev.c
@@ -135,4 +135,4 @@ static const struct ctlops fb_size_ctl = {
.write = NULL,
};
-DRIVER_EXPORT(fbdev_init);
+DRIVER_EXPORT(fbdev_init, "fbdev");
diff --git a/sys/include/arch/aarch64/board.h b/sys/include/arch/aarch64/board.h
new file mode 100644
index 0000000..bba421f
--- /dev/null
+++ b/sys/include/arch/aarch64/board.h
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Hyra nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _MACHINE_BOARD_H_
+#define _MACHINE_BOARD_H_
+
+/* Board implementer */
+#define BOARD_ARM_LIMITED 0x41 /* ARM Limited */
+#define BOARD_BROADCOM 0x42 /* Broadcom corp */
+#define BOARD_CAVIUM 0x43 /* Calvium Inc */
+#define BOARD_DIGITAL_EQUIP 0x44 /* Digital Equipment Corporation */
+#define BOARD_FUJITSU 0x46 /* Fujitsu Ltd */
+
+/*
+ * Board information, contains a part number
+ * and an implementer number.
+ */
+struct board_info {
+ uint8_t implementer;
+ uint16_t partno : 12;
+};
+
+void md_get_board(struct board_info *res);
+
+#endif /* !_MACHINE_BOARD_H_ */
diff --git a/sys/include/sys/driver.h b/sys/include/sys/driver.h
index 9f08de3..e10021a 100644
--- a/sys/include/sys/driver.h
+++ b/sys/include/sys/driver.h
@@ -43,6 +43,7 @@ struct driver_var {
struct driver {
int(*init)(void);
+ const char *name;
struct driver_var *data;
};
@@ -56,7 +57,7 @@ extern char __drivers_init_end[];
extern char __driversd_init_start[];
extern char __driversd_init_end[];
-#define DRIVER_EXPORT(INIT) \
+#define DRIVER_EXPORT(INIT, NAME) \
static struct driver_var __driver_var = { \
.deferred = 0 \
}; \
@@ -64,7 +65,8 @@ extern char __driversd_init_end[];
__attribute__((used, section(".drivers"))) \
static struct driver __driver_desc = { \
.init = INIT, \
- .data = &__driver_var \
+ .data = &__driver_var, \
+ .name = NAME \
}
/*
@@ -84,7 +86,7 @@ extern char __driversd_init_end[];
* context has yet to be initialized. The driver may
* use this to defer requests for I/O.
*/
-#define DRIVER_DEFER(INIT) \
+#define DRIVER_DEFER(INIT, NAME) \
static struct driver_var __driver_var = { \
.deferred = 1 \
}; \
@@ -92,7 +94,8 @@ extern char __driversd_init_end[];
__attribute__((used, section(".drivers.defer"))) \
static struct driver __driver_desc = { \
.init = INIT, \
- .data = &__driver_var \
+ .data = &__driver_var, \
+ .name = NAME \
}
#define DRIVER_DEFERRED() __driver_var.deferred
@@ -101,12 +104,20 @@ extern char __driversd_init_end[];
for (struct driver *__d = (struct driver *)__drivers_init_start; \
(uintptr_t)__d < (uintptr_t)__drivers_init_end; ++__d) \
{ \
+ if (driver_blacklist_check((__d)->name)) { \
+ continue; \
+ } \
__d->init(); \
}
#define DRIVERS_SCHED() \
spawn(&g_proc0, __driver_init_td, NULL, 0, NULL)
+/* Driver blacklist framework */
+int driver_blacklist(const char *name);
+int driver_blacklist_check(const char *name);
+void driver_blacklist_init(void);
+
void __driver_init_td(void);
#endif /* _KERNEL */
diff --git a/sys/include/sys/proc.h b/sys/include/sys/proc.h
index 241d990..7aa04b2 100644
--- a/sys/include/sys/proc.h
+++ b/sys/include/sys/proc.h
@@ -90,6 +90,12 @@ struct proc *this_td(void);
struct proc *get_child(struct proc *cur, pid_t pid);
void proc_reap(struct proc *td);
+pid_t getpid(void);
+pid_t getppid(void);
+
+scret_t sys_getpid(struct syscall_args *scargs);
+scret_t sys_getppid(struct syscall_args *scargs);
+
int md_spawn(struct proc *p, struct proc *parent, uintptr_t ip);
scret_t sys_spawn(struct syscall_args *scargs);
diff --git a/sys/include/sys/syscall.h b/sys/include/sys/syscall.h
index 08bd989..3650e7a 100644
--- a/sys/include/sys/syscall.h
+++ b/sys/include/sys/syscall.h
@@ -54,6 +54,8 @@
#define SYS_lseek 13
#define SYS_sleep 14
#define SYS_inject 15
+#define SYS_getpid 16
+#define SYS_getppid 17
#if defined(_KERNEL)
/* Syscall return value and arg type */
diff --git a/sys/kern/driver_blacklist.c b/sys/kern/driver_blacklist.c
new file mode 100644
index 0000000..982d5c9
--- /dev/null
+++ b/sys/kern/driver_blacklist.c
@@ -0,0 +1,170 @@
+/*
+ * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Hyra nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/types.h>
+#include <sys/errno.h>
+#include <sys/queue.h>
+#include <sys/driver.h>
+#include <vm/dynalloc.h>
+#include <string.h>
+
+#define BLACKLIST_SIZE 64
+
+/*
+ * A driver blacklist entry
+ *
+ * @name: Name of driver to be blacklisted
+ * @buckets: To handle collisions
+ */
+struct blacklist_entry {
+ char *name;
+ TAILQ_ENTRY(blacklist_entry) link;
+ TAILQ_HEAD(, blacklist_entry) buckets;
+};
+
+static struct blacklist_entry blacklist[BLACKLIST_SIZE];
+
+static uint32_t
+fnv1_hash(const char *s)
+{
+ uint32_t hash = 2166136261UL;
+ const uint8_t *p = (uint8_t *)s;
+
+ while (*p != '\0') {
+ hash ^= *p;
+ hash = hash * 0x01000193;
+ ++p;
+ }
+
+ return hash;
+}
+
+/*
+ * Returns a bucket in case of collision
+ */
+static struct blacklist_entry *
+blacklist_collide(struct blacklist_entry *entp, const char *name)
+{
+ struct blacklist_entry *tmp;
+
+ if (entp->name == NULL) {
+ return NULL;
+ }
+
+ TAILQ_FOREACH(tmp, &entp->buckets, link) {
+ if (strcmp(name, tmp->name) == 0) {
+ return tmp;
+ }
+ }
+
+ return NULL;
+}
+
+/*
+ * Mark a driver to be ignored during startup.
+ * Blacklisted drivers will not be ran.
+ *
+ * @name: Name of driver (e.g., 'ahci')
+ */
+int
+driver_blacklist(const char *name)
+{
+ struct blacklist_entry *ent;
+ struct blacklist_entry *bucket;
+ size_t name_len;
+ uint32_t hash;
+
+ if (name == NULL) {
+ return -EINVAL;
+ }
+
+ hash = fnv1_hash(name);
+ ent = &blacklist[hash % BLACKLIST_SIZE];
+ if (ent->name != NULL) {
+ bucket = dynalloc(sizeof(*bucket));
+ if (bucket == NULL) {
+ return -EINVAL;
+ }
+ TAILQ_INSERT_TAIL(&ent->buckets, bucket, link);
+ return 0;
+ }
+
+ name_len = strlen(name);
+ ent->name = dynalloc(name_len + 1);
+ if (ent->name == NULL) {
+ return -ENOMEM;
+ }
+ memcpy(ent->name, name, name_len + 1);
+ return 0;
+}
+
+/*
+ * Checks if a driver name is in the blacklist.
+ * Returns 0 if not, otherwise 1.
+ */
+int
+driver_blacklist_check(const char *name)
+{
+ struct blacklist_entry *ent;
+ uint32_t hash;
+
+ if (name == NULL) {
+ return -EINVAL;
+ }
+
+ hash = fnv1_hash(name);
+ ent = &blacklist[hash % BLACKLIST_SIZE];
+ if (ent->name == NULL) {
+ return 0;
+ }
+
+ if (strcmp(ent->name, name) == 0) {
+ return 1;
+ }
+
+ ent = blacklist_collide(ent, name);
+ if (ent != NULL) {
+ return 1;
+ }
+
+ return 0;
+}
+
+/*
+ * Initialize each entry in the driver
+ * blacklist
+ */
+void
+driver_blacklist_init(void)
+{
+ for (size_t i = 0; i < BLACKLIST_SIZE; ++i) {
+ blacklist[i].name = NULL;
+ TAILQ_INIT(&blacklist[i].buckets);
+ }
+}
diff --git a/sys/kern/driver_subr.c b/sys/kern/driver_subr.c
index b53463a..a0f9f73 100644
--- a/sys/kern/driver_subr.c
+++ b/sys/kern/driver_subr.c
@@ -55,6 +55,16 @@ __driver_init_td(void)
for (dp = (void *)start; (uintptr_t)dp < end; ++dp) {
var = dp->data;
+
+ /*
+ * Check the blacklist to see if this driver
+ * is marked to be ignored. If so, just continue
+ * to the next.
+ */
+ if (driver_blacklist_check(dp->name)) {
+ continue;
+ }
+
if (var->deferred) {
dp->init();
var->deferred = 0;
diff --git a/sys/kern/kern_proc.c b/sys/kern/kern_proc.c
new file mode 100644
index 0000000..3cf2af8
--- /dev/null
+++ b/sys/kern/kern_proc.c
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Hyra nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/types.h>
+#include <sys/proc.h>
+#include <sys/syscall.h>
+
+pid_t
+getpid(void)
+{
+ struct proc *td;
+
+ td = this_td();
+ if (td == NULL) {
+ return -1;
+ }
+
+ return td->pid;
+}
+
+
+pid_t
+getppid(void)
+{
+ struct proc *td;
+
+ td = this_td();
+ if (td == NULL) {
+ return -1;
+ }
+ if (td->parent == NULL) {
+ return -1;
+ }
+
+ return td->parent->pid;
+}
+
+scret_t
+sys_getpid(struct syscall_args *scargs)
+{
+ return getpid();
+}
+
+scret_t
+sys_getppid(struct syscall_args *scargs)
+{
+ return getppid();
+}
diff --git a/sys/kern/kern_syscall.c b/sys/kern/kern_syscall.c
index 292fa56..739dd7f 100644
--- a/sys/kern/kern_syscall.c
+++ b/sys/kern/kern_syscall.c
@@ -54,6 +54,8 @@ scret_t(*g_sctab[])(struct syscall_args *) = {
sys_lseek, /* SYS_lseek */
sys_sleep, /* SYS_sleep */
sys_inject, /* SYS_inject */
+ sys_getpid, /* SYS_getpid */
+ sys_getppid /* SYS_getppid */
};
const size_t MAX_SYSCALLS = NELEM(g_sctab);