Fixes buffer overrun problems with GetDIBits.
[wine.git] / server / mapping.c
blobb6f4b688b775ac4f7e0a8fbda88ff40bbc0b047d
1 /*
2 * Server-side file mapping management
4 * Copyright (C) 1999 Alexandre Julliard
5 */
7 #include <assert.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <unistd.h>
12 #include "winerror.h"
13 #include "winnt.h"
14 #include "server/process.h"
15 #include "server/thread.h"
17 struct mapping
19 struct object obj; /* object header */
20 int size_high; /* mapping size */
21 int size_low; /* mapping size */
22 int protect; /* protection flags */
23 struct file *file; /* file mapped */
26 static void mapping_dump( struct object *obj, int verbose );
27 static void mapping_destroy( struct object *obj );
29 static const struct object_ops mapping_ops =
31 mapping_dump,
32 no_add_queue,
33 NULL, /* should never get called */
34 NULL, /* should never get called */
35 NULL, /* should never get called */
36 no_read_fd,
37 no_write_fd,
38 no_flush,
39 no_get_file_info,
40 mapping_destroy
43 struct object *create_mapping( int size_high, int size_low, int protect,
44 int handle, const char *name )
46 struct mapping *mapping;
48 if (!(mapping = (struct mapping *)create_named_object( name, &mapping_ops,
49 sizeof(*mapping) )))
50 return NULL;
51 if (GET_ERROR() == ERROR_ALREADY_EXISTS)
52 return &mapping->obj; /* Nothing else to do */
54 mapping->size_high = size_high;
55 mapping->size_low = size_low;
56 mapping->protect = protect;
57 if (handle != -1)
59 int access = 0;
60 if (protect & VPROT_READ) access |= GENERIC_READ;
61 if (protect & VPROT_WRITE) access |= GENERIC_WRITE;
62 if (!(mapping->file = get_file_obj( current->process, handle, access )))
64 release_object( mapping );
65 return NULL;
68 else mapping->file = NULL;
69 return &mapping->obj;
72 int open_mapping( unsigned int access, int inherit, const char *name )
74 return open_object( name, &mapping_ops, access, inherit );
77 int get_mapping_info( int handle, struct get_mapping_info_reply *reply )
79 struct mapping *mapping;
80 int fd;
82 if (!(mapping = (struct mapping *)get_handle_obj( current->process, handle,
83 0, &mapping_ops )))
84 return -1;
85 reply->size_high = mapping->size_high;
86 reply->size_low = mapping->size_low;
87 reply->protect = mapping->protect;
88 if (mapping->file) fd = file_get_mmap_fd( mapping->file );
89 else fd = -1;
90 release_object( mapping );
91 return fd;
94 static void mapping_dump( struct object *obj, int verbose )
96 struct mapping *mapping = (struct mapping *)obj;
97 assert( obj->ops == &mapping_ops );
98 fprintf( stderr, "Mapping size=%08x%08x prot=%08x file=%p name='%s'\n",
99 mapping->size_high, mapping->size_low, mapping->protect,
100 mapping->file, get_object_name( &mapping->obj ) );
103 static void mapping_destroy( struct object *obj )
105 struct mapping *mapping = (struct mapping *)obj;
106 assert( obj->ops == &mapping_ops );
107 if (mapping->file) release_object( mapping->file );
108 free( mapping );