< prev index next >

src/hotspot/os/solaris/os_solaris.cpp

Print this page
rev 51957 : 8224221: add memprotect calls to event log
Reviewed-by: dholmes, mdoerr


2687 
2688   // Give back the unused reserved pieces.
2689 
2690   for (int j = 0; j < i; ++j) {
2691     if (base[j] != NULL) {
2692       unmap_memory(base[j], size[j]);
2693     }
2694   }
2695 
2696   return (i < max_tries) ? requested_addr : NULL;
2697 }
2698 
2699 bool os::pd_release_memory(char* addr, size_t bytes) {
2700   size_t size = bytes;
2701   return munmap(addr, size) == 0;
2702 }
2703 
2704 static bool solaris_mprotect(char* addr, size_t bytes, int prot) {
2705   assert(addr == (char*)align_down((uintptr_t)addr, os::vm_page_size()),
2706          "addr must be page aligned");

2707   int retVal = mprotect(addr, bytes, prot);
2708   return retVal == 0;
2709 }
2710 
2711 // Protect memory (Used to pass readonly pages through
2712 // JNI GetArray<type>Elements with empty arrays.)
2713 // Also, used for serialization page and for compressed oops null pointer
2714 // checking.
2715 bool os::protect_memory(char* addr, size_t bytes, ProtType prot,
2716                         bool is_committed) {
2717   unsigned int p = 0;
2718   switch (prot) {
2719   case MEM_PROT_NONE: p = PROT_NONE; break;
2720   case MEM_PROT_READ: p = PROT_READ; break;
2721   case MEM_PROT_RW:   p = PROT_READ|PROT_WRITE; break;
2722   case MEM_PROT_RWX:  p = PROT_READ|PROT_WRITE|PROT_EXEC; break;
2723   default:
2724     ShouldNotReachHere();
2725   }
2726   // is_committed is unused.


4287     // atexit functions can be delayed until process exit time, which
4288     // can be problematic for embedded VM situations. Embedded VMs should
4289     // call DestroyJavaVM() to assure that VM resources are released.
4290 
4291     // note: perfMemory_exit_helper atexit function may be removed in
4292     // the future if the appropriate cleanup code can be added to the
4293     // VM_Exit VMOperation's doit method.
4294     if (atexit(perfMemory_exit_helper) != 0) {
4295       warning("os::init2 atexit(perfMemory_exit_helper) failed");
4296     }
4297   }
4298 
4299   // Init pset_loadavg function pointer
4300   init_pset_getloadavg_ptr();
4301 
4302   return JNI_OK;
4303 }
4304 
4305 // Mark the polling page as unreadable
4306 void os::make_polling_page_unreadable(void) {

4307   if (mprotect((char *)_polling_page, page_size, PROT_NONE) != 0) {
4308     fatal("Could not disable polling page");
4309   }
4310 }
4311 
4312 // Mark the polling page as readable
4313 void os::make_polling_page_readable(void) {

4314   if (mprotect((char *)_polling_page, page_size, PROT_READ) != 0) {
4315     fatal("Could not enable polling page");
4316   }
4317 }
4318 
4319 // Is a (classpath) directory empty?
4320 bool os::dir_is_empty(const char* path) {
4321   DIR *dir = NULL;
4322   struct dirent *ptr;
4323 
4324   dir = opendir(path);
4325   if (dir == NULL) return true;
4326 
4327   // Scan the directory
4328   bool result = true;
4329   while (result && (ptr = readdir(dir)) != NULL) {
4330     if (strcmp(ptr->d_name, ".") != 0 && strcmp(ptr->d_name, "..") != 0) {
4331       result = false;
4332     }
4333   }




2687 
2688   // Give back the unused reserved pieces.
2689 
2690   for (int j = 0; j < i; ++j) {
2691     if (base[j] != NULL) {
2692       unmap_memory(base[j], size[j]);
2693     }
2694   }
2695 
2696   return (i < max_tries) ? requested_addr : NULL;
2697 }
2698 
2699 bool os::pd_release_memory(char* addr, size_t bytes) {
2700   size_t size = bytes;
2701   return munmap(addr, size) == 0;
2702 }
2703 
2704 static bool solaris_mprotect(char* addr, size_t bytes, int prot) {
2705   assert(addr == (char*)align_down((uintptr_t)addr, os::vm_page_size()),
2706          "addr must be page aligned");
2707   Events::log(NULL, "Protecting memory [" INTPTR_FORMAT "," INTPTR_FORMAT "] with protection modes %x", p2i(addr), p2i(addr+bytes), prot);
2708   int retVal = mprotect(addr, bytes, prot);
2709   return retVal == 0;
2710 }
2711 
2712 // Protect memory (Used to pass readonly pages through
2713 // JNI GetArray<type>Elements with empty arrays.)
2714 // Also, used for serialization page and for compressed oops null pointer
2715 // checking.
2716 bool os::protect_memory(char* addr, size_t bytes, ProtType prot,
2717                         bool is_committed) {
2718   unsigned int p = 0;
2719   switch (prot) {
2720   case MEM_PROT_NONE: p = PROT_NONE; break;
2721   case MEM_PROT_READ: p = PROT_READ; break;
2722   case MEM_PROT_RW:   p = PROT_READ|PROT_WRITE; break;
2723   case MEM_PROT_RWX:  p = PROT_READ|PROT_WRITE|PROT_EXEC; break;
2724   default:
2725     ShouldNotReachHere();
2726   }
2727   // is_committed is unused.


4288     // atexit functions can be delayed until process exit time, which
4289     // can be problematic for embedded VM situations. Embedded VMs should
4290     // call DestroyJavaVM() to assure that VM resources are released.
4291 
4292     // note: perfMemory_exit_helper atexit function may be removed in
4293     // the future if the appropriate cleanup code can be added to the
4294     // VM_Exit VMOperation's doit method.
4295     if (atexit(perfMemory_exit_helper) != 0) {
4296       warning("os::init2 atexit(perfMemory_exit_helper) failed");
4297     }
4298   }
4299 
4300   // Init pset_loadavg function pointer
4301   init_pset_getloadavg_ptr();
4302 
4303   return JNI_OK;
4304 }
4305 
4306 // Mark the polling page as unreadable
4307 void os::make_polling_page_unreadable(void) {
4308   Events::log(NULL, "Protecting polling page " INTPTR_FORMAT " with PROT_NONE", p2i(_polling_page));
4309   if (mprotect((char *)_polling_page, page_size, PROT_NONE) != 0) {
4310     fatal("Could not disable polling page");
4311   }
4312 }
4313 
4314 // Mark the polling page as readable
4315 void os::make_polling_page_readable(void) {
4316   Events::log(NULL, "Protecting polling page " INTPTR_FORMAT " with PROT_READ", p2i(_polling_page));
4317   if (mprotect((char *)_polling_page, page_size, PROT_READ) != 0) {
4318     fatal("Could not enable polling page");
4319   }
4320 }
4321 
4322 // Is a (classpath) directory empty?
4323 bool os::dir_is_empty(const char* path) {
4324   DIR *dir = NULL;
4325   struct dirent *ptr;
4326 
4327   dir = opendir(path);
4328   if (dir == NULL) return true;
4329 
4330   // Scan the directory
4331   bool result = true;
4332   while (result && (ptr = readdir(dir)) != NULL) {
4333     if (strcmp(ptr->d_name, ".") != 0 && strcmp(ptr->d_name, "..") != 0) {
4334       result = false;
4335     }
4336   }


< prev index next >