b5e1003722
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>
97 lines
2.3 KiB
C++
97 lines
2.3 KiB
C++
/* shared_info.h: shared info for cygwin
|
|
|
|
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. */
|
|
|
|
#include "tty.h"
|
|
#include "security.h"
|
|
#include "mtinfo.h"
|
|
#include "limits.h"
|
|
#include "mount.h"
|
|
#include "loadavg.h"
|
|
|
|
#define CURR_USER_MAGIC 0xab1fcce8U
|
|
|
|
class user_info
|
|
{
|
|
void initialize ();
|
|
public:
|
|
LONG version;
|
|
DWORD cb;
|
|
bool warned_msdos;
|
|
bool warned_notty;
|
|
bool warned_nonativesyms;
|
|
mount_info mountinfo;
|
|
friend void dll_crt0_1 (void *);
|
|
static void create (bool);
|
|
};
|
|
|
|
/******** Shared Info ********/
|
|
/* Data accessible to all tasks */
|
|
|
|
|
|
#define CURR_SHARED_MAGIC 0x6758de88U
|
|
|
|
#define USER_VERSION 1
|
|
|
|
/* 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. */
|
|
class shared_info
|
|
{
|
|
LONG version;
|
|
DWORD cb;
|
|
public:
|
|
tty_list tty;
|
|
LONG last_used_bindresvport;
|
|
DWORD obcaseinsensitive;
|
|
mtinfo mt;
|
|
loadavginfo loadavg;
|
|
LONG pid_src;
|
|
|
|
void initialize ();
|
|
void init_obcaseinsensitive ();
|
|
unsigned heap_chunk_size ();
|
|
static void create ();
|
|
};
|
|
|
|
extern shared_info *cygwin_shared;
|
|
extern user_info *user_shared;
|
|
#define mount_table (&(user_shared->mountinfo))
|
|
extern HANDLE cygwin_user_h;
|
|
|
|
enum shared_locations
|
|
{
|
|
SH_CYGWIN_SHARED,
|
|
SH_USER_SHARED,
|
|
SH_MYSELF,
|
|
SH_SHARED_CONSOLE,
|
|
SH_TOTAL_SIZE,
|
|
SH_JUSTCREATE,
|
|
SH_JUSTOPEN
|
|
|
|
};
|
|
|
|
void memory_init ();
|
|
void __stdcall shared_destroy ();
|
|
|
|
#define shared_align_past(p) \
|
|
((char *) (system_info.dwAllocationGranularity * \
|
|
(((DWORD) ((p) + 1) + system_info.dwAllocationGranularity - 1) / \
|
|
system_info.dwAllocationGranularity)))
|
|
|
|
HANDLE get_shared_parent_dir ();
|
|
HANDLE get_session_parent_dir ();
|
|
char *__stdcall shared_name (char *, const char *, int);
|
|
WCHAR *__stdcall shared_name (WCHAR *, const WCHAR *, int);
|
|
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);
|
|
extern void user_shared_create (bool reinit);
|