2018-10-16 09:01:38 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "types.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-23 04:13:17 +00:00
|
|
|
#include <Kernel/VirtualFileSystem.h>
|
|
|
|
#include <Kernel/UnixTypes.h>
|
2018-12-03 00:18:54 +00:00
|
|
|
#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>
|
2019-01-13 04:03:17 +00:00
|
|
|
#include <AK/WeakPtr.h>
|
2019-01-31 06:02:40 +00:00
|
|
|
#include <AK/Weakable.h>
|
2019-03-23 21:03:17 +00:00
|
|
|
#include <Kernel/Thread.h>
|
2019-03-16 12:18:22 +00:00
|
|
|
#include <Kernel/Lock.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-16 15:03:50 +00:00
|
|
|
class WSWindow;
|
2019-01-24 22:40:12 +00:00
|
|
|
class GraphicsBitmap;
|
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
|
|
|
|
|
2019-03-13 12:13:23 +00:00
|
|
|
void kgettimeofday(timeval&);
|
|
|
|
|
2019-01-31 06:02:40 +00:00
|
|
|
class Process : public InlineLinkedListNode<Process>, public Weakable<Process> {
|
2018-11-01 12:15:46 +00:00
|
|
|
friend class InlineLinkedListNode<Process>;
|
2019-03-23 21:03:17 +00:00
|
|
|
friend class Thread;
|
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
|
|
|
|
2019-02-03 11:33:11 +00:00
|
|
|
static Vector<pid_t> all_pids();
|
2019-01-31 16:31:23 +00:00
|
|
|
static Vector<Process*> all_processes();
|
2018-10-16 09:01:38 +00:00
|
|
|
|
2019-02-07 11:21:17 +00:00
|
|
|
enum Priority {
|
|
|
|
LowPriority,
|
|
|
|
NormalPriority,
|
|
|
|
HighPriority,
|
|
|
|
};
|
|
|
|
|
2018-10-16 09:01:38 +00:00
|
|
|
enum RingLevel {
|
|
|
|
Ring0 = 0,
|
|
|
|
Ring3 = 3,
|
|
|
|
};
|
|
|
|
|
2019-03-24 00:20:35 +00:00
|
|
|
bool is_dead() const { return m_dead; }
|
2019-03-23 21:03:17 +00:00
|
|
|
|
|
|
|
Thread::State state() const { return main_thread().state(); }
|
|
|
|
|
|
|
|
Thread& main_thread() { return *m_main_thread; }
|
|
|
|
const Thread& main_thread() const { return *m_main_thread; }
|
|
|
|
|
2019-01-31 16:31:23 +00:00
|
|
|
bool is_ring0() const { return m_ring == Ring0; }
|
|
|
|
bool is_ring3() const { return m_ring == Ring3; }
|
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:38:18 +00:00
|
|
|
static Process* from_pid(pid_t);
|
2018-10-16 09:01:38 +00:00
|
|
|
|
2019-02-07 11:21:17 +00:00
|
|
|
void set_priority(Priority p) { m_priority = p; }
|
|
|
|
Priority priority() const { return m_priority; }
|
|
|
|
|
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-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; }
|
2019-02-21 14:45:31 +00:00
|
|
|
const HashTable<gid_t>& gids() const { return m_gids; }
|
2018-11-05 14:04:19 +00:00
|
|
|
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
|
|
|
|
2019-02-22 01:39:13 +00:00
|
|
|
mode_t umask() const { return m_umask; }
|
|
|
|
|
2019-02-27 11:32:53 +00:00
|
|
|
bool in_group(gid_t) const;
|
|
|
|
|
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-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);
|
2018-11-11 14:36:40 +00:00
|
|
|
template<typename Callback> void for_each_child(Callback);
|
2019-03-23 21:03:17 +00:00
|
|
|
template<typename Callback> void for_each_thread(Callback) const;
|
2018-11-02 13:06:48 +00:00
|
|
|
|
2019-01-30 17:26:19 +00:00
|
|
|
void die();
|
2019-02-06 17:45:21 +00:00
|
|
|
void finalize();
|
2018-10-16 09:01:38 +00:00
|
|
|
|
2019-03-25 12:03:49 +00:00
|
|
|
int sys$gettid();
|
|
|
|
int sys$donate(int tid);
|
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);
|
2019-01-21 23:58:13 +00:00
|
|
|
int sys$open(const char* path, int options, mode_t mode = 0);
|
2018-10-16 09:01:38 +00:00
|
|
|
int sys$close(int fd);
|
2019-02-25 20:19:57 +00:00
|
|
|
ssize_t sys$read(int fd, byte*, ssize_t);
|
|
|
|
ssize_t sys$write(int fd, const byte*, ssize_t);
|
2019-01-23 05:53:01 +00:00
|
|
|
int sys$fstat(int fd, stat*);
|
|
|
|
int sys$lstat(const char*, stat*);
|
|
|
|
int sys$stat(const char*, 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);
|
2019-02-15 11:30:48 +00:00
|
|
|
[[noreturn]] void sys$exit(int status);
|
|
|
|
[[noreturn]] void sys$sigreturn();
|
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*);
|
2019-01-15 22:12:20 +00:00
|
|
|
int sys$select(const Syscall::SC_select_params*);
|
2019-01-23 06:27:41 +00:00
|
|
|
int sys$poll(pollfd*, int nfds, int timeout);
|
2019-02-25 20:19:57 +00:00
|
|
|
ssize_t sys$get_dir_entries(int fd, void*, ssize_t);
|
|
|
|
int sys$getcwd(char*, ssize_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);
|
2019-02-03 15:11:28 +00:00
|
|
|
int sys$usleep(useconds_t usec);
|
2018-10-25 15:29:49 +00:00
|
|
|
int sys$gettimeofday(timeval*);
|
2019-02-25 20:19:57 +00:00
|
|
|
int sys$gethostname(char*, ssize_t);
|
2018-10-26 12:56:21 +00:00
|
|
|
int sys$uname(utsname*);
|
2019-02-25 20:19:57 +00:00
|
|
|
int sys$readlink(const char*, char*, ssize_t);
|
|
|
|
int sys$ttyname_r(int fd, char*, ssize_t);
|
|
|
|
int sys$ptsname_r(int fd, char*, ssize_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);
|
2019-01-23 05:53:01 +00:00
|
|
|
int sys$sigaction(int signum, const sigaction* act, sigaction* old_act);
|
|
|
|
int sys$sigprocmask(int how, const sigset_t* set, sigset_t* old_set);
|
|
|
|
int sys$sigpending(sigset_t*);
|
2019-02-25 21:06:55 +00:00
|
|
|
int sys$getgroups(ssize_t, gid_t*);
|
|
|
|
int sys$setgroups(ssize_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);
|
2019-01-23 05:53:01 +00:00
|
|
|
clock_t sys$times(tms*);
|
|
|
|
int sys$utime(const char* pathname, const struct utimbuf*);
|
2019-02-21 12:26:40 +00:00
|
|
|
int sys$link(const char* old_path, const char* new_path);
|
2019-01-22 06:03:44 +00:00
|
|
|
int sys$unlink(const char* pathname);
|
2019-03-02 00:50:34 +00:00
|
|
|
int sys$symlink(const char* target, const char* linkpath);
|
2019-01-28 03:16:01 +00:00
|
|
|
int sys$rmdir(const char* pathname);
|
2019-01-25 01:09:29 +00:00
|
|
|
int sys$read_tsc(dword* lsw, dword* msw);
|
2019-01-29 03:55:08 +00:00
|
|
|
int sys$chmod(const char* pathname, mode_t);
|
2019-03-01 09:39:19 +00:00
|
|
|
int sys$fchmod(int fd, mode_t);
|
2019-02-27 11:32:53 +00:00
|
|
|
int sys$chown(const char* pathname, uid_t, gid_t);
|
2019-02-14 13:17:38 +00:00
|
|
|
int sys$socket(int domain, int type, int protocol);
|
|
|
|
int sys$bind(int sockfd, const sockaddr* addr, socklen_t);
|
|
|
|
int sys$listen(int sockfd, int backlog);
|
2019-02-14 14:17:30 +00:00
|
|
|
int sys$accept(int sockfd, sockaddr*, socklen_t*);
|
2019-02-14 13:17:38 +00:00
|
|
|
int sys$connect(int sockfd, const sockaddr*, socklen_t);
|
2019-03-12 14:51:42 +00:00
|
|
|
ssize_t sys$sendto(const Syscall::SC_sendto_params*);
|
2019-03-12 16:27:07 +00:00
|
|
|
ssize_t sys$recvfrom(const Syscall::SC_recvfrom_params*);
|
2019-03-13 12:13:23 +00:00
|
|
|
int sys$getsockopt(const Syscall::SC_getsockopt_params*);
|
|
|
|
int sys$setsockopt(const Syscall::SC_setsockopt_params*);
|
2019-03-05 09:34:08 +00:00
|
|
|
int sys$restore_signal_mask(dword mask);
|
2019-03-23 21:59:08 +00:00
|
|
|
int sys$create_thread(int(*)(void*), void*);
|
2018-10-16 09:01:38 +00:00
|
|
|
|
2019-03-08 11:22:55 +00:00
|
|
|
int sys$create_shared_buffer(pid_t peer_pid, int, void** buffer);
|
2019-02-16 11:13:43 +00:00
|
|
|
void* sys$get_shared_buffer(int shared_buffer_id);
|
|
|
|
int sys$release_shared_buffer(int shared_buffer_id);
|
2019-03-08 11:22:55 +00:00
|
|
|
int sys$seal_shared_buffer(int shared_buffer_id);
|
|
|
|
int sys$get_shared_buffer_size(int shared_buffer_id);
|
2019-02-16 11:13:43 +00:00
|
|
|
|
2018-10-16 09:01:38 +00:00
|
|
|
static void initialize();
|
|
|
|
|
2019-02-15 11:30:48 +00:00
|
|
|
[[noreturn]] void crash();
|
|
|
|
[[nodiscard]] static int reap(Process&);
|
2018-10-17 22:26:30 +00:00
|
|
|
|
2018-10-30 14:33:37 +00:00
|
|
|
const TTY* tty() const { return m_tty; }
|
2019-01-15 07:49:24 +00:00
|
|
|
void set_tty(TTY* tty) { m_tty = tty; }
|
2018-10-30 14:33:37 +00:00
|
|
|
|
2019-01-31 16:31:23 +00:00
|
|
|
size_t region_count() const { return m_regions.size(); }
|
2019-02-25 15:04:08 +00:00
|
|
|
const Vector<Retained<Region>>& regions() const { return m_regions; }
|
2019-01-31 16:31:23 +00:00
|
|
|
void dump_regions();
|
2018-10-18 12:53:00 +00:00
|
|
|
|
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 };
|
|
|
|
|
2019-01-01 01:20:01 +00:00
|
|
|
bool validate_read_from_kernel(LinearAddress) const;
|
2018-10-26 22:14:24 +00:00
|
|
|
|
2019-02-25 20:19:57 +00:00
|
|
|
bool validate_read(const void*, ssize_t) const;
|
|
|
|
bool validate_write(void*, ssize_t) const;
|
2019-02-07 23:10:01 +00:00
|
|
|
bool validate_read_str(const char* str);
|
2018-11-16 15:23:39 +00:00
|
|
|
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
|
|
|
|
2019-02-21 15:19:07 +00:00
|
|
|
Inode& cwd_inode();
|
2019-01-16 11:57:07 +00:00
|
|
|
Inode* executable_inode() { return m_executable.ptr(); }
|
2018-10-28 11:20:25 +00:00
|
|
|
|
2019-03-06 21:30:13 +00:00
|
|
|
int number_of_open_file_descriptors() const;
|
|
|
|
int max_open_file_descriptors() const { return m_max_open_file_descriptors; }
|
2018-11-01 12:39:28 +00:00
|
|
|
|
2019-02-03 17:53:18 +00:00
|
|
|
size_t amount_virtual() const;
|
|
|
|
size_t amount_resident() const;
|
|
|
|
size_t amount_shared() const;
|
|
|
|
|
2018-11-02 19:41:58 +00:00
|
|
|
Process* fork(RegisterDump&);
|
2019-02-17 09:18:25 +00:00
|
|
|
int exec(String path, Vector<String> arguments, Vector<String> environment);
|
2018-11-02 19:41:58 +00:00
|
|
|
|
2019-02-21 22:35:07 +00:00
|
|
|
bool is_superuser() const { return m_euid == 0; }
|
2018-11-07 00:38:51 +00:00
|
|
|
|
2019-02-25 15:04:08 +00:00
|
|
|
Region* allocate_region_with_vmo(LinearAddress, size_t, Retained<VMObject>&&, size_t offset_in_vmo, String&& name, bool is_readable, bool is_writable);
|
2019-02-16 08:57:42 +00:00
|
|
|
Region* allocate_file_backed_region(LinearAddress, size_t, RetainPtr<Inode>&&, String&& name, bool is_readable, bool is_writable);
|
2019-02-16 11:13:43 +00:00
|
|
|
Region* allocate_region(LinearAddress, size_t, String&& name, bool is_readable = true, bool is_writable = true, bool commit = true);
|
|
|
|
bool deallocate_region(Region& region);
|
2019-02-16 08:57:42 +00:00
|
|
|
|
2019-03-23 21:03:17 +00:00
|
|
|
void set_being_inspected(bool b) { m_being_inspected = b; }
|
|
|
|
bool is_being_inspected() const { return m_being_inspected; }
|
|
|
|
|
|
|
|
void terminate_due_to_signal(byte signal);
|
|
|
|
void send_signal(byte, Process* sender);
|
|
|
|
|
|
|
|
int thread_count() const;
|
2019-03-12 16:27:07 +00:00
|
|
|
|
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
|
|
|
|
2019-01-16 11:57:07 +00: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 09:15:17 +00:00
|
|
|
|
2019-02-17 09:18:25 +00:00
|
|
|
int do_exec(String path, Vector<String> arguments, Vector<String> environment);
|
2018-10-16 09:01:38 +00:00
|
|
|
|
2018-11-12 00:28:46 +00:00
|
|
|
int alloc_fd();
|
2019-02-16 11:13:43 +00:00
|
|
|
void disown_all_shared_buffers();
|
2018-11-12 00:28:46 +00:00
|
|
|
|
2019-03-05 11:50:55 +00:00
|
|
|
void create_signal_trampolines_if_needed();
|
|
|
|
|
2019-03-23 21:03:17 +00:00
|
|
|
Thread* m_main_thread { nullptr };
|
|
|
|
|
2019-01-22 04:01:00 +00:00
|
|
|
RetainPtr<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;
|
2019-03-23 21:03:17 +00:00
|
|
|
|
2018-10-16 09:01:38 +00:00
|
|
|
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 };
|
2019-03-23 21:03:17 +00:00
|
|
|
|
2019-02-07 11:21:17 +00:00
|
|
|
Priority m_priority { NormalPriority };
|
2019-03-23 21:03:17 +00:00
|
|
|
|
2018-11-13 00:36:31 +00:00
|
|
|
struct FileDescriptorAndFlags {
|
|
|
|
operator bool() const { return !!descriptor; }
|
|
|
|
void clear() { descriptor = nullptr; flags = 0; }
|
2019-03-06 21:14:31 +00:00
|
|
|
void set(Retained<FileDescriptor>&& d, dword f = 0) { descriptor = move(d); flags = f; }
|
2018-11-13 00:36:31 +00:00
|
|
|
RetainPtr<FileDescriptor> descriptor;
|
|
|
|
dword flags { 0 };
|
|
|
|
};
|
|
|
|
Vector<FileDescriptorAndFlags> m_fds;
|
2018-10-16 09:01:38 +00:00
|
|
|
RingLevel m_ring { Ring0 };
|
2019-03-23 21:03:17 +00:00
|
|
|
|
2019-03-06 21:30:13 +00:00
|
|
|
int m_max_open_file_descriptors { 16 };
|
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
|
|
|
|
2019-01-16 11:57:07 +00:00
|
|
|
RetainPtr<Inode> m_cwd;
|
|
|
|
RetainPtr<Inode> m_executable;
|
2018-10-24 12:28:22 +00:00
|
|
|
|
2018-10-30 12:59:29 +00:00
|
|
|
TTY* m_tty { nullptr };
|
|
|
|
|
2019-01-31 16:31:23 +00:00
|
|
|
Region* region_from_range(LinearAddress, size_t);
|
2018-10-18 12:53:00 +00:00
|
|
|
|
2019-02-25 15:04:08 +00:00
|
|
|
Vector<Retained<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?
|
2019-01-31 16:31:23 +00:00
|
|
|
LinearAddress m_next_region;
|
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-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-11-07 00:38:51 +00:00
|
|
|
HashTable<gid_t> m_gids;
|
2018-11-07 20:19:47 +00:00
|
|
|
|
2019-03-23 21:03:17 +00:00
|
|
|
bool m_being_inspected { false };
|
2019-03-24 00:20:35 +00:00
|
|
|
bool m_dead { false };
|
2019-01-09 01:29:11 +00:00
|
|
|
|
2019-03-23 21:03:17 +00:00
|
|
|
int m_next_tid { 0 };
|
2018-10-16 09:01:38 +00:00
|
|
|
};
|
|
|
|
|
2018-11-10 15:50:42 +00:00
|
|
|
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)
|
|
|
|
{
|
2019-03-23 21:03:17 +00:00
|
|
|
if (&process != ¤t->process()) {
|
|
|
|
ASSERT(!m_process.is_being_inspected());
|
|
|
|
m_process.set_being_inspected(true);
|
|
|
|
}
|
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
|
|
|
{
|
2019-03-23 21:03:17 +00:00
|
|
|
m_process.set_being_inspected(false);
|
2018-11-01 13:21:02 +00:00
|
|
|
}
|
2018-11-10 15:50:42 +00:00
|
|
|
|
2019-02-03 11:33:11 +00:00
|
|
|
Process& process() { return m_process; }
|
|
|
|
|
|
|
|
static OwnPtr<ProcessInspectionHandle> from_pid(pid_t pid)
|
|
|
|
{
|
|
|
|
InterruptDisabler disabler;
|
|
|
|
auto* process = Process::from_pid(pid);
|
|
|
|
if (process)
|
|
|
|
return make<ProcessInspectionHandle>(*process);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2019-03-05 09:34:08 +00:00
|
|
|
extern const char* to_string(Process::Priority);
|
2019-02-07 11:21:17 +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>
|
2019-03-23 21:03:17 +00:00
|
|
|
inline void Process::for_each_thread(Callback callback) const
|
2018-11-08 15:09:05 +00:00
|
|
|
{
|
2019-03-23 21:03:17 +00:00
|
|
|
InterruptDisabler disabler;
|
|
|
|
pid_t my_pid = pid();
|
|
|
|
for (auto* thread = g_threads->head(); thread;) {
|
|
|
|
auto* next_thread = thread->next();
|
|
|
|
if (thread->pid() == my_pid) {
|
|
|
|
if (callback(*thread) == IterationDecision::Abort)
|
2018-11-08 15:09:05 +00:00
|
|
|
break;
|
|
|
|
}
|
2019-03-23 21:03:17 +00:00
|
|
|
thread = next_thread;
|
2018-11-08 15:09:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Callback>
|
2019-03-23 21:03:17 +00:00
|
|
|
inline void Process::for_each_in_pgrp(pid_t pgid, Callback callback)
|
2018-11-08 15:09:05 +00:00
|
|
|
{
|
|
|
|
ASSERT_INTERRUPTS_DISABLED();
|
|
|
|
for (auto* process = g_processes->head(); process;) {
|
|
|
|
auto* next_process = process->next();
|
2019-03-23 21:03:17 +00:00
|
|
|
if (process->pgid() == pgid) {
|
|
|
|
if (!callback(*process))
|
|
|
|
break;
|
|
|
|
}
|
2018-11-08 15:09:05 +00:00
|
|
|
process = next_process;
|
|
|
|
}
|
|
|
|
}
|
2019-02-21 14:45:31 +00:00
|
|
|
|
|
|
|
inline bool InodeMetadata::may_read(Process& process) const
|
|
|
|
{
|
|
|
|
return may_read(process.euid(), process.gids());
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool InodeMetadata::may_write(Process& process) const
|
|
|
|
{
|
|
|
|
return may_write(process.euid(), process.gids());
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool InodeMetadata::may_execute(Process& process) const
|
|
|
|
{
|
|
|
|
return may_execute(process.euid(), process.gids());
|
|
|
|
}
|
2019-03-23 21:03:17 +00:00
|
|
|
|
|
|
|
inline int Thread::pid() const
|
|
|
|
{
|
|
|
|
return m_process.pid();
|
|
|
|
}
|