Skip to content

Commit

Permalink
linux-user: Simplify target_madvise
Browse files Browse the repository at this point in the history
The trivial length 0 check can be moved up, simplifying some
of the other cases.  The end < start test is handled by
guest_range_valid_untagged.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20230707204054.8792-27-richard.henderson@linaro.org>
  • Loading branch information
rth7680 committed Jul 15, 2023
1 parent ecb796d commit e230ec0
Showing 1 changed file with 4 additions and 15 deletions.
19 changes: 4 additions & 15 deletions linux-user/mmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -900,28 +900,17 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size,

abi_long target_madvise(abi_ulong start, abi_ulong len_in, int advice)
{
abi_ulong len, end;
abi_ulong len;
int ret = 0;

if (start & ~TARGET_PAGE_MASK) {
return -TARGET_EINVAL;
}
len = TARGET_PAGE_ALIGN(len_in);

if (len_in && !len) {
return -TARGET_EINVAL;
}

end = start + len;
if (end < start) {
return -TARGET_EINVAL;
}

if (end == start) {
if (len_in == 0) {
return 0;
}

if (!guest_range_valid_untagged(start, len)) {
len = TARGET_PAGE_ALIGN(len_in);
if (len == 0 || !guest_range_valid_untagged(start, len)) {
return -TARGET_EINVAL;
}

Expand Down

0 comments on commit e230ec0

Please sign in to comment.