934 RESTARTABLE(::ftruncate(fd, (off_t)size), result);
935 if (result == OS_ERR) {
936 if (PrintMiscellaneous && Verbose) {
937 warning("could not set shared memory file size: %s\n", os::strerror(errno));
938 }
939 ::close(fd);
940 return -1;
941 }
942
943 return fd;
944 }
945
946 // open the shared memory file for the given user and vmid. returns
947 // the file descriptor for the open file or -1 if the file could not
948 // be opened.
949 //
950 static int open_sharedmem_file(const char* filename, int oflags, TRAPS) {
951
952 // open the file
953 int result;
954 // No O_NOFOLLOW defined at buildtime, and it is not documented for open;
955 // so provide a workaround in this case
956 #ifdef O_NOFOLLOW
957 RESTARTABLE(::open(filename, oflags), result);
958 #else
959 result = open_o_nofollow(filename, oflags);
960 #endif
961
962 if (result == OS_ERR) {
963 if (errno == ENOENT) {
964 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(),
965 "Process not found");
966 }
967 else if (errno == EACCES) {
968 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(),
969 "Permission denied");
970 }
971 else {
972 THROW_MSG_0(vmSymbols::java_io_IOException(), os::strerror(errno));
973 }
974 }
975 int fd = result;
976
977 // Check to see if the file is secure.
978 if (!is_file_secure(fd, filename)) {
979 ::close(fd);
980 return -1;
981 }
982
983 return fd;
984 }
985
986 // create a named shared memory region. returns the address of the
987 // memory region on success or NULL on failure. A return value of
988 // NULL will ultimately disable the shared memory feature.
989 //
990 // On AIX, Solaris and Linux, the name space for shared memory objects
991 // is the file system name space.
992 //
993 // A monitoring application attaching to a JVM does not need to know
994 // the file system name of the shared memory object. However, it may
995 // be convenient for applications to discover the existence of newly
996 // created and terminating JVMs by watching the file system name space
997 // for files being created or removed.
998 //
999 static char* mmap_create_shared(size_t size) {
1000
1001 int result;
1002 int fd;
1003 char* mapAddress;
1004
1005 int vmid = os::current_process_id();
1006
1007 char* user_name = get_user_name(geteuid());
1008
1009 if (user_name == NULL)
1010 return NULL;
1011
1012 char* dirname = get_user_tmp_dir(user_name);
1013 char* filename = get_sharedmem_filename(dirname, vmid);
1014 // get the short filename.
1015 char* short_filename = strrchr(filename, '/');
1016 if (short_filename == NULL) {
1017 short_filename = filename;
1018 } else {
1019 short_filename++;
1020 }
1021
1022 // cleanup any stale shared memory files
1023 cleanup_sharedmem_resources(dirname);
1024
1025 assert(((size > 0) && (size % os::vm_page_size() == 0)),
1026 "unexpected PerfMemory region size");
1027
1028 fd = create_sharedmem_resources(dirname, short_filename, size);
1029
1030 FREE_C_HEAP_ARRAY(char, user_name);
1031 FREE_C_HEAP_ARRAY(char, dirname);
1032
1033 if (fd == -1) {
|
934 RESTARTABLE(::ftruncate(fd, (off_t)size), result);
935 if (result == OS_ERR) {
936 if (PrintMiscellaneous && Verbose) {
937 warning("could not set shared memory file size: %s\n", os::strerror(errno));
938 }
939 ::close(fd);
940 return -1;
941 }
942
943 return fd;
944 }
945
946 // open the shared memory file for the given user and vmid. returns
947 // the file descriptor for the open file or -1 if the file could not
948 // be opened.
949 //
950 static int open_sharedmem_file(const char* filename, int oflags, TRAPS) {
951
952 // open the file
953 int result;
954 // provide a workaround in case no O_NOFOLLOW is defined at buildtime
955 #ifdef O_NOFOLLOW
956 RESTARTABLE(::open(filename, oflags), result);
957 #else
958 result = open_o_nofollow(filename, oflags);
959 #endif
960 if (result == OS_ERR) {
961 if (errno == ENOENT) {
962 THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(),
963 "Process not found", OS_ERR);
964 }
965 else if (errno == EACCES) {
966 THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(),
967 "Permission denied", OS_ERR);
968 }
969 else {
970 THROW_MSG_(vmSymbols::java_io_IOException(),
971 os::strerror(errno), OS_ERR);
972 }
973 }
974 int fd = result;
975
976 // Check to see if the file is secure.
977 if (!is_file_secure(fd, filename)) {
978 ::close(fd);
979 return -1;
980 }
981
982 return fd;
983 }
984
985 // create a named shared memory region. returns the address of the
986 // memory region on success or NULL on failure. A return value of
987 // NULL will ultimately disable the shared memory feature.
988 //
989 // On AIX, the name space for shared memory objects
990 // is the file system name space.
991 //
992 // A monitoring application attaching to a JVM does not need to know
993 // the file system name of the shared memory object. However, it may
994 // be convenient for applications to discover the existence of newly
995 // created and terminating JVMs by watching the file system name space
996 // for files being created or removed.
997 //
998 static char* mmap_create_shared(size_t size) {
999
1000 int result;
1001 int fd;
1002 char* mapAddress;
1003
1004 int vmid = os::current_process_id();
1005
1006 char* user_name = get_user_name(geteuid());
1007
1008 if (user_name == NULL)
1009 return NULL;
1010
1011 char* dirname = get_user_tmp_dir(user_name);
1012 char* filename = get_sharedmem_filename(dirname, vmid);
1013
1014 // get the short filename.
1015 char* short_filename = strrchr(filename, '/');
1016 if (short_filename == NULL) {
1017 short_filename = filename;
1018 } else {
1019 short_filename++;
1020 }
1021
1022 // cleanup any stale shared memory files
1023 cleanup_sharedmem_resources(dirname);
1024
1025 assert(((size > 0) && (size % os::vm_page_size() == 0)),
1026 "unexpected PerfMemory region size");
1027
1028 fd = create_sharedmem_resources(dirname, short_filename, size);
1029
1030 FREE_C_HEAP_ARRAY(char, user_name);
1031 FREE_C_HEAP_ARRAY(char, dirname);
1032
1033 if (fd == -1) {
|