mirror of
git://sourceware.org/git/newlib-cygwin.git
synced 2025-01-27 17:40:37 +08:00
44d2fc0a45
* child_info.h: Redefine CURR_CHILD_INFO_MAGIC. (child_info_fork::abort): Rename from handle_failure. Change arguments. * cygtls.h (_local_storage::ttybuf): New field. * dcrt0.cc (vapi_fatal): Split api_fatal. Add "in forked process" to message when appropriate. (api_fatal): Use vapi_fatal. * devices.h: Make multiple inclusion safe. (fh_devices): Add FH_CONS* stuff. Reorder slightly. (device): Eliminate anonymous union. Add more ways to access minor/major. (device::setunit): Accommodate no-longer-anonymous union. (device::is_fs): Ditto. (device::is_fs_special): Ditto. (device::major): New function. (device::minor): Ditto. (device::is_device): New function. (device::not_device): Ditto. (device::operator int): New operator. (device::operator fh_devices): Ditto. (device::operator bool): Ditto. (device::operator DWORD): Ditto. (device::operator =): Ditto. (isproc_dev): New function. (isprocsys_dev): Ditto. (iscons_dev): Ditto. (istty_slave_dev): Ditto. * devices.in: Add new "/dev/cons*" strings. Accommodate no-longer-anonymous union throughout. (BRACK): Use more precise method for initialization. * devices.cc: Regenerate. * dtable.cc (dtable::stdio_init): Use get_cttyp instead of get_tty. (dtable::find_archetype): Use new DWORD operator in device to test archetypes. (dtable::init_std_file_from_handle): Use different method to initialize 'dev'. Adapt to different ctty handling and accommodate /dev/cons*. (fh_alloc): Accommodate no-longer-anonymous union. Adapt to new /dev/cons*. (build_fh_pc): Make debugging output more useful. * exceptions.cc (ctrl_c_handler): Use get_cttyp instead of get_tty. * external.cc (fillout_pinfo): Accommodate new cons* stuff. * fhandler.cc (fhandler_base::read): Eliminate is_slow() test. * fhandler.h (fhandler_base::*): Adapt to changes in device.h. (fhandler_*::is_slow): Delete. ( fhandler_proc::get_proc_fhandler): Return fh_devices type. * fhandler_console.cc (open_shared_console): New function. (console_unit): New class. (console_unit::console_unit): New constructor. (enum_windows): New function. Declare as friend to console_unit. (fhandler_console::set_unit): New function. (fhandler_console::get_tty_stuff): Call set_unit to set the unit number and determine if initialization is needed. Eliminate flags parameter. (tty_list::get_cttyp): Rename (sorta) from get_tty. Return pointer to correct tty_min. (fhandler_console::open): Adapt to elimination of argument to get_tty_stuff. (fhandler_console::output_tcsetattr): Properly detect error condition. (fhandler_console::fixup_after_fork_exec): Adapt to get_tty_stuff() setting tc automatically. * fhandler_proc.cc: Use FH_BAD rather than 0 throughout where using fh_devices enum. (fhandler_proc::get_proc_fhandler): Return fh_devices. Adapt to devices.h changes. * fhandler_process.cc: Adapt to devices.h changes. Use FH_BAD rather than 0 throughout where using fh_devices enum. * fhandler_procnet.cc: Ditto. * fhandler_procsys.cc: Ditto. * fhandler_procsysvipc.cc: Ditto. * fhandler_tape.cc (fhandler_dev_tape::fhandler_dev_tape): Ditto. * fhandler_termios.cc (handler_termios::bg_check): Use tc->ttyname() rather than assuming that we can construct a tty. * fhandler_tty.cc (fhandler_tty_master::fhandler_tty_master): Just return get_minor() of dev. (fhandler_pty_master::process_slave_output): Add slightly more debugging info. (fhandler_tty_slave::fhandler_tty_slave): Change name from ntty to unit. (fhandler_pty_master::open): Ditto. (fhandler_tty_slave::ioctl): Adapt to change which causes ctty to represent a complete device. (fhandler_tty_master::init_console): Add debugging for failure path. (fhandler_pty_master::setup): Use get_unit() to retrieve unit number rather than relying on raw ntty. (fhandler_pty_master::setup): Ditto. * fhandler_virtual.h (virt_tab_t): Redefine fhandler as fh_devices. * fork.cc: Remove obsolete vfork stuff. (frok::child): Don't assume that a ctty == 0 is valid. * mount.cc (mount_info::conv_to_win32_path): Adapt to device struct changes. (mount_info::conv_to_win32_path): Ditto. * path.cc (path_conv::check): Retrive major/minor numbers via a method rather than accessing them directly from device. Rely on dev operators to set/retrieve device information as required by device struct change. * path.h (isproc_dev): Move to devices.h. (isprocsys_dev): Ditto. (isvirtual_dev): Ditto. (path_conv:{isdevice,isfifo,isspecial,iscygdrive,issocket,get_devn,get_unitn}): Use device methods to access/manipulate devices. * pinfo.cc (pinfo::exit): Don't assume that ctty == 0 is valid. Use iscons_dev to determine if a device is a console. (_pinfo::_ctty): Use device::parse to generate tty/cons name. (_pinfo::set_ctty): Don't assume that ctty == 0 is valid. Remove redundant info from debugging. * shared.cc (offsets): Remove console offset. * shared_info.h (shared_locations): Ditto. * syscalls.cc (umask): Use device methods to manipulate device information. (ctermid): Use device::parse to generate term device name. * tlsoffsets.h: Regenerate. * tty.cc (ttyslot): Return minor number of ctty since ctty now represents a full device. (tty::create_master): Set ctty to a complete device. (tty_list::attach): Rework to detect new /dev/cons* stuff. (tty_list::terminate): Adapt to changes to ctty. (tty_list::init): Adapt to change to setntty - pass in device major number. (tty::exists): Use get_unit() to retrive tty unit number. (tty::open_mutex): Ditto. (tty::open_inuse): Ditto. (tty::create_inuse): Ditto. (tty::get_event): Ditto. (tty_min::ttyname): Define new function. * tty.h (tty_min::ntty): Redefine as fh_devices. (tty::exists): Use get_unit() to retrive tty unit number. (tty::open_mutex): Ditto. (tty::open_inuse): Ditto. (tty::create_inuse): Ditto. (tty::get_event): Ditto. (tty_min::ttyname): Declare new function. (tty::getntty): Declare as const. (tty_list::operator []): Assure that only minor part of argument is used. * dll_init.cc (dll_list::alloc): Detect mismatch of data segments early issuing an explicit error message if necessary. * heap.cc (heap_init): Adapt to changes from fork->handle_failure to fork->abort. * pinfo.h (EXITCODE_FORK_FAILED): New enum. (from Ryan Johnson) * sigproc.cc (child_info_fork::abort): Rename from handle_failure. Change arguments to allow passing in a printf-like message. * winsup.h (api_fatal): Delete macro definition. (api_fatal): Redefine from __api_fatal. (vapi_fatal): Declare new function. * include/sys/strace.h (strace_vprintf): Define new macro. * ntdll.h (_SYSTEM_INFORMATION_CLASS): Add SystemHandleInformation.
320 lines
10 KiB
C++
320 lines
10 KiB
C++
/* winsup.h: main Cygwin header file.
|
|
|
|
Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
|
|
2005, 2006, 2007, 2008, 2009, 2010, 2011 Red Hat, Inc.
|
|
|
|
This file is part of Cygwin.
|
|
|
|
This software is a copyrighted work licensed under the terms of the
|
|
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
|
|
details. */
|
|
|
|
#ifdef DEBUGIT
|
|
#define spf(a, b, c) small_printf (a, b, c)
|
|
#else
|
|
#define spf(a, b, c) do {} while (0)
|
|
#endif
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
# include "config.h"
|
|
#endif
|
|
|
|
#define __INSIDE_CYGWIN__
|
|
|
|
#define NO_COPY __attribute__((nocommon)) __attribute__((section(".data_cygwin_nocopy")))
|
|
#define NO_COPY_INIT __attribute__((section(".data_cygwin_nocopy")))
|
|
|
|
#define EXPORT_ALIAS(sym,symalias) extern "C" __typeof (sym) symalias __attribute__ ((alias(#sym)));
|
|
|
|
#define WINVER 0x0601
|
|
#define _NO_W32_PSEUDO_MODIFIERS
|
|
|
|
#include <sys/types.h>
|
|
#include <sys/strace.h>
|
|
|
|
/* Declarations for functions used in C and C++ code. */
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
__uid32_t getuid32 ();
|
|
__uid32_t geteuid32 ();
|
|
int seteuid32 (__uid32_t);
|
|
__gid32_t getegid32 (void);
|
|
struct passwd *getpwuid32 (__uid32_t);
|
|
struct passwd *getpwnam (const char *);
|
|
struct __sFILE64 *fopen64 (const char *, const char *);
|
|
struct hostent *cygwin_gethostbyname (const char *name);
|
|
/* Don't enforce definition of in_addr_t. */
|
|
uint32_t cygwin_inet_addr (const char *cp);
|
|
int fcntl64 (int fd, int cmd, ...);
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
/* Note that MAX_PATH is defined in the windows headers */
|
|
/* There is also PATH_MAX and MAXPATHLEN.
|
|
PATH_MAX is from Posix and does include the trailing NUL.
|
|
MAXPATHLEN is from Unix.
|
|
|
|
Thou shalt *not* use CYG_MAX_PATH anymore. Use NT_MAX_PATH or
|
|
dynamic allocation instead when accessing real files. Use
|
|
MAX_PATH in case you need a convenient small buffer when creating
|
|
names for synchronization objects or named pipes. */
|
|
#define CYG_MAX_PATH (MAX_PATH)
|
|
|
|
/* There's no define for the maximum path length the NT kernel can handle.
|
|
That's why we define our own to use in path length test and for path
|
|
buffer sizes. As MAX_PATH and PATH_MAX, this is defined including the
|
|
trailing 0. Internal buffers and internal path routines should use
|
|
NT_MAX_PATH. PATH_MAX as defined in limits.h is the maximum length of
|
|
application provided path strings we handle. */
|
|
#define NT_MAX_PATH 32768
|
|
|
|
/* This definition allows to define wide char strings using macros as
|
|
parameters. See the definition of __CONCAT in newlib's sys/cdefs.h
|
|
and accompanying comment. */
|
|
#define __WIDE(a) L ## a
|
|
#define _WIDE(a) __WIDE(a)
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern const char case_folded_lower[];
|
|
#define cyg_tolower(c) (case_folded_lower[(unsigned char)(c)])
|
|
extern const char case_folded_upper[];
|
|
#define cyg_toupper(c) (case_folded_upper[(unsigned char)(c)])
|
|
|
|
#ifndef MALLOC_DEBUG
|
|
#define cfree newlib_cfree_dont_use
|
|
#endif
|
|
|
|
#include "winlean.h"
|
|
#include "wincap.h"
|
|
|
|
/* The one function we use from winuser.h most of the time */
|
|
extern "C" DWORD WINAPI GetLastError (void);
|
|
|
|
/* Used as type by sys_wcstombs_alloc and sys_mbstowcs_alloc. For a
|
|
description see there. */
|
|
#define HEAP_NOTHEAP -1
|
|
|
|
/* Used to check if Cygwin DLL is dynamically loaded. */
|
|
|
|
extern int cygserver_running;
|
|
|
|
#define _MT_SAFE // DELETEME someday
|
|
|
|
#define TITLESIZE 1024
|
|
|
|
#include "debug.h"
|
|
|
|
#include <wchar.h>
|
|
|
|
/**************************** Convenience ******************************/
|
|
|
|
/* Used to define status flag accessor methods */
|
|
#define IMPLEMENT_STATUS_FLAG(type,flag) \
|
|
type flag (type val) { return (type) (status.flag = (val)); } \
|
|
type flag () const { return (type) status.flag; }
|
|
|
|
/* Used when treating / and \ as equivalent. */
|
|
#define iswdirsep(ch) \
|
|
({ \
|
|
WCHAR __c = (ch); \
|
|
((__c) == L'/' || (__c) == L'\\'); \
|
|
})
|
|
|
|
#define isdirsep(ch) \
|
|
({ \
|
|
char __c = (ch); \
|
|
((__c) == '/' || (__c) == '\\'); \
|
|
})
|
|
|
|
/* Convert a signal to a signal mask */
|
|
#define SIGTOMASK(sig) (1 << ((sig) - 1))
|
|
|
|
#define set_api_fatal_return(n) do {extern int __api_fatal_exit_val; __api_fatal_exit_val = (n);} while (0)
|
|
|
|
#undef issep
|
|
#define issep(ch) (strchr (" \t\n\r", (ch)) != NULL)
|
|
|
|
/* Every path beginning with / or \, as well as every path being X:
|
|
or starting with X:/ or X:\ */
|
|
#define isabspath_u(p) \
|
|
((p)->Length && \
|
|
(iswdirsep ((p)->Buffer[0]) || \
|
|
((p)->Length > sizeof (WCHAR) && iswalpha ((p)->Buffer[0]) \
|
|
&& (p)->Buffer[1] == L':' && \
|
|
((p)->Length == 2 * sizeof (WCHAR) || iswdirsep ((p)->Buffer[2])))))
|
|
|
|
#define iswabspath(p) \
|
|
(iswdirsep (*(p)) || (iswalpha (*(p)) && (p)[1] == L':' && (!(p)[2] || iswdirsep ((p)[2]))))
|
|
|
|
#define isabspath(p) \
|
|
(isdirsep (*(p)) || (isalpha (*(p)) && (p)[1] == ':' && (!(p)[2] || isdirsep ((p)[2]))))
|
|
|
|
/******************** Initialization/Termination **********************/
|
|
|
|
class per_process;
|
|
/* cygwin .dll initialization */
|
|
void dll_crt0 (per_process *) __asm__ ("_dll_crt0__FP11per_process");
|
|
extern "C" void __stdcall _dll_crt0 ();
|
|
void dll_crt0_1 (void *);
|
|
void dll_dllcrt0_1 (void *);
|
|
int spawn_guts (const char * prog_arg, const char *const *argv,
|
|
const char *const envp[], int mode, int __stdin = -1,
|
|
int __stdout = -1) __attribute__ ((regparm(3)));
|
|
|
|
/* dynamically loaded dll initialization */
|
|
extern "C" int dll_dllcrt0 (HMODULE, per_process *);
|
|
|
|
void _pei386_runtime_relocator (per_process *);
|
|
|
|
/* dynamically loaded dll initialization for non-cygwin apps */
|
|
extern "C" int dll_noncygwin_dllcrt0 (HMODULE, per_process *);
|
|
void __stdcall do_exit (int) __attribute__ ((regparm (1), noreturn));
|
|
|
|
/* libstdc++ malloc operator wrapper support. */
|
|
extern struct per_process_cxx_malloc default_cygwin_cxx_malloc;
|
|
|
|
/* UID/GID */
|
|
void uinfo_init ();
|
|
|
|
#define ILLEGAL_UID16 ((__uid16_t)-1)
|
|
#define ILLEGAL_UID ((__uid32_t)-1)
|
|
#define ILLEGAL_GID16 ((__gid16_t)-1)
|
|
#define ILLEGAL_GID ((__gid32_t)-1)
|
|
#define ILLEGAL_SEEK ((_off64_t)-1)
|
|
|
|
#define uid16touid32(u16) ((u16)==ILLEGAL_UID16?ILLEGAL_UID:(__uid32_t)(u16))
|
|
#define gid16togid32(g16) ((g16)==ILLEGAL_GID16?ILLEGAL_GID:(__gid32_t)(g16))
|
|
|
|
/* Convert LARGE_INTEGER into long long */
|
|
#define get_ll(pl) (((long long) (pl).HighPart << 32) | (pl).LowPart)
|
|
|
|
/* various events */
|
|
void events_init ();
|
|
void events_terminate ();
|
|
|
|
void __stdcall close_all_files (bool = false);
|
|
|
|
/* debug_on_trap support. see exceptions.cc:try_to_debug() */
|
|
extern "C" void error_start_init (const char*);
|
|
extern "C" int try_to_debug (bool waitloop = 1);
|
|
|
|
void ld_preload ();
|
|
const char *find_first_notloaded_dll (class path_conv &);
|
|
|
|
extern bool cygwin_finished_initializing;
|
|
|
|
/**************************** Miscellaneous ******************************/
|
|
|
|
void __stdcall set_std_handle (int);
|
|
int __stdcall stat_dev (DWORD, int, unsigned long, struct __stat64 *);
|
|
|
|
__ino64_t __stdcall hash_path_name (__ino64_t hash, PUNICODE_STRING name) __attribute__ ((regparm(2)));
|
|
__ino64_t __stdcall hash_path_name (__ino64_t hash, PCWSTR name) __attribute__ ((regparm(2)));
|
|
__ino64_t __stdcall hash_path_name (__ino64_t hash, const char *name) __attribute__ ((regparm(2)));
|
|
void __stdcall nofinalslash (const char *src, char *dst) __attribute__ ((regparm(2)));
|
|
|
|
void *hook_or_detect_cygwin (const char *, const void *, WORD&) __attribute__ ((regparm (3)));
|
|
|
|
/* Time related */
|
|
void __stdcall totimeval (struct timeval *, FILETIME *, int, int);
|
|
long __stdcall to_time_t (FILETIME *);
|
|
void __stdcall to_timestruc_t (FILETIME *, timestruc_t *);
|
|
void __stdcall time_as_timestruc_t (timestruc_t *);
|
|
void __stdcall timespec_to_filetime (const struct timespec *, FILETIME *);
|
|
void __stdcall timeval_to_filetime (const struct timeval *, FILETIME *);
|
|
|
|
/* Console related */
|
|
void __stdcall set_console_title (char *);
|
|
void init_console_handler (bool);
|
|
|
|
void init_global_security ();
|
|
|
|
void __set_winsock_errno (const char *fn, int ln) __attribute__ ((regparm(2)));
|
|
#define set_winsock_errno() __set_winsock_errno (__FUNCTION__, __LINE__)
|
|
|
|
extern bool wsock_started;
|
|
|
|
/* Printf type functions */
|
|
extern "C" void vapi_fatal (const char *, va_list ap) __attribute__ ((noreturn));
|
|
extern "C" void api_fatal (const char *, ...) __attribute__ ((noreturn));
|
|
int __small_sprintf (char *dst, const char *fmt, ...) /*__attribute__ ((regparm (2)))*/;
|
|
int __small_vsprintf (char *dst, const char *fmt, va_list ap) /*__attribute__ ((regparm (3)))*/;
|
|
int __small_swprintf (PWCHAR dst, const WCHAR *fmt, ...) /*__attribute__ ((regparm (2)))*/;
|
|
int __small_vswprintf (PWCHAR dst, const WCHAR *fmt, va_list ap) /*__attribute__ ((regparm (3)))*/;
|
|
void multiple_cygwin_problem (const char *, unsigned, unsigned);
|
|
|
|
extern "C" void vklog (int priority, const char *message, va_list ap);
|
|
extern "C" void klog (int priority, const char *message, ...);
|
|
bool child_copy (HANDLE, bool, ...);
|
|
|
|
int symlink_worker (const char *, const char *, bool, bool)
|
|
__attribute__ ((regparm (3)));
|
|
|
|
class path_conv;
|
|
|
|
int __stdcall stat_worker (path_conv &pc, struct __stat64 *buf) __attribute__ ((regparm (2)));
|
|
|
|
__ino64_t __stdcall readdir_get_ino (const char *path, bool dot_dot) __attribute__ ((regparm (2)));
|
|
|
|
/* Returns the real page size, not the allocation size. */
|
|
size_t getsystempagesize ();
|
|
|
|
/* mmap functions. */
|
|
enum mmap_region_status
|
|
{
|
|
MMAP_NONE,
|
|
MMAP_RAISE_SIGBUS,
|
|
MMAP_NORESERVE_COMMITED
|
|
};
|
|
mmap_region_status mmap_is_attached_or_noreserve (void *addr, size_t len);
|
|
bool is_mmapped_region (caddr_t start_addr, caddr_t end_address);
|
|
|
|
inline bool flush_file_buffers (HANDLE h)
|
|
{
|
|
return (GetFileType (h) != FILE_TYPE_PIPE) ? FlushFileBuffers (h) : true;
|
|
}
|
|
#define FlushFileBuffers flush_file_buffers
|
|
|
|
/**************************** Exports ******************************/
|
|
|
|
extern "C" {
|
|
int cygwin_select (int , fd_set *, fd_set *, fd_set *,
|
|
struct timeval *to);
|
|
int cygwin_gethostname (char *__name, size_t __len);
|
|
};
|
|
|
|
/*************************** Unsorted ******************************/
|
|
|
|
#define WM_ASYNCIO 0x8000 // WM_APP
|
|
|
|
|
|
#define STD_RBITS (S_IRUSR | S_IRGRP | S_IROTH)
|
|
#define STD_WBITS (S_IWUSR)
|
|
#define STD_XBITS (S_IXUSR | S_IXGRP | S_IXOTH)
|
|
#define NO_W ~(S_IWUSR | S_IWGRP | S_IWOTH)
|
|
#define NO_R ~(S_IRUSR | S_IRGRP | S_IROTH)
|
|
#define NO_X ~(S_IXUSR | S_IXGRP | S_IXOTH)
|
|
|
|
|
|
extern "C" char _data_start__, _data_end__, _bss_start__, _bss_end__;
|
|
extern "C" void (*__CTOR_LIST__) (void);
|
|
extern "C" void (*__DTOR_LIST__) (void);
|
|
|
|
#if !defined(_GLOBALS_H)
|
|
#include "globals.h"
|
|
inline void clear_procimptoken ()
|
|
{
|
|
if (hProcImpToken)
|
|
{
|
|
HANDLE old_procimp = hProcImpToken;
|
|
hProcImpToken = NULL;
|
|
CloseHandle (old_procimp);
|
|
}
|
|
}
|
|
#endif
|
|
|
|
#endif /* defined __cplusplus */
|