[go: nahoru, domu]

blob: cc91c67df902f1aa2fb673fd1849317e8b02bb32 [file] [log] [blame]
jcampan@chromium.org1e312112009-04-21 21:44:121// Copyright (c) 2009 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commitd7cae122008-07-26 21:49:384
5// This file/namespace contains utility functions for enumerating, ending and
6// computing statistics of processes.
7
deanm@google.comdb717282008-08-27 13:48:038#ifndef BASE_PROCESS_UTIL_H_
9#define BASE_PROCESS_UTIL_H_
initial.commitd7cae122008-07-26 21:49:3810
paulg@google.com61659062008-08-06 01:04:1811#include "base/basictypes.h"
12
dkegel@google.comab0e2222008-10-31 20:19:4313#if defined(OS_WIN)
initial.commitd7cae122008-07-26 21:49:3814#include <windows.h>
15#include <tlhelp32.h>
wtc@chromium.org4a34ce02009-08-31 22:25:0016#elif defined(OS_MACOSX)
17// kinfo_proc is defined in <sys/sysctl.h>, but this forward declaration
18// is sufficient for the vector<kinfo_proc> below.
19struct kinfo_proc;
20#elif defined(OS_POSIX)
dkegel@google.comab0e2222008-10-31 20:19:4321#include <dirent.h>
22#include <limits.h>
23#include <sys/types.h>
paulg@google.com61659062008-08-06 01:04:1824#endif
initial.commitd7cae122008-07-26 21:49:3825
paulg@google.com61659062008-08-06 01:04:1826#include <string>
thestig@chromium.org9ec8db02009-07-21 07:00:1327#include <utility>
mark@chromium.org962dd312009-02-05 21:44:1328#include <vector>
paulg@google.com61659062008-08-06 01:04:1829
estade@chromium.orgfb7f9be2008-10-22 01:15:4730#include "base/command_line.h"
dkegel@google.com78c6dd62009-06-08 23:29:1131#include "base/file_path.h"
initial.commitd7cae122008-07-26 21:49:3832#include "base/process.h"
33
paulg@google.com61659062008-08-06 01:04:1834#if defined(OS_WIN)
initial.commitd7cae122008-07-26 21:49:3835typedef PROCESSENTRY32 ProcessEntry;
36typedef IO_COUNTERS IoCounters;
paulg@google.com61659062008-08-06 01:04:1837#elif defined(OS_POSIX)
mark@chromium.org962dd312009-02-05 21:44:1338// TODO(port): we should not rely on a Win32 structure.
dkegel@google.comab0e2222008-10-31 20:19:4339struct ProcessEntry {
viettrungluu@chromium.orga4dc33f2009-10-20 15:09:5540 base::ProcessId pid;
41 base::ProcessId ppid;
mark@chromium.org962dd312009-02-05 21:44:1342 char szExeFile[NAME_MAX + 1];
dkegel@google.comab0e2222008-10-31 20:19:4343};
44
evanm@google.com0b100bc82008-10-14 20:49:1645struct IoCounters {
46 unsigned long long ReadOperationCount;
47 unsigned long long WriteOperationCount;
48 unsigned long long OtherOperationCount;
49 unsigned long long ReadTransferCount;
50 unsigned long long WriteTransferCount;
51 unsigned long long OtherTransferCount;
52};
agl@chromium.org3f04f2b2009-04-30 19:40:0353
54#include "base/file_descriptor_shuffle.h"
initial.commitd7cae122008-07-26 21:49:3855#endif
56
brettw@google.com176aa482008-11-14 03:25:1557namespace base {
initial.commitd7cae122008-07-26 21:49:3858
cpu@google.comeef576f2008-11-03 23:28:0659// A minimalistic but hopefully cross-platform set of exit codes.
60// Do not change the enumeration values or you will break third-party
61// installers.
62enum {
63 PROCESS_END_NORMAL_TERMINATON = 0,
64 PROCESS_END_KILLED_BY_USER = 1,
65 PROCESS_END_PROCESS_WAS_HUNG = 2
66};
67
initial.commitd7cae122008-07-26 21:49:3868// Returns the id of the current process.
phajdan.jr@chromium.org43cf3252009-04-01 09:19:3769ProcessId GetCurrentProcId();
initial.commitd7cae122008-07-26 21:49:3870
erikkay@google.com113ab132008-09-18 20:42:5571// Returns the ProcessHandle of the current process.
72ProcessHandle GetCurrentProcessHandle();
maruel@chromium.org52a261f2009-03-03 15:01:1273
brettw@google.com5986ed22009-02-06 00:19:1774// Converts a PID to a process handle. This handle must be closed by
phajdan.jr@chromium.org6c6cc802009-04-03 17:01:3675// CloseProcessHandle when you are done with it. Returns true on success.
76bool OpenProcessHandle(ProcessId pid, ProcessHandle* handle);
maruel@chromium.org52a261f2009-03-03 15:01:1277
phajdan.jr@chromium.org5d438dbad2009-04-30 08:59:3978// Converts a PID to a process handle. On Windows the handle is opened
79// with more access rights and must only be used by trusted code.
80// You have to close returned handle using CloseProcessHandle. Returns true
81// on success.
82bool OpenPrivilegedProcessHandle(ProcessId pid, ProcessHandle* handle);
83
brettw@google.com5986ed22009-02-06 00:19:1784// Closes the process handle opened by OpenProcessHandle.
85void CloseProcessHandle(ProcessHandle process);
erikkay@google.com113ab132008-09-18 20:42:5586
cpu@google.comeef576f2008-11-03 23:28:0687// Returns the unique ID for the specified process. This is functionally the
initial.commitd7cae122008-07-26 21:49:3888// same as Windows' GetProcessId(), but works on versions of Windows before
89// Win XP SP1 as well.
phajdan.jr@chromium.org43cf3252009-04-01 09:19:3790ProcessId GetProcId(ProcessHandle process);
initial.commitd7cae122008-07-26 21:49:3891
dkegel@google.com78c6dd62009-06-08 23:29:1192#if defined(OS_LINUX)
93// Returns the ID for the parent of the given process.
94ProcessId GetParentProcessId(ProcessHandle process);
95
96// Returns the path to the executable of the given process.
97FilePath GetProcessExecutablePath(ProcessHandle process);
evan@chromium.orgd2ed23832009-09-19 01:57:3998
99// Parse the data found in /proc/<pid>/stat and return the sum of the
100// CPU-related ticks. Returns -1 on parse error.
101// Exposed for testing.
102int ParseProcStatCPU(const std::string& input);
dkegel@google.com78c6dd62009-06-08 23:29:11103#endif
104
jeremy@chromium.orgfa3097a6a52008-12-17 22:41:50105#if defined(OS_POSIX)
jeremy@chromium.org05d4b0a2009-01-29 17:51:51106// Sets all file descriptors to close on exec except for stdin, stdout
107// and stderr.
agl@chromium.org3f04f2b2009-04-30 19:40:03108// TODO(agl): remove this function
109// WARNING: do not use. It's inherently race-prone in the face of
110// multi-threading.
jeremy@chromium.org05d4b0a2009-01-29 17:51:51111void SetAllFDsToCloseOnExec();
agl@chromium.org3f04f2b2009-04-30 19:40:03112// Close all file descriptors, expect those which are a destination in the
113// given multimap. Only call this function in a child process where you know
114// that there aren't any other threads.
115void CloseSuperfluousFds(const base::InjectiveMultimap& saved_map);
jeremy@chromium.orgfa3097a6a52008-12-17 22:41:50116#endif
117
estade@chromium.orgfb7f9be2008-10-22 01:15:47118#if defined(OS_WIN)
initial.commitd7cae122008-07-26 21:49:38119// Runs the given application name with the given command line. Normally, the
120// first command line argument should be the path to the process, and don't
121// forget to quote it.
122//
123// If wait is true, it will block and wait for the other process to finish,
124// otherwise, it will just continue asynchronously.
125//
126// Example (including literal quotes)
127// cmdline = "c:\windows\explorer.exe" -foo "c:\bar\"
128//
129// If process_handle is non-NULL, the process handle of the launched app will be
130// stored there on a successful launch.
131// NOTE: In this case, the caller is responsible for closing the handle so
132// that it doesn't leak!
133bool LaunchApp(const std::wstring& cmdline,
estade@chromium.orgfb7f9be2008-10-22 01:15:47134 bool wait, bool start_hidden, ProcessHandle* process_handle);
135#elif defined(OS_POSIX)
136// Runs the application specified in argv[0] with the command line argv.
jeremy@chromium.orgfa3097a6a52008-12-17 22:41:50137// Before launching all FDs open in the parent process will be marked as
138// close-on-exec. |fds_to_remap| defines a mapping of src fd->dest fd to
139// propagate FDs into the child process.
estade@chromium.orgfb7f9be2008-10-22 01:15:47140//
141// As above, if wait is true, execute synchronously. The pid will be stored
142// in process_handle if that pointer is non-null.
143//
mattm@chromium.orgb74d21b32009-07-17 19:36:00144// Note that the first argument in argv must point to the executable filename.
145// If the filename is not fully specified, PATH will be searched.
jeremy@chromium.orgfa3097a6a52008-12-17 22:41:50146typedef std::vector<std::pair<int, int> > file_handle_mapping_vector;
estade@chromium.orgfb7f9be2008-10-22 01:15:47147bool LaunchApp(const std::vector<std::string>& argv,
jeremy@chromium.orgfa3097a6a52008-12-17 22:41:50148 const file_handle_mapping_vector& fds_to_remap,
estade@chromium.orgfb7f9be2008-10-22 01:15:47149 bool wait, ProcessHandle* process_handle);
stuartmorgan@google.com2aea9e092009-08-06 20:03:01150
thestig@chromium.org9ec8db02009-07-21 07:00:13151// Similar to above, but also (un)set environment variables in child process
152// through |environ|.
153typedef std::vector<std::pair<const char*, const char*> > environment_vector;
154bool LaunchApp(const std::vector<std::string>& argv,
155 const environment_vector& environ,
156 const file_handle_mapping_vector& fds_to_remap,
157 bool wait, ProcessHandle* process_handle);
thestig@chromium.org9ec8db02009-07-21 07:00:13158#endif // defined(OS_POSIX)
estade@chromium.orgfb7f9be2008-10-22 01:15:47159
jcampan@chromium.org1e312112009-04-21 21:44:12160// Executes the application specified by cl. This function delegates to one
estade@chromium.orgfb7f9be2008-10-22 01:15:47161// of the above two platform-specific functions.
162bool LaunchApp(const CommandLine& cl,
initial.commitd7cae122008-07-26 21:49:38163 bool wait, bool start_hidden, ProcessHandle* process_handle);
164
jcampan@chromium.org1e312112009-04-21 21:44:12165// Executes the application specified by |cl| and wait for it to exit. Stores
phajdan.jr@chromium.org1912cfe2009-04-21 08:09:30166// the output (stdout) in |output|. Redirects stderr to /dev/null. Returns true
167// on success (application launched and exited cleanly, with exit code
168// indicating success). |output| is modified only when the function finished
169// successfully.
phajdan.jr@chromium.orgc0b210ee2009-04-17 09:57:52170bool GetAppOutput(const CommandLine& cl, std::string* output);
phajdan.jr@chromium.orgc0b210ee2009-04-17 09:57:52171
initial.commitd7cae122008-07-26 21:49:38172// Used to filter processes by process ID.
173class ProcessFilter {
174 public:
175 // Returns true to indicate set-inclusion and false otherwise. This method
176 // should not have side-effects and should be idempotent.
phajdan.jr@chromium.org43cf3252009-04-01 09:19:37177 virtual bool Includes(ProcessId pid, ProcessId parent_pid) const = 0;
avi@google.comdd950aa2008-08-12 21:24:39178 virtual ~ProcessFilter() { }
initial.commitd7cae122008-07-26 21:49:38179};
180
181// Returns the number of processes on the machine that are running from the
182// given executable name. If filter is non-null, then only processes selected
183// by the filter will be counted.
184int GetProcessCount(const std::wstring& executable_name,
185 const ProcessFilter* filter);
186
187// Attempts to kill all the processes on the current machine that were launched
188// from the given executable name, ending them with the given exit code. If
189// filter is non-null, then only processes selected by the filter are killed.
190// Returns false if all processes were able to be killed off, false if at least
191// one couldn't be killed.
192bool KillProcesses(const std::wstring& executable_name, int exit_code,
193 const ProcessFilter* filter);
194
195// Attempts to kill the process identified by the given process
196// entry structure, giving it the specified exit code. If |wait| is true, wait
197// for the process to be actually terminated before returning.
198// Returns true if this is successful, false otherwise.
stoyan@chromium.orgcd4fd152009-02-09 19:28:41199bool KillProcess(ProcessHandle process, int exit_code, bool wait);
agl@chromium.orgdfe14862009-01-22 01:23:11200#if defined(OS_WIN)
phajdan.jr@chromium.org43cf3252009-04-01 09:19:37201bool KillProcessById(ProcessId process_id, int exit_code, bool wait);
agl@chromium.orgdfe14862009-01-22 01:23:11202#endif
initial.commitd7cae122008-07-26 21:49:38203
204// Get the termination status (exit code) of the process and return true if the
agl@chromium.org140a7cd2009-04-28 01:37:23205// status indicates the process crashed. |child_exited| is set to true iff the
206// child process has terminated. (|child_exited| may be NULL.)
207//
208// On Windows, it is an error to call this if the process hasn't terminated
209// yet. On POSIX, |child_exited| is set correctly since we detect terminate in
210// a different manner on POSIX.
211bool DidProcessCrash(bool* child_exited, ProcessHandle handle);
initial.commitd7cae122008-07-26 21:49:38212
phajdan.jr@chromium.orgc7856632009-01-13 17:38:49213// Waits for process to exit. In POSIX systems, if the process hasn't been
214// signaled then puts the exit code in |exit_code|; otherwise it's considered
215// a failure. On Windows |exit_code| is always filled. Returns true on success,
216// and closes |handle| in any case.
217bool WaitForExitCode(ProcessHandle handle, int* exit_code);
218
initial.commitd7cae122008-07-26 21:49:38219// Wait for all the processes based on the named executable to exit. If filter
220// is non-null, then only processes selected by the filter are waited on.
221// Returns after all processes have exited or wait_milliseconds have expired.
222// Returns true if all the processes exited, false otherwise.
223bool WaitForProcessesToExit(const std::wstring& executable_name,
phajdan.jr@chromium.org743ace42009-06-17 17:23:51224 int64 wait_milliseconds,
initial.commitd7cae122008-07-26 21:49:38225 const ProcessFilter* filter);
226
estade@chromium.orgfb7f9be2008-10-22 01:15:47227// Wait for a single process to exit. Return true if it exited cleanly within
228// the given time limit.
229bool WaitForSingleProcess(ProcessHandle handle,
phajdan.jr@chromium.org743ace42009-06-17 17:23:51230 int64 wait_milliseconds);
estade@chromium.orgfb7f9be2008-10-22 01:15:47231
phajdan.jr@chromium.org076bf0b62009-03-04 20:57:58232// Returns true when |wait_milliseconds| have elapsed and the process
233// is still running.
phajdan.jr@chromium.org743ace42009-06-17 17:23:51234bool CrashAwareSleep(ProcessHandle handle, int64 wait_milliseconds);
phajdan.jr@chromium.org076bf0b62009-03-04 20:57:58235
initial.commitd7cae122008-07-26 21:49:38236// Waits a certain amount of time (can be 0) for all the processes with a given
237// executable name to exit, then kills off any of them that are still around.
238// If filter is non-null, then only processes selected by the filter are waited
239// on. Killed processes are ended with the given exit code. Returns false if
240// any processes needed to be killed, true if they all exited cleanly within
241// the wait_milliseconds delay.
242bool CleanupProcesses(const std::wstring& executable_name,
phajdan.jr@chromium.org743ace42009-06-17 17:23:51243 int64 wait_milliseconds,
initial.commitd7cae122008-07-26 21:49:38244 int exit_code,
245 const ProcessFilter* filter);
246
247// This class provides a way to iterate through the list of processes
248// on the current machine that were started from the given executable
249// name. To use, create an instance and then call NextProcessEntry()
250// until it returns false.
251class NamedProcessIterator {
252 public:
253 NamedProcessIterator(const std::wstring& executable_name,
254 const ProcessFilter* filter);
255 ~NamedProcessIterator();
256
257 // If there's another process that matches the given executable name,
258 // returns a const pointer to the corresponding PROCESSENTRY32.
259 // If there are no more matching processes, returns NULL.
260 // The returned pointer will remain valid until NextProcessEntry()
261 // is called again or this NamedProcessIterator goes out of scope.
262 const ProcessEntry* NextProcessEntry();
263
264 private:
265 // Determines whether there's another process (regardless of executable)
266 // left in the list of all processes. Returns true and sets entry_ to
267 // that process's info if there is one, false otherwise.
268 bool CheckForNextProcess();
269
270 bool IncludeEntry();
271
272 // Initializes a PROCESSENTRY32 data structure so that it's ready for
273 // use with Process32First/Process32Next.
274 void InitProcessEntry(ProcessEntry* entry);
275
276 std::wstring executable_name_;
dkegel@google.comab0e2222008-10-31 20:19:43277
278#if defined(OS_WIN)
initial.commitd7cae122008-07-26 21:49:38279 HANDLE snapshot_;
initial.commitd7cae122008-07-26 21:49:38280 bool started_iteration_;
dkegel@google.comab0e2222008-10-31 20:19:43281#elif defined(OS_MACOSX)
mark@chromium.org962dd312009-02-05 21:44:13282 std::vector<kinfo_proc> kinfo_procs_;
283 size_t index_of_kinfo_proc_;
wtc@chromium.org4a34ce02009-08-31 22:25:00284#elif defined(OS_POSIX)
285 DIR *procfs_dir_;
dkegel@google.comab0e2222008-10-31 20:19:43286#endif
initial.commitd7cae122008-07-26 21:49:38287 ProcessEntry entry_;
288 const ProcessFilter* filter_;
289
290 DISALLOW_EVIL_CONSTRUCTORS(NamedProcessIterator);
291};
292
293// Working Set (resident) memory usage broken down by
agl@chromium.org54fd1d32009-09-01 00:12:58294//
295// On Windows:
initial.commitd7cae122008-07-26 21:49:38296// priv (private): These pages (kbytes) cannot be shared with any other process.
297// shareable: These pages (kbytes) can be shared with other processes under
298// the right circumstances.
299// shared : These pages (kbytes) are currently shared with at least one
300// other process.
agl@chromium.org54fd1d32009-09-01 00:12:58301//
302// On Linux:
303// priv: Pages mapped only by this process
304// shared: PSS or 0 if the kernel doesn't support this
305// shareable: 0
initial.commitd7cae122008-07-26 21:49:38306struct WorkingSetKBytes {
agl@chromium.org54fd1d32009-09-01 00:12:58307 WorkingSetKBytes() : priv(0), shareable(0), shared(0) {}
initial.commitd7cae122008-07-26 21:49:38308 size_t priv;
309 size_t shareable;
310 size_t shared;
311};
312
313// Committed (resident + paged) memory usage broken down by
314// private: These pages cannot be shared with any other process.
315// mapped: These pages are mapped into the view of a section (backed by
316// pagefile.sys)
317// image: These pages are mapped into the view of an image section (backed by
318// file system)
319struct CommittedKBytes {
agl@chromium.org54fd1d32009-09-01 00:12:58320 CommittedKBytes() : priv(0), mapped(0), image(0) {}
initial.commitd7cae122008-07-26 21:49:38321 size_t priv;
322 size_t mapped;
323 size_t image;
324};
325
326// Free memory (Megabytes marked as free) in the 2G process address space.
327// total : total amount in megabytes marked as free. Maximum value is 2048.
328// largest : size of the largest contiguous amount of memory found. It is
329// always smaller or equal to FreeMBytes::total.
330// largest_ptr: starting address of the largest memory block.
331struct FreeMBytes {
332 size_t total;
333 size_t largest;
334 void* largest_ptr;
335};
336
evan@chromium.orgd2ed23832009-09-19 01:57:39337// Convert a POSIX timeval to microseconds.
338int64 TimeValToMicroseconds(const struct timeval& tv);
339
initial.commitd7cae122008-07-26 21:49:38340// Provides performance metrics for a specified process (CPU usage, memory and
341// IO counters). To use it, invoke CreateProcessMetrics() to get an instance
342// for a specific process, then access the information with the different get
343// methods.
344class ProcessMetrics {
345 public:
346 // Creates a ProcessMetrics for the specified process.
347 // The caller owns the returned object.
348 static ProcessMetrics* CreateProcessMetrics(ProcessHandle process);
349
350 ~ProcessMetrics();
351
352 // Returns the current space allocated for the pagefile, in bytes (these pages
thomasvl@chromium.org796da7c2009-06-11 12:45:45353 // may or may not be in memory). On Linux, this returns the total virtual
354 // memory size.
phajdan.jr@chromium.orgd043c2cc2009-03-25 18:30:45355 size_t GetPagefileUsage() const;
initial.commitd7cae122008-07-26 21:49:38356 // Returns the peak space allocated for the pagefile, in bytes.
phajdan.jr@chromium.orgd043c2cc2009-03-25 18:30:45357 size_t GetPeakPagefileUsage() const;
thomasvl@chromium.org796da7c2009-06-11 12:45:45358 // Returns the current working set size, in bytes. On Linux, this returns
359 // the resident set size.
phajdan.jr@chromium.orgd043c2cc2009-03-25 18:30:45360 size_t GetWorkingSetSize() const;
tc@google.com0c557f12009-05-11 23:35:52361 // Returns the peak working set size, in bytes.
362 size_t GetPeakWorkingSetSize() const;
initial.commitd7cae122008-07-26 21:49:38363 // Returns private usage, in bytes. Private bytes is the amount
364 // of memory currently allocated to a process that cannot be shared.
365 // Note: returns 0 on unsupported OSes: prior to XP SP2.
phajdan.jr@chromium.orgd043c2cc2009-03-25 18:30:45366 size_t GetPrivateBytes() const;
initial.commitd7cae122008-07-26 21:49:38367 // Fills a CommittedKBytes with both resident and paged
368 // memory usage as per definition of CommittedBytes.
phajdan.jr@chromium.orgd043c2cc2009-03-25 18:30:45369 void GetCommittedKBytes(CommittedKBytes* usage) const;
initial.commitd7cae122008-07-26 21:49:38370 // Fills a WorkingSetKBytes containing resident private and shared memory
371 // usage in bytes, as per definition of WorkingSetBytes.
phajdan.jr@chromium.orgd043c2cc2009-03-25 18:30:45372 bool GetWorkingSetKBytes(WorkingSetKBytes* ws_usage) const;
initial.commitd7cae122008-07-26 21:49:38373
374 // Computes the current process available memory for allocation.
375 // It does a linear scan of the address space querying each memory region
376 // for its free (unallocated) status. It is useful for estimating the memory
377 // load and fragmentation.
phajdan.jr@chromium.orgd043c2cc2009-03-25 18:30:45378 bool CalculateFreeMemory(FreeMBytes* free) const;
initial.commitd7cae122008-07-26 21:49:38379
380 // Returns the CPU usage in percent since the last time this method was
381 // called. The first time this method is called it returns 0 and will return
382 // the actual CPU info on subsequent calls.
383 // Note that on multi-processor machines, the CPU usage value is for all
384 // CPUs. So if you have 2 CPUs and your process is using all the cycles
385 // of 1 CPU and not the other CPU, this method returns 50.
386 int GetCPUUsage();
387
388 // Retrieves accounting information for all I/O operations performed by the
389 // process.
390 // If IO information is retrieved successfully, the function returns true
391 // and fills in the IO_COUNTERS passed in. The function returns false
392 // otherwise.
phajdan.jr@chromium.orgd043c2cc2009-03-25 18:30:45393 bool GetIOCounters(IoCounters* io_counters) const;
initial.commitd7cae122008-07-26 21:49:38394
395 private:
396 explicit ProcessMetrics(ProcessHandle process);
397
398 ProcessHandle process_;
399
400 int processor_count_;
401
evan@chromium.orgd2ed23832009-09-19 01:57:39402 // Used to store the previous times and CPU usage counts so we can
403 // compute the CPU usage between calls.
initial.commitd7cae122008-07-26 21:49:38404 int64 last_time_;
405 int64 last_system_time_;
406
evan@chromium.orgd2ed23832009-09-19 01:57:39407#if defined(OS_LINUX)
408 // Jiffie count at the last_time_ we updated.
409 int last_cpu_;
410#endif
411
initial.commitd7cae122008-07-26 21:49:38412 DISALLOW_EVIL_CONSTRUCTORS(ProcessMetrics);
413};
414
415// Enables low fragmentation heap (LFH) for every heaps of this process. This
416// won't have any effect on heaps created after this function call. It will not
417// modify data allocated in the heaps before calling this function. So it is
418// better to call this function early in initialization and again before
419// entering the main loop.
420// Note: Returns true on Windows 2000 without doing anything.
421bool EnableLowFragmentationHeap();
422
maruel@chromium.orgd6fc9fd2009-10-27 18:03:47423// Enables 'terminate on heap corruption' flag. Helps protect against heap
maruel@google.comc9d40872008-09-24 12:58:37424// overflow. Has no effect if the OS doesn't provide the necessary facility.
425void EnableTerminationOnHeapCorruption();
426
maruel@chromium.orgd6fc9fd2009-10-27 18:03:47427#if defined(UNIT_TEST)
428// Enables stack dump to console output on exception and signals.
429// When enabled, the process will quit immediately. This is meant to be used in
430// unit_tests only!
431bool EnableInProcessStackDumping();
432#endif // defined(UNIT_TEST)
433
deanm@google.comdb717282008-08-27 13:48:03434// If supported on the platform, and the user has sufficent rights, increase
435// the current process's scheduling priority to a high priority.
436void RaiseProcessToHighPriority();
437
mark@chromium.orge9a8c19f2009-09-03 21:27:36438#if defined(OS_MACOSX)
439// Restore the default exception handler, setting it to Apple Crash Reporter
440// (ReportCrash). When forking and execing a new process, the child will
441// inherit the parent's exception ports, which may be set to the Breakpad
442// instance running inside the parent. The parent's Breakpad instance should
443// not handle the child's exceptions. Calling RestoreDefaultExceptionHandler
444// in the child after forking will restore the standard exception handler.
445// See http://crbug.com/20371/ for more details.
446void RestoreDefaultExceptionHandler();
447#endif
448
brettw@google.com176aa482008-11-14 03:25:15449} // namespace base
initial.commitd7cae122008-07-26 21:49:38450
deanm@google.comdb717282008-08-27 13:48:03451#endif // BASE_PROCESS_UTIL_H_