mirror of
https://github.com/adtools/clib2.git
synced 2025-12-08 14:59:05 +00:00
- Added shared library skeleton code (68k-only for now).
git-svn-id: file:///Users/olsen/Code/migration-svn-zu-git/logical-line-staging/clib2/trunk@15000 87f5fb63-7c3d-0410-a384-fd976d0f7a62
This commit is contained in:
373
library/skeleton_library/lib_base.c
Executable file
373
library/skeleton_library/lib_base.c
Executable file
@ -0,0 +1,373 @@
|
||||
/*
|
||||
* $Id: lib_base.c,v 1.1 2005-07-04 09:39:00 obarthel Exp $
|
||||
*
|
||||
* :ts=4
|
||||
*
|
||||
* Amiga shared library skeleton example
|
||||
* Copyright (c) 2002-2005 by Olaf Barthel <olsen@sourcery.han.de>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* - Neither the name of Olaf Barthel nor the names of contributors
|
||||
* may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <exec/resident.h>
|
||||
#include <exec/libraries.h>
|
||||
#include <exec/memory.h>
|
||||
|
||||
#include <dos.h>
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
#ifndef __NOLIBBASE__
|
||||
#include <proto/exec.h>
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
#include "lib_base.h"
|
||||
#include "macros.h"
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
#include "skeleton.library_rev.h"
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
LONG _start(VOID);
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
STATIC struct SkeletonBase *ASM LibInit(REG (d0, struct SkeletonBase *sb ), REG (a0, BPTR segment_list ), REG (a6, struct Library *sys_base ));
|
||||
STATIC struct SkeletonBase *ASM LibOpen(REG (a6, struct SkeletonBase *sb ));
|
||||
STATIC BPTR ASM LibExpunge(REG (a6, struct SkeletonBase *sb ));
|
||||
STATIC BPTR ASM LibClose(REG (a6, struct SkeletonBase *sb ));
|
||||
STATIC LONG LibReserved(VOID);
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
/* This is the first executable location of the library. It must return
|
||||
an error to the unsuspecting caller who tries to run it as a program. */
|
||||
LONG
|
||||
_start(VOID)
|
||||
{
|
||||
return(-1);
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
/* This routine is called after the library has been loaded into
|
||||
memory and its base data structure has been created. Here we
|
||||
must initialize those parts of the base data structure which
|
||||
have not been set up yet. As of Kickstart 2.0 the setup code
|
||||
in ROM will have initialized the entire Library structure with
|
||||
the exception of the lib_Revision field, i.e. everything that
|
||||
could be gained from the Resident structure is now in the
|
||||
Library structure. Earlier operating system releases would leave
|
||||
the entire Library structure uninitialized. For this example
|
||||
we assume that Kickstart 2.0 is around as it must be possible
|
||||
to open dos.library V37.
|
||||
|
||||
The library initialization is single threaded, i.e. the operating
|
||||
system processes library initialization in a queue. The longer it
|
||||
takes for the following routine to set up the base data structure,
|
||||
the longer will other Tasks and Processes have to wait to get their
|
||||
disk resident libraries opened. This means, the initialization code
|
||||
has to be as brief as possible. This particular example code opens
|
||||
ROM resident libraries here, which is permitted. You should not
|
||||
open disk resident libraries and devices or do anything else that
|
||||
could take a long time to complete (in this context "long" is anything
|
||||
that takes up a second or longer).
|
||||
|
||||
This routine must return the Library base pointer if it succeeds.
|
||||
Failure is indicated by returning NULL instead. */
|
||||
STATIC struct SkeletonBase * ASM
|
||||
LibInit(
|
||||
REG(d0,struct SkeletonBase * sb),
|
||||
REG(a0,BPTR segment_list),
|
||||
REG(a6,struct Library * sys_base))
|
||||
{
|
||||
struct SkeletonBase * result = NULL;
|
||||
struct Library * SysBase;
|
||||
|
||||
SysBase = sys_base;
|
||||
|
||||
/* This library implementation requires Kickstart 2.04 or
|
||||
better to work. */
|
||||
if(SysBase->lib_Version < 37)
|
||||
{
|
||||
sb->sb_UserData = NULL;
|
||||
goto out;
|
||||
}
|
||||
|
||||
sb->sb_SysBase = SysBase;
|
||||
|
||||
InitSemaphore(&sb->sb_Semaphore);
|
||||
|
||||
/* The segment pointer must be stored for later, when this library is
|
||||
unloaded from memory again. */
|
||||
sb->sb_SegmentList = segment_list;
|
||||
|
||||
sb->sb_Library.lib_Revision = REVISION;
|
||||
|
||||
/* Allocate the implementation-specific user data structure. */
|
||||
sb->sb_UserData = AllocMem(sizeof(*sb->sb_UserData),MEMF_ANY|MEMF_PUBLIC);
|
||||
if(sb->sb_UserData == NULL)
|
||||
goto out;
|
||||
|
||||
/* Now try the user-supplied library initialization function. */
|
||||
if(UserLibInit(SysBase,sb->sb_UserData) == FALSE)
|
||||
goto out;
|
||||
|
||||
result = sb;
|
||||
|
||||
out:
|
||||
|
||||
/* Free the library data if the initialization failed. */
|
||||
if(result == NULL)
|
||||
{
|
||||
/* First take care of the user data. */
|
||||
if(sb->sb_UserData != NULL)
|
||||
FreeMem(sb->sb_UserData,sizeof(*sb->sb_UserData));
|
||||
|
||||
/* Finally, free the library data. This is necessary for a library
|
||||
of type RTF_AUTOINIT (see the "struct Resident" rt_Flags
|
||||
initialization value for the LibTag declaration at the end of
|
||||
this file). */
|
||||
FreeMem(((BYTE *)sb) - sb->sb_Library.lib_NegSize,
|
||||
(ULONG)(sb->sb_Library.lib_NegSize + sb->sb_Library.lib_PosSize));
|
||||
}
|
||||
|
||||
return(result);
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
/* This routine is called every time a Task or Process invokes
|
||||
OpenLibrary() on this library. Task switching will be disabled
|
||||
when control passes through this routine. Every action in this
|
||||
routine happens on the context of the calling Task, so unlike
|
||||
the library initialization routine one can open disk resident
|
||||
libraries, devices, etc. and generally Wait() for something
|
||||
to happen. The catch is that every busy operation that takes
|
||||
a while to execute will "freeze" the machine until control
|
||||
returns from this routine (Task switching is disabled). The Task
|
||||
switching is disabled in order to avoid having two Tasks
|
||||
execute this code at the same time. In a way, this makes the
|
||||
library routine a critical region in the textbook sense.
|
||||
|
||||
This routine must return the Library base pointer if it succeeds.
|
||||
Failure is indicated by returning NULL instead. */
|
||||
STATIC struct SkeletonBase * ASM
|
||||
LibOpen(REG(a6,struct SkeletonBase * sb))
|
||||
{
|
||||
USE_EXEC(sb);
|
||||
|
||||
struct SkeletonBase * result = NULL;
|
||||
|
||||
/* Mark the library as having another customer and
|
||||
clear the delayed expunge flag. This flag is
|
||||
referenced at the time the last customer closes
|
||||
the library. If set, the library will be both
|
||||
closed and removed from memory. We increment the
|
||||
counter here since we will attempt to gain
|
||||
access to a semaphore, which may have the effect
|
||||
of causing the caller to wait. During the time
|
||||
the caller is waiting somebody might trigger
|
||||
the library expunge function which, if the
|
||||
usage counter is zero, would unload the library. */
|
||||
sb->sb_Library.lib_OpenCnt++;
|
||||
sb->sb_Library.lib_Flags &= ~LIBF_DELEXP;
|
||||
|
||||
/* Now comes the really critical region of the code
|
||||
Only one Task at a time may enter here. */
|
||||
ObtainSemaphore(&sb->sb_Semaphore);
|
||||
|
||||
/* Invoke the user-supplied library open function. */
|
||||
if(UserLibOpen(sb->sb_UserData) == FALSE)
|
||||
goto out;
|
||||
|
||||
/* We have another customer. */
|
||||
sb->sb_Library.lib_OpenCnt++;
|
||||
|
||||
result = sb;
|
||||
|
||||
out:
|
||||
|
||||
ReleaseSemaphore(&sb->sb_Semaphore);
|
||||
|
||||
sb->sb_Library.lib_OpenCnt--;
|
||||
|
||||
return(result);
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
/* This routine will be called when the library needs to be
|
||||
removed from memory. If there are no Tasks or Processes
|
||||
which have the library open, the routine must remove itself
|
||||
from the public list of libraries, free the data that had
|
||||
been allocated for it and return the segment list pointer
|
||||
it had been given at initialization time so all its code
|
||||
can be unloaded. This routine is the last to be called in
|
||||
the life cycle of the library. It is called while Task
|
||||
switching is disabled. */
|
||||
STATIC BPTR ASM
|
||||
LibExpunge(REG(a6,struct SkeletonBase * sb))
|
||||
{
|
||||
USE_EXEC(sb);
|
||||
|
||||
BPTR result = ZERO;
|
||||
|
||||
/* If there are still customers which have the
|
||||
library open, mark the library for delayed
|
||||
expunge. This means, the library will be removed
|
||||
as soon as the last customer closes it. */
|
||||
if(sb->sb_Library.lib_OpenCnt > 0)
|
||||
{
|
||||
sb->sb_Library.lib_Flags |= LIBF_DELEXP;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Invoke the user-supplied expunge function. It must
|
||||
not break a Forbid(), i.e. it must not call Wait()
|
||||
directly or indirectly. */
|
||||
UserLibExpunge(sb->sb_UserData);
|
||||
|
||||
/* Free the user data itself. */
|
||||
FreeMem(sb->sb_UserData,sizeof(*sb->sb_UserData));
|
||||
|
||||
/* This is the segment list pointer we have to return. */
|
||||
result = sb->sb_SegmentList;
|
||||
|
||||
/* Remove the library from the public list. */
|
||||
Remove((struct Node *)sb);
|
||||
|
||||
/* Finally, free the data allocated for the
|
||||
base data structure. */
|
||||
FreeMem(((BYTE *)sb) - sb->sb_Library.lib_NegSize,
|
||||
(ULONG)(sb->sb_Library.lib_NegSize + sb->sb_Library.lib_PosSize));
|
||||
}
|
||||
|
||||
return(result);
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
/* This routine is called every time CloseLibrary() is used
|
||||
on the Library base data structure. It is called while
|
||||
Task switching is disabled and has to return the result
|
||||
code of the library expunge routine when the time is right. */
|
||||
STATIC BPTR ASM
|
||||
LibClose(REG(a6,struct SkeletonBase * sb))
|
||||
{
|
||||
USE_EXEC(sb);
|
||||
|
||||
BPTR result = ZERO;
|
||||
|
||||
/* Now comes the really critical region of the code
|
||||
Only one Task at a time may enter here. */
|
||||
ObtainSemaphore(&sb->sb_Semaphore);
|
||||
|
||||
/* Invoke the user-supplied library close function. */
|
||||
UserLibClose(sb->sb_UserData);
|
||||
|
||||
ReleaseSemaphore(&sb->sb_Semaphore);
|
||||
|
||||
/* One less customer. */
|
||||
sb->sb_Library.lib_OpenCnt--;
|
||||
|
||||
/* Trigger the library expunge function, if desired. */
|
||||
if(sb->sb_Library.lib_OpenCnt == 0 && (sb->sb_Library.lib_Flags & LIBF_DELEXP) != 0)
|
||||
result = LibExpunge(sb);
|
||||
|
||||
return(result);
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
/* This is the reserved library entry point. It always
|
||||
has to return 0. */
|
||||
STATIC LONG
|
||||
LibReserved(VOID)
|
||||
{
|
||||
return(0);
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
/* The following data structures and data are responsible for
|
||||
setting up the Library base data structure and the library
|
||||
function vector. */
|
||||
struct LibraryInitTable
|
||||
{
|
||||
ULONG lit_BaseSize; /* Size of the base data structure. */
|
||||
APTR * lit_VectorTable; /* Points to the function vector. */
|
||||
APTR lit_InitTable; /* Library base data structure setup table. */
|
||||
APTR lit_InitRoutine; /* The address of the routine to do the setup. */
|
||||
};
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
/* This is the table of functions that make up the library. The first
|
||||
four are mandatory, everything following it are user callable
|
||||
routines. The table is terminated by the value -1. */
|
||||
STATIC CONST APTR LibVectors[] =
|
||||
{
|
||||
LibOpen,
|
||||
LibClose,
|
||||
LibExpunge,
|
||||
LibReserved,
|
||||
|
||||
(APTR) -1
|
||||
};
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
/* This finally sets up the library base data structure and the
|
||||
function vector. */
|
||||
STATIC CONST struct LibraryInitTable LibInitTable =
|
||||
{
|
||||
sizeof(struct SkeletonBase),
|
||||
LibVectors,
|
||||
NULL,
|
||||
LibInit
|
||||
};
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
/* The library loader looks for this marker in the memory
|
||||
the library code and data will occupy. It is responsible
|
||||
setting up the Library base data structure. */
|
||||
struct Resident LibTag[] =
|
||||
{
|
||||
RTC_MATCHWORD, /* Marker value. */
|
||||
&LibTag[0], /* This points back to itself. */
|
||||
&LibTag[1], /* This points behind this marker. */
|
||||
RTF_AUTOINIT, /* The Library should be set up according to the given table. */
|
||||
VERSION, /* The version of this Library. */
|
||||
NT_LIBRARY, /* This defines this module as a Library. */
|
||||
0, /* Initialization priority of this Library; unused. */
|
||||
"skeleton.library", /* Points to the name of the Library. */
|
||||
VSTRING, /* The identification string of this Library. */
|
||||
&LibInitTable /* This table is for initializing the Library. */
|
||||
};
|
||||
75
library/skeleton_library/lib_base.h
Executable file
75
library/skeleton_library/lib_base.h
Executable file
@ -0,0 +1,75 @@
|
||||
/*
|
||||
* $Id: lib_base.h,v 1.1 2005-07-04 09:39:00 obarthel Exp $
|
||||
*
|
||||
* :ts=4
|
||||
*
|
||||
* Amiga shared library skeleton example
|
||||
* Copyright (c) 2002-2005 by Olaf Barthel <olsen@sourcery.han.de>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* - Neither the name of Olaf Barthel nor the names of contributors
|
||||
* may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _LIB_BASE_H
|
||||
#define _LIB_BASE_H
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
#ifndef EXEC_LIBRARIES_H
|
||||
#include <exec/libraries.h>
|
||||
#endif /* EXEC_LIBRARIES_H */
|
||||
|
||||
#ifndef EXEC_SEMAPHORES_H
|
||||
#include <exec/semaphores.h>
|
||||
#endif /* EXEC_SEMAPHORES_H */
|
||||
|
||||
#ifndef DOS_DOS_H
|
||||
#include <dos/dos.h>
|
||||
#endif /* DOS_DOS_H */
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
#ifndef _LIB_USER_H
|
||||
#include "lib_user.h"
|
||||
#endif /* _LIB_USER_H */
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
struct SkeletonBase
|
||||
{
|
||||
struct Library sb_Library;
|
||||
struct SignalSemaphore sb_Semaphore;
|
||||
BPTR sb_SegmentList;
|
||||
struct Library * sb_SysBase;
|
||||
struct UserData * sb_UserData;
|
||||
};
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
#define USE_EXEC(sb) \
|
||||
struct Library * SysBase = (sb)->sb_SysBase
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
#endif /* _LIB_BASE_H */
|
||||
116
library/skeleton_library/lib_user.c
Executable file
116
library/skeleton_library/lib_user.c
Executable file
@ -0,0 +1,116 @@
|
||||
/*
|
||||
* $Id: lib_user.c,v 1.1 2005-07-04 09:39:00 obarthel Exp $
|
||||
*
|
||||
* :ts=4
|
||||
*
|
||||
* Amiga shared library skeleton example
|
||||
* Copyright (c) 2002-2005 by Olaf Barthel <olsen@sourcery.han.de>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* - Neither the name of Olaf Barthel nor the names of contributors
|
||||
* may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "lib_base.h"
|
||||
#include "lib_user.h"
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
/* The following function is called as part of the library initialization,
|
||||
right after the library is loaded. This function should perform only
|
||||
initialization operations which can be accomplished quickly and without
|
||||
delay because only one library initialization function at a time can
|
||||
be run by the operating system. This means that until this function has
|
||||
has returned, no other program or operating system component will be able
|
||||
to open a library.
|
||||
|
||||
By the time this function is invoked the library base has already been
|
||||
initialized. It has to return TRUE for success and FALSE otherwise. */
|
||||
BOOL
|
||||
UserLibInit(struct Library * SysBase,struct UserData * ud)
|
||||
{
|
||||
BOOL result;
|
||||
|
||||
/* We reset the use count of the user data to 0, so that we can
|
||||
keep track of how many users are actually using it. Note that
|
||||
the contents of the UserData structure are completely random
|
||||
when this function is called. */
|
||||
ud->ud_UseCount = 0;
|
||||
|
||||
/* Also remember the SysBase pointer. */
|
||||
ud->ud_SysBase = SysBase;
|
||||
|
||||
result = TRUE;
|
||||
|
||||
return(result);
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
/* The following function is called whenever the library is opened. Since
|
||||
by the time is called the library may have had another opener, it cannot
|
||||
rely upon the sb->sb_Library.lib_OpenCnt value to be current, it must
|
||||
find other means to keep track of whether it was invoked for the first
|
||||
time or not. In this function initializations such as resource allocations
|
||||
are performed. Unlike the UserLibInit() function, these initializations
|
||||
can take their time to complete since these will execute on the
|
||||
schedule of the caller. Take care: some callers may be plain Tasks which
|
||||
cannot call all dos.library functions! This function has to return TRUE for
|
||||
success and FALSE otherwise. */
|
||||
BOOL
|
||||
UserLibOpen(struct UserData * ud)
|
||||
{
|
||||
BOOL result;
|
||||
|
||||
/* Remember that one more customer is using this data structure. */
|
||||
ud->ud_UseCount++;
|
||||
|
||||
result = TRUE;
|
||||
|
||||
return(result);
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
/* The following function is called whenever the library is closed. Its
|
||||
purpose is to release any resources allocated by the UserLibOpen()
|
||||
function, such as when the last caller has closed the library. */
|
||||
VOID
|
||||
UserLibClose(struct UserData * ud)
|
||||
{
|
||||
/* Remember that one less customer is using this data structure. */
|
||||
ud->ud_UseCount--;
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
/* The following function is called shortly before the library is to be
|
||||
unloaded from memory. Its purpose is to release any resources
|
||||
allocated by the UserLibInit() function. Note that this function must
|
||||
not break the Forbid() condition, i.e. it must not call Wait() directly
|
||||
or indirectly. */
|
||||
VOID
|
||||
UserLibExpunge(struct UserData * ud)
|
||||
{
|
||||
/* In this brief example no special cleanup operations are performed. */
|
||||
}
|
||||
60
library/skeleton_library/lib_user.h
Executable file
60
library/skeleton_library/lib_user.h
Executable file
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* $Id: lib_user.h,v 1.1 2005-07-04 09:39:00 obarthel Exp $
|
||||
*
|
||||
* :ts=4
|
||||
*
|
||||
* Amiga shared library skeleton example
|
||||
* Copyright (c) 2002-2005 by Olaf Barthel <olsen@sourcery.han.de>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* - Neither the name of Olaf Barthel nor the names of contributors
|
||||
* may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _LIB_USER_H
|
||||
#define _LIB_USER_H
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
#ifndef EXEC_LIBRARIES_H
|
||||
#include <exec/libraries.h>
|
||||
#endif /* EXEC_LIBRARIES_H */
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
struct UserData
|
||||
{
|
||||
struct Library * ud_SysBase;
|
||||
ULONG ud_UseCount;
|
||||
};
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
BOOL UserLibInit(struct Library *SysBase,struct UserData *ud);
|
||||
BOOL UserLibOpen(struct UserData *ud);
|
||||
VOID UserLibClose(struct UserData *ud);
|
||||
VOID UserLibExpunge(struct UserData *ud);
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
#endif /* _LIB_USER_H */
|
||||
105
library/skeleton_library/macros.h
Executable file
105
library/skeleton_library/macros.h
Executable file
@ -0,0 +1,105 @@
|
||||
/*
|
||||
* $Id: macros.h,v 1.1 2005-07-04 09:39:00 obarthel Exp $
|
||||
*
|
||||
* :ts=4
|
||||
*
|
||||
* Amiga shared library skeleton example
|
||||
* Copyright (c) 2002-2005 by Olaf Barthel <olsen@sourcery.han.de>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* - Neither the name of Olaf Barthel nor the names of contributors
|
||||
* may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _MACROS_H
|
||||
#define _MACROS_H
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
#ifndef EXEC_TYPES_H
|
||||
#include <exec/types.h>
|
||||
#endif /* EXEC_TYPES_H */
|
||||
|
||||
#ifndef DOS_DOS_H
|
||||
#include <dos/dos.h>
|
||||
#endif /* DOS_DOS_H */
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
/* We use a few macros to ease the declaration of function parameters
|
||||
which are normally part of the AmigaOS4 header files. They are
|
||||
automatically included by the <exec/types.h> header file. However,
|
||||
if you are going to build this code on the plain 68k AmigaOS
|
||||
platform, you will need to define these macros locally. */
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
#ifndef AMIGA_COMPILER_H
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
#ifdef __SASC
|
||||
|
||||
#ifndef ASM
|
||||
#define ASM __asm
|
||||
#endif /* ASM */
|
||||
|
||||
#ifndef REG
|
||||
#define REG(reg,arg) register __##reg arg
|
||||
#endif /* REG */
|
||||
|
||||
#define APICALL
|
||||
|
||||
#endif /* __SASC */
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
#ifdef __GNUC__
|
||||
|
||||
#ifndef ASM
|
||||
#define ASM
|
||||
#endif /* ASM */
|
||||
|
||||
#ifndef REG
|
||||
#define REG(reg,arg) arg __asm(#reg)
|
||||
#endif /* REG */
|
||||
|
||||
#define APICALL
|
||||
|
||||
#define VARARGS68K
|
||||
|
||||
#endif /* __GNUC__ */
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
#endif /* AMIGA_COMPILER_H */
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
#ifndef ZERO
|
||||
#define ZERO ((BPTR)NULL)
|
||||
#endif /* ZERO */
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
#endif /* _MACROS_H */
|
||||
6
library/skeleton_library/skeleton.library_rev.h
Executable file
6
library/skeleton_library/skeleton.library_rev.h
Executable file
@ -0,0 +1,6 @@
|
||||
#define VERSION 1
|
||||
#define REVISION 1
|
||||
#define DATE "4.7.2005"
|
||||
#define VERS "skeleton.library 1.1"
|
||||
#define VSTRING "skeleton.library 1.1 (4.7.2005)\r\n"
|
||||
#define VERSTAG "\0$VER: skeleton.library 1.1 (4.7.2005)"
|
||||
1
library/skeleton_library/skeleton.library_rev.rev
Executable file
1
library/skeleton_library/skeleton.library_rev.rev
Executable file
@ -0,0 +1 @@
|
||||
1
|
||||
105
library/skeleton_library/smakefile
Executable file
105
library/skeleton_library/smakefile
Executable file
@ -0,0 +1,105 @@
|
||||
#
|
||||
# $Id: smakefile,v 1.1 2005-07-04 09:39:00 obarthel Exp $
|
||||
#
|
||||
# :ts=4
|
||||
#
|
||||
# Amiga shared library skeleton example
|
||||
# Copyright (c) 2002-2005 by Olaf Barthel <olsen@sourcery.han.de>
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# - Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
#
|
||||
# - Neither the name of Olaf Barthel nor the names of contributors
|
||||
# may be used to endorse or promote products derived from this
|
||||
# software without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
|
||||
#############################################################################
|
||||
#
|
||||
# Library version
|
||||
#
|
||||
#############################################################################
|
||||
|
||||
VERSION = 1
|
||||
|
||||
###############################################################################
|
||||
|
||||
#OPTIMIZE = optimize optsize optinline optinlocal
|
||||
CPU = 060
|
||||
#DEBUG = line
|
||||
DEBUG = symbolflush noopt
|
||||
|
||||
###############################################################################
|
||||
|
||||
CFLAGS = idlen=64 comnest strmerge nostkchk \
|
||||
strsect=code $(OPTIMIZE) cpu=$(CPU) debug=$(DEBUG) \
|
||||
params=register data=faronly commentnest idir=V:include
|
||||
LFLAGS = smallcode noicons
|
||||
|
||||
###############################################################################
|
||||
|
||||
OBJS = lib_base.o lib_user.o
|
||||
|
||||
###############################################################################
|
||||
|
||||
LIBS = lib:scnb.lib lib:amiga.lib lib:debug.lib
|
||||
|
||||
###############################################################################
|
||||
|
||||
all: skeleton.library
|
||||
|
||||
skeleton.library: $(OBJS)
|
||||
slink $(OBJS) to $@.debug lib $(LIBS) $(LFLAGS) \
|
||||
map $@.map,fhx fwidth 32 pwidth 32 swidth 32
|
||||
slink $@.debug to $@ noicons nodebug
|
||||
|
||||
###############################################################################
|
||||
|
||||
clean:
|
||||
-delete \#?.o skeleton.library(%|.debug)
|
||||
|
||||
realclean: clean
|
||||
-delete tags tagfiles \#?.map all
|
||||
|
||||
###############################################################################
|
||||
|
||||
install: skeleton.library
|
||||
copy skeleton.library libs:
|
||||
|
||||
###############################################################################
|
||||
|
||||
mkid:
|
||||
mkid -v \#?.(c|h|a|asm|i)
|
||||
|
||||
update:
|
||||
mkid -v -u
|
||||
|
||||
version:
|
||||
bumprev $(VERSION) skeleton.library
|
||||
|
||||
###############################################################################
|
||||
|
||||
cvs-tag:
|
||||
cvs -q tag V$(VERSION)_`type skeleton.library_rev.rev`
|
||||
|
||||
###############################################################################
|
||||
|
||||
lib_base.o : lib_base.c lib_base.h lib_user.h skeleton.library_rev.h
|
||||
lib_user.o : lib_user.c lib_user.h lib_base.h
|
||||
Reference in New Issue
Block a user