try to make sure compiler/include/mmakefile is always refreshed correctly.
[AROS.git] / rom / exec / sumlibrary.c
blob07dbdb4e0cd3137db7268e0a985330dd7bcf5604
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Build checksum for a library.
6 Lang: english
7 */
8 #include <exec/execbase.h>
9 #include <exec/alerts.h>
10 #include <aros/libcall.h>
11 #include <proto/exec.h>
13 /*****************************************************************************
15 NAME */
17 AROS_LH1(void, SumLibrary,
19 /* SYNOPSIS */
20 AROS_LHA(struct Library *, library,A1),
22 /* LOCATION */
23 struct ExecBase *, SysBase, 71, Exec)
25 /* FUNCTION
26 Builds the checksum over a given library's jumptable and either puts
27 it into the library->lib_Sum field (if the library is marked as changed)
28 or compares it with this field and Alert()s at mismatch.
30 INPUTS
31 library - Pointer to library structure.
33 RESULT
35 NOTES
37 EXAMPLE
39 BUGS
41 SEE ALSO
42 AddLibrary(), RemLibrary(), MakeLibrary(), MakeFunctions(), InitStruct()
44 INTERNALS
46 ******************************************************************************/
48 AROS_LIBFUNC_INIT
50 UBYTE oldflags;
51 ULONG sum;
53 /* Arbitrate for library base */
54 Forbid();
57 If the library checksumming is already in progress or if the
58 checksum is unused skip this part
60 if(library->lib_Flags&LIBF_SUMUSED&&!(library->lib_Flags&LIBF_SUMMING))
62 /* As long as the library is marked as changed */
65 ULONG *lp;
67 /* Memorize library flags */
68 oldflags=library->lib_Flags;
70 /* Tell other tasks: Summing in progress */
71 library->lib_Flags|=LIBF_SUMMING;
72 library->lib_Flags&=~LIBF_CHANGED;
74 /* As long as the summing goes multitasking may be permitted. */
75 Permit();
77 /* Build checksum. Note: library bases are LONG aligned */
78 sum=0;
79 /* Get start of jumptable */
80 lp=(ULONG *)((UBYTE *)library+library->lib_NegSize);
81 /* And sum it up */
82 while(lp<(ULONG *)library)
83 sum+=*lp++;
85 /* Summing complete. Arbitrate again. */
86 Forbid();
88 /* Remove summing flag */
89 library->lib_Flags&=~LIBF_SUMMING;
91 /* Do it again if the library changed while summing. */
92 }while(library->lib_Flags&LIBF_CHANGED);
95 Alert() if the library wasn't marked as changed and if the
96 checksum mismatches.
98 if(!(oldflags&LIBF_CHANGED)&&library->lib_Sum!=sum)
99 Alert(AT_DeadEnd|AN_LibChkSum);
101 /* Set new checksum */
102 library->lib_Sum=sum;
105 /* All done. */
106 Permit();
107 AROS_LIBFUNC_EXIT
108 } /* SumLibrary */