Add a helper for finding current_uthread's context
authorBarret Rhoden <brho@cs.berkeley.edu>
Thu, 8 Sep 2016 15:47:03 +0000 (11:47 -0400)
committerBarret Rhoden <brho@cs.berkeley.edu>
Fri, 16 Sep 2016 18:35:09 +0000 (14:35 -0400)
It's a very easy bug to look into current_uthread to see its context, but
you might be looking at an old context.  Use this helper to find the
correct user context for current_uthread.

Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
user/parlib/include/parlib/uthread.h

index f0b2b07..baff2b1 100644 (file)
@@ -122,6 +122,16 @@ static inline void init_uthread_ctx(struct uthread *uth, void (*entry)(void),
        init_user_ctx(&uth->u_ctx, (long)entry, (long)(stack_bottom) + size);
 }
 
+/* When we look at the current_uthread, its context might be in the uthread
+ * struct or it might be in VCPD.  This returns a pointer to the right place. */
+static inline struct user_context *get_cur_uth_ctx(void)
+{
+       if (current_uthread->flags & UTHREAD_SAVED)
+               return &current_uthread->u_ctx;
+       else
+               return &vcpd_of(vcore_id())->uthread_ctx;
+}
+
 #define uthread_set_tls_var(uth, name, val)                                    \
 ({                                                                             \
        typeof(val) __val = val;                                                   \