server: Store a duplicate of the file descriptor for file mappings.
[wine] / server / mapping.c
1 /*
2  * Server-side file mapping management
3  *
4  * Copyright (C) 1999 Alexandre Julliard
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 #include "config.h"
22 #include "wine/port.h"
23
24 #include <assert.h>
25 #include <stdarg.h>
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <sys/stat.h>
29 #include <unistd.h>
30
31 #include "ntstatus.h"
32 #define WIN32_NO_STATUS
33 #include "windef.h"
34 #include "winternl.h"
35
36 #include "file.h"
37 #include "handle.h"
38 #include "thread.h"
39 #include "request.h"
40 #include "security.h"
41
42 /* list of memory ranges, used to store committed info */
43 struct ranges
44 {
45     unsigned int count;
46     unsigned int max;
47     struct range
48     {
49         file_pos_t  start;
50         file_pos_t  end;
51     } ranges[1];
52 };
53
54 struct mapping
55 {
56     struct object   obj;             /* object header */
57     mem_size_t      size;            /* mapping size */
58     int             protect;         /* protection flags */
59     struct fd      *fd;              /* fd for mapped file */
60     struct file    *file;            /* file mapped */
61     int             header_size;     /* size of headers (for PE image mapping) */
62     client_ptr_t    base;            /* default base addr (for PE image mapping) */
63     struct ranges  *committed;       /* list of committed ranges in this mapping */
64     struct file    *shared_file;     /* temp file for shared PE mapping */
65     struct list     shared_entry;    /* entry in global shared PE mappings list */
66 };
67
68 static void mapping_dump( struct object *obj, int verbose );
69 static struct object_type *mapping_get_type( struct object *obj );
70 static struct fd *mapping_get_fd( struct object *obj );
71 static unsigned int mapping_map_access( struct object *obj, unsigned int access );
72 static void mapping_destroy( struct object *obj );
73 static enum server_fd_type mapping_get_fd_type( struct fd *fd );
74
75 static const struct object_ops mapping_ops =
76 {
77     sizeof(struct mapping),      /* size */
78     mapping_dump,                /* dump */
79     mapping_get_type,            /* get_type */
80     no_add_queue,                /* add_queue */
81     NULL,                        /* remove_queue */
82     NULL,                        /* signaled */
83     NULL,                        /* satisfied */
84     no_signal,                   /* signal */
85     mapping_get_fd,              /* get_fd */
86     mapping_map_access,          /* map_access */
87     default_get_sd,              /* get_sd */
88     default_set_sd,              /* set_sd */
89     no_lookup_name,              /* lookup_name */
90     no_open_file,                /* open_file */
91     fd_close_handle,             /* close_handle */
92     mapping_destroy              /* destroy */
93 };
94
95 static const struct fd_ops mapping_fd_ops =
96 {
97     default_fd_get_poll_events,   /* get_poll_events */
98     default_poll_event,           /* poll_event */
99     no_flush,                     /* flush */
100     mapping_get_fd_type,          /* get_fd_type */
101     no_fd_ioctl,                  /* ioctl */
102     no_fd_queue_async,            /* queue_async */
103     default_fd_reselect_async,    /* reselect_async */
104     default_fd_cancel_async       /* cancel_async */
105 };
106
107 static struct list shared_list = LIST_INIT(shared_list);
108
109 #ifdef __i386__
110
111 /* These are always the same on an i386, and it will be faster this way */
112 # define page_mask  0xfff
113 # define page_shift 12
114 # define init_page_size() do { /* nothing */ } while(0)
115
116 #else  /* __i386__ */
117
118 static int page_shift, page_mask;
119
120 static void init_page_size(void)
121 {
122     int page_size;
123 # ifdef HAVE_GETPAGESIZE
124     page_size = getpagesize();
125 # else
126 #  ifdef __svr4__
127     page_size = sysconf(_SC_PAGESIZE);
128 #  else
129 #   error Cannot get the page size on this platform
130 #  endif
131 # endif
132     page_mask = page_size - 1;
133     /* Make sure we have a power of 2 */
134     assert( !(page_size & page_mask) );
135     page_shift = 0;
136     while ((1 << page_shift) != page_size) page_shift++;
137 }
138 #endif  /* __i386__ */
139
140 #define ROUND_SIZE(size)  (((size) + page_mask) & ~page_mask)
141
142
143 /* extend a file beyond the current end of file */
144 static int grow_file( int unix_fd, file_pos_t new_size )
145 {
146     static const char zero;
147     off_t size = new_size;
148
149     if (sizeof(new_size) > sizeof(size) && size != new_size)
150     {
151         set_error( STATUS_INVALID_PARAMETER );
152         return 0;
153     }
154     /* extend the file one byte beyond the requested size and then truncate it */
155     /* this should work around ftruncate implementations that can't extend files */
156     if (pwrite( unix_fd, &zero, 1, size ) != -1)
157     {
158         ftruncate( unix_fd, size );
159         return 1;
160     }
161     file_set_error();
162     return 0;
163 }
164
165 /* find the shared PE mapping for a given mapping */
166 static struct file *get_shared_file( struct mapping *mapping )
167 {
168     struct mapping *ptr;
169
170     LIST_FOR_EACH_ENTRY( ptr, &shared_list, struct mapping, shared_entry )
171         if (is_same_file_fd( ptr->fd, mapping->fd ))
172             return (struct file *)grab_object( ptr->shared_file );
173     return NULL;
174 }
175
176 /* return the size of the memory mapping and file range of a given section */
177 static inline void get_section_sizes( const IMAGE_SECTION_HEADER *sec, size_t *map_size,
178                                       off_t *file_start, size_t *file_size )
179 {
180     static const unsigned int sector_align = 0x1ff;
181
182     if (!sec->Misc.VirtualSize) *map_size = ROUND_SIZE( sec->SizeOfRawData );
183     else *map_size = ROUND_SIZE( sec->Misc.VirtualSize );
184
185     *file_start = sec->PointerToRawData & ~sector_align;
186     *file_size = (sec->SizeOfRawData + (sec->PointerToRawData & sector_align) + sector_align) & ~sector_align;
187     if (*file_size > *map_size) *file_size = *map_size;
188 }
189
190 /* add a range to the committed list */
191 static void add_committed_range( struct mapping *mapping, file_pos_t start, file_pos_t end )
192 {
193     unsigned int i, j;
194     struct range *ranges;
195
196     if (!mapping->committed) return;  /* everything committed already */
197
198     for (i = 0, ranges = mapping->committed->ranges; i < mapping->committed->count; i++)
199     {
200         if (ranges[i].start > end) break;
201         if (ranges[i].end < start) continue;
202         if (ranges[i].start > start) ranges[i].start = start;   /* extend downwards */
203         if (ranges[i].end < end)  /* extend upwards and maybe merge with next */
204         {
205             for (j = i + 1; j < mapping->committed->count; j++)
206             {
207                 if (ranges[j].start > end) break;
208                 if (ranges[j].end > end) end = ranges[j].end;
209             }
210             if (j > i + 1)
211             {
212                 memmove( &ranges[i + 1], &ranges[j], (mapping->committed->count - j) * sizeof(*ranges) );
213                 mapping->committed->count -= j - (i + 1);
214             }
215             ranges[i].end = end;
216         }
217         return;
218     }
219
220     /* now add a new range */
221
222     if (mapping->committed->count == mapping->committed->max)
223     {
224         unsigned int new_size = mapping->committed->max * 2;
225         struct ranges *new_ptr = realloc( mapping->committed, offsetof( struct ranges, ranges[new_size] ));
226         if (!new_ptr) return;
227         new_ptr->max = new_size;
228         ranges = new_ptr->ranges;
229         mapping->committed = new_ptr;
230     }
231     memmove( &ranges[i + 1], &ranges[i], (mapping->committed->count - i) * sizeof(*ranges) );
232     ranges[i].start = start;
233     ranges[i].end = end;
234     mapping->committed->count++;
235 }
236
237 /* find the range containing start and return whether it's committed */
238 static int find_committed_range( struct mapping *mapping, file_pos_t start, mem_size_t *size )
239 {
240     unsigned int i;
241     struct range *ranges;
242
243     if (!mapping->committed)  /* everything is committed */
244     {
245         *size = mapping->size - start;
246         return 1;
247     }
248     for (i = 0, ranges = mapping->committed->ranges; i < mapping->committed->count; i++)
249     {
250         if (ranges[i].start > start)
251         {
252             *size = ranges[i].start - start;
253             return 0;
254         }
255         if (ranges[i].end > start)
256         {
257             *size = ranges[i].end - start;
258             return 1;
259         }
260     }
261     *size = mapping->size - start;
262     return 0;
263 }
264
265 /* allocate and fill the temp file for a shared PE image mapping */
266 static int build_shared_mapping( struct mapping *mapping, int fd,
267                                  IMAGE_SECTION_HEADER *sec, unsigned int nb_sec )
268 {
269     unsigned int i;
270     mem_size_t total_size;
271     size_t file_size, map_size, max_size;
272     off_t shared_pos, read_pos, write_pos;
273     char *buffer = NULL;
274     int shared_fd;
275     long toread;
276
277     /* compute the total size of the shared mapping */
278
279     total_size = max_size = 0;
280     for (i = 0; i < nb_sec; i++)
281     {
282         if ((sec[i].Characteristics & IMAGE_SCN_MEM_SHARED) &&
283             (sec[i].Characteristics & IMAGE_SCN_MEM_WRITE))
284         {
285             get_section_sizes( &sec[i], &map_size, &read_pos, &file_size );
286             if (file_size > max_size) max_size = file_size;
287             total_size += map_size;
288         }
289     }
290     if (!total_size) return 1;  /* nothing to do */
291
292     if ((mapping->shared_file = get_shared_file( mapping ))) return 1;
293
294     /* create a temp file for the mapping */
295
296     if (!(mapping->shared_file = create_temp_file( FILE_GENERIC_READ|FILE_GENERIC_WRITE ))) return 0;
297     if ((shared_fd = get_file_unix_fd( mapping->shared_file )) == -1) goto error;
298     if (!grow_file( shared_fd, total_size )) goto error;
299
300     if (!(buffer = malloc( max_size ))) goto error;
301
302     /* copy the shared sections data into the temp file */
303
304     shared_pos = 0;
305     for (i = 0; i < nb_sec; i++)
306     {
307         if (!(sec[i].Characteristics & IMAGE_SCN_MEM_SHARED)) continue;
308         if (!(sec[i].Characteristics & IMAGE_SCN_MEM_WRITE)) continue;
309         get_section_sizes( &sec[i], &map_size, &read_pos, &file_size );
310         write_pos = shared_pos;
311         shared_pos += map_size;
312         if (!sec[i].PointerToRawData || !file_size) continue;
313         toread = file_size;
314         while (toread)
315         {
316             long res = pread( fd, buffer + file_size - toread, toread, read_pos );
317             if (!res && toread < 0x200)  /* partial sector at EOF is not an error */
318             {
319                 file_size -= toread;
320                 break;
321             }
322             if (res <= 0) goto error;
323             toread -= res;
324             read_pos += res;
325         }
326         if (pwrite( shared_fd, buffer, file_size, write_pos ) != file_size) goto error;
327     }
328     free( buffer );
329     return 1;
330
331  error:
332     release_object( mapping->shared_file );
333     mapping->shared_file = NULL;
334     free( buffer );
335     return 0;
336 }
337
338 /* retrieve the mapping parameters for an executable (PE) image */
339 static int get_image_params( struct mapping *mapping, int unix_fd )
340 {
341     IMAGE_DOS_HEADER dos;
342     IMAGE_SECTION_HEADER *sec = NULL;
343     struct
344     {
345         DWORD Signature;
346         IMAGE_FILE_HEADER FileHeader;
347         union
348         {
349             IMAGE_OPTIONAL_HEADER32 hdr32;
350             IMAGE_OPTIONAL_HEADER64 hdr64;
351         } opt;
352     } nt;
353     off_t pos;
354     int size;
355
356     /* load the headers */
357
358     if (pread( unix_fd, &dos, sizeof(dos), 0 ) != sizeof(dos)) goto error;
359     if (dos.e_magic != IMAGE_DOS_SIGNATURE) goto error;
360     pos = dos.e_lfanew;
361
362     size = pread( unix_fd, &nt, sizeof(nt), pos );
363     if (size < sizeof(nt.Signature) + sizeof(nt.FileHeader)) goto error;
364     /* zero out Optional header in the case it's not present or partial */
365     if (size < sizeof(nt)) memset( (char *)&nt + size, 0, sizeof(nt) - size );
366     if (nt.Signature != IMAGE_NT_SIGNATURE) goto error;
367
368     switch (nt.opt.hdr32.Magic)
369     {
370     case IMAGE_NT_OPTIONAL_HDR32_MAGIC:
371         mapping->size        = ROUND_SIZE( nt.opt.hdr32.SizeOfImage );
372         mapping->base        = nt.opt.hdr32.ImageBase;
373         mapping->header_size = nt.opt.hdr32.SizeOfHeaders;
374         break;
375     case IMAGE_NT_OPTIONAL_HDR64_MAGIC:
376         mapping->size        = ROUND_SIZE( nt.opt.hdr64.SizeOfImage );
377         mapping->base        = nt.opt.hdr64.ImageBase;
378         mapping->header_size = nt.opt.hdr64.SizeOfHeaders;
379         break;
380     default:
381         goto error;
382     }
383
384     /* load the section headers */
385
386     pos += sizeof(nt.Signature) + sizeof(nt.FileHeader) + nt.FileHeader.SizeOfOptionalHeader;
387     size = sizeof(*sec) * nt.FileHeader.NumberOfSections;
388     if (pos + size > mapping->size) goto error;
389     if (pos + size > mapping->header_size) mapping->header_size = pos + size;
390     if (!(sec = malloc( size ))) goto error;
391     if (pread( unix_fd, sec, size, pos ) != size) goto error;
392
393     if (!build_shared_mapping( mapping, unix_fd, sec, nt.FileHeader.NumberOfSections )) goto error;
394
395     if (mapping->shared_file) list_add_head( &shared_list, &mapping->shared_entry );
396
397     mapping->protect = VPROT_IMAGE;
398     free( sec );
399     return 1;
400
401  error:
402     free( sec );
403     set_error( STATUS_INVALID_FILE_FOR_SECTION );
404     return 0;
405 }
406
407 static struct object *create_mapping( struct directory *root, const struct unicode_str *name,
408                                       unsigned int attr, mem_size_t size, int protect,
409                                       obj_handle_t handle, const struct security_descriptor *sd )
410 {
411     struct mapping *mapping;
412     struct file *file;
413     struct fd *fd;
414     int access = 0;
415     int unix_fd;
416     struct stat st;
417
418     if (!page_mask) init_page_size();
419
420     if (!(mapping = create_named_object_dir( root, name, attr, &mapping_ops )))
421         return NULL;
422     if (get_error() == STATUS_OBJECT_NAME_EXISTS)
423         return &mapping->obj;  /* Nothing else to do */
424
425     if (sd) default_set_sd( &mapping->obj, sd, OWNER_SECURITY_INFORMATION|
426                                                GROUP_SECURITY_INFORMATION|
427                                                DACL_SECURITY_INFORMATION|
428                                                SACL_SECURITY_INFORMATION );
429     mapping->header_size = 0;
430     mapping->base        = 0;
431     mapping->fd          = NULL;
432     mapping->file        = NULL;
433     mapping->shared_file = NULL;
434     mapping->committed   = NULL;
435
436     if (protect & VPROT_READ) access |= FILE_READ_DATA;
437     if (protect & VPROT_WRITE) access |= FILE_WRITE_DATA;
438
439     if (handle)
440     {
441         if (!(protect & VPROT_COMMITTED))
442         {
443             set_error( STATUS_INVALID_PARAMETER );
444             goto error;
445         }
446         if (!(file = get_file_obj( current->process, handle, access ))) goto error;
447         fd = get_obj_fd( (struct object *)file );
448         mapping->fd = dup_fd_object( fd );
449         release_object( file );
450         release_object( fd );
451         if (!mapping->fd) goto error;
452
453         set_fd_user( mapping->fd, &mapping_fd_ops, &mapping->obj );
454         if ((unix_fd = get_unix_fd( mapping->fd )) == -1) goto error;
455         if (protect & VPROT_IMAGE)
456         {
457             if (!get_image_params( mapping, unix_fd )) goto error;
458             return &mapping->obj;
459         }
460         if (fstat( unix_fd, &st ) == -1)
461         {
462             file_set_error();
463             goto error;
464         }
465         if (!size)
466         {
467             if (!(size = st.st_size))
468             {
469                 set_error( STATUS_MAPPED_FILE_SIZE_ZERO );
470                 goto error;
471             }
472         }
473         else if (st.st_size < size && !grow_file( unix_fd, size )) goto error;
474     }
475     else  /* Anonymous mapping (no associated file) */
476     {
477         if (!size || (protect & VPROT_IMAGE))
478         {
479             set_error( STATUS_INVALID_PARAMETER );
480             goto error;
481         }
482         if (!(protect & VPROT_COMMITTED))
483         {
484             if (!(mapping->committed = mem_alloc( offsetof(struct ranges, ranges[8]) ))) goto error;
485             mapping->committed->count = 0;
486             mapping->committed->max   = 8;
487         }
488         if (!(mapping->file = create_temp_file( access ))) goto error;
489         mapping->fd = get_obj_fd( (struct object *)mapping->file );
490         if ((unix_fd = get_unix_fd( mapping->fd )) == -1) goto error;
491         if (!grow_file( unix_fd, size )) goto error;
492     }
493     mapping->size    = (size + page_mask) & ~((mem_size_t)page_mask);
494     mapping->protect = protect;
495     return &mapping->obj;
496
497  error:
498     release_object( mapping );
499     return NULL;
500 }
501
502 static void mapping_dump( struct object *obj, int verbose )
503 {
504     struct mapping *mapping = (struct mapping *)obj;
505     assert( obj->ops == &mapping_ops );
506     fprintf( stderr, "Mapping size=%08x%08x prot=%08x fd=%p header_size=%08x base=%08lx "
507              "shared_file=%p ",
508              (unsigned int)(mapping->size >> 32), (unsigned int)mapping->size,
509              mapping->protect, mapping->fd, mapping->header_size,
510              (unsigned long)mapping->base, mapping->shared_file );
511     dump_object_name( &mapping->obj );
512     fputc( '\n', stderr );
513 }
514
515 static struct object_type *mapping_get_type( struct object *obj )
516 {
517     static const WCHAR name[] = {'S','e','c','t','i','o','n'};
518     static const struct unicode_str str = { name, sizeof(name) };
519     return get_object_type( &str );
520 }
521
522 static struct fd *mapping_get_fd( struct object *obj )
523 {
524     struct mapping *mapping = (struct mapping *)obj;
525     return (struct fd *)grab_object( mapping->fd );
526 }
527
528 static unsigned int mapping_map_access( struct object *obj, unsigned int access )
529 {
530     if (access & GENERIC_READ)    access |= STANDARD_RIGHTS_READ | SECTION_QUERY | SECTION_MAP_READ;
531     if (access & GENERIC_WRITE)   access |= STANDARD_RIGHTS_WRITE | SECTION_MAP_WRITE;
532     if (access & GENERIC_EXECUTE) access |= STANDARD_RIGHTS_EXECUTE | SECTION_MAP_EXECUTE;
533     if (access & GENERIC_ALL)     access |= SECTION_ALL_ACCESS;
534     return access & ~(GENERIC_READ | GENERIC_WRITE | GENERIC_EXECUTE | GENERIC_ALL);
535 }
536
537 static void mapping_destroy( struct object *obj )
538 {
539     struct mapping *mapping = (struct mapping *)obj;
540     assert( obj->ops == &mapping_ops );
541     if (mapping->file) release_object( mapping->file );
542     if (mapping->fd) release_object( mapping->fd );
543     if (mapping->shared_file)
544     {
545         release_object( mapping->shared_file );
546         list_remove( &mapping->shared_entry );
547     }
548     free( mapping->committed );
549 }
550
551 static enum server_fd_type mapping_get_fd_type( struct fd *fd )
552 {
553     return FD_TYPE_FILE;
554 }
555
556 int get_page_size(void)
557 {
558     if (!page_mask) init_page_size();
559     return page_mask + 1;
560 }
561
562 /* create a file mapping */
563 DECL_HANDLER(create_mapping)
564 {
565     struct object *obj;
566     struct unicode_str name;
567     struct directory *root = NULL;
568     const struct object_attributes *objattr = get_req_data();
569     const struct security_descriptor *sd;
570
571     reply->handle = 0;
572
573     if (!objattr_is_valid( objattr, get_req_data_size() ))
574         return;
575
576     sd = objattr->sd_len ? (const struct security_descriptor *)(objattr + 1) : NULL;
577     objattr_get_name( objattr, &name );
578
579     if (objattr->rootdir && !(root = get_directory_obj( current->process, objattr->rootdir, 0 )))
580         return;
581
582     if ((obj = create_mapping( root, &name, req->attributes, req->size, req->protect, req->file_handle, sd )))
583     {
584         if (get_error() == STATUS_OBJECT_NAME_EXISTS)
585             reply->handle = alloc_handle( current->process, obj, req->access, req->attributes );
586         else
587             reply->handle = alloc_handle_no_access_check( current->process, obj, req->access, req->attributes );
588         release_object( obj );
589     }
590
591     if (root) release_object( root );
592 }
593
594 /* open a handle to a mapping */
595 DECL_HANDLER(open_mapping)
596 {
597     struct unicode_str name;
598     struct directory *root = NULL;
599     struct mapping *mapping;
600
601     get_req_unicode_str( &name );
602     if (req->rootdir && !(root = get_directory_obj( current->process, req->rootdir, 0 )))
603         return;
604
605     if ((mapping = open_object_dir( root, &name, req->attributes, &mapping_ops )))
606     {
607         reply->handle = alloc_handle( current->process, &mapping->obj, req->access, req->attributes );
608         release_object( mapping );
609     }
610
611     if (root) release_object( root );
612 }
613
614 /* get a mapping information */
615 DECL_HANDLER(get_mapping_info)
616 {
617     struct mapping *mapping;
618     struct fd *fd;
619
620     if ((mapping = (struct mapping *)get_handle_obj( current->process, req->handle,
621                                                      req->access, &mapping_ops )))
622     {
623         reply->size        = mapping->size;
624         reply->protect     = mapping->protect;
625         reply->header_size = mapping->header_size;
626         reply->base        = mapping->base;
627         reply->shared_file = 0;
628         if ((fd = get_obj_fd( &mapping->obj )))
629         {
630             if (!is_fd_removable(fd))
631                 reply->mapping = alloc_handle( current->process, mapping, 0, 0 );
632             release_object( fd );
633         }
634         if (mapping->shared_file)
635         {
636             if (!(reply->shared_file = alloc_handle( current->process, mapping->shared_file,
637                                                      GENERIC_READ|GENERIC_WRITE, 0 )))
638             {
639                 if (reply->mapping) close_handle( current->process, reply->mapping );
640             }
641         }
642         release_object( mapping );
643     }
644 }
645
646 /* get a range of committed pages in a file mapping */
647 DECL_HANDLER(get_mapping_committed_range)
648 {
649     struct mapping *mapping;
650
651     if ((mapping = (struct mapping *)get_handle_obj( current->process, req->handle, 0, &mapping_ops )))
652     {
653         if (!(req->offset & page_mask) && req->offset < mapping->size)
654             reply->committed = find_committed_range( mapping, req->offset, &reply->size );
655         else
656             set_error( STATUS_INVALID_PARAMETER );
657
658         release_object( mapping );
659     }
660 }
661
662 /* add a range to the committed pages in a file mapping */
663 DECL_HANDLER(add_mapping_committed_range)
664 {
665     struct mapping *mapping;
666
667     if ((mapping = (struct mapping *)get_handle_obj( current->process, req->handle, 0, &mapping_ops )))
668     {
669         if (!(req->size & page_mask) &&
670             !(req->offset & page_mask) &&
671             req->offset < mapping->size &&
672             req->size > 0 &&
673             req->size <= mapping->size - req->offset)
674             add_committed_range( mapping, req->offset, req->offset + req->size );
675         else
676             set_error( STATUS_INVALID_PARAMETER );
677
678         release_object( mapping );
679     }
680 }