Fix handling of fatal signals and exceptions on MS-Windows.
[bpt/emacs.git] / src / w32.h
CommitLineData
e588809c
JR
1#ifndef EMACS_W32_H
2#define EMACS_W32_H
b3fa71dc 3
95ed0025 4/* Support routines for the NT version of Emacs.
acaf905b 5 Copyright (C) 1994, 2001-2012 Free Software Foundation, Inc.
95ed0025
RS
6
7This file is part of GNU Emacs.
8
b9b1cc14 9GNU Emacs is free software: you can redistribute it and/or modify
95ed0025 10it under the terms of the GNU General Public License as published by
b9b1cc14
GM
11the Free Software Foundation, either version 3 of the License, or
12(at your option) any later version.
95ed0025
RS
13
14GNU Emacs is distributed in the hope that it will be useful,
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17GNU General Public License for more details.
18
19You should have received a copy of the GNU General Public License
b9b1cc14 20along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
95ed0025 21
7482f2ec 22
b3fa71dc
GV
23/* File descriptor set emulation. */
24
25/* MSVC runtime library has limit of 64 descriptors by default */
26#define FD_SETSIZE 64
27typedef struct {
28 unsigned int bits[FD_SETSIZE / 32];
29} fd_set;
30
31/* standard access macros */
32#define FD_SET(n, p) \
33 do { \
34 if ((n) < FD_SETSIZE) { \
35 (p)->bits[(n)/32] |= (1 << (n)%32); \
36 } \
37 } while (0)
38#define FD_CLR(n, p) \
39 do { \
40 if ((n) < FD_SETSIZE) { \
41 (p)->bits[(n)/32] &= ~(1 << (n)%32); \
42 } \
43 } while (0)
44#define FD_ISSET(n, p) ((n) < FD_SETSIZE ? ((p)->bits[(n)/32] & (1 << (n)%32)) : 0)
45#define FD_ZERO(p) memset((p), 0, sizeof(fd_set))
46
95ed0025 47#define SELECT_TYPE fd_set
95ed0025 48
b3fa71dc
GV
49/* ------------------------------------------------------------------------- */
50
51/* child_process.status values */
52enum {
53 STATUS_READ_ERROR = -1,
54 STATUS_READ_READY,
55 STATUS_READ_IN_PROGRESS,
56 STATUS_READ_FAILED,
57 STATUS_READ_SUCCEEDED,
58 STATUS_READ_ACKNOWLEDGED
59};
60
61/* This structure is used for both pipes and sockets; for
62 a socket, the process handle in pi is NULL. */
63typedef struct _child_process
64{
65 int fd;
66 int pid;
67 HANDLE char_avail;
68 HANDLE char_consumed;
69 HANDLE thrd;
bb06745d 70 HWND hwnd;
b3fa71dc
GV
71 PROCESS_INFORMATION procinfo;
72 volatile int status;
73 char chr;
d888760c
GM
74 OVERLAPPED ovl_read;
75 OVERLAPPED ovl_write;
b3fa71dc
GV
76} child_process;
77
78#define MAXDESC FD_SETSIZE
79#define MAX_CHILDREN MAXDESC/2
80#define CHILD_ACTIVE(cp) ((cp)->char_avail != NULL)
81
82/* parallel array of private info on file handles */
83typedef struct
84{
85 unsigned flags;
86 HANDLE hnd;
87 child_process * cp;
88} filedesc;
89
90extern filedesc fd_info [ MAXDESC ];
91
92/* fd_info flag definitions */
ead2be98
GV
93#define FILE_READ 0x0001
94#define FILE_WRITE 0x0002
d18f316e 95#define FILE_LISTEN 0x0004
ead2be98
GV
96#define FILE_BINARY 0x0010
97#define FILE_LAST_CR 0x0020
98#define FILE_AT_EOF 0x0040
99#define FILE_SEND_SIGCHLD 0x0080
100#define FILE_PIPE 0x0100
101#define FILE_SOCKET 0x0200
2c0c4d35 102#define FILE_NDELAY 0x0400
d888760c 103#define FILE_SERIAL 0x0800
b3fa71dc
GV
104
105extern child_process * new_child (void);
106extern void delete_child (child_process *cp);
107
108/* ------------------------------------------------------------------------- */
109
7482f2ec
AI
110/* Equivalent of strerror for W32 error codes. */
111extern char * w32_strerror (int error_no);
112
0c5c0e3d
EZ
113/* Validate a pointer. */
114extern int w32_valid_pointer_p (void *, int);
115
bb06745d
GV
116/* Get long (aka "true") form of file name, if it exists. */
117extern BOOL w32_get_long_filename (char * name, char * buf, int size);
95ed0025
RS
118
119/* Prepare our standard handles for proper inheritance by child processes. */
177c0ea7 120extern void prepare_standard_handles (int in, int out,
95ed0025
RS
121 int err, HANDLE handles[4]);
122
123/* Reset our standard handles to their original state. */
177c0ea7 124extern void reset_standard_handles (int in, int out,
95ed0025
RS
125 int err, HANDLE handles[4]);
126
46c91229 127/* Return the string resource associated with KEY of type TYPE. */
fbd6baed 128extern LPBYTE w32_get_resource (char * key, LPDWORD type);
b3fa71dc 129
16b22fef
EZ
130extern void init_ntproc (int);
131extern void term_ntproc (int);
52c7f9ee
JR
132extern void globals_of_w32 (void);
133extern void syms_of_w32term (void);
134extern void syms_of_w32fns (void);
135extern void globals_of_w32fns (void);
136extern void syms_of_w32select (void);
137extern void globals_of_w32select (void);
138extern void term_w32select (void);
139extern void syms_of_w32menu (void);
140extern void globals_of_w32menu (void);
141extern void syms_of_fontset (void);
db4f02f2 142extern void syms_of_w32font (void);
76151e2c 143extern void check_windows_init_file (void);
46c91229 144
c8b67880
KS
145extern int _sys_read_ahead (int fd);
146extern int _sys_wait_accept (int fd);
147
0898ca10 148extern Lisp_Object Vlibrary_cache, QCloaded_from;
d07ff9db 149extern HMODULE w32_delayed_load (Lisp_Object);
0898ca10 150
e061a11b
TZ
151#ifdef HAVE_GNUTLS
152#include <gnutls/gnutls.h>
153
154/* GnuTLS pull (read from remote) interface. */
155extern ssize_t emacs_gnutls_pull (gnutls_transport_ptr_t p,
156 void* buf, size_t sz);
157
158/* GnuTLS push (write to remote) interface. */
159extern ssize_t emacs_gnutls_push (gnutls_transport_ptr_t p,
160 const void* buf, size_t sz);
161#endif /* HAVE_GNUTLS */
162
e588809c 163#endif /* EMACS_W32_H */
ab5796a9 164