Browse code

mpool for win32, update win32 stuff

aCaB authored on 2010/05/10 10:46:46
Showing 5 changed files
... ...
@@ -1,3 +1,8 @@
1
+Mon May 10 03:43:43 CEST 2010 (acab)
2
+------------------------------------
3
+ * libclamav: Use mpool in win32 (well, sort of) as the mighty crt allocator
4
+	      chokes when loading about one milion signatures
5
+
1 6
 Sat May  8 00:18:13 CEST 2010 (acab)
2 7
 ------------------------------------
3 8
  * libclamav/fmap.c: make oof need stfu (bb#2000)
... ...
@@ -278,7 +278,11 @@ struct MP *mpool_create() {
278 278
   sz = align_to_pagesize(&mp, MIN_FRAGSIZE);
279 279
   mp.u.mpm.usize = align_to_voidptr(sizeof(struct MPMAP));
280 280
   mp.u.mpm.size = sz - align_to_voidptr(sizeof(mp));
281
+#ifndef _WIN32
281 282
   if ((mpool_p = (struct MP *)mmap(NULL, sz, PROT_READ | PROT_WRITE, MAP_PRIVATE|ANONYMOUS_MAP, -1, 0)) == MAP_FAILED)
283
+#else
284
+  if(!(mpool_p = (struct MP *)VirtualAlloc(NULL, sz, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE)))
285
+#endif
282 286
     return NULL;
283 287
 #ifdef CL_DEBUG
284 288
   memset(mpool_p, ALLOCPOISON, sz);
... ...
@@ -298,13 +302,21 @@ void mpool_destroy(struct MP *mp) {
298 298
 #ifdef CL_DEBUG
299 299
     memset(mpm, FREEPOISON, mpmsize);
300 300
 #endif
301
+#ifndef _WIN32
301 302
     munmap((void *)mpm, mpmsize);
303
+#else
304
+    VirtualFree(mpm, 0, MEM_RELEASE);
305
+#endif
302 306
   }
303 307
   mpmsize = mp->u.mpm.size;
304 308
 #ifdef CL_DEBUG
305 309
   memset(mp, FREEPOISON, mpmsize + align_to_voidptr(sizeof(*mp)));
306 310
 #endif
311
+#ifndef _WIN32
307 312
   munmap((void *)mp, mpmsize + align_to_voidptr(sizeof(*mp)));
313
+#else
314
+  VirtualFree(mp, 0, MEM_RELEASE);
315
+#endif
308 316
   spam("Map destroyed @%p\n", mp);
309 317
 }
310 318
 
... ...
@@ -323,7 +335,11 @@ void mpool_flush(struct MP *mp) {
323 323
 #ifdef CL_DEBUG
324 324
 	    memset((char *)mpm + mused, FREEPOISON, mpm->size - mused);
325 325
 #endif
326
+#ifndef _WIN32
326 327
 	    munmap((char *)mpm + mused, mpm->size - mused);
328
+#else
329
+	    VirtualFree((char *)mpm + mused, mpm->size - mused, MEM_DECOMMIT);
330
+#endif
327 331
 	    mpm->size = mused;
328 332
 	}
329 333
 	used += mpm->size;
... ...
@@ -334,7 +350,11 @@ void mpool_flush(struct MP *mp) {
334 334
 #ifdef CL_DEBUG
335 335
 	memset((char *)mp + mused, FREEPOISON, mp->u.mpm.size + align_to_voidptr(sizeof(*mp)) - mused);
336 336
 #endif
337
+#ifndef _WIN32
337 338
 	munmap((char *)mp + mused, mp->u.mpm.size + align_to_voidptr(sizeof(*mp)) - mused);
339
+#else
340
+	VirtualFree((char *)mp + mused, mp->u.mpm.size + align_to_voidptr(sizeof(*mp)) - mused, MEM_DECOMMIT);
341
+#endif
338 342
 	mp->u.mpm.size = mused - align_to_voidptr(sizeof(*mp));
339 343
     }
340 344
     used += mp->u.mpm.size;
... ...
@@ -412,8 +432,12 @@ void *mpool_malloc(struct MP *mp, size_t size) {
412 412
   i = align_to_pagesize(mp, needed + align_to_voidptr(sizeof(*mpm)));
413 413
   else
414 414
   i = align_to_pagesize(mp, MIN_FRAGSIZE);
415
-  
415
+
416
+#ifndef _WIN32
416 417
   if ((mpm = (struct MPMAP *)mmap(NULL, i, PROT_READ | PROT_WRITE, MAP_PRIVATE|ANONYMOUS_MAP, -1, 0)) == MAP_FAILED) {
418
+#else
419
+  if (!(mpm = (struct MPMAP *)VirtualAlloc(NULL, i, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE))) {
420
+#endif
417 421
     cli_errmsg("mpool_malloc(): Can't allocate memory (%lu bytes).\n", (unsigned long int)i);
418 422
     spam("failed to alloc %u bytes (%u requested)\n", i, size);
419 423
     return NULL;
... ...
@@ -394,6 +394,9 @@
394 394
 /* Define to 1 if you have the <termios.h> header file. */
395 395
 /* #undef HAVE_TERMIOS_H */
396 396
 
397
+/* Define this if uname(2) is POSIX */
398
+/* #undef HAVE_UNAME_SYSCALL */
399
+
397 400
 /* Define to 1 if you have the <unistd.h> header file. */
398 401
 /* #undef HAVE_UNISTD_H */
399 402
 
... ...
@@ -403,6 +406,9 @@
403 403
 /* This value is set to 1 to indicate that the system argz facility works */
404 404
 /* #undef HAVE_WORKING_ARGZ */
405 405
 
406
+/* For internal use only - DO NOT DEFINE */
407
+/* #undef HAVE__INTERNAL__SHA_COLLECT */
408
+
406 409
 /* "Full library version number" */
407 410
 #define LIBCLAMAV_FULLVER "6.0.4"
408 411
 
... ...
@@ -490,13 +496,13 @@
490 490
 /* #undef SUPPORT_IPv6 */
491 491
 
492 492
 /* enable memory pools */
493
-/* #undef USE_MPOOL */
493
+#define USE_MPOOL 1
494 494
 
495 495
 /* use syslog */
496 496
 /* #undef USE_SYSLOG */
497 497
 
498 498
 /* Version number of package */
499
-#define VERSION "devel-clamav-0.96rc2-34-g3d8a490"
499
+#define VERSION "devel-clamav-0.96-72-gc5afd1c"
500 500
 
501 501
 /* Version suffix for package */
502 502
 #define VERSION_SUFFIX ""
... ...
@@ -94,108 +94,110 @@ EXPORTS cli_bytecode_init @44238 NONAME
94 94
 EXPORTS cli_bytecode_debug @44239 NONAME
95 95
 EXPORTS cli_bytecode_debug_printsrc @44240 NONAME
96 96
 EXPORTS cli_bytecode_printversion @44241 NONAME
97
-EXPORTS cli_printcxxver @44336 NONAME
98
-EXPORTS cli_bytecode_describe @44242 NONAME
99
-EXPORTS cli_malloc @44243 NONAME
100
-EXPORTS cli_wm_decrypt_macro @44244 NONAME
101
-EXPORTS cli_wm_readdir @44245 NONAME
102
-EXPORTS cli_ppt_vba_read @44246 NONAME
103
-EXPORTS cli_vba_inflate @44247 NONAME
104
-EXPORTS cli_vba_readdir @44248 NONAME
105
-EXPORTS uniq_get @44249 NONAME
106
-EXPORTS cli_ole2_extract @44250 NONAME
107
-EXPORTS cli_calloc @44251 NONAME
108
-EXPORTS cli_str2hex @44252 NONAME
109
-EXPORTS cli_md5stream @44253 NONAME
110
-EXPORTS cli_md5file @44254 NONAME
111
-EXPORTS html_normalise_map @44255 NONAME
112
-EXPORTS cli_utf16toascii @44256 NONAME
113
-EXPORTS cli_strbcasestr @44257 NONAME
114
-EXPORTS cli_ac_chklsig @44258 NONAME
115
-EXPORTS cli_parse_add @44259 NONAME
116
-EXPORTS cli_initroots @44260 NONAME
117
-EXPORTS cli_hex2str @44261 NONAME
118
-EXPORTS cli_hex2ui @44262 NONAME
97
+EXPORTS cli_printcxxver @44242 NONAME
98
+EXPORTS cli_bytecode_describe @44243 NONAME
99
+EXPORTS cli_malloc @44244 NONAME
100
+EXPORTS cli_wm_decrypt_macro @44245 NONAME
101
+EXPORTS cli_wm_readdir @44246 NONAME
102
+EXPORTS cli_ppt_vba_read @44247 NONAME
103
+EXPORTS cli_vba_inflate @44248 NONAME
104
+EXPORTS cli_vba_readdir @44249 NONAME
105
+EXPORTS uniq_get @44250 NONAME
106
+EXPORTS cli_ole2_extract @44251 NONAME
107
+EXPORTS cli_calloc @44252 NONAME
108
+EXPORTS cli_str2hex @44253 NONAME
109
+EXPORTS cli_md5stream @44254 NONAME
110
+EXPORTS cli_md5file @44255 NONAME
111
+EXPORTS html_normalise_map @44256 NONAME
112
+EXPORTS cli_utf16toascii @44257 NONAME
113
+EXPORTS cli_strbcasestr @44258 NONAME
114
+EXPORTS cli_ac_chklsig @44259 NONAME
115
+EXPORTS cli_parse_add @44260 NONAME
116
+EXPORTS cli_initroots @44261 NONAME
117
+EXPORTS cli_hex2str @44262 NONAME
118
+EXPORTS cli_hex2ui @44263 NONAME
119
+EXPORTS mpool_getstats @44264 NONAME
119 120
 
120 121
 ; compatibility layer, tommath, zlib
121
-EXPORTS w32_srand @44263 NONAME
122
-EXPORTS w32_rand @44264 NONAME
123
-EXPORTS gettimeofday @44265 NONAME
124
-EXPORTS opendir @44266 NONAME
125
-EXPORTS readdir @44267 NONAME
126
-EXPORTS closedir @44268 NONAME
127
-EXPORTS safe_open @44269 NONAME
128
-EXPORTS snprintf @44270 NONAME
129
-EXPORTS mp_init @44271 NONAME
130
-EXPORTS mp_read_radix @44272 NONAME
131
-EXPORTS mp_clear @44273 NONAME
132
-EXPORTS sha256_init @44274 NONAME
133
-EXPORTS sha256_update @44275 NONAME
134
-EXPORTS sha256_final @44276 NONAME
135
-EXPORTS optget @44277 NONAME
136
-EXPORTS optparse @44278 NONAME
137
-EXPORTS optfree @44279 NONAME
138
-EXPORTS w32_glob @44280 NONAME
139
-EXPORTS dirname @44281 NONAME
140
-EXPORTS basename @44282 NONAME
141
-EXPORTS clam_options @44283 NONAME DATA
122
+EXPORTS w32_srand @44265 NONAME
123
+EXPORTS w32_rand @44266 NONAME
124
+EXPORTS gettimeofday @44267 NONAME
125
+EXPORTS opendir @44268 NONAME
126
+EXPORTS readdir @44269 NONAME
127
+EXPORTS closedir @44270 NONAME
128
+EXPORTS safe_open @44271 NONAME
129
+EXPORTS snprintf @44272 NONAME
130
+EXPORTS mp_init @44273 NONAME
131
+EXPORTS mp_read_radix @44274 NONAME
132
+EXPORTS mp_clear @44275 NONAME
133
+EXPORTS sha256_init @44276 NONAME
134
+EXPORTS sha256_update @44277 NONAME
135
+EXPORTS sha256_final @44278 NONAME
136
+EXPORTS optget @44279 NONAME
137
+EXPORTS optparse @44280 NONAME
138
+EXPORTS optfree @44281 NONAME
139
+EXPORTS w32_glob @44282 NONAME
140
+EXPORTS dirname @44283 NONAME
141
+EXPORTS basename @44284 NONAME
142
+EXPORTS clam_options @44285 NONAME DATA
142 143
 
143 144
 ; zlib
144
-EXPORTS gzopen @44284 NONAME
145
-EXPORTS gzgets @44285 NONAME
146
-EXPORTS gzdopen @44286 NONAME
147
-EXPORTS gzclose @44287 NONAME
148
-EXPORTS gzwrite @44288 NONAME
149
-EXPORTS zlibCompileFlags @44337 NONAME
150
-EXPORTS zlibVersion @44338 NONAME
145
+EXPORTS gzopen @44286 NONAME
146
+EXPORTS gzgets @44287 NONAME
147
+EXPORTS gzdopen @44288 NONAME
148
+EXPORTS gzclose @44289 NONAME
149
+EXPORTS gzwrite @44290 NONAME
150
+EXPORTS zlibCompileFlags @44291 NONAME
151
+EXPORTS zlibVersion @44292 NONAME
151 152
 
152 153
 ; pthreads
153
-EXPORTS pthread_mutex_lock @44289 NONAME
154
-EXPORTS pthread_mutex_unlock @44290 NONAME
155
-EXPORTS pthread_mutex_destroy @44291 NONAME
156
-EXPORTS pthread_once @44292 NONAME
157
-EXPORTS pthread_getspecific @44293 NONAME
158
-EXPORTS pthread_setspecific @44294 NONAME
159
-EXPORTS pthread_create @44295 NONAME
160
-EXPORTS pthread_cond_timedwait @44296 NONAME
161
-EXPORTS pthread_cond_init @44297 NONAME
162
-EXPORTS pthread_cond_broadcast @44298 NONAME
163
-EXPORTS pthread_cond_signal @44299 NONAME
164
-EXPORTS pthread_cond_destroy @44300 NONAME
165
-EXPORTS pthread_join @44301 NONAME
166
-EXPORTS pthread_key_create @44302 NONAME
167
-EXPORTS pthread_cond_wait @44303 NONAME
168
-EXPORTS pthread_attr_init @44304 NONAME
169
-EXPORTS pthread_attr_setdetachstate @44305 NONAME
170
-EXPORTS pthread_attr_destroy @44306 NONAME
171
-EXPORTS pthread_mutex_init @44307 NONAME
154
+EXPORTS pthread_mutex_lock @44293 NONAME
155
+EXPORTS pthread_mutex_unlock @44294 NONAME
156
+EXPORTS pthread_mutex_destroy @44295 NONAME
157
+EXPORTS pthread_once @44296 NONAME
158
+EXPORTS pthread_getspecific @44297 NONAME
159
+EXPORTS pthread_setspecific @44298 NONAME
160
+EXPORTS pthread_create @44299 NONAME
161
+EXPORTS pthread_cond_timedwait @44300 NONAME
162
+EXPORTS pthread_cond_init @44301 NONAME
163
+EXPORTS pthread_cond_broadcast @44302 NONAME
164
+EXPORTS pthread_cond_signal @44303 NONAME
165
+EXPORTS pthread_cond_destroy @44304 NONAME
166
+EXPORTS pthread_join @44305 NONAME
167
+EXPORTS pthread_key_create @44306 NONAME
168
+EXPORTS pthread_cond_wait @44307 NONAME
169
+EXPORTS pthread_attr_init @44308 NONAME
170
+EXPORTS pthread_attr_setdetachstate @44309 NONAME
171
+EXPORTS pthread_attr_destroy @44310 NONAME
172
+EXPORTS pthread_mutex_init @44311 NONAME
172 173
 
173 174
 ; winsock bridge and compatibility functions
174
-EXPORTS htonl @44308 NONAME
175
-EXPORTS htons @44309 NONAME
176
-EXPORTS ntohl @44310 NONAME
177
-EXPORTS ntohs @44311 NONAME
178
-EXPORTS __WSAFDIsSet @44312 NONAME
179
-EXPORTS w32_socket @44313 NONAME
180
-EXPORTS w32_getsockopt @44314 NONAME
181
-EXPORTS w32_setsockopt @44315 NONAME
182
-EXPORTS w32_bind @44316 NONAME
183
-EXPORTS w32_listen @44317 NONAME
184
-EXPORTS w32_accept @44318 NONAME
185
-EXPORTS w32_connect @44319 NONAME
186
-EXPORTS w32_shutdown @44320 NONAME
187
-EXPORTS w32_send @44321 NONAME
188
-EXPORTS w32_recv @44322 NONAME
189
-EXPORTS w32_closesocket @44323 NONAME
190
-EXPORTS w32_getservbyname @44324 NONAME
191
-EXPORTS w32_getaddrinfo @44325 NONAME
192
-EXPORTS w32_freeaddrinfo @44326 NONAME
193
-EXPORTS w32_inet_ntop @44327 NONAME
194
-EXPORTS w32_gethostbyname @44328 NONAME
195
-EXPORTS w32_select @44329 NONAME
196
-EXPORTS poll_with_event @44330 NONAME
197
-EXPORTS w32_stat @44331 NONAME
198
-EXPORTS w32_strerror @44332 NONAME
199
-EXPORTS w32_strerror_r @44333 NONAME
200
-EXPORTS inet_addr @44334 NONAME
201
-EXPORTS fcntl @44335 NONAME
175
+EXPORTS htonl @44312 NONAME
176
+EXPORTS htons @44313 NONAME
177
+EXPORTS ntohl @44314 NONAME
178
+EXPORTS ntohs @44315 NONAME
179
+EXPORTS __WSAFDIsSet @44316 NONAME
180
+EXPORTS w32_socket @44317 NONAME
181
+EXPORTS w32_getsockopt @44318 NONAME
182
+EXPORTS w32_setsockopt @44319 NONAME
183
+EXPORTS w32_bind @44320 NONAME
184
+EXPORTS w32_listen @44321 NONAME
185
+EXPORTS w32_accept @44322 NONAME
186
+EXPORTS w32_connect @44323 NONAME
187
+EXPORTS w32_shutdown @44324 NONAME
188
+EXPORTS w32_send @44325 NONAME
189
+EXPORTS w32_recv @44326 NONAME
190
+EXPORTS w32_closesocket @44327 NONAME
191
+EXPORTS w32_getservbyname @44328 NONAME
192
+EXPORTS w32_getaddrinfo @44329 NONAME
193
+EXPORTS w32_freeaddrinfo @44330 NONAME
194
+EXPORTS w32_inet_ntop @44331 NONAME
195
+EXPORTS w32_gethostbyname @44332 NONAME
196
+EXPORTS w32_select @44333 NONAME
197
+EXPORTS poll_with_event @44334 NONAME
198
+EXPORTS w32_stat @44335 NONAME
199
+EXPORTS w32_strerror @44336 NONAME
200
+EXPORTS w32_strerror_r @44337 NONAME
201
+EXPORTS inet_addr @44338 NONAME
202
+EXPORTS fcntl @44339 NONAME
203
+
... ...
@@ -177,7 +177,7 @@ my %CONF = (
177 177
     'SIZEOF_VOID_P' => '4',
178 178
     'STDC_HEADERS' => '1',
179 179
     'SUPPORT_IPv6' => -1,
180
-    'USE_MPOOL' => -1,
180
+    'USE_MPOOL' => 1,
181 181
     'USE_SYSLOG' => -1,
182 182
     'VERSION_SUFFIX' => '""',
183 183
     'WORDS_BIGENDIAN' => '0',
... ...
@@ -192,6 +192,8 @@ my %CONF = (
192 192
     'off_t' => -1,
193 193
     'restrict' => -1,
194 194
     'socklen_t' => -1,
195
+    'HAVE_UNAME_SYSCALL' => -1,
196
+    'HAVE__INTERNAL__SHA_COLLECT' => -1
195 197
     );
196 198
 
197 199