[CRIU] [PATCH 4/7] [nitpick] For anon mmap(), fd should be -1

Kir Kolyshkin kir at openvz.org
Fri Feb 10 18:30:07 EST 2012


It's probably not a bug to pass 0 as fd, but mmap(3) says that
"the fd and offset arguments are ignored; however, some implementa‐
tions require fd to be -1 if MAP_ANONYMOUS (or MAP_ANON) is
specified, and portable applications should ensure this."

crtools is way far from being a portable app :) but let's
be consistent since we use -1 in other places like these.

Signed-off-by: Kir Kolyshkin <kir at openvz.org>
---
 cr-restore.c                          |    8 ++++----
 files.c                               |    4 ++--
 test/zdtm/live/transition/file_read.c |    2 +-
 test/zdtm/live/transition/ptrace.c    |    2 +-
 4 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/cr-restore.c b/cr-restore.c
index cc6cd9a..d0dd932 100644
--- a/cr-restore.c
+++ b/cr-restore.c
@@ -376,7 +376,7 @@ static int prepare_shared(int ps_fd)
 		return -1;
 	task_pids->nr = 0;
 
-	shmems = mmap(NULL, SHMEMS_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, 0, 0);
+	shmems = mmap(NULL, SHMEMS_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0);
 	if (shmems == MAP_FAILED) {
 		pr_perror("Can't map shmem");
 		return -1;
@@ -384,7 +384,7 @@ static int prepare_shared(int ps_fd)
 
 	shmems->nr_shmems = 0;
 
-	task_entries = mmap(NULL, TASK_ENTRIES_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, 0, 0);
+	task_entries = mmap(NULL, TASK_ENTRIES_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0);
 	if (task_entries == MAP_FAILED) {
 		pr_perror("Can't map shmem");
 		return -1;
@@ -392,7 +392,7 @@ static int prepare_shared(int ps_fd)
 	task_entries->nr = 0;
 	task_entries->start = CR_STATE_RESTORE;
 
-	pipes = mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, 0, 0);
+	pipes = mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0);
 	if (pipes == MAP_FAILED) {
 		pr_perror("Can't map pipes");
 		return -1;
@@ -1740,7 +1740,7 @@ static void sigreturn_restore(pid_t pid)
 	exec_mem = mmap((void *)exec_mem_hint,
 			restore_task_vma_len + restore_thread_vma_len,
 			PROT_READ | PROT_WRITE | PROT_EXEC,
-			MAP_PRIVATE | MAP_ANON, 0, 0);
+			MAP_PRIVATE | MAP_ANON, -1, 0);
 	if (exec_mem == MAP_FAILED) {
 		pr_err("Can't mmap section for restore code\n");
 		goto err;
diff --git a/files.c b/files.c
index 23a8f3e..459d2c0 100644
--- a/files.c
+++ b/files.c
@@ -88,14 +88,14 @@ static int get_file_path(char *path, const struct fdinfo_entry *fe, int fd)
 int prepare_fdinfo_global()
 {
 	fdinfo_descs = mmap(NULL, 4096, PROT_READ | PROT_WRITE,
-			MAP_SHARED | MAP_ANON, 0, 0);
+			MAP_SHARED | MAP_ANON, -1, 0);
 	if (fdinfo_descs == MAP_FAILED) {
 		pr_perror("Can't map fdinfo_descs");
 		return -1;
 	}
 
 	fdinfo_list = mmap(NULL, 4096, PROT_READ | PROT_WRITE,
-			MAP_SHARED | MAP_ANON, 0, 0);
+			MAP_SHARED | MAP_ANON, -1, 0);
 	if (fdinfo_list == MAP_FAILED) {
 		pr_perror("Can't map fdinfo_list");
 		return -1;
diff --git a/test/zdtm/live/transition/file_read.c b/test/zdtm/live/transition/file_read.c
index 41f7dca..84e077a 100644
--- a/test/zdtm/live/transition/file_read.c
+++ b/test/zdtm/live/transition/file_read.c
@@ -117,7 +117,7 @@ static void chew_some_file(int num)
 	int fd, rv;
 
 	buf = mmap(NULL, FILE_SIZE, PROT_READ | PROT_WRITE,
-			MAP_PRIVATE | MAP_ANON, 0, 0);
+			MAP_PRIVATE | MAP_ANON, -1, 0);
 	rv = MMAP_FAILED;
 	if (buf == MAP_FAILED)
 		goto out_exit;
diff --git a/test/zdtm/live/transition/ptrace.c b/test/zdtm/live/transition/ptrace.c
index 1f1cd97..6ac7ba5 100644
--- a/test/zdtm/live/transition/ptrace.c
+++ b/test/zdtm/live/transition/ptrace.c
@@ -41,7 +41,7 @@ int main(int argc, char **argv)
 
 	pids = (int *)mmap(NULL, sizeof(int) * nr_threads,
 			PROT_READ | PROT_WRITE,
-			MAP_SHARED | MAP_ANON, 0, 0);
+			MAP_SHARED | MAP_ANON, -1, 0);
 	if (pids == MAP_FAILED) {
 		err("Can't map");
 		exit(1);
-- 
1.7.7.6




More information about the CRIU mailing list