Reorganize code in preload library

Reorganize code in preload library

Move the file access wrappers to the bottom, as they need to access the more
specific wrappers such as sockets and ioctls.

--- src/libumockdev-preload.c
+++ src/libumockdev-preload.c
@@ -48,55 +48,17 @@
 int ioctl_capture_fd = -1;
 FILE* ioctl_capture_log;

-static void ioctl_capture_open(int fd);
-

 /********************************
  *
- * Wrappers for accessing /sys
+ * Utility functions
  *
  ********************************/

-static void *nextlib;
-
-static const char *trap_path(const char *path)
-{
-	static char buf[PATH_MAX * 2];
-	const char *prefix;
-	size_t path_len, prefix_len;
-	int check_exist = 0;
-
-	/* do we need to trap this path? */
-	if (path == NULL)
-		return path;
-
-	prefix = getenv("UMOCKDEV_DIR");
-	if (prefix == NULL)
-		return path;
-
-	if (strncmp(path, "/dev/", 5) == 0)
-		check_exist = 1;
-	else if (strncmp(path, "/sys/", 5) != 0)
-		return path;
-
-	path_len = strlen(path);
-	prefix_len = strlen(prefix);
-	if (path_len + prefix_len >= sizeof(buf)) {
-		errno = ENAMETOOLONG;
-		return NULL;
-	}
-	strcpy(buf, prefix);
-	strcpy(buf + prefix_len, path);
-
-	if (check_exist && access(buf, F_OK) < 0)
-		return path;
-
-	return buf;
-}
-
 static void *get_libc_func(const char *f)
 {
 	void *fp;
+	static void *nextlib;

 	if (nextlib == NULL) {
 #ifdef RTLD_NEXT
@@ -110,6 +72,288 @@
 	assert(fp);

 	return fp;
+}
+
+
+/********************************
+ *
+ * Wrappers for accessing netlink socket
+ *
+ ********************************/
+
+/* keep track of the last socket fds wrapped by socket(), so that we can
+ * identify them in the other functions */
+static int wrapped_sockets[] = {-1, -1, -1, -1, -1, -1, -1};
+
+/* mark fd as wrapped */
+static void mark_wrapped_socket (int fd)
+{
+	unsigned i;
+	for (i = 0; i < sizeof(wrapped_sockets); ++i) {
+		if (wrapped_sockets[i] < 0) {
+			wrapped_sockets[i] = fd;
+			return;
+		}
+	}
+
+	printf("testbed mark_wrapped_socket overflow");
+	abort();
+}
+
+static void unmark_wrapped_socket (int fd)
+{
+	unsigned i;
+	for (i = 0; i < sizeof(wrapped_sockets); ++i) {
+		if (wrapped_sockets[i] == fd) {
+			wrapped_sockets[i] = -1;
+			return;
+		}
+	}
+
+	printf("testbed unmark_wrapped_socket %i not found", fd);
+	abort();
+}
+
+static int is_wrapped_socket (int fd)
+{
+	unsigned i;
+	if (fd < 0)
+		return 0;
+
+	for (i = 0; i < sizeof(wrapped_sockets); ++i)
+		if (wrapped_sockets[i] == fd)
+			return 1;
+	return 0;
+}
+
+int socket(int domain, int type, int protocol)
+{
+	static int (*_socket)(int, int, int);
+	int fd;
+	_socket = get_libc_func("socket");
+
+	if (domain == AF_NETLINK && protocol == NETLINK_KOBJECT_UEVENT) {
+		fd = _socket(AF_UNIX, type, 0);
+		mark_wrapped_socket(fd);
+		/* printf("testbed wrapped socket: intercepting netlink, fd %i\n", fd); */
+		return fd;
+	}
+
+	return _socket(domain, type, protocol);
+}
+
+int bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen)
+{
+	static int (*_bind)(int, const struct sockaddr*, socklen_t);
+	struct sockaddr_un sa;
+	const char *path = getenv("UMOCKDEV_DIR");
+	size_t path_len;
+
+	_bind = get_libc_func("bind");
+	if (is_wrapped_socket(sockfd) && path != NULL) {
+		/* printf("testbed wrapped bind: intercepting netlink socket fd %i\n", sockfd); */
+		sa.sun_family = AF_UNIX;
+
+		path_len = strlen(path);
+		assert (path_len < UNIX_PATH_MAX - 7);
+		strcpy(sa.sun_path, path);
+		strcat(sa.sun_path, "/event");
+
+		return _bind(sockfd, (struct sockaddr*) &sa, sizeof(sa));
+	}
+
+	return _bind(sockfd, addr, addrlen);
+}
+
+ssize_t recvmsg(int sockfd, struct msghdr *msg, int flags)
+{
+	static int (*_recvmsg)(int, struct msghdr *, int);
+	ssize_t ret;
+	struct cmsghdr *cmsg;
+        struct sockaddr_nl *sender;
+
+	_recvmsg = get_libc_func("recvmsg");
+	ret = _recvmsg(sockfd, msg, flags);
+
+	if (is_wrapped_socket (sockfd) && ret > 0) {
+		/*printf("testbed wrapped recvmsg: netlink socket fd %i, got %zi bytes\n", sockfd, ret); */
+
+                /* fake sender to be netlink */
+                sender = (struct sockaddr_nl*) msg->msg_name;
+                sender->nl_family = AF_NETLINK;
+                sender->nl_pid = 0;
+                sender->nl_groups = 2; /* UDEV_MONITOR_UDEV */
+                msg->msg_namelen = sizeof(sender);
+
+		/* fake sender credentials to be uid 0 */
+		cmsg = CMSG_FIRSTHDR(msg);
+		if (cmsg != NULL) {
+                        struct ucred *cred = (struct ucred *) CMSG_DATA(cmsg);
+                        cred->uid = 0;
+                }
+	}
+	return ret;
+}
+
+
+/********************************
+ *
+ * Wrappers for USBFS ioctls
+ *
+ ********************************/
+
+
+static void
+ioctl_capture_open(int fd)
+{
+	static dev_t capture_rdev = (dev_t) -1;
+	struct stat st;
+
+	/* lazily initialize capture_rdev */
+	if (capture_rdev == (dev_t) -1) {
+		const char* dev = getenv("UMOCKDEV_IOCTL_CAPTURE_DEV");
+
+		if (dev != NULL) {
+			capture_rdev = (dev_t) atoi(dev);
+		} else {
+			/* not capturing */
+			capture_rdev = 0;
+		}
+	}
+
+	if (capture_rdev == 0)
+		return;
+
+	/* check if the opened device is the one we want to capture */
+	if (fstat (fd, &st) < 0)
+		return;
+	if (!(S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode)) || st.st_rdev != capture_rdev)
+		return;
+	ioctl_capture_fd = fd;
+
+	/* lazily open the capture file */
+	if (ioctl_capture_log == NULL) {
+		const char *path = getenv("UMOCKDEV_IOCTL_CAPTURE_FILE");
+		if (path == NULL) {
+			fprintf(stderr, "umockdev: $UMOCKDEV_IOCTL_CAPTURE_FILE not set\n");
+			exit(1);
+		}
+		if (getenv("UMOCKDEV_DIR") != NULL) {
+			fprintf(stderr, "umockdev: $UMOCKDEV_DIR cannot be used while capturing\n");
+			exit(1);
+		}
+		ioctl_capture_log = fopen(path, "a");
+		if (ioctl_capture_log == NULL) {
+			perror("umockdev: failed to open ioctl capture file");
+			exit (1);
+		}
+	}
+
+	/* mark the opening of device, so that we can keep apart multiple
+	 * sessions/operations in the same dump */
+	fputs("OPEN\n", ioctl_capture_log);
+}
+
+static void
+print_buffer(FILE* file, const char* buf, int len)
+{
+	int i;
+
+	if (len == 0)
+		return;
+
+	for (i = 0; i < len; ++i)
+		fprintf(file, "%02X", buf[i]);
+	fputc('\n', file);
+}
+
+static void
+capture_ioctl (unsigned long request, void *arg)
+{
+	struct usbdevfs_urb *urb;
+
+	assert(ioctl_capture_log != NULL);
+
+	if (request == USBDEVFS_CONNECTINFO) {
+		struct usbdevfs_connectinfo *i = arg;
+		fprintf(ioctl_capture_log, "USBDEVFS_CONNECT_INFO %u %i\n", i->devnum, (int) i->slow);
+	}
+	/* we assume that every SUBMITURB is followed by a REAPURB and that
+	 * ouput EPs don't change the buffer, so we ignore USBDEVFS_SUBMITURB */
+	else if (request == USBDEVFS_REAPURBNDELAY || request == USBDEVFS_REAPURB) {
+		urb = *((struct usbdevfs_urb **) arg);
+		fprintf(ioctl_capture_log, "USBDEVFS_REAPURB %u %u %i %u %i %i %i ",
+				(unsigned) urb->type, (unsigned) urb->endpoint,
+				urb->status, (unsigned) urb->flags,
+				urb->buffer_length, urb->actual_length,
+				urb->error_count);
+		print_buffer(ioctl_capture_log, urb->buffer,
+			urb->endpoint & 0x80 ? urb->actual_length : urb->buffer_length);
+	}
+}
+
+/* note, the actual definition of ioctl is a varargs function; one cannot
+ * reliably forward arbitrary varargs (http://c-faq.com/varargs/handoff.html),
+ * but we know that ioctl gets at most one extra argument, and almost all of
+ * them are pointers or ints, both of which fit into a void*.
+ */
+int ioctl(int d, unsigned long request, void *arg);
+int
+ioctl(int d, unsigned long request, void *arg)
+{
+	static int (*_fn)(int, unsigned long, void*);
+	int result;
+
+	/* call original ioctl */
+	_fn = get_libc_func("ioctl");
+	result = _fn(d, request, arg);
+
+	if (result != -1 && ioctl_capture_fd == d)
+		capture_ioctl (request, arg);
+
+	return result;
+}
+
+
+/********************************
+ *
+ * Wrappers for accessing files
+ *
+ ********************************/
+
+static const char *trap_path(const char *path)
+{
+	static char buf[PATH_MAX * 2];
+	const char *prefix;
+	size_t path_len, prefix_len;
+	int check_exist = 0;
+
+	/* do we need to trap this path? */
+	if (path == NULL)
+		return path;
+
+	prefix = getenv("UMOCKDEV_DIR");
+	if (prefix == NULL)
+		return path;
+
+	if (strncmp(path, "/dev/", 5) == 0)
+		check_exist = 1;
+	else if (strncmp(path, "/sys/", 5) != 0)
+		return path;
+
+	path_len = strlen(path);
+	prefix_len = strlen(prefix);
+	if (path_len + prefix_len >= sizeof(buf)) {
+		errno = ENAMETOOLONG;
+		return NULL;
+	}
+	strcpy(buf, prefix);
+	strcpy(buf + prefix_len, path);
+
+	if (check_exist && access(buf, F_OK) < 0)
+		return path;
+
+	return buf;
 }

 /* wrapper template for a function with one "const char* path" argument */
@@ -209,96 +453,6 @@
 WRAP_OPEN(,);
 WRAP_OPEN(,64);

-/********************************
- *
- * Wrappers for accessing netlink socket
- *
- ********************************/
-
-/* keep track of the last socket fds wrapped by socket(), so that we can
- * identify them in the other functions */
-static int wrapped_sockets[] = {-1, -1, -1, -1, -1, -1, -1};
-
-/* mark fd as wrapped */
-static void mark_wrapped_socket (int fd)
-{
-	unsigned i;
-	for (i = 0; i < sizeof(wrapped_sockets); ++i) {
-		if (wrapped_sockets[i] < 0) {
-			wrapped_sockets[i] = fd;
-			return;
-		}
-	}
-
-	printf("testbed mark_wrapped_socket overflow");
-	abort();
-}
-
-static void unmark_wrapped_socket (int fd)
-{
-	unsigned i;
-	for (i = 0; i < sizeof(wrapped_sockets); ++i) {
-		if (wrapped_sockets[i] == fd) {
-			wrapped_sockets[i] = -1;
-			return;
-		}
-	}
-
-	printf("testbed unmark_wrapped_socket %i not found", fd);
-	abort();
-}
-
-static int is_wrapped_socket (int fd)
-{
-	unsigned i;
-	if (fd < 0)
-		return 0;
-
-	for (i = 0; i < sizeof(wrapped_sockets); ++i)
-		if (wrapped_sockets[i] == fd)
-			return 1;
-	return 0;
-}
-
-int socket(int domain, int type, int protocol)
-{
-	static int (*_socket)(int, int, int);
-	int fd;
-	_socket = get_libc_func("socket");
-
-	if (domain == AF_NETLINK && protocol == NETLINK_KOBJECT_UEVENT) {
-		fd = _socket(AF_UNIX, type, 0);
-		mark_wrapped_socket(fd);
-		/* printf("testbed wrapped socket: intercepting netlink, fd %i\n", fd); */
-		return fd;
-	}
-
-	return _socket(domain, type, protocol);
-}
-
-int bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen)
-{
-	static int (*_bind)(int, const struct sockaddr*, socklen_t);
-	struct sockaddr_un sa;
-	const char *path = getenv("UMOCKDEV_DIR");
-	size_t path_len;
-
-	_bind = get_libc_func("bind");
-	if (is_wrapped_socket(sockfd) && path != NULL) {
-		/* printf("testbed wrapped bind: intercepting netlink socket fd %i\n", sockfd); */
-		sa.sun_family = AF_UNIX;
-
-		path_len = strlen(path);
-		assert (path_len < UNIX_PATH_MAX - 7);
-		strcpy(sa.sun_path, path);
-		strcat(sa.sun_path, "/event");
-
-		return _bind(sockfd, (struct sockaddr*) &sa, sizeof(sa));
-	}
-
-	return _bind(sockfd, addr, addrlen);
-}
-
 int close(int fd)
 {
 	static int (*_close)(int);
@@ -307,159 +461,10 @@
 		/* printf("testbed wrapped close: closing netlink socket fd %i\n", fd); */
 		unmark_wrapped_socket(fd);
 	}
-	if (fd == ioctl_capture_fd)
-		ioctl_capture_fd = -1;
+	if (fd == ioctl_record_fd)
+		ioctl_record_fd = -1;

 	return _close(fd);
 }

