2018-10-16 12:01:38 +03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "types.h"
|
|
|
|
#include "TSS.h"
|
|
|
|
#include "i386.h"
|
2018-10-30 15:59:29 +03:00
|
|
|
#include "TTY.h"
|
2018-11-08 13:37:01 +03:00
|
|
|
#include "Syscall.h"
|
2019-01-13 03:59:38 +03:00
|
|
|
#include "GUITypes.h"
|
2018-12-03 03:18:54 +03:00
|
|
|
#include <VirtualFileSystem/VirtualFileSystem.h>
|
|
|
|
#include <VirtualFileSystem/UnixTypes.h>
|
|
|
|
#include <AK/InlineLinkedList.h>
|
2018-12-04 02:27:16 +03:00
|
|
|
#include <AK/AKString.h>
|
2018-12-03 03:18:54 +03:00
|
|
|
#include <AK/Vector.h>
|
2019-01-13 07:03:17 +03:00
|
|
|
#include <AK/WeakPtr.h>
|
2019-01-14 16:21:51 +03:00
|
|
|
#include <AK/Lock.h>
|
2018-10-16 12:01:38 +03:00
|
|
|
|
2018-11-07 13:37:54 +03:00
|
|
|
class FileDescriptor;
|
2018-11-02 01:04:34 +03:00
|
|
|
class PageDirectory;
|
2018-11-01 15:21:02 +03:00
|
|
|
class Region;
|
2018-11-08 23:20:09 +03:00
|
|
|
class VMObject;
|
2018-10-18 14:05:00 +03:00
|
|
|
class Zone;
|
2019-01-13 03:59:38 +03:00
|
|
|
class Window;
|
2019-01-13 07:03:17 +03:00
|
|
|
class Widget;
|
2018-10-16 12:01:38 +03:00
|
|
|
|
2018-11-08 00:15:02 +03:00
|
|
|
#define COOL_GLOBALS
|
|
|
|
#ifdef COOL_GLOBALS
|
|
|
|
struct CoolGlobals {
|
|
|
|
pid_t current_pid;
|
|
|
|
};
|
|
|
|
extern CoolGlobals* g_cool_globals;
|
|
|
|
#endif
|
|
|
|
|
2018-11-06 12:46:40 +03:00
|
|
|
struct SignalActionData {
|
|
|
|
LinearAddress handler_or_sigaction;
|
|
|
|
dword mask { 0 };
|
|
|
|
int flags { 0 };
|
|
|
|
LinearAddress restorer;
|
|
|
|
};
|
|
|
|
|
2019-01-09 04:29:11 +03:00
|
|
|
struct DisplayInfo {
|
|
|
|
unsigned width;
|
|
|
|
unsigned height;
|
|
|
|
unsigned bpp;
|
|
|
|
unsigned pitch;
|
|
|
|
byte* framebuffer;
|
|
|
|
};
|
|
|
|
|
2018-11-01 15:15:46 +03:00
|
|
|
class Process : public InlineLinkedListNode<Process> {
|
|
|
|
friend class InlineLinkedListNode<Process>;
|
2019-01-12 08:39:34 +03:00
|
|
|
friend class WindowManager; // FIXME: Make a better API for allocate_region().
|
2019-01-13 02:27:25 +03:00
|
|
|
friend class GraphicsBitmap; // FIXME: Make a better API for allocate_region().
|
2018-10-16 12:01:38 +03:00
|
|
|
public:
|
2018-12-25 01:10:48 +03:00
|
|
|
static Process* create_kernel_process(String&& name, void (*entry)());
|
2018-11-06 15:33:06 +03:00
|
|
|
static Process* create_user_process(const String& path, uid_t, gid_t, pid_t ppid, int& error, Vector<String>&& arguments = Vector<String>(), Vector<String>&& environment = Vector<String>(), TTY* = nullptr);
|
2018-11-01 15:15:46 +03:00
|
|
|
~Process();
|
2018-10-23 13:44:46 +03:00
|
|
|
|
2018-11-01 15:15:46 +03:00
|
|
|
static Vector<Process*> allProcesses();
|
2018-10-16 12:01:38 +03:00
|
|
|
|
|
|
|
enum State {
|
|
|
|
Invalid = 0,
|
2018-11-07 20:30:59 +03:00
|
|
|
Runnable,
|
|
|
|
Running,
|
2018-11-08 01:21:32 +03:00
|
|
|
Skip1SchedulerPass,
|
|
|
|
Skip0SchedulerPasses,
|
2018-11-07 20:30:59 +03:00
|
|
|
Dead,
|
|
|
|
BeingInspected,
|
|
|
|
BlockedSleep,
|
|
|
|
BlockedWait,
|
|
|
|
BlockedRead,
|
2018-11-12 03:28:46 +03:00
|
|
|
BlockedWrite,
|
2018-11-10 04:43:33 +03:00
|
|
|
BlockedSignal,
|
2019-01-16 01:12:20 +03:00
|
|
|
BlockedSelect,
|
2018-10-16 12:01:38 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
enum RingLevel {
|
|
|
|
Ring0 = 0,
|
|
|
|
Ring3 = 3,
|
|
|
|
};
|
|
|
|
|
2018-10-18 01:12:52 +03:00
|
|
|
bool isRing0() const { return m_ring == Ring0; }
|
2018-10-25 12:15:17 +03:00
|
|
|
bool isRing3() const { return m_ring == Ring3; }
|
2018-10-18 01:12:52 +03:00
|
|
|
|
2018-11-07 23:19:47 +03:00
|
|
|
bool is_blocked() const
|
|
|
|
{
|
2019-01-16 01:12:20 +03:00
|
|
|
return m_state == BlockedSleep || m_state == BlockedWait || m_state == BlockedRead || m_state == BlockedSignal || m_state == BlockedSelect;
|
2018-11-07 23:19:47 +03:00
|
|
|
}
|
|
|
|
|
2018-11-09 03:25:31 +03:00
|
|
|
PageDirectory& page_directory() { return *m_page_directory; }
|
|
|
|
const PageDirectory& page_directory() const { return *m_page_directory; }
|
|
|
|
|
2018-11-07 23:19:47 +03:00
|
|
|
bool in_kernel() const { return (m_tss.cs & 0x03) == 0; }
|
|
|
|
|
2018-11-07 23:38:18 +03:00
|
|
|
static Process* from_pid(pid_t);
|
2018-10-16 12:01:38 +03:00
|
|
|
|
|
|
|
const String& name() const { return m_name; }
|
|
|
|
pid_t pid() const { return m_pid; }
|
2018-11-02 14:56:51 +03:00
|
|
|
pid_t sid() const { return m_sid; }
|
|
|
|
pid_t pgid() const { return m_pgid; }
|
2018-11-17 02:11:08 +03:00
|
|
|
dword ticks() const { return m_ticks; }
|
|
|
|
word selector() const { return m_farPtr.selector; }
|
2018-10-16 12:01:38 +03:00
|
|
|
TSS32& tss() { return m_tss; }
|
|
|
|
State state() const { return m_state; }
|
2018-10-23 13:44:46 +03:00
|
|
|
uid_t uid() const { return m_uid; }
|
2018-11-05 17:04:19 +03:00
|
|
|
gid_t gid() const { return m_gid; }
|
|
|
|
uid_t euid() const { return m_euid; }
|
|
|
|
gid_t egid() const { return m_egid; }
|
2018-11-06 15:33:06 +03:00
|
|
|
pid_t ppid() const { return m_ppid; }
|
2018-10-25 11:15:13 +03:00
|
|
|
|
2018-10-16 12:06:35 +03:00
|
|
|
const FarPtr& farPtr() const { return m_farPtr; }
|
|
|
|
|
2018-11-07 13:37:54 +03:00
|
|
|
FileDescriptor* file_descriptor(int fd);
|
|
|
|
const FileDescriptor* file_descriptor(int fd) const;
|
2018-10-16 12:01:38 +03:00
|
|
|
|
2018-11-01 15:15:46 +03:00
|
|
|
void block(Process::State);
|
2018-10-16 12:01:38 +03:00
|
|
|
void unblock();
|
|
|
|
|
2018-11-17 02:11:08 +03:00
|
|
|
void setWakeupTime(dword t) { m_wakeupTime = t; }
|
|
|
|
dword wakeupTime() const { return m_wakeupTime; }
|
2018-10-16 12:01:38 +03:00
|
|
|
|
2018-11-08 18:09:05 +03:00
|
|
|
template<typename Callback> static void for_each(Callback);
|
|
|
|
template<typename Callback> static void for_each_in_pgrp(pid_t, Callback);
|
|
|
|
template<typename Callback> static void for_each_in_state(State, Callback);
|
|
|
|
template<typename Callback> static void for_each_not_in_state(State, Callback);
|
2018-11-11 17:36:40 +03:00
|
|
|
template<typename Callback> void for_each_child(Callback);
|
2018-11-02 16:06:48 +03:00
|
|
|
|
2018-10-16 12:01:38 +03:00
|
|
|
bool tick() { ++m_ticks; return --m_ticksLeft; }
|
2018-11-08 00:15:02 +03:00
|
|
|
void set_ticks_left(dword t) { m_ticksLeft = t; }
|
2018-10-16 12:01:38 +03:00
|
|
|
|
2018-11-17 02:11:08 +03:00
|
|
|
void setSelector(word s) { m_farPtr.selector = s; }
|
2018-11-01 16:21:02 +03:00
|
|
|
void set_state(State s) { m_state = s; }
|
2018-10-16 12:01:38 +03:00
|
|
|
|
2018-11-02 14:56:51 +03:00
|
|
|
pid_t sys$setsid();
|
|
|
|
pid_t sys$getsid(pid_t);
|
|
|
|
int sys$setpgid(pid_t pid, pid_t pgid);
|
|
|
|
pid_t sys$getpgrp();
|
|
|
|
pid_t sys$getpgid(pid_t);
|
2018-10-16 12:01:38 +03:00
|
|
|
uid_t sys$getuid();
|
2018-10-22 14:55:11 +03:00
|
|
|
gid_t sys$getgid();
|
2018-11-05 17:04:19 +03:00
|
|
|
uid_t sys$geteuid();
|
|
|
|
gid_t sys$getegid();
|
2018-10-22 14:55:11 +03:00
|
|
|
pid_t sys$getpid();
|
2018-11-06 15:33:06 +03:00
|
|
|
pid_t sys$getppid();
|
2018-11-06 15:40:23 +03:00
|
|
|
mode_t sys$umask(mode_t);
|
2018-10-28 16:11:51 +03:00
|
|
|
int sys$open(const char* path, int options);
|
2018-10-16 12:01:38 +03:00
|
|
|
int sys$close(int fd);
|
2018-10-30 17:33:37 +03:00
|
|
|
ssize_t sys$read(int fd, void* outbuf, size_t nread);
|
|
|
|
ssize_t sys$write(int fd, const void*, size_t);
|
2018-11-11 02:20:53 +03:00
|
|
|
int sys$fstat(int fd, Unix::stat*);
|
2018-10-27 01:29:31 +03:00
|
|
|
int sys$lstat(const char*, Unix::stat*);
|
2018-10-31 12:14:56 +03:00
|
|
|
int sys$stat(const char*, Unix::stat*);
|
2018-10-31 19:50:43 +03:00
|
|
|
int sys$lseek(int fd, off_t, int whence);
|
2018-10-16 12:01:38 +03:00
|
|
|
int sys$kill(pid_t pid, int sig);
|
|
|
|
int sys$geterror() { return m_error; }
|
2018-11-08 00:15:02 +03:00
|
|
|
void sys$exit(int status) NORETURN;
|
|
|
|
void sys$sigreturn() NORETURN;
|
2018-10-27 02:24:22 +03:00
|
|
|
pid_t sys$waitpid(pid_t, int* wstatus, int options);
|
2018-11-08 13:37:01 +03:00
|
|
|
void* sys$mmap(const Syscall::SC_mmap_params*);
|
2018-10-24 10:48:24 +03:00
|
|
|
int sys$munmap(void*, size_t size);
|
2018-10-28 11:57:22 +03:00
|
|
|
int sys$set_mmap_name(void*, size_t, const char*);
|
2019-01-16 01:12:20 +03:00
|
|
|
int sys$select(const Syscall::SC_select_params*);
|
2018-12-03 01:34:50 +03:00
|
|
|
ssize_t sys$get_dir_entries(int fd, void*, size_t);
|
2018-10-24 15:28:22 +03:00
|
|
|
int sys$getcwd(char*, size_t);
|
2018-10-26 15:24:11 +03:00
|
|
|
int sys$chdir(const char*);
|
2018-10-25 14:53:49 +03:00
|
|
|
int sys$sleep(unsigned seconds);
|
2018-10-25 18:29:49 +03:00
|
|
|
int sys$gettimeofday(timeval*);
|
2018-10-26 10:54:29 +03:00
|
|
|
int sys$gethostname(char* name, size_t length);
|
2018-10-26 12:16:56 +03:00
|
|
|
int sys$get_arguments(int* argc, char*** argv);
|
2018-10-31 19:50:43 +03:00
|
|
|
int sys$get_environment(char*** environ);
|
2018-10-26 15:56:21 +03:00
|
|
|
int sys$uname(utsname*);
|
2018-10-28 16:11:51 +03:00
|
|
|
int sys$readlink(const char*, char*, size_t);
|
2018-10-31 00:03:02 +03:00
|
|
|
int sys$ttyname_r(int fd, char*, size_t);
|
2019-01-15 08:30:19 +03:00
|
|
|
int sys$ptsname_r(int fd, char*, size_t);
|
2018-11-02 22:41:58 +03:00
|
|
|
pid_t sys$fork(RegisterDump&);
|
2018-11-03 03:49:40 +03:00
|
|
|
int sys$execve(const char* filename, const char** argv, const char** envp);
|
2018-11-05 20:16:00 +03:00
|
|
|
int sys$isatty(int fd);
|
2018-11-05 21:01:22 +03:00
|
|
|
int sys$getdtablesize();
|
|
|
|
int sys$dup(int oldfd);
|
|
|
|
int sys$dup2(int oldfd, int newfd);
|
2018-11-06 12:46:40 +03:00
|
|
|
int sys$sigaction(int signum, const Unix::sigaction* act, Unix::sigaction* old_act);
|
2018-11-11 01:29:07 +03:00
|
|
|
int sys$sigprocmask(int how, const Unix::sigset_t* set, Unix::sigset_t* old_set);
|
|
|
|
int sys$sigpending(Unix::sigset_t*);
|
2018-11-07 03:38:51 +03:00
|
|
|
int sys$getgroups(int size, gid_t*);
|
|
|
|
int sys$setgroups(size_t, const gid_t*);
|
2018-11-11 02:20:53 +03:00
|
|
|
int sys$pipe(int* pipefd);
|
|
|
|
int sys$killpg(int pgrp, int sig);
|
|
|
|
int sys$setgid(gid_t);
|
|
|
|
int sys$setuid(uid_t);
|
|
|
|
unsigned sys$alarm(unsigned seconds);
|
|
|
|
int sys$access(const char* pathname, int mode);
|
2018-11-11 12:38:33 +03:00
|
|
|
int sys$fcntl(int fd, int cmd, dword extra_arg);
|
2018-11-16 15:11:21 +03:00
|
|
|
int sys$ioctl(int fd, unsigned request, unsigned arg);
|
2018-11-18 16:57:41 +03:00
|
|
|
int sys$mkdir(const char* pathname, mode_t mode);
|
2018-12-03 03:12:26 +03:00
|
|
|
Unix::clock_t sys$times(Unix::tms*);
|
2018-12-19 23:14:55 +03:00
|
|
|
int sys$utime(const char* pathname, const struct Unix::utimbuf*);
|
2018-10-16 12:01:38 +03:00
|
|
|
|
2019-01-13 03:59:38 +03:00
|
|
|
int gui$create_window(const GUI_CreateWindowParameters*);
|
|
|
|
int gui$destroy_window(int window_id);
|
2019-01-14 17:25:34 +03:00
|
|
|
int gui$get_window_backing_store(int window_id, GUI_WindowBackingStoreInfo*);
|
|
|
|
int gui$invalidate_window(int window_id);
|
2019-01-13 03:59:38 +03:00
|
|
|
|
2019-01-09 04:29:11 +03:00
|
|
|
DisplayInfo get_display_info();
|
|
|
|
|
2018-10-16 12:01:38 +03:00
|
|
|
static void initialize();
|
2019-01-13 03:59:38 +03:00
|
|
|
static void initialize_gui_statics();
|
2019-01-14 16:21:51 +03:00
|
|
|
int make_window_id();
|
2018-10-16 12:01:38 +03:00
|
|
|
|
2018-11-08 00:15:02 +03:00
|
|
|
void crash() NORETURN;
|
2018-11-29 00:01:24 +03:00
|
|
|
static int reap(Process&) WARN_UNUSED_RESULT;
|
2018-10-18 01:26:30 +03:00
|
|
|
|
2018-10-30 17:33:37 +03:00
|
|
|
const TTY* tty() const { return m_tty; }
|
2019-01-15 10:49:24 +03:00
|
|
|
void set_tty(TTY* tty) { m_tty = tty; }
|
2018-10-30 17:33:37 +03:00
|
|
|
|
2018-10-26 18:42:12 +03:00
|
|
|
size_t regionCount() const { return m_regions.size(); }
|
2018-10-27 15:56:52 +03:00
|
|
|
const Vector<RetainPtr<Region>>& regions() const { return m_regions; }
|
2018-10-18 15:53:00 +03:00
|
|
|
void dumpRegions();
|
|
|
|
|
2018-11-08 00:15:02 +03:00
|
|
|
void did_schedule() { ++m_timesScheduled; }
|
2018-10-22 12:15:16 +03:00
|
|
|
dword timesScheduled() const { return m_timesScheduled; }
|
|
|
|
|
2018-12-03 03:12:26 +03:00
|
|
|
dword m_ticks_in_user { 0 };
|
|
|
|
dword m_ticks_in_kernel { 0 };
|
|
|
|
|
|
|
|
dword m_ticks_in_user_for_dead_children { 0 };
|
|
|
|
dword m_ticks_in_kernel_for_dead_children { 0 };
|
|
|
|
|
2018-11-29 01:30:06 +03:00
|
|
|
pid_t waitee_pid() const { return m_waitee_pid; }
|
2018-10-24 01:20:34 +03:00
|
|
|
|
2018-10-27 01:14:24 +03:00
|
|
|
dword framePtr() const { return m_tss.ebp; }
|
2018-10-26 23:32:35 +03:00
|
|
|
dword stackPtr() const { return m_tss.esp; }
|
|
|
|
dword stackTop() const { return m_tss.ss == 0x10 ? m_stackTop0 : m_stackTop3; }
|
|
|
|
|
2019-01-01 04:20:01 +03:00
|
|
|
bool validate_read_from_kernel(LinearAddress) const;
|
2018-10-27 01:14:24 +03:00
|
|
|
|
2018-11-16 18:10:59 +03:00
|
|
|
bool validate_read(const void*, size_t) const;
|
2018-11-16 17:41:48 +03:00
|
|
|
bool validate_write(void*, size_t) const;
|
2018-11-16 18:23:39 +03:00
|
|
|
bool validate_read_str(const char* str) { return validate_read(str, strlen(str) + 1); }
|
|
|
|
template<typename T> bool validate_read_typed(T* value, size_t count = 1) { return validate_read(value, sizeof(T) * count); }
|
|
|
|
template<typename T> bool validate_write_typed(T* value, size_t count = 1) { return validate_write(value, sizeof(T) * count); }
|
2018-11-16 17:41:48 +03:00
|
|
|
|
2019-01-16 14:57:07 +03:00
|
|
|
Inode* cwd_inode() { return m_cwd.ptr(); }
|
|
|
|
Inode* executable_inode() { return m_executable.ptr(); }
|
2018-10-28 14:20:25 +03:00
|
|
|
|
2018-11-01 15:39:28 +03:00
|
|
|
size_t number_of_open_file_descriptors() const;
|
2018-11-01 16:00:28 +03:00
|
|
|
size_t max_open_file_descriptors() const { return m_max_open_file_descriptors; }
|
2018-11-01 15:39:28 +03:00
|
|
|
|
2018-11-07 20:30:59 +03:00
|
|
|
void send_signal(byte signal, Process* sender);
|
2018-11-16 23:14:25 +03:00
|
|
|
bool dispatch_one_pending_signal();
|
|
|
|
bool dispatch_signal(byte signal);
|
2018-11-07 20:30:59 +03:00
|
|
|
bool has_unmasked_pending_signals() const;
|
|
|
|
void terminate_due_to_signal(byte signal);
|
2018-11-02 16:06:48 +03:00
|
|
|
|
2018-11-02 22:41:58 +03:00
|
|
|
Process* fork(RegisterDump&);
|
2018-11-03 12:20:23 +03:00
|
|
|
int exec(const String& path, Vector<String>&& arguments, Vector<String>&& environment);
|
2018-11-02 22:41:58 +03:00
|
|
|
|
2018-11-07 03:38:51 +03:00
|
|
|
bool is_root() const { return m_euid == 0; }
|
|
|
|
|
2019-01-14 16:21:51 +03:00
|
|
|
Vector<GUI_Event>& gui_events() { return m_gui_events; }
|
|
|
|
SpinLock& gui_events_lock() { return m_gui_events_lock; }
|
|
|
|
|
2018-10-16 12:01:38 +03:00
|
|
|
private:
|
2018-10-18 14:05:00 +03:00
|
|
|
friend class MemoryManager;
|
2018-11-08 00:15:02 +03:00
|
|
|
friend class Scheduler;
|
2018-11-08 16:35:30 +03:00
|
|
|
friend class Region;
|
2018-10-18 14:05:00 +03:00
|
|
|
|
2019-01-16 14:57:07 +03:00
|
|
|
Process(String&& name, uid_t, gid_t, pid_t ppid, RingLevel, RetainPtr<Inode>&& cwd = nullptr, RetainPtr<Inode>&& executable = nullptr, TTY* = nullptr, Process* fork_parent = nullptr);
|
2018-10-25 12:15:17 +03:00
|
|
|
|
2018-11-09 19:59:14 +03:00
|
|
|
int do_exec(const String& path, Vector<String>&& arguments, Vector<String>&& environment);
|
2018-11-06 12:46:40 +03:00
|
|
|
void push_value_on_stack(dword);
|
2018-10-16 12:01:38 +03:00
|
|
|
|
2018-11-12 03:28:46 +03:00
|
|
|
int alloc_fd();
|
|
|
|
|
2018-12-31 16:58:03 +03:00
|
|
|
OwnPtr<PageDirectory> m_page_directory;
|
2018-11-01 11:01:51 +03:00
|
|
|
|
2018-11-01 15:15:46 +03:00
|
|
|
Process* m_prev { nullptr };
|
|
|
|
Process* m_next { nullptr };
|
2018-10-16 12:01:38 +03:00
|
|
|
|
|
|
|
String m_name;
|
|
|
|
void (*m_entry)() { nullptr };
|
|
|
|
pid_t m_pid { 0 };
|
|
|
|
uid_t m_uid { 0 };
|
2018-10-22 14:55:11 +03:00
|
|
|
gid_t m_gid { 0 };
|
2018-11-05 17:04:19 +03:00
|
|
|
uid_t m_euid { 0 };
|
|
|
|
gid_t m_egid { 0 };
|
2018-11-02 14:56:51 +03:00
|
|
|
pid_t m_sid { 0 };
|
|
|
|
pid_t m_pgid { 0 };
|
2018-11-17 02:11:08 +03:00
|
|
|
dword m_ticks { 0 };
|
|
|
|
dword m_ticksLeft { 0 };
|
|
|
|
dword m_stackTop0 { 0 };
|
|
|
|
dword m_stackTop3 { 0 };
|
2018-10-16 12:06:35 +03:00
|
|
|
FarPtr m_farPtr;
|
2018-10-16 12:01:38 +03:00
|
|
|
State m_state { Invalid };
|
2018-11-17 02:11:08 +03:00
|
|
|
dword m_wakeupTime { 0 };
|
2018-10-16 12:01:38 +03:00
|
|
|
TSS32 m_tss;
|
2018-11-07 23:19:47 +03:00
|
|
|
TSS32 m_tss_to_resume_kernel;
|
2018-11-13 03:36:31 +03:00
|
|
|
struct FileDescriptorAndFlags {
|
|
|
|
operator bool() const { return !!descriptor; }
|
|
|
|
void clear() { descriptor = nullptr; flags = 0; }
|
|
|
|
void set(RetainPtr<FileDescriptor>&& d, dword f = 0) { descriptor = move(d), flags = f; }
|
|
|
|
RetainPtr<FileDescriptor> descriptor;
|
|
|
|
dword flags { 0 };
|
|
|
|
};
|
|
|
|
Vector<FileDescriptorAndFlags> m_fds;
|
2018-10-16 12:01:38 +03:00
|
|
|
RingLevel m_ring { Ring0 };
|
|
|
|
int m_error { 0 };
|
2018-10-18 15:53:00 +03:00
|
|
|
void* m_kernelStack { nullptr };
|
2018-10-22 12:15:16 +03:00
|
|
|
dword m_timesScheduled { 0 };
|
2018-11-29 01:30:06 +03:00
|
|
|
pid_t m_waitee_pid { -1 };
|
2018-11-12 03:28:46 +03:00
|
|
|
int m_blocked_fd { -1 };
|
2019-01-16 01:12:20 +03:00
|
|
|
Vector<int> m_select_read_fds;
|
|
|
|
Vector<int> m_select_write_fds;
|
2018-11-01 15:39:28 +03:00
|
|
|
size_t m_max_open_file_descriptors { 16 };
|
2018-11-06 12:46:40 +03:00
|
|
|
SignalActionData m_signal_action_data[32];
|
2018-11-07 20:30:59 +03:00
|
|
|
dword m_pending_signals { 0 };
|
2018-11-11 01:29:07 +03:00
|
|
|
dword m_signal_mask { 0xffffffff };
|
2018-11-07 20:30:59 +03:00
|
|
|
|
|
|
|
byte m_termination_status { 0 };
|
|
|
|
byte m_termination_signal { 0 };
|
2018-10-18 14:05:00 +03:00
|
|
|
|
2019-01-16 14:57:07 +03:00
|
|
|
RetainPtr<Inode> m_cwd;
|
|
|
|
RetainPtr<Inode> m_executable;
|
2018-10-24 15:28:22 +03:00
|
|
|
|
2018-10-30 15:59:29 +03:00
|
|
|
TTY* m_tty { nullptr };
|
|
|
|
|
2018-11-19 04:17:20 +03:00
|
|
|
Region* allocate_region(LinearAddress, size_t, String&& name, bool is_readable = true, bool is_writable = true, bool commit = true);
|
2019-01-16 14:57:07 +03:00
|
|
|
Region* allocate_file_backed_region(LinearAddress, size_t, RetainPtr<Inode>&&, String&& name, bool is_readable, bool is_writable);
|
2018-11-08 23:20:09 +03:00
|
|
|
Region* allocate_region_with_vmo(LinearAddress, size_t, RetainPtr<VMObject>&&, size_t offset_in_vmo, String&& name, bool is_readable, bool is_writable);
|
2018-11-03 13:28:23 +03:00
|
|
|
bool deallocate_region(Region& region);
|
2018-10-24 10:48:24 +03:00
|
|
|
|
|
|
|
Region* regionFromRange(LinearAddress, size_t);
|
2018-10-18 15:53:00 +03:00
|
|
|
|
2018-10-27 15:56:52 +03:00
|
|
|
Vector<RetainPtr<Region>> m_regions;
|
2018-10-18 14:05:00 +03:00
|
|
|
|
2018-10-18 15:53:00 +03:00
|
|
|
// FIXME: Implement some kind of ASLR?
|
|
|
|
LinearAddress m_nextRegion;
|
2018-10-24 15:28:22 +03:00
|
|
|
|
2018-11-07 23:19:47 +03:00
|
|
|
LinearAddress m_return_to_ring3_from_signal_trampoline;
|
|
|
|
LinearAddress m_return_to_ring0_from_signal_trampoline;
|
2018-11-06 12:46:40 +03:00
|
|
|
|
2018-11-06 15:33:06 +03:00
|
|
|
pid_t m_ppid { 0 };
|
2018-11-06 15:40:23 +03:00
|
|
|
mode_t m_umask { 022 };
|
2018-10-26 12:16:56 +03:00
|
|
|
|
2018-11-07 23:19:47 +03:00
|
|
|
bool m_was_interrupted_while_blocked { false };
|
|
|
|
|
2018-11-01 03:04:02 +03:00
|
|
|
static void notify_waiters(pid_t waitee, int exit_status, int signal);
|
2018-10-31 03:06:57 +03:00
|
|
|
|
2018-10-26 12:16:56 +03:00
|
|
|
Vector<String> m_arguments;
|
2018-10-31 19:50:43 +03:00
|
|
|
Vector<String> m_initialEnvironment;
|
2018-11-07 03:38:51 +03:00
|
|
|
HashTable<gid_t> m_gids;
|
2018-11-07 23:19:47 +03:00
|
|
|
|
|
|
|
Region* m_stack_region { nullptr };
|
|
|
|
Region* m_signal_stack_user_region { nullptr };
|
|
|
|
Region* m_signal_stack_kernel_region { nullptr };
|
2019-01-09 04:29:11 +03:00
|
|
|
|
|
|
|
RetainPtr<Region> m_display_framebuffer_region;
|
2019-01-13 03:59:38 +03:00
|
|
|
|
2019-01-14 16:21:51 +03:00
|
|
|
HashMap<int, OwnPtr<Window>> m_windows;
|
|
|
|
|
|
|
|
Vector<GUI_Event> m_gui_events;
|
|
|
|
SpinLock m_gui_events_lock;
|
|
|
|
int m_next_window_id { 1 };
|
2018-10-16 12:01:38 +03:00
|
|
|
};
|
|
|
|
|
2018-11-10 18:50:42 +03:00
|
|
|
extern Process* current;
|
|
|
|
|
|
|
|
class ProcessInspectionHandle {
|
2018-11-01 16:21:02 +03:00
|
|
|
public:
|
2018-11-10 18:50:42 +03:00
|
|
|
ProcessInspectionHandle(Process& process)
|
2018-11-01 16:21:02 +03:00
|
|
|
: m_process(process)
|
|
|
|
, m_original_state(process.state())
|
|
|
|
{
|
2018-11-10 18:50:42 +03:00
|
|
|
if (&process != current)
|
|
|
|
m_process.set_state(Process::BeingInspected);
|
2018-11-01 16:21:02 +03:00
|
|
|
}
|
|
|
|
|
2018-11-10 18:50:42 +03:00
|
|
|
~ProcessInspectionHandle()
|
2018-11-01 16:21:02 +03:00
|
|
|
{
|
|
|
|
m_process.set_state(m_original_state);
|
|
|
|
}
|
2018-11-10 18:50:42 +03:00
|
|
|
|
|
|
|
Process* operator->() { return &m_process; }
|
|
|
|
Process& operator*() { return m_process; }
|
2018-11-01 16:21:02 +03:00
|
|
|
private:
|
|
|
|
Process& m_process;
|
|
|
|
Process::State m_original_state { Process::Invalid };
|
|
|
|
};
|
|
|
|
|
2018-11-05 15:48:07 +03:00
|
|
|
static inline const char* toString(Process::State state)
|
|
|
|
{
|
|
|
|
switch (state) {
|
|
|
|
case Process::Invalid: return "Invalid";
|
|
|
|
case Process::Runnable: return "Runnable";
|
|
|
|
case Process::Running: return "Running";
|
2018-11-07 20:30:59 +03:00
|
|
|
case Process::Dead: return "Dead";
|
2018-11-08 01:21:32 +03:00
|
|
|
case Process::Skip1SchedulerPass: return "Skip1";
|
|
|
|
case Process::Skip0SchedulerPasses: return "Skip0";
|
2018-11-05 15:48:07 +03:00
|
|
|
case Process::BlockedSleep: return "Sleep";
|
|
|
|
case Process::BlockedWait: return "Wait";
|
|
|
|
case Process::BlockedRead: return "Read";
|
2018-11-12 03:28:46 +03:00
|
|
|
case Process::BlockedWrite: return "Write";
|
2018-11-10 04:43:33 +03:00
|
|
|
case Process::BlockedSignal: return "Signal";
|
2019-01-16 01:12:20 +03:00
|
|
|
case Process::BlockedSelect: return "Select";
|
2018-11-05 15:48:07 +03:00
|
|
|
case Process::BeingInspected: return "Inspect";
|
|
|
|
}
|
|
|
|
ASSERT_NOT_REACHED();
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2018-11-01 15:15:46 +03:00
|
|
|
extern void block(Process::State);
|
2018-11-17 02:11:08 +03:00
|
|
|
extern void sleep(dword ticks);
|
2018-10-16 12:01:38 +03:00
|
|
|
|
2018-11-08 00:15:02 +03:00
|
|
|
extern InlineLinkedList<Process>* g_processes;
|
2018-11-08 18:09:05 +03:00
|
|
|
|
|
|
|
template<typename Callback>
|
|
|
|
inline void Process::for_each(Callback callback)
|
|
|
|
{
|
|
|
|
ASSERT_INTERRUPTS_DISABLED();
|
|
|
|
for (auto* process = g_processes->head(); process;) {
|
|
|
|
auto* next_process = process->next();
|
|
|
|
if (!callback(*process))
|
|
|
|
break;
|
|
|
|
process = next_process;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-11 17:36:40 +03:00
|
|
|
template<typename Callback>
|
|
|
|
inline void Process::for_each_child(Callback callback)
|
|
|
|
{
|
|
|
|
ASSERT_INTERRUPTS_DISABLED();
|
|
|
|
pid_t my_pid = pid();
|
|
|
|
for (auto* process = g_processes->head(); process;) {
|
|
|
|
auto* next_process = process->next();
|
|
|
|
if (process->ppid() == my_pid) {
|
|
|
|
if (!callback(*process))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
process = next_process;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-08 18:09:05 +03:00
|
|
|
template<typename Callback>
|
|
|
|
inline void Process::for_each_in_pgrp(pid_t pgid, Callback callback)
|
|
|
|
{
|
|
|
|
ASSERT_INTERRUPTS_DISABLED();
|
|
|
|
for (auto* process = g_processes->head(); process;) {
|
|
|
|
auto* next_process = process->next();
|
|
|
|
if (process->pgid() == pgid) {
|
|
|
|
if (!callback(*process))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
process = next_process;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Callback>
|
|
|
|
inline void Process::for_each_in_state(State state, Callback callback)
|
|
|
|
{
|
|
|
|
ASSERT_INTERRUPTS_DISABLED();
|
|
|
|
for (auto* process = g_processes->head(); process;) {
|
|
|
|
auto* next_process = process->next();
|
|
|
|
if (process->state() == state)
|
|
|
|
callback(*process);
|
|
|
|
process = next_process;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Callback>
|
|
|
|
inline void Process::for_each_not_in_state(State state, Callback callback)
|
|
|
|
{
|
|
|
|
ASSERT_INTERRUPTS_DISABLED();
|
|
|
|
for (auto* process = g_processes->head(); process;) {
|
|
|
|
auto* next_process = process->next();
|
|
|
|
if (process->state() != state)
|
|
|
|
callback(*process);
|
|
|
|
process = next_process;
|
|
|
|
}
|
|
|
|
}
|