OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "sandbox/win/src/job.h" | 5 #include "sandbox/win/src/job.h" |
6 | 6 |
7 #include "base/win/windows_version.h" | 7 #include "base/win/windows_version.h" |
8 #include "sandbox/win/src/restricted_token.h" | 8 #include "sandbox/win/src/restricted_token.h" |
9 | 9 |
10 namespace sandbox { | 10 namespace sandbox { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 jbur.UIRestrictionsClass |= JOB_OBJECT_UILIMIT_DISPLAYSETTINGS; | 45 jbur.UIRestrictionsClass |= JOB_OBJECT_UILIMIT_DISPLAYSETTINGS; |
46 jeli.BasicLimitInformation.LimitFlags |= JOB_OBJECT_LIMIT_ACTIVE_PROCESS; | 46 jeli.BasicLimitInformation.LimitFlags |= JOB_OBJECT_LIMIT_ACTIVE_PROCESS; |
47 jeli.BasicLimitInformation.ActiveProcessLimit = 1; | 47 jeli.BasicLimitInformation.ActiveProcessLimit = 1; |
48 } | 48 } |
49 case JOB_INTERACTIVE: { | 49 case JOB_INTERACTIVE: { |
50 jbur.UIRestrictionsClass |= JOB_OBJECT_UILIMIT_SYSTEMPARAMETERS; | 50 jbur.UIRestrictionsClass |= JOB_OBJECT_UILIMIT_SYSTEMPARAMETERS; |
51 jbur.UIRestrictionsClass |= JOB_OBJECT_UILIMIT_DESKTOP; | 51 jbur.UIRestrictionsClass |= JOB_OBJECT_UILIMIT_DESKTOP; |
52 jbur.UIRestrictionsClass |= JOB_OBJECT_UILIMIT_EXITWINDOWS; | 52 jbur.UIRestrictionsClass |= JOB_OBJECT_UILIMIT_EXITWINDOWS; |
53 } | 53 } |
54 case JOB_UNPROTECTED: { | 54 case JOB_UNPROTECTED: { |
55 // The JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE flag is not supported on | 55 if (process_memory_limit_) { |
56 // Windows 2000. We need a mechanism on Windows 2000 to ensure | 56 jeli.BasicLimitInformation.LimitFlags |= |
57 // that processes in the job are terminated when the job is closed | 57 JOB_OBJECT_LIMIT_PROCESS_MEMORY; |
58 if (base::win::GetVersion() == base::win::VERSION_PRE_XP) | 58 jeli.ProcessMemoryLimit = process_memory_limit_; |
59 break; | 59 } |
60 | 60 |
61 jeli.BasicLimitInformation.LimitFlags |= | 61 jeli.BasicLimitInformation.LimitFlags |= |
62 JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE; | 62 JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE; |
63 break; | 63 break; |
64 } | 64 } |
65 default: { | 65 default: { |
66 return ERROR_BAD_ARGUMENTS; | 66 return ERROR_BAD_ARGUMENTS; |
67 } | 67 } |
68 } | 68 } |
69 | 69 |
70 if (FALSE == ::SetInformationJobObject(job_handle_, | 70 if (FALSE == ::SetInformationJobObject(job_handle_, |
71 JobObjectExtendedLimitInformation, | 71 JobObjectExtendedLimitInformation, |
72 &jeli, | 72 &jeli, |
73 sizeof(jeli))) { | 73 sizeof(jeli))) { |
74 return ::GetLastError(); | 74 return ::GetLastError(); |
75 } | 75 } |
76 | 76 |
77 jbur.UIRestrictionsClass = jbur.UIRestrictionsClass & (~ui_exceptions); | 77 jbur.UIRestrictionsClass = jbur.UIRestrictionsClass & (~ui_exceptions); |
78 if (FALSE == ::SetInformationJobObject(job_handle_, | 78 if (FALSE == ::SetInformationJobObject(job_handle_, |
79 JobObjectBasicUIRestrictions, | 79 JobObjectBasicUIRestrictions, |
80 &jbur, | 80 &jbur, |
81 sizeof(jbur))) { | 81 sizeof(jbur))) { |
82 return ::GetLastError(); | 82 return ::GetLastError(); |
83 } | 83 } |
84 | 84 |
85 return ERROR_SUCCESS; | 85 return ERROR_SUCCESS; |
86 } | 86 } |
87 | 87 |
| 88 DWORD Job::SetProcessMemoryLimit(size_t limit) { |
| 89 if (job_handle_) |
| 90 return ERROR_ALREADY_INITIALIZED; |
| 91 |
| 92 process_memory_limit_ = limit; |
| 93 return ERROR_SUCCESS; |
| 94 } |
| 95 |
88 DWORD Job::UserHandleGrantAccess(HANDLE handle) { | 96 DWORD Job::UserHandleGrantAccess(HANDLE handle) { |
89 if (!job_handle_) | 97 if (!job_handle_) |
90 return ERROR_NO_DATA; | 98 return ERROR_NO_DATA; |
91 | 99 |
92 if (!::UserHandleGrantAccess(handle, | 100 if (!::UserHandleGrantAccess(handle, |
93 job_handle_, | 101 job_handle_, |
94 TRUE)) { // Access allowed. | 102 TRUE)) { // Access allowed. |
95 return ::GetLastError(); | 103 return ::GetLastError(); |
96 } | 104 } |
97 | 105 |
(...skipping 10 matching lines...) Expand all Loading... |
108 if (!job_handle_) | 116 if (!job_handle_) |
109 return ERROR_NO_DATA; | 117 return ERROR_NO_DATA; |
110 | 118 |
111 if (FALSE == ::AssignProcessToJobObject(job_handle_, process_handle)) | 119 if (FALSE == ::AssignProcessToJobObject(job_handle_, process_handle)) |
112 return ::GetLastError(); | 120 return ::GetLastError(); |
113 | 121 |
114 return ERROR_SUCCESS; | 122 return ERROR_SUCCESS; |
115 } | 123 } |
116 | 124 |
117 } // namespace sandbox | 125 } // namespace sandbox |
OLD | NEW |