Implemented file sharing checks in the server.
[wine/hacks.git] / server / mapping.c
blobceabd5d9a7c5ab727da925a642ba0a8cd3b1a898
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/thread.h"
16 struct mapping
18 struct object obj; /* object header */
19 int size_high; /* mapping size */
20 int size_low; /* mapping size */
21 int protect; /* protection flags */
22 struct file *file; /* file mapped */
25 static void mapping_dump( struct object *obj, int verbose );
26 static void mapping_destroy( struct object *obj );
28 static const struct object_ops mapping_ops =
30 mapping_dump,
31 no_add_queue,
32 NULL, /* should never get called */
33 NULL, /* should never get called */
34 NULL, /* should never get called */
35 no_read_fd,
36 no_write_fd,
37 no_flush,
38 no_get_file_info,
39 mapping_destroy
42 struct object *create_mapping( int size_high, int size_low, int protect,
43 int handle, const char *name )
45 struct mapping *mapping;
47 if (!(mapping = (struct mapping *)create_named_object( name, &mapping_ops,
48 sizeof(*mapping) )))
49 return NULL;
50 if (GET_ERROR() == ERROR_ALREADY_EXISTS)
51 return &mapping->obj; /* Nothing else to do */
53 mapping->size_high = size_high;
54 mapping->size_low = size_low;
55 mapping->protect = protect;
56 if (handle != -1)
58 int access = 0;
59 if (protect & VPROT_READ) access |= GENERIC_READ;
60 if (protect & VPROT_WRITE) access |= GENERIC_WRITE;
61 if (!(mapping->file = get_file_obj( current->process, handle, access )))
63 release_object( mapping );
64 return NULL;
67 else mapping->file = NULL;
68 return &mapping->obj;
71 int open_mapping( unsigned int access, int inherit, const char *name )
73 return open_object( name, &mapping_ops, access, inherit );
76 int get_mapping_info( int handle, struct get_mapping_info_reply *reply )
78 struct mapping *mapping;
79 int fd;
81 if (!(mapping = (struct mapping *)get_handle_obj( current->process, handle,
82 0, &mapping_ops )))
83 return -1;
84 reply->size_high = mapping->size_high;
85 reply->size_low = mapping->size_low;
86 reply->protect = mapping->protect;
87 if (mapping->file) fd = file_get_mmap_fd( mapping->file );
88 else fd = -1;
89 release_object( mapping );
90 return fd;
93 static void mapping_dump( struct object *obj, int verbose )
95 struct mapping *mapping = (struct mapping *)obj;
96 assert( obj->ops == &mapping_ops );
97 fprintf( stderr, "Mapping size=%08x%08x prot=%08x file=%p name='%s'\n",
98 mapping->size_high, mapping->size_low, mapping->protect,
99 mapping->file, get_object_name( &mapping->obj ) );
102 static void mapping_destroy( struct object *obj )
104 struct mapping *mapping = (struct mapping *)obj;
105 assert( obj->ops == &mapping_ops );
106 if (mapping->file) release_object( mapping->file );
107 free( mapping );