Jelajahi Sumber

Add fcntl() F_DUPFD which is slightly different from dup2().

Andreas Kling 6 tahun lalu
induk
melakukan
2cf477a151
3 mengubah file dengan 22 tambahan dan 0 penghapusan
  1. 16 0
      Kernel/Process.cpp
  2. 5 0
      Kernel/sync.sh
  3. 1 0
      LibC/stdlib.cpp

+ 16 - 0
Kernel/Process.cpp

@@ -1090,6 +1090,22 @@ int Process::sys$fcntl(int fd, int cmd, dword arg)
     // NOTE: The FD flags are not shared between FileDescriptor objects.
     //       This means that dup() doesn't copy the FD_CLOEXEC flag!
     switch (cmd) {
+    case F_DUPFD: {
+        int arg_fd = (int)arg;
+        if (arg_fd < 0)
+            return -EINVAL;
+        int new_fd = -1;
+        for (int i = arg_fd; i < (int)m_max_open_file_descriptors; ++i) {
+            if (!m_fds[i]) {
+                new_fd = i;
+                break;
+            }
+        }
+        if (new_fd == -1)
+            return -EMFILE;
+        m_fds[new_fd].set(descriptor);
+        break;
+    }
     case F_GETFD:
         return m_fds[fd].flags;
     case F_SETFD:

+ 5 - 0
Kernel/sync.sh

@@ -3,6 +3,11 @@ rm -vf _fs_contents
 cp -vp _fs_contents.stock _fs_contents
 mkdir -vp mnt
 mount -o loop _fs_contents mnt/
+mkdir -vp mnt/dev
+mknod mnt/dev/tty0 c 4 0
+mknod mnt/dev/tty1 c 4 1
+mknod mnt/dev/tty2 c 4 2
+mknod mnt/dev/tty3 c 4 3
 cp -R ../Base/* mnt/
 cp -v ../Userland/sh mnt/bin/sh
 cp -v ../Userland/id mnt/bin/id

+ 1 - 0
LibC/stdlib.cpp

@@ -29,6 +29,7 @@ void __malloc_init()
 void* malloc(size_t size)
 {
     if ((nextptr + size) > endptr) {
+        fprintf(stderr, "Unable to serve malloc() request with size %u\n", size);
         volatile char* crashme = (char*)0xc007d00d;
         *crashme = 0;
     }