28 #include "memory/allocation.inline.hpp" |
28 #include "memory/allocation.inline.hpp" |
29 #include "memory/resourceArea.hpp" |
29 #include "memory/resourceArea.hpp" |
30 #include "oops/oop.inline.hpp" |
30 #include "oops/oop.inline.hpp" |
31 #include "os_aix.inline.hpp" |
31 #include "os_aix.inline.hpp" |
32 #include "runtime/handles.inline.hpp" |
32 #include "runtime/handles.inline.hpp" |
|
33 #include "runtime/os.hpp" |
33 #include "runtime/perfMemory.hpp" |
34 #include "runtime/perfMemory.hpp" |
34 #include "services/memTracker.hpp" |
35 #include "services/memTracker.hpp" |
35 #include "utilities/exceptions.hpp" |
36 #include "utilities/exceptions.hpp" |
36 |
37 |
37 // put OS-includes here |
38 // put OS-includes here |
99 RESTARTABLE(::open(destfile, O_CREAT|O_WRONLY|O_TRUNC, S_IREAD|S_IWRITE), |
100 RESTARTABLE(::open(destfile, O_CREAT|O_WRONLY|O_TRUNC, S_IREAD|S_IWRITE), |
100 result);; |
101 result);; |
101 if (result == OS_ERR) { |
102 if (result == OS_ERR) { |
102 if (PrintMiscellaneous && Verbose) { |
103 if (PrintMiscellaneous && Verbose) { |
103 warning("Could not create Perfdata save file: %s: %s\n", |
104 warning("Could not create Perfdata save file: %s: %s\n", |
104 destfile, strerror(errno)); |
105 destfile, os::strerror(errno)); |
105 } |
106 } |
106 } else { |
107 } else { |
107 int fd = result; |
108 int fd = result; |
108 |
109 |
109 for (size_t remaining = size; remaining > 0;) { |
110 for (size_t remaining = size; remaining > 0;) { |
110 |
111 |
111 RESTARTABLE(::write(fd, addr, remaining), result); |
112 RESTARTABLE(::write(fd, addr, remaining), result); |
112 if (result == OS_ERR) { |
113 if (result == OS_ERR) { |
113 if (PrintMiscellaneous && Verbose) { |
114 if (PrintMiscellaneous && Verbose) { |
114 warning("Could not write Perfdata save file: %s: %s\n", |
115 warning("Could not write Perfdata save file: %s: %s\n", |
115 destfile, strerror(errno)); |
116 destfile, os::strerror(errno)); |
116 } |
117 } |
117 break; |
118 break; |
118 } |
119 } |
119 |
120 |
120 remaining -= (size_t)result; |
121 remaining -= (size_t)result; |
122 } |
123 } |
123 |
124 |
124 result = ::close(fd); |
125 result = ::close(fd); |
125 if (PrintMiscellaneous && Verbose) { |
126 if (PrintMiscellaneous && Verbose) { |
126 if (result == OS_ERR) { |
127 if (result == OS_ERR) { |
127 warning("Could not close %s: %s\n", destfile, strerror(errno)); |
128 warning("Could not close %s: %s\n", destfile, os::strerror(errno)); |
128 } |
129 } |
129 } |
130 } |
130 } |
131 } |
131 FREE_C_HEAP_ARRAY(char, destfile); |
132 FREE_C_HEAP_ARRAY(char, destfile); |
132 } |
133 } |
395 // Directory doesn't exist or is a symlink, so there is nothing to cleanup. |
396 // Directory doesn't exist or is a symlink, so there is nothing to cleanup. |
396 if (PrintMiscellaneous && Verbose) { |
397 if (PrintMiscellaneous && Verbose) { |
397 if (errno == ELOOP) { |
398 if (errno == ELOOP) { |
398 warning("directory %s is a symlink and is not secure\n", dirname); |
399 warning("directory %s is a symlink and is not secure\n", dirname); |
399 } else { |
400 } else { |
400 warning("could not open directory %s: %s\n", dirname, strerror(errno)); |
401 warning("could not open directory %s: %s\n", dirname, os::strerror(errno)); |
401 } |
402 } |
402 } |
403 } |
403 return dirp; |
404 return dirp; |
404 } |
405 } |
405 int fd = result; |
406 int fd = result; |
505 |
506 |
506 // Determine if the file is secure. |
507 // Determine if the file is secure. |
507 RESTARTABLE(::fstat(fd, &statbuf), result); |
508 RESTARTABLE(::fstat(fd, &statbuf), result); |
508 if (result == OS_ERR) { |
509 if (result == OS_ERR) { |
509 if (PrintMiscellaneous && Verbose) { |
510 if (PrintMiscellaneous && Verbose) { |
510 warning("fstat failed on %s: %s\n", filename, strerror(errno)); |
511 warning("fstat failed on %s: %s\n", filename, os::strerror(errno)); |
511 } |
512 } |
512 return false; |
513 return false; |
513 } |
514 } |
514 if (statbuf.st_nlink > 1) { |
515 if (statbuf.st_nlink > 1) { |
515 // A file with multiple links is not expected. |
516 // A file with multiple links is not expected. |
541 |
542 |
542 if (result != 0 || p == NULL || p->pw_name == NULL || *(p->pw_name) == '\0') { |
543 if (result != 0 || p == NULL || p->pw_name == NULL || *(p->pw_name) == '\0') { |
543 if (PrintMiscellaneous && Verbose) { |
544 if (PrintMiscellaneous && Verbose) { |
544 if (result != 0) { |
545 if (result != 0) { |
545 warning("Could not retrieve passwd entry: %s\n", |
546 warning("Could not retrieve passwd entry: %s\n", |
546 strerror(result)); |
547 os::strerror(result)); |
547 } |
548 } |
548 else if (p == NULL) { |
549 else if (p == NULL) { |
549 // this check is added to protect against an observed problem |
550 // this check is added to protect against an observed problem |
550 // with getpwuid_r() on RedHat 9 where getpwuid_r returns 0, |
551 // with getpwuid_r() on RedHat 9 where getpwuid_r returns 0, |
551 // indicating success, but has p == NULL. This was observed when |
552 // indicating success, but has p == NULL. This was observed when |
555 // is safe under any condition, but the use of errno in the output |
556 // is safe under any condition, but the use of errno in the output |
556 // message may result in an erroneous message. |
557 // message may result in an erroneous message. |
557 // Bug Id 89052 was opened with RedHat. |
558 // Bug Id 89052 was opened with RedHat. |
558 // |
559 // |
559 warning("Could not retrieve passwd entry: %s\n", |
560 warning("Could not retrieve passwd entry: %s\n", |
560 strerror(errno)); |
561 os::strerror(errno)); |
561 } |
562 } |
562 else { |
563 else { |
563 warning("Could not determine user name: %s\n", |
564 warning("Could not determine user name: %s\n", |
564 p->pw_name == NULL ? "pw_name = NULL" : |
565 p->pw_name == NULL ? "pw_name = NULL" : |
565 "pw_name zero length"); |
566 "pw_name zero length"); |
591 if (errno == ESRCH) { |
592 if (errno == ESRCH) { |
592 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), |
593 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), |
593 "Process not found"); |
594 "Process not found"); |
594 } |
595 } |
595 else /* EPERM */ { |
596 else /* EPERM */ { |
596 THROW_MSG_0(vmSymbols::java_io_IOException(), strerror(errno)); |
597 THROW_MSG_0(vmSymbols::java_io_IOException(), os::strerror(errno)); |
597 } |
598 } |
598 } |
599 } |
599 |
600 |
600 // directory search |
601 // directory search |
601 char* oldest_user = NULL; |
602 char* oldest_user = NULL; |
744 // |
745 // |
745 RESTARTABLE(::unlink(path), result); |
746 RESTARTABLE(::unlink(path), result); |
746 if (PrintMiscellaneous && Verbose && result == OS_ERR) { |
747 if (PrintMiscellaneous && Verbose && result == OS_ERR) { |
747 if (errno != ENOENT) { |
748 if (errno != ENOENT) { |
748 warning("Could not unlink shared memory backing" |
749 warning("Could not unlink shared memory backing" |
749 " store file %s : %s\n", path, strerror(errno)); |
750 " store file %s : %s\n", path, os::strerror(errno)); |
750 } |
751 } |
751 } |
752 } |
752 } |
753 } |
753 |
754 |
754 // Cleanup stale shared memory resources |
755 // Cleanup stale shared memory resources |
847 // we encountered some other failure while attempting |
848 // we encountered some other failure while attempting |
848 // to create the directory |
849 // to create the directory |
849 // |
850 // |
850 if (PrintMiscellaneous && Verbose) { |
851 if (PrintMiscellaneous && Verbose) { |
851 warning("could not create directory %s: %s\n", |
852 warning("could not create directory %s: %s\n", |
852 dirname, strerror(errno)); |
853 dirname, os::strerror(errno)); |
853 } |
854 } |
854 return false; |
855 return false; |
855 } |
856 } |
856 } |
857 } |
857 return true; |
858 return true; |
898 if (result == OS_ERR) { |
899 if (result == OS_ERR) { |
899 if (PrintMiscellaneous && Verbose) { |
900 if (PrintMiscellaneous && Verbose) { |
900 if (errno == ELOOP) { |
901 if (errno == ELOOP) { |
901 warning("file %s is a symlink and is not secure\n", filename); |
902 warning("file %s is a symlink and is not secure\n", filename); |
902 } else { |
903 } else { |
903 warning("could not create file %s: %s\n", filename, strerror(errno)); |
904 warning("could not create file %s: %s\n", filename, os::strerror(errno)); |
904 } |
905 } |
905 } |
906 } |
906 // Close the directory and reset the current working directory. |
907 // Close the directory and reset the current working directory. |
907 close_directory_secure_cwd(dirp, saved_cwd_fd); |
908 close_directory_secure_cwd(dirp, saved_cwd_fd); |
908 |
909 |
922 |
923 |
923 // Truncate the file to get rid of any existing data. |
924 // Truncate the file to get rid of any existing data. |
924 RESTARTABLE(::ftruncate(fd, (off_t)0), result); |
925 RESTARTABLE(::ftruncate(fd, (off_t)0), result); |
925 if (result == OS_ERR) { |
926 if (result == OS_ERR) { |
926 if (PrintMiscellaneous && Verbose) { |
927 if (PrintMiscellaneous && Verbose) { |
927 warning("could not truncate shared memory file: %s\n", strerror(errno)); |
928 warning("could not truncate shared memory file: %s\n", os::strerror(errno)); |
928 } |
929 } |
929 ::close(fd); |
930 ::close(fd); |
930 return -1; |
931 return -1; |
931 } |
932 } |
932 // set the file size |
933 // set the file size |
933 RESTARTABLE(::ftruncate(fd, (off_t)size), result); |
934 RESTARTABLE(::ftruncate(fd, (off_t)size), result); |
934 if (result == OS_ERR) { |
935 if (result == OS_ERR) { |
935 if (PrintMiscellaneous && Verbose) { |
936 if (PrintMiscellaneous && Verbose) { |
936 warning("could not set shared memory file size: %s\n", strerror(errno)); |
937 warning("could not set shared memory file size: %s\n", os::strerror(errno)); |
937 } |
938 } |
938 ::close(fd); |
939 ::close(fd); |
939 return -1; |
940 return -1; |
940 } |
941 } |
941 |
942 |
966 else if (errno == EACCES) { |
967 else if (errno == EACCES) { |
967 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), |
968 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), |
968 "Permission denied"); |
969 "Permission denied"); |
969 } |
970 } |
970 else { |
971 else { |
971 THROW_MSG_0(vmSymbols::java_io_IOException(), strerror(errno)); |
972 THROW_MSG_0(vmSymbols::java_io_IOException(), os::strerror(errno)); |
972 } |
973 } |
973 } |
974 } |
974 int fd = result; |
975 int fd = result; |
975 |
976 |
976 // Check to see if the file is secure. |
977 // Check to see if the file is secure. |
1039 result = ::close(fd); |
1040 result = ::close(fd); |
1040 assert(result != OS_ERR, "could not close file"); |
1041 assert(result != OS_ERR, "could not close file"); |
1041 |
1042 |
1042 if (mapAddress == MAP_FAILED) { |
1043 if (mapAddress == MAP_FAILED) { |
1043 if (PrintMiscellaneous && Verbose) { |
1044 if (PrintMiscellaneous && Verbose) { |
1044 warning("mmap failed - %s\n", strerror(errno)); |
1045 warning("mmap failed - %s\n", os::strerror(errno)); |
1045 } |
1046 } |
1046 remove_file(filename); |
1047 remove_file(filename); |
1047 FREE_C_HEAP_ARRAY(char, filename); |
1048 FREE_C_HEAP_ARRAY(char, filename); |
1048 return NULL; |
1049 return NULL; |
1049 } |
1050 } |
1107 int result; |
1108 int result; |
1108 |
1109 |
1109 RESTARTABLE(::fstat(fd, &statbuf), result); |
1110 RESTARTABLE(::fstat(fd, &statbuf), result); |
1110 if (result == OS_ERR) { |
1111 if (result == OS_ERR) { |
1111 if (PrintMiscellaneous && Verbose) { |
1112 if (PrintMiscellaneous && Verbose) { |
1112 warning("fstat failed: %s\n", strerror(errno)); |
1113 warning("fstat failed: %s\n", os::strerror(errno)); |
1113 } |
1114 } |
1114 THROW_MSG_0(vmSymbols::java_io_IOException(), |
1115 THROW_MSG_0(vmSymbols::java_io_IOException(), |
1115 "Could not determine PerfMemory size"); |
1116 "Could not determine PerfMemory size"); |
1116 } |
1117 } |
1117 |
1118 |
1229 result = ::close(fd); |
1230 result = ::close(fd); |
1230 assert(result != OS_ERR, "could not close file"); |
1231 assert(result != OS_ERR, "could not close file"); |
1231 |
1232 |
1232 if (mapAddress == MAP_FAILED) { |
1233 if (mapAddress == MAP_FAILED) { |
1233 if (PrintMiscellaneous && Verbose) { |
1234 if (PrintMiscellaneous && Verbose) { |
1234 warning("mmap failed: %s\n", strerror(errno)); |
1235 warning("mmap failed: %s\n", os::strerror(errno)); |
1235 } |
1236 } |
1236 THROW_MSG(vmSymbols::java_lang_OutOfMemoryError(), |
1237 THROW_MSG(vmSymbols::java_lang_OutOfMemoryError(), |
1237 "Could not map PerfMemory"); |
1238 "Could not map PerfMemory"); |
1238 } |
1239 } |
1239 |
1240 |