]> sourceware.org Git - newlib-cygwin.git/blame - winsup/cygwin/tty.h
* Merge in cygwin-64bit-branch.
[newlib-cygwin.git] / winsup / cygwin / tty.h
CommitLineData
018a91fa 1/* tty.h: shared tty info for cygwin
29ac7f89 2
6e75c72b
CF
3 Copyright 2000, 2001, 2002, 2003, 2004, 2006, 2009, 2010, 2011, 2012, 2013
4 Red Hat, Inc.
29ac7f89
CF
5
6This file is part of Cygwin.
7
8This software is a copyrighted work licensed under the terms of the
9Cygwin license. Please consult the file "CYGWIN_LICENSE" for
10details. */
11
32bf3082
CF
12#ifndef _TTY_H
13#define _TTY_H
29ac7f89
CF
14/* tty tables */
15
16#define INP_BUFFER_SIZE 256
17#define OUT_BUFFER_SIZE 256
23771fa1 18#define NTTYS 64
480b13a3 19#define real_tty_attached(p) ((p)->ctty > 0 && !iscons_dev ((p)->ctty))
29ac7f89
CF
20
21/* Input/Output/ioctl events */
22
8bdfa78a
PH
23#define INPUT_AVAILABLE_EVENT "cygtty.input.avail"
24#define OUTPUT_MUTEX "cygtty.output.mutex"
25#define INPUT_MUTEX "cygtty.input.mutex"
26#define TTY_SLAVE_ALIVE "cygtty.slave_alive"
29ac7f89
CF
27
28#include <sys/termios.h>
29
29ac7f89
CF
30#ifndef MIN_CTRL_C_SLOP
31#define MIN_CTRL_C_SLOP 50
32#endif
33
44d2fc0a 34#include <devices.h>
29ac7f89
CF
35class tty_min
36{
37 pid_t sid; /* Session ID of tty */
7aa88267
CV
38 struct status_flags
39 {
fe0cb311
CF
40 unsigned initialized : 1; /* Set if tty is initialized */
41 unsigned rstcons : 1; /* Set if console needs to be set to "non-cooked" */
7aa88267
CV
42 } status;
43
29ac7f89 44public:
29ac7f89 45 pid_t pgid;
fe0cb311 46 bool output_stopped; /* FIXME: Maybe do this with a mutex someday? */
44d2fc0a 47 fh_devices ntty;
fe0cb311 48 DWORD last_ctrl_c; /* tick count of last ctrl-c */
c75b5b2d 49 bool is_console;
29ac7f89 50
825b3882
CV
51 IMPLEMENT_STATUS_FLAG (bool, initialized)
52 IMPLEMENT_STATUS_FLAG (bool, rstcons)
7aa88267 53
29ac7f89
CF
54 struct termios ti;
55 struct winsize winsize;
56
57 /* ioctl requests buffer */
58 int cmd;
59 union
60 {
61 struct termios termios;
62 struct winsize winsize;
63 int value;
64 pid_t pid;
65 } arg;
66 /* XXX_retval variables holds master's completion codes. Error are stored as
67 * -ERRNO
68 */
69 int ioctl_retval;
29ac7f89 70 int write_error;
f09acf77 71
61522196
CV
72 void setntty (_major_t t, _minor_t n) {ntty = (fh_devices) FHDEV (t, n);}
73 dev_t getntty () const {return ntty;}
74 _minor_t get_minor () const {return device::minor (ntty);}
44d2fc0a 75 pid_t getpgid () const {return pgid;}
f09acf77 76 void setpgid (int pid) {pgid = pid;}
44d2fc0a 77 int getsid () const {return sid;}
f09acf77 78 void setsid (pid_t tsid) {sid = tsid;}
7123c8b1
CF
79 void kill_pgrp (int);
80 int is_orphaned_process_group (int);
6e75c72b 81 const __reg1 char *ttyname () __attribute (());
29ac7f89
CF
82};
83
84class fhandler_pty_master;
85
86class tty: public tty_min
87{
6e75c72b 88 HANDLE __reg3 get_event (const char *fmt, PSECURITY_ATTRIBUTES sa,
cc01c77f 89 BOOL manual_reset = FALSE);
29ac7f89 90public:
3378bdfc 91 pid_t master_pid; /* PID of tty master process */
29ac7f89 92
61522196
CV
93private:
94 /* Since tty is shared, the HANDLEs must be 32 and 64 bit clean. The below
95 code makes sure of that by setting the upper 4 byte of the union to 0
96 when writing the handle value from a 32 bit process. Fortunately the
97 actual values are 32 bit on both platforms, so the HANDLES can be
98 used on both platforms. */
99 union {
100 HANDLE _from_master;
101 LARGE_INTEGER _fm_dummy;
102 };
103 union {
104 HANDLE _to_master;
105 LARGE_INTEGER _tm_dummy;
106 };
107public:
108 HANDLE from_master() const { return _from_master; }
109 HANDLE to_master() const { return _to_master; }
110#ifdef __x86_64__
111 void set_from_master (HANDLE h) { _from_master = h; }
112 void set_to_master (HANDLE h) { _to_master = h; }
113#else
114 void set_from_master (HANDLE h) { _fm_dummy.HighPart = 0; _from_master = h; }
115 void set_to_master (HANDLE h) { _tm_dummy.HighPart = 0; _to_master = h; }
116#endif
29ac7f89
CF
117
118 int read_retval;
2e008fb9 119 bool was_opened; /* True if opened at least once. */
29ac7f89
CF
120
121 void init ();
cc01c77f
CV
122 HANDLE open_inuse (ACCESS_MASK access);
123 HANDLE create_inuse (PSECURITY_ATTRIBUTES);
2e008fb9 124 bool slave_alive ();
cc01c77f
CV
125 HANDLE open_mutex (const char *mutex, ACCESS_MASK access);
126 inline HANDLE open_output_mutex (ACCESS_MASK access)
127 { return open_mutex (OUTPUT_MUTEX, access); }
128 inline HANDLE open_input_mutex (ACCESS_MASK access)
129 { return open_mutex (INPUT_MUTEX, access); }
3c4f2024 130 bool exists ();
23771fa1 131 bool not_allocated (HANDLE&, HANDLE&);
71d59a92 132 void set_master_closed () {master_pid = -1;}
57af0179 133 bool is_master_closed () const {return master_pid == -1;}
71d59a92
CF
134 static void __stdcall create_master (int);
135 static void __stdcall init_session ();
3378bdfc 136 friend class fhandler_pty_master;
29ac7f89
CF
137};
138
139class tty_list
140{
141 tty ttys[NTTYS];
71d59a92 142 static HANDLE mutex;
29ac7f89
CF
143
144public:
44d2fc0a 145 tty * operator [](int n) {return ttys + device::minor (n);}
23771fa1 146 int allocate (HANDLE& r, HANDLE& w); /* allocate a pty */
71d59a92 147 int connect (int);
29ac7f89 148 void init ();
44d2fc0a 149 tty_min *get_cttyp ();
6e75c72b 150 int __reg2 attach (int n);
71d59a92
CF
151 static void __stdcall init_session ();
152 friend class lock_ttys;
153};
154
155class lock_ttys
156{
157 bool release_me;
158public:
159 lock_ttys (DWORD = INFINITE);
160 static void release ();
161 void dont_release () {release_me = false;}
162 ~lock_ttys ()
163 {
164 if (release_me)
165 release ();
166 }
29ac7f89
CF
167};
168
29ac7f89 169extern "C" int ttyslot (void);
32bf3082 170#endif /*_TTY_H*/
This page took 0.409306 seconds and 5 git commands to generate.