@@ -22,7 +22,7 @@ __djgpp_map_physical_memory (void *_our_addr, unsigned long _num_bytes,
2222 || (_num_bytes & 0xfff ))
2323 {
2424 errno = EINVAL ;
25- return -1 ;
25+ goto fail ;
2626 }
2727
2828 /* Loop through the memory range, identify individual handles
@@ -38,7 +38,17 @@ __djgpp_map_physical_memory (void *_our_addr, unsigned long _num_bytes,
3838 /* Find the memory handle corresponding to the first byte. */
3939 d = __djgpp_memory_handle (p );
4040 if (d == NULL )
41- goto fail ;
41+ {
42+ errno = EINVAL ;
43+ goto fail ;
44+ }
45+
46+ /* Base address of the memory handle must be page aligned too. */
47+ if (d -> address & 0xfff )
48+ {
49+ errno = EINVAL ;
50+ goto fail ;
51+ }
4252
4353 /* Find the last byte in the range that's also in the same
4454 * memory handle as our current starting byte. We start with
@@ -56,7 +66,10 @@ __djgpp_map_physical_memory (void *_our_addr, unsigned long _num_bytes,
5666 /* Find the memory handle corresponding to this test byte. */
5767 d2 = __djgpp_memory_handle (handle_end_addr );
5868 if (d2 == NULL )
59- goto fail ;
69+ {
70+ errno = EINVAL ;
71+ goto fail ;
72+ }
6073
6174 /* Is this test byte in the same handle as the first byte? */
6275 if (d2 -> handle == d -> handle )
@@ -72,7 +85,29 @@ __djgpp_map_physical_memory (void *_our_addr, unsigned long _num_bytes,
7285 if (__dpmi_map_device_in_memory_block (& meminfo ,
7386 (_phys_addr
7487 + (p - (unsigned ) _our_addr ))))
75- goto fail ;
88+ {
89+ switch (__dpmi_error )
90+ {
91+ case 0x0508 : /* Unsupported function (returned by DPMI 0.9 host, error number is same as DPMI function number) */
92+ case 0x8001 : /* Unsupported function (returned by DPMI 1.0 host) */
93+ errno = ENOSYS ;
94+ break ;
95+ case 0x8003 : /* System integrity (invalid device address) */
96+ errno = ENXIO ;
97+ break ;
98+ case 0x8010 : /* Resource unavailable (DPMI host cannot allocate internal resources to complete an operation) */
99+ errno = ENOMEM ;
100+ break ;
101+ case 0x8023 : /* Invalid handle (in ESI) */
102+ case 0x8025 : /* Invalid linear address (specified range is not within specified block or EBX/EDX is not page-aligned) */
103+ errno = EINVAL ;
104+ break ;
105+ default : /* Other unspecified error */
106+ errno = EACCES ;
107+ break ;
108+ }
109+ goto fail ;
110+ }
76111
77112 /* Move on to the next memory handle. */
78113 p = handle_end_addr ;
@@ -82,6 +117,5 @@ __djgpp_map_physical_memory (void *_our_addr, unsigned long _num_bytes,
82117 return 0 ;
83118
84119 fail :
85- errno = EACCES ;
86120 return -1 ;
87121}
0 commit comments