2000-09-02 21:16:35 -07:00
|
|
|
/* cygheap.h: Cygwin heap manager.
|
|
|
|
|
2010-04-20 03:44:52 -07:00
|
|
|
Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
|
2011-04-18 04:26:37 -07:00
|
|
|
2010, 2011 Red Hat, Inc.
|
2000-09-02 21:16:35 -07: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 12:45:56 -08:00
|
|
|
#include "hires.h"
|
2009-08-01 12:52:46 -07:00
|
|
|
#include "cygheap_malloc.h"
|
2000-09-02 21:16:35 -07:00
|
|
|
|
2000-10-01 19:26:04 -07:00
|
|
|
#define incygheap(s) (cygheap && ((char *) (s) >= (char *) cygheap) && ((char *) (s) <= ((char *) cygheap_max)))
|
2000-09-02 21:16:35 -07:00
|
|
|
|
2000-11-13 21:53:32 -08:00
|
|
|
struct _cmalloc_entry
|
|
|
|
{
|
|
|
|
union
|
|
|
|
{
|
|
|
|
DWORD b;
|
|
|
|
char *ptr;
|
|
|
|
};
|
|
|
|
struct _cmalloc_entry *prev;
|
|
|
|
char data[0];
|
|
|
|
};
|
|
|
|
|
2001-06-02 19:31:16 -07:00
|
|
|
struct cygheap_root_mount_info
|
|
|
|
{
|
2003-11-14 15:40:06 -08:00
|
|
|
char posix_path[CYG_MAX_PATH];
|
2001-06-02 19:31:16 -07:00
|
|
|
unsigned posix_pathlen;
|
2003-11-14 15:40:06 -08:00
|
|
|
char native_path[CYG_MAX_PATH];
|
2001-06-02 19:31:16 -07:00
|
|
|
unsigned native_pathlen;
|
2008-07-16 13:20:45 -07:00
|
|
|
bool caseinsensitive;
|
2001-06-02 19:31:16 -07:00
|
|
|
};
|
|
|
|
|
2001-06-03 18:28:09 -07:00
|
|
|
/* CGF: FIXME This doesn't belong here */
|
|
|
|
|
2000-11-14 16:13:09 -08:00
|
|
|
class cygheap_root
|
|
|
|
{
|
|
|
|
/* Root directory information.
|
|
|
|
This is used after a chroot is called. */
|
2001-06-02 19:31:16 -07:00
|
|
|
struct cygheap_root_mount_info *m;
|
|
|
|
|
2000-11-14 16:13:09 -08:00
|
|
|
public:
|
2001-06-02 19:31:16 -07:00
|
|
|
bool posix_ok (const char *path)
|
|
|
|
{
|
|
|
|
if (!m)
|
|
|
|
return 1;
|
2008-07-16 13:20:45 -07:00
|
|
|
return path_prefix_p (m->posix_path, path, m->posix_pathlen,
|
|
|
|
m->caseinsensitive);
|
2001-06-02 19:31:16 -07:00
|
|
|
}
|
|
|
|
bool ischroot_native (const char *path)
|
|
|
|
{
|
|
|
|
if (!m)
|
|
|
|
return 1;
|
|
|
|
return strncasematch (m->native_path, path, m->native_pathlen)
|
2001-09-07 14:32:07 -07:00
|
|
|
&& (path[m->native_pathlen] == '\\' || !path[m->native_pathlen]);
|
2001-06-02 19:31:16 -07: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 13:20:45 -07:00
|
|
|
void set (const char *, const char *, bool);
|
2001-06-02 19:31:16 -07: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-14 16:13:09 -08:00
|
|
|
};
|
|
|
|
|
2002-06-11 22:13:54 -07:00
|
|
|
enum homebodies
|
|
|
|
{
|
|
|
|
CH_HOMEDRIVE,
|
|
|
|
CH_HOMEPATH,
|
|
|
|
CH_HOME
|
|
|
|
};
|
|
|
|
|
2001-01-17 06:57:09 -08:00
|
|
|
class cygheap_user
|
|
|
|
{
|
2000-11-14 16:13:09 -08:00
|
|
|
/* Extendend user information.
|
|
|
|
The information is derived from the internal_getlogin call
|
|
|
|
when on a NT system. */
|
2009-06-30 14:18:44 -07:00
|
|
|
char *pname; /* user's name */
|
2000-11-15 13:04:02 -08:00
|
|
|
char *plogsrv; /* Logon server, may be FQDN */
|
|
|
|
char *pdomain; /* Logon domain of the user */
|
2002-06-11 22:13:54 -07:00
|
|
|
char *homedrive; /* User's home drive */
|
|
|
|
char *homepath; /* User's home path */
|
2004-10-07 14:28:57 -07:00
|
|
|
char *psystemroot; /* Value of SYSTEMROOT */
|
2002-06-28 19:36:08 -07:00
|
|
|
char *pwinname; /* User's name as far as Windows knows it */
|
2002-06-27 13:44:27 -07:00
|
|
|
char *puserprof; /* User profile */
|
2003-09-26 18:56:36 -07:00
|
|
|
cygsid effec_cygsid; /* buffer for user's SID */
|
|
|
|
cygsid saved_cygsid; /* Remains intact even after impersonation */
|
2000-11-14 16:13:09 -08:00
|
|
|
public:
|
2003-09-16 02:24:52 -07:00
|
|
|
__uid32_t saved_uid; /* Remains intact even after impersonation */
|
|
|
|
__gid32_t saved_gid; /* Ditto */
|
2002-05-29 08:04:29 -07: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 07:10:55 -07:00
|
|
|
__gid32_t real_gid; /* Ditto */
|
2002-07-29 05:51:52 -07:00
|
|
|
user_groups groups; /* Primary and supp SIDs */
|
2000-11-14 16:13:09 -08:00
|
|
|
|
2000-11-15 13:04:02 -08: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 06:07:36 -07:00
|
|
|
HANDLE external_token;
|
|
|
|
HANDLE internal_token;
|
2005-04-03 06:06:43 -07:00
|
|
|
HANDLE curr_primary_token;
|
2007-07-16 13:01:15 -07:00
|
|
|
HANDLE curr_imp_token;
|
2009-10-13 03:23:31 -07:00
|
|
|
bool ext_token_is_restricted; /* external_token is restricted token */
|
|
|
|
bool curr_token_is_restricted; /* curr_primary_token is restricted token */
|
|
|
|
bool setuid_to_restricted; /* switch to restricted token by setuid () */
|
2000-11-15 13:04:02 -08:00
|
|
|
|
2002-06-27 13:44:27 -07: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 14:37:12 -08:00
|
|
|
I've removed the constructor entirely. Please reinstate this if this
|
2002-06-27 13:44:27 -07:00
|
|
|
situation ever changes.
|
2001-06-04 07:29:54 -07:00
|
|
|
cygheap_user () : pname (NULL), plogsrv (NULL), pdomain (NULL),
|
2003-09-16 02:24:52 -07:00
|
|
|
homedrive (NULL), homepath (NULL),
|
2002-06-27 13:44:27 -07:00
|
|
|
token (INVALID_HANDLE_VALUE) {}
|
|
|
|
*/
|
|
|
|
|
2000-11-14 16:13:09 -08:00
|
|
|
~cygheap_user ();
|
|
|
|
|
2003-09-10 14:01:40 -07:00
|
|
|
void init ();
|
2000-11-14 16:13:09 -08:00
|
|
|
void set_name (const char *new_name);
|
|
|
|
const char *name () const { return pname; }
|
|
|
|
|
2002-06-28 19:36:08 -07: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 14:28:57 -07:00
|
|
|
const char *env_systemroot (const char *, size_t);
|
2000-11-14 16:13:09 -08:00
|
|
|
|
2002-06-28 19:36:08 -07:00
|
|
|
const char *logsrv ()
|
|
|
|
{
|
2002-06-29 15:05:30 -07:00
|
|
|
const char *p = env_logsrv ("LOGONSERVER=", sizeof ("LOGONSERVER=") - 1);
|
|
|
|
return (p == almost_null) ? NULL : p;
|
2002-06-28 19:36:08 -07:00
|
|
|
}
|
|
|
|
const char *winname ()
|
|
|
|
{
|
2002-06-29 15:05:30 -07:00
|
|
|
const char *p = env_name ("USERNAME=", sizeof ("USERNAME=") - 1);
|
|
|
|
return (p == almost_null) ? NULL : p;
|
2002-06-28 19:36:08 -07:00
|
|
|
}
|
|
|
|
const char *domain ()
|
|
|
|
{
|
2002-06-29 15:05:30 -07:00
|
|
|
const char *p = env_domain ("USERDOMAIN=", sizeof ("USERDOMAIN=") - 1);
|
|
|
|
return (p == almost_null) ? NULL : p;
|
2002-06-28 19:36:08 -07:00
|
|
|
}
|
2003-09-26 18:56:36 -07: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-11 22:13:54 -07:00
|
|
|
const char *ontherange (homebodies what, struct passwd * = NULL);
|
2004-10-27 18:46:01 -07:00
|
|
|
#define NO_IMPERSONATION NULL
|
2007-07-16 13:01:15 -07:00
|
|
|
bool issetuid () const { return curr_imp_token != NO_IMPERSONATION; }
|
2005-04-03 06:06:43 -07:00
|
|
|
HANDLE primary_token () { return curr_primary_token; }
|
2007-07-16 13:01:15 -07:00
|
|
|
HANDLE imp_token () { return curr_imp_token; }
|
2003-06-30 06:07:36 -07:00
|
|
|
void deimpersonate ()
|
|
|
|
{
|
2007-01-24 02:50:47 -08:00
|
|
|
RevertToSelf ();
|
2003-06-30 06:07:36 -07:00
|
|
|
}
|
2005-04-03 06:06:43 -07:00
|
|
|
bool reimpersonate ()
|
2003-06-30 06:07:36 -07:00
|
|
|
{
|
2006-12-12 08:27:32 -08:00
|
|
|
if (issetuid ())
|
2007-07-16 13:01:15 -07:00
|
|
|
return ImpersonateLoggedOnUser (primary_token ());
|
2006-12-12 08:27:32 -08:00
|
|
|
return true;
|
2003-06-30 06:07:36 -07:00
|
|
|
}
|
2003-07-14 10:04:21 -07:00
|
|
|
bool has_impersonation_tokens ()
|
2004-10-27 18:46:01 -07:00
|
|
|
{ return external_token != NO_IMPERSONATION
|
|
|
|
|| internal_token != NO_IMPERSONATION
|
2005-04-03 06:06:43 -07:00
|
|
|
|| curr_primary_token != NO_IMPERSONATION; }
|
2003-06-30 06:07:36 -07:00
|
|
|
void close_impersonation_tokens ()
|
|
|
|
{
|
2007-07-16 13:01:15 -07:00
|
|
|
if (curr_imp_token != NO_IMPERSONATION)
|
|
|
|
CloseHandle (curr_imp_token);
|
2005-04-03 06:06:43 -07:00
|
|
|
if (curr_primary_token != NO_IMPERSONATION
|
2011-06-05 22:02:13 -07:00
|
|
|
&& curr_primary_token != external_token
|
2005-04-03 06:06:43 -07:00
|
|
|
&& curr_primary_token != internal_token)
|
|
|
|
CloseHandle (curr_primary_token);
|
2004-10-27 18:46:01 -07:00
|
|
|
if (external_token != NO_IMPERSONATION)
|
2005-04-03 06:06:43 -07:00
|
|
|
CloseHandle (external_token);
|
2004-10-27 18:46:01 -07:00
|
|
|
if (internal_token != NO_IMPERSONATION)
|
2005-04-03 06:06:43 -07:00
|
|
|
CloseHandle (internal_token);
|
2002-06-16 16:34:43 -07:00
|
|
|
}
|
2008-02-14 08:47:11 -08:00
|
|
|
PWCHAR get_windows_id (PWCHAR buf)
|
|
|
|
{
|
|
|
|
return effec_cygsid.string (buf);
|
|
|
|
}
|
|
|
|
char *get_windows_id (char *buf)
|
2004-11-20 11:09:19 -08:00
|
|
|
{
|
2007-02-22 02:54:47 -08:00
|
|
|
return effec_cygsid.string (buf);
|
2004-11-20 11:09:19 -08:00
|
|
|
}
|
2005-02-13 10:17:29 -08:00
|
|
|
|
2006-07-17 12:30:30 -07:00
|
|
|
const char *test_uid (char *&, const char *, size_t)
|
2002-06-28 19:36:08 -07:00
|
|
|
__attribute__ ((regparm (3)));
|
2000-11-14 16:13:09 -08:00
|
|
|
};
|
2000-11-13 21:53:32 -08:00
|
|
|
|
2001-04-16 20:52:08 -07:00
|
|
|
/* cwd cache stuff. */
|
|
|
|
|
|
|
|
class muto;
|
|
|
|
|
2009-05-13 08:00:06 -07:00
|
|
|
class cwdstuff
|
2001-04-16 20:52:08 -07:00
|
|
|
{
|
2009-05-13 08:00:06 -07:00
|
|
|
private:
|
2001-04-16 20:52:08 -07:00
|
|
|
char *posix;
|
2008-01-31 06:18:49 -08:00
|
|
|
HANDLE dir;
|
2010-08-13 04:51:54 -07:00
|
|
|
DWORD drive_length;
|
|
|
|
int error; /* This contains an errno number which corresponds
|
|
|
|
to the problem with this path when trying to start
|
|
|
|
a native Win32 application. See cwdstuff::set for
|
|
|
|
how it gets set. See spawn_guts for how it's
|
|
|
|
evaluated. */
|
2010-10-09 03:54:13 -07:00
|
|
|
void override_win32_cwd (bool, ULONG);
|
|
|
|
|
2009-05-13 08:00:06 -07:00
|
|
|
public:
|
|
|
|
UNICODE_STRING win32;
|
2005-04-04 21:31:00 -07:00
|
|
|
static muto cwd_lock;
|
2009-09-21 12:29:16 -07:00
|
|
|
const char *get_posix () const { return posix; };
|
|
|
|
void reset_posix (wchar_t *);
|
2008-03-07 03:24:51 -08:00
|
|
|
char *get (char *, int = 1, int = 0, unsigned = NT_MAX_PATH);
|
2008-01-31 06:18:49 -08:00
|
|
|
HANDLE get_handle () { return dir; }
|
2005-02-13 10:17:29 -08:00
|
|
|
DWORD get_drive (char * dst)
|
2004-09-07 16:26:28 -07:00
|
|
|
{
|
2007-10-23 09:26:28 -07:00
|
|
|
cwd_lock.acquire ();
|
2008-02-14 08:47:11 -08:00
|
|
|
DWORD ret = sys_wcstombs (dst, NT_MAX_PATH, win32.Buffer, drive_length);
|
2005-04-04 21:31:00 -07:00
|
|
|
cwd_lock.release ();
|
2007-10-23 09:26:28 -07:00
|
|
|
return ret;
|
2004-09-07 16:26:28 -07:00
|
|
|
}
|
2010-08-13 04:51:54 -07:00
|
|
|
int get_error () const { return error; }
|
|
|
|
const char *get_error_desc () const;
|
2001-04-16 20:52:08 -07:00
|
|
|
void init ();
|
2010-08-13 04:51:54 -07:00
|
|
|
int set (path_conv *, const char *);
|
2001-04-16 20:52:08 -07:00
|
|
|
};
|
|
|
|
|
2002-07-13 13:00:27 -07:00
|
|
|
#ifdef DEBUGGING
|
|
|
|
struct cygheap_debug
|
|
|
|
{
|
|
|
|
handle_list starth;
|
|
|
|
handle_list freeh[500];
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2009-05-14 12:49:37 -07:00
|
|
|
struct cygheap_locale
|
|
|
|
{
|
|
|
|
mbtowc_p mbtowc;
|
|
|
|
wctomb_p wctomb;
|
|
|
|
char charset[ENCODING_LEN + 1];
|
|
|
|
};
|
|
|
|
|
2002-10-22 09:18:55 -07:00
|
|
|
struct user_heap_info
|
|
|
|
{
|
|
|
|
void *base;
|
|
|
|
void *ptr;
|
|
|
|
void *top;
|
2003-08-22 12:25:56 -07:00
|
|
|
void *max;
|
2002-10-22 09:18:55 -07:00
|
|
|
unsigned chunk;
|
2006-10-31 10:41:16 -08:00
|
|
|
unsigned slop;
|
2002-10-22 09:18:55 -07:00
|
|
|
};
|
|
|
|
|
2005-03-22 11:00:31 -08:00
|
|
|
struct hook_chain
|
|
|
|
{
|
|
|
|
void **loc;
|
|
|
|
const void *func;
|
|
|
|
struct hook_chain *next;
|
|
|
|
};
|
|
|
|
|
2009-06-07 20:53:40 -07:00
|
|
|
struct mini_cygheap
|
|
|
|
{
|
|
|
|
cygheap_locale locale;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct init_cygheap: public mini_cygheap
|
2000-11-13 21:53:32 -08:00
|
|
|
{
|
|
|
|
_cmalloc_entry *chain;
|
2001-09-05 20:39:18 -07:00
|
|
|
char *buckets[32];
|
2000-11-14 16:13:09 -08:00
|
|
|
cygheap_root root;
|
|
|
|
cygheap_user user;
|
2002-10-22 09:18:55 -07:00
|
|
|
user_heap_info user_heap;
|
2000-11-13 21:53:32 -08:00
|
|
|
mode_t umask;
|
2010-04-20 03:44:52 -07:00
|
|
|
unsigned long rlim_core;
|
2001-01-27 21:51:15 -08:00
|
|
|
HANDLE console_h;
|
2001-04-16 20:52:08 -07:00
|
|
|
cwdstuff cwd;
|
2001-04-18 14:10:15 -07:00
|
|
|
dtable fdtab;
|
2002-07-13 13:00:27 -07:00
|
|
|
#ifdef DEBUGGING
|
|
|
|
cygheap_debug debug;
|
|
|
|
#endif
|
2003-08-31 19:05:32 -07:00
|
|
|
struct sigaction *sigs;
|
2003-12-07 14:37:12 -08:00
|
|
|
|
2011-04-17 12:56:25 -07:00
|
|
|
fhandler_termios *ctty; /* Current tty */
|
2004-02-11 19:01:58 -08:00
|
|
|
struct _cygtls **threadlist;
|
2004-01-14 07:45:37 -08:00
|
|
|
size_t sthreads;
|
2004-09-11 20:47:57 -07:00
|
|
|
pid_t pid; /* my pid */
|
2004-11-25 20:15:10 -08:00
|
|
|
HANDLE pid_handle; /* handle for my pid */
|
2008-03-24 07:48:58 -07:00
|
|
|
struct { /* Equivalent to using LIST_HEAD. */
|
|
|
|
struct inode_t *lh_first;
|
|
|
|
} inode_list; /* Global inode pointer for adv. locking. */
|
2005-03-22 11:00:31 -08:00
|
|
|
hook_chain hooks;
|
2004-01-14 07:45:37 -08:00
|
|
|
void close_ctty ();
|
2005-11-13 20:28:45 -08:00
|
|
|
int manage_console_count (const char *, int, bool = false) __attribute__ ((regparm (3)));
|
|
|
|
private:
|
|
|
|
int console_count;
|
2000-11-13 21:53:32 -08:00
|
|
|
};
|
|
|
|
|
2005-11-13 20:28:45 -08:00
|
|
|
|
2004-04-10 21:07:18 -07:00
|
|
|
#define _CYGHEAPSIZE_SLOP (128 * 1024)
|
2004-03-18 11:30:51 -08: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 14:10:15 -07:00
|
|
|
|
2000-11-13 21:53:32 -08:00
|
|
|
extern init_cygheap *cygheap;
|
|
|
|
extern void *cygheap_max;
|
|
|
|
|
2001-10-15 16:39:33 -07:00
|
|
|
class cygheap_fdmanip
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
int fd;
|
|
|
|
bool locked;
|
|
|
|
public:
|
2010-08-09 09:53:35 -07:00
|
|
|
cygheap_fdmanip (): fd (-1), locked (false) {}
|
2001-10-15 16:39:33 -07:00
|
|
|
virtual ~cygheap_fdmanip ()
|
|
|
|
{
|
|
|
|
if (locked)
|
2004-01-14 07:45:37 -08:00
|
|
|
cygheap->fdtab.unlock ();
|
2001-10-15 16:39:33 -07:00
|
|
|
}
|
|
|
|
void release ()
|
|
|
|
{
|
|
|
|
cygheap->fdtab.release (fd);
|
|
|
|
}
|
|
|
|
operator int &() {return fd;}
|
2010-08-09 09:53:35 -07:00
|
|
|
operator fhandler_base* &() {return cygheap->fdtab[fd];}
|
|
|
|
operator fhandler_socket* () const {return reinterpret_cast<fhandler_socket *> (cygheap->fdtab[fd]);}
|
|
|
|
operator fhandler_pipe* () const {return reinterpret_cast<fhandler_pipe *> (cygheap->fdtab[fd]);}
|
|
|
|
void operator = (fhandler_base *fh) {cygheap->fdtab[fd] = fh;}
|
|
|
|
fhandler_base *operator -> () const {return cygheap->fdtab[fd];}
|
2001-11-01 15:48:34 -08:00
|
|
|
bool isopen () const
|
|
|
|
{
|
2010-08-09 09:53:35 -07:00
|
|
|
if (cygheap->fdtab[fd])
|
2001-11-01 15:48:34 -08:00
|
|
|
return true;
|
|
|
|
set_errno (EBADF);
|
|
|
|
return false;
|
|
|
|
}
|
2001-10-15 16:39:33 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
class cygheap_fdnew : public cygheap_fdmanip
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
cygheap_fdnew (int seed_fd = -1, bool lockit = true)
|
|
|
|
{
|
|
|
|
if (lockit)
|
2004-01-14 07:45:37 -08:00
|
|
|
cygheap->fdtab.lock ();
|
2001-10-15 16:39:33 -07:00
|
|
|
if (seed_fd < 0)
|
|
|
|
fd = cygheap->fdtab.find_unused_handle ();
|
|
|
|
else
|
|
|
|
fd = cygheap->fdtab.find_unused_handle (seed_fd + 1);
|
|
|
|
if (fd >= 0)
|
2010-08-09 09:53:35 -07:00
|
|
|
locked = lockit;
|
2001-10-15 16:39:33 -07:00
|
|
|
else
|
|
|
|
{
|
|
|
|
set_errno (EMFILE);
|
|
|
|
if (lockit)
|
2004-01-14 07:45:37 -08:00
|
|
|
cygheap->fdtab.unlock ();
|
2001-10-15 16:39:33 -07:00
|
|
|
locked = false;
|
|
|
|
}
|
|
|
|
}
|
2010-08-09 09:53:35 -07:00
|
|
|
void operator = (fhandler_base *fh) {cygheap->fdtab[fd] = fh;}
|
2001-10-15 16:39:33 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
class cygheap_fdget : public cygheap_fdmanip
|
|
|
|
{
|
|
|
|
public:
|
2001-10-15 20:31:50 -07:00
|
|
|
cygheap_fdget (int fd, bool lockit = false, bool do_set_errno = true)
|
2001-10-15 16:39:33 -07:00
|
|
|
{
|
|
|
|
if (lockit)
|
2004-01-14 07:45:37 -08:00
|
|
|
cygheap->fdtab.lock ();
|
2010-08-09 09:53:35 -07:00
|
|
|
if (fd >= 0 && fd < (int) cygheap->fdtab.size && cygheap->fdtab[fd] != NULL)
|
2001-10-15 16:39:33 -07:00
|
|
|
{
|
|
|
|
this->fd = fd;
|
|
|
|
locked = lockit;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this->fd = -1;
|
2001-10-15 20:31:50 -07:00
|
|
|
if (do_set_errno)
|
2001-10-16 07:43:36 -07:00
|
|
|
set_errno (EBADF);
|
2001-10-15 16:39:33 -07:00
|
|
|
if (lockit)
|
2004-01-14 07:45:37 -08:00
|
|
|
cygheap->fdtab.unlock ();
|
2001-10-15 16:39:33 -07:00
|
|
|
locked = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2005-01-31 02:28:55 -08:00
|
|
|
class cygheap_fdenum : public cygheap_fdmanip
|
|
|
|
{
|
|
|
|
public:
|
2005-10-24 08:09:07 -07:00
|
|
|
cygheap_fdenum (bool lockit = false)
|
2005-01-31 02:28:55 -08:00
|
|
|
{
|
2005-10-23 16:47:45 -07:00
|
|
|
locked = lockit;
|
2005-01-31 02:28:55 -08:00
|
|
|
if (lockit)
|
|
|
|
cygheap->fdtab.lock ();
|
2005-10-24 08:09:07 -07:00
|
|
|
fd = -1;
|
2005-01-31 02:28:55 -08:00
|
|
|
}
|
|
|
|
int next ()
|
|
|
|
{
|
|
|
|
while (++fd < (int) cygheap->fdtab.size)
|
2010-08-09 09:53:35 -07:00
|
|
|
if (cygheap->fdtab[fd] != NULL)
|
2005-05-01 20:50:11 -07:00
|
|
|
return fd;
|
2005-01-31 02:28:55 -08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
void rewind ()
|
|
|
|
{
|
2005-10-24 08:09:07 -07:00
|
|
|
fd = -1;
|
2005-01-31 02:28:55 -08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2002-06-15 14:59:32 -07:00
|
|
|
void __stdcall cygheap_fixup_in_child (bool);
|
2000-10-01 19:26:04 -07:00
|
|
|
void __stdcall cygheap_init ();
|
2005-05-31 20:46:56 -07:00
|
|
|
extern char _cygheap_start[] __attribute__((section(".idata")));
|