source: trunk/tools/common/kFileInterfaces.cpp

Last change on this file was 21916, checked in by dmik, 14 years ago

Merge branch gcc-kmk to trunk.

File size: 4.1 KB
Line 
1/* $Id: kFileInterfaces.cpp,v 1.1 2002-02-24 02:47:25 bird Exp $
2 *
3 * kFileInterface.cpp - Interface helpers and workers.
4 *
5 * I've decided that this is the logical place to put many
6 * of those generic worker/helper methods which works on
7 * or with the interfaces. In java this would be impossible
8 * using the real interfaces, but in C++ when we use empty
9 * classes it very possible and quite helpful.
10 *
11 * Copyright (c) 2001 knut st. osmundsen (kosmunds@csc.com)
12 *
13 * Project Odin Software License can be found in LICENSE.TXT
14 *
15 */
16
17
18/*******************************************************************************
19* Header Files *
20*******************************************************************************/
21#include <malloc.h>
22
23#include "kTypes.h"
24#include "kError.h"
25#include "kFileInterfaces.h"
26
27
28
29/*******************************************************************************
30* Structures and Typedefs *
31*******************************************************************************/
32/**
33 * XRef status and search info.
34 * kRelocEntry::pv2 points to this structure.
35 */
36typedef struct _XRefState
37{
38 /* Position we wanna find references to. */
39 unsigned long ulSegment;
40 unsigned long offSegment;
41} XREFSTATE, *PXREFSTATE;
42
43
44
45/**
46 * Finds the first reference to a location in the image.
47 *
48 * @returns Success indicator.
49 * TRUE if found anything.
50 * FALSE if nothing
51 * @param ulSegment Segment number (0-based).
52 * Special segment numbers are not supported.
53 * @param offSegment Offset into the segement (ulSegment).
54 * @param preloc The enumeration 'handle.'
55 * @status implemented.
56 * @author knut st. osmundsen (kosmunds@csc.com)
57 * @remark No special segment numbers are supported.
58 */
59KBOOL kRelocI::relocXRefFindFirst(unsigned long ulSegment, unsigned long offSegment, kRelocEntry *preloc)
60{
61 kASSERT(preloc);
62 kASSERT(ulSegment < kRelocEntry::enmFirstSelector);
63
64 /*
65 * Save the target we are searching for references to.
66 */
67 PXREFSTATE pState = (PXREFSTATE)malloc(sizeof(XREFSTATE));
68 pState->ulSegment = ulSegment;
69 pState->offSegment = offSegment;
70 preloc->pv2 = (void*)pState;
71
72 /*
73 * Start searching.
74 */
75 if (relocFindFirst(0, 0, preloc))
76 {
77 kASSERT(ulSegment < kRelocEntry::enmFirstSelector);
78 if ( preloc->isInternal()
79 && preloc->Info.Internal.ulSegment == ulSegment
80 && preloc->Info.Internal.offSegment == offSegment
81 )
82 return TRUE;
83
84 KBOOL fRc = relocXRefFindNext(preloc);
85 if (!fRc)
86 relocXRefFindClose(preloc);
87 return fRc;
88 }
89
90 return FALSE;
91}
92
93
94/**
95 * Finds the next reference to the address.
96 * @returns Success indicator.
97 * Returns FALSE if no more matches.
98 * @param preloc The enumeration 'handle.'
99 * This must be initiated by a call to relocXRefFindFirst.
100 * @status implemented.
101 * @author knut st. osmundsen (kosmunds@csc.com)
102 */
103KBOOL kRelocI::relocXRefFindNext(kRelocEntry *preloc)
104{
105 kASSERT(preloc->pv2 != NULL);
106
107 while (relocFindNext(preloc))
108 {
109 kASSERT(preloc->ulSegment < kRelocEntry::enmFirstSelector);
110 if ( preloc->isInternal()
111 && preloc->Info.Internal.ulSegment == ((PXREFSTATE)preloc->pv2)->ulSegment
112 && preloc->Info.Internal.offSegment == ((PXREFSTATE)preloc->pv2)->offSegment
113 )
114 return TRUE;
115 }
116
117 return FALSE;
118}
119
120
121/**
122 * Closes a find session - this function *must* be called to
123 * clean up resources used internally.
124 *
125 * @param preloc The enumeration 'handle.'
126 * This must be initiated by a call to relocXRefFindFirst.
127 * @status implemented.
128 * @author knut st. osmundsen (kosmunds@csc.com)
129 * @remark
130 */
131void kRelocI::relocXRefFindClose(kRelocEntry *preloc)
132{
133 kASSERT(preloc != NULL);
134 relocFindClose(preloc);
135 free(preloc->pv2);
136 preloc->pv2 = NULL;
137}
138
Note: See TracBrowser for help on using the repository browser.