/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
#include "precompiled.hpp"
#include "classfile/vmSymbols.hpp"
#include "memory/allocation.inline.hpp"
#include "memory/resourceArea.hpp"
#include "oops/oop.inline.hpp"
#include "os_windows.inline.hpp"
#include "runtime/handles.inline.hpp"
#include "runtime/perfMemory.hpp"
#include "services/memTracker.hpp"
#include "utilities/exceptions.hpp"
#include <windows.h>
#include <errno.h>
#include <lmcons.h>
// Standard Memory Implementation Details
// create the PerfData memory region in standard memory.
//
// allocate an aligned chuck of memory
if (mapAddress == NULL) {
return NULL;
}
// commit memory
if (PrintMiscellaneous && Verbose) {
warning("Could not commit PerfData memory\n");
}
return NULL;
}
return mapAddress;
}
// delete the PerfData memory region
//
// there are no persistent external resources to cleanup for standard
// memory. since DestroyJavaVM does not support unloading of the JVM,
// cleanup of the memory resource is not performed. The memory will be
// reclaimed by the OS upon termination of the process.
//
return;
}
// save the specified memory region to the given file
//
if (PrintMiscellaneous && Verbose) {
warning("Could not create Perfdata save file: %s: %s\n",
}
} else {
if (PrintMiscellaneous && Verbose) {
warning("Could not write Perfdata save file: %s: %s\n",
}
break;
}
}
if (PrintMiscellaneous && Verbose) {
}
}
}
}
// Shared Memory Implementation Details
// Note: the win32 shared memory implementation uses two objects to represent
// the shared memory: a windows kernel based file mapping object and a backing
// store file. On windows, the name space for shared memory is a kernel
// based name space that is disjoint from other win32 name spaces. Since Java
// is unaware of this name space, a parallel file system based name space is
// maintained, which provides a common file system based shared memory name
// space across the supported platforms and one that Java apps can deal with
// through simple file apis.
//
// For performance and resource cleanup reasons, it is recommended that the
// user specific directory and the backing store file be stored in either a
// RAM based file system or a local disk based file system. Network based
// file systems are not recommended for performance reasons. In addition,
// use of SMB network based file systems may result in unsuccesful cleanup
// of the disk based resource on exit of the VM. The Windows TMP and TEMP
// environement variables, as used by the GetTempPath() Win32 API (see
// os::get_temp_directory() in os_win32.cpp), control the location of the
// user specific directory and the shared memory backing store file.
// return the user specific temporary directory name.
//
// the caller is expected to free the allocated memory.
//
// construct the path name to user specific tmp directory
return dirname;
}
// convert the given file name into a process id. if the file
// does not meet the file naming constraints, return 0.
//
// a filename that doesn't begin with a digit is not a
// candidate for conversion.
//
return 0;
}
// check if file name can be converted to an integer without
// any leftover characters.
//
errno = 0;
if (errno != 0) {
return 0;
}
// check for left over characters. If any, then the filename is
// not a candidate for conversion.
//
return 0;
}
// successful conversion, return the pid
return pid;
}
// check if the given path is considered a secure directory for
// the backing store files. Returns true if the directory exists
// and is considered a secure location. Returns false if the path
// is a symbolic link or if an error occurred.
//
if (fa == 0xFFFFFFFF) {
if (lasterror == ERROR_FILE_NOT_FOUND) {
return false;
}
else {
// unexpected error, declare the path insecure
if (PrintMiscellaneous && Verbose) {
warning("could not get attributes for file %s: ",
}
return false;
}
}
if (fa & FILE_ATTRIBUTE_REPARSE_POINT) {
// we don't accept any redirection for the user specific directory
// so declare the path insecure. This may be too conservative,
// as some types of reparse points might be acceptable, but it
// is probably more secure to avoid these conditions.
//
if (PrintMiscellaneous && Verbose) {
}
return false;
}
if (fa & FILE_ATTRIBUTE_DIRECTORY) {
// this is the expected case. Since windows supports symbolic
// links to directories only, not to files, there is no need
// to check for open write permissions on the directory. If the
// directory has open write permissions, any files deposited that
// are not expected will be removed by the cleanup code.
//
return true;
}
else {
// this is either a regular file or some other type of file,
// any of which are unexpected and therefore insecure.
//
if (PrintMiscellaneous && Verbose) {
warning("%s is not a directory, file attributes = "
}
return false;
}
}
// return the user name for the owner of this process
//
// the caller is expected to free the allocated memory.
//
static char* get_user_name() {
/* get the user name. This code is adapted from code found in
* java_props_md.c 1.29 02/02/06. According to the original
* source, the call to GetUserName is avoided because of a resulting
* increase in footprint of 100K.
*/
}
else {
return NULL;
}
}
return user_name;
}
// return the name of the user that owns the process identified by vmid.
//
// This method uses a slow directory search algorithm to find the backing
// store file for the specified vmid and returns the user name, as determined
// by the user name suffix of the hsperfdata_<username> directory name.
//
// the caller is expected to free the allocated memory.
//
// directory search
return NULL;
}
// for each entry in the directory that matches the pattern hsperfdata_*,
// open the directory and check if the file for the given vmid exists.
// The file with the expected name and the latest creation date is used
// to determine the user name for the process id.
//
errno = 0;
// check if the directory entry is a hsperfdata file
continue;
}
continue;
}
// Since we don't create the backing store files in directories
// pointed to by symbolic links, we also don't follow them when
// looking for the files. We check for a symbolic link after the
// call to opendir in order to eliminate a small window where the
// symlink can be exploited.
//
if (!is_directory_secure(usrdir_name)) {
continue;
}
errno = 0;
continue;
}
// skip over files that are not regular files.
continue;
}
// If we found a matching file with a newer creation time, then
// save the user name. The newer creation time indicates that
// we found a newer incarnation of the process associated with
// vmid. Due to the way that Windows recycles pids and the fact
// that we can't delete the file from the file system namespace
// until last close, it is possible for there to be more than
// one hsperfdata file with a name matching vmid (diff users).
//
// We no longer ignore hsperfdata files where (st_size == 0).
// In this function, all we're trying to do is determine the
// name of the user that owns the process associated with vmid
// so the size doesn't matter. Very rarely, we have observed
// hsperfdata files where (st_size == 0) and the st_size field
// later becomes the expected value.
//
}
}
}
}
return(latest_user);
}
// return the name of the user that owns the process identified by vmid.
//
// note: this method should only be used via the Perf native methods.
// There are various costs to this method and limiting its use to the
// Perf native methods limits the impact to monitoring applications only.
//
// A fast implementation is not provided at this time. It's possible
// to provide a fast process id to user name mapping function using
// the win32 apis, but the default ACL for the process object only
// allows processes with the same owner SID to acquire the process
// handle (via OpenProcess(PROCESS_QUERY_INFORMATION)). It's possible
// to have the JVM change the ACL for the process object to allow arbitrary
// users to access the process handle and the process security token.
// The security ramifications need to be studied before providing this
// mechanism.
//
return get_user_name_slow(vmid);
}
// return the name of the shared memory file mapping object for the
// named shared memory region for the given user name and vmid.
//
// The file mapping object's name is not the file name. It is a name
// in a separate name space.
//
// the caller is expected to free the allocated memory.
//
// construct file mapping object's name, add 3 for two '_' and a
// null terminator.
// the id is converted to an unsigned value here because win32 allows
// negative process ids. However, OpenFileMapping API complains
// about a name containing a '-' characters.
//
nbytes += UINT_CHARS;
return name;
}
// return the file name of the backing store file for the named
// shared memory region for the given user name and vmid.
//
// the caller is expected to free the allocated memory.
//
// add 2 for the file separator and a null terminator.
return name;
}
// remove file
//
// this method removes the file with the given file name.
//
// Note: if the indicated file is on an SMB network file system, this
// method may be unsuccessful in removing the file.
//
if (PrintMiscellaneous && Verbose) {
warning("Could not unlink shared memory backing"
}
}
}
}
// returns true if the process represented by pid is alive, otherwise
// returns false. the validity of the result is only accurate if the
// target process is owned by the same principal that owns this process.
// this method should not be used if to test the status of an otherwise
// arbitrary process unless it is know that this process has the appropriate
// privileges to guarantee a result valid.
//
// the process does not exist.
if (PrintMiscellaneous && Verbose) {
if (lastError != ERROR_INVALID_PARAMETER) {
}
}
return false;
}
if (PrintMiscellaneous && Verbose) {
}
return false;
}
return (exit_status == STILL_ACTIVE) ? true : false;
}
// check if the file system is considered secure for the backing store files
//
if (PerfBypassFileSystemCheck) {
if (PrintMiscellaneous && Verbose) {
}
return true;
}
if (first_colon == NULL) {
if (PrintMiscellaneous && Verbose) {
}
return false;
}
// check that we have something like "C:\" or "AA:\"
// we can't get information about the volume, so assume unsafe.
if (PrintMiscellaneous && Verbose) {
warning("could not get device information for %s: "
" path = %s: lasterror = %d\n",
}
return false;
}
if ((flags & FS_PERSISTENT_ACLS) == 0) {
// file system doesn't support ACLs, declare file system unsafe
if (PrintMiscellaneous && Verbose) {
warning("file system type %s on device %s does not support"
}
return false;
}
if ((flags & FS_VOL_IS_COMPRESSED) != 0) {
// file system is compressed, declare file system unsafe
if (PrintMiscellaneous && Verbose) {
warning("file system type %s on device %s is compressed\n",
}
return false;
}
return true;
}
// cleanup stale shared memory resources
//
// This method attempts to remove all stale shared memory files in
// the named user temporary directory. It scans the named directory
// for files matching the pattern ^$[0-9]*$. For each file found, the
// process id is extracted from the file name and a test is run to
// determine if the process is alive. If the process is not alive,
// any stale file resources are removed.
//
// open the user temp directory
// directory doesn't exist, so there is nothing to cleanup
return;
}
if (!is_directory_secure(dirname)) {
// the directory is not secure, don't attempt any cleanup
return;
}
// for each entry in the directory that matches the expected file
// name pattern, determine if the file resources are stale and if
// so, remove the file resources. Note, instrumented HotSpot processes
// remove or create new files in this directory. The behavior of this
// loop under these conditions is dependent upon the implementation of
//
errno = 0;
if (pid == 0) {
// attempt to remove all unexpected files, except "." and ".."
}
errno = 0;
continue;
}
// we now have a file name that converts to a valid integer
// that could represent a process id . if this process id
// matches the current process id or the process is not running,
// then remove the stale file resources.
//
// process liveness is detected by checking the exit status
// of the process. if the process id is valid and the exit status
// indicates that it is still running, the file file resources
// are not removed. If the process id is invalid, or if we don't
// have permissions to check the process status, or if the process
// id is valid and the process has terminated, the the file resources
// are assumed to be stale and are removed.
//
// we can only remove the file resources. Any mapped views
// of the file can only be unmapped by the processes that
// opened those views and the file mapping object will not
// get removed until all views are unmapped.
//
}
errno = 0;
}
}
// create a file mapping object with the requested name, and size
// from the file represented by the given Handle object
//
static HANDLE create_file_mapping(const char* name, HANDLE fh, LPSECURITY_ATTRIBUTES fsa, size_t size) {
// Create a file mapping object with the given name. This function
// will grow the file to the specified size.
//
fh, /* HANDLE file handle for backing store */
fsa, /* LPSECURITY_ATTRIBUTES Not inheritable */
PAGE_READWRITE, /* DWORD protections */
highSize, /* DWORD High word of max size */
lowSize, /* DWORD Low word of max size */
name); /* LPCTSTR name for object */
if (PrintMiscellaneous && Verbose) {
}
return NULL;
}
if (GetLastError() == ERROR_ALREADY_EXISTS) {
// a stale file mapping object was encountered. This object may be
// owned by this or some other user and cannot be removed until
// the other processes either exit or close their mapping objects
//
if (PrintMiscellaneous && Verbose) {
}
return NULL;
}
return fmh;
}
// method to free the given security descriptor and the contained
// access control list.
//
// get the access control list from the security descriptor
// if an ACL existed and it was not a default acl, then it must
// be an ACL we enlisted. free the resources.
//
}
// free the security descriptor
}
}
// method to free up a security attributes structure and any
// contained security descriptors and ACL
//
// free the contained security descriptor and the ACL
// free the security attributes structure
}
}
// get the user SID for the process indicated by the process handle
//
return NULL;
}
// get the process token
if (PrintMiscellaneous && Verbose) {
}
return NULL;
}
// determine the size of the token structured needed to retrieve
// the user token information from the access token.
//
if (lasterror != ERROR_INSUFFICIENT_BUFFER) {
if (PrintMiscellaneous && Verbose) {
warning("GetTokenInformation failure: lasterror = %d,"
}
return NULL;
}
}
// get the user token information
if (PrintMiscellaneous && Verbose) {
warning("GetTokenInformation failure: lasterror = %d,"
}
return NULL;
}
if (PrintMiscellaneous && Verbose) {
warning("GetTokenInformation failure: lasterror = %d,"
}
return NULL;
}
// close the access token.
return pSID;
}
// structure used to consolidate access control entry information
//
typedef struct ace_data {
} ace_data_t;
// method to add an allow access control entry with the access rights
// indicated in mask for the principal indicated in SID to the given
// security descriptor. Much of the DACL handling was adapted from
// the example provided here:
//
return false;
}
// retrieve any existing access control list.
if (PrintMiscellaneous && Verbose) {
warning("GetSecurityDescriptor failure: lasterror = %d \n",
GetLastError());
}
return false;
}
// get the size of the DACL
// GetSecurityDescriptorDacl may return true value for exists (lpbDaclPresent)
// while oldACL is NULL for some case.
}
if (exists) {
sizeof(ACL_SIZE_INFORMATION),
if (PrintMiscellaneous && Verbose) {
return false;
}
}
} else {
aclinfo.AclBytesFree = 0;
}
// compute the size needed for the new ACL
// initial size of ACL is sum of the following:
// * size of ACL structure.
// * size of each ACE structure that ACL is to contain minus the sid
// sidStart member (DWORD) of the ACE.
// * length of the SID that each ACE is to contain.
for (int i = 0; i < ace_count; i++) {
}
// create the new ACL
if (PrintMiscellaneous && Verbose) {
}
return false;
}
unsigned int ace_index = 0;
// copy any existing ACEs from the old ACL (if any) to the new ACL.
if (PrintMiscellaneous && Verbose) {
}
return false;
}
// this is an inherited, allowed ACE; break from loop so we can
// add the new access allowed, non-inherited ACE in the correct
// position, immediately following all non-inherited ACEs.
break;
}
// determine if the SID of this ACE matches any of the SIDs
// for which we plan to set ACEs.
int matches = 0;
for (int i = 0; i < ace_count; i++) {
matches++;
break;
}
}
// if there are no SID matches, then add this existing ACE to the new ACL
if (matches == 0) {
if (PrintMiscellaneous && Verbose) {
}
return false;
}
}
ace_index++;
}
}
// add the passed-in access control entries to the new ACL
for (int i = 0; i < ace_count; i++) {
if (PrintMiscellaneous && Verbose) {
warning("AddAccessAllowedAce failure: lasterror = %d \n",
GetLastError());
}
return false;
}
}
// now copy the rest of the inherited ACEs from the old ACL
// picking up at ace_index, where we left off in the
// previous ace_index loop
if (PrintMiscellaneous && Verbose) {
}
return false;
}
if (PrintMiscellaneous && Verbose) {
}
return false;
}
ace_index++;
}
}
// add the new ACL to the security descriptor.
if (PrintMiscellaneous && Verbose) {
warning("SetSecurityDescriptorDacl failure:"
" lasterror = %d \n", GetLastError());
}
return false;
}
// if running on windows 2000 or later, set the automatic inheritance
// control flags.
"SetSecurityDescriptorControl");
if (_SetSecurityDescriptorControl != NULL) {
// We do not want to further propagate inherited DACLs, so making them
// protected prevents that.
if (PrintMiscellaneous && Verbose) {
warning("SetSecurityDescriptorControl failure:"
" lasterror = %d \n", GetLastError());
}
return false;
}
}
// Note, the security descriptor maintains a reference to the newACL, not
// a copy of it. Therefore, the newACL is not freed here. It is freed when
// the security descriptor containing its reference is freed.
//
return true;
}
// method to create a security attributes structure, which contains a
// security descriptor and an access control list comprised of 0 or more
// access control entries. The method take an array of ace_data structures
// that indicate the ACE to be added to the security descriptor.
//
// the caller must free the resources associated with the security
// attributes structure created by this method by calling the
// free_security_attr() method.
//
// allocate space for a security descriptor
// initialize the security descriptor
if (PrintMiscellaneous && Verbose) {
warning("InitializeSecurityDescriptor failure: "
"lasterror = %d \n", GetLastError());
}
return NULL;
}
// add the access control entries
return NULL;
}
// allocate and initialize the security attributes structure and
// return it to the caller.
//
return(lpSA);
}
// method to create a security attributes structure with a restrictive
// of the securable object and a separate set access rights for everyone else.
// also provides for full access rights for the administrator group.
//
// the caller must free the resources associated with the security
// attributes structure created by this method by calling the
// free_security_attr() method.
//
// initialize the user ace data
return NULL;
// get the well known SID for BUILTIN\Administrators
0, 0, 0, 0, 0, 0, &administratorsSid)) {
if (PrintMiscellaneous && Verbose) {
warning("AllocateAndInitializeSid failure: "
"lasterror = %d \n", GetLastError());
}
return NULL;
}
// initialize the ace data for administrator group
// get the well known SID for the universal Everybody
0, 0, 0, 0, 0, 0, 0, &everybodySid)) {
if (PrintMiscellaneous && Verbose) {
warning("AllocateAndInitializeSid failure: "
"lasterror = %d \n", GetLastError());
}
return NULL;
}
// initialize the ace data for everybody else.
// create a security attributes structure with access control
// entries as initialized above.
return(lpSA);
}
// method to create the security attributes structure for restricting
// access to the user temporary directory.
//
// the caller must free the resources associated with the security
// attributes structure created by this method by calling the
// free_security_attr() method.
//
// and read-only access rights for everybody else. This is
// effectively equivalent to UNIX 755 permissions on a directory.
//
}
// method to create the security attributes structure for restricting
// access to the shared memory backing store file.
//
// the caller must free the resources associated with the security
// attributes structure created by this method by calling the
// free_security_attr() method.
//
// and attribute read-only access rights for everybody else. This
// is effectively equivalent to UNIX 600 permissions on a file.
//
}
// method to create the security attributes structure for restricting
// access to the name shared memory file mapping object.
//
// the caller must free the resources associated with the security
// attributes structure created by this method by calling the
// free_security_attr() method.
//
// memory object and attribute read-only access rights for everybody
// else. This is effectively equivalent to UNIX 600 permissions on
// on the shared memory object.
//
}
// make the user specific temporary directory
//
return false;
}
// create the directory with the given security attributes
if (lasterror == ERROR_ALREADY_EXISTS) {
// The directory already exists and was probably created by another
// JVM instance. However, this could also be the result of a
// deliberate symlink. Verify that the existing directory is safe.
//
if (!is_directory_secure(dirname)) {
// directory is not secure
if (PrintMiscellaneous && Verbose) {
}
return false;
}
// The administrator should be able to delete this directory.
// But the directory created by previous version of JVM may not
// have permission for administrators to delete this directory.
// So add full permission to the administrator. Also setting new
// DACLs might fix the corrupted the DACLs.
if (PrintMiscellaneous && Verbose) {
lasterror = GetLastError();
warning("SetFileSecurity failed for %s directory. lasterror %d \n",
}
}
}
else {
if (PrintMiscellaneous && Verbose) {
}
return false;
}
}
// free the security attributes structure
return true;
}
// create the shared memory resources
//
// This function creates the shared memory resources. This includes
// the backing store file and the file mapping shared memory object.
//
static HANDLE create_sharedmem_resources(const char* dirname, const char* filename, const char* objectname, size_t size) {
// create the security attributes for the backing store file
return NULL;
}
// create the security attributes for the shared memory object
return NULL;
}
// create the user temporary directory
if (!make_user_tmp_dir(dirname)) {
// was not secure
return NULL;
}
// Create the file - the FILE_FLAG_DELETE_ON_CLOSE flag allows the
// file to be deleted by the last process that closes its handle to
// the file. This is important as the apis do not allow a terminating
// JVM being monitored by another process to remove the file name.
//
// the FILE_SHARE_DELETE share mode is valid only in winnt
//
fh = CreateFile(
filename, /* LPCTSTR file name */
FILE_SHARE_READ, /* DWORD share mode, future READONLY
* open operations allowed
*/
lpFileSA, /* LPSECURITY security attributes */
CREATE_ALWAYS, /* DWORD creation disposition
* create file, if it already
* exists, overwrite it.
*/
FILE_FLAG_DELETE_ON_CLOSE, /* DWORD flags and attributes */
NULL); /* HANDLE template file access */
if (fh == INVALID_HANDLE_VALUE) {
if (PrintMiscellaneous && Verbose) {
}
return NULL;
}
// try to create the file mapping
// closing the file handle here will decrement the reference count
// on the file. When all processes accessing the file close their
// handle to it, the reference count will decrement to 0 and the
// OS will delete the file. These semantics are requested by the
// FILE_FLAG_DELETE_ON_CLOSE flag in CreateFile call above.
return NULL;
} else {
// We created the file mapping, but rarely the size of the
// backing store file is reported as zero (0) which can cause
// failures when trying to use the hsperfdata file.
if (PrintMiscellaneous && Verbose) {
warning("Could not get status information from file %s: %s\n",
}
return NULL;
}
// We could always call FlushFileBuffers() but the Microsoft
// docs indicate that it is considered expensive so we only
// call it when we observe the size as zero (0).
if (PrintMiscellaneous && Verbose) {
}
return NULL;
}
}
// the file has been successfully created and the file mapping
// object has been created.
return fmh;
}
// open the shared memory object for the given vmid.
//
// open the file mapping with the requested mode
ofm_access, /* DWORD access mode */
FALSE, /* BOOL inherit flag - Do not allow inherit */
objectname); /* name for object */
if (PrintMiscellaneous && Verbose) {
warning("OpenFileMapping failed for shared memory object %s:"
}
}
return fmh;;
}
// create a named shared memory region
//
// On Win32, a named shared memory object has a name space that
// is independent of the file system name space. Shared memory object,
// or more precisely, file mapping objects, provide no mechanism to
// inquire the size of the memory region. There is also no api to
// enumerate the memory regions for various processes.
//
// This implementation utilizes the shared memory name space in parallel
// with the file system name space. This allows us to determine the
// size of the shared memory region from the size of the file and it
// allows us to provide a common, file system based name space for
// shared memory across platforms.
//
void *mapAddress;
// get the name of the user associated with this process
return NULL;
}
// construct the name of the user specific temporary directory
// check that the file system is secure - i.e. it supports ACLs.
if (!is_filesystem_secure(dirname)) {
return NULL;
}
// create the names of the backing store files and for the
// share memory object.
//
// cleanup any stale shared memory resources
"unexpected PerfMemry region size");
// create the shared memory resources
if (sharedmem_fileMapHandle == NULL) {
return NULL;
}
// map the file into the address space
sharedmem_fileMapHandle, /* HANDLE = file mapping object */
FILE_MAP_ALL_ACCESS, /* DWORD access flags */
0, /* DWORD High word of offset */
0, /* DWORD Low word of offset */
if (mapAddress == NULL) {
if (PrintMiscellaneous && Verbose) {
}
return NULL;
}
// clear the shared memory region
// it does not go through os api, the operation has to record from here
return (char*) mapAddress;
}
// this method deletes the file mapping object.
//
// cleanup the persistent shared memory resources. since DestroyJavaVM does
// not support unloading of the JVM, unmapping of the memory resource is not
// performed. The memory will be reclaimed by the OS upon termination of all
// processes mapping the resource. The file mapping handle and the file
// handle are closed here to expedite the remove of the file by the OS. The
// file is not removed directly because it was created with
// FILE_FLAG_DELETE_ON_CLOSE semantics and any attempt to remove it would
// be unsuccessful.
// close the fileMapHandle. the file mapping will still be retained
// by the OS as long as any other JVM processes has an open file mapping
// handle or a mapped view of the file.
//
if (sharedmem_fileMapHandle != NULL) {
}
// close the file handle. This will decrement the reference count on the
// backing store file. When the reference count decrements to 0, the OS
// will delete the file. These semantics apply because the file was
// created with the FILE_FLAG_DELETE_ON_CLOSE flag.
//
if (sharedmem_fileHandle != INVALID_HANDLE_VALUE) {
}
}
// this method determines the size of the shared memory file
//
// get the file size
//
// on win95/98/me, _stat returns a file size of 0 bytes, but on
// winnt/2k the appropriate file size is returned. support for
// the sharable aspects of performance counters was abandonded
// on the non-nt win32 platforms due to this and other api
// inconsistencies
//
if (PrintMiscellaneous && Verbose) {
}
"Could not determine PerfMemory size");
}
if (PrintMiscellaneous && Verbose) {
}
"Invalid PerfMemory size");
}
}
// this method opens a file mapping object and maps the object
// into the address space of the process
//
void *mapAddress = 0;
}
#ifdef LATER
#else
"Unsupported access mode");
#endif
}
else {
"Illegal access mode");
}
// if a user name wasn't specified, then find the user name for
// the owner of the target vm.
}
else {
}
"Could not map vmid to user name");
}
// get the names for the resources for the target vm
// since we don't follow symbolic links when creating the backing
// store file, we also don't following them when attaching
//
if (!is_directory_secure(dirname)) {
"Process not found");
}
// copy heap memory to resource memory. the objectname and
// filename are passed to methods that may throw exceptions.
// using resource arrays for these names prevents the leaks
// that would otherwise occur.
//
// free the c heap resources that are no longer needed
if (*sizep == 0) {
}
// Open the file mapping object with the given name
// map the entire file into the address space
fmh, /* HANDLE Handle of file mapping object */
mv_access, /* DWORD access flags */
0, /* DWORD High word of offset */
0, /* DWORD Low word of offset */
size); /* DWORD Number of bytes to map */
if (mapAddress == NULL) {
if (PrintMiscellaneous && Verbose) {
}
"Could not map PerfMemory");
}
// it does not go through os api, the operation has to record from here
*addrp = (char*)mapAddress;
// File mapping object can be closed at this time without
// invalidating the mapped view of the file
if (PerfTraceMemOps) {
}
}
// this method unmaps the the mapped view of the the
// file mapping object.
//
// the file mapping object was closed in open_file_mapping()
// after the file map view was created. We only need to
// unmap the file view here.
}
// create the PerfData memory region in shared memory.
return mapping_create_shared(size);
}
// release a named, shared memory region
//
}
// create the PerfData memory region
//
// This method creates the memory region used to store performance
// data for the JVM. The memory may be created in standard or
// shared memory.
//
// do not share the memory for the performance data.
PerfDisableSharedMem = true;
}
else {
// creation of the shared memory region failed, attempt
// to create a contiguous, non-shared memory region instead.
//
if (PrintMiscellaneous && Verbose) {
warning("Reverting to non-shared PerfMemory region.\n");
}
PerfDisableSharedMem = true;
}
}
}
// delete the PerfData memory region
//
// This method deletes the memory region used to store performance
// data for the JVM. The memory region indicated by the <address, size>
// tuple will be inaccessible after a call to this method.
//
// If user specifies PerfDataSaveFile, it will save the performance data
// to the specified file name no matter whether PerfDataSaveToFile is specified
// or not. In other word, -XX:PerfDataSaveFile=.. overrides flag
// -XX:+PerfDataSaveToFile.
}
if (PerfDisableSharedMem) {
}
else {
}
}
// attach to the PerfData memory region for another JVM
//
// This method returns an <address, size> tuple that points to
// a memory buffer that is kept reasonably synchronized with
// the PerfData memory region for the indicated JVM. This
// buffer may be kept in synchronization via shared memory
// or some other mechanism that keeps the buffer updated.
//
// If the JVM chooses not to support the attachability feature,
// this method should throw an UnsupportedOperation exception.
//
// This implementation utilizes named shared memory to map
// the indicated process's PerfData memory region into this JVMs
// address space.
//
return;
}
}
// detach from the PerfData memory region of another JVM
//
// This method detaches the PerfData memory region of another
// JVM, specified as an <address, size> tuple of a buffer
// in this process's address space. This method may perform
// arbitrary actions to accomplish the detachment. The memory
// region specified by <address, size> will be inaccessible after
// a call to this method.
//
// If the JVM chooses not to support the attachability feature,
// this method should throw an UnsupportedOperation exception.
//
// This implementation utilizes named shared memory to detach
// the indicated process's PerfData memory region from this
// process's address space.
//
// prevent accidental detachment of this process's PerfMemory region
return;
}
// it does not go through os api, the operation has to record from here
}
return sharedmem_fileName;
}