Browse code

use ANONYMOUS_MAP from clamav-config.h instead of MAP_ANONYMOUS, fix mp_flush call mp_flush from readdb

git-svn: trunk@4340

Török Edvin authored on 2008/11/05 19:46:23
Showing 4 changed files
... ...
@@ -1,3 +1,9 @@
1
+Wed Nov  5 13:17:51 EET 2008 (edwin)
2
+------------------------------------
3
+ * libclamav/mpool.c, libclamav/mpool.h, libclamav/readdb.c: use
4
+ ANONYMOUS_MAP from clamav-config.h instead of MAP_ANONYMOUS, fix
5
+ mp_flush call mp_flush from readdb
6
+
1 7
 Wed Nov  5 10:56:28 EET 2008 (edwin)
2 8
 ------------------------------------
3 9
  * libclamav/mpool.c (mp_destroy): need to use sizeof(*mp) because mp is a pointer here!!
... ...
@@ -67,6 +67,7 @@ FILE *lfd = NULL;
67 67
 /* #define MIN_FRAGSIZE 524288	/\* 0m2.387s *\/ */
68 68
 /* #define MIN_FRAGSIZE 1048576	/\* 0m2.392s *\/ */
69 69
 /* #define MIN_FRAGSIZE 2097152	/\* 0m2.402s *\/ */
70
+/* #define MIN_FRAGSIZE 99688128 */
70 71
 
71 72
 #if SIZEOF_VOID_P==8
72 73
 static const unsigned int fragsz[] = {
... ...
@@ -357,7 +358,7 @@ struct MP *mp_create() {
357 357
   sz = align_to_pagesize(&mp, MIN_FRAGSIZE);
358 358
   mp.mpm.usize = align_to_voidptr(sizeof(struct MPMAP));
359 359
   mp.mpm.size = sz - align_to_voidptr(sizeof(mp));
360
-  if ((mp_p = (struct MP *)mmap(NULL, sz, PROT_READ | PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0)) == MAP_FAILED)
360
+  if ((mp_p = (struct MP *)mmap(NULL, sz, PROT_READ | PROT_WRITE, MAP_PRIVATE|ANONYMOUS_MAP, -1, 0)) == MAP_FAILED)
361 361
     return NULL;
362 362
   memcpy(mp_p, &mp, sizeof(mp));
363 363
   spam("Map created @ %p->%p - size %u out of %u\n", mp_p, (void*)mp_p + mp.mpm.size, mp.mpm.usize, mp.mpm.size);
... ...
@@ -375,15 +376,22 @@ void mp_destroy(struct MP *mp) {
375 375
 }
376 376
 
377 377
 void mp_flush(struct MP *mp) {
378
+  size_t used = 0, mused;
378 379
   struct MPMAP *mpm_next = mp->mpm.next, *mpm;
379 380
   while((mpm = mpm_next)) {
380 381
     mpm_next = mpm->next;
381 382
     munmap((void *)mpm + align_to_pagesize(mp, mpm->usize), mpm->size - align_to_pagesize(mp, mpm->usize));
382
-    mpm->size = mpm->usize = align_to_pagesize(mp, mpm->usize);
383
+    mpm->size = align_to_pagesize(mp, mpm->usize);
384
+    used += mpm->size;
383 385
   }
384
-  munmap(&mp->mpm + align_to_pagesize(mp, mp->mpm.usize + align_to_voidptr(sizeof(mp))), mp->mpm.size - align_to_pagesize(mp, mp->mpm.usize + align_to_voidptr(sizeof(mp))));
385
-  mp->mpm.size = mp->mpm.usize;
386
-  spam("Map flushed @ %p\n", mp);
386
+  mused = align_to_pagesize(mp, mp->mpm.usize + align_to_voidptr(sizeof(*mp)));
387
+  if (mused < mp->mpm.size) {
388
+	  munmap(&mp->mpm + mused, mp->mpm.size - mused);
389
+	  mp->mpm.size = mused;
390
+  }
391
+  used += mp->mpm.size;
392
+  spam("Map flushed @ %p, in use: %lu\n", mp, used);
393
+  return used;
387 394
 }
388 395
 
389 396
 void *mp_malloc(struct MP *mp, size_t size) {
... ...
@@ -36,6 +36,7 @@ unsigned char *cli_mp_hex2str(mp_t* mp, const unsigned char *src);
36 36
 char *cli_mp_strdup(mp_t *mp, const char *s);
37 37
 char *cli_mp_virname(mp_t *mp, char *virname, unsigned int official);
38 38
 uint16_t *cli_mp_hex2ui(mp_t *mp, const char *hex);
39
+void mp_flush(mp_t *mp);
39 40
 #else /* USE_MPOOL */
40 41
 
41 42
 #define mp_malloc(a, b) cli_malloc(b)
... ...
@@ -47,6 +48,7 @@ uint16_t *cli_mp_hex2ui(mp_t *mp, const char *hex);
47 47
 #define cli_mp_strdup(mp, s) cli_strdup(s)
48 48
 #define cli_mp_virname(mp, a, b) cli_virname(a, b)
49 49
 #define cli_mp_hex2ui(mp, hex) cli_hex2ui(hex)
50
+#define mp_flush(val)
50 51
 #endif /* USE_MPOOL */
51 52
 
52 53
 #endif
... ...
@@ -2143,6 +2143,7 @@ int cl_build(struct cl_engine *engine)
2143 2143
     cli_md5db_build(engine->md5_mdb);
2144 2144
     cli_freeign(engine);
2145 2145
     cli_dconf_print(engine->dconf);
2146
+    mp_flush(engine->mempool);
2146 2147
 
2147 2148
     return CL_SUCCESS;
2148 2149
 }