Release 940912
[wine] / DEVELOPERS-HINTS
1 This is intend to be a document to help new developers get started.
2 Existing developers should feel free to add there comments.
3
4 SUBMITTING YOUR WORK:
5
6 Submissions of code for inclussion into Wine should be sent to
7 wine-new@amscons.com (Bob Amstadt).  You MUST provide a suitable
8 ChangeLog entry for any work that you submit.  I prefer new code
9 to be submitted as unified diffs (diff -u) off of the latest release.  
10 Releases are every Tuesday evening (approximately 17:00 PST or 
11 Wednesday 01:00 GMT).
12
13 MEMORY AND SEGMENTS:
14
15 NE (Win16) executables consist of multiple segments.  The Wine loader
16 loads each segment into a unique location the Wine processes memory
17 and assigns a selector to that segment.  To make address conversion
18 simpler, Wine loads the segments in such a way that the segmented
19 address (16:16) is stored in memory the same way as the 32-bit linear
20 address.  For example, the segmented address 1237:89AB can be at the
21 address 0x123789AB in the Wine process space.
22
23 This also implies that a Win16 program cannot access any arbitrary
24 memory location.  If a pointer needs to be returned to a Win16 program,
25 then the memory block must be allocated using either GlobalAlloc()
26 or HEAP_Alloc().  The HEAP_* functions are faster than the Global*
27 functions but are only capable of managing a 64k memory block.  The
28 HEAP_* functions are used to implement local heaps.  Wine should
29 never call Local* functions.  These functions are reserved for use
30 by Win16 programs only!
31
32 The following code fragment should be used to establish a new Wine
33 local heap:
34
35         #include "heap.h"
36
37         #define MY_HEAP_SIZE    0x10000         /* Must be <= 64k */
38
39         int MyHeapHandle;
40         void *MyHeapBase;
41         MDESC *MyHeap;
42
43                 ...
44
45         int InitMyHeap()
46         {
47             MyHeapHandle = GlobalAlloc(GMEM_FIXED, MY_HEAP_SIZE);
48             if (MyHeapHandle == 0)
49                 return -1;
50             MyHeapBase = GlobalLock(MyHeapHandle);
51             HEAP_Init(&MyHeap, MyHeapBase, MY_HEAP_SIZE);
52             return 0;
53         }
54
55 Memory blocks greater than 64 kilobytes in length must be allocated
56 using GlobalAlloc().  Because of our special memory mapping, GlobalLock()
57 cannot be used to obtain the address of a linearly accessible memory
58 block that is greater than 64kB in length.  Instead GlobalLinearLock()
59 should be used.  The inverse function GlobalLinearUnlock() must be 
60 called before the block can be freed with GlobalFree().
61
62 API ENTRY POINTS:
63
64 Because Win16 programs use a 16-bit stack and because they can only
65 call 16:16 addressed functions, all API entry points must be at low
66 address offsets and must have the arguments translated and moved to
67 Wines 32-bit stack.  This task is handled by the code in the "if1632"
68 directory.  To define a new API entry point handler you must place a
69 new entry in the appropriate API specification file.  These files are
70 named *.spec.  For example, the API specification file for the USER DLL
71 is contained in the file user.spec.  These entries are processed by
72 the "build" program to create dll_*.s and dll_tab_*.c.  The dll_*.s
73 files contain the entry point code for each API call, and the dll_tab_*.s
74 files contain tables used by relay.c to translate arguments and transfer
75 control to the proper handler.  The format of the *.spec files is
76 documented in the file "tools/build-spec.txt".
77
78 REGISTER FUNCTIONS:
79
80 Some functions are defined as type "register" in the DLL specification files.
81 Inorder to return values in the registers to the WIN16 program, the handler
82 function must exit by calling ReturnFromRegisterFunc().  Look at the function
83 DOS3Call() for an example of how this works.