Relicense Sortix to the ISC license.
I hereby relicense all my work on Sortix under the ISC license as below.
All Sortix contributions by other people are already under this license,
are not substantial enough to be copyrightable, or have been removed.
All imported code from other projects is compatible with this license.
All GPL licensed code from other projects had previously been removed.
Copyright 2011-2016 Jonas 'Sortie' Termansen and contributors.
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
2016-03-02 22:38:16 +00:00
|
|
|
/*
|
2016-11-15 20:08:41 +00:00
|
|
|
* Copyright (c) 2011, 2012, 2013, 2014, 205, 2016 Jonas 'Sortie' Termansen.
|
Relicense Sortix to the ISC license.
I hereby relicense all my work on Sortix under the ISC license as below.
All Sortix contributions by other people are already under this license,
are not substantial enough to be copyrightable, or have been removed.
All imported code from other projects is compatible with this license.
All GPL licensed code from other projects had previously been removed.
Copyright 2011-2016 Jonas 'Sortie' Termansen and contributors.
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
2016-03-02 22:38:16 +00:00
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*
|
|
|
|
* sortix/kernel/process.h
|
|
|
|
* A named collection of threads.
|
|
|
|
*/
|
2013-05-12 22:41:30 +00:00
|
|
|
|
|
|
|
#ifndef INCLUDE_SORTIX_KERNEL_PROCESS_H
|
|
|
|
#define INCLUDE_SORTIX_KERNEL_PROCESS_H
|
|
|
|
|
|
|
|
#include <sortix/fork.h>
|
2013-08-30 21:55:09 +00:00
|
|
|
#include <sortix/resource.h>
|
2013-08-04 18:24:59 +00:00
|
|
|
#include <sortix/sigaction.h>
|
|
|
|
#include <sortix/signal.h>
|
|
|
|
#include <sortix/sigset.h>
|
2013-05-12 22:41:30 +00:00
|
|
|
|
|
|
|
#include <sortix/kernel/clock.h>
|
|
|
|
#include <sortix/kernel/kthread.h>
|
|
|
|
#include <sortix/kernel/refcount.h>
|
2014-03-03 23:11:13 +00:00
|
|
|
#include <sortix/kernel/registers.h>
|
2013-08-20 00:23:53 +00:00
|
|
|
#include <sortix/kernel/segment.h>
|
2013-05-12 22:41:30 +00:00
|
|
|
#include <sortix/kernel/time.h>
|
|
|
|
#include <sortix/kernel/timer.h>
|
|
|
|
#include <sortix/kernel/user-timer.h>
|
|
|
|
#include <sortix/kernel/cpu.h>
|
|
|
|
|
|
|
|
#define PROCESS_TIMER_NUM_MAX 32
|
|
|
|
|
|
|
|
namespace Sortix {
|
|
|
|
|
|
|
|
class Thread;
|
|
|
|
class Process;
|
|
|
|
class Descriptor;
|
|
|
|
class DescriptorTable;
|
|
|
|
class MountTable;
|
2014-03-19 22:34:09 +00:00
|
|
|
class ProcessTable;
|
2013-05-12 22:41:30 +00:00
|
|
|
struct ProcessSegment;
|
|
|
|
struct ProcessTimer;
|
|
|
|
struct ioctx_struct;
|
|
|
|
typedef struct ioctx_struct ioctx_t;
|
2014-02-17 22:53:03 +00:00
|
|
|
struct segment;
|
2013-05-12 22:41:30 +00:00
|
|
|
|
|
|
|
class Process
|
|
|
|
{
|
|
|
|
friend void Process__OnLastThreadExit(void*);
|
|
|
|
|
|
|
|
public:
|
|
|
|
Process();
|
|
|
|
~Process();
|
|
|
|
|
|
|
|
public:
|
|
|
|
char* program_image_path;
|
|
|
|
addr_t addrspace;
|
|
|
|
pid_t pid;
|
|
|
|
|
2013-08-30 15:35:30 +00:00
|
|
|
public:
|
|
|
|
kthread_mutex_t nicelock;
|
|
|
|
int nice;
|
|
|
|
|
2013-05-12 22:41:30 +00:00
|
|
|
public:
|
|
|
|
kthread_mutex_t idlock;
|
|
|
|
uid_t uid, euid;
|
|
|
|
gid_t gid, egid;
|
2013-05-16 20:03:15 +00:00
|
|
|
mode_t umask;
|
2013-05-12 22:41:30 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
kthread_mutex_t ptrlock;
|
2016-11-15 20:08:41 +00:00
|
|
|
Ref<Descriptor> tty;
|
2013-05-12 22:41:30 +00:00
|
|
|
Ref<Descriptor> root;
|
|
|
|
Ref<Descriptor> cwd;
|
|
|
|
Ref<MountTable> mtable;
|
|
|
|
Ref<DescriptorTable> dtable;
|
|
|
|
|
2014-03-19 22:34:09 +00:00
|
|
|
public:
|
|
|
|
Ref<ProcessTable> ptable;
|
|
|
|
|
2013-08-30 21:55:09 +00:00
|
|
|
public:
|
|
|
|
kthread_mutex_t resource_limits_lock;
|
|
|
|
struct rlimit resource_limits[RLIMIT_NUM_DECLARED];
|
|
|
|
|
2013-08-04 18:24:59 +00:00
|
|
|
public:
|
|
|
|
kthread_mutex_t signal_lock;
|
|
|
|
struct sigaction signal_actions[SIG_MAX_NUM];
|
|
|
|
sigset_t signal_pending;
|
|
|
|
void (*sigreturn)(void);
|
|
|
|
|
2013-05-12 22:41:30 +00:00
|
|
|
public:
|
|
|
|
void BootstrapTables(Ref<DescriptorTable> dtable, Ref<MountTable> mtable);
|
|
|
|
void BootstrapDirectories(Ref<Descriptor> root);
|
|
|
|
Ref<DescriptorTable> GetDTable();
|
2014-03-19 22:34:09 +00:00
|
|
|
Ref<MountTable> GetMTable();
|
|
|
|
Ref<ProcessTable> GetPTable();
|
2016-11-15 20:08:41 +00:00
|
|
|
Ref<Descriptor> GetTTY();
|
2013-05-12 22:41:30 +00:00
|
|
|
Ref<Descriptor> GetRoot();
|
|
|
|
Ref<Descriptor> GetCWD();
|
|
|
|
Ref<Descriptor> GetDescriptor(int fd);
|
2016-11-15 20:08:41 +00:00
|
|
|
void SetTTY(Ref<Descriptor> tty);
|
2013-05-29 22:32:22 +00:00
|
|
|
void SetRoot(Ref<Descriptor> newroot);
|
2013-05-12 22:41:30 +00:00
|
|
|
void SetCWD(Ref<Descriptor> newcwd);
|
|
|
|
|
2015-07-30 23:20:39 +00:00
|
|
|
public:
|
2013-05-12 22:41:30 +00:00
|
|
|
Process* parent;
|
|
|
|
Process* prevsibling;
|
|
|
|
Process* nextsibling;
|
|
|
|
Process* firstchild;
|
|
|
|
Process* zombiechild;
|
2016-11-15 20:08:41 +00:00
|
|
|
Process* group;
|
|
|
|
Process* groupprev;
|
|
|
|
Process* groupnext;
|
|
|
|
Process* groupfirst;
|
|
|
|
Process* session;
|
|
|
|
Process* sessionprev;
|
|
|
|
Process* sessionnext;
|
|
|
|
Process* sessionfirst;
|
2013-05-12 22:41:30 +00:00
|
|
|
kthread_mutex_t childlock;
|
|
|
|
kthread_mutex_t parentlock;
|
|
|
|
kthread_cond_t zombiecond;
|
|
|
|
bool iszombie;
|
|
|
|
bool nozombify;
|
2016-11-15 20:08:41 +00:00
|
|
|
bool limbo;
|
2013-08-04 18:24:59 +00:00
|
|
|
int exit_code;
|
2013-05-12 22:41:30 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
Thread* firstthread;
|
|
|
|
kthread_mutex_t threadlock;
|
2013-08-04 18:24:59 +00:00
|
|
|
bool threads_exiting;
|
2013-05-12 22:41:30 +00:00
|
|
|
|
|
|
|
public:
|
2013-08-20 00:23:53 +00:00
|
|
|
struct segment* segments;
|
|
|
|
size_t segments_used;
|
|
|
|
size_t segments_length;
|
2015-05-14 13:19:23 +00:00
|
|
|
kthread_mutex_t segment_write_lock;
|
2013-08-20 00:23:53 +00:00
|
|
|
kthread_mutex_t segment_lock;
|
2013-05-12 22:41:30 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
kthread_mutex_t user_timers_lock;
|
|
|
|
UserTimer user_timers[PROCESS_TIMER_NUM_MAX];
|
|
|
|
Timer alarm_timer;
|
2013-05-14 22:45:04 +00:00
|
|
|
Clock execute_clock;
|
|
|
|
Clock system_clock;
|
2013-05-14 22:58:54 +00:00
|
|
|
Clock child_execute_clock;
|
|
|
|
Clock child_system_clock;
|
2013-05-12 22:41:30 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
int Execute(const char* programname, const uint8_t* program,
|
|
|
|
size_t programsize, int argc, const char* const* argv,
|
|
|
|
int envc, const char* const* envp,
|
2014-03-03 23:11:13 +00:00
|
|
|
struct thread_registers* regs);
|
2013-05-12 22:41:30 +00:00
|
|
|
void ResetAddressSpace();
|
2013-08-04 18:24:59 +00:00
|
|
|
void ExitThroughSignal(int signal);
|
|
|
|
void ExitWithCode(int exit_code);
|
2013-05-12 22:41:30 +00:00
|
|
|
pid_t Wait(pid_t pid, int* status, int options);
|
|
|
|
bool DeliverSignal(int signum);
|
2013-06-11 23:35:31 +00:00
|
|
|
bool DeliverGroupSignal(int signum);
|
2016-11-15 20:08:41 +00:00
|
|
|
bool DeliverSessionSignal(int signum);
|
2013-05-12 22:41:30 +00:00
|
|
|
void OnThreadDestruction(Thread* thread);
|
|
|
|
void ScheduleDeath();
|
|
|
|
void AbortConstruction();
|
2014-02-17 22:53:03 +00:00
|
|
|
bool MapSegment(struct segment* result, void* hint, size_t size, int flags,
|
|
|
|
int prot);
|
2016-11-15 20:08:41 +00:00
|
|
|
void GroupRemoveMember(Process* child);
|
|
|
|
void SessionRemoveMember(Process* child);
|
2013-05-12 22:41:30 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
Process* Fork();
|
|
|
|
|
|
|
|
private:
|
|
|
|
void OnLastThreadExit();
|
|
|
|
void LastPrayer();
|
2015-07-31 19:59:53 +00:00
|
|
|
void WaitedFor();
|
2013-05-12 22:41:30 +00:00
|
|
|
void NotifyChildExit(Process* child, bool zombify);
|
|
|
|
void DeleteTimers();
|
2016-11-15 20:08:41 +00:00
|
|
|
bool IsLimboDone();
|
2013-06-11 23:02:01 +00:00
|
|
|
|
2013-05-12 22:41:30 +00:00
|
|
|
public:
|
|
|
|
void ResetForExecute();
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2016-11-15 20:08:41 +00:00
|
|
|
extern kthread_mutex_t process_family_lock;
|
|
|
|
|
2013-05-12 22:41:30 +00:00
|
|
|
Process* CurrentProcess();
|
|
|
|
|
|
|
|
} // namespace Sortix
|
|
|
|
|
|
|
|
#endif
|