[PATCH] server: clear area when file size is not full page.
Chao Long
longchao at uniontech.com
Wed Apr 13 20:19:34 CDT 2022
From: chenjiangyi <chenjiangyi at uniontech.com>
Signed-off-by: chenjiangyi <chenjiangyi at uniontech.com>
---
server/mapping.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/server/mapping.c b/server/mapping.c
index 8d4332d240f..4730d93be90 100644
--- a/server/mapping.c
+++ b/server/mapping.c
@@ -558,7 +558,7 @@ static int build_shared_mapping( struct mapping *mapping, int fd,
struct file *file;
unsigned int i;
mem_size_t total_size;
- size_t file_size, map_size, max_size;
+ size_t file_size, map_size, max_size, file_roundsize;
off_t shared_pos, read_pos, write_pos;
char *buffer = NULL;
int shared_fd;
@@ -595,6 +595,7 @@ static int build_shared_mapping( struct mapping *mapping, int fd,
{
if (!(sec[i].Characteristics & IMAGE_SCN_MEM_SHARED)) continue;
if (!(sec[i].Characteristics & IMAGE_SCN_MEM_WRITE)) continue;
+ memset(buffer, 0, max_size);
get_section_sizes( &sec[i], &map_size, &read_pos, &file_size );
write_pos = shared_pos;
shared_pos += map_size;
@@ -612,7 +613,16 @@ static int build_shared_mapping( struct mapping *mapping, int fd,
toread -= res;
read_pos += res;
}
- if (pwrite( shared_fd, buffer, file_size, write_pos ) != file_size) goto error;
+ if (file_size & page_mask)
+ {
+ file_roundsize = ROUND_SIZE( file_size );
+ if (file_roundsize > map_size) file_roundsize = map_size;
+ if (pwrite( shared_fd, buffer, file_roundsize, write_pos ) != file_roundsize) goto error;
+ }
+ else
+ {
+ if (pwrite( shared_fd, buffer, file_size, write_pos ) != file_size) goto error;
+ }
}
if (!(shared = alloc_object( &shared_map_ops ))) goto error;
--
2.20.1
More information about the wine-devel
mailing list