aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/common/compat.c72
-rw-r--r--src/common/compat.h19
-rw-r--r--src/or/config.c2
-rw-r--r--src/or/cpuworker.c2
-rw-r--r--src/or/dns.c2
-rw-r--r--src/or/main.c5
6 files changed, 68 insertions, 34 deletions
diff --git a/src/common/compat.c b/src/common/compat.c
index e1b7837d0c..12608bde21 100644
--- a/src/common/compat.c
+++ b/src/common/compat.c
@@ -163,47 +163,56 @@ typedef struct win_mmap_t {
tor_mmap_t *
tor_mmap_file(const char *filename)
{
- win_mmap_t *res = tor_malloc_zero(sizeof(win_mmap_t));
+ struct win_mmap_t *res = tor_malloc_zero(sizeof(struct win_mmap_t));
res->mmap_handle = res->file_handle = INVALID_HANDLE_VALUE;
- res->file_handle = CreateFileForMapping(filename,
- GENERIC_READ,
- 0, NULL,
- OPEN_EXISTING,
- FILE_ATTRIBUTE_NORMAL, 0);
+ res->file_handle = CreateFile(filename,
+ GENERIC_READ,
+ 0, NULL,
+ OPEN_EXISTING,
+ FILE_ATTRIBUTE_NORMAL,
+ 0);
+
+ if (res->file_handle == INVALID_HANDLE_VALUE)
+ goto err;
+
res->base.size = GetFileSize(res->file_handle, NULL);
res->mmap_handle = CreateFileMapping(res->file_handle,
NULL,
PAGE_READONLY,
- (size >> 32),
- (size & 0xfffffffful),
+ 0,
+ res->base.size,
NULL);
if (res->mmap_handle != INVALID_HANDLE_VALUE)
goto err;
res->base.data = (char*) MapViewOfFile(res->mmap_handle,
- access,
+ FILE_MAP_READ,
0, 0, 0);
- if (!res->data)
+ if (!res->base.data)
goto err;
return &(res->base);
err:
- tor_munmap_file(res);
+ tor_munmap_file(&res->base);
return NULL;
}
void
tor_munmap_file(tor_mmap_t *handle)
{
- win_mmap_t *h = (win_mmap_t*)
- (((char*)handle) - STRUCT_OFFSET(win_mmap_t, base));
+ struct win_mmap_t *h = (struct win_mmap_t*)
+ (((char*)handle) - STRUCT_OFFSET(struct win_mmap_t, base));
if (handle->data)
- UnmapViewOfFile(handle->data);
- if (res->mmap_handle != INVALID_HANDLE_VALUE)
- CloseHandle(res->mmap_handle);
- if (res->file_handle != INVALID_HANDLE_VALUE)
- CloseHandle(self->file_handle);
- tor_free(res);
+
+ /*this is an ugly cast, but without it, "data" in struct tor_mmap_t would
+ have to be redefined as const*/
+ UnmapViewOfFile( (LPVOID) handle->data);
+
+ if (h->mmap_handle != INVALID_HANDLE_VALUE)
+ CloseHandle(h->mmap_handle);
+ if (h->file_handle != INVALID_HANDLE_VALUE)
+ CloseHandle(h->file_handle);
+ tor_free(h);
}
#else
tor_mmap_t *
@@ -417,8 +426,8 @@ void
set_socket_nonblocking(int socket)
{
#ifdef MS_WINDOWS
- int nonblocking = 1;
- ioctlsocket(socket, FIONBIO, (unsigned long*) &nonblocking);
+ unsigned long nonblocking = 1;
+ ioctlsocket(socket, FIONBIO, (unsigned long*) &nonblocking);
#else
fcntl(socket, F_SETFL, O_NONBLOCK);
#endif
@@ -444,7 +453,8 @@ set_socket_nonblocking(int socket)
int
tor_socketpair(int family, int type, int protocol, int fd[2])
{
-#ifdef HAVE_SOCKETPAIR
+//don't use win32 socketpairs (they are always bad)
+#if defined(HAVE_SOCKETPAIR) && !defined(MS_WINDOWS)
int r;
r = socketpair(family, type, protocol, fd);
return r < 0 ? -errno : r;
@@ -562,7 +572,7 @@ set_max_file_descriptors(unsigned long limit, unsigned long cap)
log_fn(LOG_INFO, LD_NET,
"This platform is missing getrlimit(). Proceeding.");
if (limit < cap) {
- log_info(LD_CONFIG, "ConnLimit must be at most %d. Using that.", cap);
+ log_info(LD_CONFIG, "ConnLimit must be at most %d. Using that.", (int) cap);
limit = cap;
}
#else
@@ -799,6 +809,8 @@ static int uname_result_is_set = 0;
const char *
get_uname(void)
{
+
+
#ifdef HAVE_UNAME
struct utsname u;
#endif
@@ -852,7 +864,7 @@ get_uname(void)
memset(&info, 0, sizeof(info));
info.dwOSVersionInfoSize = sizeof(info);
if (! GetVersionEx((LPOSVERSIONINFO)&info)) {
- int err = GetLastError();
+
strlcpy(uname_result, "Bizarre version of Windows where GetVersionEx"
" doesn't work.", sizeof(uname_result));
uname_result_is_set = 1;
@@ -954,7 +966,7 @@ tor_pthread_helper_fn(void *_data)
* running.
*/
int
-spawn_func(int (*func)(void *), void *data)
+spawn_func(void (*func)(void *), void *data)
{
#if defined(USE_WIN32_THREADS)
int rv;
@@ -992,11 +1004,16 @@ spawn_func(int (*func)(void *), void *data)
/** End the current thread/process.
*/
+
void
spawn_exit(void)
{
#if defined(USE_WIN32_THREADS)
_endthread();
+ //we should never get here. my compiler thinks that _endthread returns, this
+ //is an attempt to fool it.
+ tor_assert(0);
+ _exit(0);
#elif defined(USE_PTHREADS)
pthread_exit(NULL);
#else
@@ -1004,6 +1021,7 @@ spawn_exit(void)
* call _exit, not exit, from child processes. */
_exit(0);
#endif
+
}
/** Set *timeval to the current time of day. On error, log and terminate.
@@ -1143,7 +1161,7 @@ tor_mutex_acquire(tor_mutex_t *m)
tor_assert(0);
break;
case WAIT_FAILED:
- log_warn(LD_GENERAL, "Failed to acquire mutex: %d", GetLastError());
+ log_warn(LD_GENERAL, "Failed to acquire mutex: %d", (int) GetLastError());
}
}
void
@@ -1152,7 +1170,7 @@ tor_mutex_release(tor_mutex_t *m)
BOOL r;
r = ReleaseMutex(m->handle);
if (!r) {
- log_warn(LD_GENERAL, "Failed to release mutex: %d", GetLastError());
+ log_warn(LD_GENERAL, "Failed to release mutex: %d", (int) GetLastError());
}
}
unsigned long
diff --git a/src/common/compat.h b/src/common/compat.h
index f0757d577f..0aff0775ec 100644
--- a/src/common/compat.h
+++ b/src/common/compat.h
@@ -273,7 +273,7 @@ int switch_id(char *user, char *group);
char *get_user_homedir(const char *username);
#endif
-int spawn_func(int (*func)(void *), void *data);
+int spawn_func(void (*func)(void *), void *data);
void spawn_exit(void) ATTR_NORETURN;
#if defined(ENABLE_THREADS) && defined(MS_WINDOWS)
@@ -306,5 +306,22 @@ unsigned long tor_get_thread_id(void);
#define tor_get_thread_id() (1UL)
#endif
+/*for some reason my compiler doesn't have these version flags defined
+ a nice homework assignment for someone one day is to define the rest*/
+//these are the values as given on MSDN
+#ifdef MS_WINDOWS
+
+#ifndef VER_SUITE_EMBEDDEDNT
+#define VER_SUITE_EMBEDDEDNT 0x00000040
+#endif
+
+#ifndef VER_SUITE_SINGLEUSERTS
+#define VER_SUITE_SINGLEUSERTS 0x00000100
+#endif
+
+
+#endif
+
+
#endif
diff --git a/src/or/config.c b/src/or/config.c
index 29f41ee3bb..146107ead7 100644
--- a/src/or/config.c
+++ b/src/or/config.c
@@ -2757,11 +2757,11 @@ options_init_from_torrc(int argc, char **argv)
if (using_default_torrc) {
/* didn't find one, try CONFDIR */
const char *dflt = get_default_conf_file();
- char *fn = NULL;
if (dflt && file_status(dflt) == FN_FILE) {
fname = tor_strdup(dflt);
} else {
#ifndef MS_WINDOWS
+ char *fn;
fn = expand_filename("~/.torrc");
if (fn && file_status(fn) == FN_FILE) {
fname = fn;
diff --git a/src/or/cpuworker.c b/src/or/cpuworker.c
index 66827bf20e..daab7d296f 100644
--- a/src/or/cpuworker.c
+++ b/src/or/cpuworker.c
@@ -333,7 +333,7 @@ spawn_cpuworker(void)
tor_assert(fdarray[1] >= 0);
fd = fdarray[0];
- spawn_func(cpuworker_main, (void*)fdarray);
+ spawn_func((void*) cpuworker_main, (void*)fdarray);
log_debug(LD_OR,"just spawned a cpu worker.");
#ifndef TOR_IS_MULTITHREADED
tor_close_socket(fdarray[1]); /* don't need the worker's side of the pipe */
diff --git a/src/or/dns.c b/src/or/dns.c
index 43459f2c58..19947e0765 100644
--- a/src/or/dns.c
+++ b/src/or/dns.c
@@ -1108,7 +1108,7 @@ spawn_dnsworker(void)
fd = fdarray[0]; /* We copy this out here, since dnsworker_main may free
* fdarray */
- spawn_func(dnsworker_main, (void*)fdarray);
+ spawn_func((void*) dnsworker_main, (void*)fdarray);
log_debug(LD_EXIT,"just spawned a dns worker.");
#ifndef TOR_IS_MULTITHREADED
tor_close_socket(fdarray[1]); /* don't need the worker's side of the pipe */
diff --git a/src/or/main.c b/src/or/main.c
index cc9999a0cf..118a82c9a7 100644
--- a/src/or/main.c
+++ b/src/or/main.c
@@ -1778,7 +1778,7 @@ nt_service_main(void)
if (!StartServiceCtrlDispatcher(table)) {
result = GetLastError();
errmsg = nt_strerror(result);
- printf("Service error %d : %s\n", result, errmsg);
+ printf("Service error %d : %s\n", (int) result, errmsg);
LocalFree(errmsg);
if (result == ERROR_FAILED_SERVICE_CONTROLLER_CONNECT) {
if (tor_init(backup_argc, backup_argv) < 0)
@@ -1902,7 +1902,7 @@ nt_service_stop(SC_HANDLE hService)
}
else {
errmsg = nt_strerror(GetLastError());
- printf("Service failed to stop : %s\n");
+ printf("Service failed to stop : %s\n",errmsg);
LocalFree(errmsg);
}
}
@@ -2015,7 +2015,6 @@ nt_service_remove(void)
{
SC_HANDLE hSCManager = NULL;
SC_HANDLE hService = NULL;
- BOOL result = FALSE;
char *errmsg;
if ((hSCManager = nt_service_open_scm()) == NULL) {