mirror of
https://github.com/alfishe/amiga-bootcamp.git
synced 2026-06-13 00:26:28 +00:00
Convert bare .md path references in 29 files to proper [name](relative/path) markdown links for GitHub navigation.
2.6 KiB
2.6 KiB
Library System — OpenLibrary Lifecycle
Overview
The AmigaOS library system provides versioned, shared code via a standardised interface. Libraries are identified by name, opened with a version check, and reference-counted for safe unloading.
Library Node
Every library is an NT_LIBRARY node on SysBase->LibList:
struct Library {
struct Node lib_Node; /* ln_Name = "dos.library" */
UBYTE lib_Flags; /* LIBF_SUMUSED | LIBF_DELEXP */
UBYTE lib_Pad;
UWORD lib_NegSize; /* size of JMP table in bytes */
UWORD lib_PosSize; /* size of library base struct */
UWORD lib_Version; /* major version */
UWORD lib_Revision; /* minor revision */
APTR lib_IdString; /* "dos.library 40.1 (16.7.93)" */
ULONG lib_Sum; /* JMP table checksum */
UWORD lib_OpenCnt; /* reference count */
};
OpenLibrary / CloseLibrary
/* Open — get a reference: */
struct DosLibrary *DOSBase =
(struct DosLibrary *)OpenLibrary("dos.library", 40);
/* Use the library ... */
/* Close — release reference: */
CloseLibrary((struct Library *)DOSBase);
Internally:
execscansLibListforln_Name == "dos.library"- If not found, searches resident list and
LIBS:path - If found on disk:
LoadSeg+ callInitLib - Check
lib_Version >= requested_version - Call library's
Open()vector →lib_OpenCnt++ - Return library base
Library Flags
| Flag | Value | Meaning |
|---|---|---|
LIBF_SUMUSED |
0x01 | Checksum is maintained |
LIBF_CHANGED |
0x02 | Checksum needs recalculation |
LIBF_DELEXP |
0x04 | Expunge deferred (opened while expunge pending) |
Version Numbering Convention
lib_Version.lib_Revision:
40.1= OS 3.1 release40.x= OS 3.1 (various revisions)44.x= OS 3.2
Increment rules:
lib_Revision— minor bugfix, compatiblelib_Version— API change or major update (requestors check this)
Finding a Library Without Opening
/* Read-only peek — no open count increment */
Forbid();
struct Library *lib = FindName(&SysBase->LibList, "graphics.library");
Permit();
if (lib) printf("Found v%d\n", lib->lib_Version);
Caution
Using
FindNamewithoutForbid()is a race condition — the library could be expunged between finding it and using it.
References
- NDK39:
exec/libraries.h - ADCD 2.1:
OpenLibrary,CloseLibrary,FindName - shared_libraries_runtime.md — expunge lifecycle