summaryrefslogtreecommitdiff
path: root/userland
diff options
context:
space:
mode:
authorAnton Kling <anton@kling.gg>2024-04-02 09:17:06 +0200
committerAnton Kling <anton@kling.gg>2024-04-02 09:39:03 +0200
commit2229fd91f7230ae7068814ae029b733945852eb1 (patch)
tree416487f8c66c389c57dee465f648362ca59b8f23 /userland
parent7eceb43433634ee253507208baf1d8298b40e377 (diff)
Kernel: Fix some memory leaks
Diffstat (limited to 'userland')
-rw-r--r--userland/libc/Makefile2
-rw-r--r--userland/libc/fcntl/open_process.c6
-rw-r--r--userland/libc/include/fcntl.h1
-rw-r--r--userland/libc/include/signal.h2
-rw-r--r--userland/libc/include/syscall.h1
-rw-r--r--userland/libc/signal/kill.c4
-rw-r--r--userland/minibox/utilities/kill.c5
-rw-r--r--userland/sh/sh.c4
8 files changed, 20 insertions, 5 deletions
diff --git a/userland/libc/Makefile b/userland/libc/Makefile
index c818200..b1291fa 100644
--- a/userland/libc/Makefile
+++ b/userland/libc/Makefile
@@ -3,7 +3,7 @@ AR="i686-sb-ar"
AS="i686-sb-as"
#CFLAGS = -ggdb -ffreestanding -O2 -Wall -Wextra -pedantic -Wimplicit-fallthrough -I./include/ -static -I../../include/ -Wno-int-conversion -Wno-unused-parameter -Wno-return-type
CFLAGS = -ggdb -ffreestanding -Wall -Wextra -pedantic -Wimplicit-fallthrough -I./include/ -static -I../../include/ -Wno-int-conversion -Wno-unused-parameter -Wno-return-type
-OBJ=crt0.o libc.o malloc/malloc.o pty.o sys/mman/mmap.o sys/mman/munmap.o memset.o assert.o stdio/snprintf.o stdio/vfprintf.o string/memcpy.o string/memcmp.o string/strcmp.o ubsan.o string/strcpy.o isspace.o stdio/puts.o stdio/putchar.o dirent/opendir.o dirent/readdir.o dirent/closedir.o unistd/getopt.o dirent/scandir.o dirent/alphasort.o stdio/printf.o stdio/vdprintf.o stdio/vprintf.o stdio/dprintf.o stdio/vprintf.o string/strlen.o string/strnlen.o stdio/stdin.o stdio/getchar.o stdio/fgetc.o arpa/inet/htons.o arpa/inet/htonl.o stdio/fread.o stdio/fwrite.o stdio/fopen.o stdio/fclose.o stdio/fseek.o ctype/isascii.o stdio/fprintf.o stdlib/atoi.o stdlib/strtol.o ctype/toupper.o ctype/tolower.o string/strcat.o string/strchr.o string/sscanf.o sys/stat/stat.o stdlib/getenv.o string/strrchr.o stdio/ftell.o stdio/tmpfile.o stdio/fgets.o stdio/feof.o stdio/fscanf.o stdio/ungetc.o string/strncmp.o stdio/fputc.o string/strncpy.o stdio/remove.o stdio/ferror.o stdio/fputs.o stdlib/rand.o stdlib/srand.o unistd/getpid.o stdlib/strtoul.o stdio/fflush.o stdlib/abort.o string/strcspn.o time/localtime.o time/time.o time/clock_gettime.o time/gmtime.o time/strftime.o string/strpbrk.o ctype/isdigit.o ctype/isalpha.o ctype/isxdigit.o ctype/ispunct.o stdio/setvbuf.o stdio/fileno.o stdio/putc.o stdio/sprintf.o stdlib/abs.o string/strspn.o stdlib/qsort.o string/memmove.o setjmp/longjmp.o setjmp/setjmp.o libgen/basename.o string/strdup.o string/strndup.o string/strlcpy.o stdlib/atexit.o stdio/open_memstream.o libgen/dirname.o unistd/unlink.o string/strstr.o string/strcasecmp.o string/strncasecmp.o stdlib/mkstemp.o string/strtok.o unistd/execvp.o unistd/_exit.o ctype/isalnum.o time/ctime_r.o stdlib/strtold.o sys/time/gettimeofday.o stdio/fgetpos.o stdio/fsetpos.o ctype/isprint.o stdlib/system.o stdio/tmpnam.o unistd/msleep.o stdlib/atof.o stdlib/strtod.o stdio/rename.o sys/stat/mkdir.o unistd/uptime.o unistd/ftruncate.o sys/socket/recvfrom.o sys/socket/sendto.o signal/kill.o signal/sigaction.o unistd/chdir.o unistd/getcwd.o stdio/getdelim.o stdio/getline.o unistd/isatty.o sys/socket/listen.o stdlib/realpath.o systemcall.o sys/random/randomfill.o fcntl/open.o unistd/write.o unistd/pwrite.o
+OBJ=crt0.o libc.o malloc/malloc.o pty.o sys/mman/mmap.o sys/mman/munmap.o memset.o assert.o stdio/snprintf.o stdio/vfprintf.o string/memcpy.o string/memcmp.o string/strcmp.o ubsan.o string/strcpy.o isspace.o stdio/puts.o stdio/putchar.o dirent/opendir.o dirent/readdir.o dirent/closedir.o unistd/getopt.o dirent/scandir.o dirent/alphasort.o stdio/printf.o stdio/vdprintf.o stdio/vprintf.o stdio/dprintf.o stdio/vprintf.o string/strlen.o string/strnlen.o stdio/stdin.o stdio/getchar.o stdio/fgetc.o arpa/inet/htons.o arpa/inet/htonl.o stdio/fread.o stdio/fwrite.o stdio/fopen.o stdio/fclose.o stdio/fseek.o ctype/isascii.o stdio/fprintf.o stdlib/atoi.o stdlib/strtol.o ctype/toupper.o ctype/tolower.o string/strcat.o string/strchr.o string/sscanf.o sys/stat/stat.o stdlib/getenv.o string/strrchr.o stdio/ftell.o stdio/tmpfile.o stdio/fgets.o stdio/feof.o stdio/fscanf.o stdio/ungetc.o string/strncmp.o stdio/fputc.o string/strncpy.o stdio/remove.o stdio/ferror.o stdio/fputs.o stdlib/rand.o stdlib/srand.o unistd/getpid.o stdlib/strtoul.o stdio/fflush.o stdlib/abort.o string/strcspn.o time/localtime.o time/time.o time/clock_gettime.o time/gmtime.o time/strftime.o string/strpbrk.o ctype/isdigit.o ctype/isalpha.o ctype/isxdigit.o ctype/ispunct.o stdio/setvbuf.o stdio/fileno.o stdio/putc.o stdio/sprintf.o stdlib/abs.o string/strspn.o stdlib/qsort.o string/memmove.o setjmp/longjmp.o setjmp/setjmp.o libgen/basename.o string/strdup.o string/strndup.o string/strlcpy.o stdlib/atexit.o stdio/open_memstream.o libgen/dirname.o unistd/unlink.o string/strstr.o string/strcasecmp.o string/strncasecmp.o stdlib/mkstemp.o string/strtok.o unistd/execvp.o unistd/_exit.o ctype/isalnum.o time/ctime_r.o stdlib/strtold.o sys/time/gettimeofday.o stdio/fgetpos.o stdio/fsetpos.o ctype/isprint.o stdlib/system.o stdio/tmpnam.o unistd/msleep.o stdlib/atof.o stdlib/strtod.o stdio/rename.o sys/stat/mkdir.o unistd/uptime.o unistd/ftruncate.o sys/socket/recvfrom.o sys/socket/sendto.o signal/kill.o signal/sigaction.o unistd/chdir.o unistd/getcwd.o stdio/getdelim.o stdio/getline.o unistd/isatty.o sys/socket/listen.o stdlib/realpath.o systemcall.o sys/random/randomfill.o fcntl/open.o unistd/write.o unistd/pwrite.o fcntl/open_process.o
all: libc.a
%.o: %.c
diff --git a/userland/libc/fcntl/open_process.c b/userland/libc/fcntl/open_process.c
new file mode 100644
index 0000000..8486728
--- /dev/null
+++ b/userland/libc/fcntl/open_process.c
@@ -0,0 +1,6 @@
+#include <fcntl.h>
+#include <syscall.h>
+
+int open_process(int pid) {
+ RC_ERRNO(syscall(SYS_OPEN_PROCESS, pid, 0, 0, 0, 0));
+}
diff --git a/userland/libc/include/fcntl.h b/userland/libc/include/fcntl.h
index 29134be..57c968a 100644
--- a/userland/libc/include/fcntl.h
+++ b/userland/libc/include/fcntl.h
@@ -11,3 +11,4 @@
#define O_RDWR (O_WRITE | O_READ)
int open(const char *file, int flags, ...);
+int open_process(int pid);
diff --git a/userland/libc/include/signal.h b/userland/libc/include/signal.h
index 2be081c..a241015 100644
--- a/userland/libc/include/signal.h
+++ b/userland/libc/include/signal.h
@@ -37,7 +37,7 @@ struct siginfo {
typedef struct siginfo siginfo_t;
-int kill(pid_t pid, int sig);
+int kill(int fd, int sig);
struct sigaction {
void (*sa_handler)(int); // Pointer to a signal-catching function or one of
diff --git a/userland/libc/include/syscall.h b/userland/libc/include/syscall.h
index e375079..c5fe3e4 100644
--- a/userland/libc/include/syscall.h
+++ b/userland/libc/include/syscall.h
@@ -61,6 +61,7 @@
#define SYS_QUEUE_ADD 50
#define SYS_QUEUE_WAIT 51
#define SYS_MUNMAP 52
+#define SYS_OPEN_PROCESS 53
int syscall(uint32_t eax, uint32_t ebx, uint32_t ecx, uint32_t edx,
uint32_t esi, uint32_t edi);
diff --git a/userland/libc/signal/kill.c b/userland/libc/signal/kill.c
index 3351baa..c5ed62b 100644
--- a/userland/libc/signal/kill.c
+++ b/userland/libc/signal/kill.c
@@ -1,4 +1,6 @@
#include <signal.h>
#include <syscall.h>
-int kill(pid_t pid, int sig) { RC_ERRNO(syscall(SYS_KILL, pid, sig, 0, 0, 0)) }
+int kill(int fd, int sig) {
+ RC_ERRNO(syscall(SYS_KILL, fd, sig, 0, 0, 0))
+}
diff --git a/userland/minibox/utilities/kill.c b/userland/minibox/utilities/kill.c
index 2888b3b..8cc6877 100644
--- a/userland/minibox/utilities/kill.c
+++ b/userland/minibox/utilities/kill.c
@@ -1,9 +1,12 @@
// kill
#include "include.h"
+#include <fcntl.h>
#include <signal.h>
#include <stdio.h>
int kill_main(int argc, char **argv) {
- kill(4, SIGTERM);
+ int fd = open_process(4);
+ kill(fd, SIGTERM);
+ close(fd);
return 0;
}
diff --git a/userland/sh/sh.c b/userland/sh/sh.c
index e7741aa..e386ef6 100644
--- a/userland/sh/sh.c
+++ b/userland/sh/sh.c
@@ -49,7 +49,9 @@ void remove_child_process(int pid) {
void slaugther_children(void) {
struct child_process *child = children;
for (; child; child = child->next) {
- kill(child->pid, SIGTERM);
+ int fd = open_process(child->pid);
+ kill(fd, SIGTERM);
+ close(fd);
}
}