Blame SOURCES/strace-rhbz1610774-0002-Add-a-generic-list-implementation.patch

6cf6ff
From a5855e84f17181167754caa26280161cd786a386 Mon Sep 17 00:00:00 2001
6cf6ff
From: Eugene Syromyatnikov <evgsyr@gmail.com>
6cf6ff
Date: Sun, 11 Sep 2016 12:11:45 +0300
6cf6ff
Subject: [PATCH 2/3] Add a generic list implementation
6cf6ff
6cf6ff
Similar to one used in the Linux kernel.
6cf6ff
6cf6ff
* macros.h (cast_ptr, containerof): New macros.
6cf6ff
* list.h: New file.
6cf6ff
* Makefile.am (strace_SOURCES): Add it.
6cf6ff
---
6cf6ff
 Makefile.am |   1 +
6cf6ff
 list.h      | 137 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
6cf6ff
 macros.h    |   9 ++++
6cf6ff
 3 files changed, 147 insertions(+)
6cf6ff
 create mode 100644 list.h
6cf6ff
6cf6ff
Index: strace-4.24/Makefile.am
6cf6ff
===================================================================
6cf6ff
--- strace-4.24.orig/Makefile.am	2018-09-13 00:07:30.798555060 +0200
6cf6ff
+++ strace-4.24/Makefile.am	2018-09-13 00:42:10.058675213 +0200
6cf6ff
@@ -185,6 +185,7 @@
6cf6ff
 	linux/asm_stat.h \
6cf6ff
 	linux/x32/asm_stat.h \
6cf6ff
 	linux/x86_64/asm_stat.h \
6cf6ff
+	list.h		\
6cf6ff
 	listen.c	\
6cf6ff
 	lookup_dcookie.c \
6cf6ff
 	loop.c		\
