Browse code

- netbsd fixes - 64 bit mini-cleanup

Andrei Pelinescu-Onciul authored on 25/11/2002 20:29:44
Showing 10 changed files
... ...
@@ -12,7 +12,7 @@ EXTRAVERSION =
12 12
 
13 13
 RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
14 14
 OS = $(shell uname -s | sed -e s/SunOS/solaris/ | tr "[A-Z]" "[a-z]")
15
-ARCH = $(shell uname -m |sed -e s/i.86/i386/ -e s/sun4u/sparc/  \
15
+ARCH = $(shell uname -m |sed -e s/i.86/i386/ -e s/sun4u/sparc64/  \
16 16
 			-e s/armv4l/arm/)
17 17
 
18 18
  # install location
... ...
@@ -220,11 +220,13 @@ $(warning	Unknown compiler $(CC)\; supported compilers: \
220 220
 			gcc, sun cc, intel icc )
221 221
 endif
222 222
 
223
-# find ldname (gnu or solaris)
224
-ifeq ($(ARCH), sparc)
223
+# find ld & as name (gnu or solaris)
224
+ifeq ($(ARCH), sparc64)
225 225
 ifeq ($(CC_NAME), gcc)
226 226
 		LDGCC=$(shell $(CC) -v 2>&1 | grep with-ld| \
227 227
 				   sed -e 's/.*--with-ld=\([^ ][^ ]*\).*/\1/' )
228
+		ASGCC=$(shell $(CC) -v 2>&1 | grep with-as| \
229
+				   sed -e 's/.*--with-as=\([^ ][^ ]*\).*/\1/' )
228 230
 		LDPATH=$(shell  if [ -z "$(LDGCC)" ] ; then echo "ld" ;\
229 231
 						else \
230 232
 						if $(LDGCC) -V 2>/dev/null 1>/dev/null; then \
... ...
@@ -232,7 +234,14 @@ ifeq ($(CC_NAME), gcc)
232 232
 						else echo "ld" ; \
233 233
 						fi\
234 234
 						fi)
235
-						
235
+		ASPATH=$(shell  if [ -z "$(ASGCC)" ] ; then echo "as" ;\
236
+						else \
237
+						if $(ASGCC) -V 2>/dev/null 1>/dev/null; then \
238
+							echo $(ASGCC); \
239
+						else echo "as" ; \
240
+						fi\
241
+						fi)
242
+							
236 243
 		LDTYPE=$(shell if $(LDPATH) -V 1>/dev/null  2>/dev/null; then \
237 244
 							if $(LDPATH) -V 2>&1|grep GNU >/dev/null; \
238 245
 							then echo gnu; \
... ...
@@ -244,6 +253,20 @@ ifeq ($(CC_NAME), gcc)
244 244
 							fi \
245 245
 							fi \
246 246
 						fi)
247
+		ASTYPE=$(shell if $(ASPATH) -V 1>/dev/null  2>/dev/null </dev/null; \
248
+						then \
249
+							if $(ASPATH) -V 2>&1 </dev/null |grep GNU >/dev/null; \
250
+							then echo gnu; \
251
+							else \
252
+							if $(ASPATH) -V 2>&1 </dev/null |grep Sun >/dev/null;\
253
+							then echo solaris; \
254
+							else \
255
+								echo unknown ; \
256
+							fi \
257
+							fi \
258
+						fi)
259
+#$(warning "using ld=$(LDPATH)/$(LDTYPE), as=$(ASPATH)/$(ASTYPE)")
260
+
247 261
 endif
248 262
 endif
249 263
 
... ...
@@ -252,7 +275,7 @@ ifeq ($(ARCH), i386)
252 252
 	DEFS+= -DFAST_LOCK
253 253
 endif
254 254
 
255
-ifeq ($(ARCH), sparc)
255
+ifeq ($(ARCH), sparc64)
256 256
 ifeq 	($(CC_NAME), gcc)
257 257
 		DEFS+= -DFAST_LOCK
258 258
 endif
... ...
@@ -310,11 +333,11 @@ endif	#ARCH, i386
310 310
 
311 311
 
312 312
 	#if sparc
313
-ifeq	($(ARCH), sparc)
313
+ifeq	($(ARCH), sparc64)
314 314
 			#if gcc
315 315
 ifeq		($(CC_NAME), gcc)
316 316
 				#common stuff
317
-				CFLAGS=-O9 -funroll-loops  $(PROFILE) \
317
+				CFLAGS=-g -O9 -funroll-loops  $(PROFILE) \
318 318
 					-Wall\
319 319
 					#-Wcast-align \
320 320
 					#-Wmissing-prototypes 
... ...
@@ -330,14 +353,24 @@ else			# CC_SHORTVER, 3.0
330 330
 ifeq			($(CC_SHORTVER), 2.9x) #older gcc version (2.9[1-5])
331 331
 $(warning 			Old gcc detected ($(CC_SHORTVER)), use  gcc >= 3.1 \
332 332
 					for better results)
333
-					
334
-					CFLAGS+= -mv8 -Wa,-xarch=v8plus
333
+ifneq				($(OS), netbsd)
334
+						# on netbsd/sparc64,  gcc 2.95.3 does not compile
335
+						# ser with -mv8
336
+						CFLAGS+= -mv8 
337
+endif
338
+ifeq					($(ASTYPE), solaris)
339
+							CFLAGS+= -Wa,-xarch=v8plus
340
+endif					
335 341
 else			#CC_SHORTVER, 2.9x
336 342
 				#really old version
337 343
 $(warning			You are using an old and unsupported gcc \
338 344
 					 version ($(CC_SHORTVER)), compile at your own risk!)
339 345
 					
340
-					CFLAGS+= -mv8 -Wa,-xarch=v8plus
346
+					CFLAGS+= -mv8 
347
+ifeq					($(ASTYPE), solaris)
348
+							CFLAGS+= -Wa,-xarch=v8plus
349
+endif					
350
+	
341 351
 endif			#CC_SHORTVER, 2.9x
342 352
 endif			#CC_SHORTVER, 3.0
343 353
 
... ...
@@ -390,7 +423,7 @@ endif	#ARCH, i386
390 390
 LDFLAGS=
391 391
 # setting LDFLAGS
392 392
 ifeq	($(CC_NAME), gcc)
393
-ifeq		($(ARCH), sparc)
393
+ifeq		($(ARCH), sparc64)
394 394
 ifeq			($(LDTYPE), solaris)
395 395
 					# solaris ld
396 396
 					LDFLAGS+=-O2 $(PROFILE)
... ...
@@ -421,7 +454,7 @@ endif
421 421
 else	#mode,release
422 422
 ifeq	($(CC_NAME), gcc)
423 423
 		CFLAGS=-g -Wcast-align $(PROFILE)
424
-ifeq		($(ARCH), sparc)
424
+ifeq		($(ARCH), sparc64)
425 425
 			CFLAGS+= -mcpu=ultrasparc 
426 426
 endif
427 427
 ifeq		($(LDTYPE), solaris)
... ...
@@ -469,21 +502,14 @@ YACC_FLAGS=-d -b cfg
469 469
 # on solaris add -lxnet (e.g. LIBS= -lxnet)
470 470
 LIBS= -lfl -ldl -lresolv
471 471
 
472
-ifneq ($(OS), solaris)
473
-	DEFS+=-DHAVE_GETHOSTBYNAME2 -DHAVE_UNION_SEMUN
474
-endif
475
-ifneq ($(OS), openbsd)
476
-	DEFS+=-DHAVE_SCHED_YIELD
477
-endif
478
-
479 472
 
480 473
 #os specific stuff
481 474
 ifeq ($(OS), linux)
482
-	#same as common
475
+	DEFS+=-DHAVE_GETHOSTBYNAME2 -DHAVE_UNION_SEMUN -DHAVE_SCHED_YIELD
483 476
 endif
484 477
 
485 478
 ifeq  ($(OS), solaris)
486
-	DEFS+= -DHAVE_GETIPNODEBYNAME -DHAVE_SYS_SOCKIO_H
479
+	DEFS+= -DHAVE_GETIPNODEBYNAME -DHAVE_SYS_SOCKIO_H -DHAVE_SCHED_YIELD
487 480
 	ifeq ($(mode), release)
488 481
 		#use these only if you're using gcc with Solaris ld
489 482
 		#LDFLAGS=-O2 $(PROFILE)
... ...
@@ -503,13 +529,14 @@ endif
503 503
 endif
504 504
 
505 505
 ifeq ($(OS), freebsd)
506
-	DEFS+=-DHAVE_SOCKADDR_SA_LEN
506
+	DEFS+=-DHAVE_SOCKADDR_SA_LEN -DHAVE_GETHOSTBYNAME2 -DHAVE_UNION_SEMUN \
507
+		-DHAVE_SCHED_YIELD
507 508
 	YACC=yacc
508 509
 	LIBS= -lfl  #dlopen is in libc
509 510
 endif
510 511
 
511 512
 ifeq ($(OS), openbsd)
512
-	DEFS+=-DHAVE_SOCKADDR_SA_LEN -DDLSYM_PREFIX='"_"'
513
+	DEFS+=-DHAVE_SOCKADDR_SA_LEN -DDLSYM_PREFIX='"_"' -DHAVE_GETHOSTBYNAME2 
513 514
 	# (symbols on openbsd are prefixed by "_")
514 515
 	YACC=yacc
515 516
 	# no sched_yield on openbsd unless linking with c_r (not recommended)
... ...
@@ -518,9 +545,9 @@ ifeq ($(OS), openbsd)
518 518
 endif
519 519
 	
520 520
 ifeq ($(OS), netbsd)
521
-	DEFS+=-DHAVE_SOCKADDR_SA_LEN
521
+	DEFS+=-DHAVE_SOCKADDR_SA_LEN -DHAVE_GETHOSTBYNAME2 
522 522
 	YACC=yacc
523
-	LIBS= -lfl  -lc_r
523
+	LIBS= -lfl 
524 524
 endif
525 525
 
526 526
 ifneq (,$(findstring CYGWIN, $(OS)))
... ...
@@ -72,7 +72,7 @@ inline static int tsl(fl_lock_t* lock)
72 72
 		" xchg %b1, %0" : "=q" (val), "=m" (*lock) : "0" (val) : "memory"
73 73
 	);
