#include "ntp_iocompletionport.h"
#include "isc/win32os.h"
+#ifdef OPENSSL
+# pragma warning(push)
+# pragma warning(disable: 4152)
+# include <openssl/applink.c>
+# pragma warning(pop)
+#endif
+
+#if defined(OPENSSL) && defined(_MSC_VER) && defined(_DEBUG)
+#define WRAP_DBG_MALLOC
+#endif
-/* Handle to SCM for updating service status */
+/*
+ * Globals
+ */
static SERVICE_STATUS_HANDLE hServiceStatus = 0;
static BOOL foreground = FALSE;
static BOOL computer_shutting_down = FALSE;
/*
* Forward declarations
*/
-void uninit_io_completion_port(void);
-int ntpdmain(int argc, char *argv[]);
-void WINAPI ServiceControl(DWORD dwCtrlCode);
-void ntservice_exit(void);
+void uninit_io_completion_port();
+int ntpdmain(int argc, char *argv[]);
+void WINAPI ServiceControl(DWORD dwCtrlCode);
+void ntservice_exit(void);
+
+#ifdef WRAP_DBG_MALLOC
+void *wrap_dbg_malloc(size_t s, const char *f, int l);
+void *wrap_dbg_realloc(void *p, size_t s, const char *f, int l);
+void wrap_dbg_free(void *p);
+#endif
void WINAPI service_main( DWORD argc, LPTSTR *argv )
{
int rc;
int i = 1;
+
+#ifdef OPENSSL
+#ifdef WRAP_DBG_MALLOC
+ CRYPTO_set_mem_ex_functions(wrap_dbg_malloc, wrap_dbg_realloc, wrap_dbg_free);
+#else
+ CRYPTO_malloc_init();
+#endif
+#endif
/* Save the command line parameters */
glb_argc = argc;
glb_argv = argv;
/* Command line users should put -n in the options */
while (argv[i]) {
if (!_strnicmp(argv[i], "-d", 2) ||
- !strcmp(argv[i], "--debug_level") ||
- !strcmp(argv[i], "--set-debug_level") ||
!strcmp(argv[i], "-q") ||
- !strcmp(argv[i], "--quit") ||
- !strcmp(argv[i], "-?") ||
!strcmp(argv[i], "--help") ||
- !strcmp(argv[i], "-n") ||
- !strcmp(argv[i], "--nofork") ||
- !strcmp(argv[i], "--saveconfigquit")) {
+ !strcmp(argv[i], "-n")) {
foreground = TRUE;
break;
}
return TRUE;
}
+
+#if defined(OPENSSL) && defined(_MSC_VER) && defined(_DEBUG)
+/*
+ * OpenSSL malloc overriding uses different parameters
+ * for DEBUG malloc/realloc/free (lacking block type).
+ * Simple wrappers convert.
+ */
+void *wrap_dbg_malloc(size_t s, const char *f, int l)
+{
+ return _malloc_dbg(s, _NORMAL_BLOCK, f, l);
+}
+
+void *wrap_dbg_realloc(void *p, size_t s, const char *f, int l)
+{
+ return _realloc_dbg(p, s, _NORMAL_BLOCK, f, l);
+}
+
+void wrap_dbg_free(void *p)
+{
+ _free_dbg(p, _NORMAL_BLOCK);
+}
+#endif /* defined(OPENSSL) && defined(_MSC_VER) && defined(_DEBUG) */