[CentOS] Problem with gettid() on CentOS 5/gcc 4.1.1

Wed Apr 4 14:10:50 UTC 2007
Alfred von Campe <alfred at 110.net>

On Apr 4, 2007, at 3:49, Luciano Miguel Ferreira Rocha wrote:

> _syscall* is deprecated, syscall(2) is the real thing now.

Yes, I saw that.  But I don't think this is documented well enough.

> My man gettid:
>        _syscall0(pid_t, gettid)
>                /* Using syscall(2) may be preferable; see intro(2) */
>
> So they do reference syscall(2).

The intro(2) man page talks mostly about the _syscall macros.  Near  
the end of the man page, in the NOTES section, we find the following  
paragraphs:

   The preferred way to invoke system calls that glibc does not know
   about yet is via syscall(2).  However, this mechanism can only be
   used if using a libc (such as glibc) that supports syscall(2), and
   if the <sys/syscall.h> header file contains the required SYS_foo
   definition.  Otherwise, the use of a _syscall macro is required.

   Some architectures, notably ia64, do not provide the _syscall
   macros.  On these architectures, syscall(2) must be used.

So it boils down to this:  On CentOS 4, to use gettid() you do this:

   _syscall0(pid_t, gettid)
   mytid = gettid()

and on CentOS 5, you have to do this:

   pid_t gettid(void)
   {
       return syscall(__NR_gettid);
   }
   mytid = gettid();

or this:

   mytid = (pid_t)syscall(__NR_gettid);

My only gripe is that the gettid man page should not refer to  
_sycall0 at all since it is not defined and just show the syscall()  
syntax directly.  I realize this is not a CentOS issue, but rather an  
upstream issue.  I still think they dropped the ball on this one, and  
if I had a support contract I would file a bug.

Alfred