blob: fd0387d59d87c7d578f39d8b50ba10da1a116b06 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
WINSUP ROADMAP
The purpose of this document is to give the briefest overview of how
the various parts of cygwin work together and where everything can be
found. The intended audience is people developing the cygwin dll
itself. Comments to dj@cygnus.com.
=== cygwin1.dll source files
- overhead
.h winsup autoload debug external shared sync
.cc assert dcrt0 debug external init ntea registry security
shared smallprint strace sync
.din cygwin
.rc winver
.sgml external shared
- processes
.h sigproc
.cc exec fork pinfo resource signal sigproc spawn wait
- signals
.cc exceptions window
- files and I/O
.h delqueue fhandler path select
.cc delqueue dir fhandler* dtable path pipe select tty
.sgml dtable path
- common unix functions
.h dll_init tz_posixrules
.cc dlfcn dll_init environ errno fcntl flog grp ioctl localtime
malloc passwd scandir strsep syscalls sysconf syslog termios
.c longjmp setjmp
.sgml dll_init
- unix emulation
.cc heap mmap net times unifo uname
--- if MT_SAFE
.h thread
.cc pthread thread
--- from other places
regex/*
../libiberty/{random,strsignal}
../newlib/* (libc)
=== libcygwin.a source files
libccrt0.cc
libcmain.cc
dll_entry.cc
dll_main.cc
getopt.c
=== gmon (profiling, -pg)
gcrt0.c
gmon.c gmon.h
mcount.c
profil.c profil.h
=== entry points
- normal cygwin program
newlib/libc/sys/cygwin/crt0.c has mainCRTStartup() and calls cygwin_crt0()
libccrt0.cc has cygwin_crt0() and calls dll_crt0()
dcrt0.cc - has dll_crt0()
Note: dll_init.cc has nothing to do with initializing the cygwin dll.
It initializes the dlls you have dl_open'd.
- cygwin-built dll
dll_entry.cc - has a macro for wrapping your dll startup function
(equivalent of DllMain()) in such a way that you get your
cygwin environment set up automatically when your dll is
loaded.
dll_main.cc - has empty DllMain() in case you don't have your own
- manually loading cygwin1.dll
init.cc - has dll_entry() which is called by the OS when the dll is
loaded. It doesn't do much except note if you linked
cygwin1.dll or are manually loading it.
=== About "fhandlers"
An fhandler is a file type handler. This is where the unix device
emulation happens.
dtable.cc maps posix file descriptors to a table of file handlers (type
fhandler) in the dll. It's mostly concerned with managing the table
of descriptors (open, dup, fork, select). Most of the posix I/O
system calls (syscalls.cc) use the fdtab table to call the right
fhandler directly.
fhandler.cc is the base class; specific types are derived as
appropriate (see fhandler.h). dtable.cc is in charge of selecting and
creating a suitable fhandler when you open a file. path.cc handles
emulated files in /dev (like /dev/null) by returning an FH_* value
from get_device_number (which dtable.cc calls in dtable::build_fhandler).
Note: if you're looking for read() and write(), they call _read() and
_write() in syscalls.cc. The non-underscored ones are in
newlib/libc/syscalls and just call the underscored ones.
=== How "fork" works
It all starts in fork() in fork.cc.
Set up a pid in the shared memory area for the new child. Use
setjmp() to capture state. First time (parent), set up some stuff and
use CreateProcess to run a second copy of the same executable. The
second copy will note in the shared memory area that it's a fork, and
do the longjmp. They sync up and the parent copies all it's program
memory to the child's address space. There's also code to reload
dlls, map shared memory and mmap'd files, etc.
Handling the special startup for the child is done in dcrt0.cc in many
places. This case is triggered by a special StartupInfo structure
that's passed from the parent to the child in CreateProcessA.
|