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
|
|
|
/*
|
2022-04-25 22:09:06 +00:00
|
|
|
* Copyright (c) 2011-2016, 2018, 2021-2022 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/thread.h
|
|
|
|
* Describes a thread belonging to a process.
|
|
|
|
*/
|
2013-05-12 22:41:30 +00:00
|
|
|
|
2022-07-07 23:09:15 +00:00
|
|
|
#ifndef _INCLUDE_SORTIX_KERNEL_THREAD_H
|
|
|
|
#define _INCLUDE_SORTIX_KERNEL_THREAD_H
|
2013-05-12 22:41:30 +00:00
|
|
|
|
2014-10-02 13:38:06 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
|
2013-08-04 18:24:59 +00:00
|
|
|
#include <sortix/sigaction.h>
|
2013-05-12 22:41:30 +00:00
|
|
|
#include <sortix/signal.h>
|
2013-08-04 18:24:59 +00:00
|
|
|
#include <sortix/sigset.h>
|
|
|
|
#include <sortix/stack.h>
|
2013-05-12 22:41:30 +00:00
|
|
|
|
2016-01-09 00:17:08 +00:00
|
|
|
#include <sortix/kernel/clock.h>
|
2013-08-04 18:24:59 +00:00
|
|
|
#include <sortix/kernel/kthread.h>
|
2014-03-03 23:11:13 +00:00
|
|
|
#include <sortix/kernel/registers.h>
|
2013-05-12 22:41:30 +00:00
|
|
|
#include <sortix/kernel/scheduler.h>
|
|
|
|
#include <sortix/kernel/signal.h>
|
|
|
|
|
|
|
|
namespace Sortix {
|
|
|
|
|
|
|
|
class Process;
|
|
|
|
class Thread;
|
|
|
|
|
|
|
|
// These functions create a new kernel process but doesn't start it.
|
2021-02-06 20:23:43 +00:00
|
|
|
Thread* CreateKernelThread(Process* process, struct thread_registers* regs,
|
|
|
|
const char* name);
|
2014-03-02 23:08:01 +00:00
|
|
|
Thread* CreateKernelThread(Process* process, void (*entry)(void*), void* user,
|
2021-02-06 20:23:43 +00:00
|
|
|
const char* name, size_t stacksize = 0);
|
|
|
|
Thread* CreateKernelThread(void (*entry)(void*), void* user, const char* name,
|
2013-05-12 22:41:30 +00:00
|
|
|
size_t stacksize = 0);
|
|
|
|
|
|
|
|
// This function can be used to start a thread from the above functions.
|
|
|
|
void StartKernelThread(Thread* thread);
|
|
|
|
|
|
|
|
// Alternatively, these functions both create and start the thread.
|
2021-02-06 20:23:43 +00:00
|
|
|
Thread* RunKernelThread(Process* process, struct thread_registers* regs,
|
|
|
|
const char* name);
|
2014-03-02 23:08:01 +00:00
|
|
|
Thread* RunKernelThread(Process* process, void (*entry)(void*), void* user,
|
2021-02-06 20:23:43 +00:00
|
|
|
const char* name, size_t stacksize = 0);
|
|
|
|
Thread* RunKernelThread(void (*entry)(void*), void* user, const char* name,
|
2013-05-12 22:41:30 +00:00
|
|
|
size_t stacksize = 0);
|
2021-02-06 20:23:43 +00:00
|
|
|
|
|
|
|
enum yield_operation
|
|
|
|
{
|
|
|
|
YIELD_OPERATION_NONE,
|
|
|
|
YIELD_OPERATION_WAIT_FUTEX,
|
|
|
|
YIELD_OPERATION_WAIT_FUTEX_SIGNAL,
|
|
|
|
};
|
2013-05-12 22:41:30 +00:00
|
|
|
|
|
|
|
class Thread
|
|
|
|
{
|
|
|
|
public:
|
2014-03-02 23:08:01 +00:00
|
|
|
Thread();
|
2013-05-12 22:41:30 +00:00
|
|
|
~Thread();
|
|
|
|
|
|
|
|
public:
|
2021-02-06 20:23:43 +00:00
|
|
|
const char* name;
|
2014-10-02 13:38:06 +00:00
|
|
|
uintptr_t system_tid;
|
|
|
|
uintptr_t yield_to_tid;
|
2014-03-03 23:11:13 +00:00
|
|
|
struct thread_registers registers;
|
2013-05-12 22:41:30 +00:00
|
|
|
size_t id;
|
|
|
|
Process* process;
|
|
|
|
Thread* prevsibling;
|
|
|
|
Thread* nextsibling;
|
2014-02-21 16:05:10 +00:00
|
|
|
Thread* scheduler_list_prev;
|
|
|
|
Thread* scheduler_list_next;
|
2013-05-12 22:41:30 +00:00
|
|
|
volatile ThreadState state;
|
2013-08-04 18:24:59 +00:00
|
|
|
sigset_t signal_pending;
|
|
|
|
sigset_t signal_mask;
|
2018-10-20 10:57:31 +00:00
|
|
|
sigset_t saved_signal_mask;
|
2013-08-04 18:24:59 +00:00
|
|
|
stack_t signal_stack;
|
2013-05-12 22:41:30 +00:00
|
|
|
addr_t kernelstackpos;
|
|
|
|
size_t kernelstacksize;
|
2016-05-13 23:14:26 +00:00
|
|
|
size_t signal_count;
|
|
|
|
uintptr_t signal_single_frame;
|
|
|
|
uintptr_t signal_canary;
|
2013-05-12 22:41:30 +00:00
|
|
|
bool kernelstackmalloced;
|
2013-08-04 18:24:59 +00:00
|
|
|
bool pledged_destruction;
|
2015-08-14 16:24:40 +00:00
|
|
|
bool force_no_signals;
|
2016-05-13 23:14:26 +00:00
|
|
|
bool signal_single;
|
2018-10-20 10:57:31 +00:00
|
|
|
bool has_saved_signal_mask;
|
2016-01-09 00:17:08 +00:00
|
|
|
Clock execute_clock;
|
|
|
|
Clock system_clock;
|
2021-02-06 20:23:43 +00:00
|
|
|
uintptr_t futex_address;
|
|
|
|
bool futex_woken;
|
|
|
|
bool timer_woken;
|
|
|
|
Thread* futex_prev_waiting;
|
|
|
|
Thread* futex_next_waiting;
|
|
|
|
enum yield_operation yield_operation;
|
2013-05-12 22:41:30 +00:00
|
|
|
|
2013-09-14 16:59:15 +00:00
|
|
|
public:
|
2014-03-03 23:11:13 +00:00
|
|
|
void HandleSignal(struct interrupt_context* intctx);
|
|
|
|
void HandleSigreturn(struct interrupt_context* intctx);
|
2013-05-12 22:41:30 +00:00
|
|
|
bool DeliverSignal(int signum);
|
2013-08-04 18:24:59 +00:00
|
|
|
bool DeliverSignalUnlocked(int signum);
|
2015-08-14 16:24:40 +00:00
|
|
|
void DoUpdatePendingSignal();
|
2013-05-12 22:41:30 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
Thread* CurrentThread();
|
|
|
|
|
|
|
|
} // namespace Sortix
|
|
|
|
|
|
|
|
#endif
|