2000-09-08 10:56:55 +08:00
|
|
|
/* shared_info.h: shared info for cygwin
|
2000-09-08 00:23:51 +08: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. */
|
|
|
|
|
2000-09-08 10:56:55 +08:00
|
|
|
#include "tty.h"
|
2003-09-10 10:12:26 +08:00
|
|
|
#include "security.h"
|
2008-04-19 04:13:37 +08:00
|
|
|
#include "mtinfo.h"
|
2008-07-25 02:25:52 +08:00
|
|
|
#include "limits.h"
|
2008-12-25 23:55:31 +08:00
|
|
|
#include "mount.h"
|
2017-03-22 03:17:42 +08:00
|
|
|
#include "loadavg.h"
|
2000-09-08 00:23:51 +08:00
|
|
|
|
2013-05-23 22:23:01 +08:00
|
|
|
#define CURR_USER_MAGIC 0xab1fcce8U
|
2011-06-09 03:27:48 +08:00
|
|
|
|
2003-09-25 10:29:05 +08:00
|
|
|
class user_info
|
|
|
|
{
|
2010-03-16 05:29:15 +08:00
|
|
|
void initialize ();
|
2003-09-25 10:29:05 +08:00
|
|
|
public:
|
2010-03-16 05:29:15 +08:00
|
|
|
LONG version;
|
2003-09-25 10:29:05 +08:00
|
|
|
DWORD cb;
|
2006-08-02 02:00:44 +08:00
|
|
|
bool warned_msdos;
|
2011-06-09 03:27:48 +08:00
|
|
|
bool warned_notty;
|
2013-05-23 22:23:01 +08:00
|
|
|
bool warned_nonativesyms;
|
2003-09-25 10:29:05 +08:00
|
|
|
mount_info mountinfo;
|
2010-03-16 05:29:15 +08:00
|
|
|
friend void dll_crt0_1 (void *);
|
|
|
|
static void create (bool);
|
2003-09-25 10:29:05 +08:00
|
|
|
};
|
2011-06-09 03:27:48 +08:00
|
|
|
|
2000-09-08 00:23:51 +08:00
|
|
|
/******** Shared Info ********/
|
|
|
|
/* Data accessible to all tasks */
|
|
|
|
|
2001-12-27 05:35:16 +08:00
|
|
|
|
2017-03-03 00:26:53 +08:00
|
|
|
#define CURR_SHARED_MAGIC 0x9f33cc5dU
|
2001-12-26 12:53:34 +08:00
|
|
|
|
2010-03-16 05:29:15 +08:00
|
|
|
#define USER_VERSION 1
|
2009-01-03 13:12:22 +08:00
|
|
|
|
2001-12-26 14:18:41 +08:00
|
|
|
/* NOTE: Do not make gratuitous changes to the names or organization of the
|
|
|
|
below class. The layout is checksummed to determine compatibility between
|
|
|
|
different cygwin versions. */
|
2000-09-08 00:23:51 +08:00
|
|
|
class shared_info
|
|
|
|
{
|
2010-03-16 05:29:15 +08:00
|
|
|
LONG version;
|
2001-12-27 05:35:16 +08:00
|
|
|
DWORD cb;
|
2001-05-25 11:13:14 +08:00
|
|
|
public:
|
2000-09-08 00:23:51 +08:00
|
|
|
tty_list tty;
|
2008-04-19 04:13:37 +08:00
|
|
|
LONG last_used_bindresvport;
|
2008-07-17 04:20:45 +08:00
|
|
|
DWORD obcaseinsensitive;
|
2008-04-19 04:13:37 +08:00
|
|
|
mtinfo mt;
|
2017-03-22 03:17:42 +08:00
|
|
|
loadavginfo loadavg;
|
Cygwin: processes: use dedicated Cygwin PID rather than Windows PID
Using the Windows PID as Cygwin PID has a few drawbacks:
- the PIDs on Windows get reused quickly. Some POSIX applications choke
on that, so we need extra code to avoid too quick PID reuse.
- The code to avoid PID reuse keeps parent process handles and
(depending on a build option) child processes open unnecessarily.
- After an execve, the process has a split personality: Its Windows PID
is a new PID, while its Cygwin PID is the PID of the execve caller
process. This requires to keep two procinfo shared sections open, the
second just to redirect process info requests to the first, correct
one.
This patch changes the way Cygwin PIDs are generated:
- Cygwin PIDs are generated independently of the Windows PID, in a way
expected by POSIX processes. The PIDs are created incrementally in
the range between 2 and 65535, round-robin.
- On startup of the first Cygwin process, choose a semi-random start PID
for the first process in the lower PID range to make the PIDs slightly
unpredictable. This may not be necessary but it seems kind of inviting
to know that the first Cygwin process always starts with PID 2.
- Every process not only creates the shared procinfo section, but also a
symlink in the NT namespace, symlinking the Windows PID to the Cygwin
PID. This drops the need for the extra procinfo section after execve.
- Don't keep other process handles around unnecessarily.
- Simplify the code creating/opening the shared procinfo section and
make a clear distinction between interfaces getting a Cygwin PID and
interfaces getting a Windows PID.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-02-01 04:19:03 +08:00
|
|
|
LONG pid_src;
|
2017-03-03 00:26:53 +08:00
|
|
|
LONG forkable_hardlink_support;
|
2008-04-19 04:13:37 +08:00
|
|
|
|
2003-09-11 05:01:40 +08:00
|
|
|
void initialize ();
|
2008-07-17 04:20:45 +08:00
|
|
|
void init_obcaseinsensitive ();
|
2001-09-10 03:06:50 +08:00
|
|
|
unsigned heap_chunk_size ();
|
2010-03-16 05:29:15 +08:00
|
|
|
static void create ();
|
2000-09-08 00:23:51 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
extern shared_info *cygwin_shared;
|
2005-02-14 02:17:29 +08:00
|
|
|
extern user_info *user_shared;
|
2003-09-25 10:29:05 +08:00
|
|
|
#define mount_table (&(user_shared->mountinfo))
|
|
|
|
extern HANDLE cygwin_user_h;
|
2000-09-08 00:23:51 +08:00
|
|
|
|
2002-10-15 15:03:45 +08:00
|
|
|
enum shared_locations
|
|
|
|
{
|
2008-04-19 04:13:37 +08:00
|
|
|
SH_CYGWIN_SHARED,
|
2003-09-25 10:29:05 +08:00
|
|
|
SH_USER_SHARED,
|
2002-10-15 15:03:45 +08:00
|
|
|
SH_MYSELF,
|
2011-06-08 04:55:10 +08:00
|
|
|
SH_SHARED_CONSOLE,
|
2005-04-29 07:59:44 +08:00
|
|
|
SH_TOTAL_SIZE,
|
|
|
|
SH_JUSTCREATE,
|
|
|
|
SH_JUSTOPEN
|
|
|
|
|
2002-10-15 15:03:45 +08:00
|
|
|
};
|
2008-07-28 06:31:48 +08:00
|
|
|
|
2014-10-17 22:36:59 +08:00
|
|
|
void memory_init ();
|
2022-06-07 00:00:45 +08:00
|
|
|
void shared_destroy ();
|
2000-09-08 00:23:51 +08:00
|
|
|
|
2001-01-28 13:51:15 +08:00
|
|
|
#define shared_align_past(p) \
|
|
|
|
((char *) (system_info.dwAllocationGranularity * \
|
|
|
|
(((DWORD) ((p) + 1) + system_info.dwAllocationGranularity - 1) / \
|
|
|
|
system_info.dwAllocationGranularity)))
|
|
|
|
|
2008-04-19 04:13:37 +08:00
|
|
|
HANDLE get_shared_parent_dir ();
|
2008-04-21 20:46:58 +08:00
|
|
|
HANDLE get_session_parent_dir ();
|
2022-06-07 00:00:45 +08:00
|
|
|
char *shared_name (char *, const char *, int);
|
|
|
|
WCHAR *shared_name (WCHAR *, const WCHAR *, int);
|
|
|
|
void *open_shared (const WCHAR *, int, HANDLE&, DWORD,
|
2010-03-10 05:26:55 +08:00
|
|
|
shared_locations, PSECURITY_ATTRIBUTES = &sec_all,
|
|
|
|
DWORD = FILE_MAP_READ | FILE_MAP_WRITE);
|
2022-06-07 00:00:45 +08:00
|
|
|
void *open_shared (const WCHAR *, int, HANDLE&, DWORD,
|
2010-03-10 05:26:55 +08:00
|
|
|
shared_locations *, PSECURITY_ATTRIBUTES = &sec_all,
|
|
|
|
DWORD = FILE_MAP_READ | FILE_MAP_WRITE);
|
2008-07-28 06:31:48 +08:00
|
|
|
extern void user_shared_create (bool reinit);
|