mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2025-02-25 15:10:48 +01:00
Make the windows process parameter initialization a subsystem
Also, move it from "main" into lib/process
This commit is contained in:
parent
175153a329
commit
178c1821b2
6 changed files with 85 additions and 31 deletions
|
@ -1388,35 +1388,6 @@ tor_run_main(const tor_main_configuration_t *tor_cfg)
|
||||||
{
|
{
|
||||||
int result = 0;
|
int result = 0;
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
#ifndef HeapEnableTerminationOnCorruption
|
|
||||||
#define HeapEnableTerminationOnCorruption 1
|
|
||||||
#endif
|
|
||||||
/* On heap corruption, just give up; don't try to play along. */
|
|
||||||
HeapSetInformation(NULL, HeapEnableTerminationOnCorruption, NULL, 0);
|
|
||||||
|
|
||||||
/* SetProcessDEPPolicy is only supported on 32-bit Windows.
|
|
||||||
* (On 64-bit Windows it always fails, and some compilers don't like the
|
|
||||||
* PSETDEP cast.)
|
|
||||||
* 32-bit Windows defines _WIN32.
|
|
||||||
* 64-bit Windows defines _WIN32 and _WIN64. */
|
|
||||||
#ifndef _WIN64
|
|
||||||
/* Call SetProcessDEPPolicy to permanently enable DEP.
|
|
||||||
The function will not resolve on earlier versions of Windows,
|
|
||||||
and failure is not dangerous. */
|
|
||||||
HMODULE hMod = GetModuleHandleA("Kernel32.dll");
|
|
||||||
if (hMod) {
|
|
||||||
typedef BOOL (WINAPI *PSETDEP)(DWORD);
|
|
||||||
PSETDEP setdeppolicy = (PSETDEP)GetProcAddress(hMod,
|
|
||||||
"SetProcessDEPPolicy");
|
|
||||||
if (setdeppolicy) {
|
|
||||||
/* PROCESS_DEP_ENABLE | PROCESS_DEP_DISABLE_ATL_THUNK_EMULATION */
|
|
||||||
setdeppolicy(3);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif /* !defined(_WIN64) */
|
|
||||||
#endif /* defined(_WIN32) */
|
|
||||||
|
|
||||||
#ifdef EVENT_SET_MEM_FUNCTIONS_IMPLEMENTED
|
#ifdef EVENT_SET_MEM_FUNCTIONS_IMPLEMENTED
|
||||||
event_set_mem_functions(tor_malloc_, tor_realloc_, tor_free_);
|
event_set_mem_functions(tor_malloc_, tor_realloc_, tor_free_);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include "lib/cc/torint.h"
|
#include "lib/cc/torint.h"
|
||||||
|
|
||||||
#include "lib/err/torerr_sys.h"
|
#include "lib/err/torerr_sys.h"
|
||||||
|
#include "lib/process/winprocess_sys.h"
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
|
@ -16,6 +17,7 @@
|
||||||
* Global list of the subsystems in Tor, in the order of their initialization.
|
* Global list of the subsystems in Tor, in the order of their initialization.
|
||||||
**/
|
**/
|
||||||
const subsys_fns_t *tor_subsystems[] = {
|
const subsys_fns_t *tor_subsystems[] = {
|
||||||
|
&sys_winprocess,
|
||||||
&sys_torerr,
|
&sys_torerr,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@ lib/malloc/*.h
|
||||||
lib/net/*.h
|
lib/net/*.h
|
||||||
lib/process/*.h
|
lib/process/*.h
|
||||||
lib/string/*.h
|
lib/string/*.h
|
||||||
|
lib/subsys/*.h
|
||||||
lib/testsupport/*.h
|
lib/testsupport/*.h
|
||||||
lib/thread/*.h
|
lib/thread/*.h
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,8 @@ src_lib_libtor_process_a_SOURCES = \
|
||||||
src/lib/process/restrict.c \
|
src/lib/process/restrict.c \
|
||||||
src/lib/process/setuid.c \
|
src/lib/process/setuid.c \
|
||||||
src/lib/process/subprocess.c \
|
src/lib/process/subprocess.c \
|
||||||
src/lib/process/waitpid.c
|
src/lib/process/waitpid.c \
|
||||||
|
src/lib/process/winprocess_sys.c
|
||||||
|
|
||||||
src_lib_libtor_process_testing_a_SOURCES = \
|
src_lib_libtor_process_testing_a_SOURCES = \
|
||||||
$(src_lib_libtor_process_a_SOURCES)
|
$(src_lib_libtor_process_a_SOURCES)
|
||||||
|
@ -26,4 +27,5 @@ noinst_HEADERS += \
|
||||||
src/lib/process/restrict.h \
|
src/lib/process/restrict.h \
|
||||||
src/lib/process/setuid.h \
|
src/lib/process/setuid.h \
|
||||||
src/lib/process/subprocess.h \
|
src/lib/process/subprocess.h \
|
||||||
src/lib/process/waitpid.h
|
src/lib/process/waitpid.h \
|
||||||
|
src/lib/process/winprocess_sys.h
|
||||||
|
|
64
src/lib/process/winprocess_sys.c
Normal file
64
src/lib/process/winprocess_sys.c
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
/* Copyright (c) 2018, The Tor Project, Inc. */
|
||||||
|
/* See LICENSE for licensing information */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file winprocess_sys.c
|
||||||
|
* \brief Subsystem object for windows process setup.
|
||||||
|
**/
|
||||||
|
|
||||||
|
#include "orconfig.h"
|
||||||
|
#include "lib/subsys/subsys.h"
|
||||||
|
#include "lib/process/winprocess_sys.h"
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#include <windows.h>
|
||||||
|
|
||||||
|
#define WINPROCESS_SYS_ENABLED true
|
||||||
|
|
||||||
|
static int
|
||||||
|
init_windows_process_params(void)
|
||||||
|
{
|
||||||
|
#ifndef HeapEnableTerminationOnCorruption
|
||||||
|
#define HeapEnableTerminationOnCorruption 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* On heap corruption, just give up; don't try to play along. */
|
||||||
|
HeapSetInformation(NULL, HeapEnableTerminationOnCorruption, NULL, 0);
|
||||||
|
|
||||||
|
/* SetProcessDEPPolicy is only supported on 32-bit Windows.
|
||||||
|
* (On 64-bit Windows it always fails, and some compilers don't like the
|
||||||
|
* PSETDEP cast.)
|
||||||
|
* 32-bit Windows defines _WIN32.
|
||||||
|
* 64-bit Windows defines _WIN32 and _WIN64. */
|
||||||
|
#ifndef _WIN64
|
||||||
|
/* Call SetProcessDEPPolicy to permanently enable DEP.
|
||||||
|
The function will not resolve on earlier versions of Windows,
|
||||||
|
and failure is not dangerous. */
|
||||||
|
HMODULE hMod = GetModuleHandleA("Kernel32.dll");
|
||||||
|
if (hMod) {
|
||||||
|
typedef BOOL (WINAPI *PSETDEP)(DWORD);
|
||||||
|
PSETDEP setdeppolicy = (PSETDEP)GetProcAddress(hMod,
|
||||||
|
"SetProcessDEPPolicy");
|
||||||
|
if (setdeppolicy) {
|
||||||
|
/* PROCESS_DEP_ENABLE | PROCESS_DEP_DISABLE_ATL_THUNK_EMULATION */
|
||||||
|
setdeppolicy(3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif /* !defined(_WIN64) */
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#else /* !defined(_WIN32) */
|
||||||
|
#define WINPROCESS_SYS_ENABLED false
|
||||||
|
#define init_windows_process_params NULL
|
||||||
|
#endif /* defined(_WIN32) */
|
||||||
|
|
||||||
|
const subsys_fns_t sys_winprocess = {
|
||||||
|
.name = "winprocess",
|
||||||
|
.level = -100,
|
||||||
|
.supported = WINPROCESS_SYS_ENABLED,
|
||||||
|
.initialize = init_windows_process_params,
|
||||||
|
};
|
14
src/lib/process/winprocess_sys.h
Normal file
14
src/lib/process/winprocess_sys.h
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
/* Copyright (c) 2018, The Tor Project, Inc. */
|
||||||
|
/* See LICENSE for licensing information */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file winprocess_sys.h
|
||||||
|
* \brief Declare subsystem object for winprocess.c
|
||||||
|
**/
|
||||||
|
|
||||||
|
#ifndef TOR_WINPROCESS_SYS_H
|
||||||
|
#define TOR_WINPROCESS_SYS_H
|
||||||
|
|
||||||
|
extern const struct subsys_fns_t sys_winprocess;
|
||||||
|
|
||||||
|
#endif /* !defined(TOR_WINPROCESS_SYS_H) */
|
Loading…
Add table
Reference in a new issue