summaryrefslogtreecommitdiff
path: root/src/kernel
diff options
context:
space:
mode:
authordzwdz2022-09-02 14:44:52 +0200
committerdzwdz2022-09-02 17:58:47 +0200
commitc16d956c0dd3d69748f7208e09bb69a6df8c6483 (patch)
tree38089f4b9e7fb153aa817e25340b7107f7cdf795 /src/kernel
parent41a15bd16806261d66d55bbb85034553cd58361e (diff)
kernel/proc: introduce child ids for telling children apart
Diffstat (limited to 'src/kernel')
-rw-r--r--src/kernel/proc.c10
-rw-r--r--src/kernel/proc.h4
-rw-r--r--src/kernel/syscalls.c15
3 files changed, 19 insertions, 10 deletions
diff --git a/src/kernel/proc.c b/src/kernel/proc.c
index 71d1f44..85992d5 100644
--- a/src/kernel/proc.c
+++ b/src/kernel/proc.c
@@ -26,7 +26,9 @@ struct process *process_seed(void *data, size_t datalen) {
process_first->state = PS_RUNNING;
process_first->pages = pagedir_new();
process_first->mount = vfs_mount_seed();
- process_first->id = next_pid++;
+ process_first->globalid = next_pid++;
+ process_first->cid = 1;
+ process_first->nextcid = 1;
process_first->_handles = kzalloc(sizeof(struct handle) * HANDLE_MAX);
// map .shared
@@ -68,7 +70,11 @@ struct process *process_fork(struct process *parent, int flags) {
child->parent = parent;
parent->child = child;
- child->id = next_pid++;
+ if (parent->nextcid == 0)
+ panic_unimplemented();
+ child->cid = parent->nextcid++;
+ child->nextcid = 1;
+ child->globalid = next_pid++;
if ((flags & FORK_NEWFS) == 0 && parent->controlled) {
child->controlled = parent->controlled;
diff --git a/src/kernel/proc.h b/src/kernel/proc.h
index 780c8ee..0ae811e 100644
--- a/src/kernel/proc.h
+++ b/src/kernel/proc.h
@@ -51,7 +51,9 @@ struct process {
struct handle **_handles; /* points to struct handle *[HANDLE_MAX] */
uint64_t *handles_refcount; /* works just like pages_refcount */
- uint32_t id; /* only for debugging, don't expose to userland */
+ uint32_t cid; /* child id. unique amongst all of this process' siblings */
+ uint32_t nextcid; /* the child id to assign to the next spawned child */
+ uint32_t globalid; /* only for debugging, don't expose to userland */
bool noreap;
/* allocated once, the requests from WAITS4FS get stored here */
diff --git a/src/kernel/syscalls.c b/src/kernel/syscalls.c
index 37a0ce3..62acf5f 100644
--- a/src/kernel/syscalls.c
+++ b/src/kernel/syscalls.c
@@ -76,7 +76,7 @@ long _syscall_fork(int flags, handle_t __user *fs_front) {
virt_cpy_to(process_current->pages, fs_front, &hid, sizeof hid);
}
}
- SYSCALL_RETURN(1);
+ SYSCALL_RETURN(child->cid);
}
handle_t _syscall_open(const char __user *path, long len, int flags) {
@@ -379,12 +379,13 @@ long _syscall_execbuf(void __user *ubuf, size_t len) {
}
void _syscall_debug_klog(const void __user *buf, size_t len) {
- (void)buf; (void)len;
- // static char kbuf[256];
- // if (len >= sizeof(kbuf)) len = sizeof(kbuf) - 1;
- // virt_cpy_from(process_current->pages, kbuf, buf, len);
- // kbuf[len] = '\0';
- // kprintf("[klog] %x\t%s\n", process_current->id, kbuf);
+ if (false) {
+ static char kbuf[256];
+ if (len >= sizeof(kbuf)) len = sizeof(kbuf) - 1;
+ virt_cpy_from(process_current->pages, kbuf, buf, len);
+ kbuf[len] = '\0';
+ kprintf("[klog] %x\t%s\n", process_current->globalid, kbuf);
+ }
}
long _syscall(long num, long a, long b, long c, long d, long e) {