Browse Source

Bugfix: Use SOCKETTYPE for notifiers, to avoid potential overflow on Win64

Luke Dashjr 13 years ago
parent
commit
13c096da11
4 changed files with 14 additions and 13 deletions
  1. 1 1
      miner.c
  2. 2 2
      miner.h
  3. 5 5
      util.c
  4. 6 5
      util.h

+ 1 - 1
miner.c

@@ -231,7 +231,7 @@ pthread_mutex_t stats_lock;
 static pthread_mutex_t submitting_lock;
 static int total_submitting;
 static struct list_head submit_waiting;
-int submit_waiting_notifier[2];
+notifier_t submit_waiting_notifier;
 
 int hw_errors;
 int total_accepted, total_rejected, total_diff1;

+ 2 - 2
miner.h

@@ -566,12 +566,12 @@ struct thr_info {
 	struct timeval tv_results_jobstart;
 	struct timeval tv_jobstart;
 	struct timeval tv_poll;
-	int notifier[2];
+	notifier_t notifier;
 	bool starting_next_work;
 	uint32_t _max_nonce;
 
 	bool	work_restart;
-	int work_restart_notifier[2];
+	notifier_t work_restart_notifier;
 };
 
 extern int thr_info_create(struct thr_info *thr, pthread_attr_t *attr, void *(*start) (void *), void *arg);

+ 5 - 5
util.c

@@ -1773,7 +1773,7 @@ static const char *WindowsErrorStr(DWORD dwMessageId)
 }
 #endif
 
-void notifier_init(int pipefd[2])
+void notifier_init(notifier_t pipefd)
 {
 #ifdef WIN32
 	SOCKET listener, connecter, acceptor;
@@ -1817,9 +1817,9 @@ void notifier_init(int pipefd[2])
 #endif
 }
 
-void notifier_wake(int fd[2])
+void notifier_wake(notifier_t fd)
 {
-	if (fd[1] == -1)
+	if (fd[1] == INVSOCK)
 		return;
 #ifdef WIN32
 	(void)send(fd[1], "\0", 1, 0);
@@ -1828,7 +1828,7 @@ void notifier_wake(int fd[2])
 #endif
 }
 
-void notifier_read(int fd[2])
+void notifier_read(notifier_t fd)
 {
 	char buf[0x10];
 #ifdef WIN32
@@ -1838,7 +1838,7 @@ void notifier_read(int fd[2])
 #endif
 }
 
-void notifier_destroy(int fd[2])
+void notifier_destroy(notifier_t fd)
 {
 #ifdef WIN32
 	closesocket(fd[0]);

+ 6 - 5
util.h

@@ -12,7 +12,7 @@
 	#include <netinet/in.h>
 	#include <arpa/inet.h>
 
-	#define SOCKETTYPE long
+	#define SOCKETTYPE int
 	#define SOCKETFAIL(a) ((a) < 0)
 	#define INVSOCK -1
 	#define INVINETADDR -1
@@ -72,10 +72,11 @@ void dev_error(struct cgpu_info *dev, enum dev_reason reason);
 void *realloc_strcat(char *ptr, char *s);
 void RenameThread(const char* name);
 
-extern void notifier_init(int pipefd[2]);
-extern void notifier_wake(int fd[2]);
-extern void notifier_read(int fd[2]);
-extern void notifier_destroy(int fd[2]);
+typedef SOCKETTYPE notifier_t[2];
+extern void notifier_init(notifier_t);
+extern void notifier_wake(notifier_t);
+extern void notifier_read(notifier_t);
+extern void notifier_destroy(notifier_t);
 
 /* Align a size_t to 4 byte boundaries for fussy arches */
 static inline void align_len(size_t *len)