d3d11: Use wined3d_device_context_dispatch_indirect().
[wine/zf.git] / server / mapping.c
blob0dcaa13e91dd1d27aeba73867a7b88a9526c7b6e
1 /*
2 * Server-side file mapping management
4 * Copyright (C) 1999 Alexandre Julliard
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.
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.
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
21 #include "config.h"
22 #include "wine/port.h"
24 #include <assert.h>
25 #include <stdarg.h>
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <sys/stat.h>
29 #ifdef HAVE_SYS_MMAN_H
30 # include <sys/mman.h>
31 #endif
32 #include <unistd.h>
34 #include "ntstatus.h"
35 #define WIN32_NO_STATUS
36 #include "windef.h"
37 #include "winternl.h"
38 #include "ddk/wdm.h"
40 #include "file.h"
41 #include "handle.h"
42 #include "thread.h"
43 #include "process.h"
44 #include "request.h"
45 #include "security.h"
47 /* list of memory ranges, used to store committed info */
48 struct ranges
50 struct object obj; /* object header */
51 unsigned int count; /* number of used ranges */
52 unsigned int max; /* number of allocated ranges */
53 struct range
55 file_pos_t start;
56 file_pos_t end;
57 } *ranges;
60 static void ranges_dump( struct object *obj, int verbose );
61 static void ranges_destroy( struct object *obj );
63 static const struct object_ops ranges_ops =
65 sizeof(struct ranges), /* size */
66 &no_type, /* type */
67 ranges_dump, /* dump */
68 no_add_queue, /* add_queue */
69 NULL, /* remove_queue */
70 NULL, /* signaled */
71 NULL, /* satisfied */
72 no_signal, /* signal */
73 no_get_fd, /* get_fd */
74 default_map_access, /* map_access */
75 default_get_sd, /* get_sd */
76 default_set_sd, /* set_sd */
77 no_get_full_name, /* get_full_name */
78 no_lookup_name, /* lookup_name */
79 no_link_name, /* link_name */
80 NULL, /* unlink_name */
81 no_open_file, /* open_file */
82 no_kernel_obj_list, /* get_kernel_obj_list */
83 no_close_handle, /* close_handle */
84 ranges_destroy /* destroy */
87 /* file backing the shared sections of a PE image mapping */
88 struct shared_map
90 struct object obj; /* object header */
91 struct fd *fd; /* file descriptor of the mapped PE file */
92 struct file *file; /* temp file holding the shared data */
93 struct list entry; /* entry in global shared maps list */
96 static void shared_map_dump( struct object *obj, int verbose );
97 static void shared_map_destroy( struct object *obj );
99 static const struct object_ops shared_map_ops =
101 sizeof(struct shared_map), /* size */
102 &no_type, /* type */
103 shared_map_dump, /* dump */
104 no_add_queue, /* add_queue */
105 NULL, /* remove_queue */
106 NULL, /* signaled */
107 NULL, /* satisfied */
108 no_signal, /* signal */
109 no_get_fd, /* get_fd */
110 default_map_access, /* map_access */
111 default_get_sd, /* get_sd */
112 default_set_sd, /* set_sd */
113 no_get_full_name, /* get_full_name */
114 no_lookup_name, /* lookup_name */
115 no_link_name, /* link_name */
116 NULL, /* unlink_name */
117 no_open_file, /* open_file */
118 no_kernel_obj_list, /* get_kernel_obj_list */
119 no_close_handle, /* close_handle */
120 shared_map_destroy /* destroy */
123 static struct list shared_map_list = LIST_INIT( shared_map_list );
125 /* memory view mapped in client address space */
126 struct memory_view
128 struct list entry; /* entry in per-process view list */
129 struct fd *fd; /* fd for mapped file */
130 struct ranges *committed; /* list of committed ranges in this mapping */
131 struct shared_map *shared; /* temp file for shared PE mapping */
132 pe_image_info_t image; /* image info (for PE image mapping) */
133 unsigned int flags; /* SEC_* flags */
134 client_ptr_t base; /* view base address (in process addr space) */
135 mem_size_t size; /* view size */
136 file_pos_t start; /* start offset in mapping */
137 data_size_t namelen;
138 WCHAR name[1]; /* filename for .so dll image views */
142 static const WCHAR mapping_name[] = {'S','e','c','t','i','o','n'};
144 struct type_descr mapping_type =
146 { mapping_name, sizeof(mapping_name) }, /* name */
147 SECTION_ALL_ACCESS | SYNCHRONIZE, /* valid_access */
148 { /* mapping */
149 STANDARD_RIGHTS_READ | SECTION_QUERY | SECTION_MAP_READ,
150 STANDARD_RIGHTS_WRITE | SECTION_MAP_WRITE,
151 STANDARD_RIGHTS_EXECUTE | SECTION_MAP_EXECUTE,
152 SECTION_ALL_ACCESS
156 struct mapping
158 struct object obj; /* object header */
159 mem_size_t size; /* mapping size */
160 unsigned int flags; /* SEC_* flags */
161 struct fd *fd; /* fd for mapped file */
162 pe_image_info_t image; /* image info (for PE image mapping) */
163 struct ranges *committed; /* list of committed ranges in this mapping */
164 struct shared_map *shared; /* temp file for shared PE mapping */
167 static void mapping_dump( struct object *obj, int verbose );
168 static struct fd *mapping_get_fd( struct object *obj );
169 static void mapping_destroy( struct object *obj );
170 static enum server_fd_type mapping_get_fd_type( struct fd *fd );
172 static const struct object_ops mapping_ops =
174 sizeof(struct mapping), /* size */
175 &mapping_type, /* type */
176 mapping_dump, /* dump */
177 no_add_queue, /* add_queue */
178 NULL, /* remove_queue */
179 NULL, /* signaled */
180 NULL, /* satisfied */
181 no_signal, /* signal */
182 mapping_get_fd, /* get_fd */
183 default_map_access, /* map_access */
184 default_get_sd, /* get_sd */
185 default_set_sd, /* set_sd */
186 default_get_full_name, /* get_full_name */
187 no_lookup_name, /* lookup_name */
188 directory_link_name, /* link_name */
189 default_unlink_name, /* unlink_name */
190 no_open_file, /* open_file */
191 no_kernel_obj_list, /* get_kernel_obj_list */
192 no_close_handle, /* close_handle */
193 mapping_destroy /* destroy */
196 static const struct fd_ops mapping_fd_ops =
198 default_fd_get_poll_events, /* get_poll_events */
199 default_poll_event, /* poll_event */
200 mapping_get_fd_type, /* get_fd_type */
201 no_fd_read, /* read */
202 no_fd_write, /* write */
203 no_fd_flush, /* flush */
204 no_fd_get_file_info, /* get_file_info */
205 no_fd_get_volume_info, /* get_volume_info */
206 no_fd_ioctl, /* ioctl */
207 no_fd_queue_async, /* queue_async */
208 default_fd_reselect_async /* reselect_async */
211 static size_t page_mask;
213 #define ROUND_SIZE(size) (((size) + page_mask) & ~page_mask)
216 static void ranges_dump( struct object *obj, int verbose )
218 struct ranges *ranges = (struct ranges *)obj;
219 fprintf( stderr, "Memory ranges count=%u\n", ranges->count );
222 static void ranges_destroy( struct object *obj )
224 struct ranges *ranges = (struct ranges *)obj;
225 free( ranges->ranges );
228 static void shared_map_dump( struct object *obj, int verbose )
230 struct shared_map *shared = (struct shared_map *)obj;
231 fprintf( stderr, "Shared mapping fd=%p file=%p\n", shared->fd, shared->file );
234 static void shared_map_destroy( struct object *obj )
236 struct shared_map *shared = (struct shared_map *)obj;
238 release_object( shared->fd );
239 release_object( shared->file );
240 list_remove( &shared->entry );
243 /* extend a file beyond the current end of file */
244 static int grow_file( int unix_fd, file_pos_t new_size )
246 static const char zero;
247 off_t size = new_size;
249 if (sizeof(new_size) > sizeof(size) && size != new_size)
251 set_error( STATUS_INVALID_PARAMETER );
252 return 0;
254 /* extend the file one byte beyond the requested size and then truncate it */
255 /* this should work around ftruncate implementations that can't extend files */
256 if (pwrite( unix_fd, &zero, 1, size ) != -1)
258 ftruncate( unix_fd, size );
259 return 1;
261 file_set_error();
262 return 0;
265 /* check if the current directory allows exec mappings */
266 static int check_current_dir_for_exec(void)
268 int fd;
269 char tmpfn[] = "anonmap.XXXXXX";
270 void *ret = MAP_FAILED;
272 fd = mkstemps( tmpfn, 0 );
273 if (fd == -1) return 0;
274 if (grow_file( fd, 1 ))
276 ret = mmap( NULL, get_page_size(), PROT_READ | PROT_EXEC, MAP_PRIVATE, fd, 0 );
277 if (ret != MAP_FAILED) munmap( ret, get_page_size() );
279 close( fd );
280 unlink( tmpfn );
281 return (ret != MAP_FAILED);
284 /* create a temp file for anonymous mappings */
285 static int create_temp_file( file_pos_t size )
287 static int temp_dir_fd = -1;
288 char tmpfn[] = "anonmap.XXXXXX";
289 int fd;
291 if (temp_dir_fd == -1)
293 temp_dir_fd = server_dir_fd;
294 if (!check_current_dir_for_exec())
296 /* the server dir is noexec, try the config dir instead */
297 fchdir( config_dir_fd );
298 if (check_current_dir_for_exec())
299 temp_dir_fd = config_dir_fd;
300 else /* neither works, fall back to server dir */
301 fchdir( server_dir_fd );
304 else if (temp_dir_fd != server_dir_fd) fchdir( temp_dir_fd );
306 fd = mkstemps( tmpfn, 0 );
307 if (fd != -1)
309 if (!grow_file( fd, size ))
311 close( fd );
312 fd = -1;
314 unlink( tmpfn );
316 else file_set_error();
318 if (temp_dir_fd != server_dir_fd) fchdir( server_dir_fd );
319 return fd;
322 /* find a memory view from its base address */
323 struct memory_view *find_mapped_view( struct process *process, client_ptr_t base )
325 struct memory_view *view;
327 LIST_FOR_EACH_ENTRY( view, &process->views, struct memory_view, entry )
328 if (view->base == base) return view;
330 set_error( STATUS_NOT_MAPPED_VIEW );
331 return NULL;
334 /* find a memory view from any address inside it */
335 static struct memory_view *find_mapped_addr( struct process *process, client_ptr_t addr )
337 struct memory_view *view;
339 LIST_FOR_EACH_ENTRY( view, &process->views, struct memory_view, entry )
340 if (addr >= view->base && addr < view->base + view->size) return view;
342 set_error( STATUS_NOT_MAPPED_VIEW );
343 return NULL;
346 /* get the main exe memory view */
347 struct memory_view *get_exe_view( struct process *process )
349 return LIST_ENTRY( list_head( &process->views ), struct memory_view, entry );
352 /* add a view to the process list */
353 static void add_process_view( struct thread *thread, struct memory_view *view )
355 struct process *process = thread->process;
356 struct unicode_str name;
358 if (view->flags & SEC_IMAGE)
360 if (is_process_init_done( process ))
361 generate_debug_event( thread, DbgLoadDllStateChange, view );
362 else if (!(view->image.image_charact & IMAGE_FILE_DLL))
364 /* main exe */
365 list_add_head( &process->views, &view->entry );
366 if (get_view_nt_name( view, &name ) && (process->image = memdup( name.str, name.len )))
367 process->imagelen = name.len;
368 return;
371 list_add_tail( &process->views, &view->entry );
374 static void free_memory_view( struct memory_view *view )
376 if (view->fd) release_object( view->fd );
377 if (view->committed) release_object( view->committed );
378 if (view->shared) release_object( view->shared );
379 list_remove( &view->entry );
380 free( view );
383 /* free all mapped views at process exit */
384 void free_mapped_views( struct process *process )
386 struct list *ptr;
388 while ((ptr = list_head( &process->views )))
389 free_memory_view( LIST_ENTRY( ptr, struct memory_view, entry ));
392 /* find the shared PE mapping for a given mapping */
393 static struct shared_map *get_shared_file( struct fd *fd )
395 struct shared_map *ptr;
397 LIST_FOR_EACH_ENTRY( ptr, &shared_map_list, struct shared_map, entry )
398 if (is_same_file_fd( ptr->fd, fd ))
399 return (struct shared_map *)grab_object( ptr );
400 return NULL;
403 /* return the size of the memory mapping and file range of a given section */
404 static inline void get_section_sizes( const IMAGE_SECTION_HEADER *sec, size_t *map_size,
405 off_t *file_start, size_t *file_size )
407 static const unsigned int sector_align = 0x1ff;
409 if (!sec->Misc.VirtualSize) *map_size = ROUND_SIZE( sec->SizeOfRawData );
410 else *map_size = ROUND_SIZE( sec->Misc.VirtualSize );
412 *file_start = sec->PointerToRawData & ~sector_align;
413 *file_size = (sec->SizeOfRawData + (sec->PointerToRawData & sector_align) + sector_align) & ~sector_align;
414 if (*file_size > *map_size) *file_size = *map_size;
417 /* add a range to the committed list */
418 static void add_committed_range( struct memory_view *view, file_pos_t start, file_pos_t end )
420 unsigned int i, j;
421 struct ranges *committed = view->committed;
422 struct range *ranges;
424 if ((start & page_mask) || (end & page_mask) ||
425 start >= view->size || end >= view->size ||
426 start >= end)
428 set_error( STATUS_INVALID_PARAMETER );
429 return;
432 if (!committed) return; /* everything committed already */
434 start += view->start;
435 end += view->start;
437 for (i = 0, ranges = committed->ranges; i < committed->count; i++)
439 if (ranges[i].start > end) break;
440 if (ranges[i].end < start) continue;
441 if (ranges[i].start > start) ranges[i].start = start; /* extend downwards */
442 if (ranges[i].end < end) /* extend upwards and maybe merge with next */
444 for (j = i + 1; j < committed->count; j++)
446 if (ranges[j].start > end) break;
447 if (ranges[j].end > end) end = ranges[j].end;
449 if (j > i + 1)
451 memmove( &ranges[i + 1], &ranges[j], (committed->count - j) * sizeof(*ranges) );
452 committed->count -= j - (i + 1);
454 ranges[i].end = end;
456 return;
459 /* now add a new range */
461 if (committed->count == committed->max)
463 unsigned int new_size = committed->max * 2;
464 struct range *new_ptr = realloc( committed->ranges, new_size * sizeof(*new_ptr) );
465 if (!new_ptr) return;
466 committed->max = new_size;
467 ranges = committed->ranges = new_ptr;
469 memmove( &ranges[i + 1], &ranges[i], (committed->count - i) * sizeof(*ranges) );
470 ranges[i].start = start;
471 ranges[i].end = end;
472 committed->count++;
475 /* find the range containing start and return whether it's committed */
476 static int find_committed_range( struct memory_view *view, file_pos_t start, mem_size_t *size )
478 unsigned int i;
479 struct ranges *committed = view->committed;
480 struct range *ranges;
482 if ((start & page_mask) || start >= view->size)
484 set_error( STATUS_INVALID_PARAMETER );
485 return 0;
487 if (!committed) /* everything is committed */
489 *size = view->size - start;
490 return 1;
492 for (i = 0, ranges = committed->ranges; i < committed->count; i++)
494 if (ranges[i].start > view->start + start)
496 *size = min( ranges[i].start, view->start + view->size ) - (view->start + start);
497 return 0;
499 if (ranges[i].end > view->start + start)
501 *size = min( ranges[i].end, view->start + view->size ) - (view->start + start);
502 return 1;
505 *size = view->size - start;
506 return 0;
509 /* allocate and fill the temp file for a shared PE image mapping */
510 static int build_shared_mapping( struct mapping *mapping, int fd,
511 IMAGE_SECTION_HEADER *sec, unsigned int nb_sec )
513 struct shared_map *shared;
514 struct file *file;
515 unsigned int i;
516 mem_size_t total_size;
517 size_t file_size, map_size, max_size;
518 off_t shared_pos, read_pos, write_pos;
519 char *buffer = NULL;
520 int shared_fd;
521 long toread;
523 /* compute the total size of the shared mapping */
525 total_size = max_size = 0;
526 for (i = 0; i < nb_sec; i++)
528 if ((sec[i].Characteristics & IMAGE_SCN_MEM_SHARED) &&
529 (sec[i].Characteristics & IMAGE_SCN_MEM_WRITE))
531 get_section_sizes( &sec[i], &map_size, &read_pos, &file_size );
532 if (file_size > max_size) max_size = file_size;
533 total_size += map_size;
536 if (!total_size) return 1; /* nothing to do */
538 if ((mapping->shared = get_shared_file( mapping->fd ))) return 1;
540 /* create a temp file for the mapping */
542 if ((shared_fd = create_temp_file( total_size )) == -1) return 0;
543 if (!(file = create_file_for_fd( shared_fd, FILE_GENERIC_READ|FILE_GENERIC_WRITE, 0 ))) return 0;
545 if (!(buffer = malloc( max_size ))) goto error;
547 /* copy the shared sections data into the temp file */
549 shared_pos = 0;
550 for (i = 0; i < nb_sec; i++)
552 if (!(sec[i].Characteristics & IMAGE_SCN_MEM_SHARED)) continue;
553 if (!(sec[i].Characteristics & IMAGE_SCN_MEM_WRITE)) continue;
554 get_section_sizes( &sec[i], &map_size, &read_pos, &file_size );
555 write_pos = shared_pos;
556 shared_pos += map_size;
557 if (!sec[i].PointerToRawData || !file_size) continue;
558 toread = file_size;
559 while (toread)
561 long res = pread( fd, buffer + file_size - toread, toread, read_pos );
562 if (!res && toread < 0x200) /* partial sector at EOF is not an error */
564 file_size -= toread;
565 break;
567 if (res <= 0) goto error;
568 toread -= res;
569 read_pos += res;
571 if (pwrite( shared_fd, buffer, file_size, write_pos ) != file_size) goto error;
574 if (!(shared = alloc_object( &shared_map_ops ))) goto error;
575 shared->fd = (struct fd *)grab_object( mapping->fd );
576 shared->file = file;
577 list_add_head( &shared_map_list, &shared->entry );
578 mapping->shared = shared;
579 free( buffer );
580 return 1;
582 error:
583 release_object( file );
584 free( buffer );
585 return 0;
588 /* load the CLR header from its section */
589 static int load_clr_header( IMAGE_COR20_HEADER *hdr, size_t va, size_t size, int unix_fd,
590 IMAGE_SECTION_HEADER *sec, unsigned int nb_sec )
592 ssize_t ret;
593 size_t map_size, file_size;
594 off_t file_start;
595 unsigned int i;
597 if (!va || !size) return 0;
599 for (i = 0; i < nb_sec; i++)
601 if (va < sec[i].VirtualAddress) continue;
602 if (sec[i].Misc.VirtualSize && va - sec[i].VirtualAddress >= sec[i].Misc.VirtualSize) continue;
603 get_section_sizes( &sec[i], &map_size, &file_start, &file_size );
604 if (size >= map_size) continue;
605 if (va - sec[i].VirtualAddress >= map_size - size) continue;
606 file_size = min( file_size, map_size );
607 size = min( size, sizeof(*hdr) );
608 ret = pread( unix_fd, hdr, min( size, file_size ), file_start + va - sec[i].VirtualAddress );
609 if (ret <= 0) break;
610 if (ret < sizeof(*hdr)) memset( (char *)hdr + ret, 0, sizeof(*hdr) - ret );
611 return (hdr->MajorRuntimeVersion > COR_VERSION_MAJOR_V2 ||
612 (hdr->MajorRuntimeVersion == COR_VERSION_MAJOR_V2 &&
613 hdr->MinorRuntimeVersion >= COR_VERSION_MINOR));
615 return 0;
618 /* retrieve the mapping parameters for an executable (PE) image */
619 static unsigned int get_image_params( struct mapping *mapping, file_pos_t file_size, int unix_fd )
621 static const char builtin_signature[] = "Wine builtin DLL";
622 static const char fakedll_signature[] = "Wine placeholder DLL";
624 IMAGE_COR20_HEADER clr;
625 IMAGE_SECTION_HEADER sec[96];
626 struct
628 IMAGE_DOS_HEADER dos;
629 char buffer[32];
630 } mz;
631 struct
633 DWORD Signature;
634 IMAGE_FILE_HEADER FileHeader;
635 union
637 IMAGE_OPTIONAL_HEADER32 hdr32;
638 IMAGE_OPTIONAL_HEADER64 hdr64;
639 } opt;
640 } nt;
641 off_t pos;
642 int size, opt_size;
643 size_t mz_size, clr_va, clr_size;
644 unsigned int i, cpu_mask = get_supported_cpu_mask();
646 /* load the headers */
648 if (!file_size) return STATUS_INVALID_FILE_FOR_SECTION;
649 size = pread( unix_fd, &mz, sizeof(mz), 0 );
650 if (size < sizeof(mz.dos)) return STATUS_INVALID_IMAGE_NOT_MZ;
651 if (mz.dos.e_magic != IMAGE_DOS_SIGNATURE) return STATUS_INVALID_IMAGE_NOT_MZ;
652 mz_size = size;
653 pos = mz.dos.e_lfanew;
655 size = pread( unix_fd, &nt, sizeof(nt), pos );
656 if (size < sizeof(nt.Signature) + sizeof(nt.FileHeader)) return STATUS_INVALID_IMAGE_PROTECT;
657 /* zero out Optional header in the case it's not present or partial */
658 opt_size = max( nt.FileHeader.SizeOfOptionalHeader, offsetof( IMAGE_OPTIONAL_HEADER32, CheckSum ));
659 size = min( size, sizeof(nt.Signature) + sizeof(nt.FileHeader) + opt_size );
660 if (size < sizeof(nt)) memset( (char *)&nt + size, 0, sizeof(nt) - size );
661 if (nt.Signature != IMAGE_NT_SIGNATURE)
663 IMAGE_OS2_HEADER *os2 = (IMAGE_OS2_HEADER *)&nt;
664 if (os2->ne_magic != IMAGE_OS2_SIGNATURE) return STATUS_INVALID_IMAGE_PROTECT;
665 if (os2->ne_exetyp == 2) return STATUS_INVALID_IMAGE_WIN_16;
666 if (os2->ne_exetyp == 5) return STATUS_INVALID_IMAGE_PROTECT;
667 return STATUS_INVALID_IMAGE_NE_FORMAT;
670 switch (nt.opt.hdr32.Magic)
672 case IMAGE_NT_OPTIONAL_HDR32_MAGIC:
673 switch (nt.FileHeader.Machine)
675 case IMAGE_FILE_MACHINE_I386:
676 if (cpu_mask & (CPU_FLAG(CPU_x86) | CPU_FLAG(CPU_x86_64))) break;
677 return STATUS_INVALID_IMAGE_FORMAT;
678 case IMAGE_FILE_MACHINE_ARMNT:
679 if (cpu_mask & (CPU_FLAG(CPU_ARM) | CPU_FLAG(CPU_ARM64))) break;
680 return STATUS_INVALID_IMAGE_FORMAT;
681 case IMAGE_FILE_MACHINE_POWERPC:
682 if (cpu_mask & CPU_FLAG(CPU_POWERPC)) break;
683 return STATUS_INVALID_IMAGE_FORMAT;
684 default:
685 return STATUS_INVALID_IMAGE_FORMAT;
687 clr_va = nt.opt.hdr32.DataDirectory[IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR].VirtualAddress;
688 clr_size = nt.opt.hdr32.DataDirectory[IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR].Size;
690 mapping->image.base = nt.opt.hdr32.ImageBase;
691 mapping->image.entry_point = nt.opt.hdr32.ImageBase + nt.opt.hdr32.AddressOfEntryPoint;
692 mapping->image.map_size = ROUND_SIZE( nt.opt.hdr32.SizeOfImage );
693 mapping->image.stack_size = nt.opt.hdr32.SizeOfStackReserve;
694 mapping->image.stack_commit = nt.opt.hdr32.SizeOfStackCommit;
695 mapping->image.subsystem = nt.opt.hdr32.Subsystem;
696 mapping->image.subsystem_minor = nt.opt.hdr32.MinorSubsystemVersion;
697 mapping->image.subsystem_major = nt.opt.hdr32.MajorSubsystemVersion;
698 mapping->image.osversion_minor = nt.opt.hdr32.MinorOperatingSystemVersion;
699 mapping->image.osversion_major = nt.opt.hdr32.MajorOperatingSystemVersion;
700 mapping->image.dll_charact = nt.opt.hdr32.DllCharacteristics;
701 mapping->image.contains_code = (nt.opt.hdr32.SizeOfCode ||
702 nt.opt.hdr32.AddressOfEntryPoint ||
703 nt.opt.hdr32.SectionAlignment & page_mask);
704 mapping->image.header_size = nt.opt.hdr32.SizeOfHeaders;
705 mapping->image.checksum = nt.opt.hdr32.CheckSum;
706 mapping->image.image_flags = 0;
707 if (nt.opt.hdr32.SectionAlignment & page_mask)
708 mapping->image.image_flags |= IMAGE_FLAGS_ImageMappedFlat;
709 if ((nt.opt.hdr32.DllCharacteristics & IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE) &&
710 mapping->image.contains_code && !(clr_va && clr_size))
711 mapping->image.image_flags |= IMAGE_FLAGS_ImageDynamicallyRelocated;
712 break;
714 case IMAGE_NT_OPTIONAL_HDR64_MAGIC:
715 if (!(cpu_mask & CPU_64BIT_MASK)) return STATUS_INVALID_IMAGE_WIN_64;
716 switch (nt.FileHeader.Machine)
718 case IMAGE_FILE_MACHINE_AMD64:
719 if (cpu_mask & (CPU_FLAG(CPU_x86) | CPU_FLAG(CPU_x86_64))) break;
720 return STATUS_INVALID_IMAGE_FORMAT;
721 case IMAGE_FILE_MACHINE_ARM64:
722 if (cpu_mask & (CPU_FLAG(CPU_ARM) | CPU_FLAG(CPU_ARM64))) break;
723 return STATUS_INVALID_IMAGE_FORMAT;
724 default:
725 return STATUS_INVALID_IMAGE_FORMAT;
727 clr_va = nt.opt.hdr64.DataDirectory[IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR].VirtualAddress;
728 clr_size = nt.opt.hdr64.DataDirectory[IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR].Size;
730 mapping->image.base = nt.opt.hdr64.ImageBase;
731 mapping->image.entry_point = nt.opt.hdr64.ImageBase + nt.opt.hdr64.AddressOfEntryPoint;
732 mapping->image.map_size = ROUND_SIZE( nt.opt.hdr64.SizeOfImage );
733 mapping->image.stack_size = nt.opt.hdr64.SizeOfStackReserve;
734 mapping->image.stack_commit = nt.opt.hdr64.SizeOfStackCommit;
735 mapping->image.subsystem = nt.opt.hdr64.Subsystem;
736 mapping->image.subsystem_minor = nt.opt.hdr64.MinorSubsystemVersion;
737 mapping->image.subsystem_major = nt.opt.hdr64.MajorSubsystemVersion;
738 mapping->image.osversion_minor = nt.opt.hdr64.MinorOperatingSystemVersion;
739 mapping->image.osversion_major = nt.opt.hdr64.MajorOperatingSystemVersion;
740 mapping->image.dll_charact = nt.opt.hdr64.DllCharacteristics;
741 mapping->image.contains_code = (nt.opt.hdr64.SizeOfCode ||
742 nt.opt.hdr64.AddressOfEntryPoint ||
743 nt.opt.hdr64.SectionAlignment & page_mask);
744 mapping->image.header_size = nt.opt.hdr64.SizeOfHeaders;
745 mapping->image.checksum = nt.opt.hdr64.CheckSum;
746 mapping->image.image_flags = 0;
747 if (nt.opt.hdr64.SectionAlignment & page_mask)
748 mapping->image.image_flags |= IMAGE_FLAGS_ImageMappedFlat;
749 if ((nt.opt.hdr64.DllCharacteristics & IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE) &&
750 mapping->image.contains_code && !(clr_va && clr_size))
751 mapping->image.image_flags |= IMAGE_FLAGS_ImageDynamicallyRelocated;
752 break;
754 default:
755 return STATUS_INVALID_IMAGE_FORMAT;
758 mapping->image.image_charact = nt.FileHeader.Characteristics;
759 mapping->image.machine = nt.FileHeader.Machine;
760 mapping->image.dbg_offset = nt.FileHeader.PointerToSymbolTable;
761 mapping->image.dbg_size = nt.FileHeader.NumberOfSymbols;
762 mapping->image.zerobits = 0; /* FIXME */
763 mapping->image.file_size = file_size;
764 mapping->image.loader_flags = clr_va && clr_size;
765 if (mz_size == sizeof(mz) && !memcmp( mz.buffer, builtin_signature, sizeof(builtin_signature) ))
766 mapping->image.image_flags |= IMAGE_FLAGS_WineBuiltin;
767 else if (mz_size == sizeof(mz) && !memcmp( mz.buffer, fakedll_signature, sizeof(fakedll_signature) ))
768 mapping->image.image_flags |= IMAGE_FLAGS_WineFakeDll;
770 /* load the section headers */
772 pos += sizeof(nt.Signature) + sizeof(nt.FileHeader) + nt.FileHeader.SizeOfOptionalHeader;
773 if (nt.FileHeader.NumberOfSections > ARRAY_SIZE( sec )) return STATUS_INVALID_IMAGE_FORMAT;
774 size = sizeof(*sec) * nt.FileHeader.NumberOfSections;
775 if (!mapping->size) mapping->size = mapping->image.map_size;
776 else if (mapping->size > mapping->image.map_size) return STATUS_SECTION_TOO_BIG;
777 if (pos + size > mapping->image.map_size) return STATUS_INVALID_FILE_FOR_SECTION;
778 if (pos + size > mapping->image.header_size) mapping->image.header_size = pos + size;
779 if (pread( unix_fd, sec, size, pos ) != size) return STATUS_INVALID_FILE_FOR_SECTION;
781 for (i = 0; i < nt.FileHeader.NumberOfSections && !mapping->image.contains_code; i++)
782 if (sec[i].Characteristics & IMAGE_SCN_MEM_EXECUTE) mapping->image.contains_code = 1;
784 if (load_clr_header( &clr, clr_va, clr_size, unix_fd, sec, nt.FileHeader.NumberOfSections ) &&
785 (clr.Flags & COMIMAGE_FLAGS_ILONLY))
787 mapping->image.image_flags |= IMAGE_FLAGS_ComPlusILOnly;
788 if (nt.opt.hdr32.Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC)
790 if (!(clr.Flags & COMIMAGE_FLAGS_32BITREQUIRED))
791 mapping->image.image_flags |= IMAGE_FLAGS_ComPlusNativeReady;
792 if (clr.Flags & COMIMAGE_FLAGS_32BITPREFERRED)
793 mapping->image.image_flags |= IMAGE_FLAGS_ComPlusPrefer32bit;
797 if (!build_shared_mapping( mapping, unix_fd, sec, nt.FileHeader.NumberOfSections ))
798 return STATUS_INVALID_FILE_FOR_SECTION;
800 return STATUS_SUCCESS;
803 static struct ranges *create_ranges(void)
805 struct ranges *ranges = alloc_object( &ranges_ops );
807 if (!ranges) return NULL;
808 ranges->count = 0;
809 ranges->max = 8;
810 if (!(ranges->ranges = mem_alloc( ranges->max * sizeof(*ranges->ranges) )))
812 release_object( ranges );
813 return NULL;
815 return ranges;
818 static unsigned int get_mapping_flags( obj_handle_t handle, unsigned int flags )
820 switch (flags & (SEC_IMAGE | SEC_RESERVE | SEC_COMMIT | SEC_FILE))
822 case SEC_IMAGE:
823 if (flags & (SEC_WRITECOMBINE | SEC_LARGE_PAGES)) break;
824 if (handle) return SEC_FILE | SEC_IMAGE;
825 set_error( STATUS_INVALID_FILE_FOR_SECTION );
826 return 0;
827 case SEC_COMMIT:
828 if (!handle) return flags;
829 /* fall through */
830 case SEC_RESERVE:
831 if (flags & SEC_LARGE_PAGES) break;
832 if (handle) return SEC_FILE | (flags & (SEC_NOCACHE | SEC_WRITECOMBINE));
833 return flags;
835 set_error( STATUS_INVALID_PARAMETER );
836 return 0;
840 static struct mapping *create_mapping( struct object *root, const struct unicode_str *name,
841 unsigned int attr, mem_size_t size, unsigned int flags,
842 obj_handle_t handle, unsigned int file_access,
843 const struct security_descriptor *sd )
845 struct mapping *mapping;
846 struct file *file;
847 struct fd *fd;
848 int unix_fd;
849 struct stat st;
851 if (!page_mask) page_mask = sysconf( _SC_PAGESIZE ) - 1;
853 if (!(mapping = create_named_object( root, &mapping_ops, name, attr, sd )))
854 return NULL;
855 if (get_error() == STATUS_OBJECT_NAME_EXISTS)
856 return mapping; /* Nothing else to do */
858 mapping->size = size;
859 mapping->fd = NULL;
860 mapping->shared = NULL;
861 mapping->committed = NULL;
863 if (!(mapping->flags = get_mapping_flags( handle, flags ))) goto error;
865 if (handle)
867 const unsigned int sharing = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
868 unsigned int mapping_access = FILE_MAPPING_ACCESS;
870 if (!(file = get_file_obj( current->process, handle, file_access ))) goto error;
871 fd = get_obj_fd( (struct object *)file );
873 /* file sharing rules for mappings are different so we use magic the access rights */
874 if (flags & SEC_IMAGE) mapping_access |= FILE_MAPPING_IMAGE;
875 else if (file_access & FILE_WRITE_DATA) mapping_access |= FILE_MAPPING_WRITE;
877 if (!(mapping->fd = get_fd_object_for_mapping( fd, mapping_access, sharing )))
879 mapping->fd = dup_fd_object( fd, mapping_access, sharing, FILE_SYNCHRONOUS_IO_NONALERT );
880 if (mapping->fd) set_fd_user( mapping->fd, &mapping_fd_ops, NULL );
882 release_object( file );
883 release_object( fd );
884 if (!mapping->fd) goto error;
886 if ((unix_fd = get_unix_fd( mapping->fd )) == -1) goto error;
887 if (fstat( unix_fd, &st ) == -1)
889 file_set_error();
890 goto error;
892 if (flags & SEC_IMAGE)
894 unsigned int err = get_image_params( mapping, st.st_size, unix_fd );
895 if (!err) return mapping;
896 set_error( err );
897 goto error;
899 if (!mapping->size)
901 if (!(mapping->size = st.st_size))
903 set_error( STATUS_MAPPED_FILE_SIZE_ZERO );
904 goto error;
907 else if (st.st_size < mapping->size)
909 if (!(file_access & FILE_WRITE_DATA))
911 set_error( STATUS_SECTION_TOO_BIG );
912 goto error;
914 if (!grow_file( unix_fd, mapping->size )) goto error;
917 else /* Anonymous mapping (no associated file) */
919 if (!mapping->size)
921 set_error( STATUS_INVALID_PARAMETER );
922 goto error;
924 if ((flags & SEC_RESERVE) && !(mapping->committed = create_ranges())) goto error;
925 mapping->size = (mapping->size + page_mask) & ~((mem_size_t)page_mask);
926 if ((unix_fd = create_temp_file( mapping->size )) == -1) goto error;
927 if (!(mapping->fd = create_anonymous_fd( &mapping_fd_ops, unix_fd, &mapping->obj,
928 FILE_SYNCHRONOUS_IO_NONALERT ))) goto error;
929 allow_fd_caching( mapping->fd );
931 return mapping;
933 error:
934 release_object( mapping );
935 return NULL;
938 /* create a read-only file mapping for the specified fd */
939 struct mapping *create_fd_mapping( struct object *root, const struct unicode_str *name,
940 struct fd *fd, unsigned int attr, const struct security_descriptor *sd )
942 struct mapping *mapping;
943 int unix_fd;
944 struct stat st;
946 if (!(mapping = create_named_object( root, &mapping_ops, name, attr, sd ))) return NULL;
947 if (get_error() == STATUS_OBJECT_NAME_EXISTS) return mapping; /* Nothing else to do */
949 mapping->shared = NULL;
950 mapping->committed = NULL;
951 mapping->flags = SEC_FILE;
952 mapping->fd = (struct fd *)grab_object( fd );
953 set_fd_user( mapping->fd, &mapping_fd_ops, NULL );
955 if ((unix_fd = get_unix_fd( mapping->fd )) == -1) goto error;
956 if (fstat( unix_fd, &st ) == -1)
958 file_set_error();
959 goto error;
961 if (!(mapping->size = st.st_size))
963 set_error( STATUS_MAPPED_FILE_SIZE_ZERO );
964 goto error;
966 return mapping;
968 error:
969 release_object( mapping );
970 return NULL;
973 static struct mapping *get_mapping_obj( struct process *process, obj_handle_t handle, unsigned int access )
975 return (struct mapping *)get_handle_obj( process, handle, access, &mapping_ops );
978 /* open a new file for the file descriptor backing the view */
979 struct file *get_view_file( const struct memory_view *view, unsigned int access, unsigned int sharing )
981 if (!view->fd) return NULL;
982 return create_file_for_fd_obj( view->fd, access, sharing );
985 /* get the image info for a SEC_IMAGE mapped view */
986 const pe_image_info_t *get_view_image_info( const struct memory_view *view, client_ptr_t *base )
988 if (!(view->flags & SEC_IMAGE)) return NULL;
989 *base = view->base;
990 return &view->image;
993 /* get the file name for a mapped view */
994 int get_view_nt_name( const struct memory_view *view, struct unicode_str *name )
996 if (view->namelen) /* .so builtin */
998 name->str = view->name;
999 name->len = view->namelen;
1000 return 1;
1002 if (!view->fd) return 0;
1003 get_nt_name( view->fd, name );
1004 return 1;
1007 /* generate all startup events of a given process */
1008 void generate_startup_debug_events( struct process *process )
1010 struct memory_view *view;
1011 struct list *ptr = list_head( &process->views );
1012 struct thread *thread, *first_thread = get_process_first_thread( process );
1014 if (!ptr) return;
1015 view = LIST_ENTRY( ptr, struct memory_view, entry );
1016 generate_debug_event( first_thread, DbgCreateProcessStateChange, view );
1018 /* generate ntdll.dll load event */
1019 while (ptr && (ptr = list_next( &process->views, ptr )))
1021 view = LIST_ENTRY( ptr, struct memory_view, entry );
1022 if (!(view->flags & SEC_IMAGE)) continue;
1023 generate_debug_event( first_thread, DbgLoadDllStateChange, view );
1024 break;
1027 /* generate creation events */
1028 LIST_FOR_EACH_ENTRY( thread, &process->thread_list, struct thread, proc_entry )
1030 if (thread != first_thread)
1031 generate_debug_event( thread, DbgCreateThreadStateChange, NULL );
1034 /* generate dll events (in loading order) */
1035 while (ptr && (ptr = list_next( &process->views, ptr )))
1037 view = LIST_ENTRY( ptr, struct memory_view, entry );
1038 if (!(view->flags & SEC_IMAGE)) continue;
1039 generate_debug_event( first_thread, DbgLoadDllStateChange, view );
1043 static void mapping_dump( struct object *obj, int verbose )
1045 struct mapping *mapping = (struct mapping *)obj;
1046 assert( obj->ops == &mapping_ops );
1047 fprintf( stderr, "Mapping size=%08x%08x flags=%08x fd=%p shared=%p\n",
1048 (unsigned int)(mapping->size >> 32), (unsigned int)mapping->size,
1049 mapping->flags, mapping->fd, mapping->shared );
1052 static struct fd *mapping_get_fd( struct object *obj )
1054 struct mapping *mapping = (struct mapping *)obj;
1055 return (struct fd *)grab_object( mapping->fd );
1058 static void mapping_destroy( struct object *obj )
1060 struct mapping *mapping = (struct mapping *)obj;
1061 assert( obj->ops == &mapping_ops );
1062 if (mapping->fd) release_object( mapping->fd );
1063 if (mapping->committed) release_object( mapping->committed );
1064 if (mapping->shared) release_object( mapping->shared );
1067 static enum server_fd_type mapping_get_fd_type( struct fd *fd )
1069 return FD_TYPE_FILE;
1072 int get_page_size(void)
1074 if (!page_mask) page_mask = sysconf( _SC_PAGESIZE ) - 1;
1075 return page_mask + 1;
1078 struct object *create_user_data_mapping( struct object *root, const struct unicode_str *name,
1079 unsigned int attr, const struct security_descriptor *sd )
1081 void *ptr;
1082 struct mapping *mapping;
1084 if (!(mapping = create_mapping( root, name, attr, sizeof(KSHARED_USER_DATA),
1085 SEC_COMMIT, 0, FILE_READ_DATA | FILE_WRITE_DATA, sd ))) return NULL;
1086 ptr = mmap( NULL, mapping->size, PROT_WRITE, MAP_SHARED, get_unix_fd( mapping->fd ), 0 );
1087 if (ptr != MAP_FAILED)
1089 user_shared_data = ptr;
1090 user_shared_data->SystemCall = 1;
1092 return &mapping->obj;
1095 /* create a file mapping */
1096 DECL_HANDLER(create_mapping)
1098 struct object *root;
1099 struct mapping *mapping;
1100 struct unicode_str name;
1101 const struct security_descriptor *sd;
1102 const struct object_attributes *objattr = get_req_object_attributes( &sd, &name, &root );
1104 if (!objattr) return;
1106 if ((mapping = create_mapping( root, &name, objattr->attributes, req->size, req->flags,
1107 req->file_handle, req->file_access, sd )))
1109 if (get_error() == STATUS_OBJECT_NAME_EXISTS)
1110 reply->handle = alloc_handle( current->process, &mapping->obj, req->access, objattr->attributes );
1111 else
1112 reply->handle = alloc_handle_no_access_check( current->process, &mapping->obj,
1113 req->access, objattr->attributes );
1114 release_object( mapping );
1117 if (root) release_object( root );
1120 /* open a handle to a mapping */
1121 DECL_HANDLER(open_mapping)
1123 struct unicode_str name = get_req_unicode_str();
1125 reply->handle = open_object( current->process, req->rootdir, req->access,
1126 &mapping_ops, &name, req->attributes );
1129 /* get a mapping information */
1130 DECL_HANDLER(get_mapping_info)
1132 struct mapping *mapping;
1134 if (!(mapping = get_mapping_obj( current->process, req->handle, req->access ))) return;
1136 reply->size = mapping->size;
1137 reply->flags = mapping->flags;
1139 if (mapping->flags & SEC_IMAGE)
1141 struct unicode_str name = { NULL, 0 };
1142 data_size_t size;
1143 void *data;
1145 if (mapping->fd) get_nt_name( mapping->fd, &name );
1146 size = min( sizeof(pe_image_info_t) + name.len, get_reply_max_size() );
1147 if ((data = set_reply_data_size( size )))
1149 memcpy( data, &mapping->image, min( sizeof(pe_image_info_t), size ));
1150 if (size > sizeof(pe_image_info_t))
1151 memcpy( (pe_image_info_t *)data + 1, name.str, size - sizeof(pe_image_info_t) );
1153 reply->total = sizeof(pe_image_info_t) + name.len;
1156 if (!(req->access & (SECTION_MAP_READ | SECTION_MAP_WRITE))) /* query only */
1158 release_object( mapping );
1159 return;
1162 if (mapping->shared)
1163 reply->shared_file = alloc_handle( current->process, mapping->shared->file,
1164 GENERIC_READ|GENERIC_WRITE, 0 );
1165 release_object( mapping );
1168 /* add a memory view in the current process */
1169 DECL_HANDLER(map_view)
1171 struct mapping *mapping = NULL;
1172 struct memory_view *view;
1173 data_size_t namelen = 0;
1175 if (!req->size || (req->base & page_mask) || req->base + req->size < req->base) /* overflow */
1177 set_error( STATUS_INVALID_PARAMETER );
1178 return;
1181 /* make sure we don't already have an overlapping view */
1182 LIST_FOR_EACH_ENTRY( view, &current->process->views, struct memory_view, entry )
1184 if (view->base + view->size <= req->base) continue;
1185 if (view->base >= req->base + req->size) continue;
1186 set_error( STATUS_INVALID_PARAMETER );
1187 return;
1190 if (!req->mapping) /* image mapping for a .so dll */
1192 if (get_req_data_size() > sizeof(view->image)) namelen = get_req_data_size() - sizeof(view->image);
1193 if (!(view = mem_alloc( offsetof( struct memory_view, name[namelen] )))) return;
1194 memset( view, 0, sizeof(*view) );
1195 view->base = req->base;
1196 view->size = req->size;
1197 view->start = req->start;
1198 view->flags = SEC_IMAGE;
1199 view->namelen = namelen;
1200 memcpy( &view->image, get_req_data(), min( sizeof(view->image), get_req_data_size() ));
1201 memcpy( view->name, (pe_image_info_t *)get_req_data() + 1, namelen );
1202 add_process_view( current, view );
1203 return;
1206 if (!(mapping = get_mapping_obj( current->process, req->mapping, req->access ))) return;
1208 if (mapping->flags & SEC_IMAGE)
1210 if (req->start || req->size > mapping->image.map_size)
1212 set_error( STATUS_INVALID_PARAMETER );
1213 goto done;
1216 else if (req->start >= mapping->size ||
1217 req->start + req->size < req->start ||
1218 req->start + req->size > ((mapping->size + page_mask) & ~(mem_size_t)page_mask))
1220 set_error( STATUS_INVALID_PARAMETER );
1221 goto done;
1224 if ((view = mem_alloc( offsetof( struct memory_view, name[namelen] ))))
1226 view->base = req->base;
1227 view->size = req->size;
1228 view->start = req->start;
1229 view->flags = mapping->flags;
1230 view->namelen = namelen;
1231 view->fd = !is_fd_removable( mapping->fd ) ? (struct fd *)grab_object( mapping->fd ) : NULL;
1232 view->committed = mapping->committed ? (struct ranges *)grab_object( mapping->committed ) : NULL;
1233 view->shared = mapping->shared ? (struct shared_map *)grab_object( mapping->shared ) : NULL;
1234 if (view->flags & SEC_IMAGE) view->image = mapping->image;
1235 add_process_view( current, view );
1236 if (view->flags & SEC_IMAGE && view->base != mapping->image.base)
1237 set_error( STATUS_IMAGE_NOT_AT_BASE );
1240 done:
1241 release_object( mapping );
1244 /* unmap a memory view from the current process */
1245 DECL_HANDLER(unmap_view)
1247 struct memory_view *view = find_mapped_view( current->process, req->base );
1249 if (!view) return;
1250 if (view->flags & SEC_IMAGE) generate_debug_event( current, DbgUnloadDllStateChange, view );
1251 free_memory_view( view );
1254 /* get a range of committed pages in a file mapping */
1255 DECL_HANDLER(get_mapping_committed_range)
1257 struct memory_view *view = find_mapped_view( current->process, req->base );
1259 if (view) reply->committed = find_committed_range( view, req->offset, &reply->size );
1262 /* add a range to the committed pages in a file mapping */
1263 DECL_HANDLER(add_mapping_committed_range)
1265 struct memory_view *view = find_mapped_view( current->process, req->base );
1267 if (view) add_committed_range( view, req->offset, req->offset + req->size );
1270 /* check if two memory maps are for the same file */
1271 DECL_HANDLER(is_same_mapping)
1273 struct memory_view *view1 = find_mapped_view( current->process, req->base1 );
1274 struct memory_view *view2 = find_mapped_view( current->process, req->base2 );
1276 if (!view1 || !view2) return;
1277 if (!view1->fd || !view2->fd ||
1278 !(view1->flags & SEC_IMAGE) || !(view2->flags & SEC_IMAGE) ||
1279 !is_same_file_fd( view1->fd, view2->fd ))
1280 set_error( STATUS_NOT_SAME_DEVICE );
1283 /* get the filename of a mapping */
1284 DECL_HANDLER(get_mapping_filename)
1286 struct process *process;
1287 struct memory_view *view;
1288 struct unicode_str name;
1290 if (!(process = get_process_from_handle( req->process, PROCESS_QUERY_INFORMATION ))) return;
1292 if ((view = find_mapped_addr( process, req->addr )) && get_view_nt_name( view, &name ))
1294 reply->len = name.len;
1295 if (name.len > get_reply_max_size()) set_error( STATUS_BUFFER_OVERFLOW );
1296 else if (!name.len) set_error( STATUS_FILE_INVALID );
1297 else set_reply_data( name.str, name.len );
1299 else set_error( STATUS_INVALID_ADDRESS );
1301 release_object( process );