< prev index next >

agent/src/os/linux/libproc.h

Print this page




  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef _LIBPROC_H_
  26 #define _LIBPROC_H_
  27 
  28 #include <jni.h>
  29 #include <unistd.h>
  30 #include <stdint.h>
  31 #include "proc_service.h"
  32 
  33 #ifdef ALT_SASRCDIR
  34 #include "libproc_md.h"
  35 #endif
  36 
  37 #include <sys/ptrace.h>
  38 




  39 /************************************************************************************
  40 
  41 0. This is very minimal subset of Solaris libproc just enough for current application.
  42 Please note that the bulk of the functionality is from proc_service interface. This
  43 adds Pgrab__ and some missing stuff. We hide the difference b/w live process and core
  44 file by this interface.
  45 
  46 1. pthread_id unique in both NPTL & LinuxThreads. We store this in
  47 OSThread::_pthread_id in JVM code.
  48 
  49 2. All threads see the same pid when they call getpid() under NPTL.
  50 Threads receive different pid under LinuxThreads. We used to save the result of
  51 ::getpid() call in OSThread::_thread_id. This way uniqueness of OSThread::_thread_id
  52 was lost under NPTL. Now, we store the result of ::gettid() call in
  53 OSThread::_thread_id. Because gettid returns actual pid of thread (lwp id), this is
  54 unique again. We therefore use OSThread::_thread_id as unique identifier.
  55 
  56 3. There is a unique LWP id under both thread libraries. libthread_db  maps pthread_id
  57 to its underlying lwp_id under both the thread libraries. thread_info.lwp_id stores
  58 lwp_id of the thread. The lwp id is nothing but the actual pid of clone'd processes. But
  59 unfortunately libthread_db does not work very well for core dumps. So, we get pthread_id
  60 only for processes. For core dumps, we don't use libthread_db at all (like gdb).
  61 
  62 4. ptrace operates on this LWP id under both the thread libraries. When we say 'pid' for
  63 ptrace call, we refer to lwp_id of the thread.
  64 
  65 5. for core file, we parse ELF files and read data from them. For processes we  use
  66 combination of ptrace and /proc calls.
  67 
  68 *************************************************************************************/
  69 
  70 
  71 #if defined(sparc) || defined(sparcv9) || defined(ppc64)
  72 #include <asm/ptrace.h>
  73 #define user_regs_struct  pt_regs



  74 #endif
  75 
  76 // This C bool type must be int for compatibility with Linux calls and
  77 // it would be a mistake to equivalence it to C++ bool on many platforms
  78 
  79 typedef int bool;
  80 #define true  1
  81 #define false 0
  82 
  83 struct ps_prochandle;
  84 
  85 // attach to a process
  86 struct ps_prochandle* Pgrab(pid_t pid, char* err_buf, size_t err_buf_len);
  87 
  88 // attach to a core dump
  89 struct ps_prochandle* Pgrab_core(const char* execfile, const char* corefile);
  90 
  91 // release a process or core
  92 void Prelease(struct ps_prochandle* ph);
  93 




  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef _LIBPROC_H_
  26 #define _LIBPROC_H_
  27 
  28 #include <jni.h>
  29 #include <unistd.h>
  30 #include <stdint.h>
  31 #include "proc_service.h"
  32 
  33 #ifdef ALT_SASRCDIR
  34 #include "libproc_md.h"
  35 #endif
  36 
  37 #include <sys/ptrace.h>
  38 
  39 #if defined(aarch64)
  40 #include "asm/ptrace.h"
  41 #endif
  42 
  43 /************************************************************************************
  44 
  45 0. This is very minimal subset of Solaris libproc just enough for current application.
  46 Please note that the bulk of the functionality is from proc_service interface. This
  47 adds Pgrab__ and some missing stuff. We hide the difference b/w live process and core
  48 file by this interface.
  49 
  50 1. pthread_id unique in both NPTL & LinuxThreads. We store this in
  51 OSThread::_pthread_id in JVM code.
  52 
  53 2. All threads see the same pid when they call getpid() under NPTL.
  54 Threads receive different pid under LinuxThreads. We used to save the result of
  55 ::getpid() call in OSThread::_thread_id. This way uniqueness of OSThread::_thread_id
  56 was lost under NPTL. Now, we store the result of ::gettid() call in
  57 OSThread::_thread_id. Because gettid returns actual pid of thread (lwp id), this is
  58 unique again. We therefore use OSThread::_thread_id as unique identifier.
  59 
  60 3. There is a unique LWP id under both thread libraries. libthread_db  maps pthread_id
  61 to its underlying lwp_id under both the thread libraries. thread_info.lwp_id stores
  62 lwp_id of the thread. The lwp id is nothing but the actual pid of clone'd processes. But
  63 unfortunately libthread_db does not work very well for core dumps. So, we get pthread_id
  64 only for processes. For core dumps, we don't use libthread_db at all (like gdb).
  65 
  66 4. ptrace operates on this LWP id under both the thread libraries. When we say 'pid' for
  67 ptrace call, we refer to lwp_id of the thread.
  68 
  69 5. for core file, we parse ELF files and read data from them. For processes we  use
  70 combination of ptrace and /proc calls.
  71 
  72 *************************************************************************************/
  73 
  74 
  75 #if defined(sparc) || defined(sparcv9) || defined(ppc64)
  76 #include <asm/ptrace.h>
  77 #define user_regs_struct  pt_regs
  78 #endif
  79 #if defined(aarch64)
  80 #define user_regs_struct user_pt_regs
  81 #endif
  82 
  83 // This C bool type must be int for compatibility with Linux calls and
  84 // it would be a mistake to equivalence it to C++ bool on many platforms
  85 
  86 typedef int bool;
  87 #define true  1
  88 #define false 0
  89 
  90 struct ps_prochandle;
  91 
  92 // attach to a process
  93 struct ps_prochandle* Pgrab(pid_t pid, char* err_buf, size_t err_buf_len);
  94 
  95 // attach to a core dump
  96 struct ps_prochandle* Pgrab_core(const char* execfile, const char* corefile);
  97 
  98 // release a process or core
  99 void Prelease(struct ps_prochandle* ph);
 100 


< prev index next >