newlib/winsup/cygwin/winsup.h

273 lines
7.9 KiB
C
Raw Normal View History

2000-02-17 20:38:33 +01:00
/* winsup.h: main Cygwin header file.
Copyright 1996, 1997, 1998, 1999, 2000, 2001 Red Hat, Inc.
2000-02-17 20:38:33 +01:00
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 HAVE_CONFIG_H
# include "config.h"
#endif
#define __INSIDE_CYGWIN__
#define alloca __builtin_alloca
2000-02-17 20:38:33 +01:00
#define strlen __builtin_strlen
#define strcmp __builtin_strcmp
2000-02-17 20:38:33 +01:00
#define strcpy __builtin_strcpy
#define memcpy __builtin_memcpy
#define memcmp __builtin_memcmp
#ifdef HAVE_BUILTIN_MEMSET
# define memset __builtin_memset
#endif
2001-03-05 07:28:25 +01:00
#ifdef __cplusplus
#if !defined(__STDC_VERSION__) || __STDC_VERSION__ >= 199900L
#define NEW_MACRO_VARARGS
#endif
2000-02-17 20:38:33 +01:00
#include <sys/types.h>
#include <sys/strace.h>
#undef strchr
#define strchr cygwin_strchr
extern "C" inline __stdcall char * strchr(const char * s, int c)
2000-02-17 20:38:33 +01:00
{
register char * __res;
__asm__ __volatile__(
"movb %%al,%%ah\n"
"1:\tmovb (%1),%%al\n\t"
"cmpb %%ah,%%al\n\t"
"je 2f\n\t"
"incl %1\n\t"
"testb %%al,%%al\n\t"
"jne 1b\n\t"
"xorl %1,%1\n"
"2:\tmovl %1,%0\n\t"
:"=a" (__res), "=r" (s)
:"0" (c), "1" (s));
return __res;
}
extern char case_folded_lower[];
#define cyg_tolower(c) (case_folded_lower[(unsigned char)(c)])
extern char case_folded_upper[];
#define cyg_toupper(c) (case_folded_upper[(unsigned char)(c)])
#define cfree newlib_cfree_dont_use
#define WIN32_LEAN_AND_MEAN 1
#define _WINGDI_H
#define _WINUSER_H
#define _WINNLS_H
#define _WINVER_H
#define _WINNETWK_H
#define _WINSVC_H
2000-02-17 20:38:33 +01:00
#include <windows.h>
#include <wincrypt.h>
#undef _WINGDI_H
#undef _WINUSER_H
#undef _WINNLS_H
#undef _WINVER_H
#undef _WINNETWK_H
#undef _WINSVC_H
/* The one function we use from winuser.h most of the time */
extern "C" DWORD WINAPI GetLastError (void);
2000-02-17 20:38:33 +01:00
/* Used for runtime OS check/decisions. */
enum os_type {winNT = 1, win95, win98, winME, win32s, unknown};
2000-02-17 20:38:33 +01:00
extern os_type os_being_run;
enum codepage_type {ansi_cp, oem_cp};
extern codepage_type current_codepage;
2000-02-17 20:38:33 +01:00
/* Used to check if Cygwin DLL is dynamically loaded. */
extern int dynamically_loaded;
#define sys_wcstombs(tgt,src,len) \
WideCharToMultiByte((current_codepage==ansi_cp?CP_ACP:CP_OEMCP),0,(src),-1,(tgt),(len),NULL,NULL)
#define sys_mbstowcs(tgt,src,len) \
MultiByteToWideChar((current_codepage==ansi_cp?CP_ACP:CP_OEMCP),0,(src),-1,(tgt),(len))
2000-02-17 20:38:33 +01:00
#define TITLESIZE 1024
#define MAX_USER_NAME 20
#define DEFAULT_UID 500
#define DEFAULT_GID 544
#define MAX_SID_LEN 40
#define MAX_HOST_NAME 256
2000-02-17 20:38:33 +01:00
/* status bit manipulation */
#define __ISSETF(what, x, prefix) \
((what)->status & prefix##_##x)
#define __SETF(what, x, prefix) \
((what)->status |= prefix##_##x)
#define __CLEARF(what, x, prefix) \
((what)->status &= ~prefix##_##x)
#define __CONDSETF(n, what, x, prefix) \
((n) ? __SETF (what, x, prefix) : __CLEARF (what, x, prefix))
#include "debug.h"
/* Events/mutexes */
extern HANDLE title_mutex;
/**************************** Convenience ******************************/
#define NO_COPY __attribute__((section(".data_cygwin_nocopy")))
/* Used when treating / and \ as equivalent. */
#define SLASH_P(ch) \
({ \
char __c = (ch); \
((__c) == '/' || (__c) == '\\'); \
})
/* Convert a signal to a signal mask */
#define SIGTOMASK(sig) (1<<((sig) - signal_shift_subtract))
extern unsigned int signal_shift_subtract;
#ifdef NEW_MACRO_VARARGS
# define api_fatal(...) __api_fatal ("%P: *** " __VA_ARGS__)
#else
# define api_fatal(fmt, args...) __api_fatal ("%P: *** " fmt,## args)
#endif
2000-02-17 20:38:33 +01:00
#undef issep
#define issep(ch) (strchr (" \t\n\r", (ch)) != NULL)
#define isdirsep SLASH_P
#define isabspath(p) \
(isdirsep (*(p)) || (isalpha (*(p)) && (p)[1] == ':' && (!(p)[2] || isdirsep ((p)[2]))))
2000-02-17 20:38:33 +01:00
/******************** Initialization/Termination **********************/
class per_process;
2000-02-17 20:38:33 +01:00
/* cygwin .dll initialization */
void dll_crt0 (per_process *) __asm__ ("_dll_crt0__FP11per_process");
extern "C" void __stdcall _dll_crt0 ();
2000-02-17 20:38:33 +01:00
/* dynamically loaded dll initialization */
extern "C" int dll_dllcrt0 (HMODULE, per_process *);
2000-02-17 20:38:33 +01:00
/* dynamically loaded dll initialization for non-cygwin apps */
extern "C" int dll_noncygwin_dllcrt0 (HMODULE, per_process *);
/* exit the program */
extern "C" void __stdcall do_exit (int) __attribute__ ((noreturn));
/* UID/GID */
void uinfo_init (void);
/* various events */
void events_init (void);
void events_terminate (void);
void __stdcall close_all_files (void);
/* Invisible window initialization/termination. */
HWND __stdcall gethwnd (void);
void __stdcall window_terminate (void);
/* Globals that handle initialization of winsock in a child process. */
extern HANDLE wsock32_handle;
extern HANDLE ws2_32_handle;
2000-02-17 20:38:33 +01:00
/* Globals that handle initialization of netapi in a child process. */
extern HANDLE netapi32_handle;
/* debug_on_trap support. see exceptions.cc:try_to_debug() */
extern "C" void error_start_init (const char*);
extern "C" int try_to_debug ();
extern int cygwin_finished_initializing;
2000-02-17 20:38:33 +01:00
/**************************** Miscellaneous ******************************/
void __stdcall set_std_handle (int);
int __stdcall writable_directory (const char *file);
int __stdcall stat_dev (DWORD, int, unsigned long, struct stat *);
extern BOOL allow_ntsec;
* Makefile.in: Remove some obsolete stuff. * dcrt0.cc (dll_crt0_1): Call signal_fixup_after_exec where appropriate. Set myself->uid from parent version. Just use ThreadItem Init method. Close or store hexec_proc as appropriate. (_dll_crt0): Store user_data->forkee here so that proper tests can be made subsequently. (do_exit): Remove hExeced stuff. * environ.cc (environ_init): Accept environ count as well as environ pointer. * environ.h: Reflect above change. * pinfo.cc (pinfo_init): Ditto. Accept environ count. (fixup_in_spawned_child): Remove. * spawn.cc (spawn_guts): Move signal code to dll_crt0_1. Don't suspend execing process since it is no longer necessary. Store envc. * exceptions.cc (signal_fixup_after_exec): New function. (call_handler): Remove hExeced test. * child_info.h (cygheap_exec_info): Store envc as well as envp. (child_info_spawn): Store hexec_proc so that it can be closed in child. * path.cc (normalize_posix_path): Avoid intermediate use of temporary cwd buf. (normalize_win32_path): Ditto. (cwdstuff::get_initial): Always set lock. * sigproc.h: Remove hExeced. * strace.cc (strace::vsprntf): Modify to accomodate for lack of hExeced. * thread.cc (MTinterface::Init): Merge Init1 and ClearReent into this method. (MTinterface::Init1): Eliminate. (MTinterface::ClearReent): Eliminate. * thread.h: Reflect above changes. * include/sys/strace.h (strace): Make microseconds() public. Make various functions 'regparm', throughout. * pinfo.h (_pinfo): Inline simple signal manipulation functions. Requires inclusion of thread.h which was removed from .cc files, where appropriate. throughout. * pinfo.cc: Eliminate signal manipulation functions. (_pinfo::exit): Calculate total rusage for exiting process here. * cygheap.cc (size2bucket): Eliminate. (init_buckets): Ditto. (_cmalloc): Calculate size and bits in a loop rather than going through a function call. (_crealloc): Use stored array index to calculate allocated size. * spawn.cc (spawn_guts): Use _pinfo exit method to exit, calculating cpu usage.
2000-10-17 01:55:58 +02:00
unsigned long __stdcall hash_path_name (unsigned long hash, const char *name) __attribute__ ((regparm(2)));
void __stdcall nofinalslash (const char *src, char *dst) __attribute__ ((regparm(2)));
extern "C" char *__stdcall rootdir (char *full_path) __attribute__ ((regparm(1)));
2000-02-17 20:38:33 +01:00
/* String manipulation */
* Makefile.in: Remove some obsolete stuff. * dcrt0.cc (dll_crt0_1): Call signal_fixup_after_exec where appropriate. Set myself->uid from parent version. Just use ThreadItem Init method. Close or store hexec_proc as appropriate. (_dll_crt0): Store user_data->forkee here so that proper tests can be made subsequently. (do_exit): Remove hExeced stuff. * environ.cc (environ_init): Accept environ count as well as environ pointer. * environ.h: Reflect above change. * pinfo.cc (pinfo_init): Ditto. Accept environ count. (fixup_in_spawned_child): Remove. * spawn.cc (spawn_guts): Move signal code to dll_crt0_1. Don't suspend execing process since it is no longer necessary. Store envc. * exceptions.cc (signal_fixup_after_exec): New function. (call_handler): Remove hExeced test. * child_info.h (cygheap_exec_info): Store envc as well as envp. (child_info_spawn): Store hexec_proc so that it can be closed in child. * path.cc (normalize_posix_path): Avoid intermediate use of temporary cwd buf. (normalize_win32_path): Ditto. (cwdstuff::get_initial): Always set lock. * sigproc.h: Remove hExeced. * strace.cc (strace::vsprntf): Modify to accomodate for lack of hExeced. * thread.cc (MTinterface::Init): Merge Init1 and ClearReent into this method. (MTinterface::Init1): Eliminate. (MTinterface::ClearReent): Eliminate. * thread.h: Reflect above changes. * include/sys/strace.h (strace): Make microseconds() public. Make various functions 'regparm', throughout. * pinfo.h (_pinfo): Inline simple signal manipulation functions. Requires inclusion of thread.h which was removed from .cc files, where appropriate. throughout. * pinfo.cc: Eliminate signal manipulation functions. (_pinfo::exit): Calculate total rusage for exiting process here. * cygheap.cc (size2bucket): Eliminate. (init_buckets): Ditto. (_cmalloc): Calculate size and bits in a loop rather than going through a function call. (_crealloc): Use stored array index to calculate allocated size. * spawn.cc (spawn_guts): Use _pinfo exit method to exit, calculating cpu usage.
2000-10-17 01:55:58 +02:00
extern "C" char *__stdcall strccpy (char *s1, const char **s2, char c);
extern "C" int __stdcall strcasematch (const char *s1, const char *s2) __attribute__ ((regparm(2)));
extern "C" int __stdcall strncasematch (const char *s1, const char *s2, size_t n) __attribute__ ((regparm(3)));
extern "C" char *__stdcall strcasestr (const char *searchee, const char *lookfor) __attribute__ ((regparm(2)));
2000-02-17 20:38:33 +01:00
/* Time related */
void __stdcall totimeval (struct timeval *dst, FILETIME * src, int sub, int flag);
long __stdcall to_time_t (FILETIME * ptr);
void __stdcall set_console_title (char *);
void set_console_handler ();
#define set_winsock_errno() __set_winsock_errno (__FUNCTION__, __LINE__)
void __set_winsock_errno (const char *fn, int ln);
2000-02-17 20:38:33 +01:00
/* Printf type functions */
extern "C" void __api_fatal (const char *, ...) __attribute__ ((noreturn));
extern "C" int __small_sprintf (char *dst, const char *fmt, ...);
extern "C" int __small_vsprintf (char *dst, const char *fmt, va_list ap);
2000-02-17 20:38:33 +01:00
/**************************** Exports ******************************/
extern "C" {
int cygwin_select (int , fd_set *, fd_set *, fd_set *,
struct timeval *to);
int cygwin_gethostname (char *__name, size_t __len);
int kill_pgrp (pid_t, int);
int _kill (int, int);
int _raise (int sig);
extern DWORD binmode;
2000-02-17 20:38:33 +01:00
extern char _data_start__, _data_end__, _bss_start__, _bss_end__;
extern void (*__CTOR_LIST__) (void);
extern void (*__DTOR_LIST__) (void);
Throughout, change 'cygwin_shared.mount' to 'mount_table'. * child_info.h (child_info): Move shared_h, console_h to cygheap. Add mount_h. * cygheap.h (init_cygheap): Add shared_h, console_h. * cygheap.cc (init_cheap): Initialize heap at a fixed location after the shared memory regions. Initialize cygheap->user name here. * dcrt0.cc (dll_crt0_1): Call getpagesize () to initialize constants. Remove cygheap_init since it is done in shared_init now. (_dll_crt0): Initialize mount_h, remove shared_h and console_h initialization. * fhandler_console.cc (console_shared_h): Eliminate. (get_tty_stuff): Use cygheap->console_h rather than console_shared_h. * heap.cc (heap_init): Use page size constant calculated earlier in initialization. * shared.cc: Eliminate cygwin_shared_h. Add cygwin_mount_h. (mount_table_init): New function for initializing a user mount table. (open_shared_file_map): Use constant for shared memory region. Initialize cygheap and mount table here. (open_shared): Improve debugging output. (shared_info::initialize): Eliminate call to mount.init. (shared_terminate): Use cygheap->shared_h. Close cygwin_mount_h. (open_shared_file_map): Eliminate. * shared_info.h (mount_info): Add a version field. (shared_align_past): New macro for calculating location for shared memory regions. * sigproc.cc (init_child_info): Eliminate shared_h, console_h. * spawn.cc (spawn_guts): Pass on cygwin_mount_h iff not a different user. * syscalls.cc (system_info): New global holding system memory defaults. (getpagesize): Use system_info. * uinfo.cc (internal_getlogin): Only fill in user name if nonexistent. * winsup.h: Declare system_info. * passwd.cc (read_etc_passwd): Use cygheap->user.name () rather than retrieving the name again.
2001-01-28 06:51:15 +01:00
extern SYSTEM_INFO system_info;
2000-02-17 20:38:33 +01:00
};
/*************************** Unsorted ******************************/
#define WM_ASYNCIO 0x8000 // WM_APP
/* Note that MAX_PATH is defined in the windows headers */
/* There is also PATH_MAX and MAXPATHLEN.
PATH_MAX is from Posix and does *not* include the trailing NUL.
MAXPATHLEN is from Unix.
Thou shalt use MAX_PATH throughout. It avoids the NUL vs no-NUL
issue and is neither of the Unixy ones [so we can punt on which
one is the right one to use]. */
#define STD_RBITS (S_IRUSR | S_IRGRP | S_IROTH)
#define STD_WBITS (S_IWUSR)
#define STD_XBITS (S_IXUSR | S_IXGRP | S_IXOTH)
2000-02-17 20:38:33 +01:00
#define O_NOSYMLINK 0x080000
#define O_DIROPEN 0x100000
/* newlib used to define O_NDELAY differently from O_NONBLOCK. Now it
properly defines both to be the same. Unfortunately, we have to
behave properly the old version, too, to accomodate older executables. */
#define OLD_O_NDELAY 4
2000-02-17 20:38:33 +01:00
/* The title on program start. */
extern char *old_title;
extern BOOL display_title;
extern HANDLE hMainThread;
extern HANDLE hMainProc;
#endif /* defined __cplusplus */