OSDN Git Service

Replace valid memory checks with new myfault class "exception handling", almost
[pf3gnuchains/pf3gnuchains4x.git] / winsup / cygwin / tty.h
1 /* tty.h: shared tty info for cygwin
2
3    Copyright 2000, 2001, 2002 Red Hat, Inc.
4
5 This file is part of Cygwin.
6
7 This software is a copyrighted work licensed under the terms of the
8 Cygwin license.  Please consult the file "CYGWIN_LICENSE" for
9 details. */
10
11 /* tty tables */
12
13 #define INP_BUFFER_SIZE 256
14 #define OUT_BUFFER_SIZE 256
15 #define NTTYS           128
16 #define real_tty_attached(p)    ((p)->ctty >= 0 && (p)->ctty != TTY_CONSOLE)
17
18 /* Input/Output/ioctl events */
19
20 #define OUTPUT_DONE_EVENT       "cygtty.output.done"
21 #define IOCTL_REQUEST_EVENT     "cygtty.ioctl.request"
22 #define IOCTL_DONE_EVENT        "cygtty.ioctl.done"
23 #define RESTART_OUTPUT_EVENT    "cygtty.output.restart"
24 #define INPUT_AVAILABLE_EVENT   "cygtty.input.avail"
25 #define OUTPUT_MUTEX            "cygtty.output.mutex"
26 #define INPUT_MUTEX             "cygtty.input.mutex"
27 #define TTY_SLAVE_ALIVE         "cygtty.slave_alive"
28 #define TTY_MASTER_ALIVE        "cygtty.master_alive"
29
30 #include <sys/termios.h>
31
32 #ifndef MIN_CTRL_C_SLOP
33 #define MIN_CTRL_C_SLOP 50
34 #endif
35
36 class tty_min
37 {
38   pid_t sid;    /* Session ID of tty */
39   struct status_flags
40   {
41     unsigned initialized : 1; /* Set if tty is initialized */
42     unsigned rstcons     : 1; /* Set if console needs to be set to "non-cooked" */
43   } status;
44
45 public:
46   pid_t pgid;
47   int output_stopped;
48   int ntty;
49   DWORD last_ctrl_c;    // tick count of last ctrl-c
50
51   IMPLEMENT_STATUS_FLAG (bool, initialized)
52   IMPLEMENT_STATUS_FLAG (bool, rstcons)
53
54   tty_min (int t = -1, pid_t s = -1) : sid (s), ntty (t) {}
55   void setntty (int n) {ntty = n;}
56   pid_t getpgid () {return pgid;}
57   void setpgid (int pid) {pgid = pid;}
58   int getsid () {return sid;}
59   void setsid (pid_t tsid) {sid = tsid;}
60   void kill_pgrp (int sig);
61   struct termios ti;
62   struct winsize winsize;
63
64   /* ioctl requests buffer */
65   int cmd;
66   union
67   {
68     struct termios termios;
69     struct winsize winsize;
70     int value;
71     pid_t pid;
72   } arg;
73   /* XXX_retval variables holds master's completion codes. Error are stored as
74    * -ERRNO
75    */
76   int ioctl_retval;
77
78   int write_error;
79 };
80
81 class fhandler_pty_master;
82
83 class tty: public tty_min
84 {
85   HANDLE get_event (const char *fmt, BOOL manual_reset = FALSE)
86     __attribute__ ((regparm (3)));
87 public:
88   HWND  hwnd;   /* Console window handle tty belongs to */
89
90   DWORD master_pid;     /* Win32 PID of tty master process */
91
92   HANDLE from_master, to_slave;
93   HANDLE from_slave, to_master;
94
95   int read_retval;
96   bool was_opened;      /* True if opened at least once. */
97
98   void init ();
99   HANDLE create_inuse (const char *);
100   bool common_init (fhandler_pty_master *);
101   bool alive (const char *fmt);
102   bool slave_alive ();
103   bool master_alive ();
104   HWND gethwnd () {return hwnd;}
105   void sethwnd (HWND wnd) {hwnd = wnd;}
106   bool make_pipes (fhandler_pty_master *ptym);
107   HANDLE open_mutex (const char *mutex);
108   HANDLE open_output_mutex ();
109   HANDLE open_input_mutex ();
110   bool exists ()
111   {
112     HANDLE h = open_output_mutex ();
113     if (h)
114       {
115         CloseHandle (h);
116         return 1;
117       }
118     return slave_alive ();
119   }
120 };
121
122 class tty_list
123 {
124   tty ttys[NTTYS];
125
126 public:
127   tty * operator [](int n) {return ttys + n;}
128   int allocate_tty (bool); /* true if allocate a tty, pty otherwise */
129   int connect_tty (int);
130   void terminate ();
131   void init ();
132   tty_min *get_tty (int n);
133 };
134
135 void __stdcall tty_init ();
136 void __stdcall tty_terminate ();
137 int __stdcall attach_tty (int);
138 void __stdcall create_tty_master (int);
139 extern "C" int ttyslot (void);