-ssize_t recvmsg(int sockfd, struct msghdr *msg, int flags)
-{
-	static int (*_recvmsg)(int, struct msghdr *, int);
-	ssize_t ret;
-	struct cmsghdr *cmsg;
-        struct sockaddr_nl *sender;
-
-	_recvmsg = get_libc_func("recvmsg");
-	ret = _recvmsg(sockfd, msg, flags);
-
-	if (is_wrapped_socket (sockfd) && ret > 0) {
-		/*printf("testbed wrapped recvmsg: netlink socket fd %i, got %zi bytes\n", sockfd, ret); */
-
-                /* fake sender to be netlink */
-                sender = (struct sockaddr_nl*) msg->msg_name;
-                sender->nl_family = AF_NETLINK;
-                sender->nl_pid = 0;
-                sender->nl_groups = 2; /* UDEV_MONITOR_UDEV */
-                msg->msg_namelen = sizeof(sender);
-
-		/* fake sender credentials to be uid 0 */
-		cmsg = CMSG_FIRSTHDR(msg);
-		if (cmsg != NULL) {
-                        struct ucred *cred = (struct ucred *) CMSG_DATA(cmsg);
-                        cred->uid = 0;
-                }
-	}
-	return ret;
-}
-
-
-/********************************
- *
- * Wrappers for USBFS ioctls
- *
- ********************************/
-
-
-static void
-ioctl_capture_open(int fd)
-{
-	static dev_t capture_rdev = (dev_t) -1;
-	struct stat st;
-
-	/* lazily initialize capture_rdev */
-	if (capture_rdev == (dev_t) -1) {
-		const char* dev = getenv("UMOCKDEV_IOCTL_CAPTURE_DEV");
-
-		if (dev != NULL) {
-			capture_rdev = (dev_t) atoi(dev);
-		} else {
-			/* not capturing */
-			capture_rdev = 0;
-		}
-	}
-
-	if (capture_rdev == 0)
-		return;
-
-	/* check if the opened device is the one we want to capture */
-	if (fstat (fd, &st) < 0)
-		return;
-	if (!(S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode)) || st.st_rdev != capture_rdev)
-		return;
-	ioctl_capture_fd = fd;
-
-	/* lazily open the capture file */
-	if (ioctl_capture_log == NULL) {
-		const char *path = getenv("UMOCKDEV_IOCTL_CAPTURE_FILE");
-		if (path == NULL) {
-			fprintf(stderr, "umockdev: $UMOCKDEV_IOCTL_CAPTURE_FILE not set\n");
-			exit(1);
-		}
-		if (getenv("UMOCKDEV_DIR") != NULL) {
-			fprintf(stderr, "umockdev: $UMOCKDEV_DIR cannot be used while capturing\n");
-			exit(1);
-		}
-		ioctl_capture_log = fopen(path, "a");
-		if (ioctl_capture_log == NULL) {
-			perror("umockdev: failed to open ioctl capture file");
-			exit (1);
-		}
-	}
-
-	/* mark the opening of device, so that we can keep apart multiple
-	 * sessions/operations in the same dump */
-	fputs("OPEN\n", ioctl_capture_log);
-}
-
-static void
-print_buffer(FILE* file, const char* buf, int len)
-{
-	int i;
-
-	if (len == 0)
-		return;
-
-	for (i = 0; i < len; ++i)
-		fprintf(file, "%02X", buf[i]);
-	fputc('\n', file);
-}
-
-static void
-capture_ioctl (unsigned long request, void *arg)
-{
-	struct usbdevfs_urb *urb;
-
-	assert(ioctl_capture_log != NULL);
-
-	if (request == USBDEVFS_CONNECTINFO) {
-		struct usbdevfs_connectinfo *i = arg;
-		fprintf(ioctl_capture_log, "USBDEVFS_CONNECT_INFO %u %i\n", i->devnum, (int) i->slow);
-	}
-	/* we assume that every SUBMITURB is followed by a REAPURB and that
-	 * ouput EPs don't change the buffer, so we ignore USBDEVFS_SUBMITURB */
-	else if (request == USBDEVFS_REAPURBNDELAY || request == USBDEVFS_REAPURB) {
-		urb = *((struct usbdevfs_urb **) arg);
-		fprintf(ioctl_capture_log, "USBDEVFS_REAPURB %u %u %i %u %i %i %i ",
-				(unsigned) urb->type, (unsigned) urb->endpoint,
-				urb->status, (unsigned) urb->flags,
-				urb->buffer_length, urb->actual_length,
-				urb->error_count);
-		print_buffer(ioctl_capture_log, urb->buffer,
-			urb->endpoint & 0x80 ? urb->actual_length : urb->buffer_length);
-	}
-}
-
-/* note, the actual definition of ioctl is a varargs function; one cannot
- * reliably forward arbitrary varargs (http://c-faq.com/varargs/handoff.html),
- * but we know that ioctl gets at most one extra argument, and almost all of
- * them are pointers or ints, both of which fit into a void*.
- */
-int ioctl(int d, unsigned long request, void *arg);
-int
-ioctl(int d, unsigned long request, void *arg)
-{
-	static int (*_fn)(int, unsigned long, void*);
-	int result;
-
-	/* call original ioctl */
-	_fn = get_libc_func("ioctl");
-	result = _fn(d, request, arg);
-
-	if (result != -1 && ioctl_capture_fd == d)
-		capture_ioctl (request, arg);
-
-	return result;
-}
-
 /* vim: set sw=8 noet: */


Do block/sector handling like the other ports

--- arch/amiga/amiga/disksubr.c
+++ arch/amiga/amiga/disksubr.c
@@ -1,4 +1,4 @@
-/*	$OpenBSD: disksubr.c,v 1.11 1997/02/23 02:33:05 niklas Exp $	*/
+/*	$OpenBSD: disksubr.c,v 1.12 1997/04/10 08:52:52 niklas Exp $	*/
 /*	$NetBSD: disksubr.c,v 1.27 1996/10/13 03:06:34 christos Exp $	*/

 /*
@@ -506,46 +506,35 @@
 	struct disklabel *lp;
 	int wlabel;
 {
-	struct partition *pp;
-	long maxsz, sz;
-
-	pp = &lp->d_partitions[DISKPART(bp->b_dev)];
-	if (bp->b_flags & B_RAW) {
-		maxsz = pp->p_size * (lp->d_secsize / DEV_BSIZE);
-		sz = (bp->b_bcount + DEV_BSIZE - 1) >> DEV_BSHIFT;
-	} else {
-		maxsz = pp->p_size;
-		sz = (bp->b_bcount + lp->d_secsize - 1) / lp->d_secsize;
+#define blockpersec(count, lp) ((count) * (((lp)->d_secsize) / DEV_BSIZE))
+	struct partition *p = lp->d_partitions + DISKPART(bp->b_dev);
+	int sz = howmany(bp->b_bcount, DEV_BSIZE);
+
+	if (bp->b_blkno + sz > blockpersec(p->p_size, lp)) {
+		sz = blockpersec(p->p_size, lp) - bp->b_blkno;
+		if (sz == 0) {
+			/* If exactly at end of disk, return EOF. */
+			bp->b_resid = bp->b_bcount;
+			goto done;
+		}
+		if (sz < 0) {
+			/* If past end of disk, return EINVAL. */
+			bp->b_error = EINVAL;
+			goto bad;
+		}
+		/* Otherwise, truncate request. */
+		bp->b_bcount = sz << DEV_BSHIFT;
 	}

-	if (bp->b_blkno < 0 || bp->b_blkno + sz > maxsz) {
-		if (bp->b_blkno == maxsz) {
-			/*
-			 * trying to get one block beyond return EOF.
-			 */
-			bp->b_resid = bp->b_bcount;
-			return(0);
-		}
-		sz = maxsz - bp->b_blkno;
-		if (sz <= 0 || bp->b_blkno < 0) {
-			bp->b_error = EINVAL;
-			bp->b_flags |= B_ERROR;
-			return(-1);
-		}
-		/*
-		 * adjust count down
-		 */
-		if (bp->b_flags & B_RAW)
-			bp->b_bcount = sz << DEV_BSHIFT;
-		else
-			bp->b_bcount = sz * lp->d_secsize;
-	}
-
-	/*
-	 * calc cylinder for disksort to order transfers with
-	 */
-	bp->b_cylin = (bp->b_blkno + pp->p_offset) / lp->d_secpercyl;
-	return(1);
+	/* Calculate cylinder for disksort to order transfers with.  */
+	bp->b_cylin = (bp->b_blkno + blockpersec(p->p_offset, lp)) /
+	    lp->d_secpercyl;
+	return (1);
+
+bad:
+	bp->b_flags |= B_ERROR;
+done:
+	return (0);
 }

 u_long


MsgPack: Fix select() (was saving the names)

--- src/msgpack.h
+++ src/msgpack.h
@@ -1947,7 +1947,7 @@
 					if (input) {
 						auto it = input->find(name);
 						if (it != input->end()) {
-							input = &*it;
+							input = &it.value();
 						} else {
 							input = nullptr;
 						}
@@ -1967,7 +1967,7 @@
 					if (input && output) {
 						auto it = input->find(name);
 						if (it != input->end()) {
-							input = &*it;
+							input = &it.value();
 							base = input;
 							output = &(*output)[name];
 						} else {
@@ -1987,7 +1987,7 @@
 					if (input && output) {
 						auto it = input->find(name);
 						if (it != input->end()) {
-							(*output)[name] = *it;
+							(*output)[name] = it.value();
 						}
 					}
 					name = "";
@@ -2019,7 +2019,7 @@
 					if (input && output) {
 						auto it = input->find(name);
 						if (it != input->end()) {
-							(*output)[name] = *it;
+							(*output)[name] = it.value();
 						}
 					}
 					name = "";
@@ -2043,7 +2043,7 @@
 		if (input && output) {
 			auto it = input->find(name);
 			if (it != input->end()) {
-				*output = *it;
+				*output = it.value();
 			}
 		}
 		name = "";


msm: scm-pas: Flush the metadata buffer

msm: scm-pas: Flush the metadata buffer

In the near future, scm_call will no longer flush
the entire cache in order to ensure that the secure
world doesn't see stale data. Therefore, flush the
metadata buffer from the cache before invoking
scm_call.

Change-Id: I0896d1bac074b6a4b004edfc1cb0a9a8de57999b
Signed-off-by: Vikram Mulukutla <577f74ec3f2c8a155237d5ad42a70103d17f8313@codeaurora.org>

--- arch/arm/mach-msm/scm-pas.c
+++ arch/arm/mach-msm/scm-pas.c
@@ -16,6 +16,8 @@
 #include <linux/slab.h>
 #include <linux/string.h>
 #include <linux/clk.h>
+
+#include <asm/cacheflush.h>

 #include <mach/scm.h>
 #include <mach/socinfo.h>
@@ -150,6 +152,10 @@
 	request.proc = id;
 	request.image_addr = virt_to_phys(mdata_buf);

+	/* Flush metadata to ensure secure world doesn't read stale data */
+	__cpuc_flush_dcache_area(mdata_buf, size);
+	outer_flush_range(request.image_addr, request.image_addr + size);
+
 	ret = scm_call(SCM_SVC_PIL, PAS_INIT_IMAGE_CMD, &request,
 			sizeof(request), &scm_ret, sizeof(scm_ret));


Fix fail long FQDN name resolve

Fix fail long FQDN name resolve

--- src/nc_util.c
+++ src/nc_util.c
@@ -443,7 +443,7 @@
     int status;
     struct addrinfo *ai, *cai; /* head and current addrinfo */
     struct addrinfo hints;
-    char *node, nodestr[NC_INET_ADDRSTRLEN], service[NC_UINTMAX_MAXLEN];
+    char *node, service[NC_UINTMAX_MAXLEN];
     bool found;

     ASSERT(nc_valid_port(port));
@@ -458,10 +458,7 @@
     hints.ai_canonname = NULL;

     if (name != NULL) {
-        size_t nodelen = MIN(NC_INET_ADDRSTRLEN - 1, name->len);
-        nc_memcpy(nodestr, name->data, nodelen);
-        nodestr[nodelen] = '\0';
-        node = nodestr;
+    	node = strdup(name->data);
     } else {
         /*
          * If AI_PASSIVE flag is specified in hints.ai_flags, and node is
@@ -502,6 +499,7 @@
     }

     freeaddrinfo(ai);
+    free(node);

     return !found ? -1 : 0;
 }


ARM: SAMSUNG: Add clk enable/disable of pwm

PWM timers use pclk("timers" clk) as parent clk. If this pclk is the
disabled state when PWM driver is probed, then it causes wrong read and
write operation about registers of PWM.

Signed-off-by: Joonyoung Shim <b2207686f8c5343cf0f505ae1d5720ecb0c3202a@samsung.com>
Signed-off-by: Kyungmin Park <504c23c4986a3760712724894be3105092c27331@samsung.com>
Signed-off-by: Kukjin Kim <3fc711f4e08bc570a586748633ff7c76d0e1e253@samsung.com>

--- arch/arm/plat-samsung/pwm.c
+++ arch/arm/plat-samsung/pwm.c
@@ -299,6 +299,9 @@
 		goto err_clk_tin;
 	}

+	clk_enable(pwm->clk);
+	clk_enable(pwm->clk_div);
+
 	local_irq_save(flags);

 	tcon = __raw_readl(S3C2410_TCON);
@@ -326,6 +329,8 @@
 	return 0;

  err_clk_tdiv:
+	clk_disable(pwm->clk_div);
+	clk_disable(pwm->clk);
 	clk_put(pwm->clk_div);

  err_clk_tin:
@@ -340,6 +345,8 @@
 {
 	struct pwm_device *pwm = platform_get_drvdata(pdev);

+	clk_disable(pwm->clk_div);
+	clk_disable(pwm->clk);
 	clk_put(pwm->clk_div);
 	clk_put(pwm->clk);
 	kfree(pwm);


Implement tcp_prepare with fixed options

--- src/net/tcp.c
+++ src/net/tcp.c
@@ -19,6 +19,66 @@
 #error TCP cannot work without NET_NETWORK
 #endif // NET_NETWORK

+uint8_t sequence_nr = 1;
+
+uint8_t *tcp_prepare(uint16_t src_port, uint8_t *dst_ip, uint16_t dst_port, uint8_t *dst_mac) {
+    // Create IP protocol header
+    ip_prepare(IP_VAL_PROTO_TCP, dst_ip, dst_mac);
+
+    // Construct UDP protocol header
+    // -----------------------------
+    // See RFC 793, p. 15
+    // Source port
+    buffer_out[TCP_PTR_PORT_SRC_H] = src_port >> 8;
+    buffer_out[TCP_PTR_PORT_SRC_L] = src_port & 0xFF;
+    // Destination port
+    buffer_out[TCP_PTR_PORT_DST_H] = dst_port >> 8;
+    buffer_out[TCP_PTR_PORT_DST_L] = dst_port & 0xFF;
+    // Sequence number
+    buffer_out[TCP_PTR_SEQ_NR+0] = 1;
+    buffer_out[TCP_PTR_SEQ_NR+1] = 0;
+    buffer_out[TCP_PTR_SEQ_NR+2] = 0;
+    buffer_out[TCP_PTR_SEQ_NR+3] = sequence_nr++;
+    // Acknowledgement number
+    buffer_out[TCP_PTR_ACK_NR+0] = 0;
+    buffer_out[TCP_PTR_ACK_NR+1] = 0;
+    buffer_out[TCP_PTR_ACK_NR+2] = 0;
+    buffer_out[TCP_PTR_ACK_NR+3] = 0;
+    // Header length (includes options)
+    // Pre options: 5 x 32 bits
+    // Options:     2 x 32 bits
+    buffer_out[TCP_PTR_DATA_OFFSET] = 0x07 << 4;
+    // Flags: Only set SYN
+    buffer_out[TCP_PTR_FLAGS] = TCP_FLAG_SYN;
+    // Window: 1024 bytes max (0x400)
+    buffer_out[TCP_PTR_WINDOW+0] = 0;
+    buffer_out[TCP_PTR_WINDOW+1] = 0;
+    buffer_out[TCP_PTR_WINDOW+2] = 0x04;
+    buffer_out[TCP_PTR_WINDOW+3] = 0;
+    // Checksum: set to 0
+    buffer_out[TCP_PTR_CHECKSUM+0] = 0;
+    buffer_out[TCP_PTR_CHECKSUM+1] = 0;
+    // Urgent pointer: set to 0
+    buffer_out[TCP_PTR_URGENT_PTR+0] = 0;
+    buffer_out[TCP_PTR_URGENT_PTR+1] = 0;
+    // Options:
+    // Maximum segment size: 1024 (0x400)
+    buffer_out[TCP_PTR_OPTIONS+0] = 0x02;
+    buffer_out[TCP_PTR_OPTIONS+1] = 0x04;
+    buffer_out[TCP_PTR_OPTIONS+2] = 0x04;
+    buffer_out[TCP_PTR_OPTIONS+3] = 0x00;
+    // Nop to fill for next option
+    //buffer_out[TCP_PTR_OPTIONS+4] = 0x01;
+    // Window scale: 0 (no multiplication)
+    buffer_out[TCP_PTR_OPTIONS+4] = 0x03;
+    buffer_out[TCP_PTR_OPTIONS+5] = 0x03;
+    buffer_out[TCP_PTR_OPTIONS+6] = 0x00;
+    // End of option list
+    buffer_out[TCP_PTR_OPTIONS+7] = 0x00;
+
+    return &buffer_out[TCP_PTR_DATA];
+}
+
 // Port services list
 #ifdef NET_TCP_SERVER
 // Check if port list size is defined


arm64: consolidate __swiotlb_mmap

arm64: consolidate __swiotlb_mmap

Since commit 9d3bfbb4df58 ("arm64: Combine coherent and non-coherent
swiotlb dma_ops"), __dma_common_mmap is no longer shared between two
callers, so roll it into the remaining one.

Signed-off-by: Robin Murphy <4f9c5a5cfa819e47d69719a414c02aa6016a9f54@arm.com>
Signed-off-by: Will Deacon <b913f13ef92ac157955c954ccaaff7be065faba4@arm.com>

--- arch/arm64/mm/dma-mapping.c
+++ arch/arm64/mm/dma-mapping.c
@@ -303,9 +303,10 @@
 				       sg->length, dir);
 }

-/* vma->vm_page_prot must be set appropriately before calling this function */
-static int __dma_common_mmap(struct device *dev, struct vm_area_struct *vma,
-			     void *cpu_addr, dma_addr_t dma_addr, size_t size)
+static int __swiotlb_mmap(struct device *dev,
+			  struct vm_area_struct *vma,
+			  void *cpu_addr, dma_addr_t dma_addr, size_t size,
+			  struct dma_attrs *attrs)
 {
 	int ret = -ENXIO;
 	unsigned long nr_vma_pages = (vma->vm_end - vma->vm_start) >>
@@ -314,6 +315,9 @@
 	unsigned long pfn = dma_to_phys(dev, dma_addr) >> PAGE_SHIFT;
 	unsigned long off = vma->vm_pgoff;

+	vma->vm_page_prot = __get_dma_pgprot(attrs, vma->vm_page_prot,
+					     is_device_dma_coherent(dev));
+
 	if (dma_mmap_from_coherent(dev, vma, cpu_addr, size, &ret))
 		return ret;

@@ -325,16 +329,6 @@
 	}

 	return ret;
-}
-
-static int __swiotlb_mmap(struct device *dev,
-			  struct vm_area_struct *vma,
-			  void *cpu_addr, dma_addr_t dma_addr, size_t size,
-			  struct dma_attrs *attrs)
-{
-	vma->vm_page_prot = __get_dma_pgprot(attrs, vma->vm_page_prot,
-					     is_device_dma_coherent(dev));
-	return __dma_common_mmap(dev, vma, cpu_addr, dma_addr, size);
 }

 static struct dma_map_ops swiotlb_dma_ops = {


Support for bios memory maps.

Support for bios memory maps.

--- arch/i386/include/biosvar.h
+++ arch/i386/include/biosvar.h
@@ -1,4 +1,4 @@
-/*	$OpenBSD: biosvar.h,v 1.15 1997/10/12 23:55:12 mickey Exp $	*/
+/*	$OpenBSD: biosvar.h,v 1.16 1997/10/14 01:04:25 weingart Exp $	*/

 /*
  * Copyright (c) 1997 Michael Shalayeff
@@ -53,6 +53,15 @@
 #define	BIOSM_HD	0xf8	/* hard drive */
 #define	BIOSM_F144K	0xf0	/* floppy ds/hd 18 spt 3.50" */
 #define	BIOSM_OTHER	0xf0	/* any other */
+
+/*
+ * BIOS memory maps
+ */
+#define	BIOS_MAP_END	0x00	/* End of array XXX - special */
+#define	BIOS_MAP_FREE	0x01	/* Usable memory */
+#define	BIOS_MAP_RES	0x02	/* Reseved memory */
+#define	BIOS_MAP_ACPI	0x03	/* ACPI Reclaim memory */
+#define	BIOS_MAP_NVS	0x04	/* ACPI NVS memory */

 /*
  * CTL_BIOS definitions.
@@ -115,6 +124,12 @@
 	u_int64_t edd_daddr; /* starting block */
 };

+struct BIOS_MAP {
+	u_int32_t addr;		/* Beginning of block */
+	u_int32_t size;		/* Size of block */
+	int type;		/* Type of block */
+};
+
 #ifdef _KERNEL
 #include <machine/bus.h>


exit with status 2 in case of DNS failure, like ping and fping

--- src/nfsping.c
+++ src/nfsping.c
@@ -321,7 +321,7 @@
                 getaddr = getnameinfo((struct sockaddr *)target->client_sock, sizeof(struct sockaddr_in), target->name, NI_MAXHOST, NULL, 0, 0);
                 if (getaddr > 0) { /* failure! */
                     fprintf(stderr, "%s: %s\n", target->name, gai_strerror(getaddr));
-                    exit(EXIT_FAILURE);
+                    exit(2); /* ping and fping return 2 for name resolution failures */
                 }
                 target->ndqf = reverse_fqdn(target->name);
             } else {
@@ -381,7 +381,7 @@
                 }
             } else {
                 fprintf(stderr, "getaddrinfo error (%s): %s\n", target->name, gai_strerror(getaddr));
-                exit(EXIT_FAILURE);
+                exit(2); /* ping and fping return 2 for name resolution failures */
             }
         }
     }


