Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
llvm-epi-0.8
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Roger Ferrer
llvm-epi-0.8
Commits
a531d04b
Commit
a531d04b
authored
18 years ago
by
Jeff Cohen
Browse files
Options
Downloads
Patches
Plain Diff
Implement memoryLimit on Windows.
llvm-svn: 34922
parent
50bf51e8
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
llvm/lib/System/Win32/Program.inc
+31
-6
31 additions, 6 deletions
llvm/lib/System/Win32/Program.inc
llvm/lib/System/Win32/Win32.h
+21
-0
21 additions, 0 deletions
llvm/lib/System/Win32/Win32.h
with
52 additions
and
6 deletions
llvm/lib/System/Win32/Program.inc
+
31
−
6
View file @
a531d04b
...
@@ -93,8 +93,8 @@ static HANDLE RedirectIO(const Path *path, int fd, std::string* ErrMsg) {
...
@@ -93,8 +93,8 @@ static HANDLE RedirectIO(const Path *path, int fd, std::string* ErrMsg) {
if
(
h
==
INVALID_HANDLE_VALUE
)
{
if
(
h
==
INVALID_HANDLE_VALUE
)
{
MakeErrMsg
(
ErrMsg
,
std
::
string
(
fname
)
+
": Can't open file for "
+
MakeErrMsg
(
ErrMsg
,
std
::
string
(
fname
)
+
": Can't open file for "
+
(
fd
?
"input: "
:
"output: "
));
(
fd
?
"input: "
:
"output: "
));
return
h
;
}
}
return
h
;
return
h
;
}
}
...
@@ -179,7 +179,7 @@ Program::ExecuteAndWait(const Path& path,
...
@@ -179,7 +179,7 @@ Program::ExecuteAndWait(const Path& path,
0
,
TRUE
,
DUPLICATE_SAME_ACCESS
);
0
,
TRUE
,
DUPLICATE_SAME_ACCESS
);
}
}
}
}
PROCESS_INFORMATION
pi
;
PROCESS_INFORMATION
pi
;
memset
(
&
pi
,
0
,
sizeof
(
pi
));
memset
(
&
pi
,
0
,
sizeof
(
pi
));
...
@@ -204,6 +204,35 @@ Program::ExecuteAndWait(const Path& path,
...
@@ -204,6 +204,35 @@ Program::ExecuteAndWait(const Path& path,
return
-
1
;
return
-
1
;
}
}
// Make sure these get closed no matter what.
AutoHandle
hProcess
(
pi
.
hProcess
);
AutoHandle
hThread
(
pi
.
hThread
);
// Assign the process to a job if a memory limit is defined.
AutoHandle
hJob
(
0
);
if
(
memoryLimit
!=
0
)
{
hJob
=
CreateJobObject
(
0
,
0
);
bool
success
=
false
;
if
(
hJob
!=
0
)
{
JOBOBJECT_EXTENDED_LIMIT_INFORMATION
jeli
;
memset
(
&
jeli
,
0
,
sizeof
(
jeli
));
jeli
.
BasicLimitInformation
.
LimitFlags
=
JOB_OBJECT_LIMIT_PROCESS_MEMORY
;
jeli
.
ProcessMemoryLimit
=
memoryLimit
*
1048576
;
if
(
SetInformationJobObject
(
hJob
,
JobObjectExtendedLimitInformation
,
&
jeli
,
sizeof
(
jeli
)))
{
if
(
AssignProcessToJobObject
(
hJob
,
pi
.
hProcess
))
success
=
true
;
}
}
if
(
!
success
)
{
SetLastError
(
GetLastError
());
MakeErrMsg
(
ErrMsg
,
std
::
string
(
"Unable to set memory limit"
));
TerminateProcess
(
pi
.
hProcess
,
1
);
WaitForSingleObject
(
pi
.
hProcess
,
INFINITE
);
return
-
1
;
}
}
// Wait for it to terminate.
// Wait for it to terminate.
DWORD
millisecondsToWait
=
INFINITE
;
DWORD
millisecondsToWait
=
INFINITE
;
if
(
secondsToWait
>
0
)
if
(
secondsToWait
>
0
)
...
@@ -223,10 +252,6 @@ Program::ExecuteAndWait(const Path& path,
...
@@ -223,10 +252,6 @@ Program::ExecuteAndWait(const Path& path,
rc
=
GetExitCodeProcess
(
pi
.
hProcess
,
&
status
);
rc
=
GetExitCodeProcess
(
pi
.
hProcess
,
&
status
);
err
=
GetLastError
();
err
=
GetLastError
();
// Done with the handles; go close them.
CloseHandle
(
pi
.
hProcess
);
CloseHandle
(
pi
.
hThread
);
if
(
!
rc
)
{
if
(
!
rc
)
{
SetLastError
(
err
);
SetLastError
(
err
);
MakeErrMsg
(
ErrMsg
,
std
::
string
(
"Failed getting status for program '"
)
+
MakeErrMsg
(
ErrMsg
,
std
::
string
(
"Failed getting status for program '"
)
+
...
...
This diff is collapsed.
Click to expand it.
llvm/lib/System/Win32/Win32.h
+
21
−
0
View file @
a531d04b
...
@@ -34,3 +34,24 @@ inline bool MakeErrMsg(std::string* ErrMsg, const std::string& prefix) {
...
@@ -34,3 +34,24 @@ inline bool MakeErrMsg(std::string* ErrMsg, const std::string& prefix) {
LocalFree
(
buffer
);
LocalFree
(
buffer
);
return
true
;
return
true
;
}
}
class
AutoHandle
{
HANDLE
handle
;
public:
AutoHandle
(
HANDLE
h
)
:
handle
(
h
)
{}
~
AutoHandle
()
{
if
(
handle
)
CloseHandle
(
handle
);
}
operator
HANDLE
()
{
return
handle
;
}
AutoHandle
&
operator
=
(
HANDLE
h
)
{
handle
=
h
;
return
*
this
;
}
};
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment