| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 874 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 885 static size_t allocate_alignment = 0; | 885 static size_t allocate_alignment = 0; |
| 886 if (allocate_alignment == 0) { | 886 if (allocate_alignment == 0) { |
| 887 SYSTEM_INFO info; | 887 SYSTEM_INFO info; |
| 888 GetSystemInfo(&info); | 888 GetSystemInfo(&info); |
| 889 allocate_alignment = info.dwAllocationGranularity; | 889 allocate_alignment = info.dwAllocationGranularity; |
| 890 } | 890 } |
| 891 return allocate_alignment; | 891 return allocate_alignment; |
| 892 } | 892 } |
| 893 | 893 |
| 894 | 894 |
| 895 void* OS::GetRandomMmapAddr() { | 895 static void* GetRandomAddr() { |
| 896 Isolate* isolate = Isolate::UncheckedCurrent(); | 896 Isolate* isolate = Isolate::UncheckedCurrent(); |
| 897 // Note that the current isolate isn't set up in a call path via | 897 // Note that the current isolate isn't set up in a call path via |
| 898 // CpuFeatures::Probe. We don't care about randomization in this case because | 898 // CpuFeatures::Probe. We don't care about randomization in this case because |
| 899 // the code page is immediately freed. | 899 // the code page is immediately freed. |
| 900 if (isolate != NULL) { | 900 if (isolate != NULL) { |
| 901 // The address range used to randomize RWX allocations in OS::Allocate | 901 // The address range used to randomize RWX allocations in OS::Allocate |
| 902 // Try not to map pages into the default range that windows loads DLLs | 902 // Try not to map pages into the default range that windows loads DLLs |
| 903 // Use a multiple of 64k to prevent committing unused memory. | 903 // Use a multiple of 64k to prevent committing unused memory. |
| 904 // Note: This does not guarantee RWX regions will be within the | 904 // Note: This does not guarantee RWX regions will be within the |
| 905 // range kAllocationRandomAddressMin to kAllocationRandomAddressMax | 905 // range kAllocationRandomAddressMin to kAllocationRandomAddressMax |
| (...skipping 12 matching lines...) Expand all Loading... |
| 918 return NULL; | 918 return NULL; |
| 919 } | 919 } |
| 920 | 920 |
| 921 | 921 |
| 922 static void* RandomizedVirtualAlloc(size_t size, int action, int protection) { | 922 static void* RandomizedVirtualAlloc(size_t size, int action, int protection) { |
| 923 LPVOID base = NULL; | 923 LPVOID base = NULL; |
| 924 | 924 |
| 925 if (protection == PAGE_EXECUTE_READWRITE || protection == PAGE_NOACCESS) { | 925 if (protection == PAGE_EXECUTE_READWRITE || protection == PAGE_NOACCESS) { |
| 926 // For exectutable pages try and randomize the allocation address | 926 // For exectutable pages try and randomize the allocation address |
| 927 for (size_t attempts = 0; base == NULL && attempts < 3; ++attempts) { | 927 for (size_t attempts = 0; base == NULL && attempts < 3; ++attempts) { |
| 928 base = VirtualAlloc(OS::GetRandomMmapAddr(), size, action, protection); | 928 base = VirtualAlloc(GetRandomAddr(), size, action, protection); |
| 929 } | 929 } |
| 930 } | 930 } |
| 931 | 931 |
| 932 // After three attempts give up and let the OS find an address to use. | 932 // After three attempts give up and let the OS find an address to use. |
| 933 if (base == NULL) base = VirtualAlloc(NULL, size, action, protection); | 933 if (base == NULL) base = VirtualAlloc(NULL, size, action, protection); |
| 934 | 934 |
| 935 return base; | 935 return base; |
| 936 } | 936 } |
| 937 | 937 |
| 938 | 938 |
| (...skipping 1051 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1990 limit_mutex = CreateMutex(); | 1990 limit_mutex = CreateMutex(); |
| 1991 } | 1991 } |
| 1992 | 1992 |
| 1993 | 1993 |
| 1994 void OS::TearDown() { | 1994 void OS::TearDown() { |
| 1995 delete limit_mutex; | 1995 delete limit_mutex; |
| 1996 } | 1996 } |
| 1997 | 1997 |
| 1998 | 1998 |
| 1999 } } // namespace v8::internal | 1999 } } // namespace v8::internal |
| OLD | NEW |