[IA64] use bcd2bin/bin2bcd

[IA64] use bcd2bin/bin2bcd

This patch changes ia64 to use the new bcd2bin/bin2bcd functions instead
of the obsolete BCD2BIN/BIN2BCD macros.

Signed-off-by: Adrian Bunk <0b86548ef377da0031a3ff3f0c4e06f016e20105@kernel.org>
Signed-off-by: Tony Luck <e7984595ec0368ff920a7b3521dc7093683f6f26@intel.com>

--- arch/ia64/include/asm/sal.h
+++ arch/ia64/include/asm/sal.h
@@ -236,7 +236,7 @@

 extern unsigned short sal_revision;	/* supported SAL spec revision */
 extern unsigned short sal_version;	/* SAL version; OEM dependent */
-#define SAL_VERSION_CODE(major, minor) ((BIN2BCD(major) << 8) | BIN2BCD(minor))
+#define SAL_VERSION_CODE(major, minor) ((bin2bcd(major) << 8) | bin2bcd(minor))

 extern const char *ia64_sal_strerror (long status);
 extern void ia64_sal_init (struct ia64_sal_systab *sal_systab);


pteid: do not call the iso7816 driver get_response operation

--- src/libopensc/card-ias.c
+++ src/libopensc/card-ias.c
@@ -31,9 +31,6 @@
 #include "asn1.h"
 #include "cardctl.h"

-/* Portugal eID uses 1024 bit keys */
-#define PTEID_RSA_KEYSIZE 128
-
 #define DRVDATA(card)	((struct ias_priv_data *) ((card)->drv_data))

 static struct sc_card_operations ias_ops;
@@ -315,8 +312,9 @@
 	int 			r;
 	size_t 			len = 0;
 	sc_apdu_t 		apdu;
-	u8 				sbuf[SC_MAX_APDU_BUFFER_SIZE];
-	sc_context_t 	*ctx = card->ctx;
+	u8			sbuf[SC_MAX_APDU_BUFFER_SIZE];
+	u8			rbuf[SC_MAX_APDU_BUFFER_SIZE];
+	sc_context_t		*ctx = card->ctx;

 	SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_VERBOSE);

@@ -325,24 +323,22 @@
 		return SC_ERROR_INVALID_ARGUMENTS;
 	}

-	/* Send the data */
-	sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x88, 0x02, 0x00);
+	sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0x88, 0x02, 0x00);
 	memcpy(sbuf, data, data_len);
 	apdu.data = sbuf;
 	apdu.lc = data_len;
 	apdu.datalen = data_len;
+	apdu.resp = rbuf;
+	apdu.resplen = sizeof(rbuf);
+	apdu.le = 0x100;

 	r = sc_transmit_apdu(card, &apdu);
 	SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");

-	/* Get the result */
 	if (apdu.sw1 == 0x90 && apdu.sw2 == 0x00) {
-		len = card->type == SC_CARD_TYPE_IAS_PTEID ? PTEID_RSA_KEYSIZE : outlen;
-		r = iso_ops->get_response(card, &len, out);
-		if (r == 0)
-			SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, len);
-		else
-			SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
+		size_t len = apdu.resplen > outlen ? outlen : apdu.resplen;
+		memcpy(out, apdu.resp, len);
+		SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, apdu.resplen);
 	}

 	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, sc_check_sw(card, apdu.sw1, apdu.sw2));


MIPS: Add processor identifiers for the interAptiv processors

Add processor identifiers for UP and MT interAptiv processors.

Signed-off-by: Leonid Yegoshin <d6aca6b5694d055adc6cbbaf8ff810fc31ed7c5d@imgtec.com>
Signed-off-by: Markos Chandras <5cdbcb0e11d2b5ebc39222958c54a1c6329d0c9d@imgtec.com>
Signed-off-by: John Crispin <be6487f9df4dce44a640672d6c07330104d43593@openwrt.org>
Patchwork: http://patchwork.linux-mips.org/patch/6151/


card-piv: invalid arguments for SC_TEST_RET macro

git-svn-id: 444ed946b9c2220da791e84c3dd156a05f92db99@5314 c6295689-39f2-0310-b995-f0e70906c6a9

--- src/libopensc/card-piv.c
+++ src/libopensc/card-piv.c
@@ -689,7 +689,7 @@

 	r = sc_transmit_apdu(card, &apdu);
 	*responselen = apdu.resplen;
-	SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, 4,  r);
+	SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "PIV select failed");
 	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE,  sc_check_sw(card, apdu.sw1, apdu.sw2));
 }


chart: fixes for faded ara under lines

chart: fixes for faded ara under lines

--- src/lv_widgets/lv_chart.c
+++ src/lv_widgets/lv_chart.c
@@ -803,8 +803,8 @@

         has_fade = area_dsc.bg_grad_dir == LV_GRAD_DIR_VER ? true : false;
         if(has_fade) {
-            lv_draw_mask_fade_init(&mask_fade_p, &chart->coords, area_dsc.bg_main_color_stop, chart->coords.y1,
-                                   area_dsc.bg_grad_color_stop, chart->coords.y2);
+            lv_draw_mask_fade_init(&mask_fade_p, series_area, area_dsc.bg_main_color_stop, series_area->y1,
+                                   area_dsc.bg_grad_color_stop, series_area->y2);
         }
     }


[POWERPC] Xilinx: boot support for Xilinx uart 16550.

The Xilinx 16550 uart core is not a standard 16550 because it uses
word-based addressing rather than byte-based adressing. With
additional properties it is compatible with the open firmware
'ns16550' compatible binding.

This code updates the ns16550 driver to use the reg-offset property
so that the Xilinx UART 16550 can be used with it. The reg-shift
was already being handled.

Signed-off-by: John Linn <dbd415a4cc0aefa8fab2e01649bb25d314d78192@xilinx.com>
Acked-by: Grant Likely <9069e6f5a2b566e2674a0ba1e2bf39c12c195fad@secretlab.ca>
Signed-off-by: Josh Boyer <94755a79aca753e683bb6d0e796d473b797056eb@linux.vnet.ibm.com>

--- arch/powerpc/boot/ns16550.c
+++ arch/powerpc/boot/ns16550.c
@@ -55,9 +55,14 @@
 int ns16550_console_init(void *devp, struct serial_console_data *scdp)
 {
 	int n;
+	u32 reg_offset;

 	if (dt_get_virtual_reg(devp, (void **)&reg_base, 1) < 1)
 		return -1;
+
+	n = getprop(devp, "reg-offset", &reg_offset, sizeof(reg_offset));
+	if (n == sizeof(reg_offset))
+		reg_base += reg_offset;

 	n = getprop(devp, "reg-shift", &reg_shift, sizeof(reg_shift));
 	if (n != sizeof(reg_shift))


Update program_11_01.c

Update program_11_01.c

--- Exercises/Chapter_11/Exercise_01/Program_11_01/program_11_01.c
+++ Exercises/Chapter_11/Exercise_01/Program_11_01/program_11_01.c
@@ -1,5 +1,5 @@
 /*
- * program_11_01.c
+ * program_11_01.c - The Bitwise AND Operator
  *
  * Program to demonstrate the bitwise AND operator.
  */


remove typos

remove typos

--- hermit/kernel/tasks.c
+++ hermit/kernel/tasks.c
@@ -315,7 +315,7 @@
 	if ((core_id >= MAX_CORES) || !readyqueues[core_id].idle)
 		core_id = CORE_ID;

-	kprintf("start new thread on core %d with base stack address %p\n", core_id, stack);
+	kprintf("start new thread on core %d with stack address %p\n", core_id, stack);

 	for(i=0; i<MAX_TASKS; i++) {
 		if (task_table[i].status == TASK_INVALID) {
@@ -401,7 +401,7 @@
 	}
 	atomic_int64_set((atomic_int64_t*) counter, 0);

-	kprintf("start new thread on core %d with base stack address %p\n", core_id, stack);
+	kprintf("start new thread on core %d with stack address %p\n", core_id, stack);

 	spinlock_irqsave_lock(&table_lock);


fixed use after free

fixed use after free

--- src/libopensc/cwa-dnie.c
+++ src/libopensc/cwa-dnie.c
@@ -265,8 +265,10 @@
 	res = SC_SUCCESS;
 	goto dnie_read_file_end;
  dnie_read_file_err:
-	if (*file)
+	if (*file) {
 		sc_file_free(*file);
+		*file = NULL;
+	}
  dnie_read_file_end:
 	if (msg)
 		sc_log(ctx, msg);


[POWERPC] DMA 4GB boundary protection

[POWERPC] DMA 4GB boundary protection

There are many adapters which can not handle DMAing acrosss any 4 GB
boundary.  For instance the latest Emulex adapters.

This normally is not an issue as firmware gives us dma-windows under
4gigs.  However, some of the new System-P boxes have dma-windows above
4gigs, and this present a problem.

I propose fixing it in the IOMMU allocation instead of making each
driver protect against it as it is more efficient, and won't require
changing every driver which has not considered this issue.

This patch checks to see if the mapping spans a 4 gig boundary, and if
it does, retries the allocation.  It tries the next allocation at the
start of the crossed 4 gig boundary.

Signed-off-by: Jake Moilanen <a7d4cd0b61da6bae680b96a0a7c51a5e20bbdb21@austin.ibm.com>
Signed-off-by: Paul Mackerras <19a0ba370c443ba08d20b5061586430ab449ee8c@samba.org>

--- arch/powerpc/kernel/iommu.c
+++ arch/powerpc/kernel/iommu.c
@@ -76,6 +76,7 @@
                                        unsigned int align_order)
 {
 	unsigned long n, end, i, start;
+	unsigned long start_addr, end_addr;
 	unsigned long limit;
 	int largealloc = npages > 15;
 	int pass = 0;
@@ -144,6 +145,15 @@
 			/* Third failure, give up */
 			return DMA_ERROR_CODE;
 		}
+	}
+
+	/* DMA cannot cross 4 GB boundary */
+	start_addr = (n + tbl->it_offset) << PAGE_SHIFT;
+	end_addr = (end + tbl->it_offset) << PAGE_SHIFT;
+	if ((start_addr >> 32) != (end_addr >> 32)) {
+		end_addr &= 0xffffffff00000000l;
+		start = (end_addr >> PAGE_SHIFT) - tbl->it_offset;
+		goto again;
 	}

 	for (i = n; i < end; i++)


