[CRIU] [PATCH 11/20] multiarch: generalized format strings to prevent invalid format string warnings and segfaults on ARM.

alekskartashov at parallels.com alekskartashov at parallels.com
Wed Dec 12 08:34:21 EST 2012


From: Alexander Kartashov <alekskartashov at parallels.com>

Signed-off-by: Alexander Kartashov <alekskartashov at parallels.com>
---
 cr-show.c      |   23 +++++++++--------------
 eventfd.c      |    2 +-
 eventpoll.c    |    2 +-
 files-reg.c    |    2 +-
 inotify.c      |    8 ++++----
 ipc_ns.c       |    4 ++--
 pie/restorer.c |   10 +++++-----
 pipes.c        |    2 +-
 proc_parse.c   |   24 ++++++++++++------------
 pstree.c       |    4 ++++
 shmem.c        |   10 +++++-----
 sk-inet.c      |    2 +-
 sk-packet.c    |    4 ++--
 sysctl.c       |    6 +++---
 util.c         |   10 ++++++----
 15 files changed, 57 insertions(+), 56 deletions(-)

diff --git a/cr-show.c b/cr-show.c
index 48031f8..71e1ae4 100644
--- a/cr-show.c
+++ b/cr-show.c
@@ -45,11 +45,6 @@
 
 #define DEF_PAGES_PER_LINE	6
 
-#ifndef CONFIG_X86_64
-# error No x86-32 support yet
-#endif
-
-
 #define PR_SYMBOL(sym)			\
 	(isprint(sym) ? sym : '.')
 
@@ -231,7 +226,7 @@ void show_pages(int fd_pages, struct cr_options *o)
 					goto out;
 				}
 
-				pr_msg("0x%16lx ", e.va);
+				pr_msg("0x%16"PRIx64" ", e.va);
 			}
 			pr_msg("\n");
 		}
