1 /* cygheap.h: Cygwin heap manager.
3 Copyright 2000 Cygnus Solutions.
5 This file is part of Cygwin.
7 This software is a copyrighted work licensed under the terms of the
8 Cygwin license. Please consult the file "CYGWIN_LICENSE" for
28 #define incygheap(s) (cygheap && ((char *) (s) >= (char *) cygheap) && ((char *) (s) <= ((char *) cygheap_max)))
37 struct _cmalloc_entry *prev;
41 struct cygheap_root_mount_info
43 char posix_path[MAX_PATH];
44 unsigned posix_pathlen;
45 char native_path[MAX_PATH];
46 unsigned native_pathlen;
49 /* CGF: FIXME This doesn't belong here */
51 int path_prefix_p (const char *path1, const char *path2, int len1) __attribute__ ((regparm (3)));
54 /* Root directory information.
55 This is used after a chroot is called. */
56 struct cygheap_root_mount_info *m;
59 bool posix_ok (const char *path)
63 return path_prefix_p (m->posix_path, path, m->posix_pathlen);
65 bool ischroot_native (const char *path)
69 return strncasematch (m->native_path, path, m->native_pathlen)
70 && (path[m->native_pathlen] == '\\' || !path[m->native_pathlen]);
72 const char *unchroot (const char *path)
76 const char *p = path + m->posix_pathlen;
81 bool exists () {return !!m;}
82 void set (const char *posix, const char *native);
83 size_t posix_length () const { return m->posix_pathlen; }
84 const char *posix_path () const { return m->posix_path; }
85 size_t native_length () const { return m->native_pathlen; }
86 const char *native_path () const { return m->native_path; }
91 /* Extendend user information.
92 The information is derived from the internal_getlogin call
93 when on a NT system. */
94 char *pname; /* user's name */
95 char *plogsrv; /* Logon server, may be FQDN */
96 char *pdomain; /* Logon domain of the user */
97 PSID psid; /* buffer for user's SID */
99 uid_t orig_uid; /* Remains intact even after impersonation */
100 uid_t orig_gid; /* Ditto */
101 uid_t real_uid; /* Remains intact on seteuid, replaced by setuid */
102 gid_t real_gid; /* Ditto */
104 /* token is needed if set(e)uid should be called. It can be set by a call
105 to `set_impersonation_token()'. */
109 cygheap_user () : pname (NULL), plogsrv (NULL), pdomain (NULL),
110 psid (NULL), token (INVALID_HANDLE_VALUE) {}
113 void set_name (const char *new_name);
114 const char *name () const { return pname; }
116 void set_logsrv (const char *new_logsrv);
117 const char *logsrv () const { return plogsrv; }
119 void set_domain (const char *new_domain);
120 const char *domain () const { return pdomain; }
122 BOOL set_sid (PSID new_sid);
123 PSID sid () const { return psid; }
125 void operator =(cygheap_user &user)
127 set_name (user.name ());
128 set_logsrv (user.logsrv ());
129 set_domain (user.domain ());
130 set_sid (user.sid ());
134 /* cwd cache stuff. */
144 char *get (char *buf, int need_posix = 1, int with_chroot = 0, unsigned ulen = MAX_PATH);
147 void fixup_after_exec (char *win32, char *posix, DWORD hash);
149 void set (const char *win32_cwd, const char *posix_cwd = NULL);
154 _cmalloc_entry *chain;
168 #define CYGHEAPSIZE (sizeof (init_cygheap) + (4000 * sizeof (fhandler_union)) + (2 * 65536))
170 extern init_cygheap *cygheap;
171 extern void *cygheap_max;
174 void __stdcall cygheap_setup_for_child (child_info *ci) __attribute__ ((regparm(1)));
175 void __stdcall cygheap_setup_for_child_cleanup (child_info *ci) __attribute__ ((regparm(1)));
176 void __stdcall cygheap_fixup_in_child (child_info *, bool);
178 void __stdcall cfree (void *) __attribute__ ((regparm(1)));
179 void *__stdcall cmalloc (cygheap_types, DWORD) __attribute__ ((regparm(2)));
180 void *__stdcall crealloc (void *, DWORD) __attribute__ ((regparm(2)));
181 void *__stdcall ccalloc (cygheap_types, DWORD, DWORD) __attribute__ ((regparm(3)));
182 char *__stdcall cstrdup (const char *) __attribute__ ((regparm(1)));
183 char *__stdcall cstrdup1 (const char *) __attribute__ ((regparm(1)));
184 void __stdcall cygheap_init ();