74 74
 #endif /*NOSMP*/
75
-#elif defined __CPU_sparc
75
+#elif defined __CPU_sparc64
76 76
 	asm volatile(
77 77
 			"ldstub [%1], %0 \n\t"
78 78
 #ifndef NOSMP
... ...
@@ -125,7 +125,7 @@ inline static void release_lock(fl_lock_t* lock)
125 125
 		" movb $0, (%0)" : /*no output*/ : "r"(lock): "memory"
126 126
 		/*" xchg %b0, %1" : "=q" (val), "=m" (*lock) : "0" (val) : "memory"*/
127 127
 	); 
128
-#elif defined __CPU_sparc
128
+#elif defined __CPU_sparc64
129 129
 	asm volatile(
130 130
 #ifndef NOSMP
131 131
 			"membar #LoadStore | #StoreStore \n\t" /*is this really needed?*/
... ...
@@ -38,8 +38,9 @@
38 38
 #include <arpa/inet.h>
39 39
 #include <sys/utsname.h>
40 40
 #include <sys/types.h>
41
+#include <sys/stat.h>
41 42
 #include <sys/mman.h>
42
-#include <sys/fcntl.h>
43
+#include <fcntl.h>
43 44
 #include <sys/time.h>
44 45
 #include <sys/wait.h>
45 46
 #include <pwd.h>
... ...
@@ -747,9 +748,10 @@ static void sig_usr(int signo)
747 747
 int add_interfaces(char* if_name, int family, unsigned short port)
748 748
 {
749 749
 	struct ifconf ifc;
750
-	struct ifreq* ifr;
750
+	struct ifreq ifr;
751 751
 	struct ifreq ifrcopy;
752 752
 	char*  last;
753
+	char* p;
753 754
 	int size;
754 755
 	int lastlen;
755 756
 	int s;
... ...
@@ -787,27 +789,30 @@ int add_interfaces(char* if_name, int family, unsigned short port)
787 787
 	}
788 788
 	
789 789
 	last=(char*)ifc.ifc_req+ifc.ifc_len;
790
-	for(ifr=ifc.ifc_req; (char*)ifr<last;
791
-			ifr=(struct ifreq*)((char*)ifr+sizeof(ifr->ifr_name)+
790
+	for(p=(char*)ifc.ifc_req; p<last;
791
+			p+=(sizeof(ifr.ifr_name)+
792 792
 			#ifdef  HAVE_SOCKADDR_SA_LEN
793
-				MAX(ifr->ifr_addr.sa_len, sizeof(struct sockaddr))
793
+				MAX(ifr.ifr_addr.sa_len, sizeof(struct sockaddr))
794 794
 			#else
795
-				( (ifr->ifr_addr.sa_family==AF_INET)?
795
+				( (ifr.ifr_addr.sa_family==AF_INET)?
796 796
 					sizeof(struct sockaddr_in):
797
-					((ifr->ifr_addr.sa_family==AF_INET6)?
797
+					((ifr.ifr_addr.sa_family==AF_INET6)?
798 798
 						sizeof(struct sockaddr_in6):sizeof(struct sockaddr)) )
799 799
 			#endif
800 800
 				)
801 801
 		)
802 802
 	{
803
-		if (ifr->ifr_addr.sa_family!=family){
803
+		/* copy contents into ifr structure
804
+		 * warning: it might be longer (e.g. ipv6 address) */
805
+		memcpy(&ifr, p, sizeof(ifr));
806
+		if (ifr.ifr_addr.sa_family!=family){
804 807
 			/*printf("strange family %d skipping...\n",
805 808
 					ifr->ifr_addr.sa_family);*/
806 809
 			continue;
807 810
 		}
808 811
 		
809 812
 		/*get flags*/
810
-		memcpy(&ifrcopy, ifr, sizeof(ifrcopy));
813
+		ifrcopy=ifr;
811 814
 		if (ioctl(s, SIOCGIFFLAGS,  &ifrcopy)!=-1){ /* ignore errors */
812 815
 			/* ignore down ifs only if listening on all of them*/
813 816
 			if (if_name==0){ 
... ...
@@ -819,11 +824,12 @@ int add_interfaces(char* if_name, int family, unsigned short port)
819 819
 		
820 820
 		
821 821
 		if ((if_name==0)||
822
-			(strncmp(if_name, ifr->ifr_name, sizeof(ifr->ifr_name))==0)){
822
+			(strncmp(if_name, ifr.ifr_name, sizeof(ifr.ifr_name))==0)){
823 823
 			
824 824
 				/*add address*/
825 825
 			if (sock_no<MAX_LISTEN){
826
-				sockaddr2ip_addr(&addr, &ifr->ifr_addr);
826
+				sockaddr2ip_addr(&addr, 
827
+					(struct sockaddr*)(p+(long)&((struct ifreq*)0)->ifr_addr));
827 828
 				if ((tmp=ip_addr2a(&addr))==0) goto error;
828 829
 				/* fill the strings*/
829 830
 				sock_info[sock_no].name.s=(char*)malloc(strlen(tmp)+1);
... ...
@@ -55,26 +55,26 @@
55 55
  * +1 .... end -  size = 2^k, big buckets */
56 56
 
57 57
 struct fm_frag{
58
-	unsigned int size;
58
+	unsigned long size;
59 59
 	union{
60 60
 		struct fm_frag* nxt_free;
61
-		int reserved;
61
+		long reserved;
62 62
 	}u;
63 63
 #ifdef DBG_F_MALLOC
64 64
 	char* file;
65 65
 	char* func;
66
-	unsigned int line;
67
-	unsigned int check;
66
+	unsigned long line;
67
+	unsigned long check;
68 68
 #endif
69 69
 };
70 70
 
71 71
 
72 72
 struct fm_block{
73
-	unsigned int size; /* total size */
73
+	unsigned long size; /* total size */
74 74
 #ifdef DBG_F_MALLOC
75
-	unsigned int used; /* alloc'ed size*/
76
-	unsigned int real_used; /* used+malloc overhead*/
77
-	unsigned int max_real_used;
75
+	unsigned long used; /* alloc'ed size*/
76
+	unsigned long real_used; /* used+malloc overhead*/
77
+	unsigned long max_real_used;
78 78
 #endif
79 79
 	
80 80
 	struct fm_frag* first_frag;
... ...
@@ -149,11 +149,11 @@ struct qm_block* qm_malloc_init(char* address, unsigned int size)
149 149
 	char* start;
150 150
 	char* end;
151 151
 	struct qm_block* qm;
152
-	unsigned int init_overhead;
152
+	unsigned long init_overhead;
153 153
 	int h;
154 154
 	
155 155
 	/* make address and size multiple of 8*/
156
-	start=(char*)ROUNDUP((unsigned int) address);
156
+	start=(char*)ROUNDUP((unsigned long) address);
157 157
 	DBG("qm_malloc_init: QM_OPTIMIZE=%d, /ROUNDTO=%d\n",
158 158
 			QM_MALLOC_OPTIMIZE, QM_MALLOC_OPTIMIZE/ROUNDTO);
159 159
 	DBG("qm_malloc_init: QM_HASH_SIZE=%d, qm_block size=%d\n",
... ...
@@ -34,7 +34,7 @@
34 34
 
35 35
 /* defs*/
36 36
 #ifdef DBG_QM_MALLOC
37
-	#define ROUNDTO		 4 /* minimum possible ROUNDTO ->heavy debugging*/
37
+	#define ROUNDTO		 8 /* minimum possible ROUNDTO ->heavy debugging*/
38 38
 #else
39 39
 	#define ROUNDTO		16 /* size we round to, must be = 2^n  and also
40 40
 							 sizeof(qm_frag)+sizeof(qm_frag_end)
... ...
@@ -60,27 +60,27 @@
60 60
  * +1 .... end -  size = 2^k, big buckets */
61 61
 
62 62
 struct qm_frag{
63
-	unsigned int size;
63
+	unsigned long size;
64 64
 	union{
65 65
 		struct qm_frag* nxt_free;
66
-		int is_free;
66
+		long is_free;
67 67
 	}u;
68 68
 #ifdef DBG_QM_MALLOC
69 69
 	char* file;
70 70
 	char* func;
71
-	unsigned int line;
72
-	unsigned int check;
71
+	unsigned long line;
72
+	unsigned long check;
73 73
 #endif
74 74
 };
75 75
 
76 76
 struct qm_frag_end{
77 77
 #ifdef DBG_QM_MALLOC
78
-	unsigned int check1;
79
-	unsigned int check2;
80
-	unsigned int reserved1;
81
-	unsigned int reserved2;
78
+	unsigned long check1;
79
+	unsigned long check2;
80
+	unsigned long reserved1;
81
+	unsigned long reserved2;
82 82
 #endif
83
-	unsigned int size;
83
+	unsigned long size;
84 84
 	struct qm_frag* prev_free;
85 85
 };
86 86
 
... ...
@@ -93,10 +93,10 @@ struct qm_frag_full{
93 93
 
94 94
 
95 95
 struct qm_block{
96
-	unsigned int size; /* total size */
97
-	unsigned int used; /* alloc'ed size*/
98
-	unsigned int real_used; /* used+malloc overhead*/
99
-	unsigned int max_real_used;
96
+	unsigned long size; /* total size */
97
+	unsigned long used; /* alloc'ed size*/
98
+	unsigned long real_used; /* used+malloc overhead*/
99
+	unsigned long max_real_used;
100 100
 	
101 101
 	struct qm_frag* first_frag;
102 102
 	struct qm_frag_end* last_frag_end;
... ...
@@ -77,7 +77,7 @@ struct vqm_frag {
77 77
 	/* total chunk size including all overhead/bellowfoot/roundings/etc */
78 78
 	/* useless as otherwise size implied by bucket (if I really want to save 
79 79
        bytes, I'll remove it  from here */
80
-	unsigned int size;
80
+	unsigned long size;
81 81
 	union{
82 82
 		/* pointer to next chunk in a bucket if free */
83 83
 		struct vqm_frag* nxt_free; 
... ...
@@ -90,18 +90,18 @@ struct vqm_frag {
90 90
 	/* source code info */
91 91
 	char* file;
92 92
 	char* func;
93
-	unsigned int line;
93
+	unsigned long line;
94 94
 	/* your safety is important to us! safety signatures */
95
-	unsigned int check;
95
+	unsigned long check;
96 96
 	char *end_check;
97 97
 	/* the size user was originally asking for */
98
-	unsigned int demanded_size;
98
+	unsigned long demanded_size;
99 99
 #endif
100 100
 };
101 101
 
102 102
 struct vqm_frag_end{
103 103
 	/* total chunk size including all overhead/bellowfoot/roundings/etc */
104
-	unsigned int size; 
104
+	unsigned long size; 
105 105
 	/* XXX */
106 106
 	/* used only for variable-size chunks; might have different
107 107
            data structures for variable/fixed length chunks */
... ...
@@ -121,7 +121,7 @@ struct vqm_block{
121 121
 	/* ... and its available net amount; note that there's lot of
122 122
            free memory in buckets too -- this just tells about memory
123 123
 	   which has not been assigned to chunks  */
124
-	unsigned int free_core;
124
+	unsigned long free_core;
125 125
 	/* we allocate huge chunks from the end on; this is the
126 126
 	   pointer to big chunks
127 127
     */
... ...
@@ -46,9 +46,11 @@
46 46
 #include "../../ut.h"
47 47
 
48 48
 
49
-
49
+/* rounds to the first 4 byte multiple on 32 bit archs 
50
+ * and to the first 8 byte mutlipe on 64 bit archs */
50 51
 #define ROUND4(s) \
51
-	(((s)+3)&(~(3UL)))
52
+	(((s)+(sizeof(char*)-1))&(~(sizeof(char*)-1)))
53
+
52 54
 #define lump_len( _lump) \
53 55
 	(ROUND4(sizeof(struct lump)) +\
54 56
 	ROUND4(((_lump)->op==LUMP_ADD)?(_lump)->len:0))
... ...
@@ -5,7 +5,7 @@
5 5
 #
6 6
 
7 7
 
8
-debug=9          # debug level (cmd line: -dddddddddd)
8
+#debug=9          # debug level (cmd line: -dddddddddd)
9 9
 #fork=yes          # (cmd. line: -D)
10 10
 #log_stderror=yes # (cmd line: -E)
11 11
 #log_stderror=no	# (cmd line: -E)
... ...
@@ -33,6 +33,6 @@ route{
33 33
 	if (myself==uri){
34 34
 		log("\n\nfrom myself\n\n");
35 35
 	};
36
-	log("\n\n continue \n\n");
36
+	log(" continue \n\n");
37 37
 	forward(uri:host, uri:port);
38 38
 }
... ...
@@ -1,4 +1,4 @@
1
-debug=9			# for speed
1
+#debug=9			# for speed
2 2
 check_via=0
3 3
 dns=off
4 4
 rev_dns=off