From bfc36cb8722198478bd46d7457208726e3fea389 Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Mon, 2 Feb 2015 20:16:30 -0500 Subject: [PATCH] process code stubs --- toolbox/CMakeLists.txt | 1 + toolbox/process.cpp | 107 +++++++++++++++++++++++++++++++++++++++++ toolbox/process.h | 13 +++++ toolbox/toolbox.cpp | 21 ++++++-- 4 files changed, 138 insertions(+), 4 deletions(-) create mode 100644 toolbox/process.cpp create mode 100644 toolbox/process.h diff --git a/toolbox/CMakeLists.txt b/toolbox/CMakeLists.txt index d282588..5ad0d3f 100644 --- a/toolbox/CMakeLists.txt +++ b/toolbox/CMakeLists.txt @@ -22,6 +22,7 @@ set(TOOLBOX_SRC sane.cpp saneparser.cpp pathnames.cpp + process.cpp utility.cpp fs_spec.cpp realpath.c diff --git a/toolbox/process.cpp b/toolbox/process.cpp new file mode 100644 index 0000000..c6affd8 --- /dev/null +++ b/toolbox/process.cpp @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2015, Kelvin W Sherlock + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include + +#include +#include + +#include "toolbox.h" +#include "stackframe.h" +#include "process.h" + +using ToolBox::Log; + +namespace Process { + + const unsigned kProcessID = 1986; + + uint16_t GetCurrentProcess() + { + // FUNCTION GetCurrentProcess (VAR PSN: ProcessSerialNumber): OSErr; + + uint32_t psn; + uint32_t sp; + sp = StackFrame<4>(psn); + Log(" GetCurrentProcess(%08x)\n", psn); + if (psn) memoryWriteLongLong(1, psn); + ToolReturn<2>(sp, 0); + return 0; + } + + uint16_t GetProcessInformation() + { + // FUNCTION GetProcessInformation (PSN: ProcessSerialNumber; + // VAR info: ProcessInfoRec): OSErr; + + enum { + /* ProcessInfoRec */ + _processInfoLength = 0, + _processName = 4, + _processNumber = 8, + _processType = 16, + _processSignature = 20, + _processMode = 24, + _processLocation = 28, + _processSize = 32, + _processFreeMem = 36, + _processLauncher = 40, + _processLaunchDate = 48, + _processActiveTime = 52, + _processAppSpec = 56, + }; + + uint32_t psn; + uint32_t info; + uint32_t sp; + sp = StackFrame<8>(psn, info); + Log(" GetProcessInformation(%08x, %08x)\n", psn, info); + + if (!psn || memoryReadLongLong(psn) != kProcessID) + { + ToolReturn<2>(sp, MacOS::paramErr); + return MacOS::paramErr; + } + + ToolReturn<2>(sp, MacOS::paramErr); + return MacOS::paramErr; + } + + +} diff --git a/toolbox/process.h b/toolbox/process.h new file mode 100644 index 0000000..c05cf36 --- /dev/null +++ b/toolbox/process.h @@ -0,0 +1,13 @@ +#ifndef __mpw_process_h__ +#define __mpw_process_h__ + +#include + +namespace Process { + + uint16_t GetCurrentProcess(); + uint16_t GetProcessInformation(); + +} + +#endif diff --git a/toolbox/toolbox.cpp b/toolbox/toolbox.cpp index b01f19f..2af6a1f 100644 --- a/toolbox/toolbox.cpp +++ b/toolbox/toolbox.cpp @@ -33,16 +33,24 @@ #include #include +#include +#include + #include "toolbox.h" -#include "rm.h" + +#include "loader.h" #include "mm.h" #include "os.h" +#include "packages.h" +#include "process.h" #include "qd.h" +#include "rm.h" #include "sane.h" -#include "utility.h" -#include "loader.h" -#include "macos/traps.h" #include "stackframe.h" +#include "utility.h" + + + // yuck. TST.W d0 extern "C" void cpuSetFlagsNZ00NewW(UWO res); @@ -80,6 +88,11 @@ namespace ToolBox { case 0x0020: return MM::TempDisposeHandle(); + case 0x0037: + return Process::GetCurrentProcess(); + + case 0x003a: + return Process::GetProcessInformation(); default: fprintf(stderr, "OSDispatch: selector %04x not implemented\n",