This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug nptl/10311] New: clone(CLONE_VM) fails with pthread_getattr_np on i386


I'm using clone() with flags CLONE_VM, but not CLONE_THREAD.
(background: I'm trying to solve the ancient overcommit failure
when spawning a small Unix process from a big process).

The act of calling clone appears to mess up the pthread library,
but only on i386, not on x86_64, using glibc version 2.7
(The bugzilla Version drop-down does not allow one to specify 2.7;
y'all should fix that)

Here's a shell transcript containing a program 
that demonstrates the problem, and shows that
the problem does not occur when running in 64-bit mode
on 64-bit Linux.  (The problem also occurs when running in 32-bit mode
on 32-bit Linux).

A program like this would be a fine addition to the glibc test suite.

$ set -x; for flag in -m32 -m64; do gcc $flag -lpthread ./clone_bug.c &&
./a.out; done; cat clone_bug.c; uname -a; getconf GNU_LIBPTHREAD_VERSION;
getconf GNU_LIBC_VERSION
+zsh:1464> set -x
+zsh:1464> flag=-m32
+zsh:1464> gcc -m32 -lpthread ./clone_bug.c
+zsh:1464> ./a.out
count=2, pthread_getattr_np failed with errno = "No such process"
+zsh:1464> flag=-m64
+zsh:1464> gcc -m64 -lpthread ./clone_bug.c
+zsh:1464> ./a.out
+zsh:1464> cat clone_bug.c
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stddef.h>
#include <sys/types.h>
#include <wait.h>
#include <errno.h>
#include <unistd.h>
#include <pthread.h>
#include <syscall.h>
#include <sched.h>

static void
debugPrint(char *format, ...) {
  FILE *tty = fopen("/dev/tty", "w");
  va_list ap;
  va_start(ap, format);
  vfprintf(tty, format, ap);
  va_end(ap);
  fclose(tty);
}

static void debugPids(void) {
//   debugPrint("getpid()=%d gettid()=%d, syscall(getpid)=%d pthread_self=%d\n",
//              getpid(), syscall(SYS_gettid), syscall(SYS_getpid), pthread_self());
  static int count = 0;
  pthread_attr_t attr;
  int result;
  ++count;
  if ((result = pthread_getattr_np(pthread_self(), &attr)) != 0)
    debugPrint("count=%d, pthread_getattr_np failed with errno = \"%s\"\n",
               count, strerror(result));
}

static int childProcess(void *ignored) {
  _exit(0);
  // debugPrint("child\n");
  // execve("/bin/true", NULL, NULL);
  // perror("execve");
}

// I'm sure there's a better way to do this,
// but pthread_join ain't it - we can't trust it.
volatile int done = 0;

void* run(void *x) {
  const int stack_size = 1024 * 1024;
  void *clone_stack = malloc(2 * stack_size);
  int status;
  debugPids();
  int pid = clone(childProcess, clone_stack + stack_size,
                  CLONE_VM | SIGCHLD, NULL);
  waitpid(pid, &status, 0);
  debugPids();
  done = 1;
  pthread_exit(0);
  return NULL;
}

int main(int argc, char *argv[]) {
  pthread_attr_t attr;
  pthread_t tid;

  pthread_attr_init(&attr);
  pthread_create(&tid, &attr, (void* (*)(void*)) run, NULL);
  // pthread_join(tid, NULL);
  while (! done)
    ;
}
+zsh:1464> uname -a
Linux spraggett.mtv.corp.google.com 2.6.24-gg23-generic #1 SMP Fri Jan 30
14:07:49 PST 2009 x86_64 GNU/Linux
+zsh:1464> getconf GNU_LIBPTHREAD_VERSION
NPTL 2.7
+zsh:1464> getconf GNU_LIBC_VERSION
glibc 2.7

-- 
           Summary: clone(CLONE_VM) fails with pthread_getattr_np on i386
           Product: glibc
           Version: 2.8
            Status: NEW
          Severity: normal
          Priority: P2
         Component: nptl
        AssignedTo: drepper at redhat dot com
        ReportedBy: martinrb at google dot com
                CC: glibc-bugs at sources dot redhat dot com
  GCC host triplet: x86_64-unknown-linux-gnu


http://sourceware.org/bugzilla/show_bug.cgi?id=10311

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]