From 4e3be6b146f9bc420a7df9e64d6c6d8979304384 Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Sat, 25 Feb 2012 14:35:37 +0100 Subject: [PATCH] Pistachio: make sure to generate global thread IDs The kernel distinguishes local from global IDs by looking at the lowest 6 bits of the thread ID (i.e., in 'L4_ThreadControl'). If those bits are zero, the ID is interpreted as a local ID. Because those zero bits overlap with the version bits of global IDs, this invariant could be violated once the version of a global ID reaches 64. In this case, 'L4_ThreadControl' will return an error on the attempt to create a new PD. To prevent this from happening, we always set the lowest bit to 1. --- base-pistachio/src/core/include/platform_pd.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/base-pistachio/src/core/include/platform_pd.h b/base-pistachio/src/core/include/platform_pd.h index 36be4cb9b..6f492e8fb 100644 --- a/base-pistachio/src/core/include/platform_pd.h +++ b/base-pistachio/src/core/include/platform_pd.h @@ -36,7 +36,7 @@ namespace Genode { enum { PD_BITS = 9, THREAD_BITS = 9, - VERSION_BITS = 14, + VERSION_BITS = 14 - 1, /* preserve 1 bit, see 'make_l4_id' */ PD_FIRST = 0, PD_MAX = (1 << PD_BITS) - 1, THREAD_MAX = (1 << THREAD_BITS) - 1, @@ -56,7 +56,15 @@ namespace Genode { unsigned thread_no, unsigned version) { - return Pistachio::L4_GlobalId((pd_no << PD_BITS) | thread_no, version); + /* + * We have to make sure that the 6 lower version bits are + * never zero. Otherwise, the kernel won't recognize the + * thread ID as a global ID (i.e., 'L4_ThreadControl' would + * fail during the creation of a new PD). To maintain this + * invariant, we always set the lowest version bit to one. + */ + return Pistachio::L4_GlobalId((pd_no << PD_BITS) | thread_no, + (version << 1) | 1); }