40
96
if (fmh == NULL) {
97
fprintf(stderr, "CreateFileMapping,
98
gle: 0x%08x", GetLastError());
99
exit(1);
100
}
101
102
/*
103
* Map into our address space and get a pointer
104
* to the beginning
105
* */
106
char *pmaddr = (char *)MapViewOfFileEx(fmh,
107
FILE_MAP_ALL_ACCESS,
108
0,
109
0,
110
filelen,
111
NULL); /* hint address */
112
113
if (pmaddr == NULL) {
114
fprintf(stderr, "MapViewOfFileEx,
115
gle: 0x%08x", GetLastError());
116
exit(1);
117
}
118
119
/*
120
* On windows must leave the file handle(s)
121
* open while mmaped
122
* */
123
124
/* Store a string to the beginning of the file */
125
strcpy(pmaddr, "This is new data written to
126
the file");
127
128
/*
129
* Flush this page with length rounded up to 4K
130
* page size
131
* */
Chapter 3 Operating SyStem SuppOrt fOr perSiStent memOry
96
if (fmh == NULL) {
97
fprintf(stderr, "CreateFileMapping,
98
gle: 0x%08x", GetLastError());
99
exit(1);
100
}
101
102
/*
103
* Map into our address space and get a pointer
104
* to the beginning
105
* */
106
char *pmaddr = (char *)MapViewOfFileEx(fmh,
107
FILE_MAP_ALL_ACCESS,
108
0,
109
0,
110
filelen,
111
NULL); /* hint address */
112
113
if (pmaddr == NULL) {
114
fprintf(stderr, "MapViewOfFileEx,
115
gle: 0x%08x", GetLastError());
116
exit(1);
117
}
118
119
/*
120
* On windows must leave the file handle(s)
121
* open while mmaped
122
* */
123
124
/* Store a string to the beginning of the file */
125
strcpy(pmaddr, "This is new data written to
126
the file");
127
128
/*
129
* Flush this page with length rounded up to 4K
130
* page size
131
* */
Chapter 3 Operating SyStem SuppOrt fOr perSiStent memOry
