summaryrefslogtreecommitdiffstats
path: root/private/ntos/rtl/alpha/localrtl.c
blob: e8e91b9ab107db5d60f35d07640a2523279ef39d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*++

Copyright (c) 1993  Digital Equipment Corporation

Module Name:

    localrtl.c

Abstract:

    This module contains alternate implementations of each of the Rtl Memory
    functions and other common functions required by the Rtl Memory test
    programs.

Author:

    Thomas Van Baak (tvb) 11-Jan-1993

Revision History:

--*/

#include <nt.h>
#include "localrtl.h"

//
// Simple pattern generator.
//

#define PATTERN "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define PATTERN_SIZE (sizeof(PATTERN) - 1)
UCHAR Pattern[] = PATTERN;

VOID
FillPattern(PUCHAR To, ULONG Length)
{
    ULONG Index;
    ULONG Rotor = 0;

    for (Index = 0; Index < Length; Index += 1) {
        To[Index] = Pattern[Rotor];
        Rotor += 1;
        if (Rotor == PATTERN_SIZE) {
            Rotor = 0;
        }
    }
}

//
// The following functions are simple, non-optimized, (and thus maybe even
// bug-proof) implementations of each of the Rtl Memory functions.
//

ULONG
LocalCompareMemory (
    PVOID Source1,
    PVOID Source2,
    ULONG Length
    )
{
    ULONG Index;
    PUCHAR Left = Source1;
    ULONG Match;
    PUCHAR Right = Source2;

    Match = 0;
    for (Index = 0; Index < Length; Index += 1) {
        if (Left[Index] != Right[Index]) {
            break;
        }
        Match += 1;
    }
    return Match;
}

ULONG
LocalCompareMemoryUlong (
    PVOID Source,
    ULONG Length,
    ULONG Pattern
    )
{
    PULONG From = Source;
    ULONG Index;
    ULONG Match;

    Match = 0;
    for (Index = 0; Index < Length / sizeof(ULONG); Index += 1) {
        if (From[Index] != Pattern) {
            break;
        }
        Match += sizeof(ULONG);
    }
    return Match;
}

VOID
LocalMoveMemory (
   PVOID Destination,
   PVOID Source,
   ULONG Length
   )
{
    PUCHAR From = Source;
    ULONG Index;
    PUCHAR To = Destination;

    for (Index = 0; Index < Length; Index += 1) {
        if (To <= From) {
            To[Index] = From[Index];

        } else {
            To[Length - 1 - Index] = From[Length - 1 - Index];
        }
    }
}

VOID
LocalFillMemory (
   PVOID Destination,
   ULONG Length,
   UCHAR Fill
   )
{
    ULONG Index;
    PUCHAR To = Destination;

    for (Index = 0; Index < Length; Index += 1) {
        To[Index] = Fill;
    }
}

VOID
LocalFillMemoryUlong (
   PVOID Destination,
   ULONG Length,
   ULONG Pattern
   )
{
    ULONG Index;
    PULONG To = Destination;

    for (Index = 0; Index < Length / sizeof(ULONG); Index += 1) {
        To[Index] = Pattern;
    }
}

VOID
LocalZeroMemory (
   PVOID Destination,
   ULONG Length
   )
{
    ULONG Index;
    PUCHAR To = Destination;

    for (Index = 0; Index < Length; Index += 1) {
        To[Index] = 0;
    }
}