Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

darwin: Fix build #23

Merged
merged 4 commits into from
Jun 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion cbits/fork-exec-ptrace.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/ptrace.h>
#include <signal.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>

// On Linux the request is `PTRACE_TRACEME`,
// on other platforms it is `PT_TRACE_ME`.
// (Although modern implementations of libc define both.)
#ifndef PT_TRACE_ME
#define PT_TRACE_ME PTRACE_TRACEME
#endif

// On Linux the `data` parameter has type `void *`,
// on other platforms it is an `int`.
#if __linux__
#define PTRACE_EMPTY_DATA NULL
#else
#define PTRACE_EMPTY_DATA 0
#endif

/* Like the fork() and it uses, on failure this function
returns -1 and sets errno.
On success it returns the PID of the child process.
Expand Down Expand Up @@ -34,7 +50,7 @@ pid_t fork_exec_with_ptrace(int argc, char **argv)
args[argc] = NULL;

// For PTRACE_TRACEME, all other arguments are ignored.
long ptrace_retval = ptrace(PTRACE_TRACEME, 0, NULL, NULL);
long ptrace_retval = ptrace(PT_TRACE_ME, 0, NULL, PTRACE_EMPTY_DATA);
if (ptrace_retval != 0)
{
perror("ptrace(PTRACE_TRACEME)");
Expand Down
1 change: 1 addition & 0 deletions hatrace.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ library
c-sources: cbits/fork-exec-ptrace.c
exposed-modules: System.Hatrace
System.Hatrace.Main
System.Hatrace.SignalMap
System.Hatrace.SyscallTables
System.Hatrace.SyscallTables.Generated
System.Hatrace.SyscallTables.Util
Expand Down
37 changes: 1 addition & 36 deletions src/System/Hatrace.hs
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,12 @@ import System.Linux.Ptrace.X86Regs (X86Regs(..))
import System.Posix.Files (readSymbolicLink)
import System.Posix.Internals (withFilePath)
import System.Posix.Signals (Signal, sigTRAP, sigSTOP, sigTSTP, sigTTIN, sigTTOU)
import qualified System.Posix.Signals as Signals
import System.Posix.Types (CPid(..), CMode(..))
import System.Posix.Waitpid (waitpid, waitpidFullStatus, Status(..), FullStatus(..), Flag(..))
import UnliftIO.Concurrent (runInBoundThread)
import UnliftIO.IORef (newIORef, writeIORef, readIORef)

import System.Hatrace.SignalMap (signalMap)
import System.Hatrace.SyscallTables.Generated (KnownSyscall(..), syscallName, syscallMap_i386, syscallMap_x64_64)
import System.Hatrace.Types

Expand Down Expand Up @@ -1561,41 +1561,6 @@ prettySignal s =
Just (_longName, shortName) -> shortName


signalMap :: Map Signal (String, String)
signalMap =
Map.fromList $ map (\(s, long, short) -> (s, (long, short))) $
[ (Signals.nullSignal, "nullSignal", "NULL")
, (Signals.internalAbort, "internalAbort", "ABRT")
, (Signals.realTimeAlarm, "realTimeAlarm", "ALRM")
, (Signals.busError, "busError", "BUS")
, (Signals.processStatusChanged, "processStatusChanged", "CHLD")
, (Signals.continueProcess, "continueProcess", "CONT")
, (Signals.floatingPointException, "floatingPointException", "FPE")
, (Signals.lostConnection, "lostConnection", "HUP")
, (Signals.illegalInstruction, "illegalInstruction", "ILL")
, (Signals.keyboardSignal, "keyboardSignal", "INT")
, (Signals.killProcess, "killProcess", "KILL")
, (Signals.openEndedPipe, "openEndedPipe", "PIPE")
, (Signals.keyboardTermination, "keyboardTermination", "QUIT")
, (Signals.segmentationViolation, "segmentationViolation", "SEGV")
, (Signals.softwareStop, "softwareStop", "STOP")
, (Signals.softwareTermination, "softwareTermination", "TERM")
, (Signals.keyboardStop, "keyboardStop", "TSTP")
, (Signals.backgroundRead, "backgroundRead", "TTIN")
, (Signals.backgroundWrite, "backgroundWrite", "TTOU")
, (Signals.userDefinedSignal1, "userDefinedSignal1", "USR1")
, (Signals.userDefinedSignal2, "userDefinedSignal2", "USR2")
, (Signals.pollableEvent, "pollableEvent", "POLL")
, (Signals.profilingTimerExpired, "profilingTimerExpired", "PROF")
, (Signals.badSystemCall, "badSystemCall", "SYS")
, (Signals.breakpointTrap, "breakpointTrap", "TRAP")
, (Signals.urgentDataAvailable, "urgentDataAvailable", "URG")
, (Signals.virtualTimerExpired, "virtualTimerExpired", "VTALRM")
, (Signals.cpuTimeLimitExceeded, "cpuTimeLimitExceeded", "XCPU")
, (Signals.fileSizeLimitExceeded, "fileSizeLimitExceeded", "XFSZ")
]


data Syscall
= KnownSyscall KnownSyscall
| UnknownSyscall !Word64
Expand Down
51 changes: 51 additions & 0 deletions src/System/Hatrace/SignalMap.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{-# LANGUAGE CPP #-}

-- We use the `CONST_*` constants from the `unix` package to know
-- whether specific signals are supported on the current platform.
#include <HsUnixConfig.h>

module System.Hatrace.SignalMap
( signalMap
) where

import Data.Map (Map)
import qualified Data.Map as Map
import System.Posix.Signals (Signal)
import qualified System.Posix.Signals as Signals


signalMap :: Map Signal (String, String)
signalMap =
Map.fromList $ map (\(s, long, short) -> (s, (long, short))) $
[ (Signals.nullSignal, "nullSignal", "NULL")
, (Signals.internalAbort, "internalAbort", "ABRT")
, (Signals.realTimeAlarm, "realTimeAlarm", "ALRM")
, (Signals.busError, "busError", "BUS")
, (Signals.processStatusChanged, "processStatusChanged", "CHLD")
, (Signals.continueProcess, "continueProcess", "CONT")
, (Signals.floatingPointException, "floatingPointException", "FPE")
, (Signals.lostConnection, "lostConnection", "HUP")
, (Signals.illegalInstruction, "illegalInstruction", "ILL")
, (Signals.keyboardSignal, "keyboardSignal", "INT")
, (Signals.killProcess, "killProcess", "KILL")
, (Signals.openEndedPipe, "openEndedPipe", "PIPE")
, (Signals.keyboardTermination, "keyboardTermination", "QUIT")
, (Signals.segmentationViolation, "segmentationViolation", "SEGV")
, (Signals.softwareStop, "softwareStop", "STOP")
, (Signals.softwareTermination, "softwareTermination", "TERM")
, (Signals.keyboardStop, "keyboardStop", "TSTP")
, (Signals.backgroundRead, "backgroundRead", "TTIN")
, (Signals.backgroundWrite, "backgroundWrite", "TTOU")
, (Signals.userDefinedSignal1, "userDefinedSignal1", "USR1")
, (Signals.userDefinedSignal2, "userDefinedSignal2", "USR2")
#if CONST_SIGPOLL != -1
, (Signals.pollableEvent, "pollableEvent", "POLL")
#endif
, (Signals.profilingTimerExpired, "profilingTimerExpired", "PROF")
, (Signals.badSystemCall, "badSystemCall", "SYS")
, (Signals.breakpointTrap, "breakpointTrap", "TRAP")
, (Signals.urgentDataAvailable, "urgentDataAvailable", "URG")
, (Signals.virtualTimerExpired, "virtualTimerExpired", "VTALRM")
, (Signals.cpuTimeLimitExceeded, "cpuTimeLimitExceeded", "XCPU")
, (Signals.fileSizeLimitExceeded, "fileSizeLimitExceeded", "XFSZ")
]