< prev index next >

src/os/aix/vm/perfMemory_aix.cpp

Print this page
rev 7960 : 8075506: aix: improve handling of native memory


 780     // then remove the stale file resources.
 781     //
 782     // Process liveness is detected by sending signal number 0 to
 783     // the process id (see kill(2)). if kill determines that the
 784     // process does not exist, then the file resources are removed.
 785     // if kill determines that that we don't have permission to
 786     // signal the process, then the file resources are assumed to
 787     // be stale and are removed because the resources for such a
 788     // process should be in a different user specific directory.
 789     if ((pid == os::current_process_id()) ||
 790         (kill(pid, 0) == OS_ERR && (errno == ESRCH || errno == EPERM))) {
 791 
 792         unlink(entry->d_name);
 793     }
 794     errno = 0;
 795   }
 796 
 797   // Close the directory and reset the current working directory.
 798   close_directory_secure_cwd(dirp, saved_cwd_fd);
 799 
 800   FREE_C_HEAP_ARRAY(char, dbuf, mtInternal);
 801 }
 802 
 803 // Make the user specific temporary directory. Returns true if
 804 // the directory exists and is secure upon return. Returns false
 805 // if the directory exists but is either a symlink, is otherwise
 806 // insecure, or if an error occurred.
 807 static bool make_user_tmp_dir(const char* dirname) {
 808 
 809   // Create the directory with 0755 permissions. note that the directory
 810   // will be owned by euid::egid, which may not be the same as uid::gid.
 811   if (mkdir(dirname, S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH) == OS_ERR) {
 812     if (errno == EEXIST) {
 813       // The directory already exists and was probably created by another
 814       // JVM instance. However, this could also be the result of a
 815       // deliberate symlink. Verify that the existing directory is safe.
 816       if (!is_directory_secure(dirname)) {
 817         // Directory is not secure.
 818         if (PrintMiscellaneous && Verbose) {
 819           warning("%s directory is insecure\n", dirname);
 820         }


1147   }
1148 
1149   if (user == NULL || strlen(user) == 0) {
1150     luser = get_user_name(vmid, CHECK);
1151   }
1152   else {
1153     luser = user;
1154   }
1155 
1156   if (luser == NULL) {
1157     THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
1158               "Could not map vmid to user Name");
1159   }
1160 
1161   char* dirname = get_user_tmp_dir(luser);
1162 
1163   // since we don't follow symbolic links when creating the backing
1164   // store file, we don't follow them when attaching either.
1165   //
1166   if (!is_directory_secure(dirname)) {
1167     FREE_C_HEAP_ARRAY(char, dirname, mtInternal);
1168     if (luser != user) {
1169       FREE_C_HEAP_ARRAY(char, luser, mtInternal);
1170     }
1171     THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
1172               "Process not found");
1173   }
1174 
1175   char* filename = get_sharedmem_filename(dirname, vmid);
1176 
1177   // copy heap memory to resource memory. the open_sharedmem_file
1178   // method below need to use the filename, but could throw an
1179   // exception. using a resource array prevents the leak that
1180   // would otherwise occur.
1181   char* rfilename = NEW_RESOURCE_ARRAY(char, strlen(filename) + 1);
1182   strcpy(rfilename, filename);
1183 
1184   // free the c heap resources that are no longer needed
1185   if (luser != user) FREE_C_HEAP_ARRAY(char, luser);
1186   FREE_C_HEAP_ARRAY(char, dirname);
1187   FREE_C_HEAP_ARRAY(char, filename);
1188 
1189   // open the shared memory file for the give vmid




 780     // then remove the stale file resources.
 781     //
 782     // Process liveness is detected by sending signal number 0 to
 783     // the process id (see kill(2)). if kill determines that the
 784     // process does not exist, then the file resources are removed.
 785     // if kill determines that that we don't have permission to
 786     // signal the process, then the file resources are assumed to
 787     // be stale and are removed because the resources for such a
 788     // process should be in a different user specific directory.
 789     if ((pid == os::current_process_id()) ||
 790         (kill(pid, 0) == OS_ERR && (errno == ESRCH || errno == EPERM))) {
 791 
 792         unlink(entry->d_name);
 793     }
 794     errno = 0;
 795   }
 796 
 797   // Close the directory and reset the current working directory.
 798   close_directory_secure_cwd(dirp, saved_cwd_fd);
 799 
 800   FREE_C_HEAP_ARRAY(char, dbuf);
 801 }
 802 
 803 // Make the user specific temporary directory. Returns true if
 804 // the directory exists and is secure upon return. Returns false
 805 // if the directory exists but is either a symlink, is otherwise
 806 // insecure, or if an error occurred.
 807 static bool make_user_tmp_dir(const char* dirname) {
 808 
 809   // Create the directory with 0755 permissions. note that the directory
 810   // will be owned by euid::egid, which may not be the same as uid::gid.
 811   if (mkdir(dirname, S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH) == OS_ERR) {
 812     if (errno == EEXIST) {
 813       // The directory already exists and was probably created by another
 814       // JVM instance. However, this could also be the result of a
 815       // deliberate symlink. Verify that the existing directory is safe.
 816       if (!is_directory_secure(dirname)) {
 817         // Directory is not secure.
 818         if (PrintMiscellaneous && Verbose) {
 819           warning("%s directory is insecure\n", dirname);
 820         }


1147   }
1148 
1149   if (user == NULL || strlen(user) == 0) {
1150     luser = get_user_name(vmid, CHECK);
1151   }
1152   else {
1153     luser = user;
1154   }
1155 
1156   if (luser == NULL) {
1157     THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
1158               "Could not map vmid to user Name");
1159   }
1160 
1161   char* dirname = get_user_tmp_dir(luser);
1162 
1163   // since we don't follow symbolic links when creating the backing
1164   // store file, we don't follow them when attaching either.
1165   //
1166   if (!is_directory_secure(dirname)) {
1167     FREE_C_HEAP_ARRAY(char, dirname);
1168     if (luser != user) {
1169       FREE_C_HEAP_ARRAY(char, luser);
1170     }
1171     THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
1172               "Process not found");
1173   }
1174 
1175   char* filename = get_sharedmem_filename(dirname, vmid);
1176 
1177   // copy heap memory to resource memory. the open_sharedmem_file
1178   // method below need to use the filename, but could throw an
1179   // exception. using a resource array prevents the leak that
1180   // would otherwise occur.
1181   char* rfilename = NEW_RESOURCE_ARRAY(char, strlen(filename) + 1);
1182   strcpy(rfilename, filename);
1183 
1184   // free the c heap resources that are no longer needed
1185   if (luser != user) FREE_C_HEAP_ARRAY(char, luser);
1186   FREE_C_HEAP_ARRAY(char, dirname);
1187   FREE_C_HEAP_ARRAY(char, filename);
1188 
1189   // open the shared memory file for the give vmid


< prev index next >