6cf6ff
Index: strace-4.24/list.h
6cf6ff
===================================================================
6cf6ff
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
6cf6ff
+++ strace-4.24/list.h	2018-09-13 00:42:10.059675201 +0200
6cf6ff
@@ -0,0 +1,137 @@
6cf6ff
+/*
6cf6ff
+ * Some simple implementation of a list similar to one used in the kernel.
6cf6ff
+ *
6cf6ff
+ * Copyright (c) 2016-2018 The strace developers.
6cf6ff
+ * All rights reserved.
6cf6ff
+ *
6cf6ff
+ * Redistribution and use in source and binary forms, with or without
6cf6ff
+ * modification, are permitted provided that the following conditions
6cf6ff
+ * are met:
6cf6ff
+ * 1. Redistributions of source code must retain the above copyright
6cf6ff
+ *    notice, this list of conditions and the following disclaimer.
6cf6ff
+ * 2. Redistributions in binary form must reproduce the above copyright
6cf6ff
+ *    notice, this list of conditions and the following disclaimer in the
6cf6ff
+ *    documentation and/or other materials provided with the distribution.
6cf6ff
+ * 3. The name of the author may not be used to endorse or promote products
6cf6ff
+ *    derived from this software without specific prior written permission.
6cf6ff
+ *
6cf6ff
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
6cf6ff
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
6cf6ff
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
6cf6ff
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
6cf6ff
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
6cf6ff
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
6cf6ff
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
6cf6ff
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
6cf6ff
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
6cf6ff
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
6cf6ff
+ */
6cf6ff
+
6cf6ff
+#ifndef STRACE_LIST_H
6cf6ff
+#define STRACE_LIST_H
6cf6ff
+
6cf6ff
+#include "macros.h"
6cf6ff
+
6cf6ff
+struct list_item {
6cf6ff
+	struct list_item *prev;
6cf6ff
+	struct list_item *next;
6cf6ff
+};
6cf6ff
+
6cf6ff
+#define EMPTY_LIST(l_) struct list_item l_ = { &l_, &l_ }
6cf6ff
+
6cf6ff
+static inline void
6cf6ff
+list_init(struct list_item *l)
6cf6ff
+{
6cf6ff
+	l->prev = l;
6cf6ff
+	l->next = l;
6cf6ff
+}
6cf6ff
+
6cf6ff
+static inline bool
6cf6ff
+list_is_empty(struct list_item *l)
6cf6ff
+{
6cf6ff
+	return (l->next == l) && (l->prev == l);
6cf6ff
+}
6cf6ff
+
6cf6ff
+#define list_elem(var, type, field) containerof((var), type, field)
6cf6ff
+
6cf6ff
+#define list_head(head, type, field) \
6cf6ff
+	(list_is_empty(head) ? NULL : list_elem((head)->next, type, field))
6cf6ff
+#define list_tail(head, type, field) \
6cf6ff
+	(list_is_empty(head) ? NULL : list_elem((head)->prev, type, field))
6cf6ff
+
6cf6ff
+#define list_next(val, field) \
6cf6ff
+	list_elem((val)->field.next, typeof(*(val)), field)
6cf6ff
+#define list_prev(val, field) \
6cf6ff
+	list_elem((val)->field.prev, typeof(*(val)), field)
6cf6ff
+
6cf6ff
+static inline void
6cf6ff
+list_insert(struct list_item *head, struct list_item *item)
6cf6ff
+{
6cf6ff
+	item->next = head->next;
6cf6ff
+	item->prev = head;
6cf6ff
+	head->next->prev = item;
6cf6ff
+	head->next = item;
6cf6ff
+}
6cf6ff
+
6cf6ff
+static inline void
6cf6ff
+list_append(struct list_item *head, struct list_item *item)
6cf6ff
+{
6cf6ff
+	item->next = head;
6cf6ff
+	item->prev = head->prev;
6cf6ff
+	head->prev->next = item;
6cf6ff
+	head->prev = item;
6cf6ff
+}
6cf6ff
+
6cf6ff
+static inline void
6cf6ff
+list_remove(struct list_item *item)
6cf6ff
+{
6cf6ff
+	if (!item->next || !item->prev)
6cf6ff
+		return;
6cf6ff
+
6cf6ff
+	item->prev->next = item->next;
6cf6ff
+	item->next->prev = item->prev;
6cf6ff
+	item->next = item->prev = NULL;
6cf6ff
+}
6cf6ff
+
6cf6ff
+static inline struct list_item *
6cf6ff
+list_remove_tail(struct list_item *head)
6cf6ff
+{
6cf6ff
+	struct list_item *t = list_is_empty(head) ? NULL : head->prev;
6cf6ff
+
6cf6ff
+	if (t)
6cf6ff
+		list_remove(t);
6cf6ff
+
6cf6ff
+	return t;
6cf6ff
+}
6cf6ff
+
6cf6ff
+static inline struct list_item *
6cf6ff
+list_remove_head(struct list_item *head)
6cf6ff
+{
6cf6ff
+	struct list_item *h = list_is_empty(head) ? NULL : head->next;
6cf6ff
+
6cf6ff
+	if (h)
6cf6ff
+		list_remove(h);
6cf6ff
+
6cf6ff
+	return h;
6cf6ff
+}
6cf6ff
+
6cf6ff
+static inline void
6cf6ff
+list_replace(struct list_item *old, struct list_item *new)
6cf6ff
+{
6cf6ff
+	new->next = old->next;
6cf6ff
+	new->prev = old->prev;
6cf6ff
+	old->prev->next = new;
6cf6ff
+	old->next->prev = new;
6cf6ff
+	old->next = old->prev = NULL;
6cf6ff
+}
6cf6ff
+
6cf6ff
+#define list_foreach(var_, head_, field_) \
6cf6ff
+	for (var_ = list_elem((head_)->next, typeof(*var_), field_); \
6cf6ff
+	    &(var_->field_) != (head_); var_ = list_next(var_, field_))
6cf6ff
+
6cf6ff
+#define list_foreach_safe(var_, head_, field_, _tmp) \
6cf6ff
+	for (var_ = list_elem((head_)->next, typeof(*var_), field_), \
6cf6ff
+	    _tmp = list_elem((var_)->field_.next, typeof(*var_), field_); \
6cf6ff
+	    &var_->field_ != head_; var_ = _tmp, _tmp = list_next(_tmp, field_))
6cf6ff
+
6cf6ff
+#endif /* !STRACE_LIST_H */
6cf6ff
Index: strace-4.24/macros.h
6cf6ff
===================================================================
6cf6ff
--- strace-4.24.orig/macros.h	2018-09-13 00:07:30.798555060 +0200
6cf6ff
+++ strace-4.24/macros.h	2018-09-13 00:42:10.059675201 +0200
6cf6ff
@@ -53,6 +53,15 @@
6cf6ff
 	(offsetof(type_, member_) + sizeof(((type_ *)0)->member_))
