]> sourceware.org Git - newlib-cygwin.git/blob - winsup/cygwin/cygheap.h
* cygheap.cc (cygheap_root::cygheap_rot): Remove constructor.
[newlib-cygwin.git] / winsup / cygwin / cygheap.h
1 /* cygheap.h: Cygwin heap manager.
2
3 Copyright 2000 Cygnus Solutions.
4
5 This file is part of Cygwin.
6
7 This software is a copyrighted work licensed under the terms of the
8 Cygwin license. Please consult the file "CYGWIN_LICENSE" for
9 details. */
10
11 #undef cfree
12
13 enum cygheap_types
14 {
15 HEAP_FHANDLER,
16 HEAP_STR,
17 HEAP_ARGV,
18 HEAP_BUF,
19 HEAP_MOUNT,
20 HEAP_1_START,
21 HEAP_1_STR,
22 HEAP_1_ARGV,
23 HEAP_1_BUF,
24 HEAP_1_EXEC,
25 HEAP_1_MAX = 100
26 };
27
28 #define incygheap(s) (cygheap && ((char *) (s) >= (char *) cygheap) && ((char *) (s) <= ((char *) cygheap_max)))
29
30 struct _cmalloc_entry
31 {
32 union
33 {
34 DWORD b;
35 char *ptr;
36 };
37 struct _cmalloc_entry *prev;
38 char data[0];
39 };
40
41 struct cygheap_root_mount_info
42 {
43 char posix_path[MAX_PATH];
44 unsigned posix_pathlen;
45 char native_path[MAX_PATH];
46 unsigned native_pathlen;
47 };
48
49 class cygheap_root
50 {
51 /* Root directory information.
52 This is used after a chroot is called. */
53 struct cygheap_root_mount_info *m;
54
55 public:
56 bool posix_ok (const char *path)
57 {
58 extern int path_prefix_p (const char *, const char *, int);
59 if (!m)
60 return 1;
61 return path_prefix_p (m->posix_path, path, m->posix_pathlen);
62 }
63 bool ischroot_native (const char *path)
64 {
65 if (!m)
66 return 1;
67 return strncasematch (m->native_path, path, m->native_pathlen)
68 && (path[m->native_pathlen] == '\\' || !path[m->native_pathlen]);
69
70 }
71 const char *unchroot (const char *path)
72 {
73 if (!m)
74 return path;
75 const char *p = path + m->posix_pathlen;
76 if (!*p)
77 p = "/";
78 return p;
79 }
80 bool exists () {return !!m;}
81 void set (const char *posix, const char *native);
82 size_t posix_length () const { return m->posix_pathlen; }
83 const char *posix_path () const { return m->posix_path; }
84 size_t native_length () const { return m->native_pathlen; }
85 const char *native_path () const { return m->native_path; }
86 };
87
88 class cygheap_user
89 {
90 /* Extendend user information.
91 The information is derived from the internal_getlogin call
92 when on a NT system. */
93 char *pname; /* user's name */
94 char *plogsrv; /* Logon server, may be FQDN */
95 char *pdomain; /* Logon domain of the user */
96 PSID psid; /* buffer for user's SID */
97 public:
98 uid_t orig_uid; /* Remains intact even after impersonation */
99 uid_t orig_gid; /* Ditto */
100 uid_t real_uid; /* Remains intact on seteuid, replaced by setuid */
101 gid_t real_gid; /* Ditto */
102
103 /* token is needed if set(e)uid should be called. It can be set by a call
104 to `set_impersonation_token()'. */
105 HANDLE token;
106 BOOL impersonated;
107
108 cygheap_user () : pname (NULL), plogsrv (NULL), pdomain (NULL), psid (NULL) {}
109 ~cygheap_user ();
110
111 void set_name (const char *new_name);
112 const char *name () const { return pname; }
113
114 void set_logsrv (const char *new_logsrv);
115 const char *logsrv () const { return plogsrv; }
116
117 void set_domain (const char *new_domain);
118 const char *domain () const { return pdomain; }
119
120 BOOL set_sid (PSID new_sid);
121 PSID sid () const { return psid; }
122
123 void operator =(cygheap_user &user)
124 {
125 set_name (user.name ());
126 set_logsrv (user.logsrv ());
127 set_domain (user.domain ());
128 set_sid (user.sid ());
129 }
130 };
131
132 /* cwd cache stuff. */
133
134 class muto;
135
136 struct cwdstuff
137 {
138 char *posix;
139 char *win32;
140 DWORD hash;
141 muto *lock;
142 char *get (char *buf, int need_posix = 1, int with_chroot = 0, unsigned ulen = MAX_PATH);
143 DWORD get_hash ();
144 void init ();
145 void fixup_after_exec (char *win32, char *posix, DWORD hash);
146 bool get_initial ();
147 void set (const char *win32_cwd, const char *posix_cwd = NULL);
148 };
149
150 struct init_cygheap
151 {
152 _cmalloc_entry *chain;
153 cygheap_root root;
154 cygheap_user user;
155 mode_t umask;
156 HANDLE shared_h;
157 HANDLE console_h;
158 cwdstuff cwd;
159 dtable fdtab;
160 };
161
162 #define CYGHEAPSIZE (sizeof (init_cygheap) + (4000 * sizeof (fhandler_union)) + (2 * 65536))
163
164 extern init_cygheap *cygheap;
165 extern void *cygheap_max;
166
167 extern "C" {
168 void __stdcall cfree (void *) __attribute__ ((regparm(1)));
169 void __stdcall cygheap_fixup_in_child (HANDLE, bool);
170 void *__stdcall cmalloc (cygheap_types, DWORD) __attribute__ ((regparm(2)));
171 void *__stdcall crealloc (void *, DWORD) __attribute__ ((regparm(2)));
172 void *__stdcall ccalloc (cygheap_types, DWORD, DWORD) __attribute__ ((regparm(3)));
173 char *__stdcall cstrdup (const char *) __attribute__ ((regparm(1)));
174 char *__stdcall cstrdup1 (const char *) __attribute__ ((regparm(1)));
175 void __stdcall cygheap_init ();
176 }
This page took 0.043517 seconds and 6 git commands to generate.