Skip to contentSkip to conversation

linux-user: use libc wrapper instead of direct mremap syscall

PATCH Applied Felix Janda 3 participants 4 messages Sep 30, 2016 – Oct 7, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 linux-user: use libc wrapper instead of direct mremap syscall

This commit essentially reverts commit 3af72a4d98dca033492102603734cbc63cd2694a, which has replaced five-argument calls to mremap() by direct mremap syscalls for compatibility with glibc older than version 2.4.

The direct syscall was buggy for 64bit targets on 32bit hosts because of the default integer type promotions. Since glibc-2.4 is now a decade old, we can remove this workaround.

---
 linux-user/mmap.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)
linux-user/mmap.c +4 -10
index c4371d9..ffd099d 100644
@@ -17,8 +17,6 @@
  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 #include "qemu/osdep.h"
-#include <linux/mman.h>
-#include <linux/unistd.h>
 
 #include "qemu.h"
 #include "qemu-common.h"
@@ -681,10 +679,8 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size,
     mmap_lock();
 
     if (flags & MREMAP_FIXED) {
-        host_addr = (void *) syscall(__NR_mremap, g2h(old_addr),
-                                     old_size, new_size,
-                                     flags,
-                                     g2h(new_addr));
+        host_addr = mremap(g2h(old_addr), old_size, new_size,
+                           flags, g2h(new_addr));
 
         if (reserved_va && host_addr != MAP_FAILED) {
             /* If new and old addresses overlap then the above mremap will
@@ -700,10 +696,8 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size,
             errno = ENOMEM;
             host_addr = MAP_FAILED;
         } else {
-            host_addr = (void *) syscall(__NR_mremap, g2h(old_addr),
-                                         old_size, new_size,
-                                         flags | MREMAP_FIXED,
-                                         g2h(mmap_start));
+            host_addr = mremap(g2h(old_addr), old_size, new_size,
+                               flags | MREMAP_FIXED, g2h(mmap_start));
             if (reserved_va) {
                 mmap_reserve(old_addr, old_size);
             }
Signature · 1 line
2.7.3
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Felix Janda

This commit essentially reverts commit 3af72a4d98dca033492102603734cbc63cd2694a, which has replaced five-argument calls to mremap() by direct mremap syscalls for compatibility with glibc older than version 2.4.

The direct syscall was buggy for 64bit targets on 32bit hosts because of the default integer type promotions. Since glibc-2.4 is now a decade old, we can remove this workaround.

thanks
-- PMM

Applied
#2 lore raw
Quoted 6 lines · Peter Maydell
Quoted 5 lines · Felix Janda

This commit essentially reverts commit 3af72a4d98dca033492102603734cbc63cd2694a, which has replaced five-argument calls to mremap() by direct mremap syscalls for compatibility with glibc older than version 2.4.

Quoted 8 lines
Quoted 5 lines

The direct syscall was buggy for 64bit targets on 32bit hosts because of the default integer type promotions. Since glibc-2.4 is now a decade old, we can remove this workaround.

Applied to linux-user, thanks

Applied
#3 lore raw
In reply to Felix Janda
Quoted 8 lines · Felix Janda

This commit essentially reverts commit 3af72a4d98dca033492102603734cbc63cd2694a, which has replaced five-argument calls to mremap() by direct mremap syscalls for compatibility with glibc older than version 2.4.

The direct syscall was buggy for 64bit targets on 32bit hosts because of the default integer type promotions. Since glibc-2.4 is now a decade old, we can remove this workaround.

Applied this and the <poll.h> patch to linux-user

Thanks,
Riku

Quoted 48 lines
---
 linux-user/mmap.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)
linux-user/mmap.c +4 -10
index c4371d9..ffd099d 100644
@@ -17,8 +17,6 @@
  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 #include "qemu/osdep.h"
-#include <linux/mman.h>
-#include <linux/unistd.h>
 
 #include "qemu.h"
 #include "qemu-common.h"
@@ -681,10 +679,8 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size,
     mmap_lock();
 
     if (flags & MREMAP_FIXED) {
-        host_addr = (void *) syscall(__NR_mremap, g2h(old_addr),
-                                     old_size, new_size,
-                                     flags,
-                                     g2h(new_addr));
+        host_addr = mremap(g2h(old_addr), old_size, new_size,
+                           flags, g2h(new_addr));
 
         if (reserved_va && host_addr != MAP_FAILED) {
             /* If new and old addresses overlap then the above mremap will
@@ -700,10 +696,8 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size,
             errno = ENOMEM;
             host_addr = MAP_FAILED;
         } else {
-            host_addr = (void *) syscall(__NR_mremap, g2h(old_addr),
-                                         old_size, new_size,
-                                         flags | MREMAP_FIXED,
-                                         g2h(mmap_start));
+            host_addr = mremap(g2h(old_addr), old_size, new_size,
+                               flags | MREMAP_FIXED, g2h(mmap_start));
             if (reserved_va) {
                 mmap_reserve(old_addr, old_size);
             }
Signature · 1 line
2.7.3