6cf6ff
 #endif
6cf6ff
 
6cf6ff
+#ifndef cast_ptr
6cf6ff
+# define cast_ptr(type, var) ((type) (uintptr_t) (const volatile void *) (var))
6cf6ff
+#endif
6cf6ff
+
6cf6ff
+#ifndef containerof
6cf6ff
+# define containerof(x, s, m)	\
6cf6ff
+	cast_ptr(s *, (const volatile char *) (x) - offsetof(s, m))
6cf6ff
+#endif
6cf6ff
+
6cf6ff
 static inline bool
6cf6ff
 is_filled(const char *ptr, char fill, size_t size)
6cf6ff
 {
6cf6ff
Index: strace-4.24/Makefile.in
6cf6ff
===================================================================
6cf6ff
--- strace-4.24.orig/Makefile.in	2018-08-14 02:44:37.000000000 +0200
6cf6ff
+++ strace-4.24/Makefile.in	2018-09-13 00:45:21.266213460 +0200
6cf6ff
@@ -340,7 +340,7 @@
6cf6ff
 	ipc_sem.c ipc_shm.c ipc_shmctl.c kcmp.c kernel_types.h kexec.c \
6cf6ff
 	keyctl.c keyctl_kdf_params.h kvm.c largefile_wrappers.h ldt.c \
6cf6ff
 	link.c linux/asm_stat.h linux/x32/asm_stat.h \
6cf6ff
-	linux/x86_64/asm_stat.h listen.c lookup_dcookie.c loop.c \
6cf6ff
+	linux/x86_64/asm_stat.h list.h listen.c lookup_dcookie.c loop.c \
6cf6ff
 	lseek.c macros.h mem.c membarrier.c memfd_create.c mknod.c \
6cf6ff
 	mmap_notify.c mmap_notify.h mmsghdr.c mount.c mpers_type.h \
6cf6ff
 	mq.c msghdr.c msghdr.h mtd.c native_defs.h negated_errno.h \
6cf6ff
@@ -1357,7 +1357,7 @@
6cf6ff
 	ipc_shmctl.c kcmp.c kernel_types.h kexec.c keyctl.c \
6cf6ff
 	keyctl_kdf_params.h kvm.c largefile_wrappers.h ldt.c link.c \
6cf6ff
 	linux/asm_stat.h linux/x32/asm_stat.h linux/x86_64/asm_stat.h \
6cf6ff
-	listen.c lookup_dcookie.c loop.c lseek.c macros.h mem.c \
6cf6ff
+	list.h listen.c lookup_dcookie.c loop.c lseek.c macros.h mem.c \
6cf6ff
 	membarrier.c memfd_create.c mknod.c mmap_notify.c \
6cf6ff
 	mmap_notify.h mmsghdr.c mount.c mpers_type.h mq.c msghdr.c \
6cf6ff
 	msghdr.h mtd.c native_defs.h negated_errno.h net.c netlink.c \