Fix pmDupContext handling of context flags.  Brain failure.

--- src/libpcp/src/context.c
+++ src/libpcp/src/context.c
@@ -583,7 +583,7 @@
 	goto done;
     }
     oldcon = contexts[old];
-    oldtype = oldcon->c_type & oldcon->c_flags;
+    oldtype = oldcon->c_type | oldcon->c_flags;
     if (oldcon->c_type == PM_CONTEXT_HOST) {
 	h = &hostspec[0];
 	__pmUnparseHostSpec(oldcon->c_pmcd->pc_hosts,


corresponding optimizations to VMUDL (same multiply, diff. clamp)

--- vu/multiply.c
+++ vu/multiply.c
@@ -1,7 +1,7 @@
 /******************************************************************************\
 * Project:  MSP Simulation Layer for Vector Unit Computational Multiplies      *
 * Authors:  Iconoclast                                                         *
-* Release:  2014.10.19                                                         *
+* Release:  2014.10.20                                                         *
 * License:  CC0 Public Domain Dedication                                       *
 *                                                                              *
 * To the extent possible under law, the author(s) have dedicated all copyright *
@@ -94,28 +94,6 @@
     return;
 }

-INLINE static void do_mulu(short* VD, short* VS, short* VT)
-{
-    register int i;
-
-    for (i = 0; i < N; i++)
-        VACC_L[i] = (SEMIFRAC << 1) >>  0;
-    for (i = 0; i < N; i++)
-        VACC_M[i] = (SEMIFRAC << 1) >> 16;
-    for (i = 0; i < N; i++)
-        VACC_H[i] = -((VACC_M[i] < 0) & (VS[i] != VT[i])); /* -32768 * -32768 */
-#if (0)
-    UNSIGNED_CLAMP(VD);
-#else
-    vector_copy(VD, VACC_M);
-    for (i = 0; i < N; i++)
-        VD[i] |=  (VACC_M[i] >> 15); /* VD |= -(result == 0x000080008000) */
-    for (i = 0; i < N; i++)
-        VD[i] &= ~(VACC_H[i] >>  0); /* VD &= -(result >= 0x000000000000) */
-#endif
-    return;
-}
-
 INLINE static void do_mudm(short* VD, short* VS, short* VT)
 {
     register int i;
@@ -342,24 +320,65 @@

 VECTOR_OPERATION VMULU(v16 vs, v16 vt)
 {
-    ALIGNED i16 VD[N];
-#ifdef ARCH_MIN_SSE2
-    ALIGNED i16 VS[N], VT[N];
-
-    *(v16 *)VS = vs;
-    *(v16 *)VT = vt;
-#else
-    v16 VS, VT;
-
-    VS = vs;
-    VT = vt;
-#endif
-    do_mulu(VD, VS, VT);
-#ifdef ARCH_MIN_SSE2
-    vs = *(v16 *)VD;
-    return (vs);
-#else
-    vector_copy(V_result, VD);
+#ifdef ARCH_MIN_SSE2
+    v16 negative;
+    v16 round;
+    v16 prod_hi, prod_lo;
+
+/*
+ * Besides the unsigned clamping method (as opposed to VMULF's signed clamp),
+ * this operation's multiplication matches VMULF.  See VMULF for annotations.
+ */
+    prod_lo = _mm_mullo_epi16(vs, vt);
+    prod_hi = _mm_mulhi_epi16(vs, vt);
+
+    prod_hi = _mm_add_epi16(prod_hi, prod_hi);
+    negative = _mm_srli_epi16(prod_lo, 15);
+    prod_hi = _mm_add_epi16(prod_hi, negative);
+    prod_lo = _mm_add_epi16(prod_lo, prod_lo);
+    negative = _mm_srli_epi16(prod_lo, 15);
+
+    round = _mm_cmpeq_epi16(vs, vs);
+    round = _mm_slli_epi16(round, 15);
+
+    prod_lo = _mm_xor_si128(prod_lo, round);
+    *(v16 *)VACC_L = prod_lo;
+    prod_hi = _mm_add_epi16(prod_hi, negative);
+    *(v16 *)VACC_M = prod_hi;
+
+/*
+ * VMULU does unsigned clamping.  However, in VMULU's case, the only possible
+ * combinations that overflow, are either negative values or -32768 * -32768.
+ */
+    negative = _mm_srai_epi16(prod_hi, 15);
+    vs = _mm_cmpeq_epi16(vs, round); /* vs == -32768 ? ~0 : 0 */
+    vt = _mm_cmpeq_epi16(vt, round); /* vt == -32768 ? ~0 : 0 */
+    vs = _mm_and_si128(vs, vt); /* vs == vt == -32768:  corner case confirmed */
+    negative = _mm_xor_si128(negative, vs);
+    *(v16 *)VACC_H = negative; /* 2*i16*i16 only fills L/M; VACC_H = 0 or ~0. */
+
+    prod_lo = _mm_srai_epi16(prod_hi, 15); /* unsigned overflow mask */
+    vs = _mm_or_si128(prod_hi, prod_lo);
+    prod_hi = _mm_srai_epi16(prod_hi, 15); /* unsigned underflow mask */
+    vs = _mm_andnot_si128(prod_hi, vs);
+    return (vs);
+#else
+    word_64 product[N]; /* (-32768 * -32768)<<1 + 32768 confuses 32-bit type. */
+    register unsigned int i;
+
+    for (i = 0; i < N; i++)
+        product[i].W = vs[i] * vt[i];
+    for (i = 0; i < N; i++)
+        product[i].W <<= 1; /* special fractional shift value */
+    for (i = 0; i < N; i++)
+        product[i].W += 32768; /* special fractional round value */
+    for (i = 0; i < N; i++)
+        VACC_L[i] = (product[i].UW & 0x00000000FFFF) >>  0;
+    for (i = 0; i < N; i++)
+        VACC_M[i] = (product[i].UW & 0x0000FFFF0000) >> 16;
+    for (i = 0; i < N; i++)
+        VACC_H[i] = -(product[i].SW < 0); /* product>>32 & 0xFFFF */
+    UNSIGNED_CLAMP(V_result);
     return;
 #endif
 }


KVM: PPC: e500: fix typo in tlb code

KVM: PPC: e500: fix typo in tlb code

The tlbncfg registers should be populated with their respective TLB's
values. Fix the obvious typo.

Signed-off-by: Alexander Graf <3ad82b0c937b9aa51276120cedd545efc822be04@suse.de>
Signed-off-by: Avi Kivity <8f920f22884d6fea9df883843c4a8095a2e5ac6f@redhat.com>

--- arch/powerpc/kvm/e500_tlb.c
+++ arch/powerpc/kvm/e500_tlb.c
@@ -1268,8 +1268,8 @@

 	vcpu->arch.tlbcfg[1] = mfspr(SPRN_TLB1CFG) &
 			     ~(TLBnCFG_N_ENTRY | TLBnCFG_ASSOC);
-	vcpu->arch.tlbcfg[0] |= vcpu_e500->gtlb_params[1].entries;
-	vcpu->arch.tlbcfg[0] |=
+	vcpu->arch.tlbcfg[1] |= vcpu_e500->gtlb_params[1].entries;
+	vcpu->arch.tlbcfg[1] |=
 		vcpu_e500->gtlb_params[1].ways << TLBnCFG_ASSOC_SHIFT;

 	return 0;


Add prefix header

Add prefix header

error: pathspec 'src/main/cpp/JniHelpers.h' did not match any file(s) known to git

--- src/main/cpp/JniHelpers.h
+++ src/main/cpp/JniHelpers.h
@@ -0,0 +1,14 @@
+#ifndef __JniHelpers_h__
+#define __JniHelpers_h__
+
+#if WIN32
+#define EXPORT __declspec(dllexport)
+#endif
+
+#include "JniClassUtils.h"
+#include "JniClassWrapper.h"
+#include "JniGlobalRef.h"
+#include "JniLocalRef.h"
+#include "JniThreadUtils.h"
+
+#endif // __JniHelpers_h__


don't consume the receiver when auto-recovering

--- src/libponyc/expr/call.c
+++ src/libponyc/expr/call.c
@@ -307,7 +307,7 @@
   bool can_recover = auto_recover_call(ast, positional, result);

   if(can_recover)
-    a_type = consume_type(r_type);
+    a_type = r_type;
   else
     a_type = alias(r_type);


[S390] cio: update sac values

[S390] cio: update sac values

Values for the sac field have changed - update code accordingly.

Signed-off-by: Peter Oberparleiter <db44112e0f7c7459f7ecb043f101f88a2e807d9f@de.ibm.com>
Signed-off-by: Martin Schwidefsky <52616596d8f5df0d597e85ab515377f92f939c68@de.ibm.com>

--- arch/s390/include/asm/fcx.h
+++ arch/s390/include/asm/fcx.h
@@ -248,8 +248,8 @@
 #define TCCB_MAX_SIZE		(sizeof(struct tccb_tcah) + \
 				 TCCB_MAX_DCW * sizeof(struct dcw) + \
 				 sizeof(struct tccb_tcat))
-#define TCCB_SAC_DEFAULT	0xf901
-#define TCCB_SAC_INTRG		0xf902
+#define TCCB_SAC_DEFAULT	0x1ffe
+#define TCCB_SAC_INTRG		0x1fff

 /**
  * struct tccb_tcah - Transport-Command-Area Header (TCAH)


Add missing documentation to Window.

Add missing documentation to Window.

--- src/main/display/Window.h
+++ src/main/display/Window.h
@@ -5,6 +5,9 @@
 #include <ncurses.h>
 #include <string>

+/**
+ * Window objects create and manage ncurses windows.
+ */
 class Window
 {
 	public:
@@ -51,8 +54,30 @@
 		 */
 		uint32_t getY();

+		/**
+		 * Add the default border around the Window.
+		 */
 		void addBorder();
+		/**
+		 * Add the specified border characters around the Window.
+		 *
+		 * @param sides Left and right sides.
+		 * @param topbot Top and bottom edges.
+		 * @param corners The corners.
+		 */
 		void addBorder(char sides, char topbot, char corners);
+		/**
+		 * Add the specified border characters around the Window.
+		 *
+		 * @param left The left edge.
+		 * @param right The right edge.
+		 * @param top The top edge.
+		 * @param bottom The bottom edge.
+		 * @param topleft The top left corner.
+		 * @param topright The top right corner.
+		 * @param botleft The bottom left corner.
+		 * @param botright The bottom right corner.
+		 */
 		void addBorder(char left, char right, char top, char bottom, char topleft, char topright, char botleft, char botright);

 		/**


sh: Kill off SH-5 enter_deep_standby() cruft.

Signed-off-by: Paul Mundt <38b52dbb5f0b63d149982b6c5de788ec93a89032@linux-sh.org>

--- arch/sh/kernel/process_64.c
+++ arch/sh/kernel/process_64.c
@@ -27,6 +27,7 @@
 #include <linux/init.h>
 #include <linux/module.h>
 #include <linux/proc_fs.h>
+#include <linux/io.h>
 #include <asm/uaccess.h>
 #include <asm/pgtable.h>

@@ -106,9 +107,20 @@

 void machine_power_off(void)
 {
-	extern void enter_deep_standby(void);
-
-	enter_deep_standby();
+#if 0
+	/* Disable watchdog timer */
+	ctrl_outl(0xa5000000, WTCSR);
+	/* Configure deep standby on sleep */
+	ctrl_outl(0x03, STBCR);
+#endif
+
+	__asm__ __volatile__ (
+		"sleep\n\t"
+		"synci\n\t"
+		"nop;nop;nop;nop\n\t"
+	);
+
+	panic("Unexpected wakeup!\n");
 }

 void (*pm_power_off)(void) = machine_power_off;


sparc64: Rework auxio driver to save some text space.

Use common functions instead of inlining and duplicating logic
over and over to handle the SBUS vs. EBUS cases.

Before:

   text	   data	    bss	    dec	    hex	filename
    715	    568	     16	   1299	    513	arch/sparc64/kernel/auxio.o

After:

   text	   data	    bss	    dec	    hex	filename
    631	    568	     16	   1215	    4bf	arch/sparc64/kernel/auxio.o

Signed-off-by: David S. Miller <fe08d3c717adf2ae63592e4c9aec6e3e404d8e3e@davemloft.net>

--- arch/sparc64/kernel/auxio.c
+++ arch/sparc64/kernel/auxio.c
@@ -27,73 +27,55 @@
 static enum auxio_type auxio_devtype = AUXIO_TYPE_NODEV;
 static DEFINE_SPINLOCK(auxio_lock);

-static void __auxio_sbus_set(u8 bits_on, u8 bits_off)
+static void __auxio_rmw(u8 bits_on, u8 bits_off, int ebus)
 {
 	if (auxio_register) {
-		unsigned char regval;
 		unsigned long flags;
-		unsigned char newval;
+		u8 regval, newval;

 		spin_lock_irqsave(&auxio_lock, flags);

-		regval =  sbus_readb(auxio_register);
+		regval = (ebus ?
+			  (u8) readl(auxio_register) :
+			  sbus_readb(auxio_register));
 		newval =  regval | bits_on;
 		newval &= ~bits_off;
-		newval &= ~AUXIO_AUX1_MASK;
-		sbus_writeb(newval, auxio_register);
+		if (!ebus)
+			newval &= ~AUXIO_AUX1_MASK;
+		if (ebus)
+			writel((u32) newval, auxio_register);
+		else
+			sbus_writeb(newval, auxio_register);

 		spin_unlock_irqrestore(&auxio_lock, flags);
 	}
 }

-static void __auxio_ebus_set(u8 bits_on, u8 bits_off)
+static void __auxio_set_bit(u8 bit, int on, int ebus)
 {
-	if (auxio_register) {
-		unsigned char regval;
-		unsigned long flags;
-		unsigned char newval;
+	u8 bits_on = (ebus ? AUXIO_PCIO_LED : AUXIO_AUX1_LED);
+	u8 bits_off = 0;

-		spin_lock_irqsave(&auxio_lock, flags);
-
-		regval =  (u8)readl(auxio_register);
-		newval =  regval | bits_on;
-		newval &= ~bits_off;
-		writel((u32)newval, auxio_register);
-
-		spin_unlock_irqrestore(&auxio_lock, flags);
+	if (!on) {
+		u8 tmp = bits_off;
+		bits_off = bits_on;
+		bits_on = tmp;
 	}
-}
-
-static inline void __auxio_ebus_set_led(int on)
-{
-	(on) ? __auxio_ebus_set(AUXIO_PCIO_LED, 0) :
-		__auxio_ebus_set(0, AUXIO_PCIO_LED) ;
-}
-
-static inline void __auxio_sbus_set_led(int on)
-{
-	(on) ? __auxio_sbus_set(AUXIO_AUX1_LED, 0) :
-		__auxio_sbus_set(0, AUXIO_AUX1_LED) ;
+	__auxio_rmw(bits_on, bits_off, ebus);
 }

 void auxio_set_led(int on)
 {
-	switch(auxio_devtype) {
-	case AUXIO_TYPE_SBUS:
-		__auxio_sbus_set_led(on);
-		break;
-	case AUXIO_TYPE_EBUS:
-		__auxio_ebus_set_led(on);
-		break;
-	default:
-		break;
-	}
+	int ebus = auxio_devtype == AUXIO_TYPE_EBUS;
+	u8 bit;
+
+	bit = (ebus ? AUXIO_PCIO_LED : AUXIO_AUX1_LED);
+	__auxio_set_bit(bit, on, ebus);
 }

-static inline void __auxio_sbus_set_lte(int on)
+static void __auxio_sbus_set_lte(int on)
 {
-	(on) ? __auxio_sbus_set(AUXIO_AUX1_LTE, 0) :
-		__auxio_sbus_set(0, AUXIO_AUX1_LTE) ;
+	__auxio_set_bit(AUXIO_AUX1_LTE, on, 0);
 }

 void auxio_set_lte(int on)


ACPI: Add a quirk for "AMILO PRO V2030" to ignore the timer overriding

This is the 2nd part of fix for kernel bugzilla 40002:
    "IRQ 0 assigned to VGA"
https://bugzilla.kernel.org/show_bug.cgi?id=40002

The root cause is the buggy FW, whose ACPI tables assign the GSI 16
to 2 irqs 0 and 16(VGA), and the VGA is the right owner of GSI 16.
So add a quirk to ignore the irq0 overriding GSI 16 for the
FUJITSU SIEMENS AMILO PRO V2030 platform will solve this issue.

Reported-and-tested-by: Szymon Kowalczyk <2950b3bc8ec2308ef6187cc2ef2e35a9ea392ffe@o2.pl>
Signed-off-by: Feng Tang <7685a6702c33a8c01ef22193062cb8069601cb3e@intel.com>
Signed-off-by: Len Brown <b060cfa1096cc6e8be83699ddb4ed8a77dd63af5@intel.com>

--- arch/x86/kernel/acpi/boot.c
+++ arch/x86/kernel/acpi/boot.c
@@ -1470,6 +1470,14 @@
 		     DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq 6715b"),
 		     },
 	 },
