security/sandbox/chromium/base/process/process_handle.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/security/sandbox/chromium/base/process/process_handle.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,96 @@
     1.4 +// Copyright (c) 2013 The Chromium Authors. All rights reserved.
     1.5 +// Use of this source code is governed by a BSD-style license that can be
     1.6 +// found in the LICENSE file.
     1.7 +
     1.8 +#ifndef BASE_PROCESS_PROCESS_HANDLE_H_
     1.9 +#define BASE_PROCESS_PROCESS_HANDLE_H_
    1.10 +
    1.11 +#include "base/base_export.h"
    1.12 +#include "base/basictypes.h"
    1.13 +#include "base/files/file_path.h"
    1.14 +#include "build/build_config.h"
    1.15 +
    1.16 +#include <sys/types.h>
    1.17 +#if defined(OS_WIN)
    1.18 +#include <windows.h>
    1.19 +#endif
    1.20 +
    1.21 +namespace base {
    1.22 +
    1.23 +// ProcessHandle is a platform specific type which represents the underlying OS
    1.24 +// handle to a process.
    1.25 +// ProcessId is a number which identifies the process in the OS.
    1.26 +#if defined(OS_WIN)
    1.27 +typedef HANDLE ProcessHandle;
    1.28 +typedef DWORD ProcessId;
    1.29 +typedef HANDLE UserTokenHandle;
    1.30 +const ProcessHandle kNullProcessHandle = NULL;
    1.31 +const ProcessId kNullProcessId = 0;
    1.32 +#elif defined(OS_POSIX)
    1.33 +// On POSIX, our ProcessHandle will just be the PID.
    1.34 +typedef pid_t ProcessHandle;
    1.35 +typedef pid_t ProcessId;
    1.36 +const ProcessHandle kNullProcessHandle = 0;
    1.37 +const ProcessId kNullProcessId = 0;
    1.38 +#endif  // defined(OS_WIN)
    1.39 +
    1.40 +// Returns the id of the current process.
    1.41 +BASE_EXPORT ProcessId GetCurrentProcId();
    1.42 +
    1.43 +// Returns the ProcessHandle of the current process.
    1.44 +BASE_EXPORT ProcessHandle GetCurrentProcessHandle();
    1.45 +
    1.46 +// Converts a PID to a process handle. This handle must be closed by
    1.47 +// CloseProcessHandle when you are done with it. Returns true on success.
    1.48 +BASE_EXPORT bool OpenProcessHandle(ProcessId pid, ProcessHandle* handle);
    1.49 +
    1.50 +// Converts a PID to a process handle. On Windows the handle is opened
    1.51 +// with more access rights and must only be used by trusted code.
    1.52 +// You have to close returned handle using CloseProcessHandle. Returns true
    1.53 +// on success.
    1.54 +// TODO(sanjeevr): Replace all calls to OpenPrivilegedProcessHandle with the
    1.55 +// more specific OpenProcessHandleWithAccess method and delete this.
    1.56 +BASE_EXPORT bool OpenPrivilegedProcessHandle(ProcessId pid,
    1.57 +                                             ProcessHandle* handle);
    1.58 +
    1.59 +// Converts a PID to a process handle using the desired access flags. Use a
    1.60 +// combination of the kProcessAccess* flags defined above for |access_flags|.
    1.61 +BASE_EXPORT bool OpenProcessHandleWithAccess(ProcessId pid,
    1.62 +                                             uint32 access_flags,
    1.63 +                                             ProcessHandle* handle);
    1.64 +
    1.65 +// Closes the process handle opened by OpenProcessHandle.
    1.66 +BASE_EXPORT void CloseProcessHandle(ProcessHandle process);
    1.67 +
    1.68 +// Returns the unique ID for the specified process. This is functionally the
    1.69 +// same as Windows' GetProcessId(), but works on versions of Windows before
    1.70 +// Win XP SP1 as well.
    1.71 +BASE_EXPORT ProcessId GetProcId(ProcessHandle process);
    1.72 +
    1.73 +#if defined(OS_WIN)
    1.74 +enum IntegrityLevel {
    1.75 +  INTEGRITY_UNKNOWN,
    1.76 +  LOW_INTEGRITY,
    1.77 +  MEDIUM_INTEGRITY,
    1.78 +  HIGH_INTEGRITY,
    1.79 +};
    1.80 +// Determine the integrity level of the specified process. Returns false
    1.81 +// if the system does not support integrity levels (pre-Vista) or in the case
    1.82 +// of an underlying system failure.
    1.83 +BASE_EXPORT bool GetProcessIntegrityLevel(ProcessHandle process,
    1.84 +                                          IntegrityLevel* level);
    1.85 +#endif
    1.86 +
    1.87 +#if defined(OS_LINUX) || defined(OS_ANDROID) || defined(OS_BSD)
    1.88 +// Returns the path to the executable of the given process.
    1.89 +BASE_EXPORT FilePath GetProcessExecutablePath(ProcessHandle process);
    1.90 +#endif
    1.91 +
    1.92 +#if defined(OS_POSIX)
    1.93 +// Returns the ID for the parent of the given process.
    1.94 +BASE_EXPORT ProcessId GetParentProcessId(ProcessHandle process);
    1.95 +#endif
    1.96 +
    1.97 +}  // namespace base
    1.98 +
    1.99 +#endif  // BASE_PROCESS_PROCESS_HANDLE_H_

mercurial