@@ -305,19 +300,19 @@ static inline char *task_state_str(int state)
 static void show_core_regs(UserX86RegsEntry *regs)
 {
 #define pr_regs4(s, n1, n2, n3, n4)	\
-	pr_msg("\t%8s: 0x%-16lx "	\
-	       "%8s: 0x%-16lx "		\
-	       "%8s: 0x%-16lx "		\
-	       "%8s: 0x%-16lx\n",	\
+	pr_msg("\t%8s: 0x%-16"PRIx64" "	\
+	       "%8s: 0x%-16"PRIx64" "	\
+	       "%8s: 0x%-16"PRIx64" "	\
+	       "%8s: 0x%-16"PRIx64"\n",	\
 	       #n1, s->n1,		\
 	       #n2, s->n2,		\
 	       #n3, s->n3,		\
 	       #n4, s->n4)
 
 #define pr_regs3(s, n1, n2, n3)		\
-	pr_msg("\t%8s: 0x%-16lx "	\
-	       "%8s: 0x%-16lx "		\
-	       "%8s: 0x%-16lx\n",	\
+	pr_msg("\t%8s: 0x%-16"PRIx64" "	\
+	       "%8s: 0x%-16"PRIx64" "	\
+	       "%8s: 0x%-16"PRIx64"\n",	\
 	       #n1, s->n1,		\
 	       #n2, s->n2,		\
 	       #n3, s->n3)
@@ -340,7 +335,7 @@ void show_thread_info(ThreadInfoX86 *thread_info)
 		return;
 
 	pr_msg("\t---[ Thread info ]---\n");
-	pr_msg("\tclear_tid_addr:  0x%lx\n", thread_info->clear_tid_addr);
+	pr_msg("\tclear_tid_addr:  0x%"PRIx64"\n", thread_info->clear_tid_addr);
 	pr_msg("\n");
 
 	show_core_regs(thread_info->gpregs);
diff --git a/eventfd.c b/eventfd.c
index 75c8b84..8d65f2d 100644
--- a/eventfd.c
+++ b/eventfd.c
@@ -40,7 +40,7 @@ int is_eventfd_link(int lfd)
 
 static void pr_info_eventfd(char *action, EventfdFileEntry *efe)
 {
-	pr_info("%s: id %#08x flags %#04x counter %#016lx\n",
+	pr_info("%s: id %#08x flags %#04x counter %#016"PRIx64"\n",
 		action, efe->id, efe->flags, efe->counter);
 }
 
diff --git a/eventpoll.c b/eventpoll.c
index c67bc07..4ad97ae 100644
--- a/eventpoll.c
+++ b/eventpoll.c
@@ -47,7 +47,7 @@ int is_eventpoll_link(int lfd)
 
 static void pr_info_eventpoll_tfd(char *action, EventpollTfdEntry *e)
 {
-	pr_info("%seventpoll-tfd: id %#08x tfd %#08x events %#08x data %#016lx\n",
+	pr_info("%seventpoll-tfd: id %#08x tfd %#08x events %#08x data %#016"PRIx64"\n",
 		action, e->id, e->tfd, e->events, e->data);
 }
 
diff --git a/files-reg.c b/files-reg.c
index c99c349..5147847 100644
--- a/files-reg.c
+++ b/files-reg.c
@@ -288,7 +288,7 @@ static int dump_ghost_remap(char *path, const struct stat *st, int lfd, u32 id)
 	pr_info("Dumping ghost file for fd %d id %#x\n", lfd, id);
 
 	if (st->st_size > MAX_GHOST_FILE_SIZE) {
-		pr_err("Can't dump ghost file %s of %lu size\n",
+		pr_err("Can't dump ghost file %s of %"PRIu64" size\n",
 				path, st->st_size);
 		return -1;
 	}
diff --git a/inotify.c b/inotify.c
index 1e54288..a87bc0c 100644
--- a/inotify.c
+++ b/inotify.c
@@ -77,9 +77,9 @@ static int dump_inotify_entry(union fdinfo_entries *e, void *arg)
 	InotifyWdEntry *we = &e->ify;
 
 	we->id = *(u32 *)arg;
-	pr_info("wd: wd 0x%08x s_dev 0x%08x i_ino 0x%16lx mask 0x%08x\n",
+	pr_info("wd: wd 0x%08x s_dev 0x%08x i_ino 0x%16"PRIx64" mask 0x%08x\n",
 			we->wd, we->s_dev, we->i_ino, we->mask);
-	pr_info("\t[fhandle] bytes 0x%08x type 0x%08x __handle 0x%016lx:0x%016lx\n",
+	pr_info("\t[fhandle] bytes 0x%08x type 0x%08x __handle 0x%016"PRIx64":0x%016"PRIx64"\n",
 			we->f_handle->bytes, we->f_handle->type,
 			we->f_handle->handle[0], we->f_handle->handle[1]);
 	return pb_write_one(fdset_fd(glob_fdset, CR_FD_INOTIFY_WD), we, PB_INOTIFY_WD);
@@ -135,7 +135,7 @@ static int restore_one_inotify(int inotify_fd, struct inotify_wd_info *info)
 	if (!info->remap) {
 		target = sys_open_by_handle_at(mntfd, (void *)&handle, 0);
 		if (target < 0) {
-			pr_perror("Can't open file handle for 0x%08x:0x%016lx",
+			pr_perror("Can't open file handle for 0x%08x:0x%016"PRIx64,
 				  iwe->s_dev, iwe->i_ino);
 			goto err;
 		}
@@ -143,7 +143,7 @@ static int restore_one_inotify(int inotify_fd, struct inotify_wd_info *info)
 	} else
 		path = info->remap->path;
 
-	pr_debug("\t\tRestore watch for 0x%08x:0x%016lx\n", iwe->s_dev, iwe->i_ino);
+	pr_debug("\t\tRestore watch for 0x%08x:0x%016"PRIx64"\n", iwe->s_dev, iwe->i_ino);
 
 	/*
 	 * FIXME The kernel allocates wd-s sequentially,
diff --git a/ipc_ns.c b/ipc_ns.c
index 223a436..8819fc8 100644
--- a/ipc_ns.c
+++ b/ipc_ns.c
@@ -155,7 +155,7 @@ static int dump_ipc_sem(int fd)
 
 static void pr_info_ipc_msg(int nr, const IpcMsg *msg)
 {
-	print_on_level(LOG_INFO, "  %-5d: type: %-20ld size: %-10d\n",
+	print_on_level(LOG_INFO, "  %-5d: type: %-20"PRId64" size: %-10d\n",
 		       nr++, msg->mtype, msg->msize);
 }
 
@@ -280,7 +280,7 @@ static int dump_ipc_msg(int fd)
 static void pr_info_ipc_shm(const IpcShmEntry *shm)
 {
 	pr_ipc_desc_entry(LOG_INFO, shm->desc);
-	print_on_level(LOG_INFO, "size: %-10lu\n", shm->size);
+	print_on_level(LOG_INFO, "size: %-10"PRIu64"\n", shm->size);
 }
 
 static int ipc_sysctl_req(IpcVarEntry *e, int op)
diff --git a/pie/restorer.c b/pie/restorer.c
index ec1ceb2..ba8451f 100644
--- a/pie/restorer.c
+++ b/pie/restorer.c
@@ -149,7 +149,7 @@ static int restore_thread_common(struct rt_sigframe *sigframe,
 {
 	int ret;
 
-	sys_set_tid_address((int *)args->clear_tid_addr);
+	sys_set_tid_address((int *)(int32_t)args->clear_tid_addr);
 
 	if (args->has_futex) {
 		if (sys_set_robust_list((void *)args->futex_rla, args->futex_rla_len)) {
@@ -254,7 +254,7 @@ static u64 restore_mapping(const VmaEntry *vma_entry)
 	if (vma_entry->fd == -1 || !(vma_entry->flags & MAP_SHARED))
 		prot |= PROT_WRITE;
 
-	pr_debug("\tmmap(%lx -> %lx, %x %x %d\n",
+	pr_debug("\tmmap(%"PRIx64" -> %"PRIx64", %x %x %d\n",
 			vma_entry->start, vma_entry->end,
 			prot, flags, (int)vma_entry->fd);
 	/*
@@ -399,7 +399,7 @@ long __export_restore_task(struct task_restore_core_args *args)
 		if (!vma_entry_is(vma_entry, VMA_AREA_REGULAR))
 			continue;
 
-		pr_debug("Examine %lx-%lx\n", vma_entry->start, vma_entry->end);
+		pr_debug("Examine %"PRIx64"-%"PRIx64"\n", vma_entry->start, vma_entry->end);
 
 		if (addr < args->premmapped_addr) {
 			if (vma_entry->end >= args->premmapped_addr)
@@ -484,7 +484,7 @@ long __export_restore_task(struct task_restore_core_args *args)
 		va = restore_mapping(vma_entry);
 
 		if (va != vma_entry->start) {
-			pr_err("Can't restore %lx mapping with %lx\n", vma_entry->start, va);
+			pr_err("Can't restore %"PRIx64" mapping with %"PRIx64"\n", vma_entry->start, va);
 			goto core_restore_end;
 		}
 	}
@@ -529,7 +529,7 @@ long __export_restore_task(struct task_restore_core_args *args)
 						  vma_entry_len(vma_entry),
 						  i);
 				if (ret) {
-					pr_err("madvise(%lx, %ld, %ld) "
+					pr_err("madvise(%"PRIx64", %"PRIi64", %lu) "
 					       "failed with %ld\n",
 						vma_entry->start,
 						vma_entry_len(vma_entry),
diff --git a/pipes.c b/pipes.c
index 6542ec6..119520a 100644
--- a/pipes.c
+++ b/pipes.c
@@ -177,7 +177,7 @@ int restore_pipe_data(int img_type, int pfd, u32 id, struct pipe_data_rst **hash
 		}
 
 		if (ret == 0 || ret > iov.iov_len /* sanity */) {
-			pr_err("%#x: Wanted to restore %lu bytes, but got %d\n", id,
+			pr_err("%#x: Wanted to restore %"PRIs" bytes, but got %d\n", id,
 					iov.iov_len, ret);
 			ret = -1;
 			goto err;
diff --git a/proc_parse.c b/proc_parse.c
index c711271..edee8c7 100644
--- a/proc_parse.c
+++ b/proc_parse.c
@@ -129,7 +129,7 @@ static int is_anon_shmem_map(dev_t dev)
 		munmap(map, PAGE_SIZE);
 
 		shmem_dev = buf.st_dev;
-		pr_info("Found anon-shmem piggie at %lx\n", shmem_dev);
+		pr_info("Found anon-shmem piggie at %"PRIx64"\n", (uint64_t)shmem_dev);
 	}
 
 	return shmem_dev == dev;
@@ -164,7 +164,7 @@ int parse_smaps(pid_t pid, struct list_head *vma_area_list, bool use_map_files)
 		if (!is_vma_range_fmt(buf)) {
 			if (!strncmp(buf, "Nonlinear", 9)) {
 				BUG_ON(!vma_area);
-				pr_err("Nonlinear mapping found %016lx-%016lx\n",
+				pr_err("Nonlinear mapping found %016"PRIx64"-%016"PRIx64"\n",
 				       vma_area->vma.start, vma_area->vma.end);
 				/*
 				 * VMA is already on list and will be
@@ -186,7 +186,7 @@ int parse_smaps(pid_t pid, struct list_head *vma_area_list, bool use_map_files)
 			goto err;
 
 		memset(file_path, 0, 6);
-		num = sscanf(buf, "%lx-%lx %c%c%c%c %lx %02x:%02x %lu %5s",
+		num = sscanf(buf, "%"PRIx64"-%"PRIx64" %c%c%c%c %"PRIx64" %02x:%02x %lu %5s",
 			     &start, &end, &r, &w, &x, &s, &pgoff, &dev_maj,
 			     &dev_min, &ino, file_path);
 		if (num < 10) {
@@ -198,7 +198,7 @@ int parse_smaps(pid_t pid, struct list_head *vma_area_list, bool use_map_files)
 			char path[32];
 
 			/* Figure out if it's file mapping */
-			snprintf(path, sizeof(path), "%lx-%lx", start, end);
+			snprintf(path, sizeof(path), "%"PRIx64"-%"PRIx64, start, end);
 
 			/*
 			 * Note that we "open" it in dumper process space
@@ -216,7 +216,7 @@ int parse_smaps(pid_t pid, struct list_head *vma_area_list, bool use_map_files)
 					if (!S_ISSOCK(buf.st_mode))
 						goto err_bogus_mapfile;
 
-					pr_info("Found socket %lu mapping @%lx\n", buf.st_ino, start);
+					pr_info("Found socket %"PRIu64" mapping @%"PRIx64"\n", buf.st_ino, start);
 					vma_area->vma.status |= VMA_AREA_SOCKET | VMA_AREA_REGULAR;
 					vma_area->vm_socket_id = buf.st_ino;
 				} else if (errno != ENOENT)
@@ -265,11 +265,11 @@ int parse_smaps(pid_t pid, struct list_head *vma_area_list, bool use_map_files)
 			struct stat st_buf;
 
 			if (fstat(vma_area->vm_file_fd, &st_buf) < 0) {
-				pr_perror("Failed fstat on %d's map %lu", pid, start);
+				pr_perror("Failed fstat on %d's map %"PRIu64, pid, start);
 				goto err;
 			}
 			if (!S_ISREG(st_buf.st_mode)) {
-				pr_err("Can't handle non-regular mapping on %d's map %lu\n", pid, start);
+				pr_err("Can't handle non-regular mapping on %d's map %"PRIu64"\n", pid, start);
 				goto err;
 			}
 
@@ -325,13 +325,13 @@ err:
 	return ret;
 
 err_bogus_mapping:
-	pr_err("Bogus mapping 0x%lx-0x%lx (flags: %#x vm_file_fd: %d)\n",
+	pr_err("Bogus mapping 0x%"PRIx64"-0x%"PRIx64" (flags: %#x vm_file_fd: %d)\n",
 	       vma_area->vma.start, vma_area->vma.end,
 	       vma_area->vma.flags, vma_area->vm_file_fd);
 	goto err;
 
 err_bogus_mapfile:
-	pr_perror("Can't open %d's mapfile link %lx", pid, start);
+	pr_perror("Can't open %d's mapfile link %"PRIx64, pid, start);
 	goto err;
 }
 
@@ -847,7 +847,7 @@ int parse_fdinfo(int fd, int type,
 
 			if (type != FD_TYPES__EVENTFD)
 				goto parse_err;
-			ret = sscanf(str, "eventfd-count: %lx",
+			ret = sscanf(str, "eventfd-count: %"PRIx64,
 					&entry.efd.counter);
 			if (ret != 1)
 				goto parse_err;
@@ -863,7 +863,7 @@ int parse_fdinfo(int fd, int type,
 
 			if (type != FD_TYPES__EVENTPOLL)
 				goto parse_err;
-			ret = sscanf(str, "tfd: %d events: %x data: %lx",
+			ret = sscanf(str, "tfd: %d events: %x data: %"PRIx64,
 					&entry.epl.tfd, &entry.epl.events, &entry.epl.data);
 			if (ret != 3)
 				goto parse_err;
@@ -900,7 +900,7 @@ int parse_fdinfo(int fd, int type,
 			if (type != FD_TYPES__INOTIFY)
 				goto parse_err;
 			ret = sscanf(str,
-					"inotify wd:%x ino:%lx sdev:%x "
+					"inotify wd:%x ino:%"PRIx64" sdev:%x "
 					"mask:%x ignored_mask:%x "
 					"fhandle-bytes:%x fhandle-type:%x "
 					"f_handle: %n",
diff --git a/pstree.c b/pstree.c
index 3ba645e..ccb80a8 100644
--- a/pstree.c
+++ b/pstree.c
@@ -11,6 +11,10 @@
 
 struct pstree_item *root_item;
 
+#ifdef CONFIG_ARM
+struct task_entries *task_entries;
+#endif
+
 void free_pstree(struct pstree_item *root_item)
 {
 	struct pstree_item *item = root_item, *parent;
diff --git a/shmem.c b/shmem.c
index cb52634..5e2c4a3 100644
--- a/shmem.c
+++ b/shmem.c
@@ -58,7 +58,7 @@ static int collect_shmem(int pid, VmaEntry *vi)
 		return -1;
 	}
 
-	pr_info("Add new shmem 0x%lx (0x0160x%lx-0x0160x%lx)",
+	pr_info("Add new shmem 0x%"PRIx64" (0x0160x%"PRIx64"-0x0160x%"PRIx64")",
 				vi->shmid, vi->start, vi->end);
 
 	si = &rst_shmems->entries[nr_shmems];
@@ -94,7 +94,7 @@ int prepare_shmem_pid(int pid)
 		if (ret <= 0)
 			break;
 
-		pr_info("vma 0x%lx 0x%lx\n", vi->start, vi->end);
+		pr_info("vma 0x%"PRIx64" 0x%"PRIx64"\n", vi->start, vi->end);
 
 		if (!vma_entry_is(vi, VMA_ANON_SHARED) ||
 		    vma_entry_is(vi, VMA_AREA_SYSVIPC)) {
@@ -167,9 +167,9 @@ int get_shmem_fd(int pid, VmaEntry *vi)
 	int f;
 
 	si = find_shmem(rst_shmems, vi->shmid);
-	pr_info("Search for 0x%016lx shmem 0x%lx %p/%d\n", vi->start, vi->shmid, si, si ? si->pid : -1);
+	pr_info("Search for 0x%016"PRIx64" shmem 0x%"PRIx64" %p/%d\n", vi->start, vi->shmid, si, si ? si->pid : -1);
 	if (!si) {
-		pr_err("Can't find my shmem 0x%016lx\n", vi->start);
+		pr_err("Can't find my shmem 0x%016"PRIx64"\n", vi->start);
 		return -1;
 	}
 
@@ -190,7 +190,7 @@ int get_shmem_fd(int pid, VmaEntry *vi)
 			PROT_WRITE | PROT_READ,
 			MAP_SHARED | MAP_ANONYMOUS, -1, 0);
 	if (addr == MAP_FAILED) {
-		pr_err("Can't mmap shmid=0x%lx size=%ld\n",
+		pr_err("Can't mmap shmid=0x%"PRIx64" size=%ld\n",
 				vi->shmid, si->size);
 		return -1;
 	}
diff --git a/sk-inet.c b/sk-inet.c
index 19a413b..80a4330 100644
--- a/sk-inet.c
+++ b/sk-inet.c
@@ -425,7 +425,7 @@ static int inet_validate_address(InetSkEntry *ie)
 			(ie->n_dst_addr == PB_ALEN_INET6))
 		return 0;
 
-	pr_err("Addr len mismatch f %d ss %lu ds %lu\n", ie->family,
+	pr_err("Addr len mismatch f %d ss %"PRIs" ds %"PRIs"\n", ie->family,
 			pb_repeated_size(ie, src_addr),
 			pb_repeated_size(ie, dst_addr));
 
diff --git a/sk-packet.c b/sk-packet.c
index a82825a..cf876ee 100644
--- a/sk-packet.c
+++ b/sk-packet.c
@@ -228,7 +228,7 @@ int dump_socket_map(struct vma_area *vma)
 		return -1;
 	}
 
-	pr_info("Dumping socket map %x -> %lx\n", sd->file_id, vma->vma.start);
+	pr_info("Dumping socket map %x -> %"PRIx64"\n", sd->file_id, vma->vma.start);
 	vma->vma.shmid = sd->file_id;
 	return 0;
 }
@@ -344,7 +344,7 @@ static int restore_mreqs(int sk, PacketSockEntry *pse)
 		pr_info("Restoring mreq type %d\n", ml->type);
 
 		if (ml->addr.len > sizeof(mreq.mr_address)) {
-			pr_err("To big mcaddr %lu\n", ml->addr.len);
+			pr_err("To big mcaddr %"PRIs"\n", ml->addr.len);
 			return -1;
 		}
 
diff --git a/sysctl.c b/sysctl.c
index a7bb6e3..25a2497 100644
--- a/sysctl.c
+++ b/sysctl.c
@@ -134,14 +134,14 @@ GEN_SYSCTL_READ_FUNC(u32, strtoul);
 GEN_SYSCTL_READ_FUNC(u64, strtoull);
 
 GEN_SYSCTL_WRITE_FUNC(u32, "%u ");
-GEN_SYSCTL_WRITE_FUNC(u64, "%lu ");
+GEN_SYSCTL_WRITE_FUNC(u64, "%"PRIu64" ");
 
 GEN_SYSCTL_PRINT_FUNC(u32, "%u ");
-GEN_SYSCTL_PRINT_FUNC(u64, "%lu ");
+GEN_SYSCTL_PRINT_FUNC(u64, "%"PRIu64" ");
 GEN_SYSCTL_PRINT_FUNC(char, "%c");
 
 GEN_SYSCTL_SHOW_FUNC(u32, "%u ");
-GEN_SYSCTL_SHOW_FUNC(u64, "%lu ");
+GEN_SYSCTL_SHOW_FUNC(u64, "%"PRIu64" ");
 GEN_SYSCTL_SHOW_FUNC(char, "%c");
 
 static int
diff --git a/util.c b/util.c
index 59ed831..7d89049 100644
--- a/util.c
+++ b/util.c
@@ -88,12 +88,14 @@ void pr_vma(unsigned int loglevel, const struct vma_area *vma_area)
 {
 	char opt[VMA_OPT_LEN];
 
+	memset(opt, 0, VMA_OPT_LEN);
+
 	if (!vma_area)
 		return;
 
 	vma_opt_str(vma_area, opt);
-	print_on_level(loglevel, "%#lx-%#lx (%liK) prot %#x flags %#x off %#lx "
-			"%s shmid: %#lx\n",
+	print_on_level(loglevel, "%#"PRIx64"-%#"PRIx64" (%"PRIi64"K) prot %#x flags %#x off %#"PRIx64
+			"%s shmid: %#"PRIx64"\n",
 			vma_area->vma.start, vma_area->vma.end,
 			KBYTES(vma_area_len(vma_area)),
 			vma_area->vma.prot,
@@ -339,7 +341,7 @@ int copy_file(int fd_in, int fd_out, size_t bytes)
 
 		if (ret == 0) {
 			if (bytes && (written != bytes)) {
-				pr_err("Ghost file size mismatch %lu/%lu\n",
+				pr_err("Ghost file size mismatch %"PRIs"/%"PRIs"\n",
 						written, bytes);
 				return -1;
 			}
@@ -387,7 +389,7 @@ void *shmalloc(size_t bytes)
 	void *ret;
 
 	if (bytes > SH_BUF_CHUNK) {
-		pr_err("Too big shared buffer requested %lu\n", bytes);
+		pr_err("Too big shared buffer requested %"PRIs"\n", bytes);
 		return NULL;
 	}
 
-- 
1.7.9.5



More information about the CRIU mailing list