On Wed, 18 Jun 2025 16:40:53 GMT, Sergey Chernyshev <[email protected]> 
wrote:

>> Hi all,
>> 
>> I would like to propose a fix for JDK-8319589. This will allow jcmd and jps 
>> running as root to get the complete list of JVMs running by all users, and 
>> to attach from root to non-root JVMs. Previously, JDK-8197387 introduced the 
>> same approach on Linux.
>> 
>> This change affects macOS, that uses "secure" per-user temporary 
>> directories. It only affects JVMs running as root, the behavior in 
>> non-privileged JVMs remains unchanged.
>> 
>> Jcmd and jps rely on LocalVmManager to get the initial list of the local 
>> VMs. The LocalVmManager uses sun.jvmstat.PlatformSupport to get the list of 
>> temp directories, where it searches for user's PerfData directory such as 
>> "hsperfdata_<username\>". In macosx the temp directories are per-user, the 
>> temp path is returned by confstr(_CS_DARWIN_USER_TEMP_DIR). The per-user 
>> directories are mode 700 and so they are read-protected from non-privileged 
>> users and can be accessed by the owner and the root.
>> 
>> Both jps and jcmd (HotSpotAttachProvider) create MonitoredVm objects, that 
>> have PerfDataBuffer that performs attachment to the target. Only the 
>> attachable VMs are listed in jcmd output.
>> 
>> The proposed patch changes the list of directories returned by the 
>> PlatformSupport#getTemporaryDirectories() in VMs running as root. The list 
>> is later used in VirtualMachineImpl (jdk.attach). It changes also the way 
>> mmap_attach_shared() searches for hsperfdata_<username\>/<pid\> files to map 
>> the shared memory. Mmap_attach_shared() and VirtualMachineImpl (via 
>> PlatformSupport) list the content of /var/folders, where the temp 
>> directories are located, more specificly the temp directories are 
>> /var/folders/<BUCKET\>/<ENCODED_UUID_UID\>/T as hinted in [1]. The full list 
>> is returned by newly added PlatformSupportImpl#getTemporaryDirectories().
>> 
>> The attaching client's VirtualMachineImpl needs the target process's temp 
>> directory to find .java<pid\> and create .attach<pid\> files. It uses the 
>> list returned by PlatformSupportImpl#getTemporaryDirectories() and the 
>> ProcessHandle of the target process to search for user's PerfData directory, 
>> e.g. hsperfdata_<username\>, which is in the target process's temp 
>> directory, exactly where it expects to see the .java<pid\> in return on 
>> sending SIGQUIT to the target VM.
>> 
>> Mmap_attach_shared() traverses the /var/folders in get_user_tmp_dir() and 
>> looks for a hsperfdata_<username\> folder. If that folder is found in 
>> /var/folders/*/*/T, that means the temp folder corresponds to the 
>> <username\> and to the ...
>
> Sergey Chernyshev has updated the pull request incrementally with two 
> additional commits since the last revision:
> 
>  - Update 
> src/jdk.attach/macosx/classes/sun/tools/attach/VirtualMachineImpl.java
>    
>    Co-authored-by: Andrey Turbanov <[email protected]>
>  - addressed review comments

will do!

