The Pedigree Project 0.1
SignalEvent.cc
1/*
2 * Copyright (c) 2008-2014, Pedigree Developers
3 *
4 * Please see the CONTRIB file in the root of the source tree for a full
5 * list of contributors.
6 *
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 */
19
20#include "pedigree/kernel/process/Event.h"
21#include "pedigree/kernel/process/SignalEvent.h"
22#include "pedigree/kernel/process/Thread.h"
23#include "pedigree/kernel/processor/Processor.h"
24#include "pedigree/kernel/processor/ProcessorInformation.h"
25#include "pedigree/kernel/processor/types.h"
26
27SignalEvent::SignalEvent(uintptr_t handlerAddress, size_t signalNum, size_t specificNestingLevel,
28 uint64_t signalMask, bool deferSignal, bool isDeletable,
29 HandlerPrivilege handlerPrivilege, DeliveryDisposition disposition,
30 bool useAlternateUserStack, size_t continuationEpoch)
31 : Event(handlerAddress, isDeletable, specificNestingLevel, handlerPrivilege),
32 m_SignalNumber(signalNum),
33 m_SignalMask(signalMask),
34 m_DeferSignal(deferSignal),
35 m_ProcessDirected(false),
36 m_Disposition(disposition),
37 m_UseAlternateUserStack(useAlternateUserStack),
38 m_ContinuationEpoch(continuationEpoch),
39 m_SignalCode(0),
40 m_SenderProcess(0),
41 m_SenderUser(0),
42 m_SignalValue(0) {}
43
44SignalEvent::SignalEvent(const SignalEvent& other) : SignalEvent(other, other.m_bIsDeletable) {}
45
46SignalEvent::SignalEvent(const SignalEvent& other, bool isDeletable)
47 : Event(other.m_HandlerAddress, isDeletable, other.m_NestingLevel, other.m_HandlerPrivilege),
48 m_SignalNumber(other.m_SignalNumber),
49 m_SignalMask(other.m_SignalMask),
50 m_DeferSignal(other.m_DeferSignal),
51 m_ProcessDirected(other.m_ProcessDirected),
52 m_Disposition(other.m_Disposition),
53 m_UseAlternateUserStack(other.m_UseAlternateUserStack),
54 m_ContinuationEpoch(other.m_ContinuationEpoch),
55 m_SignalCode(other.m_SignalCode),
56 m_SenderProcess(other.m_SenderProcess),
57 m_SenderUser(other.m_SenderUser),
58 m_SignalValue(other.m_SignalValue),
59 m_TraceBypass(other.m_TraceBypass),
60 m_ChildStatus(other.m_ChildStatus),
61 m_ChildUserTime(other.m_ChildUserTime),
62 m_ChildSystemTime(other.m_ChildSystemTime) {}
63
64SignalEvent::~SignalEvent() {
65 if (m_DeliveryState) {
66 m_DeliveryState->complete(false, 0);
67 }
68}
69
71 if (isDeletable()) {
72 return this;
73 }
74
75 return new SignalEvent(*this, true);
76}
77
79 return new SignalEvent(*this, false);
80}
81
83size_t SignalEvent::serialize(uint8_t* pBuffer) {
84 int32_t timerId = 0, overrun = 0;
85 timerInfo(timerId, overrun);
86 completeSignalDelivery(overrun);
87 Thread* pThread = Processor::information().getCurrentThread();
88 if (pThread) {
90 if (m_Disposition == DeliveryDisposition::CaughtHandler) {
92 }
93
94 constexpr uint64_t UnblockableSignals =
95 (static_cast<uint64_t>(1) << (9 - 1)) | (static_cast<uint64_t>(1) << (19 - 1));
96 uint64_t mask = pThread->getSignalMask() | m_SignalMask;
97 if (m_DeferSignal && m_SignalNumber > 0 && m_SignalNumber <= 64) {
98 mask |= static_cast<uint64_t>(1) << (m_SignalNumber - 1);
99 }
100 mask &= ~UnblockableSignals;
101 pThread->setSignalMask(mask);
102 }
103
104 pBuffer[0] = static_cast<uint8_t>(m_SignalNumber & 0xFF);
105 return 1;
106}
107
108bool SignalEvent::unserialize(uint8_t* pBuffer, Event& event) {
109 pBuffer[0] = static_cast<uint8_t>(event.getNumber() & 0xFF);
110 return true;
111}
Definition Event.h:49
virtual bool isDeletable()
Definition Event.cc:225
static ProcessorInformation & information()
bool m_DeferSignal
size_t m_SignalNumber
uint64_t m_SignalMask
virtual SignalEvent * cloneForDisposition()
size_t m_ContinuationEpoch
virtual size_t serialize(uint8_t *pBuffer)
virtual Event * cloneForDelivery()
DeliveryDisposition m_Disposition
void markSignalInterruptedWait()
Definition Thread.cc:3131
uint64_t getSignalMask()
Definition Thread.cc:1981
void setSignalMask(uint64_t mask)
Definition Thread.cc:1986
void setCurrentSignalDelivery(size_t signalNumber, size_t continuationEpoch)
Definition Thread.cc:2021