+	{
+	 .callback = dmi_ignore_irq0_timer_override,
+	 .ident = "FUJITSU SIEMENS",
+	 .matches = {
+		     DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
+		     DMI_MATCH(DMI_PRODUCT_NAME, "AMILO PRO V2030"),
+		     },
+	 },
 	{}
 };


x86, AMD IOMMU: add mapping functions for coherent mappings

This patch adds the dma_ops functions for coherent mappings.

Signed-off-by: Joerg Roedel <ebd221a096cbc71dd9e1991db28795933c85f380@amd.com>
Cc: d4d3187dbcba3fb2e2e25a4ce499c8e441b6817d@lists.linux-foundation.org
Cc: d5987f51b7b436a73cf58d68217e3549546a1888@amd.com
Cc: a8028979c9a5468bd4f8500f0d764a298219188f@amd.com
Cc: 22a70fd9773e4de05b12c05075e9bcd605577f4d@amd.com
Cc: 4688a6871ff025801033b3c4b039d55a29f8f937@8bytes.org
Signed-off-by: Ingo Molnar <9dbbbf0688fedc85ad4da37637f1a64b8c718ee2@elte.hu>

--- arch/x86/kernel/amd_iommu.c
+++ arch/x86/kernel/amd_iommu.c
@@ -798,3 +798,77 @@
 	spin_unlock_irqrestore(&domain->lock, flags);
 }

+static void *alloc_coherent(struct device *dev, size_t size,
+			    dma_addr_t *dma_addr, gfp_t flag)
+{
+	unsigned long flags;
+	void *virt_addr;
+	struct amd_iommu *iommu;
+	struct protection_domain *domain;
+	u16 devid;
+	phys_addr_t paddr;
+
+	virt_addr = (void *)__get_free_pages(flag, get_order(size));
+	if (!virt_addr)
+		return 0;
+
+	memset(virt_addr, 0, size);
+	paddr = virt_to_phys(virt_addr);
+
+	get_device_resources(dev, &iommu, &domain, &devid);
+
+	if (!iommu || !domain) {
+		*dma_addr = (dma_addr_t)paddr;
+		return virt_addr;
+	}
+
+	spin_lock_irqsave(&domain->lock, flags);
+
+	*dma_addr = __map_single(dev, iommu, domain->priv, paddr,
+				 size, DMA_BIDIRECTIONAL);
+
+	if (*dma_addr == bad_dma_address) {
+		free_pages((unsigned long)virt_addr, get_order(size));
+		virt_addr = NULL;
+		goto out;
+	}
+
+	if (iommu_has_npcache(iommu))
+		iommu_flush_pages(iommu, domain->id, *dma_addr, size);
+
+	if (iommu->need_sync)
+		iommu_completion_wait(iommu);
+
+out:
+	spin_unlock_irqrestore(&domain->lock, flags);
+
+	return virt_addr;
+}
+
+static void free_coherent(struct device *dev, size_t size,
+			  void *virt_addr, dma_addr_t dma_addr)
+{
+	unsigned long flags;
+	struct amd_iommu *iommu;
+	struct protection_domain *domain;
+	u16 devid;
+
+	get_device_resources(dev, &iommu, &domain, &devid);
+
+	if (!iommu || !domain)
+		goto free_mem;
+
+	spin_lock_irqsave(&domain->lock, flags);
+
+	__unmap_single(iommu, domain->priv, dma_addr, size, DMA_BIDIRECTIONAL);
+	iommu_flush_pages(iommu, domain->id, dma_addr, size);
+
+	if (iommu->need_sync)
+		iommu_completion_wait(iommu);
+
+	spin_unlock_irqrestore(&domain->lock, flags);
+
+free_mem:
+	free_pages((unsigned long)virt_addr, get_order(size));
+}
+


x86/amd-iommu: Fix device table write order

The V bit of the device table entry has to be set after the
rest of the entry is written to not confuse the hardware.

Signed-off-by: Joerg Roedel <ebd221a096cbc71dd9e1991db28795933c85f380@amd.com>

--- arch/x86/kernel/amd_iommu.c
+++ arch/x86/kernel/amd_iommu.c
@@ -1087,9 +1087,9 @@
 	pte_root |= IOMMU_PTE_IR | IOMMU_PTE_IW | IOMMU_PTE_P | IOMMU_PTE_TV;

 	write_lock_irqsave(&amd_iommu_devtable_lock, flags);
+	amd_iommu_dev_table[devid].data[2] = domain->id;
+	amd_iommu_dev_table[devid].data[1] = upper_32_bits(pte_root);
 	amd_iommu_dev_table[devid].data[0] = lower_32_bits(pte_root);
-	amd_iommu_dev_table[devid].data[1] = upper_32_bits(pte_root);
-	amd_iommu_dev_table[devid].data[2] = domain->id;

 	amd_iommu_pd_table[devid] = domain;
 	write_unlock_irqrestore(&amd_iommu_devtable_lock, flags);


x86, apic: Make disabled_cpu_apicid static read_mostly, fix typos

Make disabled_cpu_apicid static and read_mostly, and fix a couple of
typos.

Reported-by: Ingo Molnar <9dbbbf0688fedc85ad4da37637f1a64b8c718ee2@kernel.org>
Link: 5b6118c2d5d327bb1fdcc4c2892273c99473d3cc@gmail.com
Signed-off-by: H. Peter Anvin <8a453bad9912ffe59bc0f0b8abe03df9be19379e@linux.intel.com>
Cc: HATAYAMA Daisuke <e293c7e13ecc029aa287dca4b8ecfdf8a10ea3b9@jp.fujitsu.com>


Catch destructed proxy during clone nuke

--- mud/home/Verb/sys/verb/core/wiz/ooc/object/clone/cnuke.c
+++ mud/home/Verb/sys/verb/core/wiz/ooc/object/clone/cnuke.c
@@ -17,6 +17,7 @@
  * You should have received a copy of the GNU Affero General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
+#include <kotaka/log.h>
 #include <kotaka/paths/system.h>
 #include <kotaka/paths/verb.h>
 #include <status.h>
@@ -52,6 +53,11 @@
 {
 	int ticks;

+	if (!proxy) {
+		LOGD->post_message("system", LOG_ERROR, "Aborting clone nuke (proxy destructed)");
+		return;
+	}
+
 	ticks = status(ST_TICKS);

 	while (index >= 0 && ticks - status(ST_TICKS) < 10000) {


linux-generic: timer fix odp_timer_pool_create return code

Accodring to API return code for fail case is ODP_TIMER_POOL_INVALID
and errno set event if it's defined to NULL. Also add check on pool
alloc that input parameter is not invalid.
https://bugs.linaro.org/show_bug.cgi?id=2139

Signed-off-by: Maxim Uvarov <db4d16e02ae2d7493db430203537da8b2e34f290@linaro.org>
Reviewed-and-tested-by: Bill Fischofer <52f3c909d51cc5d355a68a403df6906b3c1a8f83@linaro.org>

--- platform/linux-generic/odp_timer.c
+++ platform/linux-generic/odp_timer.c
@@ -221,16 +221,15 @@
 static void itimer_init(odp_timer_pool *tp);
 static void itimer_fini(odp_timer_pool *tp);

-static odp_timer_pool *odp_timer_pool_new(
-	const char *_name,
-	const odp_timer_pool_param_t *param)
+static odp_timer_pool_t odp_timer_pool_new(const char *_name,
+					   const odp_timer_pool_param_t *param)
 {
 	uint32_t tp_idx = odp_atomic_fetch_add_u32(&num_timer_pools, 1);
 	if (odp_unlikely(tp_idx >= MAX_TIMER_POOLS)) {
 		/* Restore the previous value */
 		odp_atomic_sub_u32(&num_timer_pools, 1);
 		__odp_errno = ENFILE; /* Table overflow */
-		return NULL;
+		return ODP_TIMER_POOL_INVALID;
 	}
 	size_t sz0 = ODP_ALIGN_ROUNDUP(sizeof(odp_timer_pool),
 			ODP_CACHE_LINE_SIZE);
@@ -794,10 +793,9 @@
 	/* Verify that we have a valid (non-zero) timer resolution */
 	if (param->res_ns == 0) {
 		__odp_errno = EINVAL;
-		return NULL;
-	}
-	odp_timer_pool_t tp = odp_timer_pool_new(name, param);
-	return tp;
+		return ODP_TIMER_POOL_INVALID;
+	}
+	return odp_timer_pool_new(name, param);
 }

 void odp_timer_pool_start(void)
@@ -845,17 +843,18 @@
 			    odp_queue_t queue,
 			    void *user_ptr)
 {
-	if (odp_unlikely(queue == ODP_QUEUE_INVALID))
-		ODP_ABORT("%s: Invalid queue handle\n", tpid->name);
+	if (odp_unlikely(tpid == ODP_TIMER_POOL_INVALID)) {
+		ODP_ERR("Invalid timer pool.\n");
+		return ODP_TIMER_INVALID;
+	}
+
+	if (odp_unlikely(queue == ODP_QUEUE_INVALID)) {
+		ODP_ERR("%s: Invalid queue handle\n", tpid->name);
+		return ODP_TIMER_INVALID;
+	}
 	/* We don't care about the validity of user_ptr because we will not
 	 * attempt to dereference it */
-	odp_timer_t hdl = timer_alloc(tpid, queue, user_ptr);
-	if (odp_likely(hdl != ODP_TIMER_INVALID)) {
-		/* Success */
-		return hdl;
-	}
-	/* errno set by timer_alloc() */
-	return ODP_TIMER_INVALID;
+	return timer_alloc(tpid, queue, user_ptr);
 }

 odp_event_t odp_timer_free(odp_timer_t hdl)


x86: bpf_jit: fix two bugs in eBPF JIT compiler

1.
JIT compiler using multi-pass approach to converge to final image size,
since x86 instructions are variable length. It starts with large
gaps between instructions (so some jumps may use imm32 instead of imm8)
and iterates until total program size is the same as in previous pass.
This algorithm works only if program size is strictly decreasing.
Programs that use LD_ABS insn need additional code in prologue, but it
was not emitted during 1st pass, so there was a chance that 2nd pass would
adjust imm32->imm8 jump offsets to the same number of bytes as increase in
prologue, which may cause algorithm to erroneously decide that size converged.
Fix it by always emitting largest prologue in the first pass which
is detected by oldproglen==0 check.
Also change error check condition 'proglen != oldproglen' to fail gracefully.

2.
while staring at the code realized that 64-byte buffer may not be enough
when 1st insn is large, so increase it to 128 to avoid buffer overflow
(theoretical maximum size of prologue+div is 109) and add runtime check.

Fixes: 622582786c9e ("net: filter: x86: internal BPF JIT")
Reported-by: Darrick J. Wong <206af32863b9fd2fc412cf38757e7321a0f2bd37@oracle.com>
Signed-off-by: Alexei Starovoitov <c24c0248770ae98831f8a654310d4c2e07514c61@plumgrid.com>
Tested-by: Darrick J. Wong <206af32863b9fd2fc412cf38757e7321a0f2bd37@oracle.com>
Signed-off-by: David S. Miller <fe08d3c717adf2ae63592e4c9aec6e3e404d8e3e@davemloft.net>


Fixed errors in UsbDevice driver for LPC13Uxx.

Fixed initial descriptor reading.
Fixed initialization of data endpoints.
Fixed request writing for IN endpoints.

--- platform/nxp/lpc13uxx/usb_device.c
+++ platform/nxp/lpc13uxx/usb_device.c
@@ -140,7 +140,6 @@
   const uint32_t devStatus = reg->DEVCMDSTAT;
   const uint32_t intStatus = reg->INTSTAT;

-  reg->DEVCMDSTAT = devStatus;
   reg->INTSTAT = intStatus;

   /* Device interrupts */
@@ -149,6 +148,8 @@
     /* Device reset */
     if (devStatus & DEVCMDSTAT_DRES_C)
     {
+      reg->DEVCMDSTAT |= DEVCMDSTAT_DRES_C;
+
       resetDevice(device);
       usbControlNotify(device->control, USB_DEVICE_EVENT_RESET);
     }
@@ -156,6 +157,7 @@
     /* Connect Change event on VBus disappearance */
     if (devStatus & DEVCMDSTAT_DCON_C)
     {
+      reg->DEVCMDSTAT |= DEVCMDSTAT_DCON_C;
     }

     /*
@@ -166,12 +168,14 @@
      */
     if (devStatus & DEVCMDSTAT_DSUS_C)
     {
+      reg->DEVCMDSTAT |= DEVCMDSTAT_DSUS_C;
+
       usbControlNotify(device->control, ((devStatus & DEVCMDSTAT_DSUS) ?
           USB_DEVICE_EVENT_SUSPEND : USB_DEVICE_EVENT_RESUME));
     }
   }

-  uint32_t epStatus = reverseBits32(intStatus & INTSTAT_EP_INT_MASK);
+  uint32_t epStatus = intStatus & INTSTAT_EP_INT_MASK;

   /* EP interrupts */
   if (epStatus)
@@ -184,10 +188,13 @@
     do
     {
       const unsigned int index = countLeadingZeros32(epStatus);
+      const bool controlEpSetup = (index == 0) && setup;

       epStatus -= (1UL << 31) >> index;
-      epHandler((struct SbUsbEndpoint *)epArray[index],
-          !index && setup);
+      epHandler((struct SbUsbEndpoint *)epArray[index], controlEpSetup);
+
+      if (controlEpSetup)
+        reg->DEVCMDSTAT |= DEVCMDSTAT_SETUP;
     }
     while (epStatus);
   }
