]> mj.ucw.cz Git - libucw.git/commitdiff
added lizard_realloc() to avoid restoring and reestablishing SIGSEGv handler
authorRobert Spalek <robert@ucw.cz>
Fri, 25 Jun 2004 16:37:50 +0000 (16:37 +0000)
committerRobert Spalek <robert@ucw.cz>
Fri, 25 Jun 2004 16:37:50 +0000 (16:37 +0000)
lib/lizard-safe.c
lib/lizard.h

index 1c46cbdcbb58d211cd27cfb5a316a8917f1d64ae..4e07036a67a5a1eed30f3bb27b55a2c1efd62778 100644 (file)
 #include <setjmp.h>
 #include <errno.h>
 
-struct lizard_buffer *
-lizard_alloc(uns max_len)
+static void
+lizard_alloc_internal(struct lizard_buffer *buf, uns max_len)
 {
-  struct lizard_buffer *buf = xmalloc(sizeof(struct lizard_buffer));
   buf->len = ALIGN(max_len + 3, PAGE_SIZE);            // +3 due to the unaligned access
   buf->start = mmap(NULL, buf->len + PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
   if (buf->start == MAP_FAILED)
     die("mmap(anonymous): %m");
   if (mprotect(buf->start + buf->len, PAGE_SIZE, PROT_NONE) < 0)
     die("mprotect: %m");
+}
+
+struct lizard_buffer *
+lizard_alloc(uns max_len)
+{
+  struct lizard_buffer *buf = xmalloc(sizeof(struct lizard_buffer));
+  lizard_alloc_internal(buf, max_len);
   buf->old_sigsegv_handler = xmalloc(sizeof(struct sigaction));
   handle_signal(SIGSEGV, buf->old_sigsegv_handler);
   return buf;
@@ -42,6 +48,13 @@ lizard_free(struct lizard_buffer *buf)
   xfree(buf);
 }
 
+void
+lizard_realloc(struct lizard_buffer *buf, uns max_len)
+{
+  munmap(buf->start, buf->len + PAGE_SIZE);
+  lizard_alloc_internal(buf, max_len);
+}
+
 static jmp_buf safe_decompress_jump;
 static int
 sigsegv_handler(int signal UNUSED)
index fc3631ac1103f829263fced390c8281a3cffba8b..3f72b96cdce392bdca47b26d4e6498982a5c2e38 100644 (file)
@@ -37,4 +37,5 @@ struct lizard_buffer {
 
 struct lizard_buffer *lizard_alloc(uns max_len);
 void lizard_free(struct lizard_buffer *buf);
+void lizard_realloc(struct lizard_buffer *buf, uns max_len);
 int lizard_decompress_safe(byte *in, struct lizard_buffer *buf, uns expected_length);