[sanitizer] Improve FreeBSD ASLR detection
[llvm-project.git] / lldb / tools / debugserver / source / TTYState.h
blob8229a7cd5731a62bbc914994218add90f2988fca
1 //===-- TTYState.h ----------------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Created by Greg Clayton on 3/26/07.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLDB_TOOLS_DEBUGSERVER_SOURCE_TTYSTATE_H
14 #define LLDB_TOOLS_DEBUGSERVER_SOURCE_TTYSTATE_H
16 #include <cstdint>
17 #include <termios.h>
19 class TTYState {
20 public:
21 TTYState();
22 ~TTYState();
24 bool GetTTYState(int fd, bool saveProcessGroup);
25 bool SetTTYState() const;
27 bool IsValid() const {
28 return FileDescriptorValid() && TFlagsValid() && TTYStateValid();
30 bool FileDescriptorValid() const { return m_fd >= 0; }
31 bool TFlagsValid() const { return m_tflags != -1; }
32 bool TTYStateValid() const { return m_ttystateErr == 0; }
33 bool ProcessGroupValid() const { return m_processGroup != -1; }
35 protected:
36 int m_fd; // File descriptor
37 int m_tflags;
38 int m_ttystateErr;
39 struct termios m_ttystate;
40 pid_t m_processGroup;
43 class TTYStateSwitcher {
44 public:
45 TTYStateSwitcher();
46 ~TTYStateSwitcher();
48 bool GetState(uint32_t idx, int fd, bool saveProcessGroup);
49 bool SetState(uint32_t idx) const;
50 uint32_t NumStates() const { return sizeof(m_ttystates) / sizeof(TTYState); }
51 bool ValidStateIndex(uint32_t idx) const { return idx < NumStates(); }
53 protected:
54 mutable uint32_t m_currentState;
55 TTYState m_ttystates[2];
58 #endif