@@ -604,6 +611,10 @@
 {
   struct SbUsbEndpoint * const ep = object;
   struct UsbDevice * const device = ep->device;
+  const unsigned int index = EP_TO_INDEX(ep->address);
+
+  if (index >= 2 && !ep->device->configured)
+    return E_IDLE;

   assert(ep->position); /* Device should be initialized */
   assert(request->callback);
@@ -615,7 +626,11 @@

   if (ep->address & USB_EP_DIRECTION_IN)
   {
-    invokeHandler = pointerQueueEmpty(&ep->requests);
+    if (pointerQueueEmpty(&ep->requests))
+    {
+      if (!(device->base.endpointList[index].b[0] & EPCS_A))
+        invokeHandler = true;
+    }
   }
   else if (pointerQueueEmpty(&ep->requests))
   {
@@ -625,9 +640,7 @@

   if (invokeHandler)
   {
-    const unsigned int index = EP_TO_INDEX(ep->address);
     LPC_USB_Type * const reg = device->base.reg;
-
     reg->INTSETSTAT |= INTSETSTAT_EP_SET_INT(index);
   }


oprofile, x86: Simplify init/exit functions

Now, that we only call the exit function if init succeeds with commit:

 979048e oprofile: don't call arch exit code from init code on failure

we can simplify the x86 init/exit functions too. Variable using_nmi
becomes obsolete.

Signed-off-by: Robert Richter <22a70fd9773e4de05b12c05075e9bcd605577f4d@amd.com>

--- arch/x86/oprofile/nmi_int.c
+++ arch/x86/oprofile/nmi_int.c
@@ -695,17 +695,12 @@
 	return 1;
 }

-/* in order to get sysfs right */
-static int using_nmi;
-
 int __init op_nmi_init(struct oprofile_operations *ops)
 {
 	__u8 vendor = boot_cpu_data.x86_vendor;
 	__u8 family = boot_cpu_data.x86;
 	char *cpu_type = NULL;
 	int ret = 0;
-
-	using_nmi = 0;

 	if (!cpu_has_apic)
 		return -ENODEV;
@@ -790,13 +785,11 @@
 	if (ret)
 		return ret;

-	using_nmi = 1;
 	printk(KERN_INFO "oprofile: using NMI interrupt.\n");
 	return 0;
 }

 void op_nmi_exit(void)
 {
-	if (using_nmi)
-		exit_sysfs();
-}
+	exit_sysfs();
+}


Get rid of random seeds.  Addresses #162.

git-svn-id: 4b2652e19d8125fd9d24eff55f31fd1beb5a42e7@1067 c7de825b-a66e-492c-adef-691d508d4ae1

--- src/tests/test_db_curs4.c
+++ src/tests/test_db_curs4.c
@@ -330,13 +330,12 @@

 static void usage (const char *argv1) {
-    fprintf(stderr, "Usage:\n %s [ --DB-CREATE | --more ] seed ", argv1);
+    fprintf(stderr, "Usage:\n %s [ --more ]\n", argv1);
     exit(1);
 }

 int main (int argc, const char *argv[]) {
     const char *progname=argv[0];
-    int useseed=1;

     memset(&nc_key, 0, sizeof(nc_key));
     memset(&nc_data, 0, sizeof(nc_data));
@@ -353,12 +352,7 @@
 	if (strcmp(argv[0], "--more")==0) {
 	    mode = MODE_MORE;
 	} else {
-	    errno=0;
-	    char *endptr;
-	    useseed = strtoul(argv[0], &endptr, 10);
-	    if (errno!=0 || *endptr!=0 || endptr==argv[0]) {
-		usage(progname);
-	    }
+	    usage(progname);
 	}
 	argc--; argv++;
     }


Addresses #1531 Fix test_logflush

Addresses #1531 Fix test_logflush

git-svn-id: b5c078ec0b4d3a50497e9dd3081db18a5b4f16e5@9966 c7de825b-a66e-492c-adef-691d508d4ae1

--- src/tests/test_logflush.c
+++ src/tests/test_logflush.c
@@ -5,7 +5,6 @@
 #include <db.h>
 #include <sys/stat.h>
 #include <fcntl.h>
-#include <sys/mman.h>

 // Return the offset
 static int
@@ -15,22 +14,15 @@
 #else
 #define lname ENVDIR "//log.0000000001"
 #endif
-    int fd = open(lname, O_RDONLY);
-    assert(fd>=0);
-    int64_t file_size;
-    int r = toku_os_get_file_size(fd, &file_size);
-    assert(r==0);
-    void *addr_v = mmap(0, file_size, PROT_READ, MAP_PRIVATE, fd, 0);
-    assert(addr_v!=MAP_FAILED);
-    char *fstr = addr_v;
-    int   searchlen=strlen(str);
-    int i;
-    for (i=0; i+searchlen<file_size; i++) {
-	if (memcmp(str, fstr+i, searchlen)==0) {
-	    return i;
-	}
-    }
-    return -1;
+#define COMMAND "grep -F -o"
+    char systembuf[strlen(str)+sizeof(COMMAND " \"\" " lname " > /dev/null")];
+    int bytes = snprintf(systembuf, sizeof(systembuf), COMMAND " \"%s\" %s > /dev/null", str, lname);
+    assert(bytes>=0);
+    assert((size_t)bytes<sizeof(systembuf));
+    int r = system(systembuf);
+    assert(r!=-1);
+    if (r>0) r = -1;
+    return r;
 }

 int


allow multiple multiplex-funnels to exist

maintain a list of multiplex-funnels, such that we can have multiple
active multiplex-funnels inside Merovingian, and connect clients to the
multiplex-funnel they requested.

--- sql/src/backends/monet5/merovingian/daemon/client.c
+++ sql/src/backends/monet5/merovingian/daemon/client.c
@@ -42,7 +42,12 @@
 #include "proxy.h"
 #include "multiplex-funnel.h"

-static multiplex *mero_multiplex_funnel = NULL;
+typedef struct _mplist {
+	multiplex *mpf;
+	struct _mplist *next;
+} mplist;
+
+static mplist *mero_multiplex_funnel = NULL;

 static err
 handleClient(int sock, char isusock)
@@ -229,20 +234,25 @@
 	if (strcmp(lang, "multiplex-funnel") == 0) {
 		/* SQL multiplexer with funnelling capabilities */
 		/* find/start/attach funnel */
-		/* FIXME: maintain a list, search, match name, etc.
-		if (strcmp(_multiplex_funnel->name, database) == 0)
-		*/
-		if (mero_multiplex_funnel == NULL) {
-			mero_multiplex_funnel = multiplexInit(database);
-			if (pthread_create(&mero_multiplex_funnel->tid,
+		mplist *w;
+		for (w = mero_multiplex_funnel; w != NULL; w = w->next) {
+			if (strcmp(w->mpf->pool, database) == 0)
+				break;
+		}
+		if (w == NULL) {
+			w = malloc(sizeof(mplist));
+			w->next = mero_multiplex_funnel;
+			w->mpf = multiplexInit(database);
+			mero_multiplex_funnel = w;
+			if (pthread_create(&w->mpf->tid,
 					NULL, (void *(*)(void *))multiplexThread,
-					(void *)mero_multiplex_funnel) < 0)
+					(void *)w->mpf) < 0)
 			{
 				Mfprintf(stderr, "starting multiplex-funnel %s failed\n",
 						database);
 			}
 		}
-		multiplexAddClient(mero_multiplex_funnel, sock, fout, fdin, host);
+		multiplexAddClient(w->mpf, sock, fout, fdin, host);

 		return(NO_ERR);
 	}


Minor changes for watchdog

Minor changes for watchdog

--- aroop/core/src/aroop_core.c
+++ aroop/core/src/aroop_core.c
@@ -53,6 +53,7 @@
 		aroop_txt_system_init();
 		opp_str2system_init();
 		opp_queuesystem_init();
+		opp_watchdog_init();
 	}
 }

@@ -71,6 +72,7 @@
 	SYNC_UWORD16_T newval = --core_users;
 #endif
 	if(newval == 0) {
+		opp_watchdog_deinit();
 		opp_any_obj_system_deinit();
 		aroop_txt_system_deinit();
 		opp_str2system_deinit();


add If-Modified-Since support to oggz-chop CGI mode

git-svn-id: ed696e516b63563c8842837a624e30c98be77b3c@3513 8158c8cd-e7e1-0310-9fa4-c5954c97daef

--- src/tools/oggz-chop/cgi.c
+++ src/tools/oggz-chop/cgi.c
@@ -3,6 +3,10 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>

 #include "oggz-chop.h"
 #include "header.h"
@@ -139,22 +143,32 @@

   /*photo_init (&params->in, path_translated);*/

-#if 0
   if (if_modified_since != NULL) {
+    struct stat statbuf;
     int len;

     fprintf (stderr, "If-Modified-Since: %s\n", if_modified_since);
+
+    if (stat (path_translated, &statbuf) == -1) {
+      switch (errno) {
+      case ENOENT:
+        return 0;
+      default:
+        fprintf (stderr, "oggz-chop: Error checking %s: %s\n",
+                 path_translated, strerror(errno));
+        return -1;
+      }
+    }

     len = strlen (if_modified_since) + 1;
     since_time = httpdate_parse (if_modified_since, len);

-    if (state->in.mtime <= since_time) {
+    if (statbuf.st_mtime <= since_time) {
       header_not_modified();
       header_end();
       return 1;
     }
   }
-#endif

   header_content_type_ogg ();


Add accessors for SA parameters

Add accessors for SA parameters

--- src/physics/include/grins/spalart_allmaras_parameters.h
+++ src/physics/include/grins/spalart_allmaras_parameters.h
@@ -47,6 +47,48 @@
     libMesh::Real destruction_fn( libMesh::Number nu, libMesh::Real wall_distance,
                                   libMesh::Real S_tilde) const;

+    libMesh::Real get_kappa() const
+    { return _kappa;}
+
+    libMesh::Real get_cv1() const
+    { return _cv1;}
+
+    libMesh::Real get_cv2() const
+    { return _cv2;}
+
+    libMesh::Real get_cv3() const
+    { return _cv3;}
+
+    libMesh::Real get_cb1() const
+    { return _cb1;}
+
+    libMesh::Real get_cb2() const
+    { return _cb2;}
+
+    libMesh::Real get_sigma() const
+    { return _sigma;}
+
+    libMesh::Real get_cw1() const
+    { return _cw1;}
+
+    libMesh::Real get_c_w2() const
+    { return _c_w2;}
+
+    libMesh::Real get_c_w3() const
+    { return _c_w3;}
+
+    libMesh::Real get_r_lin() const
+    { return _r_lin;}
+
+    libMesh::Real get_c_t3() const
+    { return _c_t3;}
+
+    libMesh::Real get_c_t4() const
+    { return _c_t4;}
+
+    libMesh::Real get_c_n1() const
+    { return _c_n1;}
+
     //! Constants specific to the calculation of the source function
     libMesh::Real _kappa, _cv1, _cv2, _cv3;


Use our special wrapper header for qedit.h

--- plugins/videobasedtracker/DirectShowCameraLib/directx_camera_server.h
+++ plugins/videobasedtracker/DirectShowCameraLib/directx_camera_server.h
@@ -39,16 +39,19 @@
 #include <stdexcept>
 #include <memory>

-// Horrible hack to get around missing file in Platform SDK
-#pragma include_alias("dxtrans.h", "qedit.h")
-#define __IDxtCompositor_INTERFACE_DEFINED__
-#define __IDxtAlphaSetter_INTERFACE_DEFINED__
-#define __IDxtJpeg_INTERFACE_DEFINED__
-#define __IDxtKey_INTERFACE_DEFINED__
-
 // Include files for DirectShow video input
 #include <dshow.h>
-#include <qedit.h>
+
+// All we need from the "deprecated" qedit.h header file are these few lousy
+// names:
+// - ISampleGrabber
+// - ISampleGrabberCB
+// - CLSID_SampleGrabber
+// - IID_ISampleGrabber
+// - CLSID_NullRenderer
+// - IID_ISampleGrabberCB
+
+#include "qedit_wrapper.h"

 /// @brief Template alias for our desired COM smart pointer.
 template <typename T> using WinPtr = boost::intrusive_ptr<T>;


Generate Win32OSProcessPlugin from VMConstruction-Plugins-OSProcessPlugin.oscog-nice.64

There are two important changes:
1) let GetCurrentDirectory and GetEnvironmentStrings return UTF8 encoded strings
2) fix STD_ERROR_HANDLE is not a HANDLE

details from MC commits:
----------
Note: I'd like to use an OS constant defined in an OS header file (CP_UTF8), but I never know how to, except redefining my own macro function...
Note 2: every other string (including filename commands etc) passed to the plugin should better be UTF8-encoded, but I did not even started to inquire about it.
----------
STD_ERROR_HANDLE is not a HANDLE
Like the name does not tell, but like the comment got it right, it is a pseudo handle.
Therefore, we cannot simply cast to (HANDLE) and directly use that as a FILE HANDLE.
We must go thru GetStdHandle() API
https://docs.microsoft.com/en-us/windows/console/getstdhandle

How the hell do i know that stuff?
I just don't.
But I read the compiler warnings (WIN64):
C4312: conversion from DWORD to HANDLE of greater size
That can't be right, so I just google: MSDN STD_ERROR_HANDLE
et voila, 1st link is to GetStdHandle...
I hope every one sees the value of a compiler warning now!
[skip travis]

--- src/plugins/Win32OSProcessPlugin/Win32OSProcessPlugin.c
+++ src/plugins/Win32OSProcessPlugin/Win32OSProcessPlugin.c
@@ -1,9 +1,9 @@
 /* Automatically generated by
-	VMPluginCodeGenerator VMMaker.oscog-eem.2480 uuid: bb3ffda7-8241-4dea-b886-d656e474b6c1
+	VMPluginCodeGenerator VMMaker.oscog-nice.2506 uuid: f86074f0-8394-1c4a-aae3-3716eabf4a32
    from
-	Win32OSProcessPlugin VMConstruction-Plugins-OSProcessPlugin.oscog-eem.61 uuid: 95efc120-ca05-4dfc-8c17-f0206fe8e447
- */
-static char __buildInfo[] = "Win32OSProcessPlugin VMConstruction-Plugins-OSProcessPlugin.oscog-eem.61 uuid: 95efc120-ca05-4dfc-8c17-f0206fe8e447 " __DATE__ ;
+	Win32OSProcessPlugin VMConstruction-Plugins-OSProcessPlugin.oscog-nice.64 uuid: b6fede5e-831c-0343-b605-edd6dde0a963
+ */
+static char __buildInfo[] = "Win32OSProcessPlugin VMConstruction-Plugins-OSProcessPlugin.oscog-nice.64 uuid: b6fede5e-831c-0343-b605-edd6dde0a963 " __DATE__ ;
 /* D T Lewis - Win32OSProcessPlugin.c translated from class
    Win32OSProcessPlugin of OSProcessPlugin version 4.3.3 Cog */

@@ -140,11 +140,11 @@
 static usqIntptr_t socketRecordSize(void);
 static SocketPtr socketValueOf(sqInt anSQSocketRecord);
 static sqInt startHandlerThreadForAnycountsignalingSemaphoreAt(HANDLE *handleArrayPointer, sqInt arraySize, sqInt semaphoreIndex);
