remove mutex in nsis/zlib

git-svn: trunk@4379
0.95
aCaB 17 years ago
parent 0acb334efb
commit cadf86d46f
  1. 4
      ChangeLog
  2. 34
      libclamav/nsis/infblock.c
  3. 21
      libclamav/nsis/nsis_zlib.h
  4. 15
      libclamav/nsis/nulsft.c

@ -1,3 +1,7 @@
Tue Nov 11 20:42:28 CET 2008 (acab)
-----------------------------------
* libclamav/nsis: improve lateny (bb#1180)
Mon Nov 10 20:12:47 EET 2008 (edwin)
------------------------------------
* configure, libltdl/: regenerate libltdl/ to get rid of bunch of

@ -52,16 +52,13 @@
#define LAST (s->last == DRY)
#define FIXEDH 544 /* number of hufts used by fixed tables */
typedef struct inflate_blocks_state FAR inflate_blocks_statef;
#define exop word.what.Exop
#define bits word.what.Bits
/* And'ing with mask[n] masks the lower n bits */
local unsigned short inflate_mask[17] = {
local const unsigned short inflate_mask[17] = {
0x0000,
0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff,
0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff
@ -87,12 +84,13 @@ local const unsigned short cpdext[30] = { /* Extra bits for distance codes */
12, 12, 13, 13};
/* build fixed tables only once--keep them here */
local char fixed_built = 0;
local inflate_huft fixed_mem[FIXEDH];
local uInt fixed_bl=9;
local uInt fixed_bd=5;
local inflate_huft *fixed_tl;
local inflate_huft *fixed_td;
/* local char fixed_built = 0; */
/* local inflate_huft fixed_mem[FIXEDH]; */
/* local uInt fixed_bl=9; */
/* local uInt fixed_bd=5; */
/* local inflate_huft *fixed_tl; */
/* local inflate_huft *fixed_td; */
/* copy as much as possible from the sliding window to the output area */
local void ZEXPORT inflate_flush(nsis_z_streamp z)
@ -380,7 +378,7 @@ int ZEXPORT nsis_inflate(nsis_z_streamp z)
Tracev((stderr, "inflate: fixed codes block%s\n",
LAST ? " (last)" : ""));
{
if (!fixed_built)
if (!s->zs.fixed_built)
{
int _k; /* temporary variable */
uInt f = 0; /* number of hufts used in fixed_mem */
@ -398,22 +396,22 @@ int ZEXPORT nsis_inflate(nsis_z_streamp z)
lc[_k] = v;
}
huft_build(lc, 288, 257, cplens, cplext, &fixed_tl, &fixed_bl, fixed_mem, &f);
huft_build(lc, 288, 257, cplens, cplext, &s->zs.fixed_tl, &s->zs.fixed_bl, s->zs.fixed_mem, &f);
/* distance table */
for (_k = 0; _k < 30; _k++) lc[_k] = 5;
huft_build(lc, 30, 0, cpdist, cpdext, &fixed_td, &fixed_bd, fixed_mem, &f);
huft_build(lc, 30, 0, cpdist, cpdext, &s->zs.fixed_td, &s->zs.fixed_bd, s->zs.fixed_mem, &f);
/* done */
fixed_built++;
s->zs.fixed_built++;
}
/* s->sub.decode.t_codes.mode = CODES_START; */
s->sub.decode.t_codes.lbits = (Byte)fixed_bl;
s->sub.decode.t_codes.dbits = (Byte)fixed_bd;
s->sub.decode.t_codes.ltree = fixed_tl;
s->sub.decode.t_codes.dtree = fixed_td;
s->sub.decode.t_codes.lbits = (Byte)s->zs.fixed_bl;
s->sub.decode.t_codes.dbits = (Byte)s->zs.fixed_bd;
s->sub.decode.t_codes.ltree = s->zs.fixed_tl;
s->sub.decode.t_codes.dtree = s->zs.fixed_td;
}
s->mode = CODES_START;
break;

@ -107,7 +107,20 @@ struct inflate_huft_s {
typedef struct inflate_codes_state inflate_codes_statef;
#define FIXEDH 544 /* number of hufts used by fixed tables */
struct z_stuff {
char fixed_built;
inflate_huft fixed_mem[FIXEDH];
uInt fixed_bl;
uInt fixed_bd;
inflate_huft *fixed_tl;
inflate_huft *fixed_td;
};
struct inflate_blocks_state {
/* acab */
struct z_stuff zs;
/* mode */
inflate_mode mode; /* current inflate_block mode */
@ -200,7 +213,13 @@ typedef nsis_z_stream FAR *nsis_z_streamp;
#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */
#define nsis_inflateInit(x) inflateReset(x)
#define nsis_inflateInit(z) \
{ \
(z)->blocks.zs.fixed_built = 0; \
(z)->blocks.zs.fixed_bl = 9; \
(z)->blocks.zs.fixed_bd = 5; \
inflateReset(z); \
}
int ZEXPORT nsis_inflate(nsis_z_streamp z);
#define inflateReset(z) \
{ \

@ -47,13 +47,6 @@
#include "scanners.h"
#include "nulsft.h" /* SHUT UP GCC -Wextra */
/* NSIS zlib is not thread safe */
#ifdef CL_THREAD_SAFE
# include <pthread.h>
static pthread_mutex_t nsis_mutex = PTHREAD_MUTEX_INITIALIZER;
#endif
/* NSIS zlib is not thread safe */
#ifndef O_BINARY
#define O_BINARY 0
#endif
@ -108,7 +101,7 @@ static int nsis_init(struct nsis_st *n) {
n->freecomp=1;
break;
case COMP_ZLIB:
memset(&n->bz, 0, sizeof(z_stream));
memset(&n->z, 0, sizeof(z_stream));
/* inflateInit2(&n->z, -MAX_WBITS); */
/* n->freecomp=1; */
nsis_inflateInit(&n->z);
@ -555,13 +548,7 @@ int cli_scannulsft(int desc, cli_ctx *ctx, off_t offset) {
if(cli_leavetemps_flag) cli_dbgmsg("NSIS: Extracting files to %s\n", nsist.dir);
do {
#ifdef CL_THREAD_SAFE
pthread_mutex_lock(&nsis_mutex);
#endif
ret = cli_nsis_unpack(&nsist, ctx);
#ifdef CL_THREAD_SAFE
pthread_mutex_unlock(&nsis_mutex);
#endif
if (ret == CL_SUCCESS) {
cli_dbgmsg("NSIS: Successully extracted file #%u\n", nsist.fno);
lseek(nsist.ofd, 0, SEEK_SET);

Loading…
Cancel
Save