< prev index next >

src/jdk.hotspot.agent/linux/native/libsaproc/libproc.h

Print this page


   1 /*
   2  * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  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 #include <sys/ptrace.h>
  34 
  35 /************************************************************************************
  36 
  37 0. This is very minimal subset of Solaris libproc just enough for current application.
  38 Please note that the bulk of the functionality is from proc_service interface. This
  39 adds Pgrab__ and some missing stuff. We hide the difference b/w live process and core
  40 file by this interface.
  41 
  42 1. pthread_id unique in both NPTL & LinuxThreads. We store this in
  43 OSThread::_pthread_id in JVM code.
  44 
  45 2. All threads see the same pid when they call getpid() under NPTL.
  46 Threads receive different pid under LinuxThreads. We used to save the result of
  47 ::getpid() call in OSThread::_thread_id. This way uniqueness of OSThread::_thread_id
  48 was lost under NPTL. Now, we store the result of ::gettid() call in
  49 OSThread::_thread_id. Because gettid returns actual pid of thread (lwp id), this is
  50 unique again. We therefore use OSThread::_thread_id as unique identifier.
  51 
  52 3. There is a unique LWP id under both thread libraries. libthread_db  maps pthread_id
  53 to its underlying lwp_id under both the thread libraries. thread_info.lwp_id stores
  54 lwp_id of the thread. The lwp id is nothing but the actual pid of clone'd processes. But
  55 unfortunately libthread_db does not work very well for core dumps. So, we get pthread_id
  56 only for processes. For core dumps, we don't use libthread_db at all (like gdb).
  57 
  58 4. ptrace operates on this LWP id under both the thread libraries. When we say 'pid' for
  59 ptrace call, we refer to lwp_id of the thread.
  60 
  61 5. for core file, we parse ELF files and read data from them. For processes we  use
  62 combination of ptrace and /proc calls.
  63 
  64 *************************************************************************************/
  65 
  66 
  67 #if defined(sparc) || defined(sparcv9) || defined(ppc64) || defined(ppc64le)
  68 #include <asm/ptrace.h>
  69 #define user_regs_struct  pt_regs
  70 #endif
  71 #if defined(aarch64) || defined(arm64)
  72 #include <asm/ptrace.h>
  73 #define user_regs_struct user_pt_regs
  74 #elif defined(arm)
  75 #include <asm/ptrace.h>
  76 #define user_regs_struct  pt_regs
  77 #endif
  78 
  79 // This C bool type must be int for compatibility with Linux calls and
  80 // it would be a mistake to equivalence it to C++ bool on many platforms
  81 
  82 typedef int bool;
  83 #define true  1
  84 #define false 0
  85 
  86 struct ps_prochandle;
  87 
  88 // attach to a process
  89 JNIEXPORT struct ps_prochandle* JNICALL
  90 Pgrab(pid_t pid, char* err_buf, size_t err_buf_len, bool is_in_container);
  91 
  92 // attach to a core dump
  93 JNIEXPORT struct ps_prochandle* JNICALL
  94 Pgrab_core(const char* execfile, const char* corefile);
  95 
  96 // release a process or core
  97 JNIEXPORT void JNICALL
  98 Prelease(struct ps_prochandle* ph);
  99 
 100 // functions not directly available in Solaris libproc
 101 
 102 // initialize libproc (call this only once per app)
 103 // pass true to make library verbose
 104 JNIEXPORT bool JNICALL
 105 init_libproc(bool verbose);
 106 
 107 // get number of threads
 108 int get_num_threads(struct ps_prochandle* ph);
 109 
 110 // get lwp_id of n'th thread


   1 /*
   2  * Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  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 
  32 #include <sys/procfs.h>
  33 #include <sys/ptrace.h>
  34 































  35 
  36 #if defined(sparc) || defined(sparcv9) || defined(ppc64) || defined(ppc64le)
  37 #include <asm/ptrace.h>
  38 #define user_regs_struct  pt_regs
  39 #endif
  40 #if defined(aarch64) || defined(arm64)
  41 #include <asm/ptrace.h>
  42 #define user_regs_struct user_pt_regs
  43 #elif defined(arm)
  44 #include <asm/ptrace.h>
  45 #define user_regs_struct  pt_regs
  46 #endif
  47 
  48 // This C bool type must be int for compatibility with Linux calls and
  49 // it would be a mistake to equivalence it to C++ bool on many platforms
  50 
  51 typedef int bool;
  52 #define true  1
  53 #define false 0
  54 
  55 struct ps_prochandle;
  56 
  57 // attach to a process
  58 JNIEXPORT struct ps_prochandle* JNICALL
  59 Pgrab(pid_t pid, char* err_buf, size_t err_buf_len);
  60 
  61 // attach to a core dump
  62 JNIEXPORT struct ps_prochandle* JNICALL
  63 Pgrab_core(const char* execfile, const char* corefile);
  64 
  65 // release a process or core
  66 JNIEXPORT void JNICALL
  67 Prelease(struct ps_prochandle* ph);
  68 
  69 // functions not directly available in Solaris libproc
  70 
  71 // initialize libproc (call this only once per app)
  72 // pass true to make library verbose
  73 JNIEXPORT bool JNICALL
  74 init_libproc(bool verbose);
  75 
  76 // get number of threads
  77 int get_num_threads(struct ps_prochandle* ph);
  78 
  79 // get lwp_id of n'th thread


< prev index next >