00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef __EMULATORUTILITY_PROCESSINFO_H__
00033 #define __EMULATORUTILITY_PROCESSINFO_H__
00034
00035 #include <boost/pool/pool.hpp>
00036
00037 #include "Interface/EmulatorIF.h"
00038 #include "Interface/OpStateIF.h"
00039 #include "Env/Param/ParamExchange.h"
00040
00041 namespace Onikiri {
00042 class SystemIF;
00043
00044 namespace EmulatorUtility {
00045
00046 class VirtualSystem;
00047 class MemorySystem;
00048 class LoaderIF;
00049 class SyscallConvIF;
00050
00051
00052 class ProcessCreateParam : public ParamExchange
00053 {
00054 public:
00055 explicit ProcessCreateParam(int processNumber);
00056 ~ProcessCreateParam();
00057
00058 const String GetTargetBasePath() const;
00059 const String& GetTargetWorkPath() const { return m_targetWorkPath; }
00060 const String& GetCommand() const { return m_command; }
00061 const String& GetCommandArguments() const { return m_commandArguments; }
00062 const String& GetStdinFilename() const { return m_stdinFilename; }
00063 const String& GetStdinFileOpenMode() const { return m_stdinFileOpenMode; }
00064 const String& GetStdoutFilename() const { return m_stdoutFilename; }
00065 const String& GetStderrFilename() const { return m_stderrFilename; }
00066 const u64 GetStackMegaBytes() const { return m_stackMegaBytes; }
00067 private:
00068
00069 int m_processNumber;
00070 String m_targetBasePath;
00071 String m_targetWorkPath;
00072 String m_command;
00073 String m_commandArguments;
00074 String m_stdinFilename;
00075 String m_stdinFileOpenMode;
00076 String m_stdoutFilename;
00077 String m_stderrFilename;
00078 u64 m_stackMegaBytes;
00079
00080 public:
00081 BEGIN_PARAM_MAP_INDEX("/Session/Emulator/Processes/Process", m_processNumber)
00082 PARAM_ENTRY("@TargetBasePath", m_targetBasePath)
00083 PARAM_ENTRY("@TargetWorkPath", m_targetWorkPath)
00084 PARAM_ENTRY("@Command", m_command)
00085 PARAM_ENTRY("@CommandArguments", m_commandArguments)
00086 PARAM_ENTRY("@STDIN", m_stdinFilename)
00087 PARAM_ENTRY("@STDINFileOpenMode", m_stdinFileOpenMode)
00088 PARAM_ENTRY("@STDOUT", m_stdoutFilename)
00089 PARAM_ENTRY("@STDERR", m_stderrFilename)
00090 PARAM_ENTRY("@StackMegaBytes", m_stackMegaBytes)
00091 END_PARAM_MAP()
00092 };
00093
00094
00095 class ProcessState
00096 {
00097 public:
00098 ProcessState(int pid);
00099 ~ProcessState();
00100
00101 template<class Traits>
00102 void Init(const ProcessCreateParam& createParam, SystemIF* simSystem)
00103 {
00104 Init(
00105 createParam,
00106 simSystem,
00107 new typename Traits::SyscallConvType(this),
00108 new typename Traits::LoaderType(),
00109 Traits::IsBigEndian
00110 );
00111 }
00112
00113
00114 u64 GetEntryPoint() const;
00115
00116 u64 GetInitialRegValue(int index) const;
00117
00118 int GetPID() const { return m_pid; }
00119
00120
00121 std::pair<u64, size_t> GetCodeRange() const { return m_codeRange; }
00122
00123 SyscallConvIF* GetSyscallConv() { return m_syscallConv; }
00124 MemorySystem* GetMemorySystem() { return m_memorySystem; }
00125 VirtualSystem* GetVirtualSystem() { return m_virtualSystem; }
00126
00127
00128 void SetThreadUniqueValue(u64 value);
00129 u64 GetThreadUniqueValue();
00130
00131 private:
00132 void Init(const ProcessCreateParam& pcp, SystemIF* simSystem, SyscallConvIF* syscallConv, LoaderIF* loader, bool bigEndian);
00133 void InitStack(const ProcessCreateParam& createParam);
00134 void InitTargetStdIO(const ProcessCreateParam& createParam);
00135
00136 int m_pid;
00137 std::pair<u64, size_t> m_codeRange;
00138 VirtualSystem* m_virtualSystem;
00139 MemorySystem* m_memorySystem;
00140 LoaderIF* m_loader;
00141 SyscallConvIF* m_syscallConv;
00142
00143
00144 std::vector<FILE*> m_autoCloseFile;
00145
00146
00147 u64 m_threadUniqueValue;
00148 };
00149
00150 }
00151 }
00152
00153 #endif