2 * Server-side file mapping management
4 * Copyright (C) 1999 Alexandre Julliard
14 #include "server/process.h"
15 #include "server/thread.h"
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
=
33 NULL
, /* should never get called */
34 NULL
, /* should never get called */
35 NULL
, /* should never get called */
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
,
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
;
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
);
68 else mapping
->file
= NULL
;
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
;
82 if (!(mapping
= (struct mapping
*)get_handle_obj( current
->process
, handle
,
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
);
90 release_object( mapping
);
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
);