[or-cvs] r6986: Make data and size fields visible in tor_mmap_t; hide win ma (in tor/trunk: . src/common)

nickm at seul.org nickm at seul.org
Sat Aug 5 17:53:08 UTC 2006


Author: nickm
Date: 2006-08-05 13:53:08 -0400 (Sat, 05 Aug 2006)
New Revision: 6986

Modified:
   tor/trunk/
   tor/trunk/src/common/compat.c
   tor/trunk/src/common/compat.h
Log:
 r7028 at Kushana:  nickm | 2006-08-04 13:10:16 -0700
 Make data and size fields visible in tor_mmap_t; hide win magic differently.



Property changes on: tor/trunk
___________________________________________________________________
Name: svk:merge
   - 1f724f9b-111a-0410-b636-93f1a77c1813:/local/or/tor/trunk:8207
c95137ef-5f19-0410-b913-86e773d04f59:/tor/branches/eventdns:7014
c95137ef-5f19-0410-b913-86e773d04f59:/tor/branches/mmap:7027
c95137ef-5f19-0410-b913-86e773d04f59:/tor/branches/oo-connections:6950
   + 1f724f9b-111a-0410-b636-93f1a77c1813:/local/or/tor/trunk:8207
c95137ef-5f19-0410-b913-86e773d04f59:/tor/branches/eventdns:7014
c95137ef-5f19-0410-b913-86e773d04f59:/tor/branches/mmap:7028
c95137ef-5f19-0410-b913-86e773d04f59:/tor/branches/oo-connections:6950

Modified: tor/trunk/src/common/compat.c
===================================================================
--- tor/trunk/src/common/compat.c	2006-08-05 17:52:51 UTC (rev 6985)
+++ tor/trunk/src/common/compat.c	2006-08-05 17:53:08 UTC (rev 6986)
@@ -109,10 +109,6 @@
 #endif
 
 #ifdef HAVE_SYS_MMAN_H
-struct tor_mmap_t {
-  char *data;
-  size_t size;
-};
 tor_mmap_t *
 tor_mmap_file(const char *filename, const char **data, size_t *size_out)
 {
@@ -155,19 +151,18 @@
 void
 tor_munmap_file(tor_mmap_t *handle)
 {
-  munmap(handle->data, handle->size);
+  munmap((char*)handle->data, handle->size);
 }
 #elif defined(MS_WINDOWS)
-typdef struct tor_mmap_t {
-  char *data;
+typedef struct win_mmap_t {
+  tor_mmap_t base;
   HANDLE file_handle;
   HANDLE mmap_handle;
-  size_t size;
-} tor_mmap_t;
+} tor_mmap_impl_t;
 tor_mmap_t *
 tor_mmap_file(const char *filename, const char **data, size_t *size)
 {
-  win_mmap_t *res = tor_malloc_zero(res);
+  win_mmap_t *res = tor_malloc_zero(sizeof(win_mmap_t));
   res->mmap_handle = res->file_handle = INVALID_HANDLE_VALUE;
 
   res->file_handle = CreateFileForMapping(filename,
@@ -175,7 +170,7 @@
                                           0, NULL,
                                           OPEN_EXISTING,
                                           FILE_ATTRIBUTE_NORMAL, 0);
-  res->size = GetFileSize(res->file_handle, NULL);
+  res->base.size = GetFileSize(res->file_handle, NULL);
 
   res->mmap_handle = CreateFileMapping(res->file_handle,
                                        NULL,
@@ -185,16 +180,16 @@
                                        NULL);
   if (res->mmap_handle != INVALID_HANDLE_VALUE)
     goto err;
-  res->data = (char*) MapViewOfFile(res->mmap_handle,
-                                    access,
-                                    0, 0, 0);
+  res->base.data = (char*) MapViewOfFile(res->mmap_handle,
+                                         access,
+                                         0, 0, 0);
   if (!res->data)
     goto err;
 
   *size = res->size;
   *data = res->data;
 
-  return res;
+  return &(res->base);
  err:
   tor_munmap_file(res);
   return NULL;
@@ -202,6 +197,8 @@
 void
 tor_munmap_file(tor_mmap_t *handle)
 {
+  win_mmap_t *h = (win_mmap_t*)
+    (((char*)handle) - STRUCT_OFFSET(win_mmap_t, base));
   if (handle->data)
     UnmapViewOfFile(handle->data);
   if (res->mmap_handle != INVALID_HANDLE_VALUE)
@@ -211,25 +208,25 @@
   tor_free(res);
 }
 #else
-struct tor_mmap_t {
-  char *data;
-};
 tor_mmap_t *
 tor_mmap_file(const char *filename, const char **data, size_t *size)
 {
   char *res = read_file_to_str(filename, 1);
   tor_mmap_t *handle;
-  if (res)
-    *size = strlen(res) + 1;
+  if (! res)
+    return NULL;
   handle = tor_malloc_zero(sizeof(tor_mmap_t));
   *data = handle->data = res;
+  *size = handle->size = strlen(res) + 1;
   return handle;
 }
-
 void
 tor_munmap_file(tor_mmap_t *handle)
 {
-  tor_free(handle->data);
+  char *d = (char*)handle->data;
+  tor_free(d);
+  memset(handle, sizeof(tor_mmap_t), 0);
+  tor_free(handle);
 }
 #endif
 

Modified: tor/trunk/src/common/compat.h
===================================================================
--- tor/trunk/src/common/compat.h	2006-08-05 17:52:51 UTC (rev 6985)
+++ tor/trunk/src/common/compat.h	2006-08-05 17:53:08 UTC (rev 6986)
@@ -115,7 +115,10 @@
 #endif
 
 /** Opaque bookkeeping type used for mmap accounting. */
-typedef struct tor_mmap_t tor_mmap_t;
+typedef struct tor_mmap_t {
+  const char *data;
+  size_t size;
+} tor_mmap_t;
 
 tor_mmap_t *tor_mmap_file(const char *filename,
                           const char **data, size_t *size);



More information about the tor-commits mailing list