Linux header cleanups. Windows side will follow.

develop
Petr Mrázek 2011-04-10 10:19:15 +02:00
parent 425971ef8c
commit bb04aa1a32
28 changed files with 280 additions and 123 deletions

@ -1,9 +1,15 @@
#include "Internal.h" #include "Internal.h"
#include <string>
#include <vector>
#include <map>
#include <cstring>
using namespace std;
#include "private/ContextShared.h" #include "private/ContextShared.h"
#include "dfhack/VersionInfo.h" #include "dfhack/VersionInfo.h"
#include "dfhack/DFProcess.h" #include "dfhack/DFProcess.h"
#include "dfhack/DFModule.h" #include "dfhack/DFModule.h"
using namespace DFHack; using namespace DFHack;
DFContextShared::DFContextShared() DFContextShared::DFContextShared()

@ -24,6 +24,11 @@ distribution.
#include "Internal.h" #include "Internal.h"
#include <string>
#include <vector>
#include <cstring>
using namespace std;
#include "dfhack/DFProcess.h" #include "dfhack/DFProcess.h"
#include "dfhack/DFProcessEnumerator.h" #include "dfhack/DFProcessEnumerator.h"
#include "dfhack/DFContext.h" #include "dfhack/DFContext.h"

@ -24,6 +24,11 @@ distribution.
#include "Internal.h" #include "Internal.h"
#include <string>
#include <vector>
#include <map>
using namespace std;
#include "dfhack/VersionInfoFactory.h" #include "dfhack/VersionInfoFactory.h"
#include "dfhack/DFProcess.h" #include "dfhack/DFProcess.h"
#include "dfhack/DFProcessEnumerator.h" #include "dfhack/DFProcessEnumerator.h"

@ -22,6 +22,12 @@ must not be misrepresented as being the original software.
distribution. distribution.
*/ */
#include "Internal.h" #include "Internal.h"
#include <string>
#include <vector>
#include <map>
#include <cstring>
using namespace std;
#include "SHMProcess.h" #include "SHMProcess.h"
#include "ProcessFactory.h" #include "ProcessFactory.h"
#include "dfhack/VersionInfo.h" #include "dfhack/VersionInfo.h"

@ -22,6 +22,14 @@ must not be misrepresented as being the original software.
distribution. distribution.
*/ */
#include "Internal.h" #include "Internal.h"
#include "PlatformInternal.h"
#include <string>
#include <vector>
#include <map>
#include <cstdio>
using namespace std;
#include "SHMProcess.h" #include "SHMProcess.h"
#include "dfhack/VersionInfo.h" #include "dfhack/VersionInfo.h"
#include "dfhack/DFError.h" #include "dfhack/DFError.h"
@ -36,7 +44,7 @@ distribution.
#include <sys/time.h> #include <sys/time.h>
#include <time.h> #include <time.h>
#include <sched.h> #include <sched.h>
#include <md5wrapper.h>
using namespace DFHack; using namespace DFHack;
SHMProcess::Private::Private(SHMProcess * self_) SHMProcess::Private::Private(SHMProcess * self_)

@ -22,6 +22,13 @@ must not be misrepresented as being the original software.
distribution. distribution.
*/ */
#include "Internal.h" #include "Internal.h"
#include <string>
#include <vector>
#include <map>
#include <cstdio>
using namespace std;
#include "LinuxProcess.h" #include "LinuxProcess.h"
#include "dfhack/VersionInfo.h" #include "dfhack/VersionInfo.h"
#include "dfhack/DFError.h" #include "dfhack/DFError.h"

