* dcrt0.cc (set_os_type): Set 'iswinnt' appropriately.
* cygheap.cc (init_cheap): Revert to using VirtualAlloc for allocating cygheap.
(cygheap_setup_for_child_cleanup): New function. Standard function to call
after calling CreateProcess to cleanup cygheap info passed to child.
(cygheap_fixup_in_child): Copy cygheap from shared memory into allocated space
under Windows 9x or if can't relocate shared space under NT.
* cygheap.h: Declare new function.
* spawn.cc (spawn_guts): Use cygheap_fixup_in_child.
* fork.cc (fork_parent): Ditto.
* winsup.h: Declare iswinnt.
+Sat Aug 4 16:52:03 2001 Christopher Faylor <cgf@cygnus.com>
+
+ Throughout, change check for running under Windows NT to 'iswinnt'.
+ * dcrt0.cc (set_os_type): Set 'iswinnt' appropriately.
+ * cygheap.cc (init_cheap): Revert to using VirtualAlloc for allocating
+ cygheap.
+ (cygheap_setup_for_child_cleanup): New function. Standard function to
+ call after calling CreateProcess to cleanup cygheap info passed to
+ child.
+ (cygheap_fixup_in_child): Copy cygheap from shared memory into
+ allocated space under Windows 9x or if can't relocate shared space
+ under NT.
+ * cygheap.h: Declare new function.
+ * spawn.cc (spawn_guts): Use cygheap_fixup_in_child.
+ * fork.cc (fork_parent): Ditto.
+ * winsup.h: Declare iswinnt.
+
2001-08-04 Egor Duda <deo@logos-m.ru>
* dtable.cc (dtable::release): Avoid messing with console when
#define N0 ((_cmalloc_entry *) NULL)
#define to_cmalloc(s) ((_cmalloc_entry *) (((char *) (s)) - (int) (N0->data)))
+#define CFMAP_OPTIONS (SEC_RESERVE | PAGE_READWRITE)
+#define MVMAP_OPTIONS (FILE_MAP_WRITE)
+
extern "C" {
static void __stdcall _cfree (void *ptr) __attribute__((regparm(1)));
}
inline static void
init_cheap ()
{
- HANDLE cygheap_h;
- cygheap_h = CreateFileMapping (INVALID_HANDLE_VALUE, &sec_none_nih,
- PAGE_READWRITE | SEC_RESERVE, 0, CYGHEAPSIZE,
- NULL);
- cygheap = (init_cygheap *) MapViewOfFileEx (cygheap_h,
- FILE_MAP_READ | FILE_MAP_WRITE,
- 0, 0, 0, NULL);
- CloseHandle (cygheap_h);
+ cygheap = (init_cygheap *) VirtualAlloc (NULL, CYGHEAPSIZE, MEM_RESERVE, PAGE_NOACCESS);
if (!cygheap)
- api_fatal ("Couldn't reserve space for cygwin's heap, %E");
- cygheap_max = cygheap + 1;
+ api_fatal ("Couldn't reserve space for cygwin's heap, %E");
+ cygheap_max = cygheap + 1;
}
void __stdcall
cygheap_protect->acquire ();
unsigned n = (char *) cygheap_max - (char *) cygheap;
ci->cygheap_h = CreateFileMapping (INVALID_HANDLE_VALUE, &sec_none,
- PAGE_READWRITE | SEC_RESERVE, 0,
- CYGHEAPSIZE, NULL);
- newcygheap = MapViewOfFileEx (ci->cygheap_h, FILE_MAP_READ | FILE_MAP_WRITE,
- 0, 0, 0, NULL);
+ CFMAP_OPTIONS, 0, CYGHEAPSIZE, NULL);
+ newcygheap = MapViewOfFileEx (ci->cygheap_h, MVMAP_OPTIONS, 0, 0, 0, NULL);
if (!VirtualAlloc (newcygheap, n, MEM_COMMIT, PAGE_READWRITE))
api_fatal ("couldn't allocate new cygwin heap for child, %E");
memcpy (newcygheap, cygheap, n);
return;
}
+void __stdcall
+cygheap_setup_for_child_cleanup (child_info *ci)
+{
+ ForceCloseHandle1 (ci->cygheap_h, passed_cygheap_h);
+}
+
/* Called by fork or spawn to reallocate cygwin heap */
void __stdcall
cygheap_fixup_in_child (child_info *ci, bool execed)
{
cygheap = ci->cygheap;
cygheap_max = ci->cygheap_max;
-#if 0
- if (!DuplicateHandle (hMainProc, ci->cygheap_h,
- hMainProc, &cygheap_h, 0, 0,
- DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE))
- cygheap_h = ci->cygheap_h;
-#endif
- VirtualFree (cygheap, CYGHEAPSIZE, MEM_DECOMMIT);
- VirtualFree (cygheap, 0, MEM_RELEASE);
- if (MapViewOfFileEx (ci->cygheap_h, FILE_MAP_READ | FILE_MAP_WRITE,
- 0, 0, CYGHEAPSIZE, cygheap) != cygheap)
- api_fatal ("Couldn't allocate space for child's cygwin heap from %p, to %p, %E",
- cygheap, cygheap_max);
+ void *addr = iswinnt ? cygheap : NULL;
+ void *newaddr;
+ newaddr = MapViewOfFileEx (ci->cygheap_h, MVMAP_OPTIONS, 0, 0, 0, addr);
+ if (!iswinnt || newaddr != addr)
+ {
+ DWORD n = (DWORD) cygheap_max - (DWORD) cygheap;
+ /* Reserve cygwin heap in same spot as parent */
+ if (!VirtualAlloc (cygheap, CYGHEAPSIZE, MEM_RESERVE, PAGE_NOACCESS))
+ api_fatal ("Couldn't reserve space for cygwin's heap (%p) in child, cygheap, %E", cygheap);
+
+ /* Allocate same amount of memory as parent */
+ if (!VirtualAlloc (cygheap, n, MEM_COMMIT, PAGE_READWRITE))
+ api_fatal ("Couldn't allocate space for child's heap %p, size %d, %E",
+ cygheap, n);
+ memcpy (cygheap, newaddr, n);
+ UnmapViewOfFile (newaddr);
+ }
ForceCloseHandle1 (ci->cygheap_h, passed_cygheap_h);
+
cygheap_init ();
if (execed)
class child_info;
void __stdcall cygheap_setup_for_child (child_info *ci) __attribute__ ((regparm(1)));
+void __stdcall cygheap_setup_for_child_cleanup (child_info *ci) __attribute__ ((regparm(1)));
void __stdcall cygheap_fixup_in_child (child_info *, bool);
extern "C" {
void __stdcall cfree (void *) __attribute__ ((regparm(1)));
/* remember the type of Win32 OS being run for future use. */
os_type NO_COPY os_being_run;
char NO_COPY osname[40];
+bool iswinnt;
/* set_os_type: Set global variable os_being_run with type of Win32
operating system being run. This information is used internally
os_version_info.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
GetVersionEx (&os_version_info);
+ iswinnt = 0;
switch (os_version_info.dwPlatformId)
{
case VER_PLATFORM_WIN32_NT:
os_being_run = winNT;
os = "NT";
+ iswinnt = 1;
break;
case VER_PLATFORM_WIN32_WINDOWS:
if (os_version_info.dwMinorVersion == 0)
child_info_fork NO_COPY *child_proc_info = NULL;
static MEMORY_BASIC_INFORMATION sm;
-#define CYGWIN_GUARD ((os_being_run == winNT) ? PAGE_GUARD : PAGE_NOACCESS)
+#define CYGWIN_GUARD ((iswinnt) ? PAGE_GUARD : PAGE_NOACCESS)
// __inline__ void
extern void
int res = GetLastError ();
empty = 0;
if (res == ERROR_SHARING_VIOLATION ||
- (os_being_run != winNT && res == ERROR_ACCESS_DENIED))
+ (!iswinnt && res == ERROR_ACCESS_DENIED))
{
/* File still inuse, that's ok */
syscall_printf ("Still using %s", name[i]);
{
/* On 9X ERROR_ACCESS_DENIED is returned if you try to remove
a non-empty directory. */
- if (os_being_run != winNT)
+ if (!iswinnt)
set_errno (ENOTEMPTY);
else
__seterrno ();
#ifdef NTSEC_ON_BY_DEFAULT
/* Set ntsec explicit as default, if NT is running */
- if (os_being_run == winNT)
+ if (iswinnt)
allow_ntsec = TRUE;
#endif
if (get_append_p ())
SetFilePointer (get_handle(), 0, 0, FILE_END);
- else if (os_being_run != winNT && get_check_win95_lseek_bug ())
+ else if (!iswinnt && get_check_win95_lseek_bug ())
{
/* Note: this bug doesn't happen on NT4, even though the documentation
for WriteFile() says that it *may* happen on any OS. */
BOOL res;
- if (os_being_run == winNT)
+ if (iswinnt)
{
DWORD lock_flags = (cmd == F_SETLK) ? LOCKFILE_FAIL_IMMEDIATELY : 0;
lock_flags |= (fl->l_type == F_WRLCK) ? LOCKFILE_EXCLUSIVE_LOCK : 0;
/* This strange test is due to the fact that we can't rely on
Windows shells to "do the right thing" with pipes. Apparently
the can keep one end of the pipe open when it shouldn't be. */
- BOOL is_slow () {return os_being_run == winNT;}
+ BOOL is_slow () {return iswinnt;}
select_record *select_read (select_record *s);
select_record *select_write (select_record *s);
select_record *select_except (select_record *s);
part is to distinguish whether the right Alt key should be
recognized as Alt, or as AltGr. */
bool meta;
- if (os_being_run == winNT)
+ if (iswinnt)
/* WinNT: AltGr is reported as Ctrl+Alt, and Ctrl+Alt is
treated just like AltGr. However, if Ctrl+Alt+key generates
an ASCII control character, interpret is as META. */
DWORD low;
LONG high = 0;
- if (os_being_run == winNT)
+ if (iswinnt)
{
DISK_GEOMETRY di;
PARTITION_INFORMATION pi;
unit (nunit)
{
/* Reading physical memory only supported on NT/W2K. */
- if (os_being_run != winNT)
+ if (!iswinnt)
{
mem_size = 0;
return;
int
fhandler_dev_mem::open (const char *, int flags, mode_t)
{
- if (os_being_run != winNT)
+ if (!iswinnt)
{
set_errno (ENOENT);
debug_printf ("%s is accessible under NT/W2K only",
memset (buf, 0, sizeof *buf);
buf->st_mode = S_IFCHR;
- if (os_being_run != winNT)
+ if (!iswinnt)
buf->st_mode |= S_IRUSR | S_IWUSR |
S_IRGRP | S_IWGRP |
S_IROTH | S_IWOTH;
debug_printf ("done");
return 1;
-err:
+ err:
TerminateProcess (pi.hProcess, 1);
set_errno (EAGAIN);
return 0;
npid = 0;
}
}
-out:
+ out:
#endif
char sa_buf[1024];
&pi);
CloseHandle (hParent);
- ForceCloseHandle1 (ch.cygheap_h, passed_cygheap_h);
+ cygheap_setup_for_child_cleanup (&ch);
if (!rc)
{
return forked->pid;
/* Common cleanup code for failure cases */
-cleanup:
+ cleanup:
/* Remember to de-allocate the fd table. */
if (pi.hProcess)
ForceCloseHandle1 (pi.hProcess, childhProc);
/* Allocate one bit per page */
map_map_ = (DWORD *) calloc (MAPSIZE(PAGE_CNT (size_to_map_)),
sizeof (DWORD));
- if (os_being_run == winNT)
+ if (iswinnt)
{
DWORD old_prot;
if (!VirtualProtect (base_address_, size_to_map_,
off = find_empty (len);
if (off != (DWORD)-1)
{
- if (os_being_run == winNT
+ if (iswinnt
&& !VirtualProtect (base_address_ + off * getpagesize (),
len * getpagesize (), prot, &old_prot))
syscall_printf ("-1 = map_map (): %E");
}
off -= offset_;
DWORD start = off / getpagesize ();
- if (os_being_run == winNT
+ if (iswinnt
&& !VirtualProtect (base_address_ + start * getpagesize (),
len * getpagesize (), prot, &old_prot))
syscall_printf ("-1 = map_map (): %E");
DWORD off = addr - base_address_;
off /= getpagesize ();
len = PAGE_CNT (len);
- if (os_being_run == winNT
+ if (iswinnt
&& !VirtualProtect (base_address_ + off * getpagesize (),
len * getpagesize (), PAGE_NOACCESS, &old_prot))
syscall_printf ("-1 = unmap_map (): %E");
void
mmap_record::fixup_map ()
{
- if (os_being_run != winNT)
+ if (!iswinnt)
return;
DWORD prot, old_prot;
/* copy-on-write doesn't work correctly on 9x. To have at least read
access we use *READ mapping on 9x when appropriate. It will still
fail when needing write access, though. */
- if ((flags & MAP_PRIVATE) && (os_being_run == winNT || (prot & ~PROT_READ)))
+ if ((flags & MAP_PRIVATE) && (iswinnt || (prot & ~PROT_READ)))
access = FILE_MAP_COPY;
SetResourceLock(LOCK_MMAP_LIST, READ_LOCK | WRITE_LOCK, "mmap");
* CV: This assumption isn't correct. See Microsoft Platform SDK, Memory,
* description of call `MapViewOfFileEx'.
*/
- if ((os_being_run != winNT) && (flags & MAP_FIXED))
+ if ((!iswinnt) && (flags & MAP_FIXED))
{
set_errno (EINVAL);
syscall_printf ("-1 = mmap(): win95 and MAP_FIXED");
/* On 9x/ME try first to open the mapping by name when opening a
shared file object. This is needed since 9x/ME only shares
objects between processes by name. What a mess... */
- if (os_being_run != winNT
+ if (!iswinnt
&& get_handle () != INVALID_HANDLE_VALUE
&& get_device () == FH_DISK
&& !(access & FILE_MAP_COPY))
static SOCKET __stdcall
set_socket_inheritance (SOCKET sock)
{
- if (os_being_run == winNT)
+ if (iswinnt)
(void) SetHandleInformation ((HANDLE) sock, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT);
else
{
* Punt for now and assume MS-TCP on Win95.
*/
reg_key r (HKEY_LOCAL_MACHINE, KEY_READ,
- (os_being_run != winNT) ? "System" : "SYSTEM",
+ (!iswinnt) ? "System" : "SYSTEM",
"CurrentControlSet", "Services",
- (os_being_run != winNT) ? "MSTCP" : "Tcpip",
+ (!iswinnt) ? "MSTCP" : "Tcpip",
NULL);
/* FIXME: Are registry keys case sensitive? */
DWORD
winpids::enum_init (bool winpid)
{
- if (os_being_run == winNT)
+ if (iswinnt)
enum_processes = &winpids::enumNT;
else
enum_processes = &winpids::enum9x;
extern __inline pid_t
cygwin_pid (pid_t pid)
{
- return (pid_t) (os_being_run == winNT) ? pid : -(int) pid;
+ return (pid_t) (iswinnt) ? pid : -(int) pid;
}
void __stdcall pinfo_init (char **, int);
HANDLE
cygwin_logon_user (const struct passwd *pw, const char *password)
{
- if (os_being_run != winNT)
+ if (!iswinnt)
{
set_errno (ENOSYS);
return INVALID_HANDLE_VALUE;
get_nt_attribute (const char *file, int *attribute,
uid_t *uidret, gid_t *gidret)
{
- if (os_being_run != winNT)
+ if (!iswinnt)
return 0;
syscall_printf ("file: %s", file);
{
BOOL dummy;
- if (os_being_run != winNT)
+ if (!iswinnt)
return NULL;
if (!sd_ret || !sd_size_ret)
set_nt_attribute (const char *file, uid_t uid, gid_t gid,
const char *logsrv, int attribute)
{
- if (os_being_run != winNT)
+ if (!iswinnt)
return 0;
DWORD sd_size = 4096;
MALLOC_CHECK;
if (envblock)
free (envblock);
- ForceCloseHandle1 (ciresrv.cygheap_h, passed_cygheap_h);
+ cygheap_setup_for_child_cleanup (&ciresrv);
MALLOC_CHECK;
/* Set errno now so that debugging messages from it appear before our
strace.execing = 1;
hExeced = pi.hProcess;
strcpy (myself->progname, real_path);
+ close_all_files ();
}
else
{
/* Windows 9x seems to report ERROR_ACCESS_DENIED rather than sharing
violation. So, set lasterr to ERROR_SHARING_VIOLATION in this case
to simplify tests. */
- if (os_being_run != winNT && lasterr == ERROR_ACCESS_DENIED
+ if (!iswinnt && lasterr == ERROR_ACCESS_DENIED
&& !win32_name.isremote ())
lasterr = ERROR_SHARING_VIOLATION;
bool delete_on_close_ok;
- delete_on_close_ok = !win32_name.isremote () && os_being_run == winNT;
+ delete_on_close_ok = !win32_name.isremote () && iswinnt;
/* Attempt to use "delete on close" semantics to handle removing
a file which may be open. */
}
/* Try to make hard link first on Windows NT */
- if (os_being_run == winNT)
+ if (iswinnt)
{
HANDLE hFileSource;
if (check_null_empty_str_errno (name))
return -1;
- if (os_being_run != winNT) // real chown only works on NT
+ if (!iswinnt) // real chown only works on NT
res = 0; // return zero (and do nothing) under Windows 9x
else
{
dtype = real_path.get_drive_type ();
if ((atts == -1 || ! (atts & FILE_ATTRIBUTE_DIRECTORY) ||
- (os_being_run == winNT
+ (iswinnt
&& dtype != DRIVE_NO_ROOT_DIR
&& dtype != DRIVE_UNKNOWN)))
{
&& GetLastError () != ERROR_FILE_EXISTS))
goto done;
- if (os_being_run == winNT)
+ if (iswinnt)
{
if (MoveFileEx (real_old.get_win32 (), real_new.get_win32 (),
MOVEFILE_REPLACE_EXISTING))
extern int allow_ntea, allow_ntsec, allow_smbntsec;
/* Windows 95/98/ME don't support file system security at all. */
- if (os_being_run != winNT)
+ if (!iswinnt)
return 0;
/* ntea is ok for supporting permission bits but it doesn't support
seteuid (uid_t uid)
{
sigframe thisframe (mainthread);
- if (os_being_run == winNT)
+ if (iswinnt)
{
char orig_username[UNLEN + 1];
char orig_domain[INTERNET_MAX_HOST_NAME_LENGTH + 1];
setegid (gid_t gid)
{
sigframe thisframe (mainthread);
- if (os_being_run == winNT)
+ if (iswinnt)
{
if (gid != (gid_t) -1)
{
#endif
case _SC_NPROCESSORS_CONF:
case _SC_NPROCESSORS_ONLN:
- if (os_being_run != winNT)
+ if (!iswinnt)
return 1;
/*FALLTHRU*/
case _SC_PHYS_PAGES:
return;
}
- if (os_being_run != winNT)
+ if (!iswinnt)
{
/* Add a priority string - not needed for NT
as NT has its own priority codes. */
msg_strings[0] = total_msg;
- if (os_being_run == winNT)
+ if (iswinnt)
{
/* For NT, open the event log and send the message */
HANDLE hEventSrc = RegisterEventSourceA (NULL, (process_ident != NULL) ?
pthread_cond::TimedWait (DWORD dwMilliseconds)
{
DWORD rv;
- if (os_being_run != winNT)
+ if (!iswinnt)
{
// FIXME: race condition (potentially drop events
// Possible solution (single process only) - place this in a critical section.
/* Ticks is in milliseconds, convert to our ticks. Use long long to prevent
overflow. */
clock_t tc = (clock_t) ((long long) ticks * CLOCKS_PER_SEC / 1000);
- if (os_being_run == winNT)
+ if (iswinnt)
{
GetProcessTimes (hMainProc, &creation_time, &exit_time,
&kernel_time, &user_time);
/* Allow the others to open us (for handle duplication) */
- if ((os_being_run == winNT) &&
+ if ((iswinnt) &&
(SetKernelObjectSecurity (hMainProc, DACL_SECURITY_INFORMATION,
get_null_sd ()) == FALSE))
small_printf ("Can't set process security, %E");
user.set_name (username);
debug_printf ("GetUserName() = %s", user.name ());
- if (os_being_run == winNT)
+ if (iswinnt)
{
LPWKSTA_USER_INFO_1 wui;
NET_API_STATUS ret;
/* Used for runtime OS check/decisions. */
enum os_type {winNT = 1, win95, win98, winME, win32s, unknown};
extern os_type os_being_run;
+extern bool iswinnt;
enum codepage_type {ansi_cp, oem_cp};
extern codepage_type current_codepage;