-static HANDLE stdErrHandle(void);
+static DWORD stdErrHandle(void);
 static HANDLE stderrHandle(void);
-static HANDLE stdInHandle(void);
+static DWORD stdInHandle(void);
 static HANDLE stdinHandle(void);
-static HANDLE stdOutHandle(void);
+static DWORD stdOutHandle(void);
 static HANDLE stdoutHandle(void);
 static sqInt stringFromCString(const char *aCString);
 static HANDLE threadMutexHandle(void);
@@ -228,9 +228,9 @@
 struct VirtualMachine* interpreterProxy;
 static const char *moduleName =
 #ifdef SQUEAK_BUILTIN_PLUGIN
-	"Win32OSProcessPlugin VMConstruction-Plugins-OSProcessPlugin.oscog-eem.61 (i)"
+	"Win32OSProcessPlugin VMConstruction-Plugins-OSProcessPlugin.oscog-nice.64 (i)"
 #else
-	"Win32OSProcessPlugin VMConstruction-Plugins-OSProcessPlugin.oscog-eem.61 (e)"
+	"Win32OSProcessPlugin VMConstruction-Plugins-OSProcessPlugin.oscog-nice.64 (e)"
 #endif
 ;
 static int osprocessSandboxSecurity;
@@ -242,6 +242,7 @@

 /*** Macros ***/
+#define OSPP_CP_UTF8() CP_UTF8
 #define sessionIdentifierFromSqFile(sqFile) (((SQFile *)(sqFile))->sessionID)

@@ -876,19 +877,19 @@
 	commandString = stackObjectValue(3);
 	cStringPtr = cStringFromString(commandString);
 	if (stdIn == (nilObject())) {
-		inputHandle = stdInHandle();
+		inputHandle = GetStdHandle(stdInHandle());
 	}
 	else {
 		inputHandle = handleFromSQFile(stdIn);
 	}
 	if (stdOut == (nilObject())) {
-		outputHandle = stdOutHandle();
+		outputHandle = GetStdHandle(stdOutHandle());
 	}
 	else {
 		outputHandle = handleFromSQFile(stdOut);
 	}
 	if (stdErr == (nilObject())) {
-		errorHandle = stdErrHandle();
+		errorHandle = GetStdHandle(stdErrHandle());
 	}
 	else {
 		errorHandle = handleFromSQFile(stdErr);
@@ -1087,29 +1088,37 @@
 EXPORT(sqInt)
 primitiveGetCurrentWorkingDirectory(void)
 {
-    char *buffer;
+    WCHAR *buffer;
     usqIntptr_t charSize;
     DWORD cwdLen;
     sqInt cwdString;
     DWORD requiredLen;
+    DWORD utf8Len;

 	/* Determine required size of result buffer (this form counts the terminating null) */
-	charSize = sizeof(TCHAR);
-	requiredLen = GetCurrentDirectory(0, 0);
+	charSize = sizeof(WCHAR);
+	requiredLen = GetCurrentDirectoryW(0, 0);
 	if (requiredLen == 0) {
 		return primitiveFail();
 	}

 	/* Call GetCurrentDirectory() again to get the actual result (which does not count the terminating null (!!)) */
 	buffer = alloca(requiredLen * charSize);
-	cwdLen = GetCurrentDirectory(requiredLen, buffer);
+	cwdLen = GetCurrentDirectoryW(requiredLen, buffer);
 	if ((cwdLen == 0)
 	 || (cwdLen > requiredLen)) {
 		return primitiveFail();
 	}
-	cwdString = instantiateClassindexableSize(classString(), cwdLen * charSize);
-	strncpy(arrayValueOf(cwdString), buffer, cwdLen * charSize);
+
+	/* Allocate the real buffer */
+	utf8Len = WideCharToMultiByte(OSPP_CP_UTF8(), 0, buffer, cwdLen, null, 0, null, null);
+	cwdString = instantiateClassindexableSize(classString(), utf8Len);
+	if (utf8Len > 0) {
+
+		/* copy directly to the buffer, because this form does not include terminating NULL */
+		WideCharToMultiByte(OSPP_CP_UTF8(), 0, buffer, cwdLen, arrayValueOf(cwdString), utf8Len, null, null);
+	}
 	popthenPush(1, cwdString);
 	return 0;
 }
@@ -1126,17 +1135,16 @@
 {
     sqInt count;
     sqInt envArray;
-    sqInt len;
-    sqInt newString;
-    TCHAR *p;
-    TCHAR *pVarBlock;
+    WCHAR *p;
+    WCHAR *pVarBlock;
     sqInt string;
+    DWORD utf8Len;

 	/* Count the environment strings so the result array can be pre-allocated.
 	   This minimizes the number of objects which must be pushed onto the
 	   stack of remappable objects. */
-	pVarBlock = GetEnvironmentStrings();
+	pVarBlock = GetEnvironmentStringsW();
 	p = pVarBlock;
 	count = 0;
 	while (*p != 0) {
@@ -1152,21 +1160,25 @@
 	p = pVarBlock;
 	count = 0;
 	while (*p != 0) {
+
+		/* Get required length of UTF8 encoded string, without terminating NULL */
 		count += 1;
+		utf8Len = WideCharToMultiByte(OSPP_CP_UTF8(), 0, p, wcslen(p), null, 0, null, null);
 		pushRemappableOop(envArray);
-		/* begin stringFromCString: */
-		len = strlen(((char *) p));
-		newString = instantiateClassindexableSize(classString(), len);
-		strncpy(arrayValueOf(newString), ((char *) p), len);
-		string = newString;
+
+		/* May trigger garbage collection */
+		string = instantiateClassindexableSize(classString(), utf8Len);
+
+		/* Write the UTF8 conversion directly in the Smalltalk String, without terminating NULL */
 		envArray = popRemappableOop();
+		WideCharToMultiByte(OSPP_CP_UTF8(), 0, p, wcslen(p), arrayValueOf(string), utf8Len, null, null);
 		stObjectatput(envArray, count, string);
 		while (*p != 0) {
 			p += 1;
 		}
 		p += 1;
 	}
-	FreeEnvironmentStrings(pVarBlock);
+	FreeEnvironmentStringsW(pVarBlock);
 	popthenPush(1, envArray);
 	return 0;
 }
@@ -2250,10 +2262,10 @@
 /*	Answer the pseudo HANDLE for standard error. */

 	/* Win32OSProcessPlugin>>#stdErrHandle */
-static HANDLE
+static DWORD
 stdErrHandle(void)
 {
-	return (HANDLE) STD_ERROR_HANDLE;
+	return STD_ERROR_HANDLE;
 }

 	/* Win32OSProcessPlugin>>#stderrHandle */
@@ -2273,10 +2285,10 @@
 /*	Answer the pseudo HANDLE for standard input. */

 	/* Win32OSProcessPlugin>>#stdInHandle */
-static HANDLE
+static DWORD
 stdInHandle(void)
 {
-	return (HANDLE) STD_INPUT_HANDLE;
+	return STD_INPUT_HANDLE;
 }

 	/* Win32OSProcessPlugin>>#stdinHandle */
@@ -2296,10 +2308,10 @@
 /*	Answer the pseudo HANDLE for standard output. */

 	/* Win32OSProcessPlugin>>#stdOutHandle */
-static HANDLE
+static DWORD
 stdOutHandle(void)
 {
-	return (HANDLE) STD_OUTPUT_HANDLE;
+	return STD_OUTPUT_HANDLE;
 }

 	/* Win32OSProcessPlugin>>#stdoutHandle */


libxl: Use id from virDomainObj inside the driver

There is a domain id in the virDomain structure as well as in the
virDomainObj structure. While the former can become stale the latter
is kept up to date. So it is safer to always (virDomainObjPtr)->def->id
internally.

This will fix issues seen when managing Xen guests through libvirt from
virt-manager (not being able to get domain info after define or reboot).
This was caused both though libxlDomainGetInfo() only but there were
a lot of places that might potentially cause issues, too.

Signed-off-by: Stefan Bader <00beb3b1b08625be3b68f3989c75be8de7f2fd89@canonical.com>

--- src/libxl/libxl_driver.c
+++ src/libxl/libxl_driver.c
@@ -770,10 +770,10 @@
     priv = vm->privateData;

     if (virDomainObjGetState(vm, NULL) != VIR_DOMAIN_PAUSED) {
-        if (libxl_domain_pause(priv->ctx, dom->id) != 0) {
+        if (libxl_domain_pause(priv->ctx, vm->def->id) != 0) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("Failed to suspend domain '%d' with libxenlight"),
-                           dom->id);
+                           vm->def->id);
             goto endjob;
         }

@@ -829,10 +829,10 @@
     priv = vm->privateData;

     if (virDomainObjGetState(vm, NULL) == VIR_DOMAIN_PAUSED) {
-        if (libxl_domain_unpause(priv->ctx, dom->id) != 0) {
+        if (libxl_domain_unpause(priv->ctx, vm->def->id) != 0) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("Failed to resume domain '%d' with libxenlight"),
-                           dom->id);
+                           vm->def->id);
             goto endjob;
         }

@@ -883,10 +883,10 @@
     }

     priv = vm->privateData;
-    if (libxl_domain_shutdown(priv->ctx, dom->id) != 0) {
+    if (libxl_domain_shutdown(priv->ctx, vm->def->id) != 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("Failed to shutdown domain '%d' with libxenlight"),
-                       dom->id);
+                       vm->def->id);
         goto cleanup;
     }

@@ -930,10 +930,10 @@
     }

     priv = vm->privateData;
-    if (libxl_domain_reboot(priv->ctx, dom->id) != 0) {
+    if (libxl_domain_reboot(priv->ctx, vm->def->id) != 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("Failed to reboot domain '%d' with libxenlight"),
-                       dom->id);
+                       vm->def->id);
         goto cleanup;
     }
     ret = 0;
@@ -974,7 +974,7 @@
     priv = vm->privateData;
     if (libxl_domain_destroy(priv->ctx, vm->def->id, NULL) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("Failed to destroy domain '%d'"), dom->id);
+                       _("Failed to destroy domain '%d'"), vm->def->id);
         goto cleanup;
     }

@@ -1105,10 +1105,10 @@

         if (flags & VIR_DOMAIN_MEM_LIVE) {
             priv = vm->privateData;
-            if (libxl_domain_setmaxmem(priv->ctx, dom->id, newmem) < 0) {
+            if (libxl_domain_setmaxmem(priv->ctx, vm->def->id, newmem) < 0) {
                 virReportError(VIR_ERR_INTERNAL_ERROR,
                                _("Failed to set maximum memory for domain '%d'"
-                                 " with libxenlight"), dom->id);
+                                 " with libxenlight"), vm->def->id);
                 goto endjob;
             }
         }
@@ -1138,13 +1138,13 @@
             priv = vm->privateData;
             /* Unlock virDomainObj while ballooning memory */
             virObjectUnlock(vm);
-            res = libxl_set_memory_target(priv->ctx, dom->id, newmem, 0,
+            res = libxl_set_memory_target(priv->ctx, vm->def->id, newmem, 0,
                                           /* force */ 1);
             virObjectLock(vm);
             if (res < 0) {
                 virReportError(VIR_ERR_INTERNAL_ERROR,
                                _("Failed to set memory for domain '%d'"
-                                 " with libxenlight"), dom->id);
+                                 " with libxenlight"), vm->def->id);
                 goto endjob;
             }
         }
@@ -1202,9 +1202,10 @@
         info->memory = vm->def->mem.cur_balloon;
         info->maxMem = vm->def->mem.max_balloon;
     } else {
-        if (libxl_domain_info(priv->ctx, &d_info, dom->id) != 0) {
+        if (libxl_domain_info(priv->ctx, &d_info, vm->def->id) != 0) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
-                           _("libxl_domain_info failed for domain '%d'"), dom->id);
+                           _("libxl_domain_info failed for domain '%d'"),
+                           vm->def->id);
             goto cleanup;
         }
         info->cpuTime = d_info.cpu_time;
@@ -1483,11 +1484,11 @@

     if (!(flags & VIR_DUMP_LIVE) &&
         virDomainObjGetState(vm, NULL) == VIR_DOMAIN_RUNNING) {
-        if (libxl_domain_pause(priv->ctx, dom->id) != 0) {
+        if (libxl_domain_pause(priv->ctx, vm->def->id) != 0) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("Before dumping core, failed to suspend domain '%d'"
                              " with libxenlight"),
-                           dom->id);
+                           vm->def->id);
             goto endjob;
         }
         virDomainObjSetState(vm, VIR_DOMAIN_PAUSED, VIR_DOMAIN_PAUSED_DUMP);
@@ -1496,20 +1497,20 @@

     /* Unlock virDomainObj while dumping core */
     virObjectUnlock(vm);
-    ret = libxl_domain_core_dump(priv->ctx, dom->id, to, NULL);
+    ret = libxl_domain_core_dump(priv->ctx, vm->def->id, to, NULL);
     virObjectLock(vm);
     if (ret != 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("Failed to dump core of domain '%d' with libxenlight"),
-                       dom->id);
+                       vm->def->id);
         ret = -1;
         goto unpause;
     }

     if (flags & VIR_DUMP_CRASH) {
-        if (libxl_domain_destroy(priv->ctx, dom->id, NULL) < 0) {
+        if (libxl_domain_destroy(priv->ctx, vm->def->id, NULL) < 0) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
-                           _("Failed to destroy domain '%d'"), dom->id);
+                           _("Failed to destroy domain '%d'"), vm->def->id);
             goto unpause;
         }

@@ -1524,10 +1525,10 @@

  unpause:
     if (virDomainObjIsActive(vm) && paused) {
-        if (libxl_domain_unpause(priv->ctx, dom->id) != 0) {
+        if (libxl_domain_unpause(priv->ctx, vm->def->id) != 0) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("After dumping core, failed to resume domain '%d' with"
-                             " libxenlight"), dom->id);
+                             " libxenlight"), vm->def->id);
         } else {
             virDomainObjSetState(vm, VIR_DOMAIN_RUNNING,
                                  VIR_DOMAIN_RUNNING_UNPAUSED);
@@ -1786,19 +1787,19 @@
         break;

     case VIR_DOMAIN_VCPU_LIVE:
-        if (libxl_set_vcpuonline(priv->ctx, dom->id, &map) != 0) {
+        if (libxl_set_vcpuonline(priv->ctx, vm->def->id, &map) != 0) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("Failed to set vcpus for domain '%d'"
-                             " with libxenlight"), dom->id);
+                             " with libxenlight"), vm->def->id);
             goto endjob;
         }
         break;

     case VIR_DOMAIN_VCPU_LIVE | VIR_DOMAIN_VCPU_CONFIG:
-        if (libxl_set_vcpuonline(priv->ctx, dom->id, &map) != 0) {
+        if (libxl_set_vcpuonline(priv->ctx, vm->def->id, &map) != 0) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("Failed to set vcpus for domain '%d'"
-                             " with libxenlight"), dom->id);
+                             " with libxenlight"), vm->def->id);
             goto endjob;
         }
         def->vcpus = nvcpus;
@@ -1934,7 +1935,7 @@
         libxlDomainObjPrivatePtr priv;

         priv = vm->privateData;
-        if (libxl_set_vcpuaffinity(priv->ctx, dom->id, vcpu, &map) != 0) {
+        if (libxl_set_vcpuaffinity(priv->ctx, vm->def->id, vcpu, &map) != 0) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("Failed to pin vcpu '%d' with libxenlight"),
                            vcpu);
@@ -2099,11 +2100,11 @@
     }

     priv = vm->privateData;
