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