how to implement linux_gettid

Georg-W. Koltermann gwk at rahn-koltermann.de
Mon Jul 19 14:47:18 PDT 2004


Hi,

I am trying to get SUNs Linux JRE 1.5 beta2 to work, which currently
fails with unsupported system call #224, which is gettid().  In the
Linux kernel this call returns the pid, which makes sense as their
threading model allocates a proc structure per thread.

I first tried to simply return a unique number for the gettid() call by
returning (int)td.  That seemed to work, although I sometimes got JVM
crashes with negative thread ids.

Interestingly I observed that with the JRE 1.5 I also seem to get one
proc per thread in our Linux emulation on FreeBSD; ps(1) shows multiple
processes for one java invocation.  So my current attempt is to return
td->td_proc->p_pid, which is the pid just as in the Linux kernel.  This
also works, just as fine, for simple cases.

I still get JVM crashes easily when I start a Swing GUI application and
resize the window a couple times.  So I suppose returning the pid is not
really the correct solution.

Could someone explain how our threading works when accessed from Linux,
and maybe give me a hint how gettid() should be implemented correctly?

--
Thanks,
Regards,
Georg.

------------------------------------------

FreeBSD 5.2.1-p5
linux_base-8
linprocfs is mounted


Index: linux_misc.c
===================================================================
RCS file: /usr/ncvs/src/sys/compat/linux/linux_misc.c,v
retrieving revision 1.150
diff -u -r1.150 linux_misc.c
--- linux_misc.c	16 Nov 2003 15:07:10 -0000	1.150
+++ linux_misc.c	14 Jul 2004 18:57:55 -0000
@@ -1328,6 +1328,20 @@
 	return (0);
 }
 
+/*
+ * A trial implementation of linux gettid(2).
+ *
+ * We'll see if it works.  The linux source returns the pid
+ * for this call.
+ */
+int
+linux_gettid(struct thread *td, struct linux_gettid_args *args)
+{
+	/* td->td_retval[0] = (int)td; */
+	td->td_retval[0] = td->td_proc->p_pid;
+	return (0);
+}
+
 int
 linux_getgid(struct thread *td, struct linux_getgid_args *args)
 {




More information about the freebsd-emulation mailing list