@ -22,15 +22,28 @@ must not be misrepresented as being the original software.
distribution. distribution.
*/ */
#include "Internal.h" #include "Internal.h"
#include "PlatformInternal.h"
#include <string>
#include <vector>
#include <map>
#include <cstdio>
#include <cstring>
#include <fstream>
using namespace std;
#include "LinuxProcess.h" #include "LinuxProcess.h"
#include "ProcessFactory.h" #include "ProcessFactory.h"
#include "MicrosoftSTL.h" #include "MicrosoftSTL.h"
#include "dfhack/VersionInfo.h" #include "dfhack/VersionInfo.h"
#include "dfhack/DFError.h" #include "dfhack/DFError.h"
using namespace DFHack;
#include <errno.h> #include <errno.h>
#include <sys/ptrace.h> #include <sys/ptrace.h>
#include <stdio.h>
using namespace DFHack; #include <md5wrapper.h>
namespace { namespace {
class WineProcess : public LinuxProcessBase class WineProcess : public LinuxProcessBase

@ -22,12 +22,22 @@ must not be misrepresented as being the original software.
distribution. distribution.
*/ */
#include "Internal.h" #include "Internal.h"
#include "PlatformInternal.h"
#include <string>
#include <vector>
#include <map>
#include <cstdio>
#include <cstring>
using namespace std;
#include "LinuxProcess.h" #include "LinuxProcess.h"
#include "ProcessFactory.h" #include "ProcessFactory.h"
#include "dfhack/VersionInfo.h" #include "dfhack/VersionInfo.h"
#include "dfhack/DFError.h" #include "dfhack/DFError.h"
#include <errno.h> #include <errno.h>
#include <sys/ptrace.h> #include <sys/ptrace.h>
#include <md5wrapper.h>
using namespace DFHack; using namespace DFHack;
namespace { namespace {

@ -23,6 +23,17 @@ distribution.
*/ */
#include "Internal.h" #include "Internal.h"
#include "PlatformInternal.h"
#include <string>
#include <vector>
#include <cstdio>
#include <map>
#include <cstring>
#include <cassert>
#include <cstdlib>
using namespace std;
#include "ProcessFactory.h" #include "ProcessFactory.h"
#include "dfhack/VersionInfoFactory.h" #include "dfhack/VersionInfoFactory.h"
@ -119,24 +130,14 @@ Process * BadProcesses::operator[](uint32_t index)
//FIXME: wasteful //FIXME: wasteful
Process *ProcessEnumerator::Private::GetProcessObject(ProcessID ID) Process *ProcessEnumerator::Private::GetProcessObject(ProcessID ID)
{ {
/*
Process *p1 = createSHMProcess(ID.pid, meminfo);
if(p1->isIdentified())
return p1;
else
delete p1;
*/
Process *p2 = createNormalProcess(ID.pid, meminfo); Process *p2 = createNormalProcess(ID.pid, meminfo);
if(p2->isIdentified()) if(p2->isIdentified())
{ {
//cout << "IS OK" << endl;
return p2; return p2;
} }
else else
{ {
//cout << "ABOUT TO DELETE" << endl;
delete p2; delete p2;
//cout << "AFTER DELETE" << endl;
} }
#ifdef LINUX_BUILD #ifdef LINUX_BUILD
Process *p3 = createWineProcess(ID.pid, meminfo); Process *p3 = createWineProcess(ID.pid, meminfo);

@ -23,10 +23,16 @@ distribution.
*/ */
#include "Internal.h" #include "Internal.h"
#include <string>
#include <vector>
#include <map>
using namespace std;
#include "MicrosoftSTL.h" #include "MicrosoftSTL.h"
#include "dfhack/DFProcess.h" #include "dfhack/DFProcess.h"
#include "dfhack/VersionInfo.h" #include "dfhack/VersionInfo.h"
#include <string>
using namespace DFHack; using namespace DFHack;
void MicrosoftSTL::init(Process* self) void MicrosoftSTL::init(Process* self)

@ -23,15 +23,21 @@ distribution.
*/ */
#include "Internal.h" #include "Internal.h"
#include <string>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
#include "dfhack/VersionInfo.h" #include "dfhack/VersionInfo.h"
#include "dfhack/DFError.h" #include "dfhack/DFError.h"
#include "dfhack/DFProcess.h" #include "dfhack/DFProcess.h"
#include <algorithm> using namespace DFHack;
//Inital amount of space in levels vector (since we usually know the number, efficient!) //Inital amount of space in levels vector (since we usually know the number, efficient!)
#define NUM_RESERVE_LVLS 20 #define NUM_RESERVE_LVLS 20
#define NUM_RESERVE_MOODS 6 #define NUM_RESERVE_MOODS 6
using namespace DFHack;
//FIXME: put those in some shared file //FIXME: put those in some shared file
template<template <typename> class P = std::less > template<template <typename> class P = std::less >

@ -24,13 +24,19 @@ distribution.
#include "Internal.h" #include "Internal.h"
#include <string>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
#include "dfhack/VersionInfoFactory.h" #include "dfhack/VersionInfoFactory.h"
#include "dfhack/VersionInfo.h" #include "dfhack/VersionInfo.h"
#include "dfhack/DFError.h" #include "dfhack/DFError.h"
#include <algorithm>
using namespace DFHack; using namespace DFHack;
#include <tinyxml.h>
template<class _T1, class _T2, class _T3> template<class _T1, class _T2, class _T3>
struct triple struct triple
{ {

@ -23,6 +23,12 @@ distribution.
*/ */
#include "Internal.h" #include "Internal.h"
#include <string>
#include <vector>
#include <map>
using namespace std;
#include "ContextShared.h" #include "ContextShared.h"
#include "dfhack/VersionInfo.h" #include "dfhack/VersionInfo.h"

@ -23,6 +23,12 @@ distribution.
*/ */
#include "Internal.h" #include "Internal.h"
#include <string>
#include <vector>
#include <map>
using namespace std;
#include "ContextShared.h" #include "ContextShared.h"
#include "dfhack/VersionInfo.h" #include "dfhack/VersionInfo.h"

@ -23,6 +23,13 @@ distribution.
*/ */
#include "Internal.h" #include "Internal.h"
#include <string>
#include <vector>
#include <map>
#include <cstring>
using namespace std;
#include "ContextShared.h" #include "ContextShared.h"
#include "dfhack/VersionInfo.h" #include "dfhack/VersionInfo.h"

@ -23,6 +23,12 @@ distribution.
*/ */
#include "Internal.h" #include "Internal.h"
#include <string>
#include <vector>
#include <map>
using namespace std;
#include "ContextShared.h" #include "ContextShared.h"
#include "dfhack/VersionInfo.h" #include "dfhack/VersionInfo.h"

@ -23,6 +23,12 @@ distribution.
*/ */
#include "Internal.h" #include "Internal.h"
#include <string>
#include <vector>
#include <map>
using namespace std;
#include "ContextShared.h" #include "ContextShared.h"
#include "dfhack/modules/Gui.h" #include "dfhack/modules/Gui.h"
#include "dfhack/DFProcess.h" #include "dfhack/DFProcess.h"
@ -30,7 +36,6 @@ distribution.
#include "dfhack/DFTypes.h" #include "dfhack/DFTypes.h"
#include "dfhack/DFError.h" #include "dfhack/DFError.h"
#include "ModuleFactory.h" #include "ModuleFactory.h"
using namespace DFHack; using namespace DFHack;
Module* DFHack::createGui(DFContextShared * d) Module* DFHack::createGui(DFContextShared * d)

@ -23,6 +23,13 @@ distribution.
*/ */
#include "Internal.h" #include "Internal.h"
#include <string>
#include <vector>
#include <cstdio>
#include <map>
using namespace std;
#include "ContextShared.h" #include "ContextShared.h"
#include "dfhack/DFTypes.h" #include "dfhack/DFTypes.h"
#include "dfhack/VersionInfo.h" #include "dfhack/VersionInfo.h"

@ -23,13 +23,20 @@ distribution.
*/ */
#include "Internal.h" #include "Internal.h"
#include <string>
#include <vector>
#include <map>
#include <set>
#include <cassert>
using namespace std;
#include "ContextShared.h" #include "ContextShared.h"
#include "dfhack/modules/Maps.h" #include "dfhack/modules/Maps.h"
#include "dfhack/DFError.h" #include "dfhack/DFError.h"
#include "dfhack/VersionInfo.h" #include "dfhack/VersionInfo.h"
#include "dfhack/DFProcess.h" #include "dfhack/DFProcess.h"
#include "dfhack/DFVector.h" #include "dfhack/DFVector.h"
#include <set>
#include "ModuleFactory.h" #include "ModuleFactory.h"
#define MAPS_GUARD if(!d->Started) throw DFHack::Error::ModuleNotInitialized(); #define MAPS_GUARD if(!d->Started) throw DFHack::Error::ModuleNotInitialized();

@ -23,6 +23,13 @@ distribution.
*/ */
#include "Internal.h" #include "Internal.h"
#include <string>
#include <vector>
#include <map>
#include <cstring>
using namespace std;
#include "ContextShared.h" #include "ContextShared.h"
#include "dfhack/DFTypes.h" #include "dfhack/DFTypes.h"
#include "dfhack/modules/Materials.h" #include "dfhack/modules/Materials.h"

@ -23,6 +23,13 @@ distribution.
*/ */
#include "Internal.h" #include "Internal.h"
#include <string>
#include <vector>
#include <map>
#include <cassert>
using namespace std;
#include "ContextShared.h" #include "ContextShared.h"
#include "dfhack/modules/Translation.h" #include "dfhack/modules/Translation.h"
#include "dfhack/VersionInfo.h" #include "dfhack/VersionInfo.h"
@ -30,7 +37,6 @@ distribution.
#include "dfhack/DFVector.h" #include "dfhack/DFVector.h"
#include "dfhack/DFTypes.h" #include "dfhack/DFTypes.h"
#include "ModuleFactory.h" #include "ModuleFactory.h"
using namespace DFHack; using namespace DFHack;
Module* DFHack::createTranslation(DFContextShared * d) Module* DFHack::createTranslation(DFContextShared * d)

@ -23,6 +23,12 @@ distribution.
*/ */
#include "Internal.h" #include "Internal.h"
#include <string>
#include <vector>
#include <map>
using namespace std;
#include "ContextShared.h" #include "ContextShared.h"
#include "dfhack/VersionInfo.h" #include "dfhack/VersionInfo.h"
@ -32,7 +38,6 @@ distribution.
#include "dfhack/modules/Vegetation.h" #include "dfhack/modules/Vegetation.h"
#include "dfhack/modules/Translation.h" #include "dfhack/modules/Translation.h"
#include "ModuleFactory.h" #include "ModuleFactory.h"
using namespace DFHack; using namespace DFHack;
Module* DFHack::createVegetation(DFContextShared * d) Module* DFHack::createVegetation(DFContextShared * d)

@ -22,6 +22,12 @@ must not be misrepresented as being the original software.
distribution. distribution.
*/ */
#include "Internal.h" #include "Internal.h"
#include <string>
#include <vector>
#include <cstring>
#include <iostream>
using namespace std;
#include "dfhack/modules/WindowIO.h" #include "dfhack/modules/WindowIO.h"
#include <X11/Xlib.h> //need for X11 functions #include <X11/Xlib.h> //need for X11 functions

@ -23,6 +23,12 @@ distribution.
*/ */
#include "Internal.h" #include "Internal.h"
#include <string>
#include <vector>
#include <map>
#include <cstring>
using namespace std;
#include "ContextShared.h" #include "ContextShared.h"
#include "dfhack/modules/World.h" #include "dfhack/modules/World.h"
#include "dfhack/DFProcess.h" #include "dfhack/DFProcess.h"

@ -45,103 +45,8 @@ distribution.
// one file for telling the MSVC compiler where it can shove its pointless warnings // one file for telling the MSVC compiler where it can shove its pointless warnings
#include "dfhack/DFPragma.h" #include "dfhack/DFPragma.h"
// basic stl containers and IO stuff
#include <string>
#include <vector>
#include <map>
#include <fstream>
#include <iostream>
using namespace std;
// C99 integer types // C99 integer types
#include "dfhack/DFIntegers.h" #include "dfhack/DFIntegers.h"
// C includes
#include <assert.h>
#include <string.h>
#include <stdlib.h>
// platform includes and defines
#ifdef LINUX_BUILD
#include <sys/types.h>
#include <sys/ptrace.h>
#include <dirent.h>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/wait.h>
#else
// WINDOWS
#define _WIN32_WINNT 0x0501 // needed for INPUT struct
#define WINVER 0x0501 // OpenThread(), PSAPI, Toolhelp32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <winnt.h>
#include <psapi.h>
#include <tlhelp32.h>
//#include <Dbghelp.h> // NOT present in mingw32
typedef LONG NTSTATUS;
#define STATUS_SUCCESS ((NTSTATUS)0x00000000L)
// FIXME: it is uncertain how these map to 64bit
typedef struct _DEBUG_BUFFER
{
HANDLE SectionHandle;
PVOID SectionBase;
PVOID RemoteSectionBase;
ULONG SectionBaseDelta;
HANDLE EventPairHandle;
ULONG Unknown[2];
HANDLE RemoteThreadHandle;
ULONG InfoClassMask;
ULONG SizeOfInfo;
ULONG AllocatedSize;
ULONG SectionSize;
PVOID ModuleInformation;
PVOID BackTraceInformation;
PVOID HeapInformation;
PVOID LockInformation;
PVOID Reserved[8];
} DEBUG_BUFFER, *PDEBUG_BUFFER;
typedef struct _DEBUG_HEAP_INFORMATION
{
ULONG Base; // 0×00
ULONG Flags; // 0×04
USHORT Granularity; // 0×08
USHORT Unknown; // 0x0A
ULONG Allocated; // 0x0C
ULONG Committed; // 0×10
ULONG TagCount; // 0×14
ULONG BlockCount; // 0×18
ULONG Reserved[7]; // 0x1C
PVOID Tags; // 0×38
PVOID Blocks; // 0x3C
} DEBUG_HEAP_INFORMATION, *PDEBUG_HEAP_INFORMATION;
// RtlQueryProcessDebugInformation.DebugInfoClassMask constants
#define PDI_MODULES 0x01
#define PDI_BACKTRACE 0x02
#define PDI_HEAPS 0x04
#define PDI_HEAP_TAGS 0x08
#define PDI_HEAP_BLOCKS 0x10
#define PDI_LOCKS 0x20
extern "C" __declspec(dllimport) NTSTATUS __stdcall RtlQueryProcessDebugInformation( IN ULONG ProcessId, IN ULONG DebugInfoClassMask, IN OUT PDEBUG_BUFFER DebugBuffer);
extern "C" __declspec(dllimport) PDEBUG_BUFFER __stdcall RtlCreateQueryDebugBuffer( IN ULONG Size, IN BOOLEAN EventPair);
extern "C" __declspec(dllimport) NTSTATUS __stdcall RtlDestroyQueryDebugBuffer( IN PDEBUG_BUFFER DebugBuffer);
#endif
// dfhack dependencies
#include <tinyxml.h>
#include <md5wrapper.h>
/*
#if defined(_MSC_VER) && _MSC_VER >= 1400
#define fill_char_buf(buf, str) strcpy_s((buf), sizeof(buf) / sizeof((buf)[0]), (str).c_str())
#else
#define fill_char_buf(buf, str) strncpy((buf), (str).c_str(), sizeof(buf) / sizeof((buf)[0]))
#endif
*/
#endif // DFCOMMONINTERNAL_H_INCLUDED #endif // DFCOMMONINTERNAL_H_INCLUDED

@ -0,0 +1,99 @@
/*
* www.sourceforge.net/projects/dfhack
* Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any
* damages arising from the use of this software.
*
* Permission is granted to anyone to use this software for any
* purpose, including commercial applications, and to alter it and
* redistribute it freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must
* not claim that you wrote the original software. If you use this
* software in a product, an acknowledgment in the product documentation
* would be appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and
* must not be misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#ifndef DFPLATFORMINTERNAL_H_INCLUDED
#define DFPLATFORMINTERNAL_H_INCLUDED
// platform includes and defines
#ifdef LINUX_BUILD
#include <sys/types.h>
#include <sys/ptrace.h>
#include <dirent.h>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/wait.h>
#else
// WINDOWS
#define _WIN32_WINNT 0x0501 // needed for INPUT struct
#define WINVER 0x0501 // OpenThread(), PSAPI, Toolhelp32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <winnt.h>
#include <psapi.h>
#include <tlhelp32.h>
//#include <Dbghelp.h> // NOT present in mingw32
typedef LONG NTSTATUS;
#define STATUS_SUCCESS ((NTSTATUS)0x00000000L)
// FIXME: it is uncertain how these map to 64bit
typedef struct _DEBUG_BUFFER
{
HANDLE SectionHandle;
PVOID SectionBase;
PVOID RemoteSectionBase;
ULONG SectionBaseDelta;
HANDLE EventPairHandle;
ULONG Unknown[2];
HANDLE RemoteThreadHandle;
ULONG InfoClassMask;
ULONG SizeOfInfo;
ULONG AllocatedSize;
ULONG SectionSize;
PVOID ModuleInformation;
PVOID BackTraceInformation;
PVOID HeapInformation;
PVOID LockInformation;
PVOID Reserved[8];
} DEBUG_BUFFER, *PDEBUG_BUFFER;
typedef struct _DEBUG_HEAP_INFORMATION
{
ULONG Base; // 0×00
ULONG Flags; // 0×04
USHORT Granularity; // 0×08
USHORT Unknown; // 0x0A
ULONG Allocated; // 0x0C
ULONG Committed; // 0×10
ULONG TagCount; // 0×14
ULONG BlockCount; // 0×18
ULONG Reserved[7]; // 0x1C
PVOID Tags; // 0×38
PVOID Blocks; // 0x3C
} DEBUG_HEAP_INFORMATION, *PDEBUG_HEAP_INFORMATION;
// RtlQueryProcessDebugInformation.DebugInfoClassMask constants
#define PDI_MODULES 0x01
#define PDI_BACKTRACE 0x02
#define PDI_HEAPS 0x04
#define PDI_HEAP_TAGS 0x08
#define PDI_HEAP_BLOCKS 0x10
#define PDI_LOCKS 0x20
extern "C" __declspec(dllimport) NTSTATUS __stdcall RtlQueryProcessDebugInformation( IN ULONG ProcessId, IN ULONG DebugInfoClassMask, IN OUT PDEBUG_BUFFER DebugBuffer);
extern "C" __declspec(dllimport) PDEBUG_BUFFER __stdcall RtlCreateQueryDebugBuffer( IN ULONG Size, IN BOOLEAN EventPair);
extern "C" __declspec(dllimport) NTSTATUS __stdcall RtlDestroyQueryDebugBuffer( IN PDEBUG_BUFFER DebugBuffer);
#endif // WINDOWS
#endif // DFPLATFORMINTERNAL_H_INCLUDED

@ -10,7 +10,7 @@ using namespace std;
std::ostream &operator<<(std::ostream &stream, DFHack::t_gamemodes funzies) std::ostream &operator<<(std::ostream &stream, DFHack::t_gamemodes funzies)
{ {
char * gm[]= const char * gm[]=
{ {
"Fort", "Fort",
"Adventurer", "Adventurer",
@ -21,7 +21,7 @@ std::ostream &operator<<(std::ostream &stream, DFHack::t_gamemodes funzies)
"Kittens!", "Kittens!",
"Worldgen" "Worldgen"
}; };
char * cm[]= const char * cm[]=
{ {
"Managing", "Managing",
"Direct Control", "Direct Control",