Module Name:    src
Committed By:   riastradh
Date:           Sun Feb 27 14:18:34 UTC 2022

Modified Files:
        src/sys/external/bsd/drm2/include/linux: rbtree.h

Log Message:
linux: New rb_move(&to, &from) to replace `to = from'.

NetBSD rbtree(3) is not relocatable, so this extra step is needed.
Unfortunately, there's no easy way to automate detection of where we
need to apply this in ported code...


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/sys/external/bsd/drm2/include/linux/rbtree.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/external/bsd/drm2/include/linux/rbtree.h
diff -u src/sys/external/bsd/drm2/include/linux/rbtree.h:1.17 src/sys/external/bsd/drm2/include/linux/rbtree.h:1.18
--- src/sys/external/bsd/drm2/include/linux/rbtree.h:1.17	Sun Feb 27 14:18:25 2022
+++ src/sys/external/bsd/drm2/include/linux/rbtree.h	Sun Feb 27 14:18:34 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: rbtree.h,v 1.17 2022/02/27 14:18:25 riastradh Exp $	*/
+/*	$NetBSD: rbtree.h,v 1.18 2022/02/27 14:18:34 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -203,6 +203,27 @@ rb_next2_postorder(const struct rb_root 
 	}
 }
 
+/*
+ * Extension to Linux API, which allows copying a struct rb_root object
+ * with `=' or `memcpy' and no additional relocation.
+ */
+static inline void
+rb_move(struct rb_root *to, struct rb_root *from)
+{
+	struct rb_node *root;
+
+	*to = *from;
+	memset(from, 0, sizeof(*from)); /* paranoia */
+	if ((root = to->rbr_tree.rbt_root) == NULL)
+		return;
+
+	/*
+	 * The root node's `parent' is a strict-aliasing-unsafe hack
+	 * pointing at the root of the tree.
+	 */
+	RB_SET_FATHER(root, (struct rb_node *)(void *)&to->rbr_tree.rbt_root);
+}
+
 #define	rbtree_postorder_for_each_entry_safe(ENTRY, TMP, ROOT, FIELD)	      \
 	for ((ENTRY) = rb_entry_safe(rb_first_postorder(ROOT),		      \
 		    __typeof__(*(ENTRY)), FIELD);			      \

Reply via email to