annotate src/nt.h @ 450:98528da0b7fc r21-2-40

Import from CVS: tag r21-2-40
author cvs
date Mon, 13 Aug 2007 11:39:20 +0200
parents abe6d1db359e
children 4f6ba8f1fb3d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1 /* Support routines for the NT version of XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2 Copyright (C) 1994 Free Software Foundation, Inc.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4 This file is part of XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6 XEmacs is free software; you can redistribute it and/or modify it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7 under the terms of the GNU General Public License as published by the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8 Free Software Foundation; either version 2, or (at your option) any
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9 later version.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
14 for more details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17 along with XEmacs; see the file COPYING. If not, write to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19 Boston, MA 02111-1307, USA. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21 /* Adapted for XEmacs by David Hobley <david@spook-le0.cia.com.au> */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22 /* Sync'ed with Emacs 19.34.6 by Marc Paquette <marcpa@cam.org> */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24 /* #define FULL_DEBUG */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
26 #ifndef INCLUDED_nt_h_
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
27 #define INCLUDED_nt_h_
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
28
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
29 #include "syswindows.h"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
30
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31 #ifdef DEBUG_XEMACS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32 #define DebPrint(stuff) _DebPrint stuff
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
33 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34 #define DebPrint(stuff)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
36
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37 /* ------------------------------------------------------------------------- */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39 /* child_process.status values */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40 enum {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41 STATUS_READ_ERROR = -1,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42 STATUS_READ_READY,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43 STATUS_READ_IN_PROGRESS,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 STATUS_READ_FAILED,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45 STATUS_READ_SUCCEEDED,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46 STATUS_READ_ACKNOWLEDGED
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49 /* This structure is used for both pipes and sockets; for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50 a socket, the process handle in pi is NULL. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51 typedef struct _child_process
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53 int fd;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54 int pid;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55 HANDLE char_avail;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 HANDLE char_consumed;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57 HANDLE thrd;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58 HWND hwnd;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59 PROCESS_INFORMATION procinfo;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60 volatile int status;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61 char chr;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62 } child_process;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64 #define MAX_CHILDREN MAXDESC/2
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65 #define CHILD_ACTIVE(cp) ((cp)->char_avail != NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67 /* parallel array of private info on file handles */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68 typedef struct
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 unsigned flags;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71 HANDLE hnd;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72 child_process * cp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73 } filedesc;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
75 extern filedesc fd_info [];
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77 /* fd_info flag definitions */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78 #define FILE_READ 0x0001
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79 #define FILE_WRITE 0x0002
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80 #define FILE_BINARY 0x0010
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81 #define FILE_LAST_CR 0x0020
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82 #define FILE_AT_EOF 0x0040
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83 #define FILE_SEND_SIGCHLD 0x0080
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84 #define FILE_PIPE 0x0100
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85 #define FILE_SOCKET 0x0200
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87 extern child_process * new_child (void);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88 extern void delete_child (child_process *cp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 /* ------------------------------------------------------------------------- */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92 /* Get long (aka "true") form of file name, if it exists. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93 extern BOOL win32_get_long_filename (char * name, char * buf, int size);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95 /* Prepare our standard handles for proper inheritance by child processes. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96 extern void prepare_standard_handles (int in, int out,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97 int err, HANDLE handles[4]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99 /* Reset our standard handles to their original state. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100 extern void reset_standard_handles (int in, int out,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101 int err, HANDLE handles[4]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103 /* Return the string resource associated with KEY of type TYPE. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104 extern LPBYTE nt_get_resource (char * key, LPDWORD type);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106 void set_process_dir (const char * dir);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107 time_t convert_time (FILETIME ft);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
109 extern void init_ntproc (void);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
110 extern void term_ntproc (int unused);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
111
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
112 /* ----------------------------------------------------------------- */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
113 /* Useful routines for manipulating memory-mapped files. */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
114
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
115 typedef struct file_data
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
116 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
117 const char *name;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
118 unsigned long size;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
119 HANDLE file;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
120 HANDLE file_mapping;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
121 char *file_base;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
122 } file_data;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
123
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
124 #define OFFSET_TO_RVA(var,section) \
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
125 (section->VirtualAddress + ((DWORD)(var) - section->PointerToRawData))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
126
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
127 #define RVA_TO_OFFSET(var,section) \
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
128 (section->PointerToRawData + ((DWORD)(var) - section->VirtualAddress))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
129
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
130 #define RVA_TO_PTR(var,section,filedata) \
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
131 ((void *)(RVA_TO_OFFSET(var,section) + (filedata).file_base))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
132
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
133 int open_input_file (file_data *p_file, const char *name);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
134 int open_output_file (file_data *p_file, const char *name, unsigned long size);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
135 void close_file_data (file_data *p_file);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
136 void mswindows_executable_type (const char * filename, int * is_dos_app,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
137 int * is_cygnus_app);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
138
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
139 /* In process-nt.c */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
140 extern int compare_env (const void *strp1, const void *strp2);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
141
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
142 void mswindows_set_errno (unsigned long win32_error);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
143 void mswindows_set_last_errno (void);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
144
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
145 void wait_for_termination (HANDLE pid);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
146
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
147 int mswindows_fstat (int handle, struct stat *buffer);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
148 int mswindows_stat (const char * path, struct stat * buf);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
149
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
150 #endif /* INCLUDED_nt_h_ */