annotate vidix/sysdep/libdha_win32.c @ 31337:3fd6746f539c

Mark exit_sig() function as static; it is only used within the file.
author diego
date Mon, 14 Jun 2010 11:25:39 +0000
parents b77bfd94aaf3
children 9d1734a75102
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4164
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
1 /*
30419
b77bfd94aaf3 Add missing license headers.
diego
parents: 29263
diff changeset
2 * MAPDEV.h - include file for VxD MAPDEV
b77bfd94aaf3 Add missing license headers.
diego
parents: 29263
diff changeset
3 * Copyright (c) 1996 Vireo Software, Inc.
b77bfd94aaf3 Add missing license headers.
diego
parents: 29263
diff changeset
4 * Modified for libdha by Nick Kurshev.
b77bfd94aaf3 Add missing license headers.
diego
parents: 29263
diff changeset
5 *
b77bfd94aaf3 Add missing license headers.
diego
parents: 29263
diff changeset
6 * This file is part of MPlayer.
b77bfd94aaf3 Add missing license headers.
diego
parents: 29263
diff changeset
7 *
b77bfd94aaf3 Add missing license headers.
diego
parents: 29263
diff changeset
8 * MPlayer is free software; you can redistribute it and/or modify
b77bfd94aaf3 Add missing license headers.
diego
parents: 29263
diff changeset
9 * it under the terms of the GNU General Public License as published by
b77bfd94aaf3 Add missing license headers.
diego
parents: 29263
diff changeset
10 * the Free Software Foundation; either version 2 of the License, or
b77bfd94aaf3 Add missing license headers.
diego
parents: 29263
diff changeset
11 * (at your option) any later version.
b77bfd94aaf3 Add missing license headers.
diego
parents: 29263
diff changeset
12 *
b77bfd94aaf3 Add missing license headers.
diego
parents: 29263
diff changeset
13 * MPlayer is distributed in the hope that it will be useful,
b77bfd94aaf3 Add missing license headers.
diego
parents: 29263
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
b77bfd94aaf3 Add missing license headers.
diego
parents: 29263
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b77bfd94aaf3 Add missing license headers.
diego
parents: 29263
diff changeset
16 * GNU General Public License for more details.
b77bfd94aaf3 Add missing license headers.
diego
parents: 29263
diff changeset
17 *
b77bfd94aaf3 Add missing license headers.
diego
parents: 29263
diff changeset
18 * You should have received a copy of the GNU General Public License along
b77bfd94aaf3 Add missing license headers.
diego
parents: 29263
diff changeset
19 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
b77bfd94aaf3 Add missing license headers.
diego
parents: 29263
diff changeset
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
b77bfd94aaf3 Add missing license headers.
diego
parents: 29263
diff changeset
21 */
4164
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
22
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
23 #include <windows.h>
12056
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
24 #include <ddk/ntddk.h>
26994
4eb30f58ea41 Fix dhahelper.h #include paths.
diego
parents: 26900
diff changeset
25 #include "vidix/dhahelperwin/dhahelper.h"
12056
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
26
4164
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
27 /*
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
28 This is the request structure that applications use
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
29 to request services from the MAPDEV VxD.
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
30 */
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
31
25607
9d0b189ce1b2 Fix illegal identifiers: Names starting with __ or _ and uppercase are reserved
diego
parents: 22900
diff changeset
32 typedef struct MapDevRequest
4164
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
33 {
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
34 DWORD mdr_ServiceID; /* supplied by caller */
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
35 LPVOID mdr_PhysicalAddress; /* supplied by caller */
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
36 DWORD mdr_SizeInBytes; /* supplied by caller */
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
37 LPVOID mdr_LinearAddress; /* returned by VxD */
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
38 WORD mdr_Selector; /* returned if 16-bit caller */
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
39 WORD mdr_Status; /* MDR_xxxx code below */
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
40 } MAPDEVREQUEST, *PMAPDEVREQUEST;
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
41
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
42 #define MDR_SERVICE_MAP CTL_CODE(FILE_DEVICE_UNKNOWN, 1, METHOD_NEITHER, FILE_ANY_ACCESS)
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
43 #define MDR_SERVICE_UNMAP CTL_CODE(FILE_DEVICE_UNKNOWN, 2, METHOD_NEITHER, FILE_ANY_ACCESS)
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
44
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
45 #define MDR_STATUS_SUCCESS 1
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
46 #define MDR_STATUS_ERROR 0
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
47 /*#include "winioctl.h"*/
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
48 #define FILE_DEVICE_UNKNOWN 0x00000022
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
49 #define METHOD_NEITHER 3
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
50
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28232
diff changeset
51
28232
8df85ad26746 Add missing 'void' keyword to parameterless function declarations.
diego
parents: 27721
diff changeset
52 int IsWinNT(void) {
12056
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
53 OSVERSIONINFO OSVersionInfo;
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
54 OSVersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
55 GetVersionEx(&OSVersionInfo);
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
56 return OSVersionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28232
diff changeset
57 }
12056
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
58
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28232
diff changeset
59 static HANDLE hDriver = INVALID_HANDLE_VALUE;
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28232
diff changeset
60
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28232
diff changeset
61
4164
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
62 /* Memory Map a piece of Real Memory */
10980
e687fa1d55c6 port libdha to mingw
faust3
parents: 4164
diff changeset
63 void *map_phys_mem(unsigned long base, unsigned long size) {
12056
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
64 if(!IsWinNT()){
4164
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
65 HANDLE hDevice ;
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
66 PVOID inBuf[1] ; /* buffer for struct pointer to VxD */
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
67 DWORD cbBytesReturned ; /* count of bytes returned from VxD */
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
68 MAPDEVREQUEST req ; /* map device request structure */
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
69 const PCHAR VxDName = "\\\\.\\MAPDEV.VXD" ;
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
70 const PCHAR VxDNameAlreadyLoaded = "\\\\.\\MAPDEV" ;
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
71
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
72 hDevice = CreateFile(VxDName, 0,0,0,
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
73 CREATE_NEW, FILE_FLAG_DELETE_ON_CLOSE, 0) ;
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
74 if (hDevice == INVALID_HANDLE_VALUE)
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
75 hDevice = CreateFile(VxDNameAlreadyLoaded, 0,0,0,
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
76 CREATE_NEW, FILE_FLAG_DELETE_ON_CLOSE, 0) ;
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
77 if (hDevice == INVALID_HANDLE_VALUE) {
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
78 fprintf(stderr, "Cannot open driver, error=%08lx\n", GetLastError()) ;
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
79 exit(1) ; }
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
80
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
81 req.mdr_ServiceID = MDR_SERVICE_MAP ;
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
82 req.mdr_PhysicalAddress = (PVOID)base ;
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
83 req.mdr_SizeInBytes = size ;
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
84 inBuf[0] = &req ;
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
85
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
86 if ( ! DeviceIoControl(hDevice, MDR_SERVICE_MAP, inBuf, sizeof(PVOID),
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
87 NULL, 0, &cbBytesReturned, NULL) ) {
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
88 fprintf(stderr, "Failed to map device\n") ; exit(1) ; }
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
89
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
90 return (void*)req.mdr_LinearAddress ;
12056
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
91 }
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
92 else{
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
93 dhahelper_t dhahelper_priv;
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
94 DWORD dwBytesReturned;
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
95 dhahelper_priv.size = size;
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
96 dhahelper_priv.base = base;
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
97 if(hDriver==INVALID_HANDLE_VALUE)hDriver = CreateFile("\\\\.\\DHAHELPER",GENERIC_READ | GENERIC_WRITE,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
98 if (!DeviceIoControl(hDriver, IOCTL_DHAHELPER_MAPPHYSTOLIN, &dhahelper_priv,sizeof(dhahelper_t), &dhahelper_priv, sizeof(dhahelper_t),&dwBytesReturned, NULL)){
17971
fd0d4b94b5ec Change some printf calls to fprintf.
diego
parents: 12056
diff changeset
99 fprintf(stderr,"Unable to map the requested memory region.\n");
12056
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
100 return NULL;
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
101 }
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
102 else return dhahelper_priv.ptr;
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
103 }
4164
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
104 }
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
105
12056
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
106 void unmap_phys_mem(void *ptr, unsigned long size) {
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
107 if(IsWinNT()){
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
108 dhahelper_t dhahelper_priv;
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
109 DWORD dwBytesReturned;
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
110 dhahelper_priv.ptr = ptr;
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
111 DeviceIoControl(hDriver, IOCTL_DHAHELPER_UNMAPPHYSADDR, &dhahelper_priv,sizeof(dhahelper_t), NULL, 0, &dwBytesReturned, NULL);
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
112 }
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
113 }