Moves more stuff from windows.h.
[wine.git] / server / mapping.c
blob2f3dac789147a229da132ca8c0d483ce72aa0c25
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 mapping_destroy
41 struct object *create_mapping( int size_high, int size_low, int protect,
42 int handle, const char *name )
44 struct mapping *mapping;
46 if (!(mapping = (struct mapping *)create_named_object( name, &mapping_ops,
47 sizeof(*mapping) )))
48 return NULL;
49 if (GET_ERROR() == ERROR_ALREADY_EXISTS)
50 return &mapping->obj; /* Nothing else to do */
52 mapping->size_high = size_high;
53 mapping->size_low = size_low;
54 mapping->protect = protect;
55 if (handle != -1)
57 int access = 0;
58 if (protect & VPROT_READ) access |= GENERIC_READ;
59 if (protect & VPROT_WRITE) access |= GENERIC_WRITE;
60 if (!(mapping->file = get_file_obj( current->process, handle, access )))
62 release_object( mapping );
63 return NULL;
66 else mapping->file = NULL;
67 return &mapping->obj;
70 int open_mapping( unsigned int access, int inherit, const char *name )
72 return open_object( name, &mapping_ops, access, inherit );
75 int get_mapping_info( int handle, struct get_mapping_info_reply *reply )
77 struct mapping *mapping;
78 int fd;
80 if (!(mapping = (struct mapping *)get_handle_obj( current->process, handle,
81 0, &mapping_ops )))
82 return -1;
83 reply->size_high = mapping->size_high;
84 reply->size_low = mapping->size_low;
85 reply->protect = mapping->protect;
86 if (mapping->file) fd = file_get_mmap_fd( mapping->file );
87 else fd = -1;
88 release_object( mapping );
89 return fd;
92 static void mapping_dump( struct object *obj, int verbose )
94 struct mapping *mapping = (struct mapping *)obj;
95 assert( obj->ops == &mapping_ops );
96 fprintf( stderr, "Mapping size=%08x%08x prot=%08x file=%p\n",
97 mapping->size_high, mapping->size_low, mapping->protect, mapping->file );
100 static void mapping_destroy( struct object *obj )
102 struct mapping *mapping = (struct mapping *)obj;
103 assert( obj->ops == &mapping_ops );
104 if (mapping->file) release_object( mapping->file );
105 free( mapping );