2000-09-08 04:56:55 +02:00
|
|
|
/* shared_info.h: shared info for cygwin
|
2000-09-07 18:23:51 +02: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 04:56:55 +02:00
|
|
|
#include "tty.h"
|
2003-09-10 04:12:26 +02:00
|
|
|
#include "security.h"
|
2008-04-18 22:13:37 +02:00
|
|
|
#include "mtinfo.h"
|
2008-07-24 20:25:52 +02:00
|
|
|
#include "limits.h"
|
2008-12-25 16:55:31 +01:00
|
|
|
#include "mount.h"
|
2017-03-21 20:17:42 +01:00
|
|
|
#include "loadavg.h"
|
2000-09-07 18:23:51 +02:00
|
|
|
|
2013-05-23 16:23:01 +02:00
|
|
|
#define CURR_USER_MAGIC 0xab1fcce8U
|
2011-06-08 21:27:48 +02:00
|
|
|
|
2003-09-25 04:29:05 +02:00
|
|
|
class user_info
|
|
|
|
{
|
2010-03-15 22:29:15 +01:00
|
|
|
void initialize ();
|
2003-09-25 04:29:05 +02:00
|
|
|
public:
|
2010-03-15 22:29:15 +01:00
|
|
|
LONG version;
|
2003-09-25 04:29:05 +02:00
|
|
|
DWORD cb;
|
2006-08-01 20:00:44 +02:00
|
|
|
bool warned_msdos;
|
2011-06-08 21:27:48 +02:00
|
|
|
bool warned_notty;
|
2013-05-23 16:23:01 +02:00
|
|
|
bool warned_nonativesyms;
|
2003-09-25 04:29:05 +02:00
|
|
|
mount_info mountinfo;
|
2010-03-15 22:29:15 +01:00
|
|
|
friend void dll_crt0_1 (void *);
|
|
|
|
static void create (bool);
|
2003-09-25 04:29:05 +02:00
|
|
|
};
|
2011-06-08 21:27:48 +02:00
|
|
|
|
2000-09-07 18:23:51 +02:00
|
|
|
/******** Shared Info ********/
|
|
|
|
/* Data accessible to all tasks */
|
|
|
|
|
2001-12-26 22:35:16 +01:00
|
|
|
|
2017-03-02 17:26:53 +01:00
|
|
|
#define CURR_SHARED_MAGIC 0x9f33cc5dU
|
2001-12-26 05:53:34 +01:00
|
|
|
|
2010-03-15 22:29:15 +01:00
|
|
|
#define USER_VERSION 1
|
2009-01-03 06:12:22 +01:00
|
|
|
|
2001-12-26 07:18:41 +01: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-07 18:23:51 +02:00
|
|
|
class shared_info
|
|
|
|
{
|
2010-03-15 22:29:15 +01:00
|
|
|
LONG version;
|
2001-12-26 22:35:16 +01:00
|
|
|
DWORD cb;
|
2001-05-25 05:13:14 +02:00
|
|
|
public:
|
2000-09-07 18:23:51 +02:00
|
|
|
tty_list tty;
|
2008-04-18 22:13:37 +02:00
|
|
|
LONG last_used_bindresvport;
|
2008-07-16 22:20:45 +02:00
|
|
|
DWORD obcaseinsensitive;
|
2008-04-18 22:13:37 +02:00
|
|
|
mtinfo mt;
|
2017-03-21 20:17:42 +01: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-01-31 21:19:03 +01:00
|
|
|
LONG pid_src;
|
2017-03-02 17:26:53 +01:00
|
|
|
LONG forkable_hardlink_support;
|
2008-04-18 22:13:37 +02:00
|
|
|
|
2003-09-10 23:01:40 +02:00
|
|
|
void initialize ();
|
2008-07-16 22:20:45 +02:00
|
|
|
void init_obcaseinsensitive ();
|
2001-09-09 21:06:50 +02:00
|
|
|
unsigned heap_chunk_size ();
|
2010-03-15 22:29:15 +01:00
|
|
|
static void create ();
|
2000-09-07 18:23:51 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
extern shared_info *cygwin_shared;
|
2005-02-13 19:17:29 +01:00
|
|
|
extern user_info *user_shared;
|
2003-09-25 04:29:05 +02:00
|
|
|
#define mount_table (&(user_shared->mountinfo))
|
|
|
|
extern HANDLE cygwin_user_h;
|
2000-09-07 18:23:51 +02:00
|
|
|
|
2002-10-15 09:03:45 +02:00
|
|
|
enum shared_locations
|
|
|
|
{
|
2008-04-18 22:13:37 +02:00
|
|
|
SH_CYGWIN_SHARED,
|
2003-09-25 04:29:05 +02:00
|
|
|
SH_USER_SHARED,
|
2002-10-15 09:03:45 +02:00
|
|
|
SH_MYSELF,
|
2011-06-07 22:55:10 +02:00
|
|
|
SH_SHARED_CONSOLE,
|
2005-04-29 01:59:44 +02:00
|
|
|
SH_TOTAL_SIZE,
|
|
|
|
SH_JUSTCREATE,
|
|
|
|
SH_JUSTOPEN
|
|
|
|
|
2002-10-15 09:03:45 +02:00
|
|
|
};
|
2008-07-28 00:31:48 +02:00
|
|
|
|
2014-10-17 16:36:59 +02:00
|
|
|
void memory_init ();
|
2008-07-27 16:52:46 +02:00
|
|
|
void __stdcall shared_destroy ();
|
2000-09-07 18:23:51 +02:00
|
|
|
|
2001-01-28 06:51:15 +01:00
|
|
|
#define shared_align_past(p) \
|
|
|
|
((char *) (system_info.dwAllocationGranularity * \
|
|
|
|
(((DWORD) ((p) + 1) + system_info.dwAllocationGranularity - 1) / \
|
|
|
|
system_info.dwAllocationGranularity)))
|
|
|
|
|
2008-04-18 22:13:37 +02:00
|
|
|
HANDLE get_shared_parent_dir ();
|
2008-04-21 14:46:58 +02:00
|
|
|
HANDLE get_session_parent_dir ();
|
2008-04-18 22:13:37 +02:00
|
|
|
char *__stdcall shared_name (char *, const char *, int);
|
2009-01-26 14:42:37 +01:00
|
|
|
WCHAR *__stdcall shared_name (WCHAR *, const WCHAR *, int);
|
2010-03-09 22:26:55 +01:00
|
|
|
void *__stdcall open_shared (const WCHAR *, int, HANDLE&, DWORD,
|
|
|
|
shared_locations, PSECURITY_ATTRIBUTES = &sec_all,
|
|
|
|
DWORD = FILE_MAP_READ | FILE_MAP_WRITE);
|
|
|
|
void *__stdcall open_shared (const WCHAR *, int, HANDLE&, DWORD,
|
|
|
|
shared_locations *, PSECURITY_ATTRIBUTES = &sec_all,
|
|
|
|
DWORD = FILE_MAP_READ | FILE_MAP_WRITE);
|
2008-07-28 00:31:48 +02:00
|
|
|
extern void user_shared_create (bool reinit);
|