On 9/22/25 1:04 PM, Sergey Chernyshev wrote:
> *sercher* left a comment (openjdk/jdk#25824) 
> <https://urldefense.com/v3/__https://github.com/openjdk/jdk/pull/25824*issuecomment-3321272195__;Iw!!ACWV5N9M2RV99hQ!P9dALpheoPUoaoWeQ1rj6dzwU42yVWWmfrsbZt429ot-cdhEW8CspQyFVJ455ZjgbI2QssgWZS26ouu2810uaE86kA$>
>
> @turbanoff 
> <https://urldefense.com/v3/__https://github.com/turbanoff__;!!ACWV5N9M2RV99hQ!P9dALpheoPUoaoWeQ1rj6dzwU42yVWWmfrsbZt429ot-cdhEW8CspQyFVJ455ZjgbI2QssgWZS26ouu2812g3XS-WA$>
>  
> @dholmes-ora 
> <https://urldefense.com/v3/__https://github.com/dholmes-ora__;!!ACWV5N9M2RV99hQ!P9dALpheoPUoaoWeQ1rj6dzwU42yVWWmfrsbZt429ot-cdhEW8CspQyFVJ455ZjgbI2QssgWZS26ouu2813-Ly68vg$>
>  
> @larry-cable 
> <https://urldefense.com/v3/__https://github.com/larry-cable__;!!ACWV5N9M2RV99hQ!P9dALpheoPUoaoWeQ1rj6dzwU42yVWWmfrsbZt429ot-cdhEW8CspQyFVJ455ZjgbI2QssgWZS26ouu2810J2TUJ4w$>
>  
> Could you please take a look at this?
>
> —
> Reply to this email directly, view it on GitHub 
> <https://urldefense.com/v3/__https://github.com/openjdk/jdk/pull/25824*issuecomment-3321272195__;Iw!!ACWV5N9M2RV99hQ!P9dALpheoPUoaoWeQ1rj6dzwU42yVWWmfrsbZt429ot-cdhEW8CspQyFVJ455ZjgbI2QssgWZS26ouu2810uaE86kA$>,
>  
> or unsubscribe 
> <https://urldefense.com/v3/__https://github.com/notifications/unsubscribe-auth/ANTA67VRW3666Z2O5P7IMJT3UBI3LAVCNFSM6AAAAAB7MZH7WGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTGMRRGI3TEMJZGU__;!!ACWV5N9M2RV99hQ!P9dALpheoPUoaoWeQ1rj6dzwU42yVWWmfrsbZt429ot-cdhEW8CspQyFVJ455ZjgbI2QssgWZS26ouu2810UmUzuKQ$>.
> You are receiving this because you were mentioned.Message ID: 
> ***@***.***>
>

--------------clQK6hO50V7lxYIyzZn4ddE5
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 8bit

<!DOCTYPE html><html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body>
    will do!<br>
    <br>
    <div class="moz-cite-prefix">On 9/22/25 1:04 PM, Sergey Chernyshev
      wrote:<br>
    </div>
    <blockquote type="cite" ***@***.***">
      
      <div style="display: flex; flex-wrap: wrap; white-space: pre-wrap; 
align-items: center; "><img height="20" width="20" style="border-radius:50%; 
margin-right: 4px;" decoding="async" 
src="https://avatars.githubusercontent.com/u/6394632?s=20&amp;v=4"; 
moz-do-not-send="true"><strong>sercher</strong> left a comment <a 
href="https://urldefense.com/v3/__https://github.com/openjdk/jdk/pull/25824*issuecomment-3321272195__;Iw!!ACWV5N9M2RV99hQ!P9dALpheoPUoaoWeQ1rj6dzwU42yVWWmfrsbZt429ot-cdhEW8CspQyFVJ455ZjgbI2QssgWZS26ouu2810uaE86kA$";
 moz-do-not-send="true">(openjdk/jdk#25824)</a></div>
      <p dir="auto"><a class="user-mention notranslate" 
data-hovercard-type="user" data-hovercard-url="/users/turbanoff/hovercard" 
data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" 
href="https://urldefense.com/v3/__https://github.com/turbanoff__;!!ACWV5N9M2RV99hQ!P9dALpheoPUoaoWeQ1rj6dzwU42yVWWmfrsbZt429ot-cdhEW8CspQyFVJ455ZjgbI2QssgWZS26ouu2812g3XS-WA$";
 ***@***.***</a> <a class="user-mention notranslate" data-hovercard-type="user" 
data-hovercard-url="/users/dholmes-ora/hovercard" 
data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" 
href="https://urldefense.com/v3/__https://github.com/dholmes-ora__;!!ACWV5N9M2RV99hQ!P9dALpheoPUoaoWeQ1rj6dzwU42yVWWmfrsbZt429ot-cdhEW8CspQyFVJ455ZjgbI2QssgWZS26ouu2813-Ly68vg$";
 ***@***.***</a> <a class="user-mention notranslate" data-hovercard-type="user" 
data-hovercard-url="/users/larry-cable/hovercard" 
data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" 
href="https://urldefense
 
.com/v3/__https://github.com/larry-cable__;!!ACWV5N9M2RV99hQ!P9dALpheoPUoaoWeQ1rj6dzwU42yVWWmfrsbZt429ot-cdhEW8CspQyFVJ455ZjgbI2QssgWZS26ouu2810J2TUJ4w$";
 ***@***.***</a> Could you please take
        a look at this?</p>
      <p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br>
        Reply to this email directly, <a 
href="https://urldefense.com/v3/__https://github.com/openjdk/jdk/pull/25824*issuecomment-3321272195__;Iw!!ACWV5N9M2RV99hQ!P9dALpheoPUoaoWeQ1rj6dzwU42yVWWmfrsbZt429ot-cdhEW8CspQyFVJ455ZjgbI2QssgWZS26ouu2810uaE86kA$";
 moz-do-not-send="true">view it on GitHub</a>, or <a 
href="https://urldefense.com/v3/__https://github.com/notifications/unsubscribe-auth/ANTA67VRW3666Z2O5P7IMJT3UBI3LAVCNFSM6AAAAAB7MZH7WGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTGMRRGI3TEMJZGU__;!!ACWV5N9M2RV99hQ!P9dALpheoPUoaoWeQ1rj6dzwU42yVWWmfrsbZt429ot-cdhEW8CspQyFVJ455ZjgbI2QssgWZS26ouu2810UmUzuKQ$";
 moz-do-not-send="true">unsubscribe</a>.<br>
        You are receiving this because you were mentioned.<img 
src="https://github.com/notifications/beacon/ANTA67RY5B2DW4ALWX3PHZ33UBI3LA5CNFSM6AAAAAB7MZH7WGWGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTWF62LYG.gif";
 height="1" width="1" alt="" moz-do-not-send="true"><span style="color: 
transparent; font-size: 0; display: none; visibility: hidden; overflow: hidden; 
opacity: 0; width: 0; height: 0; max-width: 0; max-height: 0; mso-hide: 
all">Message
          ID: 
<span>&lt;openjdk/jdk/pull/25824/c3321272195</span><span>@</span><span>github</span><span>.</span><span>com&gt;</span></span></p>
      <script type="application/ld+json">[
{
***@***.***": "http://schema.org";,
***@***.***": "EmailMessage",
"potentialAction": {
***@***.***": "ViewAction",
"target": "https://github.com/openjdk/jdk/pull/25824#issuecomment-3321272195";,
"url": "https://github.com/openjdk/jdk/pull/25824#issuecomment-3321272195";,
"name": "View Pull Request"
},
"description": "View this Pull Request on GitHub",
"publisher": {
***@***.***": "Organization",
"name": "GitHub",
"url": "https://github.com";
}
}
]</script>
    </blockquote>
    <br>
  </body>
</html>

--------------clQK6hO50V7lxYIyzZn4ddE5--

-------------

PR Comment: https://git.openjdk.org/jdk/pull/25824#issuecomment-3321771506

Reply via email to