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