Release 960824
[wine/multimedia.git] / ipc / dde.tex
blobef4e1fff874a4c5de17a203546b233199bafeef5
1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 %%
3 %% Written by Michael Veksler.
4 %% May be freely redistributed as long as this header is unchanged.
5 %% The file be modified as long as there will be appropriate comment
6 %% containing the Author and a description.
7 %%
8 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
10 \documentstyle{article}
11 \renewcommand{\thepage}{}
12 \newcommand{\Wine}{Wine}
13 \newcommand{\WINE}{{\em WINdows Emulator}}
14 \newcommand{\DDE}{{\em Dynamic Data Exchange}}
15 \newcommand{\windoz}{MS-Win\-dows}
16 \newcommand{\fname}[1]{{\tt #1}}
17 \newcommand{\libwine}{\fname{libwine.a}}
18 \title{DDE\footnote{DDE is \DDE\ mechanism provided by \windoz.
19 (Appendix~\protect\ref{sec:DDE}).
21 \ capability for \Wine\footnote{\Wine\ (\WINE) Runs \windoz\
22 programs under UNIX\@. (Appendix~\protect\ref{sec:Wine}).
25 \author{Michael Veksler 11678223}
26 %%\date{Aug 6, 1995}
27 \begin{document}
28 \maketitle
29 \vfill
30 \abstract{\Wine{} provides an environment for running or compiling
31 \windoz{} applications for UNIX clones (such as Linux).
32 \Wine{} is not yet finished and lacks many basic important features.
33 One of the missing features is DDE\@. DDE implementation
34 (especially for \libwine) requires
35 UNIX IPC\footnote{IPC - Inter-Process Communication}. This Project
36 introduces the IPC mechanism into \Wine{}, thus allowing DDE to work
37 between different \Wine{} processes.}
40 \vfill
41 {\LARGE
42 \begin{itemize}
43 \item[Instructor:] Avner Lottem
44 \item[Done for:] Technion- Israel Institute of Technology,\\
45 Electrical Engineering software lab$^{\mbox{\small\copyright}}$.
46 \end{itemize}
48 \vfill
50 \newpage
51 \renewcommand{\thepage}{\roman{page}}
52 \setcounter{page}{1}
53 \begin{center}
54 {\LARGE Table Of Contents}
55 \end{center}
56 \tableofcontents
58 \newpage
59 \renewcommand{\thepage}{\arabic{page}}
60 \setcounter{page}{1}
62 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
64 %% end of title
66 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
67 \section{Introduction}
69 \subsection{The project}
70 The purpose of the project is to add DDE capabilities into \Wine.
71 The project enables \Wine{} DDE client-server applications communication.
72 This involved messing around with:
73 \begin{itemize}
74 \item \windoz\ message mechanism.
75 \item \windoz\ memory management.
76 \item \windoz\ task management.
77 \item UNIX messages among \Wine\ processes.
78 \item Exchanging (sharing) UNIX memory.
79 \end{itemize}
81 \subsection{Problem description}
82 DDE is essentially a communication protocol between \windoz\
83 tasks. Implementing this protocol requires communication among
84 \Wine{} processes and among tasks in one process (each \Wine{} process
85 can contain several tasks). Since \Wine\ already provides
86 communication among internal tasks, this project provides communication
87 between \Wine\ processes.
89 Different \Wine\ processes should be able to send \windoz\ messages
90 and to pass \windoz\ memory handles. There also has to be a
91 synchronization mechanism between the processes (\windoz\ applications
92 make assumptions about task switching - and don't use semaphores, or
93 any \windoz\ equivalent).
95 Passing messages is a bit tricky. \windoz\ gives a feedback about the
96 success of a message (fails if the window does not exist).
97 In case of SendMessage (see Appendix~\ref{sec:WindozMsg}), the process
98 will have to halt until the message has been processed.
99 In case of PostMessage, things are simpler - only the existence of the
100 recipient has to be checked.
102 \windoz\ switches tasks only when certain system calls are used (such
103 as delivering or polling messages). \windoz\ applications rely on this
104 behavior. The problem arises when two applications run on different
105 \Wine\ processes. Since UNIX preempts processes there is no guaranty
106 that the UNIX task will occur at the correct place (in respect of the
107 application).
108 One one hand is the need for compatibility (no UNIX ``current''
109 execution), and on the other hand is performance and stability.
111 Another problem is passing handles between \Wine\ processes. \windoz\
112 applications pass atoms\footnote{See appendix~\ref{sec:WhatAreAtoms}},
113 memory handles and window handles. These handles have to be allocated
114 globally (in shared memory) or translated on the fly.
117 If a process dies from ``unnatural causes'' (e.g.\ kill $-9$). It will
118 leave garbage in memory and other IPC handles will start floating
119 around. There should be some way to collect this garbage.
121 \subsection{Solutions}
122 \label{sec:ProjSolutions}
123 \Wine\ uses Sys-V IPC mechanism (See
124 Appendix~\ref{sec:SysV-IPC}). This allows sharing data and passing
125 data between processes (The alternatives are not that good in that
126 respect - see Appendix~\ref{DDE-Alternatives}).
127 The shared data contains only essential information (performance or
128 compatibility). The minimum is kept on shared memory in order to get
129 maximum stability (\windoz\ is known as an unstable system, \Wine\
130 should not imitate \windoz\ in this respect).
132 Communications are done by Sys-V messages and UNIX signals (a signal
133 wakes \Wine\ up and the message passes the data). Sys-V messages are
134 used for carrying \windoz\ messages, as well as synchronization
135 information. There are 3 types of messages: sent, posted and ack.
136 Ack message is used for synchronization as well as for returning error
137 codes (In case sending/posting messages fail). When a message is sent,
138 the sending process will block until \Wine's {\em ack}{} message is
139 received.
141 Synchronization between \Wine\ processes is divided into 2 categories,
142 in both cases the sender of a message waits for an ack message:
143 \begin{enumerate}
144 \item Sent messages - Wait until the recipient delivers ack message.
145 (When the recipient finished message processing)
146 \item Posted message - The recipient will send ack only during
147 task switching instructions (like PostMessage, GetMessage, Yield,
148 etc.). This way nothing will be done after PostMessage until it is
149 safe.
150 \end{enumerate}
152 There is no real \Wine\ server. Every \Wine\ process has to handle
153 it's end. This approach somehow resembles a distributed OS\@. This
154 introduces some problems (Resources might not be freed in case of a
155 crash). On the other hand this ``distributed OS'' approach simplifies
156 installation and use, and improves performance.
158 Atoms are stored on shared memory, so every two \Wine\ processes will
159 be in sync in this respect (atom 5 will mean the same on both
160 processes). Shared memory handles are stored on shared memory as
161 well. Shared memory handles are not from the same range as local
162 memory handles (\windoz\ requires an plication to declare about it's
163 shared memory). Since local memory handles have different range they
164 can be allocated locally (without any sync requirements - handle x may
165 appear on 10 different \Wine\ processes and address different data).
167 Window handles are allocated locally. This approach gives stability,
168 but window handles are no longer unique (same handle may appear
169 on different processes). This requires on the fly window handle
170 translation. When an \windoz\ message is transfered, \Wine\ will
171 translate any contained window handle. The sender translates the
172 handle to a global (unique) handle, the receiver translates the global
173 handle to the local window handle.
175 Collecting the garbage of dead processes is done in two cases:
176 \begin{enumerate}
177 \item When setting up a new \Wine\ process: If no \Wine\ process is
178 running and shared memory is floating around all the IPC stuff is
179 deleted.
180 \item When sending a message: If the recipient is dead it's IPC
181 handles are deleted.
182 \end{enumerate}
186 \section{The software}
188 \subsection{DDE project structure}
189 Old \Wine\ functions call the new DDE functions whenever needed.
190 (e.g.\ when sending a DDE message, the original SendMessage function calls
191 DDE\_SendMessage). This approach minimizes changes to original \Wine{}
192 code. The new code was written in C. The new capabilities where written
193 as much as possible in OOP\footnote{OOP stands for Object Oriented
194 Programming}{} style.
196 Currently DDE uses Sys-V IPC mechanism, for it's operation.
199 \paragraph{Major OOP objects and files:}
201 \begin{table}[h]
202 \begin{center}
203 \leavevmode
204 \begin{tabular}{|l|p{20em}|} \hline
205 Object & Description \\ \hline
206 shm\_block & shared memory block operations. \\
207 shm\_main\_block & (derived from shm\_block.) Things all
208 DDE applications need access to. \\
209 shm\_fragment & Allocation of in-block fragments. \\
210 shm\_semaph & Semaphore operations. \\
211 dde\_proc & Process and DDE message handling. \\
212 dde\_mem & Front end of DDE memory handling
213 (Interface of DDE to outer world). \\
214 dde\_atom & Handling global atoms. \\
215 bit\_array & Array of bits. It has atomic
216 operations, so bits can be used instead
217 of semaphores. \\ \hline
218 \end{tabular}
219 \caption{Objects constructing the DDE extension.}
220 \label{tab:ObjList}
221 \end{center}
222 \end{table}
224 Table~\ref{tab:ObjList}{} lists the objects used in the DDE code.
225 The following rules apply to objects:
227 \begin{itemize}
228 \item Object names that begin with {\em dde\_$\cdots$}{} are the front
229 end. These objects are working directly with the rest of
230 \Wine. Objects that start with {\em shm\_$\cdots$}{} are the back
231 end. These objects provide services for the rest of the
232 implementation.
233 \item The objects are stored in file with the same name as the object.
234 (e.g.\ dde\_mem is stored in dde\_mem.c and dde\_mem.h).
235 \item For each object there is a test file (that partially tests it).
236 The name of this file is object's name with the word ``test''
237 (e.g.\ dde\_mem object has dde\_mem\_test.c).
238 \item dde.h file has declarations used by dde\_proc and external DDE
239 users.
240 \end{itemize}
243 \subsection{Major algorithms}
245 \paragraph{Delivering messages:}
246 \label{sec:DeliveringMessages}
247 \windoz\ messages are passed using Sys-V IPC messages. Processing
248 starts with SendMessage() or PostMessage() \windoz\ system
249 functions:
250 \begin{enumerate}
251 \item SendMessage and PostMessage call the DDE functions (same names
252 prefixed with DDE\_). If the DDE functions pass, don't go any
253 further. If it fails try to process the message in the
254 conventional way.
255 \item The DDE message functions call DDE\_DoMessage, which is
256 the main DDE message processing function. From now on there is no
257 difference between sending and posting messages (from initiator's
258 point of view).
259 \item If the message is not a DDE message or the recipient is not
260 remote, fail and return to original message functions.
261 \item Bring the message to a format suitable for IPC delivery. The
262 format includes:
263 \begin{itemize}
264 \item message type (sent or posted).
265 \item Sender window handle (translated to global window id.)
266 \item Other message ingredients (msg, lParam).
267 \end{itemize}
268 \item Deliver the message to every recipients using
269 DDE\_DoOneMessage. There might be many recipients in case of a
270 broadcast (when the ``recipient'' window is -1).
271 \item DDE\_DoOneMessage delivers the message and waits for response.
272 Fail if timeout is reached.
273 \end{enumerate}
276 \paragraph{Receiving messages:}
277 Messages from other \Wine\ processes are received. Processing start
278 from DDE\_GetRemoteMessage():
279 \begin{enumerate}
280 \item DDE\_GetRemoteMessage is called whenever wine is going to wait
281 or receive X-windows message. If wine is sleeping (waiting for X),
282 it will waken by a SIGUSR2 signal. In this case the handler will
283 siglongjmp() out of the select() function.
284 \item If no remote message is pending in the message queue - exit.
285 (Sys-V message queue holds the remote messages until they are
286 read).
287 \item If the message is broadcasted, goto stage~\ref{BroadcastAlgo}.
288 \item Translate the global window handle of the recipient to local
289 handle.
290 \item Do this if the message was sent. Send the message to the
291 recipient window. Reply with ack to the sender. (Reply with the
292 return code of the SendMessage function). {\em \bf Return}\ with
293 positive return value.
294 \item Post the message.
295 \item If PostMessage fails - send failing ack message.
296 \item If PostMessage passes, add the message data into a FIFO\@. This
297 FIFO contains all messages that have to be acknowledged (who's
298 sender is waiting for ack). Whenever internal task switch occurs,
299 a item from this FIFO is popped out and an ack message is sent.
300 \item \label{BroadcastAlgo} Iterate through the local windows and
301 deliver the message to every one of them.
302 \item Send a positive ack message.
303 \end{enumerate}
305 \paragraph{Allocating memory:}
306 Shared memory allocation is divided into two categories: internal wine
307 and \windoz\ application. The memory used by \windoz\ applications is
308 allocated in two phases - allocate internal wine, and then prepare all
309 the stuff needed by \windoz.
311 The internal allocation (DDE\_malloc):
312 \begin{enumerate}
313 \item Try to allocate big enough memory fragment in allocated shared
314 memory.
315 \item If fragment could not be allocated, allocate a new shared
316 memory block. Allocate the memory fragment.
317 \item Allocate a shared memory handle (call the dde\_alloc\_handle()
318 function). The allocated handle is from a range used only by
319 shared memory handles. This allocation function is used only for
320 shared DDE memory.
321 \item Write the handle in the data structure. Also write the
322 relative location of this handle (Pointer location is useless since
323 it differs from one \Wine\ process to another).
324 This information is written in the main shared memory block.
325 \end{enumerate}
326 When a fragment is allocated, it is removed from the list of free
327 memory.
329 Allocation for \windoz\ applications (this is done in GlobalAlloc):
330 \begin{enumerate}
331 \item Do the internal allocation (instead of malloc in the local
332 allocation).
333 \item Everything else is the same as with local memory. A segment is
334 allocated for the new memory, and it's data is kept in the data
335 structure.
336 \end{enumerate}
339 \paragraph{Atoms:}
340 Atoms have pretty simple algorithms operating on them. Since atoms are
341 supposed to give a unique number for each string - atoms are
342 implemented as hash tables. The id of the atom is the entry in the
343 hash table. The disadvantage of this approach is that there is a limit
344 on the number of atoms, the big advantages are simplicity and
345 speed.
347 Since implementing a hash tables is strait forward, I will not
348 discuss it in depth. This hash table has two hash functions - primary
349 and secondary. When searching for an item (for deletion, addition, or
350 a seek) the following steps are taken:
351 \begin{enumerate}
352 \item The primary hash function returns the first entry.
353 \item \label{AtomHashLoop}
354 If the entry is empty or no unchecked entries {\bf \em fail}.
355 \item If the entry is correct, {\bf \em success!!!}.
356 \item Add the result of secondary hash function to the item index.
357 \item Goto step~\ref{AtomHashLoop}.
358 \end{enumerate}
361 \subsection{Major data structures}
362 There are two kinds of data structure, local and shared. The local
363 data structures are strait forward and will not be discussed in
364 detail.
366 The shared data structures have four level hierarchy. Each level
367 depend on the other and can not exist without it. Most structures have
368 much less than four levels.
370 \paragraph{Level one data structure - the main block:}
371 This data structure is part of the shm\_main\_block object. It
372 contains essential information needed by all \Wine\ processes. :
373 \begin{enumerate}
374 \item Semaphore identifier used for locking the data structure.
375 \item A table containing information about \Wine\ processes.
376 \item Relative pointers to atoms.
377 \item A table containing window information.
378 \item Tables with global memory handles.
379 \end{enumerate}
381 The first level is allocated and initialized when \Wine\ calls a DDE
382 function the first time. DDE functions are: global memory allocation,
383 global atoms or DDE messages.
385 The first level data structure contains the second level data
386 structure.
389 \paragraph{Atom element (level two):}
390 Each element is allocated dynamically (the size of the string is
391 unknown). The allocation is gained from the shm\_fragment object (each
392 atom is an instance of that object). Each atom contains:
393 \begin{enumerate}
394 \item Count of links. Each allocation of the atom establishes a new
395 link and each deallocation deletes one link (until all links are
396 removed).
397 \item The string of the atom. The string ends with a null character.
398 \end{enumerate}
400 \paragraph{Wine processes data (level two):}
401 (part of the dde\_proc object) :
402 \begin{enumerate}
403 \item pid (\Wine\ process id).
404 \item Message queue id.
405 \item Semaphore used for locking process's data structure.
406 \item Sys-V shared memory id of the first block in the chain of
407 process's blocks.
408 \end{enumerate}
411 \paragraph{Window information (level two):}
412 This is part of the dde\_proc object. The index of array entry
413 specifies the window handle. Each entry contains:
414 \begin{enumerate}
415 \item The process index of the \Wine\ process running this window.
416 \item The local window handle of this window (remember that each DDE
417 window has different global and local handles).
418 \end{enumerate}
421 \paragraph{Global memory handles (Level two):}
422 (part of bit\_array and dde\_mem objects):
423 \begin{enumerate}
424 \item A bit array contains '1' in every entry that refers to
425 used global memory handle.
426 \item Array of handles contains handle data. Each entry refers
427 to a global memory handle (The index is a function of the
428 handle). The data includes: 1) Sys-V shared memory handles 2)
429 offset into the memory block.
430 \end{enumerate}
432 \paragraph{Block allocation data structure (Level three):}
433 This data structure a part of the shm\_block object. It is local to
434 each shared memory block, so every memory block has it's own data
435 structure. The shared memory blocks are organized in chains grouped by
436 processes (each DDE process has one and only one chain):
437 \begin{enumerate}
438 \item The id of the next shared memory block in the chain.
439 \item The size of the block.
440 \item Number of free bytes in the block.
441 \item The index of the owner process.
442 \item The first item in the free list (a linked list of free items).
443 \end{enumerate}
446 \paragraph{Fragment allocation (Level four):}
447 This data is a part of the shm\_fragment object. It is a part of the shared
448 memory allocation mechanism. Every fragment is a part of shared memory
449 block. Each fragments contain:
450 \begin{enumerate}
451 \item The size of the fragment (for allocating and freeing this
452 fragment).
453 \item A union that contains one of:
454 \begin{itemize}
455 \item data - if it is allocated.
456 \item offset of the next free fragment (if it is a member of the
457 free list).
458 \end{itemize}
459 \end{enumerate}
462 \paragraph{Local reference to global memory:}
463 Global memory blocks are referenced from local memory. This is used
464 for storing pointers that refer to the memory block. It contains:
465 \begin{enumerate}
466 \item next item in the list.
467 \item shared memory block id.
468 \item Owner process.
469 \item Pointer to the data.
470 \end{enumerate}
472 \paragraph{Local mirroring of global handles:}
473 Global handles require local segments handles (when they are locked).
474 These segments have to be deleted when the handle is freed.
475 There is a minimal mirroring of handles in the original tables of
476 wine, this information is stored the way local handles have always
477 been stored.
479 \subsection{Interface and IO}
480 The DDE section of wine has several interfaces to different entities:
481 \begin{enumerate}
482 \item User debug information.
483 \item Interface between several \Wine\ processes.
484 \item Interface to the `old' code of \Wine.
485 \end{enumerate}
488 \paragraph{User debug information:}
489 The debug information is written according to \Wine's
490 conventions. This means that dprintf\_$\cdots$ macros are used to
491 print the debug information. (These macros allow runtime or compile time
492 disabling of a any sort of debug information).
494 In some cases the dprintf\_$\cdots$ macros are not powerful enough. In
495 those cases the following construct is used instead:
496 \begin{verbatim}
497 if (debugging_dde) {
498 /* print whatever is needed for dde debugging */
500 \end{verbatim}
503 \paragraph{Interface between \Wine\ processes:}
504 The interface between processes includes:
505 \begin{itemize}
506 \item Message delivery (see Section~\ref{sec:DeliveringMessages}).
507 \item Sharing \windoz\ constructs (atoms, memory, window
508 handles).
509 \item Synchronization among different \Wine\ processes so it will
510 appear to a \windoz\ as if there is only one process.
511 \end{itemize}
513 \paragraph{Interface to the rest of \Wine:}
514 Most of the interface has been minimized to an additional few lines in
515 the original functions. The hook for DDE are in the following
516 locations:
517 \begin{itemize}
518 \item Global atoms functions - these are called directly from
519 \windoz\ applications.
520 \item Message delivery - a hook calls the DDE functions from the
521 original message delivery functions.
522 \item Initialization - Every PeekMessage() call a DDE function to
523 check if the current window has DDE management (by sending
524 a dummy WM\_DDE\_INITIATE message).
525 \item Waiting on messages - The original code for waiting on X
526 messages was enhanced to wait on DDE messages as well. This
527 includes aborting sleeps when SIGUSR2 signal is sent. The actual
528 test for DDE messages is done in the DDE code.
529 \end{itemize}
531 \subsection{Major functions and their role}
532 \paragraph{Message delivery functions:}
533 \begin{itemize}
534 \item DDE\_SendMessage and DDE\_PostMessage - hooks used by original
535 \Wine's SendMessage and PostMessage. They return true if the
536 message could be successfully sent to a remote \Wine\ process.
537 Only in this case SendMessage and PostMessage stop further
538 processing.
539 \item DDE\_DoMessage - Try to post or send a message to another
540 \Wine\ process. This function can do broadcasting as well as
541 sending. (A message is `broadcasted' if it is delivered to every
542 window on the system).
543 \item DDE\_DoOneMessage - Deliver a message to a given wine
544 {\bf process}.
545 \item dde\_proc\_send\_ack - Send ack message to \Wine\
546 process. The input window handle is used for detecting the
547 process.
548 \item get\_ack - wait for ack or timeout.
549 \end{itemize}
551 \paragraph{Memory allocation functions:}
552 \begin{itemize}
553 \item DDE\_malloc - Allocate a shared memory fragment. This function
554 also allocates global memory handle.
555 \item DDE\_GlobalFree - Free a shared memory fragment according to
556 it's handle. And free the handle.
557 \item DDE\_SyncHandle - synchronize the global handles mirrored
558 locally. Delete any outdated handles, or remap reallocated
559 handles.
560 \item DDE\_mem\_init - initialize or attach the main shared memory
561 block, and relevant local data structures.
562 \item shm\_delete\_all - delete all IPC stuff related to this
563 process. Kill the main memory block if appropriate.
564 \end{itemize}
567 \section{Software testing}
568 The testing of this module was a substantial part of the
569 development. Testing revealed bugs just as they where created.
571 \subsection{Testing methods utilized}
572 \label{sec:TestMethod}
573 Two major testing methods where used:
574 \begin{enumerate}
575 \item Running DDE \windoz\ applications. The applications used are
576 DDE demonstration applications. This applications seem to show
577 precisely what DDE is all about. The applications used where:
578 ddepop1.exe (server), showpop1.exe (client). These
579 applications come with \windoz\ programming manual by Charles
580 Petzold \cite{bib:WinManual}.
581 \item Running standalone DDE objects linked with a test
582 object. Every object was tested this way. Some objects had to be
583 linked with a stub that emulated \Wine's functions. The stub is
584 pretty poor with dde\_mem object since this object requires hard
585 to emulate functionalities (things like allocating a segment).
587 For some objects the coverage seems to be perfect (100\%). For
588 some object the coverage is poor. The objects with massive stub
589 usage suffer from this (especially dde\_mem).
590 \end{enumerate}
592 \subsection{input for testing}
593 Most of the testing described in section~\ref{sec:TestMethod} has no
594 input. Most of the testing knowledge is in the test objects
595 themselves. There are two exceptions to this rule:
596 \begin{enumerate}
597 \item The \windoz\ applications described in
598 section~\ref{sec:TestMethod} - which are essentially an input to
599 the software. These applications can't be distributed since it
600 will be a \copyright{} violation.
601 \item A trace file which is used for comparing test's output with
602 the expected trace result. This trace file is used for
603 shm\_fragment validation. This file is implementation Dependants
604 and should be updated whenever the object is rewritten. When
605 updating the trace, it should be inspected manually before it is
606 released.
607 \end{enumerate}
609 \subsection{usage instructions}
611 \paragraph{Running the DDE applications:}
612 To test the DDE applications one must run:
613 \begin{verbatim}
614 prompt> wine /full-path/ddepop1.exe > /dev/null &
615 \end{verbatim}
616 Wait for the server window to pop up (A tiny window should appear at
617 the lower left corner of your screen). Then activate the client by
618 typing:
619 \begin{verbatim}
620 prompt> wine /full-path/showpop1.exe > /dev/null
621 \end{verbatim}
622 The server updates ``USA population'' data every 5 seconds. The client
623 asks for a hot link (i.e.\ it sends a WM\_DDE\_ADVISE on every
624 item). From that point on the server updates the client of any
625 population change.
628 \paragraph{Running the object tests:}
629 The {\em run\_tests}{} script is provided to automate the object
630 tests. Every object test is run and the script checks for results. At
631 the end the script prints a nice summary table.
633 Invoking tests outside the {\em run\_tests}{} script is not as simple
634 as it may look. Every test has differently looking output.
635 \begin{itemize}
636 \item dde\_atom\_test - The executable is run. It passes if no
637 errors are printed at the bottom.
638 \item dde\_mem\_test - The same as for dde\_atom\_test.
639 \item shm\_semaph\_test - The same as for dde\_atom\_test.
640 \item bit\_array\_test - The same as for dde\_atom\_test.
641 \item shm\_fragment\_test - After the executable is run, the output
642 has to be compared with TEST\_FRAGMENT.std
643 \item dde\_proc\_test - This actually runs as a client and as a
644 server. To activate the server one should write:
645 \begin{verbatim}
646 prompt> dde_proc_test 1 > server.log
647 \end{verbatim}
648 Then the client has to be activated within five seconds by
649 writing:
650 \begin{verbatim}
651 prompt> dde_proc_test > client.log
652 \end{verbatim}
653 The log files should contain:
654 \begin{description}
655 \item[server.log:] Should contain traces of received
656 WM\_DDE\_INITIATE message, and ack sent for it. (Pretty much
657 the same what {\em run\_tests}{} does).
658 \item[client.log:] Should contain traces of sending
659 WM\_DDE\_INITIATE and then receiving an ack message.
660 \end{description}
661 No `timeout' traces should be present in the log files.
663 \end{itemize}
666 \section{Summary}
667 \subsection{Software limitations}
668 \begin{itemize}
669 \item Only most fundamental memory management functions where
670 written. This means that the following functions will not work:
671 \begin{itemize}
672 \item GlobalReAlloc
673 \item GlobalSize - two line fix.
674 \item GlobalFlags - two line fix.
675 \item LockSegment - two line fix.
676 \item UnlockSegment - two line fix.
677 \item GlobalFreeAll - will not free DDE memory.
678 \item GlobalPageLock - two line fix.
679 \item GlobalPageUnlock - two line fix.
680 \item GlobalFix - two line fix.
681 \item GlobalUnfix - two line fix.
682 \end{itemize}
683 \item Non DDE messages to remote windows will not work. This is
684 currently only a sanity check, it may be removed in the future.
685 \item Message sending has a timeout limit. This is incompatible with
686 \windoz. This limit increases stability of a singe \Wine\ process.
687 \item Synchronization mechanism between wine processes is not
688 perfect. It was not proved theoretically. I never saw it fail.
689 \end{itemize}
691 \subsection{Concluding Remarks}
692 This extension to \Wine{} enables further development of \windoz\ IPC
693 support. Things like OLE can be extended using these features -
694 although some modifications might be inevitable.
696 The most important contribution of this project is the support for
697 \libwine{}. Any \windoz\ application compiled under UNIX and linked to
698 \libwine{} will need the IPC mechanism provided by this project.
700 During the progress of the project it got a bit outdated. During that
701 time \Wine{} started to handle tasks internally, so the external IPC
702 was no longer needed for the emulator configuration of
703 wine. Nevertheless the support of IPC for \libwine will never
704 be obsolete.
709 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
711 %% Appendixes
713 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
714 \clearpage
715 \appendix
717 \section{\Wine}
718 \label{sec:Wine}
719 \Wine\ stand for {\em WINdows Emulator}. It is an X-windows - UNIX
720 application (Linux and FreeBSD). \Wine\ emulates \windoz\ environment
721 for the \windoz\ applications. It has two uses:
722 \begin{enumerate}
723 \item Run \windoz\ binary code (compiled under \windoz).
724 \item To be used as a toolkit for compiling \windoz\ applications
725 under UNIX. (The \libwine\ library is provided)
726 \end{enumerate}
727 For emulation, only Intel-Architecture CPU (386, 486, Pentium) are
728 supported. \libwine\ Toolkit should run on any platforms, but it was not
729 tested. \Wine\ is still in alpha state, and does not support all \windoz\
730 capabilities yet.
733 \section{Messages under \windoz}
734 \label{sec:WindozMsg}
735 Messages are the means of communication to a user window (from another
736 window or from \windoz\ itself).
737 Messages can be delivered in two ways:
738 \begin{itemize}
739 \item Messages can be sent. The sent message enters the window handler
740 asynchronously (The handler may be reentered many times).
741 A window sending the message waits for the recipient to process
742 the message and return an exit code.
743 \item Messages can be posted. The posted message enters a queue, and
744 it's up to the recipient to process it. If the recipient ignores
745 it, the message might be eventually sent to the recipient from
746 WinMain handler.
747 \end{itemize}
749 \section{DDE}
750 \label{sec:DDE}
751 DDE stands for \DDE\@. DDE is an \windoz\
752 protocol used for data exchange between applications.
753 It has synchronous and asynchronous operation modes.
754 DDE mechanism is based on messages, atoms
755 (Section~\ref{sec:WhatAreAtoms}) and shared memory.
757 DDE applications are divided roughly into two classes: servers AND
758 clients. Clients have the initiative, they try to connect to the
759 server. Servers only maintain an existing DDE link.
762 \subsection{DDE Messages}
763 \paragraph{DDE message format}:
765 \label{sec:DDEMessageFormat}
767 DDE messages contain the following fields.
768 \begin{description}
769 \item[wnd] The recipient of this message ($-1$ if every window
770 should receive).
771 \item[msg] The ID of the message.
772 \item[wParam] Who sent this message.
773 \item[lParam] 32 bit parameter, divided into two 16 bit words.
774 Usually, the lower 16 bits contain a memory handle. The handle
775 points to some extra DATA about this message.
777 \end{description}
779 \paragraph{Available messages:}
780 \begin{description}
781 \item[WM\_DDE\_INITIATE]
782 This message is sent by the client to the whole ``world''.
783 {\em lParam}{} contains the two atoms used for passing the topic and
784 application information.
786 Every server application checks if this message refers to it
787 (According to the Application and the Topic atoms).
790 \item[WM\_DDE\_ACK]
791 This is a generic response to various events
792 (one of them is WM\_DDE\_INITIATE).
793 The low part of {\em lParam}{} passes extra information, such as
794 success/failure.
796 \item[WM\_DDE\_TERMINATE]
797 Kill the DDE link.
800 \item[WM\_DDE\_ADVISE]
801 Tell the server to inform the client of any updates.
804 \item[WM\_DDE\_UNADVISE]
805 Stop the WM\_DDE\_UNADVISE mode.
808 \item[WM\_DDE\_DATA]
809 Transfer data handle (note that the data handle must be globally allocated
810 with the GMEM\_DDESHARE flag).
812 \item[WM\_DDE\_REQUEST]
813 Request a data item from the server. This message is used in a
814 cold link. {\em lParam}{} contains an atom describing the desired
815 item, and a WORD describing the wanted data format.
816 \item[WM\_DDE\_POKE]
817 The client gives the server new data.
818 \item[WM\_DDE\_EXECUTE]
819 The client asks the server to execute a procedure (according to a
820 command string).
822 \end{description}
824 \subsection{Atoms}
825 \label{sec:WhatAreAtoms}
826 Atoms are represented by numbers. Every atom maps uniquely to a string
827 (i.e.\ two atoms can't map to the same string).
828 There are two types of atoms - local and global. The local are visible
829 only to the application that created them. Global atoms are seen by all
830 \windoz\ applications.
832 Functions:
833 \begin{description}
834 \item[AddAtom(str)] create a local atom that maps to ``str''.
835 If it exists, increment the allocation-counter,
836 and return the atom.
837 \item[DeleteAtom(atom)] decrement the allocation-counter. When it
838 reaches zero the atom, will be deleted.
839 \item[FindAtom(str)] Find the atom that maps to this string (if exist).
841 \item[GetAtomName(\ldots)] Find the string that this atom points to.
842 \end{description}
844 NOTE:
845 \begin{description}
846 \item[Global atoms] Add ``Global'' before the listed names to get Global
847 atom functions.
848 \item[Case sensitivity] All atom operations ignore case.
849 \end{description}
852 \section{DDE under \Wine\ - Alternatives}
853 \label{DDE-Alternatives}
854 There where three possible approaches for this project. I have chosen
855 System-V IPC, but it can be easily changed.
857 \subsection{IPC - Inter-Process Communication}
858 \label{sec:SysV-IPC}
860 The IPC mechanism was originated from System-V UNIX\@. This mechanism
861 allows complicate communication between two process (on the same machine).
862 IPC includes the following capabilities:
863 \begin{enumerate}
864 \item Shared Memory (shm) - can be shared among few processes and users.
865 \item Semaphores (These semaphores allow grouped operations - i.e.\
866 operations gathered as an atomic operation).
867 \item Message Queues (allow few messages at a time).
868 \end{enumerate}
870 The advantages of IPC over the other variants are:
871 \begin{itemize}
872 \item Memory access speed is good. (after the memory was attached).
873 \item Easy to block critical code (don't enter critical code from two
874 processes at the same time)
875 \end{itemize}
876 Disadvantages of IPC:
877 \begin{itemize}
878 \item Impossible to communicate to other machine.
879 \item Requires complex mechanism to wait both for X and IPC messages.
880 \end{itemize}
882 \subsection{X-Windows Communication mechanisms}
883 The advantages of X-Windows Communication over the other variants are:
884 \begin{itemize}
885 \item Possible to communicate to other machines.
886 \item No need for additional mechanism that will wait both for X and DDE\@.
887 \item Many of the required capabilities are already there.
888 \end{itemize}
889 Disadvantages of X-windows communication:
890 \begin{itemize}
891 \item {\em Slow}\ and complex memory access.
892 \item May be hard to avoid two applications from entering critical
893 code at the same time.
894 \end{itemize}
896 \subsection{BSD Sockets}
897 The advantages of Sockets are:
898 \begin{itemize}
899 \item Possible to communicate to other machines.
900 \item No need for complex mechanism that will wait both for X and
901 DDE\@. (can use one ``select'' on X-windows socket in concert with
902 the DDE socket).
903 \end{itemize}
904 Disadvantages of socket are:
905 \begin{itemize}
906 \item {\em Slow}{} and complex memory access. (note that mmap on a
907 descriptor does not work for Linux 0.99).
908 \item May be hard to avoid two applications from entering critical
909 code at the same time.
910 \end{itemize}
912 \subsection{Why was it written in C? Pros and cons.}
913 Advantages of C:
915 \begin{itemize}
916 \item History- \Wine{} is already written in C.
917 \item Portability- not all systems have C++.
918 \item Speed- C++ sometimes makes it very difficult to write fast code.
919 \item Maintenance- More programmers know C than C++.
920 \end{itemize}
922 Advantages of C++:
924 \begin{itemize}
925 \item smaller code - Templates allow Smaller and more readable code.
926 \item Maintenance - It is easier to add and modify code in C++ (than in C).
927 \item Verification - Functionality can be verified and debugged for
928 individual objects.
929 \end{itemize}
931 I have decided to use C. Most of C++ advantages can be acquired
932 by using OOP methodologies. OOP methods that require inline functions
933 can't be used (without performance impact). GCC supports inline functions,
934 but this solution is not compatible.
938 \section{\Wine\ basics}
939 \subsection{How it runs}
940 \Wine\ works in the following order:
941 \begin{enumerate}
942 \item \Wine\ loads the \windoz\ application into it's memory.
943 (in the process it, links
944 DLL's\footnote{DLL (Dynamically Linked Library) is linked on load-time.}
945 creates 16-bit segments).
946 \item \windoz\ code is executed.
947 \end{enumerate}
949 \section{bibliography}
950 \begin{thebibliography}{99}
951 \bibitem{bib:WinManual} Charles Petzold {\em Programming
952 Windows~3.1}{} - 1992. \\
953 On cover: {\em the Microsoft guide to writing applications for
954 windows~3.1}. \\
955 Published by {\em Microsoft press}.
956 \end{thebibliography}
959 \newpage
962 \end{document}