svn commit: r253166 - stable/9/lib/libkvm
Mikolaj Golub
trociny at FreeBSD.org
Wed Jul 10 19:42:08 UTC 2013
Author: trociny
Date: Wed Jul 10 19:42:07 2013
New Revision: 253166
URL: http://svnweb.freebsd.org/changeset/base/253166
Log:
Direct commit to stable branch to fix ABI breakage:
In r227839, when removing libkvm dependency on procfs(5),
kvm_uread() function, used for reading from /proc/pid/mem, was
removed too. This change broke ABI.
Bring kvm_uread() back so that the ABI is kept. In head soname is
going to be bumped instead.
Reported by: rmh
Discussed on: arch
Suggested by: jilles
Modified:
stable/9/lib/libkvm/kvm_proc.c
Modified: stable/9/lib/libkvm/kvm_proc.c
==============================================================================
--- stable/9/lib/libkvm/kvm_proc.c Wed Jul 10 19:15:59 2013 (r253165)
+++ stable/9/lib/libkvm/kvm_proc.c Wed Jul 10 19:42:07 2013 (r253166)
@@ -712,3 +712,55 @@ kvm_getenvv(kvm_t *kd, const struct kinf
{
return (kvm_argv(kd, kp, 1, nchr));
}
+
+/*
+ * Read from user space. The user context is given by p.
+ */
+ssize_t
+kvm_uread(kvm_t *kd, const struct kinfo_proc *kp, u_long uva, char *buf,
+ size_t len)
+{
+ char *cp;
+ char procfile[MAXPATHLEN];
+ ssize_t amount;
+ int fd;
+
+ if (!ISALIVE(kd)) {
+ _kvm_err(kd, kd->program,
+ "cannot read user space from dead kernel");
+ return (0);
+ }
+
+ sprintf(procfile, "/proc/%d/mem", kp->ki_pid);
+ fd = open(procfile, O_RDONLY, 0);
+ if (fd < 0) {
+ _kvm_err(kd, kd->program, "cannot open %s", procfile);
+ return (0);
+ }
+
+ cp = buf;
+ while (len > 0) {
+ errno = 0;
+ if (lseek(fd, (off_t)uva, 0) == -1 && errno != 0) {
+ _kvm_err(kd, kd->program, "invalid address (%lx) in %s",
+ uva, procfile);
+ break;
+ }
+ amount = read(fd, cp, len);
+ if (amount < 0) {
+ _kvm_syserr(kd, kd->program, "error reading %s",
+ procfile);
+ break;
+ }
+ if (amount == 0) {
+ _kvm_err(kd, kd->program, "EOF reading %s", procfile);
+ break;
+ }
+ cp += amount;
+ uva += amount;
+ len -= amount;
+ }
+
+ close(fd);
+ return ((ssize_t)(cp - buf));
+}
More information about the svn-src-stable-9
mailing list