OSDN Git Service

6a8e56290260226b1a03d5f0edbda4db5afc8dd4
[pf3gnuchains/pf3gnuchains4x.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_1_START,
20   HEAP_1_STR,
21   HEAP_1_ARGV,
22   HEAP_1_BUF,
23   HEAP_1_EXEC,
24   HEAP_1_MAX = 100
25 };
26
27 #define incygheap(s) (cygheap && ((char *) (s) >= (char *) cygheap) && ((char *) (s) <= ((char *) cygheap_max)))
28
29 struct _cmalloc_entry
30 {
31   union
32   {
33     DWORD b;
34     char *ptr;
35   };
36   struct _cmalloc_entry *prev;
37   char data[0];
38 };
39
40 class cygheap_root
41 {
42   /* Root directory information.
43      This is used after a chroot is called. */
44   size_t rootlen;
45   char *root;
46 public:
47   cygheap_root (cygheap_root &nroot);
48   ~cygheap_root ();
49   char *operator =(const char *new_root);
50   size_t length () const { return rootlen; }
51   const char *path () const { return root; }
52 };
53
54 class cygheap_user
55 {
56   /* Extendend user information.
57      The information is derived from the internal_getlogin call
58      when on a NT system. */
59   char  *pname;         /* user's name */
60   char  *plogsrv;       /* Logon server, may be FQDN */
61   char  *pdomain;       /* Logon domain of the user */
62   PSID   psid;          /* buffer for user's SID */
63 public:
64   uid_t orig_uid;      /* Remains intact even after impersonation */
65   uid_t orig_gid;      /* Ditto */
66   uid_t real_uid;      /* Remains intact on seteuid, replaced by setuid */
67   gid_t real_gid;      /* Ditto */
68
69   /* token is needed if set(e)uid should be called. It can be set by a call
70      to `set_impersonation_token()'. */
71   HANDLE token;
72   BOOL   impersonated;
73
74   cygheap_user () : pname (NULL), plogsrv (NULL), pdomain (NULL), psid (NULL) {}
75   ~cygheap_user ();
76
77   void set_name (const char *new_name);
78   const char *name () const { return pname; }
79
80   void set_logsrv (const char *new_logsrv);
81   const char *logsrv () const { return plogsrv; }
82
83   void set_domain (const char *new_domain);
84   const char *domain () const { return pdomain; }
85
86   BOOL set_sid (PSID new_sid);
87   PSID sid () const { return psid; }
88
89   void operator =(cygheap_user &user)
90   {
91     set_name (user.name ());
92     set_logsrv (user.logsrv ());
93     set_domain (user.domain ());
94     set_sid (user.sid ());
95   }
96 };
97
98 /* cwd cache stuff.  */
99
100 class muto;
101
102 struct cwdstuff
103 {
104   char *posix;
105   char *win32;
106   DWORD hash;
107   muto *lock;
108   char *get (char *buf, int need_posix = 1, int with_chroot = 0, unsigned ulen = MAX_PATH);
109   DWORD get_hash ();
110   void init ();
111   void fixup_after_exec (char *win32, char *posix, DWORD hash);
112   bool get_initial ();
113   void set (const char *win32_cwd, const char *posix_cwd = NULL);
114 };
115
116 struct init_cygheap
117 {
118   _cmalloc_entry *chain;
119   cygheap_root root;
120   cygheap_user user;
121   mode_t umask;
122   HANDLE shared_h;
123   HANDLE console_h;
124   cwdstuff cwd;
125   dtable fdtab;
126 };
127
128 #define CYGHEAPSIZE (sizeof (init_cygheap) + (4000 * sizeof (fhandler_union)) + (2 * 65536))
129
130 extern init_cygheap *cygheap;
131 extern void *cygheap_max;
132
133 extern "C" {
134 void __stdcall cfree (void *) __attribute__ ((regparm(1)));
135 void __stdcall cygheap_fixup_in_child (HANDLE, bool);
136 void *__stdcall cmalloc (cygheap_types, DWORD) __attribute__ ((regparm(2)));
137 void *__stdcall crealloc (void *, DWORD) __attribute__ ((regparm(2)));
138 void *__stdcall ccalloc (cygheap_types, DWORD, DWORD) __attribute__ ((regparm(3)));
139 char *__stdcall cstrdup (const char *) __attribute__ ((regparm(1)));
140 char *__stdcall cstrdup1 (const char *) __attribute__ ((regparm(1)));
141 void __stdcall cygheap_init ();
142 }