Permalink
Browse files

Windows: In-depth cleanup (see details)

-Fix x64 builds for Windows. Now all configurations compile.
-Remove the non-working rebase stuff.
-Remove the Windows fork hack and instead use FreeConsole() to emulate the behavior. This directly allows us to compile with ASLR, which is turned on now.
-Remove the old IPC mechanism for the removed GUI. This is not needed anymore as the GUI wasn't ever supported on anything newer than 1.2
-Remove the WIN32/WINDOWS macros. _WIN32 is supported on all x86-based VC++ targets, so that's what we need.
-Enable optimizations for release builds.
-De-duplicate printf_c(), it was previously copy-pasted into colors.h for configure
-Add the VC++ specific bad files in .gitignore
-Disable PID writing on Windows. This is only making sense for *nix builds.
-Replace the CPU usage retrieval with an algorithm analogous to the *nix behavior. Also supports separated now/total values. (Tested with a dummy busy loop - seems working)
-Removed certain unused functions and variables
-Remove stdint defines from the windows wrapper
-Remove CRT debug alloc. This is a bad idea as it would define a macro to replace free which breaks builds.
-Re-evaluated the warnings list, commented it.
-Moved inspircd_config/_version to include/ to match *nix
-Removed the creation of inspircd_se_config, as it isn't used at all.
-Made non-git builds show as "r0" instead of "r" (thanks to @SaberUK for pointing this out)
-Fixed up m_spanningtree's project paths. Now all configurations (debug/release x86/x64) have been tested and build properly.
-Moved FindDNS out of the wrapper and matched its log behavior with *nix. (It's pointless having it in the wrapper after the recent slimming down)
-Replaced random/srandom wrappers with a mechanism that tries to use Windows' Random API first is no SSL module is loaded.
-Removed more old junk from support for compilers older than VC++ 2010 (we don't have project files for these, so compiling them would be hard anyways)
-Removed the unused ClearConsole()
-Removed unused includes from the wrapper. Also, do not include psapi.h here if we don't link psapi.lib. This should be done where appropriate.
-Made inet_aton an inline function for increased performance
-C4800, performance warning about bool forcing, resolved at all occurrences.
-C4701, uninitialized variable 'cached', resolved at all occurrences.
-dlerror() was migrated out of the wrapper for more thread safety (no global buffer being shared) and increased performance.
-Removed the wrong CRT debug flags. This drains a lot of performance.
-Removed the clock_gettime/gettimeofday wrappers
-Replaced all TCHAR/ANSI mix-ups of functions with the correct respective function.
-Added a block of C4355 for < VS2012
-Update project files for c870714
  • Loading branch information...
1 parent 152bf49 commit 5b9682275e384635a1fd9f7320cf4d9a604a43b4 ChrisTX committed Oct 12, 2012
Showing with 533 additions and 1,287 deletions.
  1. +25 −0 .gitignore
  2. +0 −4 include/bancache.h
  3. +2 −2 include/base.h
  4. +1 −1 include/configparser.h
  5. +0 −4 include/dns.h
  6. +6 −0 include/dynamic.h
  7. +4 −14 include/hash_map.h
  8. +1 −1 include/hashcomp.h
  9. +14 −6 include/inspircd.h
  10. +1 −1 include/modules.h
  11. +1 −1 include/socket.h
  12. +0 −4 include/threadengine.h
  13. +4 −1 include/threadengines/threadengine_win32.h
  14. +5 −10 include/typedefs.h
  15. +1 −1 include/users.h
  16. +30 −4 src/commands/cmd_stats.cpp
  17. +35 −5 src/configreader.cpp
  18. +1 −1 src/dns.cpp
  19. +23 −1 src/dynamic.cpp
  20. +5 −12 src/hashcomp.cpp
  21. +17 −0 src/helperfuncs.cpp
  22. +56 −51 src/inspircd.cpp
  23. +1 −1 src/modmanager_dynamic.cpp
  24. +2 −2 src/modules.cpp
  25. +1 −1 src/modules/extra/m_geoip.cpp
  26. +1 −1 src/modules/extra/m_ldapauth.cpp
  27. +1 −1 src/modules/extra/m_ldapoper.cpp
  28. +1 −1 src/modules/extra/m_mysql.cpp
  29. +1 −1 src/modules/extra/m_regex_pcre.cpp
  30. +1 −1 src/modules/extra/m_sqlite3.cpp
  31. +1 −1 src/modules/extra/m_ssl_gnutls.cpp
  32. +1 −1 src/modules/extra/m_ssl_openssl.cpp
  33. +1 −1 src/modules/m_spanningtree/main.cpp
  34. +2 −2 src/modules/m_spanningtree/resolvers.cpp
  35. +1 −1 src/modules/m_spanningtree/utils.cpp
  36. +3 −7 src/modules/m_spanningtree/utils.h
  37. +2 −5 src/modules/m_watch.cpp
  38. +1 −1 src/modules/ssl.h
  39. +5 −3 src/server.cpp
  40. +6 −6 src/socketengine.cpp
  41. +1 −1 src/socketengines/socketengine_poll.cpp
  42. +2 −2 src/socketengines/socketengine_select.cpp
  43. +10 −1 src/threadengines/threadengine_win32.cpp
  44. +1 −3 win/{colours.h → colors.h}
  45. +64 −129 win/configure.cpp
  46. +28 −23 win/configure.vcxproj
  47. +47 −47 win/inspircd.vcxproj
  48. +2 −2 win/inspircd_memory_functions.cpp
  49. +0 −196 win/inspircd_namedpipe.cpp
  50. +0 −55 win/inspircd_namedpipe.h
  51. +13 −496 win/inspircd_win32wrapper.cpp
  52. +49 −122 win/inspircd_win32wrapper.h
  53. +28 −30 win/m_spanningtree.vcxproj
  54. +0 −3 win/rebase.bat
  55. +24 −16 win/win32service.cpp
View
@@ -9,6 +9,7 @@
/inspircd
/org.inspircd.plist
/run
+/bin
/include/inspircd_config.h
/include/inspircd_version.h
@@ -26,3 +27,27 @@
/src/modules/m_sqlite3.cpp
/src/modules/m_ssl_gnutls.cpp
/src/modules/m_ssl_openssl.cpp
+
+*.ilk
+*.lib
+*.pdb
+*.exp
+*.dll
+*.exe
+/src/commands/debug
+/src/commands/release
+/src/commands/debug_x64
+/src/commands/release_x64
+/src/commands/commands.mak
+/src/modules/debug
+/src/modules/release
+/src/modules/debug_x64
+/src/modules/release_x64
+/src/modules/modules.mak
+/win/x64*
+/win/debug*
+/win/release*
+/win/*.suo
+/win/*.sdf
+/win/*.user
+/win/*.opensdf
View
@@ -65,11 +65,7 @@ class CoreExport BanCacheHit
/* A container of ban cache items.
* must be defined after class BanCacheHit.
*/
-#if defined(WINDOWS) && !defined(HASHMAP_DEPRECATED)
-typedef nspace::hash_map<std::string, BanCacheHit*, nspace::hash_compare<std::string, std::less<std::string> > > BanCacheHash;
-#else
typedef nspace::hash_map<std::string, BanCacheHit*, nspace::hash<std::string> > BanCacheHash;
-#endif
/** A manager for ban cache, which allocates and deallocates and checks cached bans.
*/
View
@@ -157,15 +157,15 @@ class CoreExport reference
return *this;
}
- inline operator bool() const { return value; }
+ inline operator bool() const { return (value != NULL); }
inline operator T*() const { return value; }
inline T* operator->() const { return value; }
inline T& operator*() const { return *value; }
inline bool operator<(const reference<T>& other) const { return value < other.value; }
inline bool operator>(const reference<T>& other) const { return value > other.value; }
static inline void* operator new(size_t, void* m) { return m; }
private:
-#ifndef WIN32
+#ifndef _WIN32
static void* operator new(size_t);
static void operator delete(void*);
#endif
@@ -63,7 +63,7 @@ struct FileWrapper
FILE* const f;
bool close_with_pclose;
FileWrapper(FILE* file, bool use_pclose = false) : f(file), close_with_pclose(use_pclose) {}
- operator bool() { return f; }
+ operator bool() { return (f != NULL); }
operator FILE*() { return f; }
~FileWrapper()
{
View
@@ -102,11 +102,7 @@ class CoreExport CachedQuery
/** DNS cache information. Holds IPs mapped to hostnames, and hostnames mapped to IPs.
*/
-#if defined(WINDOWS) && !defined(HASHMAP_DEPRECATED)
-typedef nspace::hash_map<irc::string, CachedQuery, nspace::hash_compare<irc::string> > dnscache;
-#else
typedef nspace::hash_map<irc::string, CachedQuery, irc::hash> dnscache;
-#endif
/**
* Error types that class Resolver can emit to its error method.
View
@@ -33,6 +33,12 @@ class CoreExport DLLManager : public classbase
*/
std::string err;
+#ifdef _WIN32
+ /** Sets the last error string
+ */
+ void RetrieveLastError();
+#endif
+
public:
/** This constructor loads the module using dlopen()
* @param fname The filename to load. This should be within
View
@@ -28,7 +28,7 @@
/** Where hash_map is varies from compiler to compiler
* as it is not standard unless we have tr1.
*/
- #ifndef WIN32
+ #ifndef _WIN32
#ifdef HASHMAP_DEPRECATED
// GCC4+ has deprecated hash_map and uses tr1. But of course, uses a different include to MSVC. FOR FUCKS SAKE.
#include <tr1/unordered_map>
@@ -41,19 +41,9 @@
#define END_HASHMAP_NAMESPACE }
#endif
#else
- #if _MSC_VER >= 1600
- // New MSVC has tr1. Just to make things fucked up, though, MSVC and GCC use different includes! FFS.
- #include <unordered_map>
- #define HAS_TR1_UNORDERED
- #define HASHMAP_DEPRECATED
- #else
- /** Oddball windows namespace for hash_map */
- #include <hash_map>
- #define nspace stdext
- using stdext::hash_map;
- #define BEGIN_HASHMAP_NAMESPACE namespace nspace {
- #define END_HASHMAP_NAMESPACE }
- #endif
+ #include <unordered_map>
+ #define HAS_TR1_UNORDERED
+ #define HASHMAP_DEPRECATED
#endif
// tr1: restoring sanity to our headers. now if only compiler vendors could agree on a FUCKING INCLUDE FILE.
View
@@ -598,7 +598,7 @@ BEGIN_HASHMAP_NAMESPACE
/** Hashing function to hash irc::string
*/
-#if defined(WINDOWS) && !defined(HAS_TR1_UNORDERED)
+#if defined(_WIN32) && !defined(HAS_TR1_UNORDERED)
template<> class CoreExport hash_compare<irc::string, std::less<irc::string> >
{
public:
View
@@ -31,7 +31,7 @@
#define _LARGEFILE_SOURCE
#endif
-#ifndef WIN32
+#ifndef _WIN32
#define DllExport
#define CoreExport
#define printf_c printf
@@ -55,7 +55,7 @@
#include <cstring>
#include <climits>
#include <cstdio>
-#ifndef WIN32
+#ifndef _WIN32
#include <unistd.h>
#endif
@@ -232,12 +232,24 @@ class serverstats
/** Total bytes of data received
*/
unsigned long statsRecv;
+#ifdef _WIN32
+ /** Cpu usage at last sample
+ */
+ FILETIME LastCPU;
+ /** Time QP sample was read
+ */
+ LARGE_INTEGER LastSampled;
+ /** QP frequency
+ */
+ LARGE_INTEGER QPFrequency;
+#else
/** Cpu usage at last sample
*/
timeval LastCPU;
/** Time last sample was read
*/
timespec LastSampled;
+#endif
/** The constructor initializes all the counts to zero
*/
serverstats()
@@ -308,10 +320,6 @@ class CoreExport InspIRCd
*/
char ReadBuffer[65535];
-#ifdef WIN32
- IPC* WindowsIPC;
-#endif
-
public:
/** Global cull list, will be processed on next iteration
View
@@ -1696,7 +1696,7 @@ struct AllModuleList {
* and functions needed to make a module loadable by the OS.
* It defines the class factory and external init_module function.
*/
-#ifdef WINDOWS
+#ifdef _WIN32
#define MODULE_INIT(y) \
extern "C" DllExport Module * MODULE_INIT_SYM() \
View
@@ -25,7 +25,7 @@
#ifndef INSPIRCD_SOCKET_H
#define INSPIRCD_SOCKET_H
-#ifndef WIN32
+#ifndef _WIN32
#include <arpa/inet.h>
#include <sys/time.h>
@@ -27,10 +27,6 @@
#include "inspircd_config.h"
#include "base.h"
-#ifdef WINDOWS
-#include "threadengines/threadengine_win32.h"
-#endif
-
class ThreadData;
/** Derive from this class to implement your own threaded sections of
@@ -108,12 +108,15 @@ class ThreadQueueData
public:
ThreadQueueData()
{
- InitializeCriticalSection(&mutex);
event = CreateEvent(NULL, false, false, NULL);
+ if (event == NULL)
+ throw CoreException("CreateEvent() failed in ThreadQueueData::ThreadQueueData()!");
+ InitializeCriticalSection(&mutex);
}
~ThreadQueueData()
{
+ CloseHandle(event);
DeleteCriticalSection(&mutex);
}
View
@@ -56,17 +56,12 @@ struct ResourceRecord;
#include "hashcomp.h"
#include "base.h"
-#if defined(WINDOWS) && !defined(HASHMAP_DEPRECATED)
- typedef nspace::hash_map<std::string, User*, nspace::hash_compare<std::string, std::less<std::string> > > user_hash;
- typedef nspace::hash_map<std::string, Channel*, nspace::hash_compare<std::string, std::less<std::string> > > chan_hash;
+#ifdef HASHMAP_DEPRECATED
+ typedef nspace::hash_map<std::string, User*, nspace::insensitive, irc::StrHashComp> user_hash;
+ typedef nspace::hash_map<std::string, Channel*, nspace::insensitive, irc::StrHashComp> chan_hash;
#else
- #ifdef HASHMAP_DEPRECATED
- typedef nspace::hash_map<std::string, User*, nspace::insensitive, irc::StrHashComp> user_hash;
- typedef nspace::hash_map<std::string, Channel*, nspace::insensitive, irc::StrHashComp> chan_hash;
- #else
- typedef nspace::hash_map<std::string, User*, nspace::hash<std::string>, irc::StrHashComp> user_hash;
- typedef nspace::hash_map<std::string, Channel*, nspace::hash<std::string>, irc::StrHashComp> chan_hash;
- #endif
+ typedef nspace::hash_map<std::string, User*, nspace::hash<std::string>, irc::StrHashComp> user_hash;
+ typedef nspace::hash_map<std::string, Channel*, nspace::hash<std::string>, irc::StrHashComp> chan_hash;
#endif
/** A list of failed port bindings, used for informational purposes on startup */
View
@@ -60,7 +60,7 @@ enum UserModes {
*/
enum RegistrationState {
-#ifndef WIN32 // Burlex: This is already defined in win32, luckily it is still 0.
+#ifndef _WIN32 // Burlex: This is already defined in win32, luckily it is still 0.
REG_NONE = 0, /* Has sent nothing */
#endif
@@ -23,8 +23,9 @@
#include "xline.h"
#include "commands/cmd_whowas.h"
-#ifdef WINDOWS
-# pragma comment(lib, "psapi.lib") // For GetProcessMemoryInfo()
+#ifdef _WIN32
+#include <psapi.h>
+#pragma comment(lib, "psapi.lib") // For GetProcessMemoryInfo()
#endif
/** Handle /STATS. These command handlers can be reloaded by the core,
@@ -240,7 +241,7 @@ void CommandStats::DoStats(char statschar, User* user, string_list &results)
results.push_back(sn+" 249 "+user->nick+" :Bandwidth out: "+ConvToStr(kbitpersec_out_s)+" kilobits/sec");
results.push_back(sn+" 249 "+user->nick+" :Bandwidth in: "+ConvToStr(kbitpersec_in_s)+" kilobits/sec");
-#ifndef WIN32
+#ifndef _WIN32
/* Moved this down here so all the not-windows stuff (look w00tie, I didn't say win32!) is in one ifndef.
* Also cuts out some identical code in both branches of the ifndef. -- Om
*/
@@ -278,7 +279,32 @@ void CommandStats::DoStats(char statschar, User* user, string_list &results)
results.push_back(sn+" 249 "+user->nick+" :Total allocation: "+ConvToStr((MemCounters.WorkingSetSize + MemCounters.PagefileUsage) / 1024)+"K");
results.push_back(sn+" 249 "+user->nick+" :Pagefile usage: "+ConvToStr(MemCounters.PagefileUsage / 1024)+"K");
results.push_back(sn+" 249 "+user->nick+" :Page faults: "+ConvToStr(MemCounters.PageFaultCount));
- results.push_back(sn+" 249 "+user->nick+" :CPU Usage: " + ConvToStr(getcpu()) + "%");
+ }
+
+ FILETIME CreationTime;
+ FILETIME ExitTime;
+ FILETIME KernelTime;
+ FILETIME UserTime;
+ LARGE_INTEGER ThisSample;
+ if(GetProcessTimes(GetCurrentProcess(), &CreationTime, &ExitTime, &KernelTime, &UserTime) &&
+ QueryPerformanceCounter(&ThisSample))
+ {
+ KernelTime.dwHighDateTime += UserTime.dwHighDateTime;
+ KernelTime.dwLowDateTime += UserTime.dwLowDateTime;
+ double n_eaten = (double)( ( (uint64_t)(KernelTime.dwHighDateTime - ServerInstance->stats->LastCPU.dwHighDateTime) << 32 ) + (uint64_t)(KernelTime.dwLowDateTime - ServerInstance->stats->LastCPU.dwLowDateTime) )/100000;
+ double n_elapsed = (double)(ThisSample.QuadPart - ServerInstance->stats->LastSampled.QuadPart) / ServerInstance->stats->QPFrequency.QuadPart;
+ double per = (n_eaten/n_elapsed);
+
+ char percent[30];
+
+ snprintf(percent, 30, "%03.5f%%", per);
+ results.push_back(sn+" 249 "+user->nick+" :CPU Use (now): "+percent);
+
+ n_elapsed = ServerInstance->Time() - ServerInstance->startup_time;
+ n_eaten = (double)(( (uint64_t)(KernelTime.dwHighDateTime) << 32 ) + (uint64_t)(KernelTime.dwLowDateTime))/100000;
+ per = (n_eaten / n_elapsed);
+ snprintf(percent, 30, "%03.5f%%", per);
+ results.push_back(sn+" 249 "+user->nick+" :CPU Use (total): "+percent);
}
#endif
}
View
@@ -28,6 +28,10 @@
#include "exitcodes.h"
#include "commands/cmd_whowas.h"
#include "configparser.h"
+#ifdef _WIN32
+#include <Iphlpapi.h>
+#pragma comment(lib, "Iphlpapi.lib")
+#endif
ServerConfig::ServerConfig()
{
@@ -140,15 +144,41 @@ bool ServerConfig::ApplyDisabledCommands(const std::string& data)
return true;
}
-#ifdef WINDOWS
-// Note: the windows validator is in win32wrapper.cpp
-void FindDNS(std::string& server);
-#else
static void FindDNS(std::string& server)
{
if (!server.empty())
return;
+#ifdef _WIN32
+ // attempt to look up their nameserver from the system
+ ServerInstance->Logs->Log("CONFIG",DEFAULT,"WARNING: <dns:server> not defined, attempting to find a working server in the system settings...");
+
+ PFIXED_INFO pFixedInfo;
+ DWORD dwBufferSize = sizeof(FIXED_INFO);
+ pFixedInfo = (PFIXED_INFO) HeapAlloc(GetProcessHeap(), 0, sizeof(FIXED_INFO));
+
+ if(pFixedInfo)
+ {
+ if (GetNetworkParams(pFixedInfo, &dwBufferSize) == ERROR_BUFFER_OVERFLOW) {
+ HeapFree(GetProcessHeap(), 0, pFixedInfo);
+ pFixedInfo = (PFIXED_INFO) HeapAlloc(GetProcessHeap(), 0, dwBufferSize);
+ }
+
+ if(pFixedInfo) {
+ if (GetNetworkParams(pFixedInfo, &dwBufferSize) == NO_ERROR)
+ server = pFixedInfo->DnsServerList.IpAddress.String;
+
+ HeapFree(GetProcessHeap(), 0, pFixedInfo);
+ }
+
+ if(!server.empty())
+ {
+ ServerInstance->Logs->Log("CONFIG",DEFAULT,"<dns:server> set to '%s' as first active resolver in the system settings.", server.c_str());
+ return;
+ }
+ }
+ ServerInstance->Logs->Log("CONFIG",DEFAULT,"No viable nameserver found! Defaulting to nameserver '127.0.0.1'!");
+#else
// attempt to look up their nameserver from /etc/resolv.conf
ServerInstance->Logs->Log("CONFIG",DEFAULT,"WARNING: <dns:server> not defined, attempting to find working server in /etc/resolv.conf...");
@@ -168,9 +198,9 @@ static void FindDNS(std::string& server)
}
ServerInstance->Logs->Log("CONFIG",DEFAULT,"/etc/resolv.conf contains no viable nameserver entries! Defaulting to nameserver '127.0.0.1'!");
+#endif
server = "127.0.0.1";
}
-#endif
static void ReadXLine(ServerConfig* conf, const std::string& tag, const std::string& key, XLineFactory* make)
{
Oops, something went wrong.

0 comments on commit 5b96822

Please sign in to comment.