2000-09-03 06:16:35 +02:00
|
|
|
/* cygheap.h: Cygwin heap manager.
|
|
|
|
|
2008-04-01 15:22:47 +02:00
|
|
|
Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Red Hat, Inc.
|
2000-09-03 06:16:35 +02: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. */
|
|
|
|
|
2005-11-04 21:45:56 +01:00
|
|
|
#include "hires.h"
|
|
|
|
|
2000-09-03 06:16:35 +02:00
|
|
|
#undef cfree
|
|
|
|
|
|
|
|
enum cygheap_types
|
|
|
|
{
|
|
|
|
HEAP_FHANDLER,
|
|
|
|
HEAP_STR,
|
|
|
|
HEAP_ARGV,
|
2000-09-27 07:12:09 +02:00
|
|
|
HEAP_BUF,
|
2001-06-03 04:31:16 +02:00
|
|
|
HEAP_MOUNT,
|
2003-09-01 04:05:32 +02:00
|
|
|
HEAP_SIGS,
|
2003-12-11 07:12:41 +01:00
|
|
|
HEAP_ARCHETYPES,
|
2004-01-14 16:45:37 +01:00
|
|
|
HEAP_TLS,
|
2005-08-24 06:38:39 +02:00
|
|
|
HEAP_COMMUNE,
|
2000-09-27 07:12:09 +02:00
|
|
|
HEAP_1_START,
|
2005-03-22 20:00:31 +01:00
|
|
|
HEAP_1_HOOK,
|
2000-09-27 07:12:09 +02:00
|
|
|
HEAP_1_STR,
|
|
|
|
HEAP_1_ARGV,
|
|
|
|
HEAP_1_BUF,
|
2000-09-30 06:54:11 +02:00
|
|
|
HEAP_1_EXEC,
|
2003-08-23 02:03:54 +02:00
|
|
|
HEAP_1_MAX = 100,
|
2006-04-21 23:34:38 +02:00
|
|
|
HEAP_2_STR,
|
2003-08-23 02:03:54 +02:00
|
|
|
HEAP_MMAP = 200
|
2000-09-03 06:16:35 +02:00
|
|
|
};
|
|
|
|
|
2000-10-02 04:26:04 +02:00
|
|
|
#define incygheap(s) (cygheap && ((char *) (s) >= (char *) cygheap) && ((char *) (s) <= ((char *) cygheap_max)))
|
2000-09-03 06:16:35 +02:00
|
|
|
|
2000-11-14 06:53:32 +01:00
|
|
|
struct _cmalloc_entry
|
|
|
|
{
|
|
|
|
union
|
|
|
|
{
|
|
|
|
DWORD b;
|
|
|
|
char *ptr;
|
|
|
|
};
|
|
|
|
struct _cmalloc_entry *prev;
|
|
|
|
char data[0];
|
|
|
|
};
|
|
|
|
|
2001-06-03 04:31:16 +02:00
|
|
|
struct cygheap_root_mount_info
|
|
|
|
{
|
2003-11-15 00:40:06 +01:00
|
|
|
char posix_path[CYG_MAX_PATH];
|
2001-06-03 04:31:16 +02:00
|
|
|
unsigned posix_pathlen;
|
2003-11-15 00:40:06 +01:00
|
|
|
char native_path[CYG_MAX_PATH];
|
2001-06-03 04:31:16 +02:00
|
|
|
unsigned native_pathlen;
|
2008-07-16 22:20:45 +02:00
|
|
|
bool caseinsensitive;
|
2001-06-03 04:31:16 +02:00
|
|
|
};
|
|
|
|
|
2001-06-04 03:28:09 +02:00
|
|
|
/* CGF: FIXME This doesn't belong here */
|
|
|
|
|
2000-11-15 01:13:09 +01:00
|
|
|
class cygheap_root
|
|
|
|
{
|
|
|
|
/* Root directory information.
|
|
|
|
This is used after a chroot is called. */
|
2001-06-03 04:31:16 +02:00
|
|
|
struct cygheap_root_mount_info *m;
|
|
|
|
|
2000-11-15 01:13:09 +01:00
|
|
|
public:
|
2001-06-03 04:31:16 +02:00
|
|
|
bool posix_ok (const char *path)
|
|
|
|
{
|
|
|
|
if (!m)
|
|
|
|
return 1;
|
2008-07-16 22:20:45 +02:00
|
|
|
return path_prefix_p (m->posix_path, path, m->posix_pathlen,
|
|
|
|
m->caseinsensitive);
|
2001-06-03 04:31:16 +02:00
|
|
|
}
|
|
|
|
bool ischroot_native (const char *path)
|
|
|
|
{
|
|
|
|
if (!m)
|
|
|
|
return 1;
|
|
|
|
return strncasematch (m->native_path, path, m->native_pathlen)
|
2001-09-07 23:32:07 +02:00
|
|
|
&& (path[m->native_pathlen] == '\\' || !path[m->native_pathlen]);
|
2001-06-03 04:31:16 +02:00
|
|
|
}
|
|
|
|
const char *unchroot (const char *path)
|
|
|
|
{
|
|
|
|
if (!m)
|
|
|
|
return path;
|
|
|
|
const char *p = path + m->posix_pathlen;
|
|
|
|
if (!*p)
|
|
|
|
p = "/";
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
bool exists () {return !!m;}
|
2008-07-16 22:20:45 +02:00
|
|
|
void set (const char *, const char *, bool);
|
2001-06-03 04:31:16 +02:00
|
|
|
size_t posix_length () const { return m->posix_pathlen; }
|
|
|
|
const char *posix_path () const { return m->posix_path; }
|
|
|
|
size_t native_length () const { return m->native_pathlen; }
|
|
|
|
const char *native_path () const { return m->native_path; }
|
2000-11-15 01:13:09 +01:00
|
|
|
};
|
|
|
|
|
2002-06-12 07:13:54 +02:00
|
|
|
enum homebodies
|
|
|
|
{
|
|
|
|
CH_HOMEDRIVE,
|
|
|
|
CH_HOMEPATH,
|
|
|
|
CH_HOME
|
|
|
|
};
|
|
|
|
|
2001-01-17 15:57:09 +01:00
|
|
|
class cygheap_user
|
|
|
|
{
|
2000-11-15 01:13:09 +01:00
|
|
|
/* Extendend user information.
|
|
|
|
The information is derived from the internal_getlogin call
|
|
|
|
when on a NT system. */
|
2000-11-15 22:04:02 +01:00
|
|
|
char *pname; /* user's name */
|
|
|
|
char *plogsrv; /* Logon server, may be FQDN */
|
|
|
|
char *pdomain; /* Logon domain of the user */
|
2002-06-12 07:13:54 +02:00
|
|
|
char *homedrive; /* User's home drive */
|
|
|
|
char *homepath; /* User's home path */
|
2004-10-07 23:28:57 +02:00
|
|
|
char *psystemroot; /* Value of SYSTEMROOT */
|
2002-06-29 04:36:08 +02:00
|
|
|
char *pwinname; /* User's name as far as Windows knows it */
|
2002-06-27 22:44:27 +02:00
|
|
|
char *puserprof; /* User profile */
|
2003-09-27 03:56:36 +02:00
|
|
|
cygsid effec_cygsid; /* buffer for user's SID */
|
|
|
|
cygsid saved_cygsid; /* Remains intact even after impersonation */
|
2000-11-15 01:13:09 +01:00
|
|
|
public:
|
2003-09-16 11:24:52 +02:00
|
|
|
__uid32_t saved_uid; /* Remains intact even after impersonation */
|
|
|
|
__gid32_t saved_gid; /* Ditto */
|
2002-05-29 17:04:29 +02:00
|
|
|
__uid32_t real_uid; /* Remains intact on seteuid, replaced by setuid */
|
Change internal gid datatype from __gid16_t to __gid32_t
throughout.
* cygwin.din: Export new symbols chown32, fchown32, getegid32,
getgid32, getgrgid32, getgrnam32, getgroups32, initgroups32, lchown32,
setgid32, setegid32, getgrent32.
* grp.cc (grp32togrp16): New static function.
(getgrgid32): New function.
(getgrnam32): Ditto.
(getgrent32): Ditto.
(getgroups32): Change name of internal function from getgroups.
(getgroups32): New function.
(initgroups32): Ditto.
* syscalls.cc (chown32): Ditto.
(lchown32): Ditto.
(fchown32): Ditto.
(setegid32): Ditto.
(setgid32): Ditto.
* uinfo.cc (getgid32): Ditto.
(getegid32): Ditto.
* include/cygwin/grp.h: Remove declaration of getgrgid() and getgrnam().
Declare getgrgid32() and getgrnam32() instead. Declare getgid32().
2002-05-28 16:10:55 +02:00
|
|
|
__gid32_t real_gid; /* Ditto */
|
2002-07-29 14:51:52 +02:00
|
|
|
user_groups groups; /* Primary and supp SIDs */
|
2000-11-15 01:13:09 +01:00
|
|
|
|
2000-11-15 22:04:02 +01:00
|
|
|
/* token is needed if set(e)uid should be called. It can be set by a call
|
|
|
|
to `set_impersonation_token()'. */
|
2003-06-30 15:07:36 +02:00
|
|
|
HANDLE external_token;
|
|
|
|
HANDLE internal_token;
|
2005-04-03 15:06:43 +02:00
|
|
|
HANDLE curr_primary_token;
|
2007-07-16 22:01:15 +02:00
|
|
|
HANDLE curr_imp_token;
|
2000-11-15 22:04:02 +01:00
|
|
|
|
2002-06-27 22:44:27 +02:00
|
|
|
/* CGF 2002-06-27. I removed the initializaton from this constructor
|
|
|
|
since this class is always allocated statically. That means that everything
|
|
|
|
is zero anyway so there is no need to initialize it to zero. Since the
|
|
|
|
token initialization is always handled during process startup as well,
|
2003-12-07 23:37:12 +01:00
|
|
|
I've removed the constructor entirely. Please reinstate this if this
|
2002-06-27 22:44:27 +02:00
|
|
|
situation ever changes.
|
2001-06-04 16:29:54 +02:00
|
|
|
cygheap_user () : pname (NULL), plogsrv (NULL), pdomain (NULL),
|
2003-09-16 11:24:52 +02:00
|
|
|
homedrive (NULL), homepath (NULL),
|
2002-06-27 22:44:27 +02:00
|
|
|
token (INVALID_HANDLE_VALUE) {}
|
|
|
|
*/
|
|
|
|
|
2000-11-15 01:13:09 +01:00
|
|
|
~cygheap_user ();
|
|
|
|
|
2003-09-10 23:01:40 +02:00
|
|
|
void init ();
|
2000-11-15 01:13:09 +01:00
|
|
|
void set_name (const char *new_name);
|
|
|
|
const char *name () const { return pname; }
|
|
|
|
|
2002-06-29 04:36:08 +02:00
|
|
|
const char *env_logsrv (const char *, size_t);
|
|
|
|
const char *env_homepath (const char *, size_t);
|
|
|
|
const char *env_homedrive (const char *, size_t);
|
|
|
|
const char *env_userprofile (const char *, size_t);
|
|
|
|
const char *env_domain (const char *, size_t);
|
|
|
|
const char *env_name (const char *, size_t);
|
2004-10-07 23:28:57 +02:00
|
|
|
const char *env_systemroot (const char *, size_t);
|
2000-11-15 01:13:09 +01:00
|
|
|
|
2002-06-29 04:36:08 +02:00
|
|
|
const char *logsrv ()
|
|
|
|
{
|
2002-06-30 00:05:30 +02:00
|
|
|
const char *p = env_logsrv ("LOGONSERVER=", sizeof ("LOGONSERVER=") - 1);
|
|
|
|
return (p == almost_null) ? NULL : p;
|
2002-06-29 04:36:08 +02:00
|
|
|
}
|
|
|
|
const char *winname ()
|
|
|
|
{
|
2002-06-30 00:05:30 +02:00
|
|
|
const char *p = env_name ("USERNAME=", sizeof ("USERNAME=") - 1);
|
|
|
|
return (p == almost_null) ? NULL : p;
|
2002-06-29 04:36:08 +02:00
|
|
|
}
|
|
|
|
const char *domain ()
|
|
|
|
{
|
2002-06-30 00:05:30 +02:00
|
|
|
const char *p = env_domain ("USERDOMAIN=", sizeof ("USERDOMAIN=") - 1);
|
|
|
|
return (p == almost_null) ? NULL : p;
|
2002-06-29 04:36:08 +02:00
|
|
|
}
|
2003-09-27 03:56:36 +02:00
|
|
|
BOOL set_sid (PSID new_sid) {return (BOOL) (effec_cygsid = new_sid);}
|
|
|
|
BOOL set_saved_sid () { return (BOOL) (saved_cygsid = effec_cygsid); }
|
|
|
|
PSID sid () { return effec_cygsid; }
|
|
|
|
PSID saved_sid () { return saved_cygsid; }
|
2002-06-12 07:13:54 +02:00
|
|
|
const char *ontherange (homebodies what, struct passwd * = NULL);
|
2004-10-28 03:46:01 +02:00
|
|
|
#define NO_IMPERSONATION NULL
|
2007-07-16 22:01:15 +02:00
|
|
|
bool issetuid () const { return curr_imp_token != NO_IMPERSONATION; }
|
2005-04-03 15:06:43 +02:00
|
|
|
HANDLE primary_token () { return curr_primary_token; }
|
2007-07-16 22:01:15 +02:00
|
|
|
HANDLE imp_token () { return curr_imp_token; }
|
2003-06-30 15:07:36 +02:00
|
|
|
void deimpersonate ()
|
|
|
|
{
|
2007-01-24 11:50:47 +01:00
|
|
|
RevertToSelf ();
|
2003-06-30 15:07:36 +02:00
|
|
|
}
|
2005-04-03 15:06:43 +02:00
|
|
|
bool reimpersonate ()
|
2003-06-30 15:07:36 +02:00
|
|
|
{
|
2006-12-12 17:27:32 +01:00
|
|
|
if (issetuid ())
|
2007-07-16 22:01:15 +02:00
|
|
|
return ImpersonateLoggedOnUser (primary_token ());
|
2006-12-12 17:27:32 +01:00
|
|
|
return true;
|
2003-06-30 15:07:36 +02:00
|
|
|
}
|
2003-07-14 19:04:21 +02:00
|
|
|
bool has_impersonation_tokens ()
|
2004-10-28 03:46:01 +02:00
|
|
|
{ return external_token != NO_IMPERSONATION
|
|
|
|
|| internal_token != NO_IMPERSONATION
|
2005-04-03 15:06:43 +02:00
|
|
|
|| curr_primary_token != NO_IMPERSONATION; }
|
2003-06-30 15:07:36 +02:00
|
|
|
void close_impersonation_tokens ()
|
|
|
|
{
|
2007-07-16 22:01:15 +02:00
|
|
|
if (curr_imp_token != NO_IMPERSONATION)
|
|
|
|
CloseHandle (curr_imp_token);
|
2005-04-03 15:06:43 +02:00
|
|
|
if (curr_primary_token != NO_IMPERSONATION
|
|
|
|
&& curr_primary_token != external_token
|
|
|
|
&& curr_primary_token != internal_token)
|
|
|
|
CloseHandle (curr_primary_token);
|
2004-10-28 03:46:01 +02:00
|
|
|
if (external_token != NO_IMPERSONATION)
|
2005-04-03 15:06:43 +02:00
|
|
|
CloseHandle (external_token);
|
2004-10-28 03:46:01 +02:00
|
|
|
if (internal_token != NO_IMPERSONATION)
|
2005-04-03 15:06:43 +02:00
|
|
|
CloseHandle (internal_token);
|
2002-06-17 01:34:43 +02:00
|
|
|
}
|
2008-02-14 17:47:11 +01:00
|
|
|
PWCHAR get_windows_id (PWCHAR buf)
|
|
|
|
{
|
|
|
|
return effec_cygsid.string (buf);
|
|
|
|
}
|
|
|
|
char *get_windows_id (char *buf)
|
2004-11-20 20:09:19 +01:00
|
|
|
{
|
2007-02-22 11:54:47 +01:00
|
|
|
return effec_cygsid.string (buf);
|
2004-11-20 20:09:19 +01:00
|
|
|
}
|
2005-02-13 19:17:29 +01:00
|
|
|
|
2006-07-17 21:30:30 +02:00
|
|
|
const char *test_uid (char *&, const char *, size_t)
|
2002-06-29 04:36:08 +02:00
|
|
|
__attribute__ ((regparm (3)));
|
2000-11-15 01:13:09 +01:00
|
|
|
};
|
2000-11-14 06:53:32 +01:00
|
|
|
|
2001-04-17 05:52:08 +02:00
|
|
|
/* cwd cache stuff. */
|
|
|
|
|
|
|
|
class muto;
|
|
|
|
|
|
|
|
struct cwdstuff
|
|
|
|
{
|
|
|
|
char *posix;
|
2007-10-23 18:26:28 +02:00
|
|
|
UNICODE_STRING win32;
|
2008-01-31 15:18:49 +01:00
|
|
|
HANDLE dir;
|
2004-09-08 01:26:28 +02:00
|
|
|
DWORD drive_length;
|
2005-04-05 06:31:00 +02:00
|
|
|
static muto cwd_lock;
|
2008-03-07 12:24:51 +01:00
|
|
|
char *get (char *, int = 1, int = 0, unsigned = NT_MAX_PATH);
|
2008-01-31 15:18:49 +01:00
|
|
|
HANDLE get_handle () { return dir; }
|
2005-02-13 19:17:29 +01:00
|
|
|
DWORD get_drive (char * dst)
|
2004-09-08 01:26:28 +02:00
|
|
|
{
|
2007-10-23 18:26:28 +02:00
|
|
|
cwd_lock.acquire ();
|
2008-02-14 17:47:11 +01:00
|
|
|
DWORD ret = sys_wcstombs (dst, NT_MAX_PATH, win32.Buffer, drive_length);
|
2005-04-05 06:31:00 +02:00
|
|
|
cwd_lock.release ();
|
2007-10-23 18:26:28 +02:00
|
|
|
return ret;
|
2004-09-08 01:26:28 +02:00
|
|
|
}
|
2001-04-17 05:52:08 +02:00
|
|
|
void init ();
|
2007-10-23 18:26:28 +02:00
|
|
|
int set (PUNICODE_STRING, const char *, bool);
|
2001-04-17 05:52:08 +02:00
|
|
|
};
|
|
|
|
|
2002-07-13 22:00:27 +02:00
|
|
|
#ifdef DEBUGGING
|
|
|
|
struct cygheap_debug
|
|
|
|
{
|
|
|
|
handle_list starth;
|
|
|
|
handle_list *endh;
|
|
|
|
handle_list freeh[500];
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2002-10-22 18:18:55 +02:00
|
|
|
struct user_heap_info
|
|
|
|
{
|
|
|
|
void *base;
|
|
|
|
void *ptr;
|
|
|
|
void *top;
|
2003-08-22 21:25:56 +02:00
|
|
|
void *max;
|
2002-10-22 18:18:55 +02:00
|
|
|
unsigned chunk;
|
2006-10-31 19:41:16 +01:00
|
|
|
unsigned slop;
|
2002-10-22 18:18:55 +02:00
|
|
|
};
|
|
|
|
|
2005-03-22 20:00:31 +01:00
|
|
|
struct hook_chain
|
|
|
|
{
|
|
|
|
void **loc;
|
|
|
|
const void *func;
|
|
|
|
struct hook_chain *next;
|
|
|
|
};
|
|
|
|
|
2000-11-14 06:53:32 +01:00
|
|
|
struct init_cygheap
|
|
|
|
{
|
|
|
|
_cmalloc_entry *chain;
|
2001-09-06 05:39:18 +02:00
|
|
|
char *buckets[32];
|
2000-11-15 01:13:09 +01:00
|
|
|
cygheap_root root;
|
|
|
|
cygheap_user user;
|
2002-10-22 18:18:55 +02:00
|
|
|
user_heap_info user_heap;
|
2000-11-14 06:53:32 +01:00
|
|
|
mode_t umask;
|
2001-01-28 06:51:15 +01:00
|
|
|
HANDLE console_h;
|
2001-04-17 05:52:08 +02:00
|
|
|
cwdstuff cwd;
|
2001-04-18 23:10:15 +02:00
|
|
|
dtable fdtab;
|
2002-07-13 22:00:27 +02:00
|
|
|
#ifdef DEBUGGING
|
|
|
|
cygheap_debug debug;
|
|
|
|
#endif
|
2003-09-01 04:05:32 +02:00
|
|
|
struct sigaction *sigs;
|
2003-12-07 23:37:12 +01:00
|
|
|
|
2003-12-11 07:12:41 +01:00
|
|
|
fhandler_tty_slave *ctty; /* Current tty */
|
2004-01-24 00:05:33 +01:00
|
|
|
#ifdef NEWVFORK
|
2004-01-03 19:15:03 +01:00
|
|
|
fhandler_tty_slave *ctty_on_hold;
|
2004-01-24 00:05:33 +01:00
|
|
|
#endif
|
2004-02-12 04:01:58 +01:00
|
|
|
struct _cygtls **threadlist;
|
2004-01-14 16:45:37 +01:00
|
|
|
size_t sthreads;
|
2004-09-12 05:47:57 +02:00
|
|
|
pid_t pid; /* my pid */
|
2004-11-26 05:15:10 +01:00
|
|
|
HANDLE pid_handle; /* handle for my pid */
|
2008-03-24 15:48:58 +01:00
|
|
|
struct { /* Equivalent to using LIST_HEAD. */
|
|
|
|
struct inode_t *lh_first;
|
|
|
|
} inode_list; /* Global inode pointer for adv. locking. */
|
2005-03-22 20:00:31 +01:00
|
|
|
hook_chain hooks;
|
2004-01-14 16:45:37 +01:00
|
|
|
void close_ctty ();
|
2005-11-14 05:28:45 +01:00
|
|
|
int manage_console_count (const char *, int, bool = false) __attribute__ ((regparm (3)));
|
|
|
|
private:
|
|
|
|
int console_count;
|
2000-11-14 06:53:32 +01:00
|
|
|
};
|
|
|
|
|
2005-11-14 05:28:45 +01:00
|
|
|
|
2004-04-11 06:07:18 +02:00
|
|
|
#define _CYGHEAPSIZE_SLOP (128 * 1024)
|
2004-03-18 20:30:51 +01:00
|
|
|
#define CYGHEAPSIZE (sizeof (init_cygheap) + (20000 * sizeof (fhandler_union)) + _CYGHEAPSIZE_SLOP)
|
|
|
|
#define CYGHEAPSIZE_MIN (sizeof (init_cygheap) + (10000 * sizeof (fhandler_union)))
|
2001-04-18 23:10:15 +02:00
|
|
|
|
2000-11-14 06:53:32 +01:00
|
|
|
extern init_cygheap *cygheap;
|
|
|
|
extern void *cygheap_max;
|
|
|
|
|
2001-10-16 01:39:33 +02:00
|
|
|
class cygheap_fdmanip
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
int fd;
|
|
|
|
fhandler_base **fh;
|
|
|
|
bool locked;
|
|
|
|
public:
|
2001-10-31 01:55:32 +01:00
|
|
|
cygheap_fdmanip (): fh (NULL) {}
|
2001-10-16 01:39:33 +02:00
|
|
|
virtual ~cygheap_fdmanip ()
|
|
|
|
{
|
|
|
|
if (locked)
|
2004-01-14 16:45:37 +01:00
|
|
|
cygheap->fdtab.unlock ();
|
2001-10-16 01:39:33 +02:00
|
|
|
}
|
|
|
|
void release ()
|
|
|
|
{
|
|
|
|
cygheap->fdtab.release (fd);
|
|
|
|
}
|
|
|
|
operator int &() {return fd;}
|
|
|
|
operator fhandler_base* &() {return *fh;}
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 02:37:18 +02:00
|
|
|
operator fhandler_socket* () const {return reinterpret_cast<fhandler_socket *> (*fh);}
|
2005-02-06 12:15:29 +01:00
|
|
|
operator fhandler_pipe* () const {return reinterpret_cast<fhandler_pipe *> (*fh);}
|
2001-10-16 01:39:33 +02:00
|
|
|
void operator = (fhandler_base *fh) {*this->fh = fh;}
|
|
|
|
fhandler_base *operator -> () const {return *fh;}
|
2001-11-02 00:48:34 +01:00
|
|
|
bool isopen () const
|
|
|
|
{
|
|
|
|
if (*fh)
|
|
|
|
return true;
|
|
|
|
set_errno (EBADF);
|
|
|
|
return false;
|
|
|
|
}
|
2001-10-16 01:39:33 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class cygheap_fdnew : public cygheap_fdmanip
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
cygheap_fdnew (int seed_fd = -1, bool lockit = true)
|
|
|
|
{
|
|
|
|
if (lockit)
|
2004-01-14 16:45:37 +01:00
|
|
|
cygheap->fdtab.lock ();
|
2001-10-16 01:39:33 +02:00
|
|
|
if (seed_fd < 0)
|
|
|
|
fd = cygheap->fdtab.find_unused_handle ();
|
|
|
|
else
|
|
|
|
fd = cygheap->fdtab.find_unused_handle (seed_fd + 1);
|
|
|
|
if (fd >= 0)
|
|
|
|
{
|
|
|
|
locked = lockit;
|
|
|
|
fh = cygheap->fdtab + fd;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
set_errno (EMFILE);
|
|
|
|
if (lockit)
|
2004-01-14 16:45:37 +01:00
|
|
|
cygheap->fdtab.unlock ();
|
2001-10-16 01:39:33 +02:00
|
|
|
locked = false;
|
|
|
|
}
|
|
|
|
}
|
2001-11-21 07:47:57 +01:00
|
|
|
void operator = (fhandler_base *fh) {*this->fh = fh;}
|
2001-10-16 01:39:33 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class cygheap_fdget : public cygheap_fdmanip
|
|
|
|
{
|
|
|
|
public:
|
2001-10-16 05:31:50 +02:00
|
|
|
cygheap_fdget (int fd, bool lockit = false, bool do_set_errno = true)
|
2001-10-16 01:39:33 +02:00
|
|
|
{
|
|
|
|
if (lockit)
|
2004-01-14 16:45:37 +01:00
|
|
|
cygheap->fdtab.lock ();
|
2001-10-16 01:39:33 +02:00
|
|
|
if (fd >= 0 && fd < (int) cygheap->fdtab.size
|
|
|
|
&& *(fh = cygheap->fdtab + fd) != NULL)
|
|
|
|
{
|
|
|
|
this->fd = fd;
|
|
|
|
locked = lockit;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this->fd = -1;
|
2001-10-16 05:31:50 +02:00
|
|
|
if (do_set_errno)
|
2001-10-16 16:43:36 +02:00
|
|
|
set_errno (EBADF);
|
2001-10-16 01:39:33 +02:00
|
|
|
if (lockit)
|
2004-01-14 16:45:37 +01:00
|
|
|
cygheap->fdtab.unlock ();
|
2001-10-16 01:39:33 +02:00
|
|
|
locked = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2005-01-31 11:28:55 +01:00
|
|
|
class cygheap_fdenum : public cygheap_fdmanip
|
|
|
|
{
|
|
|
|
public:
|
2005-10-24 17:09:07 +02:00
|
|
|
cygheap_fdenum (bool lockit = false)
|
2005-01-31 11:28:55 +01:00
|
|
|
{
|
2005-10-24 01:47:45 +02:00
|
|
|
locked = lockit;
|
2005-01-31 11:28:55 +01:00
|
|
|
if (lockit)
|
|
|
|
cygheap->fdtab.lock ();
|
2005-10-24 17:09:07 +02:00
|
|
|
fd = -1;
|
2005-01-31 11:28:55 +01:00
|
|
|
}
|
|
|
|
int next ()
|
|
|
|
{
|
|
|
|
while (++fd < (int) cygheap->fdtab.size)
|
|
|
|
if (*(fh = cygheap->fdtab + fd) != NULL)
|
2005-05-02 05:50:11 +02:00
|
|
|
return fd;
|
2005-01-31 11:28:55 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
void rewind ()
|
|
|
|
{
|
2005-10-24 17:09:07 +02:00
|
|
|
fd = -1;
|
2005-01-31 11:28:55 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2001-07-17 05:41:52 +02:00
|
|
|
class child_info;
|
2002-06-15 23:59:32 +02:00
|
|
|
void __stdcall cygheap_fixup_in_child (bool);
|
2000-09-03 06:16:35 +02:00
|
|
|
extern "C" {
|
2000-10-17 01:55:58 +02:00
|
|
|
void __stdcall cfree (void *) __attribute__ ((regparm(1)));
|
|
|
|
void *__stdcall cmalloc (cygheap_types, DWORD) __attribute__ ((regparm(2)));
|
|
|
|
void *__stdcall crealloc (void *, DWORD) __attribute__ ((regparm(2)));
|
|
|
|
void *__stdcall ccalloc (cygheap_types, DWORD, DWORD) __attribute__ ((regparm(3)));
|
2007-11-26 22:30:49 +01:00
|
|
|
void *__stdcall cmalloc_abort (cygheap_types, DWORD) __attribute__ ((regparm(2)));
|
|
|
|
void *__stdcall crealloc_abort (void *, DWORD) __attribute__ ((regparm(2)));
|
|
|
|
void *__stdcall ccalloc_abort (cygheap_types, DWORD, DWORD) __attribute__ ((regparm(3)));
|
2008-02-14 17:47:11 +01:00
|
|
|
PWCHAR __stdcall cwcsdup (const PWCHAR) __attribute__ ((regparm(1)));
|
|
|
|
PWCHAR __stdcall cwcsdup1 (const PWCHAR) __attribute__ ((regparm(1)));
|
2000-10-17 01:55:58 +02:00
|
|
|
char *__stdcall cstrdup (const char *) __attribute__ ((regparm(1)));
|
|
|
|
char *__stdcall cstrdup1 (const char *) __attribute__ ((regparm(1)));
|
2002-06-27 22:44:27 +02:00
|
|
|
void __stdcall cfree_and_set (char *&, char * = NULL) __attribute__ ((regparm(2)));
|
2000-10-02 04:26:04 +02:00
|
|
|
void __stdcall cygheap_init ();
|
2005-06-01 05:46:56 +02:00
|
|
|
extern char _cygheap_start[] __attribute__((section(".idata")));
|
2004-04-11 19:36:05 +02:00
|
|
|
}
|