-    if ((vcpuinfo = libxl_list_vcpu(priv->ctx, dom->id, &maxcpu,
+    if ((vcpuinfo = libxl_list_vcpu(priv->ctx, vm->def->id, &maxcpu,
                                     &hostcpus)) == NULL) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("Failed to list vcpus for domain '%d' with libxenlight"),
-                       dom->id);
+                       vm->def->id);
         goto cleanup;
     }

@@ -3608,7 +3609,7 @@
     default:
         virReportError(VIR_ERR_INTERNAL_ERROR,
                    _("Failed to get scheduler id for domain '%d'"
-                     " with libxenlight"), dom->id);
+                     " with libxenlight"), vm->def->id);
         goto cleanup;
     }

@@ -3659,10 +3660,10 @@
         goto cleanup;
     }

-    if (libxl_domain_sched_params_get(priv->ctx, dom->id, &sc_info) != 0) {
+    if (libxl_domain_sched_params_get(priv->ctx, vm->def->id, &sc_info) != 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("Failed to get scheduler parameters for domain '%d'"
-                         " with libxenlight"), dom->id);
+                         " with libxenlight"), vm->def->id);
         goto cleanup;
     }

@@ -3740,10 +3741,10 @@
         goto endjob;
     }

-    if (libxl_domain_sched_params_get(priv->ctx, dom->id, &sc_info) != 0) {
+    if (libxl_domain_sched_params_get(priv->ctx, vm->def->id, &sc_info) != 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("Failed to get scheduler parameters for domain '%d'"
-                         " with libxenlight"), dom->id);
+                         " with libxenlight"), vm->def->id);
         goto endjob;
     }

@@ -3756,10 +3757,10 @@
             sc_info.cap = params[i].value.ui;
     }

-    if (libxl_domain_sched_params_set(priv->ctx, dom->id, &sc_info) != 0) {
+    if (libxl_domain_sched_params_set(priv->ctx, vm->def->id, &sc_info) != 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("Failed to set scheduler parameters for domain '%d'"
-                         " with libxenlight"), dom->id);
+                         " with libxenlight"), vm->def->id);
         goto endjob;
     }


Updated doc

Updated doc

--- src/BabylonCpp/include/babylon/gizmos/light_gizmo.h
+++ src/BabylonCpp/include/babylon/gizmos/light_gizmo.h
@@ -53,8 +53,7 @@
 protected:
   /**
    * @brief Override attachedNode because lightgizmo only support attached mesh
-   * It will return the attached mesh (if any) and setting an attached node will log
-   * a warning
+   * It will return the attached mesh (if any) and setting an attached node will log a warning.
    */
   NodePtr& get_attachedNode() override;


libxl: Set current memory value after successful balloon

The libxl driver does not set the new memory value in the active domain def
after a successful balloon. This results in the old memory value in
<currentMemory>. E.g.

virsh dumpxml test | grep currentMemory
  <currentMemory unit='KiB'>20971520</currentMemory>
virsh setmem test 16777216 --live
virsh dumpxml test | grep currentMemory
  <currentMemory unit='KiB'>20971520</currentMemory>

Set the new memory value in active domain def after a successful call to
libxl_set_memory_target().

Signed-off-by: Jim Fehlig <39929b5b86d72d51fceac59b52303e3fe8a3083e@suse.com>
Reviewed-by: Ján Tomko <4cab11cfb98d3c937327354a78eb07dbb6ee2bc6@redhat.com>

--- src/libxl/libxl_driver.c
+++ src/libxl/libxl_driver.c
@@ -1676,6 +1676,7 @@
                                  " with libxenlight"), vm->def->id);
                 goto endjob;
             }
+            vm->def->mem.cur_balloon = newmem;
         }

         if (flags & VIR_DOMAIN_MEM_CONFIG) {


schema REFACTOR avoid code duplication and improve code readability

lysc_node_children_p() and lysc_node_children_full() were wery similar,
refactoring should avoid code duplication and emphasis the differences
between the functions.

Fixes #1352

--- src/tree_schema_helpers.c
+++ src/tree_schema_helpers.c
@@ -1468,7 +1468,7 @@
         return NULL;
     }

-    children = lysc_node_children_p((struct lysc_node *)node, flags);
+    children = lysc_node_children_p(node, flags);
     if (children) {
         return *children;
     } else {
@@ -1479,30 +1479,19 @@
 API const struct lysc_node *
 lysc_node_children_full(const struct lysc_node *node, uint16_t flags)
 {
-    switch (node->nodetype) {
-    case LYS_CONTAINER:
-        return ((struct lysc_node_container *)node)->child;
-    case LYS_CHOICE:
-        return (struct lysc_node *)((struct lysc_node_choice *)node)->cases;
-    case LYS_CASE:
-        return ((struct lysc_node_case *)node)->child;
-    case LYS_LIST:
-        return ((struct lysc_node_list *)node)->child;
-    case LYS_RPC:
-    case LYS_ACTION:
+    if (!node) {
+        return NULL;
+    }
+
+    if (node->nodetype == LYS_RPC || node->nodetype == LYS_ACTION) {
         if (flags & LYS_CONFIG_R) {
             return (struct lysc_node *)&((struct lysc_action *)node)->output;
         } else {
             /* LYS_CONFIG_W, but also the default case */
             return (struct lysc_node *)&((struct lysc_action *)node)->input;
         }
-    case LYS_INPUT:
-    case LYS_OUTPUT:
-        return ((struct lysc_action_inout *)node)->data;
-    case LYS_NOTIF:
-        return ((struct lysc_notif *)node)->data;
-    default:
-        return NULL;
+    } else {
+        return lysc_node_children(node, flags);
     }
 }


Fixed detection of running window managers at startup

--- libAfterStep/wmprops.c
+++ libAfterStep/wmprops.c
@@ -230,8 +230,10 @@
 		XGetWindowAttributes (dpy, wmprops->scr->Root, &attr);

 		old_handler = XSetErrorHandler ((XErrorHandler) catch_redirect_error);
+
 		XSelectInput (dpy, wmprops->scr->Root, attr.your_event_mask | SubstructureRedirectMask);
 		XSync( dpy, False );
+
 		XSetErrorHandler (old_handler);

 		/* lets notify all the clients that we are new selection owner */


libxl: support dom0

libxl: support dom0

In Xen, dom0 is really just another domain that supports ballooning,
adding/removing devices, changing vcpu configuration, etc. This patch
adds support to the libxl driver for managing dom0. Note that the
legacy xend driver has long supported managing dom0.

Operations that are not supported on dom0 are filtered in libvirt
where a sensible error is reported. Errors from libxl are not
always helpful. E.g., attempting a save on dom0 results in

2015-06-23 15:25:05 MDT libxl: debug: libxl_dom.c:1570:libxl__toolstack_save: domain=0 toolstack data size=8
2015-06-23 15:25:05 MDT libxl: debug: libxl.c:979:do_libxl_domain_suspend: ao 0x7f7e68000b70: inprogress: poller=0x7f7e68000930, flags=i
2015-06-23 15:25:05 MDT libxl-save-helper: debug: starting save: Success
2015-06-23 15:25:05 MDT xc: detail: xc_domain_save_suse: starting save of domid 0
2015-06-23 15:25:05 MDT xc: error: Couldn't map live_shinfo (3 = No such process): Internal error
2015-06-23 15:25:05 MDT xc: detail: Save exit of domid 0 with errno=3
2015-06-23 15:25:05 MDT libxl-save-helper: debug: complete r=1: No such process
2015-06-23 15:25:05 MDT libxl: error: libxl_dom.c:1876:libxl__xc_domain_save_done: saving domain: domain did not respond to suspend request: No such process
2015-06-23 15:25:05 MDT libxl: error: libxl_dom.c:2033:remus_teardown_done: Remus: failed to teardown device for guest with domid 0, rc -8

Signed-off-by: Jim Fehlig <39929b5b86d72d51fceac59b52303e3fe8a3083e@suse.com>

--- src/libxl/libxl_driver.c
+++ src/libxl/libxl_driver.c
@@ -79,6 +79,15 @@
 /* Number of Xen scheduler parameters */
 #define XEN_SCHED_CREDIT_NPARAM   2

+#define LIBXL_CHECK_DOM0_GOTO(name, label)                               \
+    do {                                                                  \
+        if (STREQ_NULLABLE(name, "Domain-0")) {                           \
+            virReportError(VIR_ERR_OPERATION_INVALID, "%s",               \
+                           _("Domain-0 does not support requested operation")); \
+            goto label;                                                   \
+        }                                                                 \
+    } while (0)
+

 static libxlDriverPrivatePtr libxl_driver;

@@ -501,6 +510,63 @@
 };

 static int
+libxlAddDom0(libxlDriverPrivatePtr driver)
+{
+    libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
+    virDomainDefPtr def = NULL;
+    virDomainObjPtr vm = NULL;
+    virDomainDefPtr oldDef = NULL;
+    libxl_dominfo d_info;
+    int ret = -1;
+
+    libxl_dominfo_init(&d_info);
+
+    /* Ensure we have a dom0 */
+    if (libxl_domain_info(cfg->ctx, &d_info, 0) != 0) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       "%s", _("unable to get Domain-0 information from libxenlight"));
+        goto cleanup;
+    }
+
+    if (!(def = virDomainDefNew()))
+        goto cleanup;
+
+    def->id = 0;
+    def->virtType = VIR_DOMAIN_VIRT_XEN;
+    if (VIR_STRDUP(def->name, "Domain-0") < 0)
+        goto cleanup;
+
+    def->os.type = VIR_DOMAIN_OSTYPE_XEN;
+
+    if (virUUIDParse("00000000-0000-0000-0000-000000000000", def->uuid) < 0)
+        goto cleanup;
+
+    if (!(vm = virDomainObjListAdd(driver->domains, def,
+                                   driver->xmlopt,
+                                   0,
+                                   &oldDef)))
+        goto cleanup;
+
+    def = NULL;
+
+    vm->def->vcpus = d_info.vcpu_online;
+    vm->def->maxvcpus = d_info.vcpu_max_id + 1;
+    vm->def->mem.cur_balloon = d_info.current_memkb;
+    vm->def->mem.max_balloon = d_info.max_memkb;
+
+    ret = 0;
+
+ cleanup:
+    libxl_dominfo_dispose(&d_info);
+    virDomainDefFree(def);
+    virDomainDefFree(oldDef);
+    if (vm)
+        virObjectUnlock(vm);
+    virObjectUnref(cfg);
+    return ret;
+}
+
+static int
 libxlStateInitialize(bool privileged,
                      virStateInhibitCallback callback ATTRIBUTE_UNUSED,
                      void *opaque ATTRIBUTE_UNUSED)
@@ -614,6 +680,10 @@
     }

     if (!(libxl_driver->xmlopt = libxlCreateXMLConf()))
+        goto error;
+
+    /* Add Domain-0 */
+    if (libxlAddDom0(libxl_driver) < 0)
         goto error;

     /* Load running domains first. */
@@ -1030,6 +1100,8 @@
     if (!(vm = libxlDomObjFromDomain(dom)))
         goto cleanup;

+    LIBXL_CHECK_DOM0_GOTO(vm->def->name, cleanup);
+
     if (virDomainSuspendEnsureACL(dom->conn, vm->def) < 0)
         goto cleanup;

@@ -1086,6 +1158,8 @@
     if (!(vm = libxlDomObjFromDomain(dom)))
         goto cleanup;

+    LIBXL_CHECK_DOM0_GOTO(vm->def->name, cleanup);
+
     if (virDomainResumeEnsureACL(dom->conn, vm->def) < 0)
         goto cleanup;

@@ -1146,6 +1220,8 @@

     if (!(vm = libxlDomObjFromDomain(dom)))
         goto cleanup;
+
+    LIBXL_CHECK_DOM0_GOTO(vm->def->name, cleanup);

     if (virDomainShutdownFlagsEnsureACL(dom->conn, vm->def, flags) < 0)
         goto cleanup;
@@ -1212,6 +1288,8 @@
     if (!(vm = libxlDomObjFromDomain(dom)))
         goto cleanup;

+    LIBXL_CHECK_DOM0_GOTO(vm->def->name, cleanup);
+
     if (virDomainRebootEnsureACL(dom->conn, vm->def, flags) < 0)
         goto cleanup;

@@ -1253,6 +1331,8 @@

     if (!(vm = libxlDomObjFromDomain(dom)))
         goto cleanup;
+
+    LIBXL_CHECK_DOM0_GOTO(vm->def->name, cleanup);

     if (virDomainDestroyFlagsEnsureACL(dom->conn, vm->def) < 0)
         goto cleanup;
@@ -1656,6 +1736,8 @@
     if (!(vm = libxlDomObjFromDomain(dom)))
         goto cleanup;

+    LIBXL_CHECK_DOM0_GOTO(vm->def->name, cleanup);
+
     if (virDomainSaveFlagsEnsureACL(dom->conn, vm->def) < 0)
         goto cleanup;

@@ -1781,6 +1863,8 @@

     if (!(vm = libxlDomObjFromDomain(dom)))
         goto cleanup;
+
+    LIBXL_CHECK_DOM0_GOTO(vm->def->name, cleanup);

     if (virDomainCoreDumpEnsureACL(dom->conn, vm->def) < 0)
         goto cleanup;
@@ -1876,6 +1960,8 @@

     if (!(vm = libxlDomObjFromDomain(dom)))
         goto cleanup;
+
+    LIBXL_CHECK_DOM0_GOTO(vm->def->name, cleanup);

     if (virDomainManagedSaveEnsureACL(dom->conn, vm->def) < 0)
         goto cleanup;
@@ -4000,6 +4086,8 @@
     if (!(vm = libxlDomObjFromDomain(dom)))
         goto cleanup;

+    LIBXL_CHECK_DOM0_GOTO(vm->def->name, cleanup);
+
     if (virDomainSetAutostartEnsureACL(dom->conn, vm->def) < 0)
         goto cleanup;

@@ -4294,6 +4382,8 @@
     if (!(vm = libxlDomObjFromDomain(dom)))
         goto cleanup;

+    LIBXL_CHECK_DOM0_GOTO(vm->def->name, cleanup);
+
     if (virDomainOpenConsoleEnsureACL(dom->conn, vm->def) < 0)
         goto cleanup;

@@ -4816,6 +4906,12 @@

     if (!(vm = libxlDomObjFromDomain(domain)))
         return NULL;
+
+    if (STREQ_NULLABLE(vm->def->name, "Domain-0")) {
+            virReportError(VIR_ERR_OPERATION_INVALID, "%s",
+                           _("Domain-0 cannot be migrated"));
+            return NULL;
+    }

     if (virDomainMigrateBegin3ParamsEnsureACL(domain->conn, vm->def) < 0) {
         virObjectUnlock(vm);


libvorbis: Use 0-10 range for audio quality.
Patch by Nicolas George (nicolas george normalesup org)

git-svn-id: a4d7c1866f8397a4106e0b57fc4fbf792bbdaaaf@17107 9553f0bf-9b14-0410-a0b8-cfaf0461ba5b

--- libavcodec/libvorbis.c
+++ libavcodec/libvorbis.c
@@ -57,7 +57,7 @@
         /* variable bitrate */
         if(vorbis_encode_setup_vbr(vi, avccontext->channels,
                 avccontext->sample_rate,
-                avccontext->global_quality / (float)FF_QP2LAMBDA))
+                avccontext->global_quality / (float)FF_QP2LAMBDA / 10.0))
             return -1;
     } else {
         /* constant bitrate */