mirror of
https://github.com/clang-retro/mac-sdk.git
synced 2026-11-28 13:19:22 -08:00
Open Transport, MacTCP and Shared Library Manager support for 68k and PowerPC (#38)
Adds the Open Transport and MacTCP name resolver headers and calls on both CPUs, a Shared Library Manager client on 68k, native Open Transport on 68k through ASLM with a MacTCP fallback, a fetch sample, a QEMU network test script and docs. Signed-off-by: Neo-Desktop <321592+Neo-Desktop@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01B82eRU3QJgPHoQrF9EQ8YZ
This commit is contained in:
1 parent
58de736f38
commit
7ba5f78ac6
43 files changed
+8885
-178
No files matched your search
@@ -408,6 +408,13 @@ links both archives before `libmacrt.a`, and starts the program at
|
||||
driver), names from the MacTCP resolver (`getaddrinfo`,
|
||||
`gethostbyname`), and `AF_UNIX` sockets and named pipes (`mkfifo`)
|
||||
between programs over the PPC Toolbox. See docs/network.md.
|
||||
- Open Transport (`OpenTransport.h`, `OpenTransportProviders.h`): on
|
||||
PowerPC over Mac OS's Open Transport, on 68k over Apple's 68k
|
||||
libraries (through the Shared Library Manager) or over MacTCP. Also the
|
||||
MacTCP TCP and UDP blocks (`MacTCP.h`) and the name resolver
|
||||
(`AddressXlation.h`). See docs/opentransport.md.
|
||||
- The Shared Library Manager client on 68k (`LibraryManager.h`): load
|
||||
an ASLM library and call its functions. See docs/aslm.md.
|
||||
- OpenGL on PowerPC: `GL/gl.h` (OpenGL 1.2 and Apple's extensions),
|
||||
`GL/glu.h` and `AGL/agl.h`, imported weakly from Apple's
|
||||
`OpenGLLibrary` and `OpenGLUtility`. See docs/opengl.md.
|
||||
@@ -519,7 +526,9 @@ the C library. `runtime/build-libstdcxx.sh` builds the library, and
|
||||
install CD (`-boot d`) does not mount a disk that `hformat` made,
|
||||
since it has no partition map; put that image in the second CD drive
|
||||
instead, from the monitor: `change ide1-cd0 xfer.img raw`. And `tools/qemu/mon.py` takes
|
||||
screenshots and clicks through the QEMU monitor.
|
||||
screenshots and clicks through the QEMU monitor. `tools/qemu/nettest.py`
|
||||
runs a network test on Mac OS in QEMU and collects its report (see
|
||||
docs/opentransport.md).
|
||||
- For PowerPC on Mac OS 8.1 and earlier, use SheepShaver with an
|
||||
OldWorld ROM image (such as the beige G3's), with the install CD
|
||||
attached as a CD-ROM.
|
||||
@@ -536,8 +545,8 @@ definition gives one, checks the argument-block calls against the ROM,
|
||||
and links every example into a fat application. With `LLVM_SRC` set it
|
||||
also builds the runtime library and runs its test, and with
|
||||
`PICOLIBC_SRC` set as well it builds the C library and runs its tests
|
||||
(`tests/libc.c`, `tests/console.c`, `tests/thread.c`, `tests/net.c` and
|
||||
the soft float test, `tests/softfloat68k.c`).
|
||||
(`tests/libc.c`, `tests/console.c`, `tests/thread.c`, `tests/net.c`,
|
||||
`tests/ot.c` and the soft float test, `tests/softfloat68k.c`).
|
||||
With `GCC_SRC` set too, it builds the C++ library and runs
|
||||
`tests/cxx.cpp`.
|
||||
|
||||
@@ -561,7 +570,8 @@ and also fails when `include/` or `docs/coverage.md` differ from what
|
||||
- Threads on a real Thread Manager: `tests/thread.c` has run only on
|
||||
the simulators' fake Thread Manager.
|
||||
- Sockets on a real network: `tests/net.c` has run only on the
|
||||
simulators' fake MacTCP and PPC Toolbox.
|
||||
simulators' fake MacTCP and PPC Toolbox. `examples/net/fetch.c` (TCP
|
||||
and names) has run on Mac OS 8.1 and 9.2.1 in QEMU.
|
||||
- Shared libraries in the linkers.
|
||||
- Programs over 32 KB of 68k code are one CODE segment that large.
|
||||
`tests/cxx.cpp` (415 KB of 68k code) has run on System 7.6.1, but no
|
||||
|
||||
@@ -0,0 +1,267 @@
|
||||
# AddressXlation.yaml: the MacTCP name resolver (DNR)
|
||||
#
|
||||
# Written from the MacTCP Programmer's Guide and Inside Macintosh:
|
||||
# Networking. Clean-room: no Apple header text is reproduced.
|
||||
#
|
||||
# The resolver is a code resource ('dnrp') in the MacTCP control panel
|
||||
# or, with Open Transport, in the System file. Applications do not
|
||||
# call a trap: the SDK's C library (runtime/libc/dnr.c) finds the
|
||||
# resource, loads it and calls it. These functions use the C calling
|
||||
# convention on both CPUs, as in Apple's dnr.c.
|
||||
#
|
||||
# A call that must ask a name server gives cacheFault at once. The
|
||||
# resolver then calls the result procedure (at interrupt level) when
|
||||
# the answer comes; the rtnCode field stays cacheFault until then.
|
||||
|
||||
- enum:
|
||||
values:
|
||||
- name: NUM_ALT_ADDRS
|
||||
value: 4
|
||||
comment: |
|
||||
The most addresses that one hostInfo record holds.
|
||||
|
||||
- struct:
|
||||
name: hostInfo
|
||||
comment: |
|
||||
The result of StrToAddr and AddrToName. cname is a C string
|
||||
(the resolver ends a domain name with a dot).
|
||||
members:
|
||||
- name: rtnCode
|
||||
type: int32_t # 0
|
||||
- name: cname
|
||||
type: char[255] # 4
|
||||
- name: addr
|
||||
type: uint32_t[4] # 260
|
||||
size: 276
|
||||
|
||||
- enum:
|
||||
name: AddrClasses
|
||||
comment: |
|
||||
Resource record types of the domain name system.
|
||||
values:
|
||||
- name: A
|
||||
value: 1
|
||||
- name: NS
|
||||
value: 2
|
||||
- name: CNAME
|
||||
value: 5
|
||||
- name: HINFO
|
||||
value: 13
|
||||
- name: MX
|
||||
value: 15
|
||||
- name: lastClass
|
||||
value: 32767
|
||||
|
||||
- struct:
|
||||
name: HInfoRec
|
||||
comment: |
|
||||
A host information record: CPU and system names (C strings).
|
||||
members:
|
||||
- name: cpuType
|
||||
type: char[30] # 0
|
||||
- name: osType
|
||||
type: char[30] # 30
|
||||
size: 60
|
||||
|
||||
- struct:
|
||||
name: MXRec
|
||||
comment: |
|
||||
A mail exchange record.
|
||||
members:
|
||||
- name: preference
|
||||
type: uint16_t # 0
|
||||
- name: exchange
|
||||
type: char[255] # 2
|
||||
size: 258
|
||||
|
||||
- union:
|
||||
name: returnRecData
|
||||
members:
|
||||
- name: addr
|
||||
type: uint32_t[4]
|
||||
- name: hinfo
|
||||
type: HInfoRec
|
||||
- name: mx
|
||||
type: MXRec
|
||||
size: 258
|
||||
|
||||
- struct:
|
||||
name: returnRec
|
||||
comment: |
|
||||
The result of HInfo and MXInfo.
|
||||
members:
|
||||
- name: rtnCode
|
||||
type: int32_t # 0
|
||||
- name: cname
|
||||
type: char[255] # 4
|
||||
- name: rdata
|
||||
type: returnRecData # 260
|
||||
size: 518
|
||||
|
||||
- union:
|
||||
name: cacheEntryRecordData
|
||||
members:
|
||||
- name: name
|
||||
type: char*
|
||||
- name: addr
|
||||
type: ip_addr
|
||||
size: 4
|
||||
|
||||
- struct:
|
||||
name: cacheEntryRecord
|
||||
comment: |
|
||||
One entry of the resolver's cache, which EnumCache gives.
|
||||
members:
|
||||
- name: cname
|
||||
type: char* # 0
|
||||
- name: type
|
||||
type: uint16_t # 4
|
||||
- name: cacheClass
|
||||
type: uint16_t # 6
|
||||
- name: ttl
|
||||
type: uint32_t # 8
|
||||
- name: rdata
|
||||
type: cacheEntryRecordData # 12
|
||||
size: 16
|
||||
|
||||
- funptr:
|
||||
name: ResultUPP
|
||||
comment: |
|
||||
Called when StrToAddr or AddrToName ends. Pascal convention,
|
||||
at interrupt level.
|
||||
args:
|
||||
- name: hostInfoPtr
|
||||
type: hostInfo*
|
||||
- name: userDataPtr
|
||||
type: char*
|
||||
|
||||
- funptr:
|
||||
name: ResultProc2UPP
|
||||
comment: |
|
||||
Called when HInfo or MXInfo ends. Pascal convention, at
|
||||
interrupt level.
|
||||
args:
|
||||
- name: returnRecPtr
|
||||
type: returnRec*
|
||||
- name: userDataPtr
|
||||
type: char*
|
||||
|
||||
- funptr:
|
||||
name: EnumResultUPP
|
||||
comment: |
|
||||
Called by EnumCache once for each cache entry. Pascal
|
||||
convention.
|
||||
args:
|
||||
- name: cacheEntryRecordPtr
|
||||
type: cacheEntryRecord*
|
||||
- name: userDataPtr
|
||||
type: char*
|
||||
|
||||
- function:
|
||||
name: OpenResolver
|
||||
return: OSErr
|
||||
args:
|
||||
- name: fileName
|
||||
type: char*
|
||||
callconv: C
|
||||
comment: |
|
||||
Loads and opens the resolver. fileName is ignored (pass NULL):
|
||||
the library finds the resolver in the MacTCP control panel or
|
||||
in the System file.
|
||||
|
||||
- function:
|
||||
name: CloseResolver
|
||||
return: OSErr
|
||||
callconv: C
|
||||
comment: |
|
||||
Closes the resolver.
|
||||
|
||||
- function:
|
||||
name: StrToAddr
|
||||
return: OSErr
|
||||
args:
|
||||
- name: hostName
|
||||
type: char*
|
||||
- name: rtnStruct
|
||||
type: hostInfo*
|
||||
- name: resultproc
|
||||
type: ResultUPP
|
||||
- name: userDataPtr
|
||||
type: char*
|
||||
callconv: C
|
||||
comment: |
|
||||
Finds the addresses of a host name or a dotted number. Gives
|
||||
noErr when the answer is ready now, cacheFault when the result
|
||||
procedure will get it, or an error.
|
||||
|
||||
- function:
|
||||
name: AddrToStr
|
||||
return: OSErr
|
||||
args:
|
||||
- name: addr
|
||||
type: uint32_t
|
||||
- name: addrStr
|
||||
type: char*
|
||||
callconv: C
|
||||
comment: |
|
||||
Writes an address as a dotted number (C string, 16 bytes).
|
||||
|
||||
- function:
|
||||
name: EnumCache
|
||||
return: OSErr
|
||||
args:
|
||||
- name: resultproc
|
||||
type: EnumResultUPP
|
||||
- name: userDataPtr
|
||||
type: char*
|
||||
callconv: C
|
||||
comment: |
|
||||
Calls resultproc for each entry of the resolver's cache.
|
||||
|
||||
- function:
|
||||
name: AddrToName
|
||||
return: OSErr
|
||||
args:
|
||||
- name: addr
|
||||
type: ip_addr
|
||||
- name: rtnStruct
|
||||
type: hostInfo*
|
||||
- name: resultproc
|
||||
type: ResultUPP
|
||||
- name: userDataPtr
|
||||
type: char*
|
||||
callconv: C
|
||||
comment: |
|
||||
Finds the name of an address. Results as for StrToAddr.
|
||||
|
||||
- function:
|
||||
name: HInfo
|
||||
return: OSErr
|
||||
args:
|
||||
- name: hostName
|
||||
type: char*
|
||||
- name: returnRecPtr
|
||||
type: returnRec*
|
||||
- name: resultProc
|
||||
type: ResultProc2UPP
|
||||
- name: userDataPtr
|
||||
type: char*
|
||||
callconv: C
|
||||
comment: |
|
||||
Finds the host information record of a name.
|
||||
|
||||
- function:
|
||||
name: MXInfo
|
||||
return: OSErr
|
||||
args:
|
||||
- name: hostName
|
||||
type: char*
|
||||
- name: returnRecPtr
|
||||
type: returnRec*
|
||||
- name: resultProc
|
||||
type: ResultProc2UPP
|
||||
- name: userDataPtr
|
||||
type: char*
|
||||
callconv: C
|
||||
comment: |
|
||||
Finds the mail exchange record of a name.
|
||||
@@ -0,0 +1,149 @@
|
||||
# LibraryManager.yaml: the client side of the Apple Shared Library
|
||||
# Manager (ASLM) on 68k.
|
||||
#
|
||||
# Written from a study of how Open Transport's 68k code calls ASLM.
|
||||
# Clean-room: no Apple header text is reproduced. Apple's own client
|
||||
# header for ASLM is C++; this header gives a small C interface:
|
||||
#
|
||||
# - InitLibraryManager and CleanupLibraryManager, with the names and
|
||||
# arguments of Apple's calls.
|
||||
# - ASLMPresent, ASLMLoadFunctionSet and ASLMCallPascal, which are
|
||||
# names of this SDK.
|
||||
# - ASLM_FUNCTION_SET and ASLM_FUNCTION, which make the records and
|
||||
# the stubs that a client needs to call the functions of a function
|
||||
# set. Apple's LibraryBuilder made these from an export file.
|
||||
#
|
||||
# The C library (runtime/libc/aslm.c) has the calls. docs/aslm.md
|
||||
# tells how to use them. There is no ASLM on PowerPC: there, shared
|
||||
# libraries are Code Fragment Manager fragments.
|
||||
|
||||
- verbatim: |
|
||||
#if TARGET_CPU_68K
|
||||
#include <stddef.h>
|
||||
|
||||
/* The result code of Apple's glue when ASLM is not installed (the
|
||||
name is the SDK's). */
|
||||
enum { kASLMNotPresentErr = -3132 };
|
||||
|
||||
/* The zone and the memory kind that InitLibraryManager takes.
|
||||
Open Transport's glue passes 1 for both; the SDK uses its values
|
||||
as the defaults. */
|
||||
enum { kASLMDefaultPoolSize = 1024, kASLMDefaultZone = 1, kASLMDefaultMemory = 1 };
|
||||
|
||||
/* The record that names a function set. ASLM keeps its own data in
|
||||
reserved. version is the version that the client wants, and
|
||||
minVersion the oldest version that it accepts. The record must
|
||||
be writable. */
|
||||
#define ASLM_FUNCTION_SET(var, idString, ver, minVer) \
|
||||
struct { long reserved[3]; unsigned short version, minVersion; \
|
||||
char id[sizeof(idString)]; } var \
|
||||
__attribute__((aligned(2))) = { {0, 0, 0}, (ver), (minVer), idString }
|
||||
|
||||
/* The slot of one stub: ASLM puts the address of the function in
|
||||
fn when the stub binds for the first time. */
|
||||
typedef struct ASLMStubSlot {
|
||||
void *fn;
|
||||
void *set;
|
||||
long reserved;
|
||||
short index;
|
||||
} __attribute__((packed, aligned(2))) ASLMStubSlot;
|
||||
|
||||
/* Makes a stub with the name sym for the function number index of
|
||||
the function set var. Declare sym as an array of char, and call
|
||||
it with ASLMCallC (a C function of MPW) or ASLMCallPascal (a
|
||||
Pascal function). Do not call it directly from C: MPW code can
|
||||
change register D2, which clang keeps across a call, and gives a
|
||||
pointer result in D0, where clang expects A0. The first call
|
||||
binds the stub through ASLM; the next calls go directly to the
|
||||
function. Call InitLibraryManager before the first call. */
|
||||
#define ASLM_FUNCTION(sym, var, index) \
|
||||
ASLMStubSlot sym##__aslm_slot __attribute__((used)) = { 0, &(var), 0, (index) }; \
|
||||
__asm__(".text\n\t.globl " #sym "\n\t.p2align 1\n" #sym ":\n" \
|
||||
"\tlea " #sym "__aslm_slot, %a0\n\tmove.l (%a0), %d0\n" \
|
||||
"\tbeq 1f\n\tmove.l %d0, %a0\n\tjmp (%a0)\n1:\tjmp __aslm_bind\n")
|
||||
|
||||
#endif
|
||||
|
||||
- function:
|
||||
name: InitLibraryManager
|
||||
return: OSErr
|
||||
args:
|
||||
- name: poolSize
|
||||
type: size_t
|
||||
- name: zoneType
|
||||
type: int
|
||||
- name: memType
|
||||
type: int
|
||||
callconv: C
|
||||
comment: |
|
||||
Starts the program's use of ASLM (68k only). poolSize is the
|
||||
size of the memory pool that ASLM makes for the program. zoneType
|
||||
and memType select where the pool comes from: use the
|
||||
kASLMDefault values. Gives noErr, or kASLMNotPresentErr when ASLM
|
||||
is not installed. The C library calls CleanupLibraryManager when
|
||||
the program ends.
|
||||
|
||||
- function:
|
||||
name: CleanupLibraryManager
|
||||
return: void
|
||||
callconv: C
|
||||
comment: |
|
||||
Ends the program's use of ASLM and unloads its libraries.
|
||||
|
||||
- function:
|
||||
name: ASLMPresent
|
||||
return: Boolean
|
||||
callconv: C
|
||||
comment: |
|
||||
Gives true when ASLM is installed (SDK name).
|
||||
|
||||
- function:
|
||||
name: ASLMLoadFunctionSet
|
||||
return: OSErr
|
||||
args:
|
||||
- name: id
|
||||
type: const char*
|
||||
callconv: C
|
||||
comment: |
|
||||
Loads the library that has the function set id (for example
|
||||
"OTClnt$LclUtils"), so that the stubs of the set can bind. Gives
|
||||
noErr or an ASLM error (SDK name).
|
||||
|
||||
- function:
|
||||
name: ASLMCallC
|
||||
return: long
|
||||
args:
|
||||
- name: fn
|
||||
type: const void*
|
||||
- name: nargs
|
||||
type: int
|
||||
- name: args
|
||||
type: const long*
|
||||
callconv: C
|
||||
comment: |
|
||||
Calls fn, a function of the MPW C calling convention, with nargs
|
||||
4-byte arguments: args[0] is the first. Gives the value of D0 (a
|
||||
pointer result too). Keeps all the registers that clang keeps
|
||||
(SDK name).
|
||||
|
||||
- function:
|
||||
name: ASLMCallPascal
|
||||
return: long
|
||||
args:
|
||||
- name: fn
|
||||
type: const void*
|
||||
- name: nargs
|
||||
type: int
|
||||
- name: wordMask
|
||||
type: unsigned long
|
||||
- name: resultSize
|
||||
type: int
|
||||
- name: args
|
||||
type: const long*
|
||||
callconv: C
|
||||
comment: |
|
||||
Calls the Pascal function fn with nargs arguments: args[0] is the
|
||||
first. Bit i of wordMask is 1 when argument i is a 2-byte value (a
|
||||
short or a Boolean); else the argument is 4 bytes. resultSize is
|
||||
0, 2 or 4: the size of the result. Gives the result. A Boolean
|
||||
result is in bits 8 to 15 (SDK name).
|
||||
+165
-6
@@ -580,15 +580,174 @@
|
||||
type: ip_addr # 32
|
||||
size: 36
|
||||
|
||||
# #### UDP
|
||||
|
||||
- enum:
|
||||
name: UDPEventCode
|
||||
comment: |
|
||||
Event codes that MacTCP gives to a UDP notification routine.
|
||||
values:
|
||||
- name: UDPDataArrival
|
||||
value: 1
|
||||
- name: UDPICMPReceived
|
||||
value: 2
|
||||
|
||||
- funptr:
|
||||
name: UDPNotifyUPP
|
||||
comment: |
|
||||
UDP notification routine (ASR). Pascal convention. MacTCP
|
||||
calls it at interrupt level.
|
||||
args:
|
||||
- name: udpStream
|
||||
type: StreamPtr
|
||||
- name: eventCode
|
||||
type: uint16_t
|
||||
- name: userDataPtr
|
||||
type: Ptr
|
||||
- name: icmpMsg
|
||||
type: ICMPReport*
|
||||
|
||||
- struct:
|
||||
name: UDPCreatePB
|
||||
comment: |
|
||||
udpCreate and udpMultiCreate. localPort 0 asks MacTCP for a
|
||||
free port; MacTCP puts the port it used here.
|
||||
members:
|
||||
- name: rcvBuff
|
||||
type: Ptr # 0
|
||||
- name: rcvBuffLen
|
||||
type: uint32_t # 4
|
||||
- name: notifyProc
|
||||
type: UDPNotifyUPP # 8
|
||||
- name: localPort
|
||||
type: uint16_t # 12
|
||||
- name: userDataPtr
|
||||
type: Ptr # 14
|
||||
- name: endingPort
|
||||
type: uint16_t # 18
|
||||
size: 20
|
||||
|
||||
- struct:
|
||||
name: UDPSendPB
|
||||
comment: |
|
||||
udpWrite. wdsPtr points to a wdsEntry list that ends with a
|
||||
zero length.
|
||||
members:
|
||||
- name: reserved
|
||||
type: uint16_t # 0
|
||||
- name: remoteHost
|
||||
type: ip_addr # 2
|
||||
- name: remotePort
|
||||
type: uint16_t # 6
|
||||
- name: wdsPtr
|
||||
type: Ptr # 8
|
||||
- name: checkSum
|
||||
type: Boolean # 12
|
||||
- name: sendLength
|
||||
type: uint16_t # 14
|
||||
- name: userDataPtr
|
||||
type: Ptr # 16
|
||||
- name: localPort
|
||||
type: uint16_t # 20
|
||||
size: 22
|
||||
|
||||
- struct:
|
||||
name: UDPReceivePB
|
||||
comment: |
|
||||
udpRead and udpBfrReturn. MacTCP gives rcvBuff and rcvBuffLen;
|
||||
return the buffer with udpBfrReturn. timeOut is in seconds
|
||||
(0: wait without a limit).
|
||||
members:
|
||||
- name: timeOut
|
||||
type: uint16_t # 0
|
||||
- name: remoteHost
|
||||
type: ip_addr # 2
|
||||
- name: remotePort
|
||||
type: uint16_t # 6
|
||||
- name: rcvBuff
|
||||
type: Ptr # 8
|
||||
- name: rcvBuffLen
|
||||
type: uint16_t # 12
|
||||
- name: secondTimeStamp
|
||||
type: uint16_t # 14
|
||||
- name: userDataPtr
|
||||
type: Ptr # 16
|
||||
- name: destHost
|
||||
type: ip_addr # 20
|
||||
- name: destPort
|
||||
type: uint16_t # 24
|
||||
size: 26
|
||||
|
||||
- struct:
|
||||
name: UDPMTUPB
|
||||
comment: |
|
||||
udpMaxMTUSize: the largest datagram to remoteHost.
|
||||
members:
|
||||
- name: mtuSize
|
||||
type: uint16_t # 0
|
||||
- name: remoteHost
|
||||
type: ip_addr # 2
|
||||
- name: userDataPtr
|
||||
type: Ptr # 6
|
||||
size: 10
|
||||
|
||||
- union:
|
||||
name: UDPcsParam
|
||||
members:
|
||||
- name: mtu
|
||||
type: UDPMTUPB
|
||||
- name: create
|
||||
type: UDPCreatePB
|
||||
- name: send
|
||||
type: UDPSendPB
|
||||
- name: receive
|
||||
type: UDPReceivePB
|
||||
size: 26
|
||||
|
||||
- struct:
|
||||
name: UDPiopb
|
||||
comment: |
|
||||
The UDP I/O parameter block passed to PBControl on the .IPP
|
||||
driver. The header is the same as in TCPiopb: udpStream 28,
|
||||
csParam 32.
|
||||
members:
|
||||
- name: qLink
|
||||
type: QElemPtr # 0
|
||||
- name: qType
|
||||
type: INTEGER # 4
|
||||
- name: ioTrap
|
||||
type: INTEGER # 6
|
||||
- name: ioCmdAddr
|
||||
type: Ptr # 8
|
||||
- name: ioCompletion
|
||||
type: ProcPtr # 12
|
||||
- name: ioResult
|
||||
type: OSErr # 16
|
||||
- name: ioNamePtr
|
||||
type: StringPtr # 18
|
||||
- name: ioVRefNum
|
||||
type: INTEGER # 22
|
||||
- name: ioCRefNum
|
||||
type: INTEGER # 24
|
||||
- name: csCode
|
||||
type: INTEGER # 26
|
||||
- name: udpStream
|
||||
type: StreamPtr # 28
|
||||
- name: csParam
|
||||
type: UDPcsParam # 32
|
||||
size: 58
|
||||
|
||||
- typedef:
|
||||
name: UDPiopbPtr
|
||||
type: UDPiopb*
|
||||
|
||||
# ####
|
||||
#
|
||||
# Deliberately not yet defined (phase 3):
|
||||
# - UDPiopb and the UDP csParam blocks
|
||||
# Not yet defined:
|
||||
# - TCPGlobalInfoPB / TCPExtendedStat result blocks
|
||||
# - AddressXlation.h material (hostInfo, DNR selectors) — the DNR is
|
||||
# a code resource loaded by applications, not a driver interface,
|
||||
# and will be specified in its own defs file alongside the 'dnrp'
|
||||
# stub resource.
|
||||
# - The name resolver (AddressXlation.h) is a code resource, not a
|
||||
# driver interface. defs/AddressXlation.yaml declares it, and
|
||||
# runtime/libc/dnr.c loads and calls it.
|
||||
#
|
||||
# Verification: tests/mactcp_abi.cpp asserts every size and offset
|
||||
# above. It is dual-mode, so the same assertions can be rebuilt
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,352 @@
|
||||
- verbatim: "/* Open Transport TCP/IP: addresses, Internet services (the name\n resolver) and the TCP,\
|
||||
\ UDP and IP options. */"
|
||||
- typedef:
|
||||
name: InetPort
|
||||
type: UInt16
|
||||
- typedef:
|
||||
name: InetHost
|
||||
type: UInt32
|
||||
comment: An IPv4 address in network order.
|
||||
- typedef:
|
||||
name: InetSvcRef
|
||||
type: ProviderRef
|
||||
comment: An open Internet services provider. All provider calls take it.
|
||||
- typedef:
|
||||
name: InetDomainName
|
||||
type: char[256]
|
||||
- verbatim: '#ifndef AF_INET
|
||||
|
||||
#define AF_INET 2
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef AF_DNS
|
||||
|
||||
#define AF_DNS 42
|
||||
|
||||
#endif'
|
||||
- enum:
|
||||
values:
|
||||
- name: kOTAnyInetAddress
|
||||
value: 0
|
||||
- name: kMaxHostAddrs
|
||||
value: 10
|
||||
- name: kMaxSysStringLen
|
||||
value: 32
|
||||
- name: kMaxHostNameLen
|
||||
value: 255
|
||||
- name: kDefaultInetInterface
|
||||
value: -1
|
||||
- name: kInetInterfaceInfoVersion
|
||||
value: 3
|
||||
- define:
|
||||
name: kTCPName
|
||||
value: '"tcp"'
|
||||
- define:
|
||||
name: kUDPName
|
||||
value: '"udp"'
|
||||
- define:
|
||||
name: kRawIPName
|
||||
value: '"rawip"'
|
||||
- define:
|
||||
name: kDNRName
|
||||
value: '"dnr"'
|
||||
- define:
|
||||
name: kDefaultInternetServicesPath
|
||||
value: ((OTConfigurationRef)(long)-3)
|
||||
- enum:
|
||||
comment: Events of the Internet services provider.
|
||||
values:
|
||||
- name: T_DNRSTRINGTOADDRCOMPLETE
|
||||
value: 268435457
|
||||
- name: T_DNRADDRTONAMECOMPLETE
|
||||
value: 268435458
|
||||
- name: T_DNRSYSINFOCOMPLETE
|
||||
value: 268435459
|
||||
- name: T_DNRMAILEXCHANGECOMPLETE
|
||||
value: 268435460
|
||||
- name: T_DNRQUERYCOMPLETE
|
||||
value: 268435461
|
||||
- enum:
|
||||
comment: Option levels.
|
||||
values:
|
||||
- name: INET_IP
|
||||
value: 0
|
||||
- name: INET_TCP
|
||||
value: 6
|
||||
- name: INET_UDP
|
||||
value: 17
|
||||
- verbatim: "/* Option names. The BSD socket headers use some of the same names with\n other values:\
|
||||
\ a file that includes <netinet/in.h> or <netinet/tcp.h>\n first keeps their values. */\n#ifndef\
|
||||
\ TCP_NODELAY\n#define TCP_NODELAY 0x1\n#endif\n#ifndef TCP_MAXSEG\n#define TCP_MAXSEG 0x2\n#endif\n\
|
||||
#ifndef TCP_NOTIFY_THRESHOLD\n#define TCP_NOTIFY_THRESHOLD 0x10\n#endif\n#ifndef TCP_ABORT_THRESHOLD\n\
|
||||
#define TCP_ABORT_THRESHOLD 0x11\n#endif\n#ifndef TCP_CONN_NOTIFY_THRESHOLD\n#define TCP_CONN_NOTIFY_THRESHOLD\
|
||||
\ 0x12\n#endif\n#ifndef TCP_CONN_ABORT_THRESHOLD\n#define TCP_CONN_ABORT_THRESHOLD 0x13\n#endif\n\
|
||||
#ifndef TCP_OOBINLINE\n#define TCP_OOBINLINE 0x14\n#endif\n#ifndef TCP_URGENT_PTR_TYPE\n#define TCP_URGENT_PTR_TYPE\
|
||||
\ 0x15\n#endif\n#ifndef TCP_KEEPALIVE\n#define TCP_KEEPALIVE 0x8\n#endif\n#ifndef UDP_CHECKSUM\n#define\
|
||||
\ UDP_CHECKSUM 0x600\n#endif\n#ifndef IP_OPTIONS\n#define IP_OPTIONS 0x1\n#endif\n#ifndef IP_TOS\n\
|
||||
#define IP_TOS 0x2\n#endif\n#ifndef IP_TTL\n#define IP_TTL 0x3\n#endif\n#ifndef IP_REUSEADDR\n#define\
|
||||
\ IP_REUSEADDR 0x4\n#endif\n#ifndef IP_DONTROUTE\n#define IP_DONTROUTE 0x10\n#endif\n#ifndef IP_BROADCAST\n\
|
||||
#define IP_BROADCAST 0x20\n#endif\n#ifndef IP_REUSEPORT\n#define IP_REUSEPORT 0x200\n#endif\n#ifndef\
|
||||
\ IP_HDRINCL\n#define IP_HDRINCL 0x1002\n#endif\n#ifndef IP_RCVOPTS\n#define IP_RCVOPTS 0x1005\n#endif\n\
|
||||
#ifndef IP_RCVDSTADDR\n#define IP_RCVDSTADDR 0x1006\n#endif\n#ifndef IP_MULTICAST_IF\n#define IP_MULTICAST_IF\
|
||||
\ 0x1010\n#endif\n#ifndef IP_MULTICAST_TTL\n#define IP_MULTICAST_TTL 0x1011\n#endif\n#ifndef IP_MULTICAST_LOOP\n\
|
||||
#define IP_MULTICAST_LOOP 0x1012\n#endif\n#ifndef IP_ADD_MEMBERSHIP\n#define IP_ADD_MEMBERSHIP 0x1013\n\
|
||||
#endif\n#ifndef IP_DROP_MEMBERSHIP\n#define IP_DROP_MEMBERSHIP 0x1014\n#endif"
|
||||
- struct:
|
||||
name: InetAddress
|
||||
comment: An IPv4 address and port (fAddressType AF_INET).
|
||||
members:
|
||||
- name: fAddressType
|
||||
type: OTAddressType
|
||||
- name: fPort
|
||||
type: InetPort
|
||||
- name: fHost
|
||||
type: InetHost
|
||||
- name: fUnused[8]
|
||||
type: UInt8
|
||||
size: 16
|
||||
align: power
|
||||
- struct:
|
||||
name: DNSAddress
|
||||
comment: A host name and port as text, "name:port" (fAddressType AF_DNS).
|
||||
members:
|
||||
- name: fAddressType
|
||||
type: OTAddressType
|
||||
- name: fName
|
||||
type: InetDomainName
|
||||
size: 258
|
||||
align: power
|
||||
- struct:
|
||||
name: InetHostInfo
|
||||
comment: 'The result of OTInetStringToAddress: the full name and up to
|
||||
|
||||
kMaxHostAddrs addresses (the unused ones are 0).'
|
||||
members:
|
||||
- name: name
|
||||
type: InetDomainName
|
||||
- name: addrs[10]
|
||||
type: InetHost
|
||||
size: 296
|
||||
align: power
|
||||
- struct:
|
||||
name: InetSysInfo
|
||||
members:
|
||||
- name: cpuType[32]
|
||||
type: char
|
||||
- name: osType[32]
|
||||
type: char
|
||||
size: 64
|
||||
align: power
|
||||
- struct:
|
||||
name: InetMailExchange
|
||||
members:
|
||||
- name: preference
|
||||
type: UInt16
|
||||
- name: exchange
|
||||
type: InetDomainName
|
||||
size: 258
|
||||
align: power
|
||||
- struct:
|
||||
name: DNSQueryInfo
|
||||
members:
|
||||
- name: qType
|
||||
type: UInt16
|
||||
- name: qClass
|
||||
type: UInt16
|
||||
- name: ttl
|
||||
type: UInt32
|
||||
- name: name
|
||||
type: InetDomainName
|
||||
- name: responseType
|
||||
type: UInt16
|
||||
- name: resourceLen
|
||||
type: UInt16
|
||||
- name: resourceData[4]
|
||||
type: char
|
||||
size: 272
|
||||
align: power
|
||||
- struct:
|
||||
name: InetInterfaceInfo
|
||||
comment: The settings of an IP interface (OTInetGetInterfaceInfo).
|
||||
members:
|
||||
- name: fAddress
|
||||
type: InetHost
|
||||
- name: fNetmask
|
||||
type: InetHost
|
||||
- name: fBroadcastAddr
|
||||
type: InetHost
|
||||
- name: fDefaultGatewayAddr
|
||||
type: InetHost
|
||||
- name: fDNSAddr
|
||||
type: InetHost
|
||||
- name: fVersion
|
||||
type: UInt16
|
||||
- name: fHWAddrLen
|
||||
type: UInt16
|
||||
- name: fHWAddr
|
||||
type: UInt8*
|
||||
- name: fIfMTU
|
||||
type: UInt32
|
||||
- name: fReservedPtrs[2]
|
||||
type: UInt8*
|
||||
- name: fDomainName
|
||||
type: InetDomainName
|
||||
- name: fIPSecondaryCount
|
||||
type: UInt32
|
||||
- name: fReserved[252]
|
||||
type: UInt8
|
||||
size: 552
|
||||
align: power
|
||||
- function:
|
||||
name: OTOpenInternetServices
|
||||
return: InetSvcRef
|
||||
args:
|
||||
- name: cfig
|
||||
type: OTConfigurationRef
|
||||
- name: oflag
|
||||
type: OTOpenFlags
|
||||
- name: err
|
||||
type: OSStatus*
|
||||
callconv: C
|
||||
comment: 'Opens the Internet services provider (the name resolver), synchronous.
|
||||
|
||||
Pass kDefaultInternetServicesPath as cfig.'
|
||||
- function:
|
||||
name: OTAsyncOpenInternetServices
|
||||
return: OSStatus
|
||||
args:
|
||||
- name: cfig
|
||||
type: OTConfigurationRef
|
||||
- name: oflag
|
||||
type: OTOpenFlags
|
||||
- name: proc
|
||||
type: OTNotifyUPP
|
||||
- name: contextPtr
|
||||
type: void*
|
||||
callconv: C
|
||||
- function:
|
||||
name: OTInetStringToHost
|
||||
return: OSStatus
|
||||
args:
|
||||
- name: str
|
||||
type: const char*
|
||||
- name: host
|
||||
type: InetHost*
|
||||
callconv: C
|
||||
- function:
|
||||
name: OTInetHostToString
|
||||
args:
|
||||
- name: host
|
||||
type: InetHost
|
||||
- name: str
|
||||
type: char*
|
||||
callconv: C
|
||||
- function:
|
||||
name: OTInetGetInterfaceInfo
|
||||
return: OSStatus
|
||||
args:
|
||||
- name: info
|
||||
type: InetInterfaceInfo*
|
||||
- name: val
|
||||
type: SInt32
|
||||
callconv: C
|
||||
- function:
|
||||
name: OTInetGetSecondaryAddresses
|
||||
return: OSStatus
|
||||
args:
|
||||
- name: addr
|
||||
type: InetHost*
|
||||
- name: count
|
||||
type: UInt32*
|
||||
- name: val
|
||||
type: SInt32
|
||||
callconv: C
|
||||
- function:
|
||||
name: OTInetStringToAddress
|
||||
return: OSStatus
|
||||
args:
|
||||
- name: ref
|
||||
type: InetSvcRef
|
||||
- name: name
|
||||
type: char*
|
||||
- name: hinfo
|
||||
type: InetHostInfo*
|
||||
callconv: C
|
||||
- function:
|
||||
name: OTInetAddressToName
|
||||
return: OSStatus
|
||||
args:
|
||||
- name: ref
|
||||
type: InetSvcRef
|
||||
- name: addr
|
||||
type: InetHost
|
||||
- name: name
|
||||
type: char*
|
||||
callconv: C
|
||||
- function:
|
||||
name: OTInetSysInfo
|
||||
return: OSStatus
|
||||
args:
|
||||
- name: ref
|
||||
type: InetSvcRef
|
||||
- name: name
|
||||
type: char*
|
||||
- name: sysinfo
|
||||
type: InetSysInfo*
|
||||
callconv: C
|
||||
- function:
|
||||
name: OTInetMailExchange
|
||||
return: OSStatus
|
||||
args:
|
||||
- name: ref
|
||||
type: InetSvcRef
|
||||
- name: name
|
||||
type: char*
|
||||
- name: num
|
||||
type: UInt16*
|
||||
- name: mx
|
||||
type: InetMailExchange*
|
||||
callconv: C
|
||||
- function:
|
||||
name: OTInetQuery
|
||||
return: OSStatus
|
||||
args:
|
||||
- name: ref
|
||||
type: InetSvcRef
|
||||
- name: name
|
||||
type: char*
|
||||
- name: qClass
|
||||
type: UInt16
|
||||
- name: qType
|
||||
type: UInt16
|
||||
- name: buf
|
||||
type: char*
|
||||
- name: buflen
|
||||
type: OTByteCount
|
||||
- name: argv
|
||||
type: void**
|
||||
- name: argvlen
|
||||
type: OTByteCount
|
||||
- name: requestFlags
|
||||
type: OTFlags
|
||||
callconv: C
|
||||
- function:
|
||||
name: OTInitInetAddress
|
||||
args:
|
||||
- name: addr
|
||||
type: InetAddress*
|
||||
- name: port
|
||||
type: InetPort
|
||||
- name: host
|
||||
type: InetHost
|
||||
callconv: C
|
||||
- function:
|
||||
name: OTInitDNSAddress
|
||||
return: OTByteCount
|
||||
args:
|
||||
- name: addr
|
||||
type: DNSAddress*
|
||||
- name: str
|
||||
type: char*
|
||||
callconv: C
|
||||
+127
@@ -0,0 +1,127 @@
|
||||
# Shared Library Manager (ASLM)
|
||||
|
||||
The Apple Shared Library Manager (ASLM) loads shared libraries on 68k
|
||||
Macintosh computers. Open Transport's 68k libraries are ASLM
|
||||
libraries. The SDK has a small C interface to the client side of ASLM,
|
||||
in `LibraryManager.h`. The C library (`runtime/libc/aslm.c`) has the
|
||||
calls.
|
||||
|
||||
There is no ASLM on PowerPC. On PowerPC, shared libraries are Code
|
||||
Fragment Manager fragments, and the SDK links to them directly.
|
||||
|
||||
## What the SDK has
|
||||
|
||||
| Name | Kind | What it does |
|
||||
| --- | --- | --- |
|
||||
| `InitLibraryManager` | Apple call | Starts the program's use of ASLM. |
|
||||
| `CleanupLibraryManager` | Apple call | Ends the program's use of ASLM. The C library calls it when the program ends. |
|
||||
| `ASLMPresent` | SDK call | Gives `true` when ASLM is installed. Loads ASLM when it is installed but not loaded. |
|
||||
| `ASLMLoadFunctionSet` | SDK call | Loads the library that has a function set. |
|
||||
| `ASLMCallC` | SDK call | Calls a function of the MPW C calling convention. |
|
||||
| `ASLMCallPascal` | SDK call | Calls a Pascal function. |
|
||||
| `ASLM_FUNCTION_SET` | SDK macro | Makes the record that names a function set. |
|
||||
| `ASLM_FUNCTION` | SDK macro | Makes a stub for one function of a function set. |
|
||||
|
||||
Apple's own client header for ASLM is C++, and Apple's LibraryBuilder
|
||||
tool made the stubs from an export file. The SDK does not have these.
|
||||
The macros do the work of LibraryBuilder for a C program.
|
||||
|
||||
## Requirements
|
||||
|
||||
- A 68k Macintosh with ASLM installed. Open Transport on 68k installs
|
||||
ASLM. Other software also installs it as the `Shared Library
|
||||
Manager` extension.
|
||||
- Without ASLM, `InitLibraryManager` gives `kASLMNotPresentErr`
|
||||
(-3132), and each stub gives the same value.
|
||||
|
||||
## How to call a function of a library
|
||||
|
||||
1. Make the record of the function set. Give the identifier of the set,
|
||||
the version that you want and the oldest version that you accept.
|
||||
2. Make a stub for each function. The index is the number of the
|
||||
function in the export file of the library.
|
||||
3. Call `InitLibraryManager`, then `ASLMLoadFunctionSet`.
|
||||
4. Call each stub through `ASLMCallC` or `ASLMCallPascal`. The first
|
||||
call binds the stub through ASLM. The next calls go directly to the
|
||||
function.
|
||||
|
||||
Example (a function of Open Transport's 68k utilities library):
|
||||
|
||||
```c
|
||||
#include <LibraryManager.h>
|
||||
|
||||
ASLM_FUNCTION_SET(utils, "OTClnt$LclUtils", 0x0100, 0x0100);
|
||||
ASLM_FUNCTION(my_free_mem, utils, 31); /* OTFreeMem */
|
||||
extern const char my_free_mem[];
|
||||
|
||||
void free_block(void *p) {
|
||||
long args[1];
|
||||
args[0] = (long)p;
|
||||
ASLMCallC(my_free_mem, 1, args);
|
||||
}
|
||||
|
||||
int start(void) {
|
||||
if (InitLibraryManager(kASLMDefaultPoolSize, kASLMDefaultZone,
|
||||
kASLMDefaultMemory) != noErr)
|
||||
return 0;
|
||||
return ASLMLoadFunctionSet("OTClnt$LclUtils") == noErr;
|
||||
}
|
||||
```
|
||||
|
||||
## Calling conventions
|
||||
|
||||
Do not call a stub directly from C. Use `ASLMCallC` or
|
||||
`ASLMCallPascal`, for these reasons:
|
||||
|
||||
- MPW code can change register D2. Clang keeps a value in D2 across a
|
||||
call.
|
||||
- An MPW C function gives a pointer result in D0. Clang reads a pointer
|
||||
result from A0.
|
||||
|
||||
`ASLMCallC` pushes the arguments from right to left, as MPW C does,
|
||||
and gives the value of D0. Each argument is 4 bytes.
|
||||
|
||||
`ASLMCallPascal` reserves space for the result, then pushes the
|
||||
arguments from left to right. Set bit `i` of `wordMask` when argument
|
||||
`i` is 2 bytes (a `short` or a `Boolean`). Give `resultSize` as 0, 2 or
|
||||
4. A `Boolean` result is in bits 8 to 15 of the result. A `Boolean`
|
||||
argument is 2 bytes, with the value in bits 8 to 15 (pass `0x100` for
|
||||
`true`).
|
||||
|
||||
## Open Transport on 68k
|
||||
|
||||
The C library uses this interface for Open Transport on 68k. When
|
||||
ASLM and Open Transport are installed, `InitOpenTransport` starts
|
||||
Apple's 68k Open Transport libraries through ASLM. Otherwise it uses
|
||||
the SDK's Open Transport over MacTCP. See
|
||||
[Open Transport and MacTCP](opentransport.md).
|
||||
|
||||
## Limits
|
||||
|
||||
- The SDK has the client side only. A program cannot export a
|
||||
function set or be an ASLM library.
|
||||
- The SDK does not have the C++ class interfaces of ASLM (for example
|
||||
`TLibraryManager` or class sets).
|
||||
|
||||
## How the SDK found the interface
|
||||
|
||||
The SDK's interface comes from a study of how the 68k code of Open
|
||||
Transport 1.3 calls ASLM. No Apple header text is in the SDK. The data
|
||||
that the study found:
|
||||
|
||||
- ASLM's global record is at offset `0x10C` of the `ExpandMem` record.
|
||||
- The library manager object is at offset `0x10` of the global record.
|
||||
It is zero when ASLM is not loaded. The routine at offset `0x64`
|
||||
loads ASLM.
|
||||
- The objects use the MPW C++ object layout. The function at offset
|
||||
`0x9C` of the manager's table starts a client. The function at
|
||||
offset `0x40` of the client's table loads a function set.
|
||||
- The binder at offset `0x88` of the global record binds a stub. A0
|
||||
holds the stub's slot, and D0 holds the client.
|
||||
|
||||
These runs passed:
|
||||
|
||||
| Program | System | Machine | Result |
|
||||
| --- | --- | --- | --- |
|
||||
| `tests/ot.c` (68k, native Open Transport through ASLM) | Mac OS 8.1, Open Transport 1.3 | QEMU `q800` | all ok |
|
||||
| `examples/net/fetch.c` (68k) | Mac OS 8.1 | QEMU `q800` | Both requests got `200 OK` |
|
||||
+1
-1
@@ -8,7 +8,7 @@ The ROM's InterfaceLib exports 2493 symbols. The headers declare 2490 of them (1
|
||||
|
||||
## 68k
|
||||
|
||||
- 65 declared calls have no 68k trap and need glue code on 68k (listed in `include/needs-glue.txt`). Most are Mac OS 9 calls that never ran on 68k: the HFS Plus API, Navigation Services, Driver Services and the Name Registry.
|
||||
- 194 declared calls have no 68k trap and need glue code on 68k (listed in `include/needs-glue.txt`). The C library supplies 129 of them: Open Transport, the MacTCP name resolver and the Shared Library Manager client. Most of the others are Mac OS 9 calls that never ran on 68k: the HFS Plus API, Navigation Services, Driver Services and the Name Registry.
|
||||
- The ROM's PowerPC glue describes 1575 68k calls. Checked against it: 1960 calls match the ROM, 0 differ, 233 implemented in C glue or not declared.
|
||||
|
||||
## Not declared yet
|
||||
|
||||
+11
-2
@@ -2,7 +2,10 @@
|
||||
|
||||
The C library has BSD sockets and pipes for 68k and PowerPC. Programs
|
||||
from Unix can use them without changes. The code is in
|
||||
`runtime/libc/socket.c`, `netdb.c`, `unix.c` and `pipe.c`.
|
||||
`runtime/libc/socket.c`, `netdb.c`, `dnr.c`, `unix.c` and `pipe.c`.
|
||||
|
||||
For the Open Transport and MacTCP interfaces, see
|
||||
[Open Transport and MacTCP](opentransport.md).
|
||||
|
||||
## Summary
|
||||
|
||||
@@ -25,7 +28,8 @@ from Unix can use them without changes. The code is in
|
||||
Toolbox, the calls fail with `EAFNOSUPPORT`.
|
||||
- Names need the MacTCP resolver (`dnrp` resource of MacTCP or of the
|
||||
TCP/IP control panel). Without it, only numbers, `localhost` and the
|
||||
name of the computer resolve.
|
||||
name of the computer resolve. `runtime/libc/dnr.c` loads the
|
||||
resolver; `AddressXlation.h` declares its calls.
|
||||
|
||||
## Sockets
|
||||
|
||||
@@ -107,3 +111,8 @@ named pipes. `tests/run.sh` runs it in `tools/sim68k.py --os` and
|
||||
`tools/simppc.py`. Their fake MacTCP uses the network of the host
|
||||
(loopback), and their fake PPC Toolbox connects ports in the
|
||||
simulator.
|
||||
|
||||
`examples/net/fetch.c` gets a web page with BSD sockets (and with Open
|
||||
Transport). It ran on Mac OS 8.1 (68k, QEMU `q800`) and Mac OS 9.2.1
|
||||
(PowerPC, QEMU `mac99`) with `tools/qemu/nettest.py`. Names resolved
|
||||
through the MacTCP resolver of Open Transport on both systems.
|
||||
@@ -0,0 +1,199 @@
|
||||
# Open Transport and MacTCP
|
||||
|
||||
The SDK has the Open Transport client interface and the MacTCP
|
||||
interface for 68k and PowerPC. A program can use either interface, or
|
||||
the BSD sockets of the C library (see [Networking and pipes](network.md)).
|
||||
This page tells what each interface does, which systems it runs on and
|
||||
how to test it.
|
||||
|
||||
## Summary
|
||||
|
||||
| Interface | Headers | 68k | PowerPC |
|
||||
| --- | --- | --- | --- |
|
||||
| Open Transport | `OpenTransport.h`, `OpenTransportProviders.h` (also `OpenTptInternet.h`) | Apple's 68k Open Transport libraries (through ASLM), else the C library over MacTCP | Mac OS's Open Transport libraries |
|
||||
| MacTCP | `MacTCP.h` (TCP and UDP parameter blocks) | The `.IPP` driver | The `.IPP` driver |
|
||||
| Name resolver | `AddressXlation.h` | The C library, over the `dnrp` resource | The C library, over the `dnrp` resource |
|
||||
| BSD sockets | `sys/socket.h`, `netdb.h` | The C library, over MacTCP | The C library, over MacTCP |
|
||||
|
||||
## Requirements
|
||||
|
||||
- Open Transport on PowerPC needs Open Transport 1.1 or later (Mac OS
|
||||
7.5.2 to 9.2.2). The SDK imports `OTClientLib`, `OTClientUtilLib`,
|
||||
`OTUtilityLib` and `OTInetClientLib` weakly. Without Open Transport,
|
||||
the program starts, and `InitOpenTransport` gives `kOTNotFoundErr`.
|
||||
- Open Transport on 68k uses Apple's 68k Open Transport libraries when
|
||||
Open Transport and the Shared Library Manager (ASLM) are installed.
|
||||
Otherwise it needs the `.IPP` driver of MacTCP (System 7). Without
|
||||
either, `InitOpenTransport` gives `kOTNotFoundErr`.
|
||||
- The MacTCP calls need the `.IPP` driver on both processors.
|
||||
- Names need the resolver: the `dnrp` resource of MacTCP or of the
|
||||
TCP/IP control panel. Without the resolver, only dotted addresses
|
||||
resolve.
|
||||
|
||||
## Open Transport on PowerPC
|
||||
|
||||
The calls go to Mac OS's Open Transport. `runtime/libc/ot.c` gives the
|
||||
calls that Apple's `OpenTransportAppPPC.o` and `OpenTptInetPPC.o`
|
||||
supplied:
|
||||
|
||||
- `InitOpenTransport`, `InitOpenTransportUtilities` and
|
||||
`CloseOpenTransport`.
|
||||
- `OTOpenEndpoint`, `OTAsyncOpenEndpoint`, `OTOpenInternetServices`,
|
||||
`OTAsyncOpenInternetServices` and `OTCloseProvider`.
|
||||
- `OTAllocMem`, `OTAlloc`, `OTRegisterAsClient`,
|
||||
`OTUnregisterAsClient`, `OTCreateDeferredTask` and
|
||||
`OTCreateSystemTask`.
|
||||
|
||||
Open Transport exports these calls only in a private form, with one
|
||||
more argument: the address of the program's client record. `ot.c` keeps
|
||||
this record. Apple's `ExitToShell` patch of Open Transport closes the
|
||||
program's providers when the program quits.
|
||||
|
||||
All other calls (for example `OTBind`, `OTSnd`, `OTRcv`, `OTLook`,
|
||||
`OTInetStringToAddress`) go directly to the Open Transport libraries.
|
||||
|
||||
## Open Transport on 68k
|
||||
|
||||
On 68k, the C library has two forms of each Open Transport call:
|
||||
|
||||
- The native form (`runtime/libc/otnative.c`) calls Apple's 68k Open
|
||||
Transport libraries through the Apple Shared Library Manager (ASLM).
|
||||
See [Shared Library Manager (ASLM)](aslm.md).
|
||||
- The MacTCP form (`runtime/libc/ot68k.c`) gives the calls itself. It
|
||||
uses the BSD sockets of the C library (MacTCP's `.IPP` driver) and
|
||||
the name resolver.
|
||||
|
||||
`InitOpenTransport` selects the form. When the `otan` Gestalt selector
|
||||
is present and ASLM is installed, it starts the native libraries.
|
||||
When that fails, it starts the MacTCP form. The program uses the same
|
||||
calls with each form. `runtime/libc/ot68k-names.h` lists the calls that
|
||||
have two forms.
|
||||
|
||||
Differences of the native form:
|
||||
|
||||
- `OTInetGetInterfaceInfo` and `OTInetGetSecondaryAddresses` always
|
||||
use the MacTCP form. In the 68k library, these calls fail on Mac OS
|
||||
8.1.
|
||||
- `OTOpenInternetServices` changes `kDefaultInternetServicesPath` to
|
||||
the `dnr` configuration, because the 68k library does not accept
|
||||
it.
|
||||
|
||||
### The MacTCP form
|
||||
|
||||
These parts of the MacTCP form work:
|
||||
|
||||
- Endpoints of the `tcp` and `udp` configurations: `OTBind` (with
|
||||
`qlen` for a listener), `OTConnect`, `OTRcvConnect`, `OTListen`,
|
||||
`OTAccept`, `OTSnd`, `OTRcv`, `OTSndUData`, `OTRcvUData`,
|
||||
`OTSndOrderlyDisconnect`, `OTRcvOrderlyDisconnect`,
|
||||
`OTSndDisconnect`, `OTRcvDisconnect`, `OTUnbind`, `OTLook`,
|
||||
`OTCountDataBytes`, `OTGetEndpointState`, `OTGetEndpointInfo` and
|
||||
`OTGetProtAddress`.
|
||||
- Synchronous and asynchronous mode, blocking and nonblocking mode,
|
||||
notifiers and completion events (`T_OPENCOMPLETE`, `T_BINDCOMPLETE`,
|
||||
`T_ACCEPTCOMPLETE`, ...), and the events of `OTLook` (`T_LISTEN`,
|
||||
`T_CONNECT`, `T_DATA`, `T_ORDREL`, `T_DISCONNECT`).
|
||||
- The Internet services: `OTInetStringToHost`, `OTInetHostToString`,
|
||||
`OTInetGetInterfaceInfo`, `OTInetStringToAddress`,
|
||||
`OTInetAddressToName`, `OTInetSysInfo` and `OTInetMailExchange`.
|
||||
- The utilities: memory, strings, lists, time stamps, atomic
|
||||
operations, and deferred and system tasks.
|
||||
|
||||
Differences of the MacTCP form from Open Transport:
|
||||
|
||||
- A notifier runs when the program calls `OTIdle`, and while a
|
||||
synchronous blocking call waits. A notifier never runs at interrupt
|
||||
time. A program in asynchronous mode must call `OTIdle` in its event
|
||||
loop.
|
||||
- A deferred task and a system task run at the next `OTIdle`.
|
||||
- Only `tcp`, `udp` and `dnr` configurations open. Other names (for
|
||||
example `ddp` or `rawip`) give `kOTBadConfigurationErr`.
|
||||
- `OTOptionManagement` accepts the options and gives them back without
|
||||
a change. `OTIoctl` and `OTInetQuery` give `kOTNotSupportedErr`.
|
||||
- `OTInetGetInterfaceInfo` gives the address, the net mask of the
|
||||
address class and the broadcast address. It does not give the
|
||||
gateway or the name server.
|
||||
|
||||
## Starting state of an endpoint
|
||||
|
||||
An endpoint starts in synchronous, nonblocking mode, as in Open
|
||||
Transport. Call `OTSetBlocking` to make the calls wait.
|
||||
|
||||
On Mac OS 9.2.1, a blocking `OTRcv` in a program that does not let
|
||||
other programs run can wait for ever, also when data is there. Use
|
||||
nonblocking mode and a loop with `OTIdle` and `EventAvail` or
|
||||
`WaitNextEvent`. `examples/net/fetch.c` shows this loop.
|
||||
|
||||
## MacTCP
|
||||
|
||||
`MacTCP.h` has the TCP and UDP parameter blocks (`TCPiopb`, `UDPiopb`)
|
||||
and their control codes. Send them to the `.IPP` driver with
|
||||
`PBControl`. The C library's sockets use these calls.
|
||||
|
||||
`AddressXlation.h` has the name resolver: `OpenResolver`,
|
||||
`CloseResolver`, `StrToAddr`, `AddrToStr`, `AddrToName`, `EnumCache`,
|
||||
`HInfo` and `MXInfo`. The C library (`runtime/libc/dnr.c`) loads the
|
||||
`dnrp` resource from the MacTCP or TCP/IP control panel, or from the
|
||||
System file, and calls it. On PowerPC it calls the resource through the
|
||||
Mixed Mode Manager. `OpenResolver` makes `CloseResolver` run when the
|
||||
program ends.
|
||||
|
||||
The resolver gives its result in the low word of `D0`. Open Transport's
|
||||
resolver puts other bits in the high word. The library uses only the
|
||||
low word.
|
||||
|
||||
## Sample
|
||||
|
||||
`examples/net/fetch.c` gets a web page twice: once with Open Transport
|
||||
and once with BSD sockets. It shows the first line of each reply in a
|
||||
console window. The same source builds for 68k and PowerPC:
|
||||
|
||||
```sh
|
||||
python3 tools/macapp.py --console window -o Fetch.bin -- examples/net/fetch.c
|
||||
```
|
||||
|
||||
## Tests
|
||||
|
||||
- `tests/ot.c` checks the utilities, the Internet services, a TCP
|
||||
connection between three endpoints of one program (listener, client
|
||||
and worker), a UDP datagram and an asynchronous endpoint with a
|
||||
notifier. It prints one `ok` line for each check, then `all ok`.
|
||||
- `tests/run.sh` runs `tests/ot.c` for 68k in `tools/sim68k.py --os`.
|
||||
The simulator has no ASLM, so the test uses the MacTCP form. The fake
|
||||
MacTCP of the simulator uses the loopback network of the host.
|
||||
- On 68k, `tests/ot.c` prints a `note` line that tells which form it
|
||||
uses.
|
||||
- `tools/qemu/nettest.py` runs a program on Mac OS in QEMU. It puts the
|
||||
program in the Startup Items folder of a copy of the disk, starts a
|
||||
report server (port 7009) and a web server (port 8080) on the host,
|
||||
boots QEMU and collects the report. The guest finds the host at
|
||||
10.0.2.2.
|
||||
|
||||
These runs passed:
|
||||
|
||||
| Program | System | Machine | Result |
|
||||
| --- | --- | --- | --- |
|
||||
| `tests/ot.c` (68k, native form) | Mac OS 8.1, Open Transport 1.3 | QEMU `q800` | all ok |
|
||||
| `tests/ot.c` (PowerPC) | Mac OS 9.2.1 install CD | QEMU `mac99` | all ok |
|
||||
| `examples/net/fetch.c` (68k, native form) | Mac OS 8.1 | QEMU `q800` | Both requests got `200 OK` |
|
||||
| `examples/net/fetch.c` (PowerPC) | Mac OS 9.2.1 | QEMU `mac99` | Both requests got `200 OK` |
|
||||
|
||||
Example commands:
|
||||
|
||||
```sh
|
||||
python3 tools/macapp.py --cpu ppc -o ot-ppc.bin -- tests/ot.c
|
||||
python3 tools/qemu/nettest.py --machine mac99 --image "Mac OS 9.2.1.iso" ot-ppc.bin
|
||||
|
||||
python3 tools/macapp.py --cpu 68k -o ot-68k.bin -- tests/ot.c
|
||||
python3 tools/qemu/nettest.py --machine q800 --rom q800.rom --image hd81.qcow2 ot-68k.bin
|
||||
```
|
||||
|
||||
The `q800` machine needs a Quadra 800 ROM image and a disk with Mac OS
|
||||
installed. The SDK cannot supply them.
|
||||
|
||||
## Not done yet
|
||||
|
||||
- A test of the native form on System 7.5 with Open Transport 1.1.
|
||||
- AppleTalk, serial and raw IP endpoints.
|
||||
- An Open Transport path for the BSD sockets on PowerPC. The sockets use
|
||||
MacTCP's `.IPP` driver, which Open Transport supplies.
|
||||
@@ -0,0 +1,189 @@
|
||||
/* Fetch: gets a web page twice, once with Open Transport and once with
|
||||
* BSD sockets, and shows the first line of each reply in a console
|
||||
* window. It builds for 68k and PowerPC from this one source.
|
||||
*
|
||||
* On PowerPC the Open Transport calls go to Mac OS's Open Transport. On
|
||||
* 68k they go to Apple's 68k Open Transport through the Shared Library
|
||||
* Manager, or to the SDK's Open Transport over MacTCP. The socket calls
|
||||
* use MacTCP's driver on both, which Open Transport also supplies. So
|
||||
* the program runs on System 7 with MacTCP and on Mac OS 7.6 to 9 with
|
||||
* Open Transport.
|
||||
*
|
||||
* python3 tools/macapp.py --console window -o Fetch.bin -- examples/net/fetch.c
|
||||
*
|
||||
* Define FETCH_HOST and FETCH_PORT to get a page from another server
|
||||
* (tools/qemu/nettest.py uses the QEMU host, 10.0.2.2).
|
||||
*
|
||||
* Copyright (C) clang-retro contributors.
|
||||
* SPDX-License-Identifier: AGPL-3.0-only */
|
||||
#include <netdb.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <unistd.h>
|
||||
#include <Events.h>
|
||||
#include <OpenTransport.h>
|
||||
#include <OpenTransportProviders.h>
|
||||
|
||||
#ifndef FETCH_HOST
|
||||
#define FETCH_HOST "example.com"
|
||||
#endif
|
||||
#ifndef FETCH_PORT
|
||||
#define FETCH_PORT 80
|
||||
#endif
|
||||
#define WAIT_TICKS (60UL * 20) /* the longest wait for a reply: 20 seconds */
|
||||
|
||||
static char reply[4096]; /* the start of a reply */
|
||||
|
||||
/* Makes the request, with a User-Agent that names the interface. Gives
|
||||
its length. */
|
||||
static int request(char *buf, size_t size, const char *api) {
|
||||
return snprintf(buf, size,
|
||||
"GET / HTTP/1.0\r\nHost: %s\r\nUser-Agent: clang-retro-fetch (%s)\r\n"
|
||||
"Connection: close\r\n\r\n",
|
||||
FETCH_HOST, api);
|
||||
}
|
||||
|
||||
/* Shows the first line of a reply of n bytes (total bytes in all). */
|
||||
static void show(const char *api, long n, long total) {
|
||||
char *end;
|
||||
if (n <= 0) {
|
||||
printf("%s: no reply\n", api);
|
||||
return;
|
||||
}
|
||||
reply[n < (long)sizeof reply ? n : (long)sizeof reply - 1] = 0;
|
||||
end = strpbrk(reply, "\r\n");
|
||||
if (end)
|
||||
*end = 0;
|
||||
printf("%s: %s (%ld bytes)\n", api, reply, total);
|
||||
}
|
||||
|
||||
/* Lets the other programs run for a moment, and lets Open Transport's
|
||||
notifiers run on 68k. */
|
||||
static void pause_a_moment(void) {
|
||||
EventRecord ev;
|
||||
OTIdle();
|
||||
EventAvail(0, &ev);
|
||||
}
|
||||
|
||||
/* Gets the page with Open Transport. The endpoint is synchronous and
|
||||
nonblocking: the program waits in its own loop and lets other
|
||||
programs run. */
|
||||
static void fetch_ot(void) {
|
||||
OSStatus err;
|
||||
InetSvcRef svc;
|
||||
InetHostInfo host;
|
||||
EndpointRef ep;
|
||||
InetAddress addr;
|
||||
TCall call;
|
||||
OTFlags flags;
|
||||
OTResult n;
|
||||
long got = 0;
|
||||
unsigned long until;
|
||||
char req[256];
|
||||
if (InitOpenTransport() != kOTNoError) {
|
||||
printf("Open Transport: not here\n");
|
||||
return;
|
||||
}
|
||||
svc = OTOpenInternetServices(kDefaultInternetServicesPath, 0, &err);
|
||||
if (err != kOTNoError) {
|
||||
printf("Open Transport: no Internet services (%ld)\n", (long)err);
|
||||
return;
|
||||
}
|
||||
err = OTInetStringToAddress(svc, (char *)FETCH_HOST, &host);
|
||||
OTCloseProvider(svc);
|
||||
if (err != kOTNoError) {
|
||||
printf("Open Transport: cannot find %s (%ld)\n", FETCH_HOST, (long)err);
|
||||
return;
|
||||
}
|
||||
ep = OTOpenEndpoint(OTCreateConfiguration(kTCPName), 0, NULL, &err);
|
||||
if (err != kOTNoError) {
|
||||
printf("Open Transport: no TCP endpoint (%ld)\n", (long)err);
|
||||
return;
|
||||
}
|
||||
OTSetBlocking(ep);
|
||||
err = OTBind(ep, NULL, NULL);
|
||||
if (err == kOTNoError) {
|
||||
OTInitInetAddress(&addr, FETCH_PORT, host.addrs[0]);
|
||||
memset(&call, 0, sizeof call);
|
||||
call.addr.buf = (UInt8 *)&addr;
|
||||
call.addr.len = sizeof addr;
|
||||
err = OTConnect(ep, &call, NULL);
|
||||
}
|
||||
if (err == kOTNoError) {
|
||||
int len = request(req, sizeof req, "Open Transport");
|
||||
if (OTSnd(ep, req, len, 0) != len)
|
||||
err = kOTLookErr;
|
||||
}
|
||||
if (err != kOTNoError) {
|
||||
printf("Open Transport: cannot connect (%ld)\n", (long)err);
|
||||
OTCloseProvider(ep);
|
||||
return;
|
||||
}
|
||||
/* Read until the server closes the connection. */
|
||||
OTSetNonBlocking(ep);
|
||||
until = TickCount() + WAIT_TICKS;
|
||||
for (;;) {
|
||||
char buf[512];
|
||||
n = OTRcv(ep, buf, sizeof buf, &flags);
|
||||
if (n > 0) {
|
||||
if (got < (long)sizeof reply - 1)
|
||||
memcpy(reply + got, buf, (size_t)n < sizeof reply - 1 - got ? (size_t)n : sizeof reply - 1 - got);
|
||||
got += n;
|
||||
} else if (n == kOTNoDataErr && TickCount() < until) {
|
||||
pause_a_moment();
|
||||
} else {
|
||||
if (n == kOTLookErr && OTLook(ep) == T_ORDREL)
|
||||
OTRcvOrderlyDisconnect(ep);
|
||||
break;
|
||||
}
|
||||
}
|
||||
show("Open Transport", got < (long)sizeof reply ? got : (long)sizeof reply - 1, got);
|
||||
OTCloseProvider(ep);
|
||||
}
|
||||
|
||||
/* Gets the page with BSD sockets. */
|
||||
static void fetch_sockets(void) {
|
||||
struct hostent *h = gethostbyname(FETCH_HOST);
|
||||
struct sockaddr_in sin;
|
||||
char req[256];
|
||||
long got = 0, n;
|
||||
int fd, len;
|
||||
if (!h) {
|
||||
printf("Sockets: cannot find %s\n", FETCH_HOST);
|
||||
return;
|
||||
}
|
||||
fd = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if (fd < 0) {
|
||||
printf("Sockets: no socket\n");
|
||||
return;
|
||||
}
|
||||
memset(&sin, 0, sizeof sin);
|
||||
sin.sin_family = AF_INET;
|
||||
sin.sin_port = htons(FETCH_PORT);
|
||||
memcpy(&sin.sin_addr, h->h_addr_list[0], sizeof sin.sin_addr);
|
||||
len = request(req, sizeof req, "BSD sockets");
|
||||
if (connect(fd, (struct sockaddr *)&sin, sizeof sin) < 0 || send(fd, req, len, 0) != len) {
|
||||
printf("Sockets: cannot connect\n");
|
||||
close(fd);
|
||||
return;
|
||||
}
|
||||
/* recv waits and lets other programs run meanwhile. */
|
||||
while ((n = recv(fd, reply + got, sizeof reply - 1 - got, 0)) > 0) {
|
||||
got += n;
|
||||
if (got >= (long)sizeof reply - 1)
|
||||
break;
|
||||
}
|
||||
show("BSD sockets", got, got);
|
||||
close(fd);
|
||||
}
|
||||
|
||||
/* Gets the page both ways. */
|
||||
int main(void) {
|
||||
printf("Fetching http://%s:%d/\n", FETCH_HOST, FETCH_PORT);
|
||||
fetch_ot();
|
||||
fetch_sockets();
|
||||
CloseOpenTransport();
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
/* AddressXlation.h: generated by tools/gen-headers.py. */
|
||||
#include "Multiverse.h"
|
||||
#include "mv/AddressXlation.h"
|
||||
@@ -0,0 +1,3 @@
|
||||
/* LibraryManager.h: generated by tools/gen-headers.py. */
|
||||
#include "Multiverse.h"
|
||||
#include "mv/LibraryManager.h"
|
||||
@@ -0,0 +1,2 @@
|
||||
/* MacTCP.h: generated by tools/gen-headers.py. */
|
||||
#include "Multiverse.h"
|
||||
@@ -19,6 +19,7 @@
|
||||
#include "mv/DeviceMgr.h"
|
||||
#include "mv/AppleTalk.h"
|
||||
#include "mv/ADSP.h"
|
||||
#include "mv/MacTCP.h"
|
||||
#include "mv/CQuickDraw.h"
|
||||
#include "mv/NotifyMgr.h"
|
||||
#include "mv/AppleEvents.h"
|
||||
@@ -66,7 +67,6 @@
|
||||
#include "mv/Keychain.h"
|
||||
#include "mv/LowMem.h"
|
||||
#include "mv/MIDI.h"
|
||||
#include "mv/MacTCP.h"
|
||||
#include "mv/MixedMode.h"
|
||||
#include "mv/Multiprocessing.h"
|
||||
#include "mv/NameRegistry.h"
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
/* OpenTptInternet.h: generated by tools/gen-headers.py. */
|
||||
#include "Multiverse.h"
|
||||
#include "mv/OpenTransportProviders.h"
|
||||
@@ -0,0 +1,3 @@
|
||||
/* OpenTransport.h: generated by tools/gen-headers.py. */
|
||||
#include "Multiverse.h"
|
||||
#include "mv/OpenTransport.h"
|
||||
@@ -0,0 +1,3 @@
|
||||
/* OpenTransportProviders.h: generated by tools/gen-headers.py. */
|
||||
#include "Multiverse.h"
|
||||
#include "mv/OpenTransportProviders.h"
|
||||
@@ -0,0 +1,171 @@
|
||||
/* AddressXlation.h: generated by tools/gen-headers.py from defs/AddressXlation.yaml. Do not edit. */
|
||||
#ifndef __MV_ADDRESSXLATION__
|
||||
#define __MV_ADDRESSXLATION__
|
||||
|
||||
#include "../ConditionalMacros.h"
|
||||
#include "MacTCP.h"
|
||||
#include "MacTypes.h"
|
||||
|
||||
#pragma options align=mac68k
|
||||
/* The headers' own inline code may call newer calls behind a
|
||||
check; the MAC_MIN_SYSTEM warnings are for the program's calls. */
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wuser-defined-warnings"
|
||||
|
||||
/* The Toolbox calls are C functions, also in C++. */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
enum {
|
||||
NUM_ALT_ADDRS = 4, /* The most addresses that one hostInfo record holds. */
|
||||
};
|
||||
|
||||
// The result of StrToAddr and AddrToName. cname is a C string
|
||||
// (the resolver ends a domain name with a dot).
|
||||
typedef struct hostInfo hostInfo;
|
||||
struct hostInfo {
|
||||
long rtnCode;
|
||||
char cname[255];
|
||||
unsigned long addr[4];
|
||||
};
|
||||
|
||||
// Resource record types of the domain name system.
|
||||
typedef enum {
|
||||
A = 1,
|
||||
NS = 2,
|
||||
CNAME = 5,
|
||||
HINFO = 13,
|
||||
MX = 15,
|
||||
lastClass = 32767,
|
||||
} AddrClasses;
|
||||
|
||||
// A host information record: CPU and system names (C strings).
|
||||
typedef struct HInfoRec HInfoRec;
|
||||
struct HInfoRec {
|
||||
char cpuType[30];
|
||||
char osType[30];
|
||||
};
|
||||
|
||||
// A mail exchange record.
|
||||
typedef struct MXRec MXRec;
|
||||
struct MXRec {
|
||||
uint16_t preference;
|
||||
char exchange[255];
|
||||
};
|
||||
|
||||
typedef union returnRecData returnRecData;
|
||||
union returnRecData {
|
||||
unsigned long addr[4];
|
||||
HInfoRec hinfo;
|
||||
MXRec mx;
|
||||
};
|
||||
|
||||
// The result of HInfo and MXInfo.
|
||||
typedef struct returnRec returnRec;
|
||||
struct returnRec {
|
||||
long rtnCode;
|
||||
char cname[255];
|
||||
returnRecData rdata;
|
||||
};
|
||||
|
||||
typedef union cacheEntryRecordData cacheEntryRecordData;
|
||||
union cacheEntryRecordData {
|
||||
char *name;
|
||||
ip_addr addr;
|
||||
};
|
||||
|
||||
// One entry of the resolver's cache, which EnumCache gives.
|
||||
typedef struct cacheEntryRecord cacheEntryRecord;
|
||||
struct cacheEntryRecord {
|
||||
char *cname;
|
||||
uint16_t type;
|
||||
uint16_t cacheClass;
|
||||
unsigned long ttl;
|
||||
cacheEntryRecordData rdata;
|
||||
};
|
||||
|
||||
// Called when StrToAddr or AddrToName ends. Pascal convention,
|
||||
// at interrupt level.
|
||||
typedef pascal void (*ResultProcPtr)(hostInfo *hostInfoPtr, char *userDataPtr);
|
||||
#if TARGET_RT_MAC_CFM
|
||||
typedef UniversalProcPtr ResultUPP;
|
||||
enum { uppResultProcInfo = 0x000003C0 };
|
||||
#define NewResultUPP(proc) ((ResultUPP)NewRoutineDescriptor((ProcPtr)(proc), uppResultProcInfo, GetCurrentArchitecture()))
|
||||
#define DisposeResultUPP(upp) DisposeRoutineDescriptor((UniversalProcPtr)(upp))
|
||||
#else
|
||||
typedef ResultProcPtr ResultUPP;
|
||||
#define NewResultUPP(proc) (proc)
|
||||
#define DisposeResultUPP(upp) ((void)0)
|
||||
#endif
|
||||
#define NewResultProc(proc) NewResultUPP(proc)
|
||||
#define DisposeResultProc(proc) DisposeResultUPP(proc)
|
||||
|
||||
// Called when HInfo or MXInfo ends. Pascal convention, at
|
||||
// interrupt level.
|
||||
typedef pascal void (*ResultProc2ProcPtr)(returnRec *returnRecPtr, char *userDataPtr);
|
||||
#if TARGET_RT_MAC_CFM
|
||||
typedef UniversalProcPtr ResultProc2UPP;
|
||||
enum { uppResultProc2ProcInfo = 0x000003C0 };
|
||||
#define NewResultProc2UPP(proc) ((ResultProc2UPP)NewRoutineDescriptor((ProcPtr)(proc), uppResultProc2ProcInfo, GetCurrentArchitecture()))
|
||||
#define DisposeResultProc2UPP(upp) DisposeRoutineDescriptor((UniversalProcPtr)(upp))
|
||||
#else
|
||||
typedef ResultProc2ProcPtr ResultProc2UPP;
|
||||
#define NewResultProc2UPP(proc) (proc)
|
||||
#define DisposeResultProc2UPP(upp) ((void)0)
|
||||
#endif
|
||||
#define NewResultProc2Proc(proc) NewResultProc2UPP(proc)
|
||||
#define DisposeResultProc2Proc(proc) DisposeResultProc2UPP(proc)
|
||||
|
||||
// Called by EnumCache once for each cache entry. Pascal
|
||||
// convention.
|
||||
typedef pascal void (*EnumResultProcPtr)(cacheEntryRecord *cacheEntryRecordPtr, char *userDataPtr);
|
||||
#if TARGET_RT_MAC_CFM
|
||||
typedef UniversalProcPtr EnumResultUPP;
|
||||
enum { uppEnumResultProcInfo = 0x000003C0 };
|
||||
#define NewEnumResultUPP(proc) ((EnumResultUPP)NewRoutineDescriptor((ProcPtr)(proc), uppEnumResultProcInfo, GetCurrentArchitecture()))
|
||||
#define DisposeEnumResultUPP(upp) DisposeRoutineDescriptor((UniversalProcPtr)(upp))
|
||||
#else
|
||||
typedef EnumResultProcPtr EnumResultUPP;
|
||||
#define NewEnumResultUPP(proc) (proc)
|
||||
#define DisposeEnumResultUPP(upp) ((void)0)
|
||||
#endif
|
||||
#define NewEnumResultProc(proc) NewEnumResultUPP(proc)
|
||||
#define DisposeEnumResultProc(proc) DisposeEnumResultUPP(proc)
|
||||
|
||||
// Loads and opens the resolver. fileName is ignored (pass NULL):
|
||||
// the library finds the resolver in the MacTCP control panel or
|
||||
// in the System file.
|
||||
OSErr OpenResolver(char *fileName) MAC_IMPORT(OpenResolver);
|
||||
|
||||
// Closes the resolver.
|
||||
OSErr CloseResolver(void) MAC_IMPORT(CloseResolver);
|
||||
|
||||
// Finds the addresses of a host name or a dotted number. Gives
|
||||
// noErr when the answer is ready now, cacheFault when the result
|
||||
// procedure will get it, or an error.
|
||||
OSErr StrToAddr(char *hostName, hostInfo *rtnStruct, ResultUPP resultproc, char *userDataPtr) MAC_IMPORT(StrToAddr);
|
||||
|
||||
// Writes an address as a dotted number (C string, 16 bytes).
|
||||
OSErr AddrToStr(unsigned long addr, char *addrStr) MAC_IMPORT(AddrToStr);
|
||||
|
||||
// Calls resultproc for each entry of the resolver's cache.
|
||||
OSErr EnumCache(EnumResultUPP resultproc, char *userDataPtr) MAC_IMPORT(EnumCache);
|
||||
|
||||
// Finds the name of an address. Results as for StrToAddr.
|
||||
OSErr AddrToName(ip_addr addr, hostInfo *rtnStruct, ResultUPP resultproc, char *userDataPtr) MAC_IMPORT(AddrToName);
|
||||
|
||||
// Finds the host information record of a name.
|
||||
OSErr HInfo(char *hostName, returnRec *returnRecPtr, ResultProc2UPP resultProc, char *userDataPtr) MAC_IMPORT(HInfo);
|
||||
|
||||
// Finds the mail exchange record of a name.
|
||||
OSErr MXInfo(char *hostName, returnRec *returnRecPtr, ResultProc2UPP resultProc, char *userDataPtr) MAC_IMPORT(MXInfo);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#pragma clang diagnostic pop
|
||||
#pragma options align=reset
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,104 @@
|
||||
/* LibraryManager.h: generated by tools/gen-headers.py from defs/LibraryManager.yaml. Do not edit. */
|
||||
#ifndef __MV_LIBRARYMANAGER__
|
||||
#define __MV_LIBRARYMANAGER__
|
||||
|
||||
#include "../ConditionalMacros.h"
|
||||
#include "MacTypes.h"
|
||||
|
||||
#pragma options align=mac68k
|
||||
/* The headers' own inline code may call newer calls behind a
|
||||
check; the MAC_MIN_SYSTEM warnings are for the program's calls. */
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wuser-defined-warnings"
|
||||
|
||||
/* The Toolbox calls are C functions, also in C++. */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if TARGET_CPU_68K
|
||||
#include <stddef.h>
|
||||
|
||||
/* The result code of Apple's glue when ASLM is not installed (the
|
||||
name is the SDK's). */
|
||||
enum { kASLMNotPresentErr = -3132 };
|
||||
|
||||
/* The zone and the memory kind that InitLibraryManager takes.
|
||||
Open Transport's glue passes 1 for both; the SDK uses its values
|
||||
as the defaults. */
|
||||
enum { kASLMDefaultPoolSize = 1024, kASLMDefaultZone = 1, kASLMDefaultMemory = 1 };
|
||||
|
||||
/* The record that names a function set. ASLM keeps its own data in
|
||||
reserved. version is the version that the client wants, and
|
||||
minVersion the oldest version that it accepts. The record must
|
||||
be writable. */
|
||||
#define ASLM_FUNCTION_SET(var, idString, ver, minVer) \
|
||||
struct { long reserved[3]; unsigned short version, minVersion; \
|
||||
char id[sizeof(idString)]; } var \
|
||||
__attribute__((aligned(2))) = { {0, 0, 0}, (ver), (minVer), idString }
|
||||
|
||||
/* The slot of one stub: ASLM puts the address of the function in
|
||||
fn when the stub binds for the first time. */
|
||||
typedef struct ASLMStubSlot {
|
||||
void *fn;
|
||||
void *set;
|
||||
long reserved;
|
||||
short index;
|
||||
} __attribute__((packed, aligned(2))) ASLMStubSlot;
|
||||
|
||||
/* Makes a stub with the name sym for the function number index of
|
||||
the function set var. Declare sym as an array of char, and call
|
||||
it with ASLMCallC (a C function of MPW) or ASLMCallPascal (a
|
||||
Pascal function). Do not call it directly from C: MPW code can
|
||||
change register D2, which clang keeps across a call, and gives a
|
||||
pointer result in D0, where clang expects A0. The first call
|
||||
binds the stub through ASLM; the next calls go directly to the
|
||||
function. Call InitLibraryManager before the first call. */
|
||||
#define ASLM_FUNCTION(sym, var, index) \
|
||||
ASLMStubSlot sym##__aslm_slot __attribute__((used)) = { 0, &(var), 0, (index) }; \
|
||||
__asm__(".text\n\t.globl " #sym "\n\t.p2align 1\n" #sym ":\n" \
|
||||
"\tlea " #sym "__aslm_slot, %a0\n\tmove.l (%a0), %d0\n" \
|
||||
"\tbeq 1f\n\tmove.l %d0, %a0\n\tjmp (%a0)\n1:\tjmp __aslm_bind\n")
|
||||
|
||||
#endif
|
||||
|
||||
// Starts the program's use of ASLM (68k only). poolSize is the
|
||||
// size of the memory pool that ASLM makes for the program. zoneType
|
||||
// and memType select where the pool comes from: use the
|
||||
// kASLMDefault values. Gives noErr, or kASLMNotPresentErr when ASLM
|
||||
// is not installed. The C library calls CleanupLibraryManager when
|
||||
// the program ends.
|
||||
OSErr InitLibraryManager(size_t poolSize, int zoneType, int memType) MAC_IMPORT(InitLibraryManager);
|
||||
|
||||
// Ends the program's use of ASLM and unloads its libraries.
|
||||
void CleanupLibraryManager(void) MAC_IMPORT(CleanupLibraryManager);
|
||||
|
||||
// Gives true when ASLM is installed (SDK name).
|
||||
Boolean ASLMPresent(void) MAC_IMPORT(ASLMPresent);
|
||||
|
||||
// Loads the library that has the function set id (for example
|
||||
// "OTClnt$LclUtils"), so that the stubs of the set can bind. Gives
|
||||
// noErr or an ASLM error (SDK name).
|
||||
OSErr ASLMLoadFunctionSet(const char *id) MAC_IMPORT(ASLMLoadFunctionSet);
|
||||
|
||||
// Calls fn, a function of the MPW C calling convention, with nargs
|
||||
// 4-byte arguments: args[0] is the first. Gives the value of D0 (a
|
||||
// pointer result too). Keeps all the registers that clang keeps
|
||||
// (SDK name).
|
||||
long ASLMCallC(const void *fn, int nargs, const long *args) MAC_IMPORT(ASLMCallC);
|
||||
|
||||
// Calls the Pascal function fn with nargs arguments: args[0] is the
|
||||
// first. Bit i of wordMask is 1 when argument i is a 2-byte value (a
|
||||
// short or a Boolean); else the argument is 4 bytes. resultSize is
|
||||
// 0, 2 or 4: the size of the result. Gives the result. A Boolean
|
||||
// result is in bits 8 to 15 (SDK name).
|
||||
long ASLMCallPascal(const void *fn, int nargs, unsigned long wordMask, int resultSize, const long *args) MAC_IMPORT(ASLMCallPascal);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#pragma clang diagnostic pop
|
||||
#pragma options align=reset
|
||||
|
||||
#endif
|
||||
@@ -325,6 +325,107 @@ struct GetAddrParamBlock {
|
||||
ip_addr ourNetMask;
|
||||
};
|
||||
|
||||
// Event codes that MacTCP gives to a UDP notification routine.
|
||||
typedef enum {
|
||||
UDPDataArrival = 1,
|
||||
UDPICMPReceived = 2,
|
||||
} UDPEventCode;
|
||||
|
||||
// UDP notification routine (ASR). Pascal convention. MacTCP
|
||||
// calls it at interrupt level.
|
||||
typedef pascal void (*UDPNotifyProcPtr)(StreamPtr udpStream, uint16_t eventCode, Ptr userDataPtr, ICMPReport *icmpMsg);
|
||||
#if TARGET_RT_MAC_CFM
|
||||
typedef UniversalProcPtr UDPNotifyUPP;
|
||||
enum { uppUDPNotifyProcInfo = 0x00003EC0 };
|
||||
#define NewUDPNotifyUPP(proc) ((UDPNotifyUPP)NewRoutineDescriptor((ProcPtr)(proc), uppUDPNotifyProcInfo, GetCurrentArchitecture()))
|
||||
#define DisposeUDPNotifyUPP(upp) DisposeRoutineDescriptor((UniversalProcPtr)(upp))
|
||||
#else
|
||||
typedef UDPNotifyProcPtr UDPNotifyUPP;
|
||||
#define NewUDPNotifyUPP(proc) (proc)
|
||||
#define DisposeUDPNotifyUPP(upp) ((void)0)
|
||||
#endif
|
||||
#define NewUDPNotifyProc(proc) NewUDPNotifyUPP(proc)
|
||||
#define DisposeUDPNotifyProc(proc) DisposeUDPNotifyUPP(proc)
|
||||
|
||||
// udpCreate and udpMultiCreate. localPort 0 asks MacTCP for a
|
||||
// free port; MacTCP puts the port it used here.
|
||||
typedef struct UDPCreatePB UDPCreatePB;
|
||||
struct UDPCreatePB {
|
||||
Ptr rcvBuff;
|
||||
unsigned long rcvBuffLen;
|
||||
UDPNotifyUPP notifyProc;
|
||||
uint16_t localPort;
|
||||
Ptr userDataPtr;
|
||||
uint16_t endingPort;
|
||||
};
|
||||
|
||||
// udpWrite. wdsPtr points to a wdsEntry list that ends with a
|
||||
// zero length.
|
||||
typedef struct UDPSendPB UDPSendPB;
|
||||
struct UDPSendPB {
|
||||
uint16_t reserved;
|
||||
ip_addr remoteHost;
|
||||
uint16_t remotePort;
|
||||
Ptr wdsPtr;
|
||||
Boolean checkSum;
|
||||
uint16_t sendLength;
|
||||
Ptr userDataPtr;
|
||||
uint16_t localPort;
|
||||
};
|
||||
|
||||
// udpRead and udpBfrReturn. MacTCP gives rcvBuff and rcvBuffLen;
|
||||
// return the buffer with udpBfrReturn. timeOut is in seconds
|
||||
// (0: wait without a limit).
|
||||
typedef struct UDPReceivePB UDPReceivePB;
|
||||
struct UDPReceivePB {
|
||||
uint16_t timeOut;
|
||||
ip_addr remoteHost;
|
||||
uint16_t remotePort;
|
||||
Ptr rcvBuff;
|
||||
uint16_t rcvBuffLen;
|
||||
uint16_t secondTimeStamp;
|
||||
Ptr userDataPtr;
|
||||
ip_addr destHost;
|
||||
uint16_t destPort;
|
||||
};
|
||||
|
||||
// udpMaxMTUSize: the largest datagram to remoteHost.
|
||||
typedef struct UDPMTUPB UDPMTUPB;
|
||||
struct UDPMTUPB {
|
||||
uint16_t mtuSize;
|
||||
ip_addr remoteHost;
|
||||
Ptr userDataPtr;
|
||||
};
|
||||
|
||||
typedef union UDPcsParam UDPcsParam;
|
||||
union UDPcsParam {
|
||||
UDPMTUPB mtu;
|
||||
UDPCreatePB create;
|
||||
UDPSendPB send;
|
||||
UDPReceivePB receive;
|
||||
};
|
||||
|
||||
// The UDP I/O parameter block passed to PBControl on the .IPP
|
||||
// driver. The header is the same as in TCPiopb: udpStream 28,
|
||||
// csParam 32.
|
||||
typedef struct UDPiopb UDPiopb;
|
||||
struct UDPiopb {
|
||||
QElemPtr qLink;
|
||||
INTEGER qType;
|
||||
INTEGER ioTrap;
|
||||
Ptr ioCmdAddr;
|
||||
ProcPtr ioCompletion;
|
||||
OSErr ioResult;
|
||||
StringPtr ioNamePtr;
|
||||
INTEGER ioVRefNum;
|
||||
INTEGER ioCRefNum;
|
||||
INTEGER csCode;
|
||||
StreamPtr udpStream;
|
||||
UDPcsParam csParam;
|
||||
};
|
||||
|
||||
typedef UDPiopb *UDPiopbPtr;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,768 @@
|
||||
/* OpenTransport.h: generated by tools/gen-headers.py from defs/OpenTransport.yaml. Do not edit. */
|
||||
#ifndef __MV_OPENTRANSPORT__
|
||||
#define __MV_OPENTRANSPORT__
|
||||
|
||||
#include "../ConditionalMacros.h"
|
||||
#include "DriverServices.h"
|
||||
#include "MacTypes.h"
|
||||
|
||||
#pragma options align=mac68k
|
||||
/* The headers' own inline code may call newer calls behind a
|
||||
check; the MAC_MIN_SYSTEM warnings are for the program's calls. */
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wuser-defined-warnings"
|
||||
|
||||
/* The Toolbox calls are C functions, also in C++. */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Open Transport: the client calls of the Open Transport networking
|
||||
system (System 7.5 to Mac OS 9). Records use PowerPC (natural)
|
||||
alignment, as in Apple's headers, on both CPUs. */
|
||||
|
||||
typedef UInt32 OTTimeout;
|
||||
|
||||
typedef SInt32 OTSequence;
|
||||
|
||||
typedef SInt32 OTNameID;
|
||||
|
||||
typedef SInt32 OTReason;
|
||||
|
||||
typedef UInt32 OTQLen;
|
||||
|
||||
typedef UInt8 *OTClientName;
|
||||
|
||||
typedef SInt32 OTCommand;
|
||||
|
||||
typedef UInt32 OTOpenFlags;
|
||||
|
||||
typedef UInt16 OTUnitDataFlags;
|
||||
|
||||
typedef UInt32 OTFlags;
|
||||
|
||||
typedef UInt8 OTBand;
|
||||
|
||||
typedef SInt32 OTResult;
|
||||
|
||||
typedef UInt32 OTEventCode;
|
||||
|
||||
typedef UInt32 OTByteCount;
|
||||
|
||||
typedef UInt32 OTItemCount;
|
||||
|
||||
typedef SInt32 OTInt32;
|
||||
|
||||
typedef UInt32 OTUInt32;
|
||||
|
||||
typedef UInt8 OTUInt8Param;
|
||||
|
||||
typedef UInt16 OTUInt16Param;
|
||||
|
||||
typedef SInt32 OTDataSize;
|
||||
|
||||
typedef UInt32 OTServiceType;
|
||||
|
||||
typedef UInt32 OTStructType;
|
||||
|
||||
typedef UInt32 OTFieldsType;
|
||||
|
||||
typedef UInt32 OTXTILevel;
|
||||
|
||||
typedef UInt32 OTXTIName;
|
||||
|
||||
typedef UInt32 OTXTIStates;
|
||||
|
||||
typedef UInt16 OTAddressType;
|
||||
|
||||
typedef UInt32 OTPortRef;
|
||||
|
||||
typedef UnsignedWide OTTimeStamp;
|
||||
|
||||
typedef UInt32 OTInitializationFlags;
|
||||
|
||||
typedef long OTDeferredTaskRef;
|
||||
|
||||
typedef long OTSystemTaskRef;
|
||||
|
||||
// An open provider. kOTInvalidProviderRef (NULL) is none.
|
||||
typedef struct OpaqueProviderRef *ProviderRef;
|
||||
|
||||
// An open endpoint. All provider calls take it.
|
||||
typedef ProviderRef EndpointRef;
|
||||
|
||||
// An open mapper. All provider calls take it.
|
||||
typedef ProviderRef MapperRef;
|
||||
|
||||
// A configuration that OTCreateConfiguration makes, which an open call takes
|
||||
// (and frees).
|
||||
typedef struct OpaqueOTConfigurationRef *OTConfigurationRef;
|
||||
|
||||
typedef struct OpaqueOTClientContextPtr *OTClientContextPtr;
|
||||
|
||||
enum {
|
||||
kOTInvalidRef = 0,
|
||||
kOTInvalidProviderRef = 0,
|
||||
kOTInvalidEndpointRef = 0,
|
||||
kOTInvalidMapperRef = 0,
|
||||
};
|
||||
|
||||
// A notifier: Open Transport calls it with the events of a provider.
|
||||
// PowerPC Open Transport calls it directly (not through Mixed Mode), so
|
||||
// NewOTNotifyUPP gives the function itself on both CPUs.
|
||||
typedef pascal void (*OTNotifyProcPtr)(void *contextPtr, OTEventCode code, OTResult result, void *cookie);
|
||||
typedef OTNotifyProcPtr OTNotifyUPP;
|
||||
#define NewOTNotifyUPP(proc) ((OTNotifyUPP)(proc))
|
||||
#define DisposeOTNotifyUPP(upp) ((void)0)
|
||||
#define NewOTNotifyProc(proc) NewOTNotifyUPP(proc)
|
||||
#define DisposeOTNotifyProc(proc) DisposeOTNotifyUPP(proc)
|
||||
|
||||
// A deferred task or system task procedure.
|
||||
typedef void (*OTProcessUPP)(void *arg);
|
||||
|
||||
#define NewOTProcessUPP(proc) ((OTProcessUPP)(proc))
|
||||
#define DisposeOTProcessUPP(upp) ((void)0)
|
||||
|
||||
// Result codes. The XTI errors are -3150 to -3180; the
|
||||
// Unix-style errors start at -3200.
|
||||
enum {
|
||||
kOTNoError = 0,
|
||||
kOTOutOfMemoryErr = -3211,
|
||||
kOTNotFoundErr = -3201,
|
||||
kOTDuplicateFoundErr = -3216,
|
||||
kOTBadAddressErr = -3150,
|
||||
kOTBadOptionErr = -3151,
|
||||
kOTAccessErr = -3152,
|
||||
kOTBadReferenceErr = -3153,
|
||||
kOTNoAddressErr = -3154,
|
||||
kOTOutStateErr = -3155,
|
||||
kOTBadSequenceErr = -3156,
|
||||
kOTSysErrorErr = -3157,
|
||||
kOTLookErr = -3158,
|
||||
kOTBadDataErr = -3159,
|
||||
kOTBufferOverflowErr = -3160,
|
||||
kOTFlowErr = -3161,
|
||||
kOTNoDataErr = -3162,
|
||||
kOTNoDisconnectErr = -3163,
|
||||
kOTNoUDErrErr = -3164,
|
||||
kOTBadFlagErr = -3165,
|
||||
kOTNoReleaseErr = -3166,
|
||||
kOTNotSupportedErr = -3167,
|
||||
kOTStateChangeErr = -3168,
|
||||
kOTNoStructureTypeErr = -3169,
|
||||
kOTBadNameErr = -3170,
|
||||
kOTBadQLenErr = -3171,
|
||||
kOTAddressBusyErr = -3172,
|
||||
kOTIndOutErr = -3173,
|
||||
kOTProviderMismatchErr = -3174,
|
||||
kOTResQLenErr = -3175,
|
||||
kOTResAddressErr = -3176,
|
||||
kOTQFullErr = -3177,
|
||||
kOTProtocolErr = -3178,
|
||||
kOTBadSyncErr = -3179,
|
||||
kOTCanceledErr = -3180,
|
||||
kEPERMErr = -3200,
|
||||
kENOENTErr = -3201,
|
||||
kENORSRCErr = -3202,
|
||||
kEINTRErr = -3203,
|
||||
kEIOErr = -3204,
|
||||
kENXIOErr = -3205,
|
||||
kEBADFErr = -3208,
|
||||
kEAGAINErr = -3210,
|
||||
kENOMEMErr = -3211,
|
||||
kEACCESErr = -3212,
|
||||
kEFAULTErr = -3213,
|
||||
kEBUSYErr = -3215,
|
||||
kEEXISTErr = -3216,
|
||||
kENODEVErr = -3218,
|
||||
kEINVALErr = -3221,
|
||||
kENOTTYErr = -3224,
|
||||
kEPIPEErr = -3231,
|
||||
kERANGEErr = -3233,
|
||||
kEWOULDBLOCKErr = -3234,
|
||||
kEALREADYErr = -3236,
|
||||
kENOTSOCKErr = -3237,
|
||||
kEDESTADDRREQErr = -3238,
|
||||
kEMSGSIZEErr = -3239,
|
||||
kEPROTOTYPEErr = -3240,
|
||||
kENOPROTOOPTErr = -3241,
|
||||
kEPROTONOSUPPORTErr = -3242,
|
||||
kESOCKTNOSUPPORTErr = -3243,
|
||||
kEOPNOTSUPPErr = -3244,
|
||||
kEADDRINUSEErr = -3247,
|
||||
kEADDRNOTAVAILErr = -3248,
|
||||
kENETDOWNErr = -3249,
|
||||
kENETUNREACHErr = -3250,
|
||||
kENETRESETErr = -3251,
|
||||
kECONNABORTEDErr = -3252,
|
||||
kECONNRESETErr = -3253,
|
||||
kENOBUFSErr = -3254,
|
||||
kEISCONNErr = -3255,
|
||||
kENOTCONNErr = -3256,
|
||||
kESHUTDOWNErr = -3257,
|
||||
kETOOMANYREFSErr = -3258,
|
||||
kETIMEDOUTErr = -3259,
|
||||
kECONNREFUSEDErr = -3260,
|
||||
kEHOSTDOWNErr = -3263,
|
||||
kEHOSTUNREACHErr = -3264,
|
||||
kEPROTOErr = -3269,
|
||||
kETIMEErr = -3270,
|
||||
kENOSRErr = -3271,
|
||||
kEBADMSGErr = -3272,
|
||||
kECANCELErr = -3273,
|
||||
kENOSTRErr = -3274,
|
||||
kENODATAErr = -3275,
|
||||
kEINPROGRESSErr = -3276,
|
||||
kESRCHErr = -3277,
|
||||
kENOMSGErr = -3278,
|
||||
kOTClientNotInittedErr = -3279,
|
||||
kOTPortHasDiedErr = -3280,
|
||||
kOTPortWasEjectedErr = -3281,
|
||||
kOTBadConfigurationErr = -3282,
|
||||
kOTConfigurationChangedErr = -3283,
|
||||
kOTUserRequestedErr = -3284,
|
||||
kOTPortLostConnection = -3285,
|
||||
};
|
||||
|
||||
// Event codes that a notifier gets (OTEventCode) and that OTLook gives.
|
||||
enum {
|
||||
T_LISTEN = 1,
|
||||
T_CONNECT = 2,
|
||||
T_DATA = 4,
|
||||
T_EXDATA = 8,
|
||||
T_DISCONNECT = 16,
|
||||
T_ERROR = 32,
|
||||
T_UDERR = 64,
|
||||
T_ORDREL = 128,
|
||||
T_GODATA = 256,
|
||||
T_GOEXDATA = 512,
|
||||
T_REQUEST = 1024,
|
||||
T_REPLY = 2048,
|
||||
T_PASSCON = 4096,
|
||||
T_RESET = 8192,
|
||||
kPRIVATEEVENT = 268435456,
|
||||
kCOMPLETEEVENT = 536870912,
|
||||
T_BINDCOMPLETE = 536870913,
|
||||
T_UNBINDCOMPLETE = 536870914,
|
||||
T_ACCEPTCOMPLETE = 536870915,
|
||||
T_REPLYCOMPLETE = 536870916,
|
||||
T_DISCONNECTCOMPLETE = 536870917,
|
||||
T_OPTMGMTCOMPLETE = 536870918,
|
||||
T_OPENCOMPLETE = 536870919,
|
||||
T_GETPROTADDRCOMPLETE = 536870920,
|
||||
T_RESOLVEADDRCOMPLETE = 536870921,
|
||||
T_GETINFOCOMPLETE = 536870922,
|
||||
T_SYNCCOMPLETE = 536870923,
|
||||
T_MEMORYRELEASED = 536870924,
|
||||
T_REGNAMECOMPLETE = 536870925,
|
||||
T_DELNAMECOMPLETE = 536870926,
|
||||
T_LKUPNAMECOMPLETE = 536870927,
|
||||
T_LKUPNAMERESULT = 536870928,
|
||||
kOTSyncIdleEvent = 536870929,
|
||||
kSTREAMEVENT = 553648128,
|
||||
kOTProviderWillClose = 603979777,
|
||||
kOTProviderIsClosed = 603979778,
|
||||
};
|
||||
|
||||
// Endpoint states (OTGetEndpointState).
|
||||
enum {
|
||||
T_UNINIT = 0,
|
||||
T_UNBND = 1,
|
||||
T_IDLE = 2,
|
||||
T_OUTCON = 3,
|
||||
T_INCON = 4,
|
||||
T_DATAXFER = 5,
|
||||
T_OUTREL = 6,
|
||||
T_INREL = 7,
|
||||
};
|
||||
|
||||
// Data flags (OTFlags) of OTSnd and OTRcv.
|
||||
enum {
|
||||
T_MORE = 1,
|
||||
T_EXPEDITED = 2,
|
||||
T_ACKNOWLEDGED = 4,
|
||||
T_PARTIALDATA = 8,
|
||||
T_NORECEIPT = 16,
|
||||
T_TIMEDOUT = 32,
|
||||
};
|
||||
|
||||
// Option management flags and option status values.
|
||||
enum {
|
||||
T_NEGOTIATE = 4,
|
||||
T_CHECK = 8,
|
||||
T_DEFAULT = 16,
|
||||
T_CURRENT = 128,
|
||||
T_SUCCESS = 32,
|
||||
T_FAILURE = 64,
|
||||
T_PARTSUCCESS = 256,
|
||||
T_READONLY = 512,
|
||||
T_NOTSUPPORT = 1024,
|
||||
};
|
||||
|
||||
// Service types (TEndpointInfo.servtype).
|
||||
enum {
|
||||
T_COTS = 1,
|
||||
T_COTS_ORD = 2,
|
||||
T_CLTS = 3,
|
||||
T_TRANS = 5,
|
||||
T_TRANS_ORD = 6,
|
||||
T_TRANS_CLTS = 7,
|
||||
};
|
||||
|
||||
// TEndpointInfo.flags.
|
||||
enum {
|
||||
T_SENDZERO = 1,
|
||||
T_XPG4_1 = 2,
|
||||
};
|
||||
|
||||
// Sizes in TEndpointInfo: no limit, or not supported.
|
||||
enum {
|
||||
T_INFINITE = -1,
|
||||
T_INVALID = -2,
|
||||
};
|
||||
|
||||
// Record types for OTAlloc and OTFree.
|
||||
enum {
|
||||
T_BIND = 1,
|
||||
T_OPTMGMT = 2,
|
||||
T_CALL = 3,
|
||||
T_DIS = 4,
|
||||
T_UNITDATA = 5,
|
||||
T_UDERROR = 6,
|
||||
T_INFO = 7,
|
||||
T_REPLYDATA = 8,
|
||||
T_REQUESTDATA = 9,
|
||||
T_UNITREQUEST = 10,
|
||||
T_UNITREPLY = 11,
|
||||
};
|
||||
|
||||
// The buffers that OTAlloc makes.
|
||||
enum {
|
||||
T_ADDR = 1,
|
||||
T_OPT = 2,
|
||||
T_UDATA = 4,
|
||||
T_ALL = 65535,
|
||||
};
|
||||
|
||||
// Option levels, names and sizes.
|
||||
enum {
|
||||
XTI_GENERIC = 65535,
|
||||
XTI_DEBUG = 1,
|
||||
XTI_LINGER = 128,
|
||||
XTI_RCVBUF = 4098,
|
||||
XTI_RCVLOWAT = 4100,
|
||||
XTI_SNDBUF = 4097,
|
||||
XTI_SNDLOWAT = 4099,
|
||||
XTI_PROTOTYPE = 4101,
|
||||
OPT_CHECKSUM = 1536,
|
||||
OPT_RETRYCNT = 1537,
|
||||
OPT_INTERVAL = 1538,
|
||||
OPT_ENABLEEOM = 1539,
|
||||
OPT_SELFSEND = 1540,
|
||||
OPT_SERVERSTATUS = 1541,
|
||||
OPT_ALERTENABLE = 1542,
|
||||
OPT_KEEPALIVE = 8,
|
||||
T_YES = 1,
|
||||
T_NO = 0,
|
||||
T_UNUSED = -1,
|
||||
kOTOptionHeaderSize = 16,
|
||||
kOTBooleanOptionDataSize = 4,
|
||||
kOTBooleanOptionSize = 20,
|
||||
kOTOneByteOptionSize = 17,
|
||||
kOTTwoByteOptionSize = 18,
|
||||
kOTFourByteOptionSize = 20,
|
||||
};
|
||||
|
||||
enum {
|
||||
kInitOTForApplicationMask = 1,
|
||||
kInitOTForExtensionMask = 2,
|
||||
};
|
||||
|
||||
// Bits of Gestalt('otan') (gestaltOpenTpt).
|
||||
enum {
|
||||
gestaltOpenTptPresentMask = 1,
|
||||
gestaltOpenTptLoadedMask = 2,
|
||||
gestaltOpenTptAppleTalkPresentMask = 4,
|
||||
gestaltOpenTptAppleTalkLoadedMask = 8,
|
||||
gestaltOpenTptTCPPresentMask = 16,
|
||||
gestaltOpenTptTCPLoadedMask = 32,
|
||||
gestaltOpenTptIPXSPXPresentMask = 64,
|
||||
gestaltOpenTptIPXSPXLoadedMask = 128,
|
||||
gestaltOpenTptVersions = 'otvr',
|
||||
};
|
||||
|
||||
#define kNetbufDataIsOTData (~(UInt32)1)
|
||||
|
||||
#define kOTNetbufDataIsOTData kNetbufDataIsOTData
|
||||
|
||||
// A buffer: maxlen bytes at buf, of which len are used.
|
||||
typedef struct TNetbuf TNetbuf;
|
||||
#pragma options align=power
|
||||
struct TNetbuf {
|
||||
OTByteCount maxlen;
|
||||
OTByteCount len;
|
||||
UInt8 *buf;
|
||||
};
|
||||
#pragma options align=reset
|
||||
|
||||
// One part of a gather list (a TNetbuf whose len is kNetbufDataIsOTData).
|
||||
typedef struct OTData OTData;
|
||||
#pragma options align=power
|
||||
struct OTData {
|
||||
void *fNext;
|
||||
void *fData;
|
||||
OTByteCount fLen;
|
||||
};
|
||||
#pragma options align=reset
|
||||
|
||||
// The start of every address record.
|
||||
typedef struct OTAddress OTAddress;
|
||||
#pragma options align=power
|
||||
struct OTAddress {
|
||||
OTAddressType fAddressType;
|
||||
UInt8 fAddress[1];
|
||||
};
|
||||
#pragma options align=reset
|
||||
|
||||
// An address to bind, and the most connections that wait (qlen).
|
||||
typedef struct TBind TBind;
|
||||
#pragma options align=power
|
||||
struct TBind {
|
||||
TNetbuf addr;
|
||||
OTQLen qlen;
|
||||
};
|
||||
#pragma options align=reset
|
||||
|
||||
typedef struct TDiscon TDiscon;
|
||||
#pragma options align=power
|
||||
struct TDiscon {
|
||||
TNetbuf udata;
|
||||
OTReason reason;
|
||||
OTSequence sequence;
|
||||
};
|
||||
#pragma options align=reset
|
||||
|
||||
// A connection request or a connection: address, options, data.
|
||||
typedef struct TCall TCall;
|
||||
#pragma options align=power
|
||||
struct TCall {
|
||||
TNetbuf addr;
|
||||
TNetbuf opt;
|
||||
TNetbuf udata;
|
||||
OTSequence sequence;
|
||||
};
|
||||
#pragma options align=reset
|
||||
|
||||
// A datagram: address, options, data.
|
||||
typedef struct TUnitData TUnitData;
|
||||
#pragma options align=power
|
||||
struct TUnitData {
|
||||
TNetbuf addr;
|
||||
TNetbuf opt;
|
||||
TNetbuf udata;
|
||||
};
|
||||
#pragma options align=reset
|
||||
|
||||
// The error of a datagram that was not sent.
|
||||
typedef struct TUDErr TUDErr;
|
||||
#pragma options align=power
|
||||
struct TUDErr {
|
||||
TNetbuf addr;
|
||||
TNetbuf opt;
|
||||
SInt32 error;
|
||||
};
|
||||
#pragma options align=reset
|
||||
|
||||
typedef struct TOptMgmt TOptMgmt;
|
||||
#pragma options align=power
|
||||
struct TOptMgmt {
|
||||
TNetbuf opt;
|
||||
OTFlags flags;
|
||||
};
|
||||
#pragma options align=reset
|
||||
|
||||
typedef struct TOptionHeader TOptionHeader;
|
||||
#pragma options align=power
|
||||
struct TOptionHeader {
|
||||
OTByteCount len;
|
||||
OTXTILevel level;
|
||||
OTXTIName name;
|
||||
UInt32 status;
|
||||
};
|
||||
#pragma options align=reset
|
||||
|
||||
typedef struct TOption TOption;
|
||||
#pragma options align=power
|
||||
struct TOption {
|
||||
OTByteCount len;
|
||||
OTXTILevel level;
|
||||
OTXTIName name;
|
||||
UInt32 status;
|
||||
UInt32 value[1];
|
||||
};
|
||||
#pragma options align=reset
|
||||
|
||||
// The limits of an endpoint, in bytes.
|
||||
typedef struct TEndpointInfo TEndpointInfo;
|
||||
#pragma options align=power
|
||||
struct TEndpointInfo {
|
||||
OTDataSize addr;
|
||||
OTDataSize options;
|
||||
OTDataSize tsdu;
|
||||
OTDataSize etsdu;
|
||||
OTDataSize connect;
|
||||
OTDataSize discon;
|
||||
OTServiceType servtype;
|
||||
UInt32 flags;
|
||||
};
|
||||
#pragma options align=reset
|
||||
|
||||
// A link of a list.
|
||||
typedef struct OTLink OTLink;
|
||||
#pragma options align=power
|
||||
struct OTLink {
|
||||
struct OTLink *fNext;
|
||||
};
|
||||
#pragma options align=reset
|
||||
|
||||
// A last-in, first-out list for interrupt-safe use.
|
||||
typedef struct OTLIFO OTLIFO;
|
||||
#pragma options align=power
|
||||
struct OTLIFO {
|
||||
OTLink *fHead;
|
||||
};
|
||||
#pragma options align=reset
|
||||
|
||||
// A list.
|
||||
typedef struct OTList OTList;
|
||||
#pragma options align=power
|
||||
struct OTList {
|
||||
OTLink *fHead;
|
||||
};
|
||||
#pragma options align=reset
|
||||
|
||||
// Starts Open Transport for the program. Call it before the other
|
||||
// calls; it gives kOTNotFoundErr when Open Transport is not there.
|
||||
OSStatus InitOpenTransport(void) MAC_IMPORT(InitOpenTransport);
|
||||
|
||||
// Starts the utility calls only (memory, lists, time).
|
||||
OSStatus InitOpenTransportUtilities(void) MAC_IMPORT(InitOpenTransportUtilities);
|
||||
|
||||
// Closes the program's providers and ends its use of Open Transport.
|
||||
// The SDK's library also calls it when the program ends.
|
||||
void CloseOpenTransport(void) MAC_IMPORT(CloseOpenTransport);
|
||||
|
||||
// Asks for the client events (port changes) of Open Transport.
|
||||
OSStatus OTRegisterAsClient(OTClientName name, OTNotifyUPP proc) MAC_IMPORT(OTRegisterAsClient);
|
||||
|
||||
OSStatus OTUnregisterAsClient(void) MAC_IMPORT(OTUnregisterAsClient);
|
||||
|
||||
// Allocates memory that a notifier may also allocate.
|
||||
void* OTAllocMem(OTByteCount size) MAC_IMPORT(OTAllocMem);
|
||||
|
||||
// Allocates a TBind, TCall, TUnitData or other record with buffers of
|
||||
// the endpoint's sizes. Free it with OTFree.
|
||||
void* OTAlloc(EndpointRef ref, OTStructType structType, OTFieldsType fields, OSStatus *err) MAC_IMPORT(OTAlloc);
|
||||
|
||||
// Opens an endpoint (synchronous). config comes from OTCreateConfiguration
|
||||
// (for example "tcp" or "udp") and is freed.
|
||||
EndpointRef OTOpenEndpoint(OTConfigurationRef config, OTOpenFlags oflag, TEndpointInfo *info, OSStatus *err) MAC_IMPORT(OTOpenEndpoint);
|
||||
|
||||
// Opens an endpoint; proc gets T_OPENCOMPLETE with the endpoint as cookie.
|
||||
OSStatus OTAsyncOpenEndpoint(OTConfigurationRef config, OTOpenFlags oflag, TEndpointInfo *info, OTNotifyUPP proc, void *contextPtr) MAC_IMPORT(OTAsyncOpenEndpoint);
|
||||
|
||||
// Closes an endpoint or other provider.
|
||||
OSStatus OTCloseProvider(ProviderRef ref) MAC_IMPORT(OTCloseProvider);
|
||||
|
||||
long OTCreateDeferredTask(OTProcessUPP proc, void *contextInfo) MAC_IMPORT(OTCreateDeferredTask);
|
||||
|
||||
long OTCreateSystemTask(OTProcessUPP proc, void *contextInfo) MAC_IMPORT(OTCreateSystemTask);
|
||||
|
||||
OSStatus OTSetSynchronous(ProviderRef ref) MAC_IMPORT(OTSetSynchronous);
|
||||
|
||||
OSStatus OTSetAsynchronous(ProviderRef ref) MAC_IMPORT(OTSetAsynchronous);
|
||||
|
||||
Boolean OTIsSynchronous(ProviderRef ref) MAC_IMPORT(OTIsSynchronous);
|
||||
|
||||
OSStatus OTSetBlocking(ProviderRef ref) MAC_IMPORT(OTSetBlocking);
|
||||
|
||||
OSStatus OTSetNonBlocking(ProviderRef ref) MAC_IMPORT(OTSetNonBlocking);
|
||||
|
||||
Boolean OTIsBlocking(ProviderRef ref) MAC_IMPORT(OTIsBlocking);
|
||||
|
||||
OSStatus OTInstallNotifier(ProviderRef ref, OTNotifyUPP proc, void *contextPtr) MAC_IMPORT(OTInstallNotifier);
|
||||
|
||||
void OTRemoveNotifier(ProviderRef ref) MAC_IMPORT(OTRemoveNotifier);
|
||||
|
||||
OSStatus OTUseSyncIdleEvents(ProviderRef ref, Boolean useEvents) MAC_IMPORT(OTUseSyncIdleEvents);
|
||||
|
||||
Boolean OTEnterNotifier(ProviderRef ref) MAC_IMPORT(OTEnterNotifier);
|
||||
|
||||
void OTLeaveNotifier(ProviderRef ref) MAC_IMPORT(OTLeaveNotifier);
|
||||
|
||||
OSStatus OTAckSends(ProviderRef ref) MAC_IMPORT(OTAckSends);
|
||||
|
||||
OSStatus OTDontAckSends(ProviderRef ref) MAC_IMPORT(OTDontAckSends);
|
||||
|
||||
Boolean OTIsAckingSends(ProviderRef ref) MAC_IMPORT(OTIsAckingSends);
|
||||
|
||||
OSStatus OTCancelSynchronousCalls(ProviderRef ref, OSStatus err) MAC_IMPORT(OTCancelSynchronousCalls);
|
||||
|
||||
SInt32 OTIoctl(ProviderRef ref, UInt32 cmd, void *data) MAC_IMPORT(OTIoctl);
|
||||
|
||||
OTPortRef OTGetProviderPortRef(ProviderRef ref) MAC_IMPORT(OTGetProviderPortRef);
|
||||
|
||||
OSStatus OTGetEndpointInfo(EndpointRef ref, TEndpointInfo *info) MAC_IMPORT(OTGetEndpointInfo);
|
||||
|
||||
OTResult OTGetEndpointState(EndpointRef ref) MAC_IMPORT(OTGetEndpointState);
|
||||
|
||||
OTResult OTLook(EndpointRef ref) MAC_IMPORT(OTLook);
|
||||
|
||||
OSStatus OTCountDataBytes(EndpointRef ref, OTByteCount *countPtr) MAC_IMPORT(OTCountDataBytes);
|
||||
|
||||
OSStatus OTGetProtAddress(EndpointRef ref, TBind *boundAddr, TBind *peerAddr) MAC_IMPORT(OTGetProtAddress);
|
||||
|
||||
OSStatus OTResolveAddress(EndpointRef ref, TBind *reqAddr, TBind *retAddr, OTTimeout timeOut) MAC_IMPORT(OTResolveAddress);
|
||||
|
||||
OTResult OTFree(void *ptr, OTStructType structType) MAC_IMPORT(OTFree);
|
||||
|
||||
OSStatus OTOptionManagement(EndpointRef ref, TOptMgmt *req, TOptMgmt *ret) MAC_IMPORT(OTOptionManagement);
|
||||
|
||||
OSStatus OTNextOption(UInt8 *buffer, UInt32 buflen, TOption **prevOptPtr) MAC_IMPORT(OTNextOption);
|
||||
|
||||
TOption* OTFindOption(UInt8 *buffer, UInt32 buflen, OTXTILevel level, OTXTIName name) MAC_IMPORT(OTFindOption);
|
||||
|
||||
OSStatus OTBind(EndpointRef ref, TBind *reqAddr, TBind *retAddr) MAC_IMPORT(OTBind);
|
||||
|
||||
OSStatus OTUnbind(EndpointRef ref) MAC_IMPORT(OTUnbind);
|
||||
|
||||
OSStatus OTConnect(EndpointRef ref, TCall *sndCall, TCall *rcvCall) MAC_IMPORT(OTConnect);
|
||||
|
||||
OSStatus OTRcvConnect(EndpointRef ref, TCall *call) MAC_IMPORT(OTRcvConnect);
|
||||
|
||||
OSStatus OTListen(EndpointRef ref, TCall *call) MAC_IMPORT(OTListen);
|
||||
|
||||
OSStatus OTAccept(EndpointRef listener, EndpointRef worker, TCall *call) MAC_IMPORT(OTAccept);
|
||||
|
||||
OSStatus OTSndDisconnect(EndpointRef ref, TCall *call) MAC_IMPORT(OTSndDisconnect);
|
||||
|
||||
OSStatus OTSndOrderlyDisconnect(EndpointRef ref) MAC_IMPORT(OTSndOrderlyDisconnect);
|
||||
|
||||
OSStatus OTRcvDisconnect(EndpointRef ref, TDiscon *discon) MAC_IMPORT(OTRcvDisconnect);
|
||||
|
||||
OSStatus OTRcvOrderlyDisconnect(EndpointRef ref) MAC_IMPORT(OTRcvOrderlyDisconnect);
|
||||
|
||||
OTResult OTRcv(EndpointRef ref, void *buf, OTByteCount nbytes, OTFlags *flags) MAC_IMPORT(OTRcv);
|
||||
|
||||
OTResult OTSnd(EndpointRef ref, void *buf, OTByteCount nbytes, OTFlags flags) MAC_IMPORT(OTSnd);
|
||||
|
||||
OSStatus OTSndUData(EndpointRef ref, TUnitData *udata) MAC_IMPORT(OTSndUData);
|
||||
|
||||
OSStatus OTRcvUData(EndpointRef ref, TUnitData *udata, OTFlags *flags) MAC_IMPORT(OTRcvUData);
|
||||
|
||||
OSStatus OTRcvUDErr(EndpointRef ref, TUDErr *uderr) MAC_IMPORT(OTRcvUDErr);
|
||||
|
||||
void OTIdle(void) MAC_IMPORT(OTIdle);
|
||||
|
||||
OSStatus OTDelay(UInt32 seconds) MAC_IMPORT(OTDelay);
|
||||
|
||||
OTConfigurationRef OTCreateConfiguration(const char *path) MAC_IMPORT(OTCreateConfiguration);
|
||||
|
||||
OTConfigurationRef OTCloneConfiguration(OTConfigurationRef cfig) MAC_IMPORT(OTCloneConfiguration);
|
||||
|
||||
void OTDestroyConfiguration(OTConfigurationRef cfig) MAC_IMPORT(OTDestroyConfiguration);
|
||||
|
||||
void OTFreeMem(void *mem) MAC_IMPORT(OTFreeMem);
|
||||
|
||||
void OTMemcpy(void *dest, const void *src, OTByteCount nBytes) MAC_IMPORT(OTMemcpy);
|
||||
|
||||
Boolean OTMemcmp(const void *mem1, const void *mem2, OTByteCount nBytes) MAC_IMPORT(OTMemcmp);
|
||||
|
||||
void OTMemmove(void *dest, const void *src, OTByteCount nBytes) MAC_IMPORT(OTMemmove);
|
||||
|
||||
void OTMemzero(void *dest, OTByteCount nBytes) MAC_IMPORT(OTMemzero);
|
||||
|
||||
void OTMemset(void *dest, OTUInt8Param toSet, OTByteCount nBytes) MAC_IMPORT(OTMemset);
|
||||
|
||||
OTByteCount OTStrLength(const char *str) MAC_IMPORT(OTStrLength);
|
||||
|
||||
void OTStrCopy(char *dest, const char *src) MAC_IMPORT(OTStrCopy);
|
||||
|
||||
void OTStrCat(char *dest, const char *src) MAC_IMPORT(OTStrCat);
|
||||
|
||||
Boolean OTStrEqual(const char *src1, const char *src2) MAC_IMPORT(OTStrEqual);
|
||||
|
||||
void OTGetTimeStamp(OTTimeStamp *currentTime) MAC_IMPORT(OTGetTimeStamp);
|
||||
|
||||
OTTimeStamp* OTSubtractTimeStamps(OTTimeStamp *result, OTTimeStamp *startTime, OTTimeStamp *endEnd) MAC_IMPORT(OTSubtractTimeStamps);
|
||||
|
||||
UInt32 OTTimeStampInMilliseconds(OTTimeStamp *delta) MAC_IMPORT(OTTimeStampInMilliseconds);
|
||||
|
||||
UInt32 OTTimeStampInMicroseconds(OTTimeStamp *delta) MAC_IMPORT(OTTimeStampInMicroseconds);
|
||||
|
||||
UInt32 OTElapsedMilliseconds(OTTimeStamp *startTime) MAC_IMPORT(OTElapsedMilliseconds);
|
||||
|
||||
UInt32 OTElapsedMicroseconds(OTTimeStamp *startTime) MAC_IMPORT(OTElapsedMicroseconds);
|
||||
|
||||
UInt32 OTGetClockTimeInSecs(void) MAC_IMPORT(OTGetClockTimeInSecs);
|
||||
|
||||
void OTLIFOEnqueue(OTLIFO *list, OTLink *link) MAC_IMPORT(OTLIFOEnqueue);
|
||||
|
||||
OTLink* OTLIFODequeue(OTLIFO *list) MAC_IMPORT(OTLIFODequeue);
|
||||
|
||||
OTLink* OTLIFOStealList(OTLIFO *list) MAC_IMPORT(OTLIFOStealList);
|
||||
|
||||
OTLink* OTReverseList(OTLink *list) MAC_IMPORT(OTReverseList);
|
||||
|
||||
void OTAddFirst(OTList *list, OTLink *link) MAC_IMPORT(OTAddFirst);
|
||||
|
||||
void OTAddLast(OTList *list, OTLink *link) MAC_IMPORT(OTAddLast);
|
||||
|
||||
OTLink* OTRemoveFirst(OTList *list) MAC_IMPORT(OTRemoveFirst);
|
||||
|
||||
OTLink* OTRemoveLast(OTList *list) MAC_IMPORT(OTRemoveLast);
|
||||
|
||||
OTLink* OTGetFirst(OTList *list) MAC_IMPORT(OTGetFirst);
|
||||
|
||||
OTLink* OTGetLast(OTList *list) MAC_IMPORT(OTGetLast);
|
||||
|
||||
Boolean OTIsInList(OTList *list, OTLink *link) MAC_IMPORT(OTIsInList);
|
||||
|
||||
Boolean OTRemoveLink(OTList *list, OTLink *link) MAC_IMPORT(OTRemoveLink);
|
||||
|
||||
OTLink* OTGetIndexedLink(OTList *list, OTItemCount index) MAC_IMPORT(OTGetIndexedLink);
|
||||
|
||||
Boolean OTScheduleDeferredTask(long dtCookie) MAC_IMPORT(OTScheduleDeferredTask);
|
||||
|
||||
OSStatus OTDestroyDeferredTask(long dtCookie) MAC_IMPORT(OTDestroyDeferredTask);
|
||||
|
||||
Boolean OTScheduleSystemTask(long stCookie) MAC_IMPORT(OTScheduleSystemTask);
|
||||
|
||||
Boolean OTCancelSystemTask(long stCookie) MAC_IMPORT(OTCancelSystemTask);
|
||||
|
||||
OSStatus OTDestroySystemTask(long stCookie) MAC_IMPORT(OTDestroySystemTask);
|
||||
|
||||
Boolean OTCanMakeSyncCall(void) MAC_IMPORT(OTCanMakeSyncCall);
|
||||
|
||||
Boolean OTIsAtInterruptLevel(void) MAC_IMPORT(OTIsAtInterruptLevel);
|
||||
|
||||
Boolean OTAtomicSetBit(UInt8 *bytePtr, OTByteCount bitNumber) MAC_IMPORT(OTAtomicSetBit);
|
||||
|
||||
Boolean OTAtomicClearBit(UInt8 *bytePtr, OTByteCount bitNumber) MAC_IMPORT(OTAtomicClearBit);
|
||||
|
||||
Boolean OTAtomicTestBit(UInt8 *bytePtr, OTByteCount bitNumber) MAC_IMPORT(OTAtomicTestBit);
|
||||
|
||||
Boolean OTCompareAndSwapPtr(void *oldValue, void *newValue, void **dest) MAC_IMPORT(OTCompareAndSwapPtr);
|
||||
|
||||
Boolean OTCompareAndSwap32(UInt32 oldValue, UInt32 newValue, UInt32 *dest) MAC_IMPORT(OTCompareAndSwap32);
|
||||
|
||||
SInt32 OTAtomicAdd32(SInt32 toAdd, SInt32 *dest) MAC_IMPORT(OTAtomicAdd32);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#pragma clang diagnostic pop
|
||||
#pragma options align=reset
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,269 @@
|
||||
/* OpenTransportProviders.h: generated by tools/gen-headers.py from defs/OpenTransportProviders.yaml. Do not edit. */
|
||||
#ifndef __MV_OPENTRANSPORTPROVIDERS__
|
||||
#define __MV_OPENTRANSPORTPROVIDERS__
|
||||
|
||||
#include "../ConditionalMacros.h"
|
||||
#include "DriverServices.h"
|
||||
#include "MacTypes.h"
|
||||
#include "OpenTransport.h"
|
||||
|
||||
#pragma options align=mac68k
|
||||
/* The headers' own inline code may call newer calls behind a
|
||||
check; the MAC_MIN_SYSTEM warnings are for the program's calls. */
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wuser-defined-warnings"
|
||||
|
||||
/* The Toolbox calls are C functions, also in C++. */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Open Transport TCP/IP: addresses, Internet services (the name
|
||||
resolver) and the TCP, UDP and IP options. */
|
||||
|
||||
typedef UInt16 InetPort;
|
||||
|
||||
// An IPv4 address in network order.
|
||||
typedef UInt32 InetHost;
|
||||
|
||||
// An open Internet services provider. All provider calls take it.
|
||||
typedef ProviderRef InetSvcRef;
|
||||
|
||||
typedef char InetDomainName[256];
|
||||
|
||||
#ifndef AF_INET
|
||||
#define AF_INET 2
|
||||
#endif
|
||||
#ifndef AF_DNS
|
||||
#define AF_DNS 42
|
||||
#endif
|
||||
|
||||
enum {
|
||||
kOTAnyInetAddress = 0,
|
||||
kMaxHostAddrs = 10,
|
||||
kMaxSysStringLen = 32,
|
||||
kMaxHostNameLen = 255,
|
||||
kDefaultInetInterface = -1,
|
||||
kInetInterfaceInfoVersion = 3,
|
||||
};
|
||||
|
||||
#define kTCPName "tcp"
|
||||
|
||||
#define kUDPName "udp"
|
||||
|
||||
#define kRawIPName "rawip"
|
||||
|
||||
#define kDNRName "dnr"
|
||||
|
||||
#define kDefaultInternetServicesPath ((OTConfigurationRef)(long)-3)
|
||||
|
||||
// Events of the Internet services provider.
|
||||
enum {
|
||||
T_DNRSTRINGTOADDRCOMPLETE = 268435457,
|
||||
T_DNRADDRTONAMECOMPLETE = 268435458,
|
||||
T_DNRSYSINFOCOMPLETE = 268435459,
|
||||
T_DNRMAILEXCHANGECOMPLETE = 268435460,
|
||||
T_DNRQUERYCOMPLETE = 268435461,
|
||||
};
|
||||
|
||||
// Option levels.
|
||||
enum {
|
||||
INET_IP = 0,
|
||||
INET_TCP = 6,
|
||||
INET_UDP = 17,
|
||||
};
|
||||
|
||||
/* Option names. The BSD socket headers use some of the same names with
|
||||
other values: a file that includes <netinet/in.h> or <netinet/tcp.h>
|
||||
first keeps their values. */
|
||||
#ifndef TCP_NODELAY
|
||||
#define TCP_NODELAY 0x1
|
||||
#endif
|
||||
#ifndef TCP_MAXSEG
|
||||
#define TCP_MAXSEG 0x2
|
||||
#endif
|
||||
#ifndef TCP_NOTIFY_THRESHOLD
|
||||
#define TCP_NOTIFY_THRESHOLD 0x10
|
||||
#endif
|
||||
#ifndef TCP_ABORT_THRESHOLD
|
||||
#define TCP_ABORT_THRESHOLD 0x11
|
||||
#endif
|
||||
#ifndef TCP_CONN_NOTIFY_THRESHOLD
|
||||
#define TCP_CONN_NOTIFY_THRESHOLD 0x12
|
||||
#endif
|
||||
#ifndef TCP_CONN_ABORT_THRESHOLD
|
||||
#define TCP_CONN_ABORT_THRESHOLD 0x13
|
||||
#endif
|
||||
#ifndef TCP_OOBINLINE
|
||||
#define TCP_OOBINLINE 0x14
|
||||
#endif
|
||||
#ifndef TCP_URGENT_PTR_TYPE
|
||||
#define TCP_URGENT_PTR_TYPE 0x15
|
||||
#endif
|
||||
#ifndef TCP_KEEPALIVE
|
||||
#define TCP_KEEPALIVE 0x8
|
||||
#endif
|
||||
#ifndef UDP_CHECKSUM
|
||||
#define UDP_CHECKSUM 0x600
|
||||
#endif
|
||||
#ifndef IP_OPTIONS
|
||||
#define IP_OPTIONS 0x1
|
||||
#endif
|
||||
#ifndef IP_TOS
|
||||
#define IP_TOS 0x2
|
||||
#endif
|
||||
#ifndef IP_TTL
|
||||
#define IP_TTL 0x3
|
||||
#endif
|
||||
#ifndef IP_REUSEADDR
|
||||
#define IP_REUSEADDR 0x4
|
||||
#endif
|
||||
#ifndef IP_DONTROUTE
|
||||
#define IP_DONTROUTE 0x10
|
||||
#endif
|
||||
#ifndef IP_BROADCAST
|
||||
#define IP_BROADCAST 0x20
|
||||
#endif
|
||||
#ifndef IP_REUSEPORT
|
||||
#define IP_REUSEPORT 0x200
|
||||
#endif
|
||||
#ifndef IP_HDRINCL
|
||||
#define IP_HDRINCL 0x1002
|
||||
#endif
|
||||
#ifndef IP_RCVOPTS
|
||||
#define IP_RCVOPTS 0x1005
|
||||
#endif
|
||||
#ifndef IP_RCVDSTADDR
|
||||
#define IP_RCVDSTADDR 0x1006
|
||||
#endif
|
||||
#ifndef IP_MULTICAST_IF
|
||||
#define IP_MULTICAST_IF 0x1010
|
||||
#endif
|
||||
#ifndef IP_MULTICAST_TTL
|
||||
#define IP_MULTICAST_TTL 0x1011
|
||||
#endif
|
||||
#ifndef IP_MULTICAST_LOOP
|
||||
#define IP_MULTICAST_LOOP 0x1012
|
||||
#endif
|
||||
#ifndef IP_ADD_MEMBERSHIP
|
||||
#define IP_ADD_MEMBERSHIP 0x1013
|
||||
#endif
|
||||
#ifndef IP_DROP_MEMBERSHIP
|
||||
#define IP_DROP_MEMBERSHIP 0x1014
|
||||
#endif
|
||||
|
||||
// An IPv4 address and port (fAddressType AF_INET).
|
||||
typedef struct InetAddress InetAddress;
|
||||
#pragma options align=power
|
||||
struct InetAddress {
|
||||
OTAddressType fAddressType;
|
||||
InetPort fPort;
|
||||
InetHost fHost;
|
||||
UInt8 fUnused[8];
|
||||
};
|
||||
#pragma options align=reset
|
||||
|
||||
// A host name and port as text, "name:port" (fAddressType AF_DNS).
|
||||
typedef struct DNSAddress DNSAddress;
|
||||
#pragma options align=power
|
||||
struct DNSAddress {
|
||||
OTAddressType fAddressType;
|
||||
InetDomainName fName;
|
||||
};
|
||||
#pragma options align=reset
|
||||
|
||||
// The result of OTInetStringToAddress: the full name and up to
|
||||
// kMaxHostAddrs addresses (the unused ones are 0).
|
||||
typedef struct InetHostInfo InetHostInfo;
|
||||
#pragma options align=power
|
||||
struct InetHostInfo {
|
||||
InetDomainName name;
|
||||
InetHost addrs[10];
|
||||
};
|
||||
#pragma options align=reset
|
||||
|
||||
typedef struct InetSysInfo InetSysInfo;
|
||||
#pragma options align=power
|
||||
struct InetSysInfo {
|
||||
char cpuType[32];
|
||||
char osType[32];
|
||||
};
|
||||
#pragma options align=reset
|
||||
|
||||
typedef struct InetMailExchange InetMailExchange;
|
||||
#pragma options align=power
|
||||
struct InetMailExchange {
|
||||
UInt16 preference;
|
||||
InetDomainName exchange;
|
||||
};
|
||||
#pragma options align=reset
|
||||
|
||||
typedef struct DNSQueryInfo DNSQueryInfo;
|
||||
#pragma options align=power
|
||||
struct DNSQueryInfo {
|
||||
UInt16 qType;
|
||||
UInt16 qClass;
|
||||
UInt32 ttl;
|
||||
InetDomainName name;
|
||||
UInt16 responseType;
|
||||
UInt16 resourceLen;
|
||||
char resourceData[4];
|
||||
};
|
||||
#pragma options align=reset
|
||||
|
||||
// The settings of an IP interface (OTInetGetInterfaceInfo).
|
||||
typedef struct InetInterfaceInfo InetInterfaceInfo;
|
||||
#pragma options align=power
|
||||
struct InetInterfaceInfo {
|
||||
InetHost fAddress;
|
||||
InetHost fNetmask;
|
||||
InetHost fBroadcastAddr;
|
||||
InetHost fDefaultGatewayAddr;
|
||||
InetHost fDNSAddr;
|
||||
UInt16 fVersion;
|
||||
UInt16 fHWAddrLen;
|
||||
UInt8 *fHWAddr;
|
||||
UInt32 fIfMTU;
|
||||
UInt8 *fReservedPtrs[2];
|
||||
InetDomainName fDomainName;
|
||||
UInt32 fIPSecondaryCount;
|
||||
UInt8 fReserved[252];
|
||||
};
|
||||
#pragma options align=reset
|
||||
|
||||
// Opens the Internet services provider (the name resolver), synchronous.
|
||||
// Pass kDefaultInternetServicesPath as cfig.
|
||||
InetSvcRef OTOpenInternetServices(OTConfigurationRef cfig, OTOpenFlags oflag, OSStatus *err) MAC_IMPORT(OTOpenInternetServices);
|
||||
|
||||
OSStatus OTAsyncOpenInternetServices(OTConfigurationRef cfig, OTOpenFlags oflag, OTNotifyUPP proc, void *contextPtr) MAC_IMPORT(OTAsyncOpenInternetServices);
|
||||
|
||||
OSStatus OTInetStringToHost(const char *str, InetHost *host) MAC_IMPORT(OTInetStringToHost);
|
||||
|
||||
void OTInetHostToString(InetHost host, char *str) MAC_IMPORT(OTInetHostToString);
|
||||
|
||||
OSStatus OTInetGetInterfaceInfo(InetInterfaceInfo *info, SInt32 val) MAC_IMPORT(OTInetGetInterfaceInfo);
|
||||
|
||||
OSStatus OTInetGetSecondaryAddresses(InetHost *addr, UInt32 *count, SInt32 val) MAC_IMPORT(OTInetGetSecondaryAddresses);
|
||||
|
||||
OSStatus OTInetStringToAddress(InetSvcRef ref, char *name, InetHostInfo *hinfo) MAC_IMPORT(OTInetStringToAddress);
|
||||
|
||||
OSStatus OTInetAddressToName(InetSvcRef ref, InetHost addr, char *name) MAC_IMPORT(OTInetAddressToName);
|
||||
|
||||
OSStatus OTInetSysInfo(InetSvcRef ref, char *name, InetSysInfo *sysinfo) MAC_IMPORT(OTInetSysInfo);
|
||||
|
||||
OSStatus OTInetMailExchange(InetSvcRef ref, char *name, UInt16 *num, InetMailExchange *mx) MAC_IMPORT(OTInetMailExchange);
|
||||
|
||||
OSStatus OTInetQuery(InetSvcRef ref, char *name, UInt16 qClass, UInt16 qType, char *buf, OTByteCount buflen, void **argv, OTByteCount argvlen, OTFlags requestFlags) MAC_IMPORT(OTInetQuery);
|
||||
|
||||
void OTInitInetAddress(InetAddress *addr, InetPort port, InetHost host) MAC_IMPORT(OTInitInetAddress);
|
||||
|
||||
OTByteCount OTInitDNSAddress(DNSAddress *addr, char *str) MAC_IMPORT(OTInitDNSAddress);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#pragma clang diagnostic pop
|
||||
#pragma options align=reset
|
||||
|
||||
#endif
|
||||
@@ -19,6 +19,14 @@ PrepareMemoryForIO
|
||||
CheckpointIO
|
||||
ATEvent
|
||||
ATPreFlightEvent
|
||||
OpenResolver
|
||||
CloseResolver
|
||||
StrToAddr
|
||||
AddrToStr
|
||||
EnumCache
|
||||
AddrToName
|
||||
HInfo
|
||||
MXInfo
|
||||
GetDefaultUser
|
||||
StartSecureSession
|
||||
KillProcess
|
||||
@@ -27,6 +35,12 @@ MakeDataExecutable
|
||||
InstallExceptionHandler
|
||||
FSCreateResourceFile
|
||||
FSOpenResourceFile
|
||||
InitLibraryManager
|
||||
CleanupLibraryManager
|
||||
ASLMPresent
|
||||
ASLMLoadFunctionSet
|
||||
ASLMCallC
|
||||
ASLMCallPascal
|
||||
CallUniversalProc
|
||||
CallOSTrapUniversalProc
|
||||
RegistryEntryIDDispose
|
||||
@@ -56,6 +70,121 @@ NavAskDiscardChanges
|
||||
NavCompleteSave
|
||||
NavCreatePreview
|
||||
NavCustomControl
|
||||
InitOpenTransport
|
||||
InitOpenTransportUtilities
|
||||
CloseOpenTransport
|
||||
OTRegisterAsClient
|
||||
OTUnregisterAsClient
|
||||
OTAllocMem
|
||||
OTAlloc
|
||||
OTOpenEndpoint
|
||||
OTAsyncOpenEndpoint
|
||||
OTCloseProvider
|
||||
OTCreateDeferredTask
|
||||
OTCreateSystemTask
|
||||
OTSetSynchronous
|
||||
OTSetAsynchronous
|
||||
OTIsSynchronous
|
||||
OTSetBlocking
|
||||
OTSetNonBlocking
|
||||
OTIsBlocking
|
||||
OTInstallNotifier
|
||||
OTRemoveNotifier
|
||||
OTUseSyncIdleEvents
|
||||
OTEnterNotifier
|
||||
OTLeaveNotifier
|
||||
OTAckSends
|
||||
OTDontAckSends
|
||||
OTIsAckingSends
|
||||
OTCancelSynchronousCalls
|
||||
OTIoctl
|
||||
OTGetProviderPortRef
|
||||
OTGetEndpointInfo
|
||||
OTGetEndpointState
|
||||
OTLook
|
||||
OTCountDataBytes
|
||||
OTGetProtAddress
|
||||
OTResolveAddress
|
||||
OTFree
|
||||
OTOptionManagement
|
||||
OTNextOption
|
||||
OTFindOption
|
||||
OTBind
|
||||
OTUnbind
|
||||
OTConnect
|
||||
OTRcvConnect
|
||||
OTListen
|
||||
OTAccept
|
||||
OTSndDisconnect
|
||||
OTSndOrderlyDisconnect
|
||||
OTRcvDisconnect
|
||||
OTRcvOrderlyDisconnect
|
||||
OTRcv
|
||||
OTSnd
|
||||
OTSndUData
|
||||
OTRcvUData
|
||||
OTRcvUDErr
|
||||
OTIdle
|
||||
OTDelay
|
||||
OTCreateConfiguration
|
||||
OTCloneConfiguration
|
||||
OTDestroyConfiguration
|
||||
OTFreeMem
|
||||
OTMemcpy
|
||||
OTMemcmp
|
||||
OTMemmove
|
||||
OTMemzero
|
||||
OTMemset
|
||||
OTStrLength
|
||||
OTStrCopy
|
||||
OTStrCat
|
||||
OTStrEqual
|
||||
OTGetTimeStamp
|
||||
OTSubtractTimeStamps
|
||||
OTTimeStampInMilliseconds
|
||||
OTTimeStampInMicroseconds
|
||||
OTElapsedMilliseconds
|
||||
OTElapsedMicroseconds
|
||||
OTGetClockTimeInSecs
|
||||
OTLIFOEnqueue
|
||||
OTLIFODequeue
|
||||
OTLIFOStealList
|
||||
OTReverseList
|
||||
OTAddFirst
|
||||
OTAddLast
|
||||
OTRemoveFirst
|
||||
OTRemoveLast
|
||||
OTGetFirst
|
||||
OTGetLast
|
||||
OTIsInList
|
||||
OTRemoveLink
|
||||
OTGetIndexedLink
|
||||
OTScheduleDeferredTask
|
||||
OTDestroyDeferredTask
|
||||
OTScheduleSystemTask
|
||||
OTCancelSystemTask
|
||||
OTDestroySystemTask
|
||||
OTCanMakeSyncCall
|
||||
OTIsAtInterruptLevel
|
||||
OTAtomicSetBit
|
||||
OTAtomicClearBit
|
||||
OTAtomicTestBit
|
||||
OTCompareAndSwapPtr
|
||||
OTCompareAndSwap32
|
||||
OTAtomicAdd32
|
||||
OTOpenInternetServices
|
||||
OTAsyncOpenInternetServices
|
||||
OTInetStringToHost
|
||||
OTInetHostToString
|
||||
OTInetGetInterfaceInfo
|
||||
OTInetGetSecondaryAddresses
|
||||
OTInetStringToAddress
|
||||
OTInetAddressToName
|
||||
OTInetSysInfo
|
||||
OTInetMailExchange
|
||||
OTInetQuery
|
||||
OTInitInetAddress
|
||||
OTInitDNSAddress
|
||||
ExpMgrConfigReadByte
|
||||
ExpMgrConfigReadWord
|
||||
ExpMgrConfigReadLong
|
||||
|
||||
@@ -30,6 +30,8 @@ nav:
|
||||
- "Threads": threads.md
|
||||
- "POSIX functions": posix.md
|
||||
- "Networking and pipes": network.md
|
||||
- "Open Transport and MacTCP": opentransport.md
|
||||
- "Shared Library Manager (ASLM)": aslm.md
|
||||
- "OpenGL": opengl.md
|
||||
- "Soft float on the 68000": softfloat.md
|
||||
- "QuickDraw 3D (Quesa)": quesa.md
|
||||
|
||||
@@ -0,0 +1,271 @@
|
||||
/* The client side of the Apple Shared Library Manager (ASLM) on 68k.
|
||||
*
|
||||
* ASLM keeps its global record at offset 0x10C of ExpandMem. The
|
||||
* fields that a client uses:
|
||||
* 0x10 the library manager object (zero when ASLM is not loaded)
|
||||
* 0x0C a field that the client sets to zero after it starts
|
||||
* 0x64 a routine that loads ASLM (D0 = 1) or unloads it (D0 = 2)
|
||||
* 0x88 the binder: a stub jumps to it with A0 = the stub slot and
|
||||
* D0 = the client's local library manager
|
||||
*
|
||||
* The objects use the MPW C++ object layout: the first long is the
|
||||
* address of a table of function addresses. The functions use the C
|
||||
* calling convention, with the object as the first argument:
|
||||
* manager 0x9C starts a client (gives its local library manager)
|
||||
* manager 0xA0 ends a client
|
||||
* client 0x40 loads the library that has a function set
|
||||
*
|
||||
* The start call takes a jump buffer: when ASLM cannot make the client
|
||||
* (for example, without memory), it jumps back to the buffer with D0
|
||||
* nonzero.
|
||||
*
|
||||
* MPW code keeps only D3-D7 and A2-A4 (and A5, A6): it can change D2,
|
||||
* which clang keeps across a call. So each call to MPW code goes
|
||||
* through ASLMCallC or ASLMCallPascal, which keep D2.
|
||||
*
|
||||
* Copyright (C) clang-retro contributors.
|
||||
* SPDX-License-Identifier: AGPL-3.0-only */
|
||||
#if defined(__m68k__)
|
||||
#include <stdlib.h>
|
||||
#include <LibraryManager.h>
|
||||
#include <Multiverse.h>
|
||||
|
||||
/* The offsets in ASLM's global record. */
|
||||
enum { ROOT_CLEAR = 0x0C, ROOT_MANAGER = 0x10, ROOT_LOADER = 0x64, ROOT_BINDER = 0x88 };
|
||||
|
||||
/* The offsets in the function tables. */
|
||||
enum { MANAGER_START = 0x9C, MANAGER_END = 0xA0, CLIENT_LOAD = 0x40 };
|
||||
|
||||
char *__aslm_root; /* ASLM's global record */
|
||||
void *__aslm_client; /* the program's local library manager */
|
||||
static int exit_set; /* CleanupLibraryManager is an atexit function */
|
||||
|
||||
long __aslm_start(void *manager, void **client, long pool, long zone, long mem, long shared);
|
||||
long __aslm_loader(void *routine, long selector);
|
||||
void *__aslm_auto_start(void);
|
||||
|
||||
/* Calls the start function of the manager with a jump buffer.
|
||||
Gives the result of the call, or the value of D0 when ASLM jumps
|
||||
back to the buffer. */
|
||||
__asm__(".text\n\t.globl __aslm_start\n\t.p2align 1\n__aslm_start:\n"
|
||||
"\tlink.w %a6, #-48\n"
|
||||
"\tmovem.l %d2-%d7/%a2-%a4, -(%sp)\n"
|
||||
"\tlea (-48, %a6), %a0\n"
|
||||
"\tlea (2f, %pc), %a1\n"
|
||||
"\tmovem.l %d2-%d7/%a1-%a4/%a6-%a7, (%a0)\n"
|
||||
"\tmoveq #0, %d0\n"
|
||||
"2:\tcmpi.l #0, %d0\n"
|
||||
"\tbne 3f\n"
|
||||
"\tmove.l (28, %a6), -(%sp)\n" /* shared */
|
||||
"\tmove.l (24, %a6), -(%sp)\n" /* mem */
|
||||
"\tmove.l (20, %a6), -(%sp)\n" /* zone */
|
||||
"\tmove.l (16, %a6), -(%sp)\n" /* pool */
|
||||
"\tlea (-48, %a6), %a0\n"
|
||||
"\tmove.l %a0, -(%sp)\n" /* the jump buffer */
|
||||
"\tmove.l (12, %a6), -(%sp)\n" /* client */
|
||||
"\tmove.l (8, %a6), %a0\n"
|
||||
"\tmove.l %a0, -(%sp)\n" /* the manager */
|
||||
"\tmove.l (%a0), %a0\n"
|
||||
"\tmove.l (0x9C, %a0), %a0\n"
|
||||
"\tjsr (%a0)\n"
|
||||
"\tlea (28, %sp), %sp\n"
|
||||
"\text.l %d0\n"
|
||||
"\tbra 4f\n"
|
||||
"3:\tmove.l #-3132, %d0\n"
|
||||
"4:\tmovem.l (%sp)+, %d2-%d7/%a2-%a4\n"
|
||||
"\tunlk %a6\n"
|
||||
"\trts\n");
|
||||
|
||||
/* Calls ASLM's load routine with the selector in D0. Keeps all
|
||||
registers. Gives D0. */
|
||||
__asm__(".text\n\t.globl __aslm_loader\n\t.p2align 1\n__aslm_loader:\n"
|
||||
"\tmovem.l %d1-%d7/%a1-%a6, -(%sp)\n"
|
||||
"\tmove.l (56, %sp), %a0\n"
|
||||
"\tmove.l (60, %sp), %d0\n"
|
||||
"\tjsr (%a0)\n"
|
||||
"\tmovem.l (%sp)+, %d1-%d7/%a1-%a6\n"
|
||||
"\trts\n");
|
||||
|
||||
/* The binder of the stubs that ASLM_FUNCTION makes: A0 is the slot.
|
||||
It starts ASLM for the program when the program did not, then jumps
|
||||
to ASLM's binder with D0 = the program's local library manager.
|
||||
Without ASLM it gives kASLMNotPresentErr. */
|
||||
__asm__(".text\n\t.globl __aslm_bind\n\t.p2align 1\n__aslm_bind:\n"
|
||||
"\tmove.l __aslm_client, %d0\n"
|
||||
"\tbne 1f\n"
|
||||
"\tmove.l %a0, -(%sp)\n"
|
||||
"\tjsr __aslm_auto_start\n"
|
||||
"\tmove.l (%sp)+, %a0\n"
|
||||
"\tcmpi.l #0, %d0\n"
|
||||
"\tbeq 2f\n"
|
||||
"1:\tmove.l __aslm_root, %a1\n"
|
||||
"\tmove.l (0x88, %a1), %a1\n"
|
||||
"\tjmp (%a1)\n"
|
||||
"2:\tmove.l #-3132, %d0\n"
|
||||
"\trts\n");
|
||||
|
||||
/* Calls a function of the MPW C calling convention: see
|
||||
LibraryManager.h. __mac_mpw_call is the name for the rest of the C
|
||||
library. */
|
||||
__asm__(".text\n\t.globl ASLMCallC\n\t.globl __mac_mpw_call\n\t.p2align 1\n"
|
||||
"ASLMCallC:\n__mac_mpw_call:\n"
|
||||
"\tlink.w %a6, #0\n"
|
||||
"\tmovem.l %d2-%d7/%a2-%a4, -(%sp)\n"
|
||||
"\tmove.l (8, %a6), %a2\n" /* fn */
|
||||
"\tmove.l (12, %a6), %d2\n" /* nargs */
|
||||
"\tmove.l (16, %a6), %a3\n" /* args */
|
||||
"\tmove.l %d2, %d3\n"
|
||||
"\tlsl.l #2, %d3\n"
|
||||
"\tadda.l %d3, %a3\n" /* after the last argument */
|
||||
"\tmoveq #0, %d4\n"
|
||||
"1:\tcmp.l %d2, %d4\n"
|
||||
"\tbge 2f\n"
|
||||
"\tmove.l -(%a3), -(%sp)\n"
|
||||
"\tadd.l #1, %d4\n"
|
||||
"\tbra 1b\n"
|
||||
"2:\tjsr (%a2)\n"
|
||||
"\tmove.l (12, %a6), %d2\n"
|
||||
"\tlsl.l #2, %d2\n"
|
||||
"\tadda.l %d2, %sp\n"
|
||||
"\tmovem.l (%sp)+, %d2-%d7/%a2-%a4\n"
|
||||
"\tunlk %a6\n"
|
||||
"\trts\n");
|
||||
|
||||
/* Calls a Pascal function: see LibraryManager.h. */
|
||||
__asm__(".text\n\t.globl ASLMCallPascal\n\t.p2align 1\nASLMCallPascal:\n"
|
||||
"\tlink.w %a6, #0\n"
|
||||
"\tmovem.l %d2-%d7/%a2-%a4, -(%sp)\n"
|
||||
"\tmove.l (8, %a6), %a2\n" /* fn */
|
||||
"\tmove.l (12, %a6), %d2\n" /* nargs */
|
||||
"\tmove.l (16, %a6), %d3\n" /* wordMask */
|
||||
"\tmove.l (20, %a6), %d4\n" /* resultSize */
|
||||
"\tmove.l (24, %a6), %a3\n" /* args */
|
||||
"\tcmpi.l #2, %d4\n"
|
||||
"\tbeq 1f\n"
|
||||
"\tcmpi.l #4, %d4\n"
|
||||
"\tbne 2f\n"
|
||||
"\tclr.l -(%sp)\n"
|
||||
"\tbra 2f\n"
|
||||
"1:\tclr.w -(%sp)\n"
|
||||
"2:\tmoveq #0, %d5\n"
|
||||
"3:\tcmp.l %d2, %d5\n"
|
||||
"\tbge 6f\n"
|
||||
"\tmove.l (%a3)+, %d0\n"
|
||||
"\tbtst %d5, %d3\n"
|
||||
"\tbeq 4f\n"
|
||||
"\tmove.w %d0, -(%sp)\n"
|
||||
"\tbra 5f\n"
|
||||
"4:\tmove.l %d0, -(%sp)\n"
|
||||
"5:\tadd.l #1, %d5\n"
|
||||
"\tbra 3b\n"
|
||||
"6:\tjsr (%a2)\n"
|
||||
"\tmoveq #0, %d0\n"
|
||||
"\tcmpi.l #2, %d4\n"
|
||||
"\tbne 7f\n"
|
||||
"\tmove.w (%sp)+, %d0\n"
|
||||
"\tbra 8f\n"
|
||||
"7:\tcmpi.l #4, %d4\n"
|
||||
"\tbne 8f\n"
|
||||
"\tmove.l (%sp)+, %d0\n"
|
||||
"8:\tmovem.l (%sp)+, %d2-%d7/%a2-%a4\n"
|
||||
"\tunlk %a6\n"
|
||||
"\trts\n");
|
||||
|
||||
/* Gives the address of a function in the function table of an MPW
|
||||
C++ object. */
|
||||
static void *method(void *object, int offset) {
|
||||
return *(void **)(*(char **)object + offset);
|
||||
}
|
||||
|
||||
/* Gives ASLM's global record, or NULL when the system has none. */
|
||||
static char *find_root(void) {
|
||||
char *em = *(char **)0x2B6; /* ExpandMem */
|
||||
if (!em || GetPtrSize(em) < 0x110)
|
||||
return NULL;
|
||||
return *(char **)(em + 0x10C);
|
||||
}
|
||||
|
||||
/* Gives true when ASLM is installed. Loads ASLM when it is installed
|
||||
but not loaded. */
|
||||
Boolean ASLMPresent(void) {
|
||||
char *root = find_root();
|
||||
void *loader;
|
||||
if (!root)
|
||||
return false;
|
||||
if (*(long *)(root + ROOT_MANAGER))
|
||||
return true;
|
||||
loader = *(void **)(root + ROOT_LOADER);
|
||||
if (loader)
|
||||
__aslm_loader(loader, 1);
|
||||
return *(long *)(root + ROOT_MANAGER) != 0;
|
||||
}
|
||||
|
||||
/* Gives the value of A5. */
|
||||
static long current_a5(void) {
|
||||
long a5;
|
||||
__asm__("move.l %%a5, %0" : "=d"(a5));
|
||||
return a5;
|
||||
}
|
||||
|
||||
/* Starts the program's use of ASLM. */
|
||||
OSErr InitLibraryManager(size_t poolSize, int zoneType, int memType) {
|
||||
void *manager;
|
||||
long rc;
|
||||
if (__aslm_client)
|
||||
return noErr;
|
||||
if (!ASLMPresent())
|
||||
return kASLMNotPresentErr;
|
||||
__aslm_root = find_root();
|
||||
manager = *(void **)(__aslm_root + ROOT_MANAGER);
|
||||
rc = __aslm_start(manager, &__aslm_client, (long)poolSize, zoneType, memType, 0);
|
||||
if (rc != noErr || !__aslm_client) {
|
||||
__aslm_client = NULL;
|
||||
return rc ? (OSErr)rc : kASLMNotPresentErr;
|
||||
}
|
||||
/* Apple's glue does this for an application (A5 is CurrentA5). */
|
||||
if (current_a5() == *(long *)0x904)
|
||||
*(long *)(__aslm_root + ROOT_CLEAR) = 0;
|
||||
if (!exit_set) {
|
||||
exit_set = 1;
|
||||
atexit(CleanupLibraryManager);
|
||||
}
|
||||
return noErr;
|
||||
}
|
||||
|
||||
/* Starts ASLM with the default values for the first call of a stub.
|
||||
Gives the program's local library manager, or NULL. */
|
||||
void *__aslm_auto_start(void) {
|
||||
InitLibraryManager(kASLMDefaultPoolSize, kASLMDefaultZone, kASLMDefaultMemory);
|
||||
return __aslm_client;
|
||||
}
|
||||
|
||||
/* Ends the program's use of ASLM. */
|
||||
void CleanupLibraryManager(void) {
|
||||
void *manager, *loader;
|
||||
unsigned char unload;
|
||||
long args[3];
|
||||
if (!__aslm_client)
|
||||
return;
|
||||
manager = *(void **)(__aslm_root + ROOT_MANAGER);
|
||||
args[0] = (long)manager;
|
||||
args[1] = (long)&__aslm_client;
|
||||
args[2] = 0;
|
||||
unload = (unsigned char)ASLMCallC(method(manager, MANAGER_END), 3, args);
|
||||
__aslm_client = NULL;
|
||||
loader = *(void **)(__aslm_root + ROOT_LOADER);
|
||||
if (unload && loader)
|
||||
__aslm_loader(loader, 2);
|
||||
}
|
||||
|
||||
/* Loads the library that has a function set. */
|
||||
OSErr ASLMLoadFunctionSet(const char *id) {
|
||||
long args[3];
|
||||
if (!__aslm_client &&
|
||||
InitLibraryManager(kASLMDefaultPoolSize, kASLMDefaultZone, kASLMDefaultMemory) != noErr)
|
||||
return kASLMNotPresentErr;
|
||||
args[0] = (long)__aslm_client;
|
||||
args[1] = (long)id;
|
||||
args[2] = 1;
|
||||
return (OSErr)ASLMCallC(method(__aslm_client, CLIENT_LOAD), 3, args);
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,202 @@
|
||||
/* The MacTCP name resolver (DNR): OpenResolver, StrToAddr, AddrToName
|
||||
* and the other calls of AddressXlation.h.
|
||||
*
|
||||
* The resolver is a 68k code resource ('dnrp'). MacTCP keeps it in its
|
||||
* control panel; Open Transport keeps it in the System file. This file
|
||||
* finds the resource, keeps it locked in the heap, and calls it with a
|
||||
* selector and the arguments of the call. On PowerPC the calls go
|
||||
* through the Mixed Mode Manager. netdb.c uses the same calls for
|
||||
* getaddrinfo and the other name functions.
|
||||
*
|
||||
* Copyright (C) clang-retro contributors.
|
||||
* SPDX-License-Identifier: AGPL-3.0-only */
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <Files.h>
|
||||
#include <Folders.h>
|
||||
#include <MacMemory.h>
|
||||
#include <MixedMode.h>
|
||||
#include <Multiverse.h>
|
||||
#include <Resources.h>
|
||||
#include <AddressXlation.h>
|
||||
#include "macos.h"
|
||||
#include "socket.h"
|
||||
|
||||
/* The selectors of the resolver's entry point. */
|
||||
enum {
|
||||
OPENRESOLVER = 1,
|
||||
CLOSERESOLVER = 2,
|
||||
STRTOADDR = 3,
|
||||
ADDRTOSTR = 4,
|
||||
ENUMCACHE = 5,
|
||||
ADDRTONAME = 6,
|
||||
HXINFO = 7,
|
||||
MXINFO = 8
|
||||
};
|
||||
|
||||
/* A Pascal result procedure in 68k code that does nothing: it takes
|
||||
its two arguments off the stack. A caller without a result procedure
|
||||
examines rtnCode.
|
||||
movea.l (sp)+,a0 ; addq.l #8,sp ; jmp (a0) */
|
||||
static const unsigned short no_result[] = {0x205F, 0x508F, 0x4ED0};
|
||||
|
||||
static Handle dnr; /* the resolver's code, locked; NULL when closed */
|
||||
|
||||
/* Calls the resolver with a selector and up to four long arguments.
|
||||
Gives the resolver's result: an OSErr in the low word of D0. The high
|
||||
word is not defined (Open Transport's resolver leaves other bits
|
||||
there), so the result is only that word. */
|
||||
static OSErr dnr_call(long sel, long a, long b, long c, long d) {
|
||||
#if defined(__powerpc__)
|
||||
/* C on the stack, a 4-byte result, five 4-byte arguments. */
|
||||
const ProcInfoType info = 1 | (3 << 4) | (3 << 6) | (3 << 8) | (3 << 10) | (3 << 12) | (3 << 14);
|
||||
return (OSErr)CallUniversalProc((UniversalProcPtr)*dnr, info, sel, a, b, c, d);
|
||||
#else
|
||||
/* The resolver is MPW code: it can change D2, so call it through
|
||||
__mac_mpw_call (aslm.c), which keeps the registers that clang
|
||||
keeps. */
|
||||
const long args[5] = {sel, a, b, c, d};
|
||||
return (OSErr)__mac_mpw_call((const void *)*dnr, 5, args);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Looks in one folder for the MacTCP control panel (type 'cdev',
|
||||
creator 'ztcp' or 'mtcp') and opens its resource fork. Gives its
|
||||
reference number, or -1. */
|
||||
static short open_panel(short vol, long dir) {
|
||||
CInfoPBRec pb;
|
||||
Str255 name;
|
||||
short i;
|
||||
for (i = 1;; i++) {
|
||||
OSType type, creator;
|
||||
memset(&pb, 0, sizeof pb);
|
||||
pb.hFileInfo.ioNamePtr = name;
|
||||
pb.hFileInfo.ioVRefNum = vol;
|
||||
pb.hFileInfo.ioDirID = dir;
|
||||
pb.hFileInfo.ioFDirIndex = i;
|
||||
if (PBGetCatInfoSync(&pb) != noErr)
|
||||
return -1;
|
||||
if (pb.hFileInfo.ioFlAttrib & 0x10)
|
||||
continue;
|
||||
type = pb.hFileInfo.ioFlFndrInfo.fdType;
|
||||
creator = pb.hFileInfo.ioFlFndrInfo.fdCreator;
|
||||
if (type == 'cdev' && (creator == 'ztcp' || creator == 'mtcp')) {
|
||||
short ref = HOpenResFile(vol, dir, name, fsRdPerm);
|
||||
if (ref != -1)
|
||||
return ref;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Finds the resolver's code and detaches it from its file. Gives the
|
||||
handle, or NULL. */
|
||||
static Handle find_resolver(void) {
|
||||
static const OSType folders[] = {kControlPanelFolderType, kExtensionFolderType, kSystemFolderType};
|
||||
short ref = -1, vol;
|
||||
long dir;
|
||||
unsigned i;
|
||||
Handle h;
|
||||
for (i = 0; ref == -1 && i < sizeof folders / sizeof folders[0]; i++)
|
||||
if (FindFolder(kOnSystemDisk, folders[i], 0, &vol, &dir) == noErr)
|
||||
ref = open_panel(vol, dir);
|
||||
/* Open Transport keeps the resolver in the System file. */
|
||||
h = ref != -1 ? Get1IndResource('dnrp', 1) : 0;
|
||||
if (!h)
|
||||
h = GetIndResource('dnrp', 1);
|
||||
if (h)
|
||||
DetachResource(h);
|
||||
if (ref != -1)
|
||||
CloseResFile(ref);
|
||||
return h;
|
||||
}
|
||||
|
||||
/* Closes the resolver when the program ends. */
|
||||
static void close_at_exit(void) { CloseResolver(); }
|
||||
|
||||
/* Loads and opens the resolver. Gives noErr when it is open (also when
|
||||
it was open before), or an error. */
|
||||
OSErr OpenResolver(char *fileName) {
|
||||
static int registered;
|
||||
OSErr rc;
|
||||
(void)fileName;
|
||||
if (dnr)
|
||||
return noErr;
|
||||
if (__mac_ip_address() == 0)
|
||||
return ipNoCnfgErr;
|
||||
dnr = find_resolver();
|
||||
if (!dnr)
|
||||
return resNotFound;
|
||||
HLock(dnr);
|
||||
rc = dnr_call(OPENRESOLVER, 0, 0, 0, 0);
|
||||
if (rc != noErr) {
|
||||
DisposeHandle(dnr);
|
||||
dnr = NULL;
|
||||
return rc;
|
||||
}
|
||||
if (!registered) {
|
||||
registered = 1;
|
||||
atexit(close_at_exit);
|
||||
}
|
||||
return noErr;
|
||||
}
|
||||
|
||||
/* Closes the resolver and frees its code. Gives noErr, or notOpenErr
|
||||
when it was not open. */
|
||||
OSErr CloseResolver(void) {
|
||||
if (!dnr)
|
||||
return notOpenErr;
|
||||
dnr_call(CLOSERESOLVER, 0, 0, 0, 0);
|
||||
DisposeHandle(dnr);
|
||||
dnr = NULL;
|
||||
return noErr;
|
||||
}
|
||||
|
||||
/* Gives the result procedure to pass: proc, or the one that does
|
||||
nothing when proc is NULL. */
|
||||
static long result_proc(void *proc) { return proc ? (long)proc : (long)no_result; }
|
||||
|
||||
/* Finds the addresses of a host name or a dotted number. */
|
||||
OSErr StrToAddr(char *hostName, hostInfo *rtnStruct, ResultUPP resultproc, char *userDataPtr) {
|
||||
if (!dnr)
|
||||
return notOpenErr;
|
||||
return dnr_call(STRTOADDR, (long)hostName, (long)rtnStruct, result_proc((void *)resultproc),
|
||||
(long)userDataPtr);
|
||||
}
|
||||
|
||||
/* Writes an address as a dotted number. */
|
||||
OSErr AddrToStr(unsigned long addr, char *addrStr) {
|
||||
if (!dnr)
|
||||
return notOpenErr;
|
||||
return dnr_call(ADDRTOSTR, (long)addr, (long)addrStr, 0, 0);
|
||||
}
|
||||
|
||||
/* Calls resultproc for each entry of the resolver's cache. */
|
||||
OSErr EnumCache(EnumResultUPP resultproc, char *userDataPtr) {
|
||||
if (!dnr)
|
||||
return notOpenErr;
|
||||
return dnr_call(ENUMCACHE, result_proc((void *)resultproc), (long)userDataPtr, 0, 0);
|
||||
}
|
||||
|
||||
/* Finds the name of an address. */
|
||||
OSErr AddrToName(ip_addr addr, hostInfo *rtnStruct, ResultUPP resultproc, char *userDataPtr) {
|
||||
if (!dnr)
|
||||
return notOpenErr;
|
||||
return dnr_call(ADDRTONAME, (long)addr, (long)rtnStruct, result_proc((void *)resultproc),
|
||||
(long)userDataPtr);
|
||||
}
|
||||
|
||||
/* Finds the host information record of a name. */
|
||||
OSErr HInfo(char *hostName, returnRec *returnRecPtr, ResultProc2UPP resultProc, char *userDataPtr) {
|
||||
if (!dnr)
|
||||
return notOpenErr;
|
||||
return dnr_call(HXINFO, (long)hostName, (long)returnRecPtr, result_proc((void *)resultProc),
|
||||
(long)userDataPtr);
|
||||
}
|
||||
|
||||
/* Finds the mail exchange record of a name. */
|
||||
OSErr MXInfo(char *hostName, returnRec *returnRecPtr, ResultProc2UPP resultProc, char *userDataPtr) {
|
||||
if (!dnr)
|
||||
return notOpenErr;
|
||||
return dnr_call(MXINFO, (long)hostName, (long)returnRecPtr, result_proc((void *)resultProc),
|
||||
(long)userDataPtr);
|
||||
}
|
||||
@@ -91,4 +91,9 @@ int __mac_fifo_open(const char *path, int flags);
|
||||
way to wait for a pipe, a socket or a driver. */
|
||||
void __mac_wait(void);
|
||||
|
||||
/* Calls fn, a function of the MPW C calling convention (68k), with
|
||||
nargs 4-byte arguments, and keeps the registers that clang keeps.
|
||||
Gives D0. In aslm.c. */
|
||||
long __mac_mpw_call(const void *fn, int nargs, const long *args);
|
||||
|
||||
#endif
|
||||
+12
-102
@@ -27,6 +27,7 @@
|
||||
#include <MacMemory.h>
|
||||
#include <MixedMode.h>
|
||||
#include <Resources.h>
|
||||
#include <AddressXlation.h>
|
||||
#include "macos.h"
|
||||
#include "socket.h"
|
||||
|
||||
@@ -245,114 +246,23 @@ int inet_pton(int family, const char *text, void *addr) {
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
/* The resolver of MacTCP and Open Transport */
|
||||
/* The resolver of MacTCP and Open Transport (dnr.c) */
|
||||
|
||||
#define OPENRESOLVER 1
|
||||
#define CLOSERESOLVER 2
|
||||
#define STRTOADDR 3
|
||||
#define ADDRTONAME 6
|
||||
|
||||
#pragma options align=mac68k
|
||||
struct host_info {
|
||||
long rtnCode;
|
||||
char cname[255];
|
||||
unsigned long addr[4];
|
||||
};
|
||||
#pragma options align=reset
|
||||
|
||||
/* A Pascal result procedure in 68k code that does nothing: it takes
|
||||
its two arguments off the stack. The caller looks at rtnCode.
|
||||
movea.l (sp)+,a0 ; addq.l #8,sp ; jmp (a0) */
|
||||
static const unsigned short no_result[] = {0x205F, 0x508F, 0x4ED0};
|
||||
|
||||
static Handle dnr; /* the resolver's code, locked */
|
||||
static int dnr_state; /* 0 not tried, 1 open, -1 not there */
|
||||
|
||||
/* Calls the resolver with a selector and up to four long arguments. */
|
||||
static long dnr_call(long sel, long a, long b, long c, long d) {
|
||||
#if defined(__powerpc__)
|
||||
/* C on the stack, a 4-byte result, five 4-byte arguments. */
|
||||
const ProcInfoType info = 1 | (3 << 4) | (3 << 6) | (3 << 8) | (3 << 10) | (3 << 12) | (3 << 14);
|
||||
return CallUniversalProc((UniversalProcPtr)*dnr, info, sel, a, b, c, d);
|
||||
#else
|
||||
typedef long (*proc)(long, long, long, long, long);
|
||||
return ((proc)*dnr)(sel, a, b, c, d);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Looks in one folder for the MacTCP control panel (type 'cdev', creator
|
||||
'ztcp' or 'mtcp') and opens its resource fork. Gives its reference
|
||||
number, or -1. */
|
||||
static short open_panel(short vol, long dir) {
|
||||
CInfoPBRec pb;
|
||||
Str255 name;
|
||||
short i;
|
||||
for (i = 1;; i++) {
|
||||
OSType type, creator;
|
||||
memset(&pb, 0, sizeof pb);
|
||||
pb.hFileInfo.ioNamePtr = name;
|
||||
pb.hFileInfo.ioVRefNum = vol;
|
||||
pb.hFileInfo.ioDirID = dir;
|
||||
pb.hFileInfo.ioFDirIndex = i;
|
||||
if (PBGetCatInfoSync(&pb) != noErr)
|
||||
return -1;
|
||||
if (pb.hFileInfo.ioFlAttrib & 0x10)
|
||||
continue;
|
||||
type = pb.hFileInfo.ioFlFndrInfo.fdType;
|
||||
creator = pb.hFileInfo.ioFlFndrInfo.fdCreator;
|
||||
if (type == 'cdev' && (creator == 'ztcp' || creator == 'mtcp')) {
|
||||
short ref = HOpenResFile(vol, dir, name, fsRdPerm);
|
||||
if (ref != -1)
|
||||
return ref;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Closes the resolver when the program ends. */
|
||||
static void dnr_close(void) {
|
||||
if (dnr_state > 0)
|
||||
dnr_call(CLOSERESOLVER, 0, 0, 0, 0);
|
||||
dnr_state = -1;
|
||||
}
|
||||
|
||||
/* Loads and opens the resolver the first time. Gives 0, or -1. */
|
||||
/* Opens the resolver the first time. Gives 0, or -1. */
|
||||
static int dnr_open(void) {
|
||||
static const OSType folders[] = {kControlPanelFolderType, kExtensionFolderType, kSystemFolderType};
|
||||
short ref = -1, vol;
|
||||
long dir;
|
||||
unsigned i;
|
||||
if (dnr_state)
|
||||
return dnr_state > 0 ? 0 : -1;
|
||||
dnr_state = -1;
|
||||
if (__mac_ip_address() == 0)
|
||||
static int failed;
|
||||
if (failed)
|
||||
return -1;
|
||||
for (i = 0; ref == -1 && i < sizeof folders / sizeof folders[0]; i++)
|
||||
if (FindFolder(kOnSystemDisk, folders[i], 0, &vol, &dir) == noErr)
|
||||
ref = open_panel(vol, dir);
|
||||
/* Open Transport keeps the resolver in the System file. */
|
||||
dnr = ref != -1 ? Get1IndResource('dnrp', 1) : 0;
|
||||
if (!dnr)
|
||||
dnr = GetIndResource('dnrp', 1);
|
||||
if (dnr)
|
||||
DetachResource(dnr);
|
||||
if (ref != -1)
|
||||
CloseResFile(ref);
|
||||
if (!dnr)
|
||||
return -1;
|
||||
HLock(dnr);
|
||||
if (dnr_call(OPENRESOLVER, 0, 0, 0, 0) != noErr) {
|
||||
DisposeHandle(dnr);
|
||||
dnr = 0;
|
||||
if (OpenResolver(NULL) != noErr) {
|
||||
failed = 1;
|
||||
return -1;
|
||||
}
|
||||
dnr_state = 1;
|
||||
atexit(dnr_close);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Waits for a resolver call: its rtnCode stays cacheFault (or
|
||||
inProgress) until it ends. */
|
||||
static long dnr_wait(long rc, volatile struct host_info *hi) {
|
||||
static long dnr_wait(long rc, volatile hostInfo *hi) {
|
||||
if (rc != cacheFault)
|
||||
return rc;
|
||||
while (hi->rtnCode == cacheFault || hi->rtnCode == inProgress)
|
||||
@@ -363,7 +273,7 @@ static long dnr_wait(long rc, volatile struct host_info *hi) {
|
||||
/* Finds the addresses of a name with the resolver. Gives how many (up
|
||||
to max), or 0 with h_errno set. */
|
||||
static int dnr_lookup(const char *name, in_addr_t *out, int max, char *cname, size_t cnamelen) {
|
||||
static struct host_info hi;
|
||||
static hostInfo hi;
|
||||
long rc;
|
||||
int n = 0;
|
||||
if (dnr_open() < 0) {
|
||||
@@ -372,7 +282,7 @@ static int dnr_lookup(const char *name, in_addr_t *out, int max, char *cname, si
|
||||
}
|
||||
memset(&hi, 0, sizeof hi);
|
||||
hi.rtnCode = cacheFault;
|
||||
rc = dnr_call(STRTOADDR, (long)name, (long)&hi, (long)no_result, 0);
|
||||
rc = StrToAddr((char *)name, &hi, NULL, NULL);
|
||||
rc = dnr_wait(rc, &hi);
|
||||
if (rc != noErr) {
|
||||
h_errno = rc == noNameServer || rc == noAnsErr ? TRY_AGAIN : HOST_NOT_FOUND;
|
||||
@@ -394,13 +304,13 @@ static int dnr_lookup(const char *name, in_addr_t *out, int max, char *cname, si
|
||||
|
||||
/* Finds the name of an address with the resolver. Gives 0, or -1. */
|
||||
static int dnr_name(in_addr_t addr, char *name, size_t len) {
|
||||
static struct host_info hi;
|
||||
static hostInfo hi;
|
||||
long rc;
|
||||
if (dnr_open() < 0)
|
||||
return -1;
|
||||
memset(&hi, 0, sizeof hi);
|
||||
hi.rtnCode = cacheFault;
|
||||
rc = dnr_call(ADDRTONAME, (long)addr, (long)&hi, (long)no_result, 0);
|
||||
rc = AddrToName(addr, &hi, NULL, NULL);
|
||||
if (dnr_wait(rc, &hi) != noErr || !hi.cname[0])
|
||||
return -1;
|
||||
strncpy(name, hi.cname, len - 1);
|
||||
|
||||
@@ -0,0 +1,161 @@
|
||||
/* Open Transport on PowerPC: the client calls that Apple's
|
||||
* OpenTransportAppPPC.o and OpenTptInetPPC.o supplied.
|
||||
*
|
||||
* Open Transport's shared libraries (OTClientLib, OTClientUtilLib,
|
||||
* OTUtilityLib, OTInetClientLib) export most calls by their own names.
|
||||
* The calls that open a provider, allocate memory or start Open
|
||||
* Transport are exported only as "Priv" forms, which take one more
|
||||
* argument: the address of the program's client record. This file
|
||||
* keeps that record and gives the public names (InitOpenTransport,
|
||||
* OTOpenEndpoint, ...).
|
||||
*
|
||||
* The client record is 36 bytes. The program fills three fields before
|
||||
* InitOpenTransportPriv; Open Transport uses the rest:
|
||||
* 8 the address of a long that Open Transport keeps for the program
|
||||
* 12 the address of 8 bytes that Open Transport keeps for the program
|
||||
* 16 a routine descriptor that Open Transport installs as a patch on
|
||||
* ExitToShell; the patch calls OTExitPatchPriv, so that Open
|
||||
* Transport closes the program's providers when it quits
|
||||
* 32 1 (a byte)
|
||||
* Apple's application glue passes 3 to InitOpenTransportPriv, and 0
|
||||
* for the utilities only.
|
||||
*
|
||||
* On 68k, ot68k.c implements the same calls over MacTCP.
|
||||
*
|
||||
* Copyright (C) clang-retro contributors.
|
||||
* SPDX-License-Identifier: AGPL-3.0-only */
|
||||
#if defined(__powerpc__)
|
||||
#include <Gestalt.h>
|
||||
#include <MixedMode.h>
|
||||
#include <Multiverse.h>
|
||||
#include <OpenTransport.h>
|
||||
#include <OpenTransportProviders.h>
|
||||
|
||||
/* The forms that Open Transport exports. They are weak: a program that
|
||||
runs without Open Transport loads, and InitOpenTransport fails. */
|
||||
#define PRIV(ret, name, args) extern ret name args __asm__("__imp_" #name) __attribute__((weak))
|
||||
PRIV(OSStatus, InitOpenTransportPriv, (UInt32 flags, void *client));
|
||||
PRIV(void, CloseOpenTransportPriv, (void *client));
|
||||
PRIV(void, OTExitPatchPriv, (void *client));
|
||||
PRIV(OSStatus, OTRegisterAsClientPriv, (OTClientName name, OTNotifyUPP proc, void *client));
|
||||
PRIV(OSStatus, OTUnregisterAsClientPriv, (void *client));
|
||||
PRIV(void *, OTAllocMemPriv, (OTByteCount size, void *client));
|
||||
PRIV(void *, OTAllocPriv,
|
||||
(EndpointRef ref, OTStructType structType, OTFieldsType fields, OSStatus *err, void *client));
|
||||
PRIV(EndpointRef, OTOpenEndpointPriv,
|
||||
(OTConfigurationRef config, OTOpenFlags oflag, TEndpointInfo *info, OSStatus *err, void *client));
|
||||
PRIV(OSStatus, OTAsyncOpenEndpointPriv,
|
||||
(OTConfigurationRef config, OTOpenFlags oflag, TEndpointInfo *info, OTNotifyUPP proc,
|
||||
void *contextPtr, void *client));
|
||||
PRIV(OSStatus, OTCloseProviderPriv, (ProviderRef ref, void *client));
|
||||
PRIV(long, OTCreateDeferredTaskPriv, (OTProcessUPP proc, void *contextInfo, void *client));
|
||||
PRIV(long, OTCreateSystemTaskPriv, (OTProcessUPP proc, void *contextInfo, void *client));
|
||||
PRIV(InetSvcRef, OTOpenInternetServicesPriv,
|
||||
(OTConfigurationRef cfig, OTOpenFlags oflag, OSStatus *err, void *client));
|
||||
PRIV(OSStatus, OTAsyncOpenInternetServicesPriv,
|
||||
(OTConfigurationRef cfig, OTOpenFlags oflag, OTNotifyUPP proc, void *contextPtr, void *client));
|
||||
|
||||
/* The values that InitOpenTransportPriv takes. */
|
||||
enum { INIT_UTILITIES = 0, INIT_APPLICATION = 3 };
|
||||
|
||||
/* The client record and the storage that its fields point to. */
|
||||
static struct {
|
||||
void *info; /* 0: Open Transport's client information */
|
||||
void *context; /* 4 */
|
||||
long *slot; /* 8 */
|
||||
long *data; /* 12 */
|
||||
RoutineDescriptor *exit_patch; /* 16 */
|
||||
long reserved[3]; /* 20 */
|
||||
unsigned char flags[4]; /* 32 */
|
||||
} client;
|
||||
static long client_slot;
|
||||
static long client_data[2];
|
||||
|
||||
/* The ExitToShell patch that Open Transport installs: it closes the
|
||||
program's providers. Gives 0. */
|
||||
static long exit_patch(void) {
|
||||
OTExitPatchPriv(&client);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* A routine descriptor for exit_patch: PowerPC code, a Pascal function
|
||||
with a 4-byte result and no arguments (procInfo 0x30). */
|
||||
static RoutineDescriptor exit_patch_rd = {
|
||||
0xAAFE, 7, 0, 0, 0, 0, 0, {{0x30, 0, 1, 4, (ProcPtr)exit_patch, 0, 0}}};
|
||||
|
||||
/* Starts Open Transport with the flags that InitOpenTransportPriv
|
||||
takes. Gives kOTNotFoundErr when Open Transport is not there. */
|
||||
static OSStatus start(UInt32 flags) {
|
||||
long resp;
|
||||
if (Gestalt(gestaltOpenTpt, &resp) != noErr || !(resp & gestaltOpenTptPresentMask))
|
||||
return kOTNotFoundErr;
|
||||
if (!InitOpenTransportPriv)
|
||||
return kOTNotFoundErr;
|
||||
client.slot = &client_slot;
|
||||
client.data = client_data;
|
||||
client.exit_patch = &exit_patch_rd;
|
||||
client.flags[0] = 1;
|
||||
return InitOpenTransportPriv(flags, &client);
|
||||
}
|
||||
|
||||
/* Starts Open Transport for the program. */
|
||||
OSStatus InitOpenTransport(void) { return start(INIT_APPLICATION); }
|
||||
|
||||
/* Starts the utility calls of Open Transport only. */
|
||||
OSStatus InitOpenTransportUtilities(void) { return start(INIT_UTILITIES); }
|
||||
|
||||
/* Ends the program's use of Open Transport and closes its providers. */
|
||||
void CloseOpenTransport(void) { CloseOpenTransportPriv(&client); }
|
||||
|
||||
/* Asks for the client events of Open Transport. */
|
||||
OSStatus OTRegisterAsClient(OTClientName name, OTNotifyUPP proc) {
|
||||
return OTRegisterAsClientPriv(name, proc, &client);
|
||||
}
|
||||
|
||||
/* Stops the client events. */
|
||||
OSStatus OTUnregisterAsClient(void) { return OTUnregisterAsClientPriv(&client); }
|
||||
|
||||
/* Allocates memory from Open Transport's pool for the program. */
|
||||
void *OTAllocMem(OTByteCount size) { return OTAllocMemPriv(size, &client); }
|
||||
|
||||
/* Allocates an XTI record with buffers of the endpoint's sizes. */
|
||||
void *OTAlloc(EndpointRef ref, OTStructType structType, OTFieldsType fields, OSStatus *err) {
|
||||
return OTAllocPriv(ref, structType, fields, err, &client);
|
||||
}
|
||||
|
||||
/* Opens an endpoint and waits until it is open. */
|
||||
EndpointRef OTOpenEndpoint(OTConfigurationRef config, OTOpenFlags oflag, TEndpointInfo *info,
|
||||
OSStatus *err) {
|
||||
return OTOpenEndpointPriv(config, oflag, info, err, &client);
|
||||
}
|
||||
|
||||
/* Opens an endpoint; proc gets T_OPENCOMPLETE. */
|
||||
OSStatus OTAsyncOpenEndpoint(OTConfigurationRef config, OTOpenFlags oflag, TEndpointInfo *info,
|
||||
OTNotifyUPP proc, void *contextPtr) {
|
||||
return OTAsyncOpenEndpointPriv(config, oflag, info, proc, contextPtr, &client);
|
||||
}
|
||||
|
||||
/* Closes an endpoint or other provider. */
|
||||
OSStatus OTCloseProvider(ProviderRef ref) { return OTCloseProviderPriv(ref, &client); }
|
||||
|
||||
/* Makes a deferred task. Gives its reference, or 0. */
|
||||
long OTCreateDeferredTask(OTProcessUPP proc, void *contextInfo) {
|
||||
return OTCreateDeferredTaskPriv(proc, contextInfo, &client);
|
||||
}
|
||||
|
||||
/* Makes a system task. Gives its reference, or 0. */
|
||||
long OTCreateSystemTask(OTProcessUPP proc, void *contextInfo) {
|
||||
return OTCreateSystemTaskPriv(proc, contextInfo, &client);
|
||||
}
|
||||
|
||||
/* Opens the Internet services provider and waits until it is open. */
|
||||
InetSvcRef OTOpenInternetServices(OTConfigurationRef cfig, OTOpenFlags oflag, OSStatus *err) {
|
||||
return OTOpenInternetServicesPriv(cfig, oflag, err, &client);
|
||||
}
|
||||
|
||||
/* Opens the Internet services provider; proc gets T_OPENCOMPLETE. */
|
||||
OSStatus OTAsyncOpenInternetServices(OTConfigurationRef cfig, OTOpenFlags oflag, OTNotifyUPP proc,
|
||||
void *contextPtr) {
|
||||
return OTAsyncOpenInternetServicesPriv(cfig, oflag, proc, contextPtr, &client);
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,100 @@
|
||||
/* The Open Transport calls that have two forms on 68k: one over native
|
||||
* Open Transport (otnative.c) and one over MacTCP (ot68k.c).
|
||||
*
|
||||
* ot68k.c includes this file before <OpenTransport.h>, so that its
|
||||
* forms get the names __otsock_X. otnative.c gives the public names:
|
||||
* each one calls the native form when InitOpenTransport started native
|
||||
* Open Transport, else the __otsock_ form.
|
||||
*
|
||||
* OT68K_CALLS lists the calls. Each entry is X(name).
|
||||
*
|
||||
* Copyright (C) clang-retro contributors.
|
||||
* SPDX-License-Identifier: AGPL-3.0-only */
|
||||
#ifndef OT68K_NAMES_H
|
||||
#define OT68K_NAMES_H
|
||||
|
||||
#define OT68K_CALLS(X) \
|
||||
X(InitOpenTransport) X(InitOpenTransportUtilities) X(CloseOpenTransport) \
|
||||
X(OTRegisterAsClient) X(OTUnregisterAsClient) X(OTAllocMem) X(OTFreeMem) X(OTAlloc) X(OTFree) \
|
||||
X(OTIdle) X(OTCreateConfiguration) X(OTCloneConfiguration) X(OTDestroyConfiguration) \
|
||||
X(OTOpenEndpoint) X(OTAsyncOpenEndpoint) X(OTOpenInternetServices) \
|
||||
X(OTAsyncOpenInternetServices) X(OTCloseProvider) X(OTSetSynchronous) X(OTSetAsynchronous) \
|
||||
X(OTIsSynchronous) X(OTSetBlocking) X(OTSetNonBlocking) X(OTIsBlocking) X(OTInstallNotifier) \
|
||||
X(OTRemoveNotifier) X(OTUseSyncIdleEvents) X(OTEnterNotifier) X(OTLeaveNotifier) X(OTAckSends) \
|
||||
X(OTDontAckSends) X(OTIsAckingSends) X(OTCancelSynchronousCalls) X(OTIoctl) \
|
||||
X(OTGetProviderPortRef) X(OTGetEndpointInfo) X(OTGetEndpointState) X(OTLook) \
|
||||
X(OTCountDataBytes) X(OTGetProtAddress) X(OTResolveAddress) X(OTOptionManagement) X(OTBind) \
|
||||
X(OTUnbind) X(OTConnect) X(OTRcvConnect) X(OTListen) X(OTAccept) X(OTSndDisconnect) \
|
||||
X(OTSndOrderlyDisconnect) X(OTRcvDisconnect) X(OTRcvOrderlyDisconnect) X(OTRcv) X(OTSnd) \
|
||||
X(OTSndUData) X(OTRcvUData) X(OTRcvUDErr) X(OTInetGetInterfaceInfo) \
|
||||
X(OTInetGetSecondaryAddresses) X(OTInetStringToAddress) X(OTInetAddressToName) \
|
||||
X(OTInetSysInfo) X(OTInetMailExchange) X(OTInetQuery)
|
||||
|
||||
#ifdef OT68K_RENAME
|
||||
#define InitOpenTransport __otsock_InitOpenTransport
|
||||
#define InitOpenTransportUtilities __otsock_InitOpenTransportUtilities
|
||||
#define CloseOpenTransport __otsock_CloseOpenTransport
|
||||
#define OTRegisterAsClient __otsock_OTRegisterAsClient
|
||||
#define OTUnregisterAsClient __otsock_OTUnregisterAsClient
|
||||
#define OTAllocMem __otsock_OTAllocMem
|
||||
#define OTFreeMem __otsock_OTFreeMem
|
||||
#define OTAlloc __otsock_OTAlloc
|
||||
#define OTFree __otsock_OTFree
|
||||
#define OTIdle __otsock_OTIdle
|
||||
#define OTCreateConfiguration __otsock_OTCreateConfiguration
|
||||
#define OTCloneConfiguration __otsock_OTCloneConfiguration
|
||||
#define OTDestroyConfiguration __otsock_OTDestroyConfiguration
|
||||
#define OTOpenEndpoint __otsock_OTOpenEndpoint
|
||||
#define OTAsyncOpenEndpoint __otsock_OTAsyncOpenEndpoint
|
||||
#define OTOpenInternetServices __otsock_OTOpenInternetServices
|
||||
#define OTAsyncOpenInternetServices __otsock_OTAsyncOpenInternetServices
|
||||
#define OTCloseProvider __otsock_OTCloseProvider
|
||||
#define OTSetSynchronous __otsock_OTSetSynchronous
|
||||
#define OTSetAsynchronous __otsock_OTSetAsynchronous
|
||||
#define OTIsSynchronous __otsock_OTIsSynchronous
|
||||
#define OTSetBlocking __otsock_OTSetBlocking
|
||||
#define OTSetNonBlocking __otsock_OTSetNonBlocking
|
||||
#define OTIsBlocking __otsock_OTIsBlocking
|
||||
#define OTInstallNotifier __otsock_OTInstallNotifier
|
||||
#define OTRemoveNotifier __otsock_OTRemoveNotifier
|
||||
#define OTUseSyncIdleEvents __otsock_OTUseSyncIdleEvents
|
||||
#define OTEnterNotifier __otsock_OTEnterNotifier
|
||||
#define OTLeaveNotifier __otsock_OTLeaveNotifier
|
||||
#define OTAckSends __otsock_OTAckSends
|
||||
#define OTDontAckSends __otsock_OTDontAckSends
|
||||
#define OTIsAckingSends __otsock_OTIsAckingSends
|
||||
#define OTCancelSynchronousCalls __otsock_OTCancelSynchronousCalls
|
||||
#define OTIoctl __otsock_OTIoctl
|
||||
#define OTGetProviderPortRef __otsock_OTGetProviderPortRef
|
||||
#define OTGetEndpointInfo __otsock_OTGetEndpointInfo
|
||||
#define OTGetEndpointState __otsock_OTGetEndpointState
|
||||
#define OTLook __otsock_OTLook
|
||||
#define OTCountDataBytes __otsock_OTCountDataBytes
|
||||
#define OTGetProtAddress __otsock_OTGetProtAddress
|
||||
#define OTResolveAddress __otsock_OTResolveAddress
|
||||
#define OTOptionManagement __otsock_OTOptionManagement
|
||||
#define OTBind __otsock_OTBind
|
||||
#define OTUnbind __otsock_OTUnbind
|
||||
#define OTConnect __otsock_OTConnect
|
||||
#define OTRcvConnect __otsock_OTRcvConnect
|
||||
#define OTListen __otsock_OTListen
|
||||
#define OTAccept __otsock_OTAccept
|
||||
#define OTSndDisconnect __otsock_OTSndDisconnect
|
||||
#define OTSndOrderlyDisconnect __otsock_OTSndOrderlyDisconnect
|
||||
#define OTRcvDisconnect __otsock_OTRcvDisconnect
|
||||
#define OTRcvOrderlyDisconnect __otsock_OTRcvOrderlyDisconnect
|
||||
#define OTRcv __otsock_OTRcv
|
||||
#define OTSnd __otsock_OTSnd
|
||||
#define OTSndUData __otsock_OTSndUData
|
||||
#define OTRcvUData __otsock_OTRcvUData
|
||||
#define OTRcvUDErr __otsock_OTRcvUDErr
|
||||
#define OTInetGetInterfaceInfo __otsock_OTInetGetInterfaceInfo
|
||||
#define OTInetGetSecondaryAddresses __otsock_OTInetGetSecondaryAddresses
|
||||
#define OTInetStringToAddress __otsock_OTInetStringToAddress
|
||||
#define OTInetAddressToName __otsock_OTInetAddressToName
|
||||
#define OTInetSysInfo __otsock_OTInetSysInfo
|
||||
#define OTInetMailExchange __otsock_OTInetMailExchange
|
||||
#define OTInetQuery __otsock_OTInetQuery
|
||||
#endif
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,820 @@
|
||||
/* Open Transport on 68k: the calls to native Open Transport.
|
||||
*
|
||||
* Open Transport's 68k client code is in Apple Shared Library Manager
|
||||
* (ASLM) libraries. Three function sets have the client calls:
|
||||
* "OTClnt$LclUtils" start and end, memory, configurations
|
||||
* "OTClnt$LclClnt" providers and endpoints
|
||||
* "ot:inet$LclInetClnt" the Internet services
|
||||
* The stubs below bind to them through aslm.c. The number of a stub is
|
||||
* the place of the function in the export table of its set (Open
|
||||
* Transport 1.1 to 1.3 have the same tables).
|
||||
*
|
||||
* InitOpenTransport starts native Open Transport when ASLM and Open
|
||||
* Transport are installed. Then each public call goes to the native
|
||||
* function. Else InitOpenTransport starts the MacTCP form (ot68k.c),
|
||||
* and each public call goes to the __otsock_ form.
|
||||
*
|
||||
* The functions with names in capitals use the Pascal calling
|
||||
* convention: ASLMCallPascal calls them. The others use MPW's C calling
|
||||
* convention: ASLMCallC calls them, because MPW code can change D2 and
|
||||
* gives a pointer result in D0 (clang expects A0).
|
||||
*
|
||||
* Native Open Transport calls a notifier with the Pascal calling
|
||||
* convention. The SDK's notifiers use the C calling convention, so the
|
||||
* library gives Open Transport a Pascal trampoline and a slot that
|
||||
* holds the program's notifier and context.
|
||||
*
|
||||
* The client record (36 bytes) is the same as on PowerPC (ot.c), with
|
||||
* these 68k values, as Apple's application glue sets them:
|
||||
* 8 the address of the program's ASLM client (aslm.c)
|
||||
* 12 the address of ASLM's global record (aslm.c)
|
||||
* 28 1 when the glue started ASLM
|
||||
* 30 1 when the glue loaded "OTClnt$LclUtils"
|
||||
* 32 1 for an application
|
||||
*
|
||||
* Copyright (C) clang-retro contributors.
|
||||
* SPDX-License-Identifier: AGPL-3.0-only */
|
||||
#if defined(__m68k__)
|
||||
#include <Gestalt.h>
|
||||
#include <LibraryManager.h>
|
||||
#include <Multiverse.h>
|
||||
#include <OpenTransport.h>
|
||||
#include <OpenTransportProviders.h>
|
||||
#include "ot68k-names.h"
|
||||
|
||||
/* The MacTCP forms (ot68k.c). */
|
||||
#define SOCK_FORM(name) extern __typeof__(name) __otsock_##name;
|
||||
OT68K_CALLS(SOCK_FORM)
|
||||
|
||||
extern void *__aslm_client;
|
||||
extern char *__aslm_root;
|
||||
|
||||
/* The function sets, with the versions that Apple's glue asks for. */
|
||||
static ASLM_FUNCTION_SET(utils, "OTClnt$LclUtils", 0x0100, 0x0100);
|
||||
static ASLM_FUNCTION_SET(clnt, "OTClnt$LclClnt", 0x0100, 0x0100);
|
||||
static ASLM_FUNCTION_SET(inet, "ot:inet$LclInetClnt", 0x0300, 0x0300);
|
||||
|
||||
/* "OTClnt$LclUtils" */
|
||||
ASLM_FUNCTION(__otn_AllocMemPriv, utils, 1);
|
||||
ASLM_FUNCTION(__otn_InitPriv, utils, 3);
|
||||
ASLM_FUNCTION(__otn_ClosePriv, utils, 4);
|
||||
ASLM_FUNCTION(__otn_RegisterAsClientPriv, utils, 5);
|
||||
ASLM_FUNCTION(__otn_UnregisterAsClientPriv, utils, 6);
|
||||
ASLM_FUNCTION(__otn_CREATECONFIGURATION, utils, 16);
|
||||
ASLM_FUNCTION(__otn_DESTROYCONFIGURATION, utils, 17);
|
||||
ASLM_FUNCTION(__otn_CLONECONFIGURATION, utils, 18);
|
||||
ASLM_FUNCTION(__otn_FreeMem, utils, 31);
|
||||
/* "OTClnt$LclClnt" */
|
||||
ASLM_FUNCTION(__otn_IDLE, clnt, 1);
|
||||
ASLM_FUNCTION(__otn_CloseProviderPriv, clnt, 9);
|
||||
ASLM_FUNCTION(__otn_SETNONBLOCKING, clnt, 10);
|
||||
ASLM_FUNCTION(__otn_SETBLOCKING, clnt, 11);
|
||||
ASLM_FUNCTION(__otn_ISBLOCKING, clnt, 12);
|
||||
ASLM_FUNCTION(__otn_SETSYNCHRONOUS, clnt, 13);
|
||||
ASLM_FUNCTION(__otn_SETASYNCHRONOUS, clnt, 14);
|
||||
ASLM_FUNCTION(__otn_ISSYNCHRONOUS, clnt, 15);
|
||||
ASLM_FUNCTION(__otn_DONTACKSENDS, clnt, 16);
|
||||
ASLM_FUNCTION(__otn_ACKSENDS, clnt, 17);
|
||||
ASLM_FUNCTION(__otn_ISACKINGSENDS, clnt, 18);
|
||||
ASLM_FUNCTION(__otn_CANCELSYNCHRONOUSCALLS, clnt, 19);
|
||||
ASLM_FUNCTION(__otn_INSTALLNOTIFIER, clnt, 20);
|
||||
ASLM_FUNCTION(__otn_REMOVENOTIFIER, clnt, 21);
|
||||
ASLM_FUNCTION(__otn_IOCTL, clnt, 22);
|
||||
ASLM_FUNCTION(__otn_OpenEndpointPriv, clnt, 29);
|
||||
ASLM_FUNCTION(__otn_AsyncOpenEndpointPriv, clnt, 30);
|
||||
ASLM_FUNCTION(__otn_GETENDPOINTINFO, clnt, 31);
|
||||
ASLM_FUNCTION(__otn_GETPROTADDRESS, clnt, 32);
|
||||
ASLM_FUNCTION(__otn_RESOLVEADDRESS, clnt, 33);
|
||||
ASLM_FUNCTION(__otn_GETENDPOINTSTATE, clnt, 34);
|
||||
ASLM_FUNCTION(__otn_AllocPriv, clnt, 35);
|
||||
ASLM_FUNCTION(__otn_FREE, clnt, 36);
|
||||
ASLM_FUNCTION(__otn_LOOK, clnt, 37);
|
||||
ASLM_FUNCTION(__otn_COUNTDATABYTES, clnt, 39);
|
||||
ASLM_FUNCTION(__otn_OPTIONMANAGEMENT, clnt, 40);
|
||||
ASLM_FUNCTION(__otn_BIND, clnt, 41);
|
||||
ASLM_FUNCTION(__otn_UNBIND, clnt, 42);
|
||||
ASLM_FUNCTION(__otn_CONNECT, clnt, 43);
|
||||
ASLM_FUNCTION(__otn_RCVCONNECT, clnt, 44);
|
||||
ASLM_FUNCTION(__otn_LISTEN, clnt, 45);
|
||||
ASLM_FUNCTION(__otn_ACCEPT, clnt, 46);
|
||||
ASLM_FUNCTION(__otn_SNDDISCONNECT, clnt, 47);
|
||||
ASLM_FUNCTION(__otn_SNDORDERLYDISCONNECT, clnt, 48);
|
||||
ASLM_FUNCTION(__otn_RCVDISCONNECT, clnt, 49);
|
||||
ASLM_FUNCTION(__otn_RCVORDERLYDISCONNECT, clnt, 50);
|
||||
ASLM_FUNCTION(__otn_SND, clnt, 51);
|
||||
ASLM_FUNCTION(__otn_RCV, clnt, 52);
|
||||
ASLM_FUNCTION(__otn_SNDUDATA, clnt, 53);
|
||||
ASLM_FUNCTION(__otn_RCVUDATA, clnt, 54);
|
||||
ASLM_FUNCTION(__otn_RCVUDERR, clnt, 55);
|
||||
ASLM_FUNCTION(__otn_GETPROVIDERPORTREF, clnt, 72);
|
||||
ASLM_FUNCTION(__otn_USESYNCIDLEEVENTS, clnt, 74);
|
||||
ASLM_FUNCTION(__otn_ENTERNOTIFIER, clnt, 75);
|
||||
ASLM_FUNCTION(__otn_LEAVENOTIFIER, clnt, 76);
|
||||
/* "ot:inet$LclInetClnt" */
|
||||
ASLM_FUNCTION(__otn_AsyncOpenInternetServicesPriv, inet, 1);
|
||||
ASLM_FUNCTION(__otn_OpenInternetServicesPriv, inet, 2);
|
||||
ASLM_FUNCTION(__otn_INETSTRINGTOADDRESS, inet, 3);
|
||||
ASLM_FUNCTION(__otn_INETADDRESSTONAME, inet, 4);
|
||||
ASLM_FUNCTION(__otn_INETSYSINFO, inet, 5);
|
||||
ASLM_FUNCTION(__otn_INETMAILEXCHANGE, inet, 6);
|
||||
ASLM_FUNCTION(__otn_INETQUERY, inet, 12);
|
||||
|
||||
/* The C functions: ASLMCallC calls them. */
|
||||
extern const char __otn_AllocMemPriv[], __otn_InitPriv[], __otn_ClosePriv[],
|
||||
__otn_RegisterAsClientPriv[], __otn_UnregisterAsClientPriv[], __otn_FreeMem[],
|
||||
__otn_CloseProviderPriv[], __otn_OpenEndpointPriv[], __otn_AsyncOpenEndpointPriv[],
|
||||
__otn_AllocPriv[], __otn_AsyncOpenInternetServicesPriv[], __otn_OpenInternetServicesPriv[];
|
||||
|
||||
/* Calls the C function fn of MPW. */
|
||||
#define CCALL(fn, ...) \
|
||||
({ \
|
||||
const long args_[] = {__VA_ARGS__}; \
|
||||
ASLMCallC(fn, (int)(sizeof args_ / sizeof args_[0]), args_); \
|
||||
})
|
||||
|
||||
/* The Pascal functions: ASLMCallPascal calls them. */
|
||||
extern const char __otn_CREATECONFIGURATION[], __otn_DESTROYCONFIGURATION[],
|
||||
__otn_CLONECONFIGURATION[], __otn_IDLE[], __otn_SETNONBLOCKING[], __otn_SETBLOCKING[],
|
||||
__otn_ISBLOCKING[], __otn_SETSYNCHRONOUS[], __otn_SETASYNCHRONOUS[], __otn_ISSYNCHRONOUS[],
|
||||
__otn_DONTACKSENDS[], __otn_ACKSENDS[], __otn_ISACKINGSENDS[],
|
||||
__otn_CANCELSYNCHRONOUSCALLS[], __otn_INSTALLNOTIFIER[], __otn_REMOVENOTIFIER[],
|
||||
__otn_IOCTL[], __otn_GETENDPOINTINFO[], __otn_GETPROTADDRESS[], __otn_RESOLVEADDRESS[],
|
||||
__otn_GETENDPOINTSTATE[], __otn_FREE[], __otn_LOOK[], __otn_COUNTDATABYTES[],
|
||||
__otn_OPTIONMANAGEMENT[], __otn_BIND[], __otn_UNBIND[], __otn_CONNECT[], __otn_RCVCONNECT[],
|
||||
__otn_LISTEN[], __otn_ACCEPT[], __otn_SNDDISCONNECT[], __otn_SNDORDERLYDISCONNECT[],
|
||||
__otn_RCVDISCONNECT[], __otn_RCVORDERLYDISCONNECT[], __otn_SND[], __otn_RCV[],
|
||||
__otn_SNDUDATA[], __otn_RCVUDATA[], __otn_RCVUDERR[], __otn_GETPROVIDERPORTREF[],
|
||||
__otn_USESYNCIDLEEVENTS[], __otn_ENTERNOTIFIER[], __otn_LEAVENOTIFIER[],
|
||||
__otn_INETSTRINGTOADDRESS[], __otn_INETADDRESSTONAME[], __otn_INETSYSINFO[],
|
||||
__otn_INETMAILEXCHANGE[], __otn_INETQUERY[];
|
||||
|
||||
/* Calls the Pascal function fn with a result of rsize bytes (0, 2 or
|
||||
4). mask has a bit for each 2-byte argument. */
|
||||
#define PCALL(fn, rsize, mask, ...) \
|
||||
({ \
|
||||
const long args_[] = {__VA_ARGS__}; \
|
||||
ASLMCallPascal(fn, (int)(sizeof args_ / sizeof args_[0]), mask, rsize, args_); \
|
||||
})
|
||||
|
||||
/* Calls the Pascal function fn with one 4-byte argument. */
|
||||
#define PCALL1(fn, rsize, a) PCALL(fn, rsize, 0, (long)(a))
|
||||
|
||||
/* Gives the Boolean in a 2-byte Pascal result. */
|
||||
#define PBOOL(r) ((Boolean)(((r) >> 8) & 0xFF) != 0)
|
||||
|
||||
/* The values that InitOpenTransportPriv takes. */
|
||||
enum { INIT_UTILITIES = 0, INIT_APPLICATION = 3 };
|
||||
|
||||
/* The client record. */
|
||||
static struct {
|
||||
void *info; /* 0: Open Transport's client information */
|
||||
void *context; /* 4 */
|
||||
void **client; /* 8 */
|
||||
char **root; /* 12 */
|
||||
long reserved[3]; /* 16 */
|
||||
unsigned char flags[8]; /* 28 */
|
||||
} rec;
|
||||
|
||||
static int native; /* native Open Transport is in use */
|
||||
static int started_aslm; /* this file started ASLM */
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
/* Notifiers */
|
||||
|
||||
/* A slot that holds a notifier of the program. The context that Open
|
||||
Transport gives the trampoline is the address of the slot. */
|
||||
struct nslot {
|
||||
OTNotifyProcPtr proc;
|
||||
void *context;
|
||||
ProviderRef ref; /* the provider, when it is known */
|
||||
int used;
|
||||
};
|
||||
|
||||
#define NSLOTS 64
|
||||
static struct nslot nslots[NSLOTS];
|
||||
static OTNotifyProcPtr client_proc; /* the notifier of OTRegisterAsClient */
|
||||
|
||||
void __otn_trampoline(void);
|
||||
void __otn_client_trampoline(void);
|
||||
void __otn_notify(struct nslot *s, OTEventCode code, OTResult result, void *cookie);
|
||||
void __otn_client_notify(void *context, OTEventCode code, OTResult result, void *cookie);
|
||||
|
||||
/* The Pascal trampolines. Open Transport calls them with (contextPtr,
|
||||
code, result, cookie) and expects them to remove 16 bytes of
|
||||
arguments. They call __otn_notify or __otn_client_notify with the
|
||||
C calling convention. */
|
||||
__asm__(".text\n\t.p2align 1\n\t.globl __otn_trampoline\n__otn_trampoline:\n"
|
||||
"\tlea __otn_notify, %a1\n"
|
||||
"\tbra 1f\n"
|
||||
"\t.globl __otn_client_trampoline\n__otn_client_trampoline:\n"
|
||||
"\tlea __otn_client_notify, %a1\n"
|
||||
"1:\tmove.l (4, %sp), -(%sp)\n" /* cookie */
|
||||
"\tmove.l (12, %sp), -(%sp)\n" /* result */
|
||||
"\tmove.l (20, %sp), -(%sp)\n" /* code */
|
||||
"\tmove.l (28, %sp), -(%sp)\n" /* contextPtr */
|
||||
"\tjsr (%a1)\n"
|
||||
"\tlea (16, %sp), %sp\n"
|
||||
"\tmove.l (%sp)+, %a0\n"
|
||||
"\tlea (16, %sp), %sp\n"
|
||||
"\tjmp (%a0)\n");
|
||||
|
||||
/* Calls the program's notifier of a slot. When an asynchronous open
|
||||
ends, the slot learns its provider. */
|
||||
void __otn_notify(struct nslot *s, OTEventCode code, OTResult result, void *cookie) {
|
||||
if ((code == T_OPENCOMPLETE) && result == kOTNoError && !s->ref)
|
||||
s->ref = (ProviderRef)cookie;
|
||||
if (s->proc)
|
||||
s->proc(s->context, code, result, cookie);
|
||||
}
|
||||
|
||||
/* Calls the program's client notifier. */
|
||||
void __otn_client_notify(void *context, OTEventCode code, OTResult result, void *cookie) {
|
||||
if (client_proc)
|
||||
client_proc(context, code, result, cookie);
|
||||
}
|
||||
|
||||
/* Masks the interrupts and gives the old status register. */
|
||||
static inline short disable(void) {
|
||||
register short sr __asm__("d0");
|
||||
__asm__ volatile(".short 0x40C0, 0x007C, 0x0700" : "=r"(sr) : : "memory");
|
||||
return sr;
|
||||
}
|
||||
|
||||
/* Puts back the status register that disable gave. */
|
||||
static inline void restore(short old) {
|
||||
register short sr __asm__("d0") = old;
|
||||
__asm__ volatile(".short 0x46C0" : : "r"(sr) : "memory");
|
||||
}
|
||||
|
||||
/* Gives a slot for a notifier, or NULL when all slots are in use. */
|
||||
static struct nslot *new_slot(OTNotifyUPP proc, void *context, ProviderRef ref) {
|
||||
struct nslot *found = NULL;
|
||||
short sr = disable();
|
||||
int i;
|
||||
for (i = 0; i < NSLOTS && !found; i++)
|
||||
if (!nslots[i].used) {
|
||||
found = &nslots[i];
|
||||
found->used = 1;
|
||||
}
|
||||
restore(sr);
|
||||
if (found) {
|
||||
found->proc = (OTNotifyProcPtr)proc;
|
||||
found->context = context;
|
||||
found->ref = ref;
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
/* Frees the slots of a provider. */
|
||||
static void free_slots(ProviderRef ref) {
|
||||
int i;
|
||||
for (i = 0; i < NSLOTS; i++)
|
||||
if (nslots[i].used && nslots[i].ref == ref)
|
||||
nslots[i].used = 0;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
/* Start and end */
|
||||
|
||||
/* Starts native Open Transport with the flags of InitOpenTransportPriv.
|
||||
Gives kOTNotFoundErr when ASLM or Open Transport is not there. */
|
||||
static OSStatus start_native(long flags) {
|
||||
long resp;
|
||||
OSStatus err;
|
||||
if (native)
|
||||
return kOTNoError;
|
||||
if (Gestalt(gestaltOpenTpt, &resp) != noErr || !(resp & gestaltOpenTptPresentMask))
|
||||
return kOTNotFoundErr;
|
||||
if (!ASLMPresent())
|
||||
return kOTNotFoundErr;
|
||||
if (!__aslm_client) {
|
||||
/* Apple's application glue: a 1 KB pool in the application zone. */
|
||||
if (InitLibraryManager(kASLMDefaultPoolSize, 3, kASLMDefaultMemory) != noErr)
|
||||
return kOTNotFoundErr;
|
||||
started_aslm = 1;
|
||||
}
|
||||
rec.client = &__aslm_client;
|
||||
rec.root = &__aslm_root;
|
||||
rec.flags[0] = (unsigned char)started_aslm; /* 28 */
|
||||
rec.flags[4] = 1; /* 32: an application */
|
||||
if (ASLMLoadFunctionSet("OTClnt$LclUtils") != noErr)
|
||||
return kOTNotFoundErr;
|
||||
rec.flags[2] = 1; /* 30 */
|
||||
err = (OSStatus)CCALL(__otn_InitPriv, flags, (long)&rec);
|
||||
if (err == kOTNoError)
|
||||
native = 1;
|
||||
return err;
|
||||
}
|
||||
|
||||
/* Gives 1 when the calls go to native Open Transport, 0 when they go
|
||||
to the MacTCP form. For the tests. */
|
||||
int __ot68k_native(void) { return native; }
|
||||
|
||||
/* Starts Open Transport for the program: native Open Transport when it
|
||||
is installed, else Open Transport over MacTCP. */
|
||||
OSStatus InitOpenTransport(void) {
|
||||
if (start_native(INIT_APPLICATION) == kOTNoError)
|
||||
return kOTNoError;
|
||||
return __otsock_InitOpenTransport();
|
||||
}
|
||||
|
||||
/* Starts the utility calls only. */
|
||||
OSStatus InitOpenTransportUtilities(void) {
|
||||
if (start_native(INIT_UTILITIES) == kOTNoError)
|
||||
return kOTNoError;
|
||||
return __otsock_InitOpenTransportUtilities();
|
||||
}
|
||||
|
||||
/* Ends Open Transport for the program and closes its providers. */
|
||||
void CloseOpenTransport(void) {
|
||||
if (native) {
|
||||
CCALL(__otn_ClosePriv, (long)&rec);
|
||||
native = 0;
|
||||
return;
|
||||
}
|
||||
__otsock_CloseOpenTransport();
|
||||
}
|
||||
|
||||
/* Asks for the client events of Open Transport. */
|
||||
OSStatus OTRegisterAsClient(OTClientName name, OTNotifyUPP proc) {
|
||||
if (!native)
|
||||
return __otsock_OTRegisterAsClient(name, proc);
|
||||
client_proc = (OTNotifyProcPtr)proc;
|
||||
return (OSStatus)CCALL(__otn_RegisterAsClientPriv, (long)name, (long)__otn_client_trampoline,
|
||||
(long)&rec);
|
||||
}
|
||||
|
||||
/* Stops the client events. */
|
||||
OSStatus OTUnregisterAsClient(void) {
|
||||
if (!native)
|
||||
return __otsock_OTUnregisterAsClient();
|
||||
client_proc = NULL;
|
||||
return (OSStatus)CCALL(__otn_UnregisterAsClientPriv, (long)&rec);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
/* Memory, configurations and idle time */
|
||||
|
||||
/* Allocates memory; a notifier can call it. */
|
||||
void *OTAllocMem(OTByteCount size) {
|
||||
return native ? (void *)CCALL(__otn_AllocMemPriv, (long)size, (long)&rec) : __otsock_OTAllocMem(size);
|
||||
}
|
||||
|
||||
/* Frees memory from OTAllocMem. */
|
||||
void OTFreeMem(void *mem) {
|
||||
if (native)
|
||||
CCALL(__otn_FreeMem, (long)mem);
|
||||
else
|
||||
__otsock_OTFreeMem(mem);
|
||||
}
|
||||
|
||||
/* Allocates an XTI record with buffers of the endpoint's sizes. */
|
||||
void *OTAlloc(EndpointRef ref, OTStructType structType, OTFieldsType fields, OSStatus *err) {
|
||||
if (!native)
|
||||
return __otsock_OTAlloc(ref, structType, fields, err);
|
||||
return (void *)CCALL(__otn_AllocPriv, (long)ref, (long)structType, (long)fields, (long)err,
|
||||
(long)&rec);
|
||||
}
|
||||
|
||||
/* Frees a record from OTAlloc. */
|
||||
OTResult OTFree(void *ptr, OTStructType structType) {
|
||||
if (!native)
|
||||
return __otsock_OTFree(ptr, structType);
|
||||
return (OTResult)PCALL(__otn_FREE, 4, 0, (long)ptr, (long)structType);
|
||||
}
|
||||
|
||||
/* Lets the notifiers and the other programs run. Also runs the
|
||||
deferred and system tasks (ot68k.c). */
|
||||
void OTIdle(void) {
|
||||
if (native)
|
||||
ASLMCallPascal(__otn_IDLE, 0, 0, 0, NULL);
|
||||
__otsock_OTIdle();
|
||||
}
|
||||
|
||||
/* Makes a configuration from a path such as "tcp". */
|
||||
OTConfigurationRef OTCreateConfiguration(const char *path) {
|
||||
if (!native)
|
||||
return __otsock_OTCreateConfiguration(path);
|
||||
return (OTConfigurationRef)PCALL1(__otn_CREATECONFIGURATION, 4, path);
|
||||
}
|
||||
|
||||
/* Copies a configuration. */
|
||||
OTConfigurationRef OTCloneConfiguration(OTConfigurationRef cfig) {
|
||||
if (!native)
|
||||
return __otsock_OTCloneConfiguration(cfig);
|
||||
return (OTConfigurationRef)PCALL1(__otn_CLONECONFIGURATION, 4, cfig);
|
||||
}
|
||||
|
||||
/* Frees a configuration that no open call used. */
|
||||
void OTDestroyConfiguration(OTConfigurationRef cfig) {
|
||||
if (!native)
|
||||
__otsock_OTDestroyConfiguration(cfig);
|
||||
else
|
||||
PCALL1(__otn_DESTROYCONFIGURATION, 0, cfig);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
/* Providers */
|
||||
|
||||
/* Opens an endpoint and waits until it is open. */
|
||||
EndpointRef OTOpenEndpoint(OTConfigurationRef config, OTOpenFlags oflag, TEndpointInfo *info,
|
||||
OSStatus *err) {
|
||||
OSStatus e = kOTNoError;
|
||||
EndpointRef ref;
|
||||
if (!native)
|
||||
return __otsock_OTOpenEndpoint(config, oflag, info, err);
|
||||
ref = (EndpointRef)CCALL(__otn_OpenEndpointPriv, (long)config, (long)oflag, (long)info,
|
||||
(long)&e, (long)&rec);
|
||||
if (err)
|
||||
*err = e;
|
||||
return ref;
|
||||
}
|
||||
|
||||
/* Opens an endpoint; proc gets T_OPENCOMPLETE. */
|
||||
OSStatus OTAsyncOpenEndpoint(OTConfigurationRef config, OTOpenFlags oflag, TEndpointInfo *info,
|
||||
OTNotifyUPP proc, void *contextPtr) {
|
||||
struct nslot *s;
|
||||
OSStatus err;
|
||||
if (!native)
|
||||
return __otsock_OTAsyncOpenEndpoint(config, oflag, info, proc, contextPtr);
|
||||
s = new_slot(proc, contextPtr, NULL);
|
||||
if (!s)
|
||||
return kOTOutOfMemoryErr;
|
||||
err = (OSStatus)CCALL(__otn_AsyncOpenEndpointPriv, (long)config, (long)oflag, (long)info,
|
||||
(long)__otn_trampoline, (long)s, (long)&rec);
|
||||
if (err != kOTNoError)
|
||||
s->used = 0;
|
||||
return err;
|
||||
}
|
||||
|
||||
/* Gives the configuration of the Internet services: the 68k library
|
||||
does not take kDefaultInternetServicesPath, so make "dnr". */
|
||||
static OTConfigurationRef inet_config(OTConfigurationRef cfig) {
|
||||
if (cfig == kDefaultInternetServicesPath)
|
||||
return OTCreateConfiguration(kDNRName);
|
||||
return cfig;
|
||||
}
|
||||
|
||||
/* Opens the Internet services and waits until they are open. */
|
||||
InetSvcRef OTOpenInternetServices(OTConfigurationRef cfig, OTOpenFlags oflag, OSStatus *err) {
|
||||
OSStatus e = kOTNoError;
|
||||
InetSvcRef ref;
|
||||
if (!native)
|
||||
return __otsock_OTOpenInternetServices(cfig, oflag, err);
|
||||
cfig = inet_config(cfig);
|
||||
ref = (InetSvcRef)CCALL(__otn_OpenInternetServicesPriv, (long)cfig, (long)oflag, (long)&e,
|
||||
(long)&rec);
|
||||
if (err)
|
||||
*err = e;
|
||||
return ref;
|
||||
}
|
||||
|
||||
/* Opens the Internet services; proc gets T_OPENCOMPLETE. */
|
||||
OSStatus OTAsyncOpenInternetServices(OTConfigurationRef cfig, OTOpenFlags oflag, OTNotifyUPP proc,
|
||||
void *contextPtr) {
|
||||
struct nslot *s;
|
||||
OSStatus err;
|
||||
if (!native)
|
||||
return __otsock_OTAsyncOpenInternetServices(cfig, oflag, proc, contextPtr);
|
||||
cfig = inet_config(cfig);
|
||||
s = new_slot(proc, contextPtr, NULL);
|
||||
if (!s)
|
||||
return kOTOutOfMemoryErr;
|
||||
err = (OSStatus)CCALL(__otn_AsyncOpenInternetServicesPriv, (long)cfig, (long)oflag,
|
||||
(long)__otn_trampoline, (long)s, (long)&rec);
|
||||
if (err != kOTNoError)
|
||||
s->used = 0;
|
||||
return err;
|
||||
}
|
||||
|
||||
/* Closes a provider. */
|
||||
OSStatus OTCloseProvider(ProviderRef ref) {
|
||||
OSStatus err;
|
||||
if (!native)
|
||||
return __otsock_OTCloseProvider(ref);
|
||||
err = (OSStatus)CCALL(__otn_CloseProviderPriv, (long)ref, (long)&rec);
|
||||
free_slots(ref);
|
||||
return err;
|
||||
}
|
||||
|
||||
/* Puts a provider in synchronous mode. */
|
||||
OSStatus OTSetSynchronous(ProviderRef ref) {
|
||||
return native ? (OSStatus)PCALL1(__otn_SETSYNCHRONOUS, 4, ref) : __otsock_OTSetSynchronous(ref);
|
||||
}
|
||||
|
||||
/* Puts a provider in asynchronous mode. */
|
||||
OSStatus OTSetAsynchronous(ProviderRef ref) {
|
||||
return native ? (OSStatus)PCALL1(__otn_SETASYNCHRONOUS, 4, ref)
|
||||
: __otsock_OTSetAsynchronous(ref);
|
||||
}
|
||||
|
||||
/* Gives true when a provider is in synchronous mode. */
|
||||
Boolean OTIsSynchronous(ProviderRef ref) {
|
||||
return native ? PBOOL(PCALL1(__otn_ISSYNCHRONOUS, 2, ref)) : __otsock_OTIsSynchronous(ref);
|
||||
}
|
||||
|
||||
/* Makes the calls of a provider wait. */
|
||||
OSStatus OTSetBlocking(ProviderRef ref) {
|
||||
return native ? (OSStatus)PCALL1(__otn_SETBLOCKING, 4, ref) : __otsock_OTSetBlocking(ref);
|
||||
}
|
||||
|
||||
/* Makes the calls of a provider give kOTNoDataErr or kOTFlowErr at once. */
|
||||
OSStatus OTSetNonBlocking(ProviderRef ref) {
|
||||
return native ? (OSStatus)PCALL1(__otn_SETNONBLOCKING, 4, ref) : __otsock_OTSetNonBlocking(ref);
|
||||
}
|
||||
|
||||
/* Gives true when the calls of a provider wait. */
|
||||
Boolean OTIsBlocking(ProviderRef ref) {
|
||||
return native ? PBOOL(PCALL1(__otn_ISBLOCKING, 2, ref)) : __otsock_OTIsBlocking(ref);
|
||||
}
|
||||
|
||||
/* Installs the notifier of a provider. */
|
||||
OSStatus OTInstallNotifier(ProviderRef ref, OTNotifyUPP proc, void *contextPtr) {
|
||||
struct nslot *s;
|
||||
OSStatus err;
|
||||
if (!native)
|
||||
return __otsock_OTInstallNotifier(ref, proc, contextPtr);
|
||||
s = new_slot(proc, contextPtr, ref);
|
||||
if (!s)
|
||||
return kOTOutOfMemoryErr;
|
||||
err = (OSStatus)PCALL(__otn_INSTALLNOTIFIER, 4, 0, (long)ref, (long)__otn_trampoline, (long)s);
|
||||
if (err != kOTNoError)
|
||||
s->used = 0;
|
||||
return err;
|
||||
}
|
||||
|
||||
/* Removes the notifier of a provider. */
|
||||
void OTRemoveNotifier(ProviderRef ref) {
|
||||
if (!native) {
|
||||
__otsock_OTRemoveNotifier(ref);
|
||||
return;
|
||||
}
|
||||
PCALL1(__otn_REMOVENOTIFIER, 0, ref);
|
||||
free_slots(ref);
|
||||
}
|
||||
|
||||
/* Asks for kOTSyncIdleEvent while a synchronous call waits. */
|
||||
OSStatus OTUseSyncIdleEvents(ProviderRef ref, Boolean useEvents) {
|
||||
if (!native)
|
||||
return __otsock_OTUseSyncIdleEvents(ref, useEvents);
|
||||
return (OSStatus)PCALL(__otn_USESYNCIDLEEVENTS, 4, 2, (long)ref, (long)(useEvents ? 0x100 : 0));
|
||||
}
|
||||
|
||||
/* Stops the notifier of a provider from running. */
|
||||
Boolean OTEnterNotifier(ProviderRef ref) {
|
||||
return native ? PBOOL(PCALL1(__otn_ENTERNOTIFIER, 2, ref)) : __otsock_OTEnterNotifier(ref);
|
||||
}
|
||||
|
||||
/* Lets the notifier of a provider run again. */
|
||||
void OTLeaveNotifier(ProviderRef ref) {
|
||||
if (native)
|
||||
PCALL1(__otn_LEAVENOTIFIER, 0, ref);
|
||||
else
|
||||
__otsock_OTLeaveNotifier(ref);
|
||||
}
|
||||
|
||||
/* Asks for T_MEMORYRELEASED after each send. */
|
||||
OSStatus OTAckSends(ProviderRef ref) {
|
||||
return native ? (OSStatus)PCALL1(__otn_ACKSENDS, 4, ref) : __otsock_OTAckSends(ref);
|
||||
}
|
||||
|
||||
/* Stops T_MEMORYRELEASED. */
|
||||
OSStatus OTDontAckSends(ProviderRef ref) {
|
||||
return native ? (OSStatus)PCALL1(__otn_DONTACKSENDS, 4, ref) : __otsock_OTDontAckSends(ref);
|
||||
}
|
||||
|
||||
/* Gives true after OTAckSends. */
|
||||
Boolean OTIsAckingSends(ProviderRef ref) {
|
||||
return native ? PBOOL(PCALL1(__otn_ISACKINGSENDS, 2, ref)) : __otsock_OTIsAckingSends(ref);
|
||||
}
|
||||
|
||||
/* Ends the synchronous calls that wait, with the error err. */
|
||||
OSStatus OTCancelSynchronousCalls(ProviderRef ref, OSStatus err) {
|
||||
if (!native)
|
||||
return __otsock_OTCancelSynchronousCalls(ref, err);
|
||||
return (OSStatus)PCALL(__otn_CANCELSYNCHRONOUSCALLS, 4, 0, (long)ref, (long)err);
|
||||
}
|
||||
|
||||
/* Sends a control call to a provider. */
|
||||
SInt32 OTIoctl(ProviderRef ref, UInt32 cmd, void *data) {
|
||||
if (!native)
|
||||
return __otsock_OTIoctl(ref, cmd, data);
|
||||
return (SInt32)PCALL(__otn_IOCTL, 4, 0, (long)ref, (long)cmd, (long)data);
|
||||
}
|
||||
|
||||
/* Gives the port of a provider. */
|
||||
OTPortRef OTGetProviderPortRef(ProviderRef ref) {
|
||||
return native ? (OTPortRef)PCALL1(__otn_GETPROVIDERPORTREF, 4, ref)
|
||||
: __otsock_OTGetProviderPortRef(ref);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
/* Endpoints */
|
||||
|
||||
/* Gives the sizes and the kind of an endpoint. */
|
||||
OSStatus OTGetEndpointInfo(EndpointRef ref, TEndpointInfo *info) {
|
||||
if (!native)
|
||||
return __otsock_OTGetEndpointInfo(ref, info);
|
||||
return (OSStatus)PCALL(__otn_GETENDPOINTINFO, 4, 0, (long)ref, (long)info);
|
||||
}
|
||||
|
||||
/* Gives the state of an endpoint (T_UNBND, T_IDLE, ...). */
|
||||
OTResult OTGetEndpointState(EndpointRef ref) {
|
||||
return native ? (OTResult)PCALL1(__otn_GETENDPOINTSTATE, 4, ref)
|
||||
: __otsock_OTGetEndpointState(ref);
|
||||
}
|
||||
|
||||
/* Gives the event that waits on an endpoint. */
|
||||
OTResult OTLook(EndpointRef ref) {
|
||||
return native ? (OTResult)PCALL1(__otn_LOOK, 4, ref) : __otsock_OTLook(ref);
|
||||
}
|
||||
|
||||
/* Gives the bytes that wait to be received. */
|
||||
OSStatus OTCountDataBytes(EndpointRef ref, OTByteCount *countPtr) {
|
||||
if (!native)
|
||||
return __otsock_OTCountDataBytes(ref, countPtr);
|
||||
return (OSStatus)PCALL(__otn_COUNTDATABYTES, 4, 0, (long)ref, (long)countPtr);
|
||||
}
|
||||
|
||||
/* Gives the local and the remote address of an endpoint. */
|
||||
OSStatus OTGetProtAddress(EndpointRef ref, TBind *boundAddr, TBind *peerAddr) {
|
||||
if (!native)
|
||||
return __otsock_OTGetProtAddress(ref, boundAddr, peerAddr);
|
||||
return (OSStatus)PCALL(__otn_GETPROTADDRESS, 4, 0, (long)ref, (long)boundAddr, (long)peerAddr);
|
||||
}
|
||||
|
||||
/* Resolves an address with the endpoint's mapper. */
|
||||
OSStatus OTResolveAddress(EndpointRef ref, TBind *reqAddr, TBind *retAddr, OTTimeout timeOut) {
|
||||
if (!native)
|
||||
return __otsock_OTResolveAddress(ref, reqAddr, retAddr, timeOut);
|
||||
return (OSStatus)PCALL(__otn_RESOLVEADDRESS, 4, 0, (long)ref, (long)reqAddr, (long)retAddr,
|
||||
(long)timeOut);
|
||||
}
|
||||
|
||||
/* Sets or gets the options of an endpoint. */
|
||||
OSStatus OTOptionManagement(EndpointRef ref, TOptMgmt *req, TOptMgmt *ret) {
|
||||
if (!native)
|
||||
return __otsock_OTOptionManagement(ref, req, ret);
|
||||
return (OSStatus)PCALL(__otn_OPTIONMANAGEMENT, 4, 0, (long)ref, (long)req, (long)ret);
|
||||
}
|
||||
|
||||
/* Gives an endpoint a local address. */
|
||||
OSStatus OTBind(EndpointRef ref, TBind *reqAddr, TBind *retAddr) {
|
||||
if (!native)
|
||||
return __otsock_OTBind(ref, reqAddr, retAddr);
|
||||
return (OSStatus)PCALL(__otn_BIND, 4, 0, (long)ref, (long)reqAddr, (long)retAddr);
|
||||
}
|
||||
|
||||
/* Takes the local address away. */
|
||||
OSStatus OTUnbind(EndpointRef ref) {
|
||||
return native ? (OSStatus)PCALL1(__otn_UNBIND, 4, ref) : __otsock_OTUnbind(ref);
|
||||
}
|
||||
|
||||
/* Connects to a remote address. */
|
||||
OSStatus OTConnect(EndpointRef ref, TCall *sndCall, TCall *rcvCall) {
|
||||
if (!native)
|
||||
return __otsock_OTConnect(ref, sndCall, rcvCall);
|
||||
return (OSStatus)PCALL(__otn_CONNECT, 4, 0, (long)ref, (long)sndCall, (long)rcvCall);
|
||||
}
|
||||
|
||||
/* Ends an asynchronous or nonblocking connect. */
|
||||
OSStatus OTRcvConnect(EndpointRef ref, TCall *call) {
|
||||
if (!native)
|
||||
return __otsock_OTRcvConnect(ref, call);
|
||||
return (OSStatus)PCALL(__otn_RCVCONNECT, 4, 0, (long)ref, (long)call);
|
||||
}
|
||||
|
||||
/* Takes a connection request. */
|
||||
OSStatus OTListen(EndpointRef ref, TCall *call) {
|
||||
if (!native)
|
||||
return __otsock_OTListen(ref, call);
|
||||
return (OSStatus)PCALL(__otn_LISTEN, 4, 0, (long)ref, (long)call);
|
||||
}
|
||||
|
||||
/* Accepts a connection request on the worker endpoint. */
|
||||
OSStatus OTAccept(EndpointRef listener, EndpointRef worker, TCall *call) {
|
||||
if (!native)
|
||||
return __otsock_OTAccept(listener, worker, call);
|
||||
return (OSStatus)PCALL(__otn_ACCEPT, 4, 0, (long)listener, (long)worker, (long)call);
|
||||
}
|
||||
|
||||
/* Ends a connection at once, or refuses a request. */
|
||||
OSStatus OTSndDisconnect(EndpointRef ref, TCall *call) {
|
||||
if (!native)
|
||||
return __otsock_OTSndDisconnect(ref, call);
|
||||
return (OSStatus)PCALL(__otn_SNDDISCONNECT, 4, 0, (long)ref, (long)call);
|
||||
}
|
||||
|
||||
/* Tells the peer that no more data comes. */
|
||||
OSStatus OTSndOrderlyDisconnect(EndpointRef ref) {
|
||||
return native ? (OSStatus)PCALL1(__otn_SNDORDERLYDISCONNECT, 4, ref)
|
||||
: __otsock_OTSndOrderlyDisconnect(ref);
|
||||
}
|
||||
|
||||
/* Takes the T_DISCONNECT event. */
|
||||
OSStatus OTRcvDisconnect(EndpointRef ref, TDiscon *discon) {
|
||||
if (!native)
|
||||
return __otsock_OTRcvDisconnect(ref, discon);
|
||||
return (OSStatus)PCALL(__otn_RCVDISCONNECT, 4, 0, (long)ref, (long)discon);
|
||||
}
|
||||
|
||||
/* Takes the T_ORDREL event. */
|
||||
OSStatus OTRcvOrderlyDisconnect(EndpointRef ref) {
|
||||
return native ? (OSStatus)PCALL1(__otn_RCVORDERLYDISCONNECT, 4, ref)
|
||||
: __otsock_OTRcvOrderlyDisconnect(ref);
|
||||
}
|
||||
|
||||
/* Receives data. */
|
||||
OTResult OTRcv(EndpointRef ref, void *buf, OTByteCount nbytes, OTFlags *flags) {
|
||||
if (!native)
|
||||
return __otsock_OTRcv(ref, buf, nbytes, flags);
|
||||
return (OTResult)PCALL(__otn_RCV, 4, 0, (long)ref, (long)buf, (long)nbytes, (long)flags);
|
||||
}
|
||||
|
||||
/* Sends data. */
|
||||
OTResult OTSnd(EndpointRef ref, void *buf, OTByteCount nbytes, OTFlags flags) {
|
||||
if (!native)
|
||||
return __otsock_OTSnd(ref, buf, nbytes, flags);
|
||||
return (OTResult)PCALL(__otn_SND, 4, 0, (long)ref, (long)buf, (long)nbytes, (long)flags);
|
||||
}
|
||||
|
||||
/* Sends a datagram. */
|
||||
OSStatus OTSndUData(EndpointRef ref, TUnitData *udata) {
|
||||
if (!native)
|
||||
return __otsock_OTSndUData(ref, udata);
|
||||
return (OSStatus)PCALL(__otn_SNDUDATA, 4, 0, (long)ref, (long)udata);
|
||||
}
|
||||
|
||||
/* Receives a datagram. */
|
||||
OSStatus OTRcvUData(EndpointRef ref, TUnitData *udata, OTFlags *flags) {
|
||||
if (!native)
|
||||
return __otsock_OTRcvUData(ref, udata, flags);
|
||||
return (OSStatus)PCALL(__otn_RCVUDATA, 4, 0, (long)ref, (long)udata, (long)flags);
|
||||
}
|
||||
|
||||
/* Takes the error of a datagram that was not sent. */
|
||||
OSStatus OTRcvUDErr(EndpointRef ref, TUDErr *uderr) {
|
||||
if (!native)
|
||||
return __otsock_OTRcvUDErr(ref, uderr);
|
||||
return (OSStatus)PCALL(__otn_RCVUDERR, 4, 0, (long)ref, (long)uderr);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
/* Internet services */
|
||||
|
||||
/* Gives the address and other values of an interface. The native
|
||||
function finds Open Transport's configurator by name through ASLM,
|
||||
which fails for a program that uses this glue, so the MacTCP form
|
||||
answers in both modes (Open Transport also supplies MacTCP's .IPP
|
||||
driver). */
|
||||
OSStatus OTInetGetInterfaceInfo(InetInterfaceInfo *info, SInt32 val) {
|
||||
return __otsock_OTInetGetInterfaceInfo(info, val);
|
||||
}
|
||||
|
||||
/* Gives the secondary addresses of an interface (the MacTCP form, as
|
||||
for OTInetGetInterfaceInfo). */
|
||||
OSStatus OTInetGetSecondaryAddresses(InetHost *addr, UInt32 *count, SInt32 val) {
|
||||
return __otsock_OTInetGetSecondaryAddresses(addr, count, val);
|
||||
}
|
||||
|
||||
/* Finds the addresses of a host name or a dotted address. */
|
||||
OSStatus OTInetStringToAddress(InetSvcRef ref, char *name, InetHostInfo *hinfo) {
|
||||
if (!native)
|
||||
return __otsock_OTInetStringToAddress(ref, name, hinfo);
|
||||
return (OSStatus)PCALL(__otn_INETSTRINGTOADDRESS, 4, 0, (long)ref, (long)name, (long)hinfo);
|
||||
}
|
||||
|
||||
/* Finds the name of an address. */
|
||||
OSStatus OTInetAddressToName(InetSvcRef ref, InetHost addr, char *name) {
|
||||
if (!native)
|
||||
return __otsock_OTInetAddressToName(ref, addr, name);
|
||||
return (OSStatus)PCALL(__otn_INETADDRESSTONAME, 4, 0, (long)ref, (long)addr, (long)name);
|
||||
}
|
||||
|
||||
/* Gives the CPU and system of a host. */
|
||||
OSStatus OTInetSysInfo(InetSvcRef ref, char *name, InetSysInfo *sysinfo) {
|
||||
if (!native)
|
||||
return __otsock_OTInetSysInfo(ref, name, sysinfo);
|
||||
return (OSStatus)PCALL(__otn_INETSYSINFO, 4, 0, (long)ref, (long)name, (long)sysinfo);
|
||||
}
|
||||
|
||||
/* Gives the mail exchangers of a domain. */
|
||||
OSStatus OTInetMailExchange(InetSvcRef ref, char *name, UInt16 *num, InetMailExchange *mx) {
|
||||
if (!native)
|
||||
return __otsock_OTInetMailExchange(ref, name, num, mx);
|
||||
return (OSStatus)PCALL(__otn_INETMAILEXCHANGE, 4, 0, (long)ref, (long)name, (long)num,
|
||||
(long)mx);
|
||||
}
|
||||
|
||||
/* Sends a query to the name server. */
|
||||
OSStatus OTInetQuery(InetSvcRef ref, char *name, UInt16 qClass, UInt16 qType, char *buf,
|
||||
OTByteCount buflen, void **argv, OTByteCount argvlen, OTFlags requestFlags) {
|
||||
if (!native)
|
||||
return __otsock_OTInetQuery(ref, name, qClass, qType, buf, buflen, argv, argvlen,
|
||||
requestFlags);
|
||||
/* qClass and qType are 2-byte arguments (bits 2 and 3). */
|
||||
return (OSStatus)PCALL(__otn_INETQUERY, 4, 0x0C, (long)ref, (long)name, (long)qClass,
|
||||
(long)qType, (long)buf, (long)buflen, (long)argv, (long)argvlen,
|
||||
(long)requestFlags);
|
||||
}
|
||||
#endif
|
||||
+5
-57
@@ -32,58 +32,6 @@
|
||||
#include "macos.h"
|
||||
#include "socket.h"
|
||||
|
||||
/* The UDP parameter blocks, which MacTCP.h does not have. The layout is
|
||||
that of Apple's MacTCP.h. */
|
||||
#pragma options align=mac68k
|
||||
struct udp_create {
|
||||
Ptr rcvBuff;
|
||||
unsigned long rcvBuffLen;
|
||||
ProcPtr notifyProc;
|
||||
unsigned short localPort;
|
||||
Ptr userDataPtr;
|
||||
Byte endingPort;
|
||||
};
|
||||
struct udp_send {
|
||||
unsigned short reserved;
|
||||
ip_addr remoteHost;
|
||||
unsigned short remotePort;
|
||||
Ptr wdsPtr;
|
||||
Boolean checkSum;
|
||||
unsigned short sendLength;
|
||||
Ptr userDataPtr;
|
||||
unsigned short localPort;
|
||||
};
|
||||
struct udp_receive {
|
||||
unsigned short timeOut;
|
||||
ip_addr remoteHost;
|
||||
unsigned short remotePort;
|
||||
Ptr rcvBuff;
|
||||
unsigned short rcvBuffLen;
|
||||
unsigned short secondTimeStamp;
|
||||
Ptr userDataPtr;
|
||||
ip_addr destHost;
|
||||
unsigned short destPort;
|
||||
};
|
||||
struct udp_iopb {
|
||||
QElemPtr qLink;
|
||||
INTEGER qType;
|
||||
INTEGER ioTrap;
|
||||
Ptr ioCmdAddr;
|
||||
ProcPtr ioCompletion;
|
||||
OSErr ioResult;
|
||||
StringPtr ioNamePtr;
|
||||
INTEGER ioVRefNum;
|
||||
INTEGER ioCRefNum;
|
||||
INTEGER csCode;
|
||||
StreamPtr udpStream;
|
||||
union {
|
||||
struct udp_create create;
|
||||
struct udp_send send;
|
||||
struct udp_receive receive;
|
||||
} csParam;
|
||||
};
|
||||
#pragma options align=reset
|
||||
|
||||
#define TCP_BUFFER 16384 /* a TCP stream's receive buffer */
|
||||
#define UDP_BUFFER 8192 /* a UDP stream's receive buffer */
|
||||
#define MAX_PENDING 4 /* streams that wait for connections */
|
||||
@@ -104,7 +52,7 @@ struct inet {
|
||||
int closing;
|
||||
char in[1024]; /* bytes taken from MacTCP but not read */
|
||||
size_t inlen;
|
||||
struct udp_iopb upb; /* the UDP read in progress */
|
||||
UDPiopb upb; /* the UDP read in progress */
|
||||
int reading;
|
||||
char *ubuf;
|
||||
StreamPtr us;
|
||||
@@ -340,7 +288,7 @@ static int inet_bind(struct sock *k, const struct sockaddr *a, socklen_t len) {
|
||||
/* Makes a UDP socket's stream the first time. */
|
||||
static int udp_open(struct sock *k) {
|
||||
struct inet *n = k->impl;
|
||||
struct udp_iopb pb;
|
||||
UDPiopb pb;
|
||||
OSErr err;
|
||||
if (n->us)
|
||||
return 0;
|
||||
@@ -520,7 +468,7 @@ static long inet_send(struct sock *k, const void *buf, size_t len, int nonblock,
|
||||
size_t sent = 0;
|
||||
(void)nonblock;
|
||||
if (k->type == SOCK_DGRAM) {
|
||||
struct udp_iopb pb;
|
||||
UDPiopb pb;
|
||||
wdsEntry wds[2];
|
||||
ip_addr host = k->peer_host;
|
||||
unsigned short port = k->peer_port;
|
||||
@@ -667,7 +615,7 @@ static long inet_recv(struct sock *k, void *buf, size_t len, int nonblock, int p
|
||||
*fromlen = sizeof in;
|
||||
}
|
||||
if (!peek) {
|
||||
struct udp_iopb pb;
|
||||
UDPiopb pb;
|
||||
memset(&pb, 0, sizeof pb);
|
||||
pb.udpStream = n->us;
|
||||
pb.csParam.receive.rcvBuff = n->upb.csParam.receive.rcvBuff;
|
||||
@@ -785,7 +733,7 @@ static void inet_close(struct sock *k) {
|
||||
set_bound(k, 0);
|
||||
if (k->type == SOCK_DGRAM) {
|
||||
if (n->us) {
|
||||
struct udp_iopb pb;
|
||||
UDPiopb pb;
|
||||
memset(&pb, 0, sizeof pb);
|
||||
pb.udpStream = n->us;
|
||||
call(&pb, udpRelease);
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
#include <Multiverse.h>
|
||||
#include <AddressXlation.h>
|
||||
#include <OpenTransport.h>
|
||||
#include <OpenTransportProviders.h>
|
||||
#include <OpenTptInternet.h>
|
||||
#include <AGL/agl.h>
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glext.h>
|
||||
|
||||
@@ -8,6 +8,13 @@ import yaml
|
||||
|
||||
root = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
|
||||
print("#include <Multiverse.h>")
|
||||
# The headers that Multiverse.h leaves out (tools/gen-headers.py
|
||||
# STANDALONE).
|
||||
for f in sorted(os.listdir(os.path.join(root, "include", "mv"))):
|
||||
if not f.endswith(".h"):
|
||||
continue
|
||||
if f'"mv/{f}"' not in open(os.path.join(root, "include", "Multiverse.h")).read():
|
||||
print(f'#include <mv/{f}>')
|
||||
for f in sorted(os.listdir(os.path.join(root, "defs"))):
|
||||
if not f.endswith(".yaml") or f == "MPW.yaml": # MPW.h is separate
|
||||
continue
|
||||
|
||||
+353
@@ -0,0 +1,353 @@
|
||||
/* Checks the Open Transport calls: the utilities, the Internet services
|
||||
* (addresses and names), a TCP connection between two endpoints of this
|
||||
* program (a listener, a client and the endpoint that accepts), a UDP
|
||||
* datagram to this program, and an endpoint that a notifier follows.
|
||||
*
|
||||
* On PowerPC the calls go to Open Transport (runtime/libc/ot.c). On 68k
|
||||
* they go to native Open Transport through the Apple Shared Library
|
||||
* Manager (runtime/libc/otnative.c) when it is installed, else to the
|
||||
* SDK's Open Transport over MacTCP (runtime/libc/ot68k.c).
|
||||
* tests/run.sh runs it in tools/sim68k.py --os, whose fake MacTCP uses
|
||||
* the host's loopback network; tools/qemu/nettest.py runs it on Mac OS
|
||||
* 8.1 (68k) and 9.2.1 (PowerPC) in QEMU. The output has one "ok" line
|
||||
* per check, then "all ok". With a report server at 10.0.2.2 port 7009
|
||||
* (the QEMU host), the lines also go there.
|
||||
*
|
||||
* Copyright (C) clang-retro contributors.
|
||||
* SPDX-License-Identifier: AGPL-3.0-only */
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <OpenTransport.h>
|
||||
#include <OpenTransportProviders.h>
|
||||
#include <Events.h>
|
||||
|
||||
#define TCP_PORT 7101 /* the listener's port */
|
||||
|
||||
static int failures;
|
||||
static EndpointRef report; /* the report connection, or NULL */
|
||||
static char early[2048]; /* the lines before the report connection */
|
||||
static size_t nearly;
|
||||
|
||||
/* Writes one line to the console and to the report connection. */
|
||||
static void say(const char *fmt, ...) {
|
||||
char line[200];
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
vsnprintf(line, sizeof line - 1, fmt, ap);
|
||||
va_end(ap);
|
||||
printf("%s\n", line);
|
||||
fflush(stdout);
|
||||
{
|
||||
size_t n = strlen(line);
|
||||
line[n++] = '\n';
|
||||
if (report)
|
||||
OTSnd(report, line, n, 0);
|
||||
else if (nearly + n <= sizeof early) {
|
||||
memcpy(early + nearly, line, n);
|
||||
nearly += n;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Prints one check's result, and counts the failures. */
|
||||
static void check(const char *what, int ok) {
|
||||
say("%s %s", ok ? "ok" : "FAILED", what);
|
||||
if (!ok)
|
||||
failures++;
|
||||
}
|
||||
|
||||
/* Waits until cond is true or about secs seconds pass, and lets other
|
||||
programs run. Gives cond. */
|
||||
#define WAIT_FOR(cond, secs) \
|
||||
do { \
|
||||
unsigned long until_ = TickCount() + 60UL * (secs); \
|
||||
while (!(cond) && TickCount() < until_) { \
|
||||
EventRecord ev_; \
|
||||
OTIdle(); \
|
||||
EventAvail(0, &ev_); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
/* Opens an endpoint of a configuration name ("tcp" or "udp"), and puts
|
||||
it in blocking mode (an endpoint starts synchronous and nonblocking).
|
||||
Gives NULL on an error. */
|
||||
static EndpointRef open_ep(const char *name, TEndpointInfo *info) {
|
||||
OSStatus err = -1;
|
||||
EndpointRef ep = OTOpenEndpoint(OTCreateConfiguration(name), 0, info, &err);
|
||||
if (err != kOTNoError) {
|
||||
say("note: OTOpenEndpoint %s: error %ld", name, (long)err);
|
||||
return NULL;
|
||||
}
|
||||
OTSetBlocking(ep);
|
||||
return ep;
|
||||
}
|
||||
|
||||
/* Binds ep to port (0: any) with qlen waiting connections. Gives the
|
||||
bound port, or 0. */
|
||||
static InetPort bind_ep(EndpointRef ep, InetPort port, OTQLen qlen) {
|
||||
InetAddress want, got;
|
||||
TBind req, ret;
|
||||
OTInitInetAddress(&want, port, kOTAnyInetAddress);
|
||||
memset(&req, 0, sizeof req);
|
||||
memset(&ret, 0, sizeof ret);
|
||||
req.addr.buf = (UInt8 *)&want;
|
||||
req.addr.len = sizeof want;
|
||||
req.qlen = qlen;
|
||||
ret.addr.buf = (UInt8 *)&got;
|
||||
ret.addr.maxlen = sizeof got;
|
||||
if (OTBind(ep, &req, &ret) != kOTNoError)
|
||||
return 0;
|
||||
return got.fPort;
|
||||
}
|
||||
|
||||
/* Connects a report endpoint to the QEMU host, when one listens. */
|
||||
static void open_report(InetHost me) {
|
||||
InetAddress host;
|
||||
TCall call;
|
||||
EndpointRef ep;
|
||||
if ((me & 0xFFFFFF00UL) != 0x0A000200UL) /* QEMU's user network */
|
||||
return;
|
||||
ep = open_ep(kTCPName, NULL);
|
||||
if (!ep)
|
||||
return;
|
||||
if (bind_ep(ep, 0, 0) == 0) {
|
||||
OTCloseProvider(ep);
|
||||
return;
|
||||
}
|
||||
OTInitInetAddress(&host, 7009, 0x0A000202UL);
|
||||
memset(&call, 0, sizeof call);
|
||||
call.addr.buf = (UInt8 *)&host;
|
||||
call.addr.len = sizeof host;
|
||||
if (OTConnect(ep, &call, NULL) == kOTNoError) {
|
||||
report = ep;
|
||||
OTSnd(report, early, nearly, 0);
|
||||
} else
|
||||
OTCloseProvider(ep);
|
||||
}
|
||||
|
||||
/* The utility calls: memory, strings, time. */
|
||||
static void check_utilities(void) {
|
||||
char a[16], b[16];
|
||||
OTTimeStamp start;
|
||||
void *mem;
|
||||
OTMemset(a, 'x', sizeof a);
|
||||
OTMemcpy(b, a, sizeof a);
|
||||
check("OTMemcpy, OTMemcmp", OTMemcmp(a, b, sizeof a) && a[15] == 'x');
|
||||
OTMemzero(a, 4);
|
||||
check("OTMemzero", a[0] == 0 && a[3] == 0 && a[4] == 'x');
|
||||
OTStrCopy(a, "open");
|
||||
OTStrCat(a, "tpt");
|
||||
check("OTStrCopy, OTStrCat, OTStrLength", OTStrLength(a) == 7 && OTStrEqual(a, "opentpt"));
|
||||
OTGetTimeStamp(&start);
|
||||
check("OTElapsedMilliseconds", OTElapsedMilliseconds(&start) < 5000);
|
||||
mem = OTAllocMem(100);
|
||||
check("OTAllocMem", mem != NULL);
|
||||
if (mem)
|
||||
OTFreeMem(mem);
|
||||
}
|
||||
|
||||
/* Address text, the interface, and the name resolver. Gives this
|
||||
Mac's address. */
|
||||
static InetHost check_inet(void) {
|
||||
InetHost h = 0;
|
||||
InetInterfaceInfo info;
|
||||
InetHostInfo hinfo;
|
||||
InetSvcRef svc;
|
||||
OSStatus err = -1;
|
||||
char text[32];
|
||||
check("OTInetStringToHost", OTInetStringToHost("10.0.2.15", &h) == kOTNoError && h == 0x0A00020FUL);
|
||||
OTInetHostToString(0xC0A80001UL, text);
|
||||
check("OTInetHostToString", strcmp(text, "192.168.0.1") == 0);
|
||||
memset(&info, 0, sizeof info);
|
||||
err = OTInetGetInterfaceInfo(&info, kDefaultInetInterface);
|
||||
check("OTInetGetInterfaceInfo", err == kOTNoError && info.fAddress != 0);
|
||||
OTInetHostToString(info.fAddress, text);
|
||||
say("note: address %s", text);
|
||||
open_report(info.fAddress);
|
||||
svc = OTOpenInternetServices(kDefaultInternetServicesPath, 0, &err);
|
||||
check("OTOpenInternetServices", err == kOTNoError && svc != NULL);
|
||||
if (err == kOTNoError) {
|
||||
memset(&hinfo, 0, sizeof hinfo);
|
||||
err = OTInetStringToAddress(svc, (char *)"10.0.2.2", &hinfo);
|
||||
check("OTInetStringToAddress (a number)", err == kOTNoError && hinfo.addrs[0] == 0x0A000202UL);
|
||||
memset(&hinfo, 0, sizeof hinfo);
|
||||
err = OTInetStringToAddress(svc, (char *)"example.com", &hinfo);
|
||||
say("note: example.com: result %ld, %08lx", (long)err, (unsigned long)hinfo.addrs[0]);
|
||||
OTCloseProvider(svc);
|
||||
}
|
||||
return info.fAddress;
|
||||
}
|
||||
|
||||
/* Receives want bytes from ep in nonblocking mode, and lets other
|
||||
programs run while it waits (up to 10 seconds). Gives the count. */
|
||||
static int rcv_all(EndpointRef ep, char *buf, int want) {
|
||||
OTFlags flags = 0;
|
||||
OTResult n = kOTNoDataErr;
|
||||
int got = 0;
|
||||
OTSetNonBlocking(ep);
|
||||
while (got < want) {
|
||||
WAIT_FOR((n = OTRcv(ep, buf + got, want - got, &flags)) != kOTNoDataErr, 10);
|
||||
if (n <= 0)
|
||||
break;
|
||||
got += n;
|
||||
}
|
||||
OTSetBlocking(ep);
|
||||
return got;
|
||||
}
|
||||
|
||||
/* A TCP connection between two endpoints of this program. */
|
||||
static void check_tcp(InetHost me) {
|
||||
EndpointRef listener, client, worker;
|
||||
TEndpointInfo info;
|
||||
InetAddress to, from;
|
||||
TCall call;
|
||||
OTByteCount count = 0;
|
||||
char buf[64];
|
||||
OTResult n;
|
||||
int got;
|
||||
listener = open_ep(kTCPName, &info);
|
||||
check("OTOpenEndpoint tcp", listener != NULL && info.servtype == T_COTS_ORD);
|
||||
if (!listener)
|
||||
return;
|
||||
check("OTBind (listener)", bind_ep(listener, TCP_PORT, 1) == TCP_PORT);
|
||||
check("OTGetEndpointState (idle)", OTGetEndpointState(listener) == T_IDLE);
|
||||
client = open_ep(kTCPName, NULL);
|
||||
worker = open_ep(kTCPName, NULL);
|
||||
check("OTBind (client, worker)", client && worker && bind_ep(client, 0, 0) != 0 &&
|
||||
bind_ep(worker, 0, 0) != 0);
|
||||
OTSetNonBlocking(client);
|
||||
OTInitInetAddress(&to, TCP_PORT, me);
|
||||
memset(&call, 0, sizeof call);
|
||||
call.addr.buf = (UInt8 *)&to;
|
||||
call.addr.len = sizeof to;
|
||||
n = OTConnect(client, &call, NULL);
|
||||
check("OTConnect (nonblocking)", n == kOTNoDataErr || n == kOTNoError);
|
||||
memset(&call, 0, sizeof call);
|
||||
call.addr.buf = (UInt8 *)&from;
|
||||
call.addr.maxlen = sizeof from;
|
||||
check("OTListen", OTListen(listener, &call) == kOTNoError && from.fHost == me);
|
||||
check("OTAccept", OTAccept(listener, worker, &call) == kOTNoError);
|
||||
if (n == kOTNoDataErr) {
|
||||
WAIT_FOR(OTLook(client) == T_CONNECT, 10);
|
||||
check("OTRcvConnect", OTRcvConnect(client, NULL) == kOTNoError);
|
||||
}
|
||||
check("connected", OTGetEndpointState(client) == T_DATAXFER &&
|
||||
OTGetEndpointState(worker) == T_DATAXFER);
|
||||
OTSetBlocking(client);
|
||||
check("OTSnd", OTSnd(client, (void *)"hello, worker", 13, 0) == 13);
|
||||
got = rcv_all(worker, buf, 13);
|
||||
check("OTRcv", got == 13 && memcmp(buf, "hello, worker", 13) == 0);
|
||||
check("OTSnd (back)", OTSnd(worker, (void *)"reply", 5, 0) == 5);
|
||||
WAIT_FOR(OTCountDataBytes(client, &count) == kOTNoError && count >= 5, 10);
|
||||
check("OTCountDataBytes", count == 5);
|
||||
check("OTRcv (back)", rcv_all(client, buf, 5) == 5 && memcmp(buf, "reply", 5) == 0);
|
||||
check("OTSndOrderlyDisconnect", OTSndOrderlyDisconnect(client) == kOTNoError);
|
||||
WAIT_FOR(OTLook(worker) == T_ORDREL, 10);
|
||||
check("T_ORDREL", OTRcvOrderlyDisconnect(worker) == kOTNoError);
|
||||
check("OTSndOrderlyDisconnect (back)", OTSndOrderlyDisconnect(worker) == kOTNoError);
|
||||
WAIT_FOR(OTLook(client) == T_ORDREL, 10);
|
||||
check("T_ORDREL (back)", OTRcvOrderlyDisconnect(client) == kOTNoError);
|
||||
check("OTUnbind", OTUnbind(client) == kOTNoError && OTGetEndpointState(client) == T_UNBND);
|
||||
OTCloseProvider(client);
|
||||
OTCloseProvider(worker);
|
||||
OTCloseProvider(listener);
|
||||
}
|
||||
|
||||
/* A UDP datagram from one endpoint of this program to another. */
|
||||
static void check_udp(InetHost me) {
|
||||
EndpointRef a, b;
|
||||
TEndpointInfo info;
|
||||
InetAddress to, from;
|
||||
TUnitData ud;
|
||||
OTFlags flags = 0;
|
||||
OSStatus err = kOTNoDataErr;
|
||||
char buf[64];
|
||||
InetPort port;
|
||||
a = open_ep(kUDPName, &info);
|
||||
b = open_ep(kUDPName, NULL);
|
||||
check("OTOpenEndpoint udp", a && b && info.servtype == T_CLTS);
|
||||
if (!a || !b)
|
||||
return;
|
||||
port = bind_ep(b, 0, 0);
|
||||
check("OTBind udp", bind_ep(a, 0, 0) != 0 && port != 0);
|
||||
OTInitInetAddress(&to, port, me);
|
||||
memset(&ud, 0, sizeof ud);
|
||||
ud.addr.buf = (UInt8 *)&to;
|
||||
ud.addr.len = sizeof to;
|
||||
ud.udata.buf = (UInt8 *)"datagram";
|
||||
ud.udata.len = 8;
|
||||
check("OTSndUData", OTSndUData(a, &ud) == kOTNoError);
|
||||
OTSetNonBlocking(b);
|
||||
memset(&ud, 0, sizeof ud);
|
||||
ud.addr.buf = (UInt8 *)&from;
|
||||
ud.addr.maxlen = sizeof from;
|
||||
ud.udata.buf = (UInt8 *)buf;
|
||||
ud.udata.maxlen = sizeof buf;
|
||||
WAIT_FOR((err = OTRcvUData(b, &ud, &flags)) != kOTNoDataErr, 10);
|
||||
check("OTRcvUData", err == kOTNoError && ud.udata.len == 8 && memcmp(buf, "datagram", 8) == 0 &&
|
||||
from.fHost == me);
|
||||
OTCloseProvider(a);
|
||||
OTCloseProvider(b);
|
||||
}
|
||||
|
||||
static volatile EndpointRef async_ep;
|
||||
static volatile OTResult async_result = 1;
|
||||
static volatile int bound;
|
||||
|
||||
/* The notifier of the asynchronous endpoint. */
|
||||
static pascal void notifier(void *context, OTEventCode code, OTResult result, void *cookie) {
|
||||
(void)context;
|
||||
if (code == T_OPENCOMPLETE) {
|
||||
async_result = result;
|
||||
async_ep = (EndpointRef)cookie;
|
||||
} else if (code == T_BINDCOMPLETE) {
|
||||
bound = result == kOTNoError ? 1 : -1;
|
||||
}
|
||||
}
|
||||
|
||||
/* An endpoint opened and bound asynchronously. */
|
||||
static void check_async(void) {
|
||||
OSStatus err;
|
||||
err = OTAsyncOpenEndpoint(OTCreateConfiguration(kTCPName), 0, NULL, NewOTNotifyUPP(notifier),
|
||||
NULL);
|
||||
check("OTAsyncOpenEndpoint", err == kOTNoError);
|
||||
WAIT_FOR(async_result != 1, 10);
|
||||
check("T_OPENCOMPLETE", async_result == kOTNoError && async_ep != NULL);
|
||||
if (async_ep) {
|
||||
check("OTIsSynchronous (no)", !OTIsSynchronous(async_ep));
|
||||
check("OTBind (asynchronous)", OTBind(async_ep, NULL, NULL) == kOTNoError);
|
||||
WAIT_FOR(bound != 0, 10);
|
||||
check("T_BINDCOMPLETE", bound == 1);
|
||||
OTCloseProvider(async_ep);
|
||||
}
|
||||
}
|
||||
|
||||
/* Runs the checks. */
|
||||
int main(void) {
|
||||
InetHost me;
|
||||
OSStatus err = InitOpenTransport();
|
||||
check("InitOpenTransport", err == kOTNoError);
|
||||
if (err != kOTNoError)
|
||||
return 1;
|
||||
#if defined(__m68k__)
|
||||
{
|
||||
int __ot68k_native(void);
|
||||
say("note: %s", __ot68k_native() ? "native Open Transport (through ASLM)" : "Open Transport over MacTCP");
|
||||
}
|
||||
#endif
|
||||
check_utilities();
|
||||
me = check_inet();
|
||||
if (me) {
|
||||
check_tcp(me);
|
||||
check_udp(me);
|
||||
}
|
||||
check_async();
|
||||
say(failures ? "%d FAILED" : "all ok", failures);
|
||||
if (report) {
|
||||
OTSndOrderlyDisconnect(report);
|
||||
OTCloseProvider(report);
|
||||
}
|
||||
CloseOpenTransport();
|
||||
return failures != 0;
|
||||
}
|
||||
+18
-1
@@ -121,7 +121,7 @@ fi
|
||||
# in tools/simppc.py, checking the console output file each leaves, and tests/console.c
|
||||
# with the console window, typing into it, tests/thread.c with the
|
||||
# simulators' fake Thread Manager, tests/net.c with their fake MacTCP
|
||||
# and PPC Toolbox, and tests/gl.c with the PowerPC simulator's fake
|
||||
# and PPC Toolbox, tests/ot.c (68k) with the fake MacTCP, and tests/gl.c with the PowerPC simulator's fake
|
||||
# OpenGL.
|
||||
if [ -n "$LLVM_SRC" ] && [ -n "$PICOLIBC_SRC" ]; then
|
||||
CLANG="$CLANG" PICOLIBC_SRC="$PICOLIBC_SRC" runtime/build-libc.sh "$APPS/lib"
|
||||
@@ -135,6 +135,13 @@ if [ -n "$LLVM_SRC" ] && [ -n "$PICOLIBC_SRC" ]; then
|
||||
-o "$APPS/thread-$cpu.bin" -- -Wall -Werror tests/thread.c >/dev/null
|
||||
CLANG="$CLANG" python3 tools/macapp.py --cpu $cpu --lib "$APPS/lib" \
|
||||
-o "$APPS/net-$cpu.bin" -- -Wall -Werror tests/net.c >/dev/null
|
||||
CLANG="$CLANG" python3 tools/macapp.py --cpu $cpu --lib "$APPS/lib" \
|
||||
-o "$APPS/ot-$cpu.bin" -- -Wall -Werror tests/ot.c >/dev/null
|
||||
# The examples that need the C library.
|
||||
for ex in examples/net/*.c; do
|
||||
CLANG="$CLANG" python3 tools/macapp.py --cpu $cpu --lib "$APPS/lib" \
|
||||
--console window -o "$APPS/$(basename "$ex" .c)-$cpu.bin" -- -Wall -Werror "$ex" >/dev/null
|
||||
done
|
||||
done
|
||||
# OpenGL is PowerPC only.
|
||||
CLANG="$CLANG" python3 tools/macapp.py --cpu ppc --lib "$APPS/lib" \
|
||||
@@ -186,6 +193,16 @@ if [ -n "$LLVM_SRC" ] && [ -n "$PICOLIBC_SRC" ]; then
|
||||
if grep -q FAILED "$APPS/sim.txt" || ! grep -q "^all ok" "$APPS/sim.txt"; then
|
||||
echo "sockets on PowerPC:"; cat "$APPS/sim.txt"; exit 1
|
||||
fi
|
||||
# Open Transport on 68k (over MacTCP), over the fake MacTCP. On
|
||||
# PowerPC the calls go to Mac OS's Open Transport, which the
|
||||
# simulator does not have: tools/qemu/nettest.py runs that build.
|
||||
for c in 68000 68020; do
|
||||
python3 tools/sim68k.py --cpu $c --os --files --exit-anywhere \
|
||||
"$APPS/ot-68k.bin" >"$APPS/sim.txt" || { cat "$APPS/sim.txt"; exit 1; }
|
||||
if grep -q FAILED "$APPS/sim.txt" || ! grep -q "^all ok" "$APPS/sim.txt"; then
|
||||
echo "Open Transport on a $c:"; cat "$APPS/sim.txt"; exit 1
|
||||
fi
|
||||
done
|
||||
# OpenGL and AGL, over the PowerPC simulator's fake OpenGL.
|
||||
python3 tools/simppc.py --files "$APPS/gl-ppc.bin" >"$APPS/sim.txt" ||
|
||||
{ cat "$APPS/sim.txt"; exit 1; }
|
||||
|
||||
+11
-1
@@ -90,6 +90,14 @@ def main():
|
||||
r = subprocess.run([sys.executable, os.path.join(HERE, "check-traps.py")],
|
||||
capture_output=True, text=True)
|
||||
summary = r.stderr.strip().splitlines()[-1].replace("check-traps: ", "")
|
||||
# The C library supplies these on 68k: Open Transport (ot68k.c and
|
||||
# otnative.c), the MacTCP name resolver (dnr.c) and the ASLM client
|
||||
# (aslm.c).
|
||||
libc_glue = set()
|
||||
for f in ("OpenTransport.h", "OpenTransportProviders.h", "AddressXlation.h",
|
||||
"LibraryManager.h"):
|
||||
libc_glue |= set(re.findall(r"\b(\w+)\(", open(os.path.join(ROOT, "include", "mv", f)).read()))
|
||||
in_libc = [n for n in glue if n in libc_glue]
|
||||
funcs = set(re.findall(r"\b(\w+)\(", "".join(
|
||||
re.sub(r"MAC_SINCE(?:_GESTALT)?\([^()]*\) |MAC_COLOR_QD ", "", open(os.path.join(ROOT, "include", "mv", f)).read())
|
||||
for f in os.listdir(os.path.join(ROOT, "include", "mv")))))
|
||||
@@ -104,7 +112,9 @@ def main():
|
||||
"predates, such as the HFS Plus API.", "",
|
||||
"## 68k", "",
|
||||
f"- {len(glue)} declared calls have no 68k trap and need glue code "
|
||||
"on 68k (listed in `include/needs-glue.txt`). Most are Mac OS 9 "
|
||||
"on 68k (listed in `include/needs-glue.txt`). The C library "
|
||||
f"supplies {len(in_libc)} of them: Open Transport, the MacTCP "
|
||||
"name resolver and the Shared Library Manager client. Most of the others are Mac OS 9 "
|
||||
"calls that never ran on 68k: the HFS Plus API, Navigation "
|
||||
"Services, Driver Services and the Name Registry.",
|
||||
f"- The ROM's PowerPC glue describes {len(info)} 68k calls. Checked "
|
||||
|
||||
+22
-2
@@ -41,6 +41,18 @@ TYPE_SIZE = {"uint8_t": 1, "uint16_t": 2, "uint32_t": 4, "uint64_t": 8,
|
||||
"int8_t": 1, "int16_t": 2, "int32_t": 4, "int64_t": 8,
|
||||
"char": 1, "Point": 4, "ProcPtr": 4, "void": 0, "double": 8}
|
||||
|
||||
# Definition files that Multiverse.h leaves out, as Apple's MacHeaders
|
||||
# did: their short names (A, MX, T_MORE, ...) would collide with
|
||||
# program names. A program includes them by their own names
|
||||
# (<AddressXlation.h>, <OpenTransport.h>, ...), which include
|
||||
# Multiverse.h first.
|
||||
STANDALONE = {
|
||||
"AddressXlation": ["AddressXlation"],
|
||||
"OpenTransport": ["OpenTransport"],
|
||||
"OpenTransportProviders": ["OpenTransportProviders", "OpenTptInternet"],
|
||||
"LibraryManager": ["LibraryManager"],
|
||||
}
|
||||
|
||||
# Headers from Apple's Universal Interfaces that programs include. Each
|
||||
# one includes the whole set.
|
||||
APPLE_NAMES = [
|
||||
@@ -50,7 +62,7 @@ APPLE_NAMES = [
|
||||
"Movies", "ImageCompression", "QuickTimeComponents", "MediaHandler", "ImageCodec", "MoviesFormat",
|
||||
"Errors", "Events", "Files", "Finder", "FixMath", "Folders", "Fonts",
|
||||
"Gestalt", "Icons", "Interrupts", "Kernel", "Lists", "LowMem",
|
||||
"MacErrors", "MacMemory", "MacTypes", "MacWindows", "Memory", "Menus",
|
||||
"MacErrors", "MacMemory", "MacTCP", "MacTypes", "MacWindows", "Memory", "Menus",
|
||||
"MixedMode", "NameRegistry", "Navigation", "Notification",
|
||||
"NumberFormatting", "OSUtils", "Packages", "PCI", "Printing",
|
||||
"Processes", "Quickdraw", "QuickdrawText", "Resources", "Retrace",
|
||||
@@ -751,7 +763,7 @@ def main():
|
||||
"tools/gen-headers.py. */\n#ifndef __MULTIVERSE__\n"
|
||||
"#define __MULTIVERSE__\n")
|
||||
for n in order:
|
||||
if n != "MPW":
|
||||
if n != "MPW" and n not in STANDALONE:
|
||||
f.write(f'#include "mv/{n}.h"\n')
|
||||
f.write('\n#ifdef __cplusplus\nextern "C" QDGlobals qd;\n#else\n'
|
||||
'extern QDGlobals qd;\n#endif\n#endif\n')
|
||||
@@ -761,6 +773,14 @@ def main():
|
||||
with open(os.path.join(a.out, n + ".h"), "w") as f:
|
||||
f.write(f"/* {n}.h: generated by tools/gen-headers.py. */\n"
|
||||
'#include "Multiverse.h"\n')
|
||||
for n, names in STANDALONE.items():
|
||||
if n not in headers:
|
||||
continue
|
||||
for name in names:
|
||||
with open(os.path.join(a.out, name + ".h"), "w") as f:
|
||||
f.write(f"/* {name}.h: generated by tools/gen-headers.py. */\n"
|
||||
'#include "Multiverse.h"\n'
|
||||
f'#include "mv/{n}.h"\n')
|
||||
with open(os.path.join(a.out, "needs-glue.txt"), "w") as f:
|
||||
f.write("".join(n + "\n" for n in gen.glue))
|
||||
print(f"gen-headers: {len(order)} headers, "
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"ATAManager":{"data":[],"func":["ATAFamBusEventForAIM","ATAFamIODone","NativeATAMgr"],"weak":false},"ATSUnicodeLib":{"data":[],"func":["ATSUBreakLine","ATSUCalculateBaselineDeltas","ATSUClearAttributes","ATSUClearFontFeatures","ATSUClearFontVariations","ATSUClearLayoutCache","ATSUClearLayoutControls","ATSUClearLineControls","ATSUClearSoftLineBreaks","ATSUClearStyle","ATSUCompareStyles","ATSUCopyAttributes","ATSUCopyLayoutControls","ATSUCopyLineControls","ATSUCopyToHandle","ATSUCountFontFeatureSelectors","ATSUCountFontFeatureTypes","ATSUCountFontInstances","ATSUCountFontNames","ATSUCountFontTracking","ATSUCountFontVariations","ATSUCreateAndCopyStyle","ATSUCreateAndCopyTextLayout","ATSUCreateMemorySetting","ATSUCreateStyle","ATSUCreateTextLayout","ATSUCreateTextLayoutWithTextHandle","ATSUCreateTextLayoutWithTextPtr","ATSUDisposeMemorySetting","ATSUDisposeStyle","ATSUDisposeTextLayout","ATSUDrawGlyphInfo","ATSUDrawText","ATSUFONDtoFontID","ATSUFindFontFromName","ATSUFindFontName","ATSUFontCount","ATSUFontIDtoFOND","ATSUGetAllAttributes","ATSUGetAllFontFeatures","ATSUGetAllFontVariations","ATSUGetAllLayoutControls","ATSUGetAllLineControls","ATSUGetAttribute","ATSUGetContinuousAttributes","ATSUGetCurrentMemorySetting","ATSUGetFontFallbacks","ATSUGetFontFeature","ATSUGetFontFeatureNameCode","ATSUGetFontFeatureSelectors","ATSUGetFontFeatureTypes","ATSUGetFontIDs","ATSUGetFontInstance","ATSUGetFontInstanceNameCode","ATSUGetFontVariationNameCode","ATSUGetFontVariationValue","ATSUGetGlyphBounds","ATSUGetGlyphInfo","ATSUGetIndFontName","ATSUGetIndFontTracking","ATSUGetIndFontVariation","ATSUGetLayoutControl","ATSUGetLineControl","ATSUGetNativeCurveType","ATSUGetRunStyle","ATSUGetSoftLineBreaks","ATSUGetStyleRefCon","ATSUGetTextHighlight","ATSUGetTextLayoutRefCon","ATSUGetTextLocation","ATSUGetTransientFontMatching","ATSUGlyphGetCubicPaths","ATSUGlyphGetCurvePaths","ATSUGlyphGetIdealMetrics","ATSUGlyphGetQuadraticPaths","ATSUGlyphGetScreenMetrics","ATSUHighlightText","ATSUIdle","ATSULeftwardCursorPosition","ATSUMatchFontsToText","ATSUMeasureText","ATSUMeasureTextImage","ATSUNextCursorPosition","ATSUOffsetToPosition","ATSUOverwriteAttributes","ATSUPasteFromHandle","ATSUPositionToOffset","ATSUPreviousCursorPosition","ATSURightwardCursorPosition","ATSUSetAttributes","ATSUSetCurrentMemorySetting","ATSUSetFontFallbacks","ATSUSetFontFeatures","ATSUSetLayoutControls","ATSUSetLineControls","ATSUSetRunStyle","ATSUSetSoftLineBreak","ATSUSetStyleRefCon","ATSUSetTextHandleLocation","ATSUSetTextLayoutRefCon","ATSUSetTextPointerLocation","ATSUSetTransientFontMatching","ATSUSetVariations","ATSUStyleIsEmpty","ATSUTextDeleted","ATSUTextInserted","ATSUTextMoved","ATSUUnderwriteAttributes","ATSUUnhighlightText"],"weak":false},"AppearanceLib":{"data":[],"func":["ActivateControl","AdvanceKeyboardFocus","ApplyThemeBackground","AutoEmbedControl","AutoSizeDialog","BeginThemeDragSound","ClearKeyboardFocus","CollapseAllWindows","CollapseWindow","CountSubControls","CreateRootControl","DeactivateControl","DisposeThemeDrawingState","DrawControlInCurrentPort","DrawThemeButton","DrawThemeChasingArrows","DrawThemeEditTextFrame","DrawThemeFocusRect","DrawThemeFocusRegion","DrawThemeGenericWell","DrawThemeListBoxFrame","DrawThemeMenuBackground","DrawThemeMenuBarBackground","DrawThemeMenuItem","DrawThemeMenuSeparator","DrawThemeMenuTitle","DrawThemeModelessDialogFrame","DrawThemePlacard","DrawThemePopupArrow","DrawThemePrimaryGroup","DrawThemeScrollBarArrows","DrawThemeScrollBarDelimiters","DrawThemeSecondaryGroup","DrawThemeSeparator","DrawThemeStandaloneGrowBox","DrawThemeStandaloneNoGrowBox","DrawThemeTab","DrawThemeTabPane","DrawThemeTickMark","DrawThemeTitleBarWidget","DrawThemeTrack","DrawThemeTrackTickMarks","DrawThemeWindowFrame","DrawThemeWindowHeader","DrawThemeWindowListViewHeader","DumpControlHierarchy","EmbedControl","EndThemeDragSound","FindControlUnderMouse","GetBestControlRect","GetBevelButtonContentInfo","GetBevelButtonMenuHandle","GetBevelButtonMenuValue","GetControlData","GetControlDataSize","GetControlFeatures","GetDialogItemAsControl","GetImageWellContentInfo","GetIndexedSubControl","GetKeyboardFocus","GetMenuItemCommandID","GetMenuItemFontID","GetMenuItemHierarchicalID","GetMenuItemIconHandle","GetMenuItemKeyGlyph","GetMenuItemModifiers","GetMenuItemRefCon","GetMenuItemRefCon2","GetMenuItemTextEncoding","GetRootControl","GetSuperControl","GetTabContentRect","GetTheme","GetThemeAccentColors","GetThemeBrushAsColor","GetThemeButtonBackgroundBounds","GetThemeButtonContentBounds","GetThemeButtonRegion","GetThemeCheckBoxStyle","GetThemeDrawingState","GetThemeFont","GetThemeMenuBackgroundRegion","GetThemeMenuBarHeight","GetThemeMenuItemExtra","GetThemeMenuSeparatorHeight","GetThemeMenuTitleExtra","GetThemeScrollBarArrowStyle","GetThemeScrollBarThumbStyle","GetThemeScrollBarTrackRect","GetThemeStandaloneGrowBoxBounds","GetThemeTabRegion","GetThemeTextColor","GetThemeTrackBounds","GetThemeTrackDragRect","GetThemeTrackLiveValue","GetThemeTLine truncated
|
||||
{"ATAManager":{"data":[],"func":["ATAFamBusEventForAIM","ATAFamIODone","NativeATAMgr"],"weak":false},"ATSUnicodeLib":{"data":[],"func":["ATSUBreakLine","ATSUCalculateBaselineDeltas","ATSUClearAttributes","ATSUClearFontFeatures","ATSUClearFontVariations","ATSUClearLayoutCache","ATSUClearLayoutControls","ATSUClearLineControls","ATSUClearSoftLineBreaks","ATSUClearStyle","ATSUCompareStyles","ATSUCopyAttributes","ATSUCopyLayoutControls","ATSUCopyLineControls","ATSUCopyToHandle","ATSUCountFontFeatureSelectors","ATSUCountFontFeatureTypes","ATSUCountFontInstances","ATSUCountFontNames","ATSUCountFontTracking","ATSUCountFontVariations","ATSUCreateAndCopyStyle","ATSUCreateAndCopyTextLayout","ATSUCreateMemorySetting","ATSUCreateStyle","ATSUCreateTextLayout","ATSUCreateTextLayoutWithTextHandle","ATSUCreateTextLayoutWithTextPtr","ATSUDisposeMemorySetting","ATSUDisposeStyle","ATSUDisposeTextLayout","ATSUDrawGlyphInfo","ATSUDrawText","ATSUFONDtoFontID","ATSUFindFontFromName","ATSUFindFontName","ATSUFontCount","ATSUFontIDtoFOND","ATSUGetAllAttributes","ATSUGetAllFontFeatures","ATSUGetAllFontVariations","ATSUGetAllLayoutControls","ATSUGetAllLineControls","ATSUGetAttribute","ATSUGetContinuousAttributes","ATSUGetCurrentMemorySetting","ATSUGetFontFallbacks","ATSUGetFontFeature","ATSUGetFontFeatureNameCode","ATSUGetFontFeatureSelectors","ATSUGetFontFeatureTypes","ATSUGetFontIDs","ATSUGetFontInstance","ATSUGetFontInstanceNameCode","ATSUGetFontVariationNameCode","ATSUGetFontVariationValue","ATSUGetGlyphBounds","ATSUGetGlyphInfo","ATSUGetIndFontName","ATSUGetIndFontTracking","ATSUGetIndFontVariation","ATSUGetLayoutControl","ATSUGetLineControl","ATSUGetNativeCurveType","ATSUGetRunStyle","ATSUGetSoftLineBreaks","ATSUGetStyleRefCon","ATSUGetTextHighlight","ATSUGetTextLayoutRefCon","ATSUGetTextLocation","ATSUGetTransientFontMatching","ATSUGlyphGetCubicPaths","ATSUGlyphGetCurvePaths","ATSUGlyphGetIdealMetrics","ATSUGlyphGetQuadraticPaths","ATSUGlyphGetScreenMetrics","ATSUHighlightText","ATSUIdle","ATSULeftwardCursorPosition","ATSUMatchFontsToText","ATSUMeasureText","ATSUMeasureTextImage","ATSUNextCursorPosition","ATSUOffsetToPosition","ATSUOverwriteAttributes","ATSUPasteFromHandle","ATSUPositionToOffset","ATSUPreviousCursorPosition","ATSURightwardCursorPosition","ATSUSetAttributes","ATSUSetCurrentMemorySetting","ATSUSetFontFallbacks","ATSUSetFontFeatures","ATSUSetLayoutControls","ATSUSetLineControls","ATSUSetRunStyle","ATSUSetSoftLineBreak","ATSUSetStyleRefCon","ATSUSetTextHandleLocation","ATSUSetTextLayoutRefCon","ATSUSetTextPointerLocation","ATSUSetTransientFontMatching","ATSUSetVariations","ATSUStyleIsEmpty","ATSUTextDeleted","ATSUTextInserted","ATSUTextMoved","ATSUUnderwriteAttributes","ATSUUnhighlightText"],"weak":false},"AppearanceLib":{"data":[],"func":["ActivateControl","AdvanceKeyboardFocus","ApplyThemeBackground","AutoEmbedControl","AutoSizeDialog","BeginThemeDragSound","ClearKeyboardFocus","CollapseAllWindows","CollapseWindow","CountSubControls","CreateRootControl","DeactivateControl","DisposeThemeDrawingState","DrawControlInCurrentPort","DrawThemeButton","DrawThemeChasingArrows","DrawThemeEditTextFrame","DrawThemeFocusRect","DrawThemeFocusRegion","DrawThemeGenericWell","DrawThemeListBoxFrame","DrawThemeMenuBackground","DrawThemeMenuBarBackground","DrawThemeMenuItem","DrawThemeMenuSeparator","DrawThemeMenuTitle","DrawThemeModelessDialogFrame","DrawThemePlacard","DrawThemePopupArrow","DrawThemePrimaryGroup","DrawThemeScrollBarArrows","DrawThemeScrollBarDelimiters","DrawThemeSecondaryGroup","DrawThemeSeparator","DrawThemeStandaloneGrowBox","DrawThemeStandaloneNoGrowBox","DrawThemeTab","DrawThemeTabPane","DrawThemeTickMark","DrawThemeTitleBarWidget","DrawThemeTrack","DrawThemeTrackTickMarks","DrawThemeWindowFrame","DrawThemeWindowHeader","DrawThemeWindowListViewHeader","DumpControlHierarchy","EmbedControl","EndThemeDragSound","FindControlUnderMouse","GetBestControlRect","GetBevelButtonContentInfo","GetBevelButtonMenuHandle","GetBevelButtonMenuValue","GetControlData","GetControlDataSize","GetControlFeatures","GetDialogItemAsControl","GetImageWellContentInfo","GetIndexedSubControl","GetKeyboardFocus","GetMenuItemCommandID","GetMenuItemFontID","GetMenuItemHierarchicalID","GetMenuItemIconHandle","GetMenuItemKeyGlyph","GetMenuItemModifiers","GetMenuItemRefCon","GetMenuItemRefCon2","GetMenuItemTextEncoding","GetRootControl","GetSuperControl","GetTabContentRect","GetTheme","GetThemeAccentColors","GetThemeBrushAsColor","GetThemeButtonBackgroundBounds","GetThemeButtonContentBounds","GetThemeButtonRegion","GetThemeCheckBoxStyle","GetThemeDrawingState","GetThemeFont","GetThemeMenuBackgroundRegion","GetThemeMenuBarHeight","GetThemeMenuItemExtra","GetThemeMenuSeparatorHeight","GetThemeMenuTitleExtra","GetThemeScrollBarArrowStyle","GetThemeScrollBarThumbStyle","GetThemeScrollBarTrackRect","GetThemeStandaloneGrowBoxBounds","GetThemeTabRegion","GetThemeTextColor","GetThemeTrackBounds","GetThemeTrackDragRect","GetThemeTrackLiveValue","GetThemeTLine truncated
|
||||
@@ -0,0 +1,230 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Run a network test program on Mac OS in QEMU, and collect its report.
|
||||
|
||||
The script puts the program in the Startup Items folder of a copy of a
|
||||
Mac OS disk or CD, so that Mac OS starts it after it boots. It starts two
|
||||
servers on the host, which the guest finds at 10.0.2.2 (QEMU's user
|
||||
network):
|
||||
|
||||
port 7009 a report server: it keeps what the program sends
|
||||
port 8080 a web server: it gives a short page to each GET
|
||||
|
||||
Then it boots QEMU and waits for the report to end (the program closes
|
||||
the connection), or for a request with --until-request.
|
||||
|
||||
# PowerPC: Mac OS 9.2.1 from its install CD
|
||||
python3 tools/qemu/nettest.py --machine mac99 --image "Mac OS 9.2.1.iso" ot-ppc.bin
|
||||
|
||||
# 68k: Mac OS 8.1 on a Quadra 800 disk (needs the Quadra 800 ROM)
|
||||
python3 tools/qemu/nettest.py --machine q800 --rom q800.rom \\
|
||||
--image hd81.qcow2 ot-68k.bin
|
||||
|
||||
# A program that reports nothing: wait for its web requests
|
||||
python3 tools/qemu/nettest.py --machine mac99 --image os921.iso \\
|
||||
--until-request "BSD sockets" --shot fetch.png Fetch.bin
|
||||
|
||||
The exit status is 0 when the report has "all ok" (or the request came),
|
||||
1 when it has "FAILED" or the time ends. tests/ot.c and examples/net/
|
||||
fetch.c know these servers. The guest needs TCP/IP set to DHCP (the
|
||||
default of the install CDs).
|
||||
|
||||
Needs qemu-system-ppc or qemu-system-m68k, qemu-img and hfsutils.
|
||||
"""
|
||||
import argparse
|
||||
import http.server
|
||||
import os
|
||||
import shutil
|
||||
import socket
|
||||
import socketserver
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import threading
|
||||
import time
|
||||
|
||||
HERE = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
|
||||
class Report:
|
||||
"""Keeps the bytes that the guest sends to the report server."""
|
||||
|
||||
def __init__(self):
|
||||
"""Makes an empty report."""
|
||||
self.text = ""
|
||||
self.ended = False
|
||||
self.requests = []
|
||||
self.lock = threading.Lock()
|
||||
|
||||
def add(self, data):
|
||||
"""Adds bytes from the guest to the report."""
|
||||
with self.lock:
|
||||
self.text += data.decode("latin-1")
|
||||
|
||||
def end(self):
|
||||
"""Records that the guest closed the report connection."""
|
||||
with self.lock:
|
||||
self.ended = True
|
||||
|
||||
|
||||
def serve_reports(report, port):
|
||||
"""Starts the report server on a thread. Gives the server."""
|
||||
class Handler(socketserver.BaseRequestHandler):
|
||||
"""Reads one report connection until the guest closes it."""
|
||||
|
||||
def handle(self):
|
||||
"""Adds each block that comes to the report."""
|
||||
while True:
|
||||
data = self.request.recv(4096)
|
||||
if not data:
|
||||
break
|
||||
report.add(data)
|
||||
report.end()
|
||||
|
||||
socketserver.TCPServer.allow_reuse_address = True
|
||||
server = socketserver.ThreadingTCPServer(("127.0.0.1", port), Handler)
|
||||
threading.Thread(target=server.serve_forever, daemon=True).start()
|
||||
return server
|
||||
|
||||
|
||||
def serve_web(report, port):
|
||||
"""Starts the web server on a thread. Gives the server."""
|
||||
class Handler(http.server.BaseHTTPRequestHandler):
|
||||
"""Gives a short page, and records the User-Agent of each GET."""
|
||||
|
||||
def do_GET(self):
|
||||
"""Sends the page."""
|
||||
body = b"<html><body>Hello from the QEMU host.</body></html>\n"
|
||||
self.send_response(200)
|
||||
self.send_header("Content-Type", "text/html")
|
||||
self.send_header("Content-Length", str(len(body)))
|
||||
self.end_headers()
|
||||
self.wfile.write(body)
|
||||
with report.lock:
|
||||
report.requests.append(self.headers.get("User-Agent", ""))
|
||||
|
||||
def log_message(self, *args):
|
||||
"""Writes no log."""
|
||||
|
||||
http.server.HTTPServer.allow_reuse_address = True
|
||||
server = http.server.ThreadingHTTPServer(("127.0.0.1", port), Handler)
|
||||
threading.Thread(target=server.serve_forever, daemon=True).start()
|
||||
return server
|
||||
|
||||
|
||||
def run(cmd, env=None):
|
||||
"""Runs a command, and stops the script when it fails."""
|
||||
subprocess.run(cmd, check=True, stdout=subprocess.DEVNULL, env=env)
|
||||
|
||||
|
||||
def install(image, app, name, work):
|
||||
"""Copies a MacBinary program into the Startup Items folder of the
|
||||
first HFS volume of a raw disk image. hfsutils keeps its current
|
||||
volume in $HOME/.hcwd, so each run gets its own HOME."""
|
||||
env = dict(os.environ, HOME=work)
|
||||
run(["hmount", image], env)
|
||||
try:
|
||||
# hmkdir fails when the folder is there: that is correct. (hls
|
||||
# gives status 0 also for a missing folder, so it cannot tell.)
|
||||
subprocess.run(["hmkdir", ":System Folder:Startup Items"], env=env,
|
||||
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||
run(["hcopy", "-m", app, ":System Folder:Startup Items:" + name], env)
|
||||
finally:
|
||||
subprocess.run(["humount"], stdout=subprocess.DEVNULL, env=env)
|
||||
|
||||
|
||||
def qemu_command(a, image, work):
|
||||
"""Gives the QEMU command for the machine."""
|
||||
mon = ["-monitor", f"unix:{work}/mon.sock,server,nowait",
|
||||
"-display", "none", "-vnc", a.vnc]
|
||||
if a.machine == "mac99":
|
||||
cd = a.image.lower().endswith((".iso", ".toast", ".cdr"))
|
||||
drive = (["-drive", f"file={image},format=raw,media=cdrom", "-boot", "d"] if cd else
|
||||
["-drive", f"file={image},format=raw,media=disk", "-boot", "c"])
|
||||
return (["qemu-system-ppc", "-M", "mac99,via=pmu", "-m", "512"] + drive +
|
||||
["-netdev", "user,id=n0", "-device", "sungem,netdev=n0",
|
||||
"-prom-env", "auto-boot?=true"] + mon)
|
||||
if not a.rom:
|
||||
sys.exit("nettest: --machine q800 needs --rom (a Quadra 800 ROM image)")
|
||||
return (["qemu-system-m68k", "-M", "q800", "-m", "128", "-bios", a.rom,
|
||||
"-g", "800x600x8",
|
||||
"-device", "scsi-hd,scsi-id=0,drive=hd0",
|
||||
"-drive", f"file={image},format=raw,if=none,id=hd0",
|
||||
"-nic", "user,model=dp83932",
|
||||
"-audiodev", "none,id=snd", "-machine", "audiodev=snd"] + mon)
|
||||
|
||||
|
||||
def screenshot(work, path):
|
||||
"""Saves the guest's screen as a PNG file (needs Pillow)."""
|
||||
s = socket.socket(socket.AF_UNIX)
|
||||
s.connect(os.path.join(work, "mon.sock"))
|
||||
ppm = os.path.join(work, "screen.ppm")
|
||||
s.sendall(f"screendump {ppm}\n".encode())
|
||||
time.sleep(1.5)
|
||||
s.close()
|
||||
from PIL import Image
|
||||
Image.open(ppm).save(path)
|
||||
|
||||
|
||||
def main():
|
||||
"""Prepares the disk, starts the servers and QEMU, and waits."""
|
||||
ap = argparse.ArgumentParser(description=__doc__.split("\n")[0])
|
||||
ap.add_argument("app", help="the program, a MacBinary file")
|
||||
ap.add_argument("--machine", choices=["mac99", "q800"], required=True)
|
||||
ap.add_argument("--image", required=True,
|
||||
help="a Mac OS install CD or disk (raw, ISO or qcow2); "
|
||||
"the script works on a copy")
|
||||
ap.add_argument("--rom", help="the Quadra 800 ROM (q800 only)")
|
||||
ap.add_argument("--timeout", type=int, default=600, help="seconds")
|
||||
ap.add_argument("--until-request", metavar="TEXT",
|
||||
help="end at a web request whose User-Agent has TEXT")
|
||||
ap.add_argument("--shot", metavar="PNG", help="save the screen at the end")
|
||||
ap.add_argument("--vnc", default=":3", help="the VNC display (default :3)")
|
||||
ap.add_argument("--report-port", type=int, default=7009)
|
||||
ap.add_argument("--web-port", type=int, default=8080)
|
||||
a = ap.parse_args()
|
||||
|
||||
work = tempfile.mkdtemp(prefix="nettest.")
|
||||
proc = None
|
||||
try:
|
||||
image = os.path.join(work, "disk.img")
|
||||
run(["qemu-img", "convert", "-O", "raw", a.image, image])
|
||||
install(image, a.app, "Net Test", work)
|
||||
report = Report()
|
||||
servers = [serve_reports(report, a.report_port), serve_web(report, a.web_port)]
|
||||
proc = subprocess.Popen(qemu_command(a, image, work),
|
||||
stdout=subprocess.DEVNULL, stderr=subprocess.PIPE)
|
||||
end = time.time() + a.timeout
|
||||
while time.time() < end and proc.poll() is None:
|
||||
with report.lock:
|
||||
if a.until_request:
|
||||
if any(a.until_request in r for r in report.requests):
|
||||
break
|
||||
elif report.ended or "all ok" in report.text:
|
||||
break
|
||||
time.sleep(2)
|
||||
if a.shot and proc.poll() is None:
|
||||
time.sleep(5)
|
||||
screenshot(work, a.shot)
|
||||
for s in servers:
|
||||
s.shutdown()
|
||||
sys.stdout.write(report.text)
|
||||
for r in report.requests:
|
||||
print(f"GET from {r}")
|
||||
if a.until_request:
|
||||
ok = any(a.until_request in r for r in report.requests)
|
||||
else:
|
||||
ok = "all ok" in report.text and "FAILED" not in report.text
|
||||
if proc.poll() is not None:
|
||||
print(f"nettest: QEMU stopped: {proc.stderr.read().decode(errors='replace')}")
|
||||
elif not ok:
|
||||
print("nettest: the time ended" if time.time() >= end else "nettest: failed")
|
||||
return 0 if ok else 1
|
||||
finally:
|
||||
if proc and proc.poll() is None:
|
||||
proc.kill()
|
||||
proc.wait()
|
||||
shutil.rmtree(work, ignore_errors=True)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
@@ -108,6 +108,7 @@ TRAPS = {
|
||||
0xA91E: ("TrackGoAway", 8, 2), 0xA91F: ("SelectWindow", 4, 0),
|
||||
0xA9B3: ("SystemClick", 8, 0), 0xA8D8: ("NewRgn", 0, 4),
|
||||
0xA8EF: ("ScrollRect", 12, 0), 0xA975: ("TickCount", 0, 4),
|
||||
0xA823: ("FindFolder", 16, 2), 0xA99D: ("GetIndResource", 6, 4),
|
||||
# What a program that shows its own pictures uses (FakeScreen).
|
||||
0xA916: ("HideWindow", 4, 0), 0xA91A: ("SetWTitle", 8, 0),
|
||||
0xA917: ("GetWRefCon", 4, 4), 0xA862: ("ForeColor", 4, 0),
|
||||
@@ -1502,6 +1503,10 @@ def main():
|
||||
uc.mem_write(sp, struct.pack(">I", 0x40000))
|
||||
elif name == "NewMenu":
|
||||
uc.mem_write(sp, struct.pack(">I", 0x50000))
|
||||
elif name == "GetIndResource": # finds no resource
|
||||
uc.mem_write(sp, b"\0\0\0\0")
|
||||
elif name == "FindFolder": # finds no folder
|
||||
uc.mem_write(sp, struct.pack(">h", -43))
|
||||
elif name == "TickCount": # one tick per call
|
||||
state["ticks"] += 1
|
||||
uc.mem_write(sp, struct.pack(">I", state["ticks"]))
|
||||
|
||||
Reference in new issue
Block a user