Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wine-winehq
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wine
wine-winehq
Commits
4ebd2fc0
Commit
4ebd2fc0
authored
Aug 15, 2005
by
Alexandre Julliard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Better handling of conflicting section information between
SizeOfRawData and VirtualSize.
parent
050b9ebf
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
30 deletions
+51
-30
virtual.c
dlls/ntdll/virtual.c
+29
-22
mapping.c
server/mapping.c
+22
-8
No files found.
dlls/ntdll/virtual.c
View file @
4ebd2fc0
...
...
@@ -920,27 +920,36 @@ static NTSTATUS map_image( HANDLE hmapping, int fd, char *base, SIZE_T total_siz
for
(
i
=
pos
=
0
;
i
<
nt
->
FileHeader
.
NumberOfSections
;
i
++
,
sec
++
)
{
SIZE_T
size
;
SIZE_T
map_size
,
file_size
,
end
;
if
(
!
sec
->
Misc
.
VirtualSize
)
{
file_size
=
sec
->
SizeOfRawData
;
map_size
=
ROUND_SIZE
(
0
,
file_size
);
}
else
{
map_size
=
ROUND_SIZE
(
0
,
sec
->
Misc
.
VirtualSize
);
file_size
=
min
(
sec
->
SizeOfRawData
,
map_size
);
}
/* a few sanity checks */
size
=
sec
->
VirtualAddress
+
ROUND_SIZE
(
sec
->
VirtualAddress
,
sec
->
Misc
.
VirtualS
ize
);
if
(
sec
->
VirtualAddress
>
total_size
||
size
>
total_size
||
size
<
sec
->
VirtualAddress
)
end
=
sec
->
VirtualAddress
+
ROUND_SIZE
(
sec
->
VirtualAddress
,
map_s
ize
);
if
(
sec
->
VirtualAddress
>
total_size
||
end
>
total_size
||
end
<
sec
->
VirtualAddress
)
{
ERR_
(
module
)(
"Section %.8s too large (%lx+%lx/%lx)
\n
"
,
sec
->
Name
,
sec
->
VirtualAddress
,
sec
->
Misc
.
VirtualS
ize
,
total_size
);
sec
->
Name
,
sec
->
VirtualAddress
,
map_s
ize
,
total_size
);
goto
error
;
}
size
=
ROUND_SIZE
(
0
,
sec
->
Misc
.
VirtualSize
);
if
((
sec
->
Characteristics
&
IMAGE_SCN_MEM_SHARED
)
&&
(
sec
->
Characteristics
&
IMAGE_SCN_MEM_WRITE
))
{
TRACE_
(
module
)(
"mapping shared section %.8s at %p off %lx (%x) size %lx (%lx) flags %lx
\n
"
,
sec
->
Name
,
ptr
+
sec
->
VirtualAddress
,
sec
->
PointerToRawData
,
(
int
)
pos
,
sec
->
SizeOfRawData
,
size
,
sec
->
Characteristics
);
if
(
map_file_into_view
(
view
,
shared_fd
,
sec
->
VirtualAddress
,
size
,
pos
,
sec
->
PointerToRawData
,
(
int
)
pos
,
file_size
,
map_size
,
sec
->
Characteristics
);
if
(
map_file_into_view
(
view
,
shared_fd
,
sec
->
VirtualAddress
,
map_
size
,
pos
,
VPROT_COMMITTED
|
VPROT_READ
|
PROT_WRITE
,
FALSE
)
!=
STATUS_SUCCESS
)
{
...
...
@@ -950,33 +959,32 @@ static NTSTATUS map_image( HANDLE hmapping, int fd, char *base, SIZE_T total_siz
/* check if the import directory falls inside this section */
if
(
imports
&&
imports
->
VirtualAddress
>=
sec
->
VirtualAddress
&&
imports
->
VirtualAddress
<
sec
->
VirtualAddress
+
size
)
imports
->
VirtualAddress
<
sec
->
VirtualAddress
+
map_
size
)
{
UINT_PTR
base
=
imports
->
VirtualAddress
&
~
page_mask
;
UINT_PTR
end
=
base
+
ROUND_SIZE
(
imports
->
VirtualAddress
,
imports
->
Size
);
if
(
end
>
sec
->
VirtualAddress
+
size
)
end
=
sec
->
VirtualAddress
+
size
;
if
(
end
>
sec
->
VirtualAddress
+
map_size
)
end
=
sec
->
VirtualAddress
+
map_
size
;
if
(
end
>
base
)
map_file_into_view
(
view
,
shared_fd
,
base
,
end
-
base
,
pos
+
(
base
-
sec
->
VirtualAddress
),
VPROT_COMMITTED
|
VPROT_READ
|
VPROT_WRITECOPY
,
FALSE
);
}
pos
+=
size
;
pos
+=
map_
size
;
continue
;
}
TRACE_
(
module
)(
"mapping section %.8s at %p off %lx size %lx virt %lx flags %lx
\n
"
,
sec
->
Name
,
ptr
+
sec
->
VirtualAddress
,
sec
->
PointerToRawData
,
sec
->
SizeOfRawData
,
size
,
sec
->
Characteristics
);
s
ec
->
Misc
.
VirtualS
ize
,
sec
->
Characteristics
);
if
(
!
sec
->
PointerToRawData
||
!
sec
->
SizeOfRawData
)
continue
;
if
(
sec
->
SizeOfRawData
<
size
)
size
=
sec
->
SizeOfRawData
;
if
(
!
sec
->
PointerToRawData
||
!
file_size
)
continue
;
/* Note: if the section is not aligned properly map_file_into_view will magically
* fall back to read(), so we don't need to check anything here.
*/
if
(
map_file_into_view
(
view
,
fd
,
sec
->
VirtualAddress
,
size
,
sec
->
PointerToRawData
,
if
(
map_file_into_view
(
view
,
fd
,
sec
->
VirtualAddress
,
file_
size
,
sec
->
PointerToRawData
,
VPROT_COMMITTED
|
VPROT_READ
|
VPROT_WRITECOPY
,
removable
)
!=
STATUS_SUCCESS
)
{
...
...
@@ -984,15 +992,14 @@ static NTSTATUS map_image( HANDLE hmapping, int fd, char *base, SIZE_T total_siz
goto
error
;
}
if
(
(
sec
->
SizeOfRawData
<
sec
->
Misc
.
VirtualSize
)
&&
(
sec
->
SizeOfRawData
&
page_mask
)
)
if
(
file_size
&
page_mask
)
{
DWORD
end
=
ROUND_SIZE
(
0
,
sec
->
SizeOfRawData
);
if
(
end
>
sec
->
Misc
.
VirtualSize
)
end
=
sec
->
Misc
.
VirtualS
ize
;
end
=
ROUND_SIZE
(
0
,
file_size
);
if
(
end
>
map_size
)
end
=
map_s
ize
;
TRACE_
(
module
)(
"clearing %p - %p
\n
"
,
ptr
+
sec
->
VirtualAddress
+
sec
->
SizeOfRawData
,
ptr
+
sec
->
VirtualAddress
+
file_size
,
ptr
+
sec
->
VirtualAddress
+
end
);
memset
(
ptr
+
sec
->
VirtualAddress
+
sec
->
SizeOfRawData
,
0
,
end
-
sec
->
SizeOfRawData
);
memset
(
ptr
+
sec
->
VirtualAddress
+
file_size
,
0
,
end
-
file_size
);
}
}
...
...
server/mapping.c
View file @
4ebd2fc0
...
...
@@ -116,11 +116,25 @@ static struct file *get_shared_file( struct mapping *mapping )
return
NULL
;
}
/* return the size of the memory mapping of a given section */
static
inline
unsigned
int
get_section_map_size
(
const
IMAGE_SECTION_HEADER
*
sec
)
{
if
(
!
sec
->
Misc
.
VirtualSize
)
return
ROUND_SIZE
(
sec
->
SizeOfRawData
);
else
return
ROUND_SIZE
(
sec
->
Misc
.
VirtualSize
);
}
/* return the size of the file mapping of a given section */
static
inline
unsigned
int
get_section_filemap_size
(
const
IMAGE_SECTION_HEADER
*
sec
)
{
if
(
!
sec
->
Misc
.
VirtualSize
)
return
sec
->
SizeOfRawData
;
else
return
min
(
sec
->
SizeOfRawData
,
ROUND_SIZE
(
sec
->
Misc
.
VirtualSize
)
);
}
/* allocate and fill the temp file for a shared PE image mapping */
static
int
build_shared_mapping
(
struct
mapping
*
mapping
,
int
fd
,
IMAGE_SECTION_HEADER
*
sec
,
unsigned
int
nb_sec
)
{
unsigned
int
i
,
max_size
,
total_size
;
unsigned
int
i
,
size
,
max_size
,
total_size
;
off_t
shared_pos
,
read_pos
,
write_pos
;
char
*
buffer
=
NULL
;
int
shared_fd
;
...
...
@@ -134,9 +148,9 @@ static int build_shared_mapping( struct mapping *mapping, int fd,
if
((
sec
[
i
].
Characteristics
&
IMAGE_SCN_MEM_SHARED
)
&&
(
sec
[
i
].
Characteristics
&
IMAGE_SCN_MEM_WRITE
))
{
unsigned
int
size
=
ROUND_SIZE
(
sec
[
i
].
Misc
.
VirtualSize
);
size
=
get_section_filemap_size
(
&
sec
[
i
]
);
if
(
size
>
max_size
)
max_size
=
size
;
total_size
+=
size
;
total_size
+=
get_section_map_size
(
&
sec
[
i
]
)
;
}
}
if
(
!
(
mapping
->
shared_size
=
total_size
))
return
1
;
/* nothing to do */
...
...
@@ -159,10 +173,11 @@ 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
;
write_pos
=
shared_pos
;
shared_pos
+=
ROUND_SIZE
(
sec
[
i
].
Misc
.
VirtualSize
);
if
(
!
sec
[
i
].
PointerToRawData
||
!
sec
[
i
].
SizeOfRawData
)
continue
;
shared_pos
+=
get_section_map_size
(
&
sec
[
i
]
);
read_pos
=
sec
[
i
].
PointerToRawData
;
toread
=
sec
[
i
].
SizeOfRawData
;
size
=
get_section_filemap_size
(
&
sec
[
i
]
);
if
(
!
read_pos
||
!
size
)
continue
;
toread
=
size
;
while
(
toread
)
{
long
res
=
pread
(
fd
,
buffer
+
sec
[
i
].
SizeOfRawData
-
toread
,
toread
,
read_pos
);
...
...
@@ -170,8 +185,7 @@ static int build_shared_mapping( struct mapping *mapping, int fd,
toread
-=
res
;
read_pos
+=
res
;
}
if
(
pwrite
(
shared_fd
,
buffer
,
sec
[
i
].
SizeOfRawData
,
write_pos
)
!=
sec
[
i
].
SizeOfRawData
)
goto
error
;
if
(
pwrite
(
shared_fd
,
buffer
,
size
,
write_pos
)
!=
size
)
goto
error
;
}
free
(
buffer
);
return
1
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment