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 #define user_regs_struct pt_regs
73 #endif
74 #if defined(aarch64)
75 #define user_regs_struct user_pt_regs
76 #endif
77
78 // This C bool type must be int for compatibility with Linux calls and
79 // it would be a mistake to equivalence it to C++ bool on many platforms
80
81 typedef int bool;
82 #define true 1
83 #define false 0
84
85 struct ps_prochandle;
|
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. For historical reasons there are both pthread id (stored in OSThread::_pthread_id)
47 and kernel thread id (gettid() syscall, stored in OSThread::_thread_id) kept in OSThread.
48 Both are unique. We use OSThread::_thread_id as unique identifier.
49
50 2. There is a unique LWP id under both thread libraries. libthread_db maps pthread_id
51 to its underlying lwp_id under both the thread libraries. thread_info.lwp_id stores
52 lwp_id of the thread. The lwp id is nothing but the actual pid of clone'd processes. But
53 unfortunately libthread_db does not work very well for core dumps. So, we get pthread_id
54 only for processes. For core dumps, we don't use libthread_db at all (like gdb).
55
56 3. ptrace operates on this LWP id under both the thread libraries. When we say 'pid' for
57 ptrace call, we refer to lwp_id of the thread.
58
59 4. for core file, we parse ELF files and read data from them. For processes we use
60 combination of ptrace and /proc calls.
61
62 *************************************************************************************/
63
64
65 #if defined(sparc) || defined(sparcv9) || defined(ppc64)
66 #define user_regs_struct pt_regs
67 #endif
68 #if defined(aarch64)
69 #define user_regs_struct user_pt_regs
70 #endif
71
72 // This C bool type must be int for compatibility with Linux calls and
73 // it would be a mistake to equivalence it to C++ bool on many platforms
74
75 typedef int bool;
76 #define true 1
77 #define false 0
78
79 struct ps_prochandle;
|