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 */
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
,
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
;
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
);
66 else mapping
->file
= NULL
;
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
;
80 if (!(mapping
= (struct mapping
*)get_handle_obj( current
->process
, handle
,
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
);
88 release_object( mapping
);
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
);