@@ -28,7 +28,7 @@ __djgpp_set_page_attributes (void *_our_addr, unsigned long _num_bytes,
2828 || ((_attributes & 0x3 ) == 2 ))
2929 {
3030 errno = EINVAL ;
31- return -1 ;
31+ goto fail ;
3232 }
3333
3434 /* Set up an array of page attribute information. */
@@ -50,7 +50,17 @@ __djgpp_set_page_attributes (void *_our_addr, unsigned long _num_bytes,
5050 /* Find the memory handle corresponding to the first byte. */
5151 d = __djgpp_memory_handle (p );
5252 if (d == NULL )
53- goto fail ;
53+ {
54+ errno = EFAULT ;
55+ goto fail ;
56+ }
57+
58+ /* Base address of the memory handle must be page aligned too. */
59+ if (d -> address & 0xfff )
60+ {
61+ errno = EFAULT ;
62+ goto fail ;
63+ }
5464
5565 /* Find the last byte in the range that's also in the same
5666 * memory handle as our current starting byte. We start with
@@ -68,7 +78,10 @@ __djgpp_set_page_attributes (void *_our_addr, unsigned long _num_bytes,
6878 /* Find the memory handle corresponding to this test byte. */
6979 d2 = __djgpp_memory_handle (handle_end_addr );
7080 if (d2 == NULL )
71- goto fail ;
81+ {
82+ errno = EFAULT ;
83+ goto fail ;
84+ }
7285
7386 /* Is this test byte in the same handle as the first byte? */
7487 if (d2 -> handle == d -> handle )
@@ -81,9 +94,33 @@ __djgpp_set_page_attributes (void *_our_addr, unsigned long _num_bytes,
8194 meminfo .handle = d -> handle ;
8295 meminfo .size = num_pages2 ;
8396 meminfo .address = p - d -> address ;
84- if (__dpmi_set_page_attributes (& meminfo , attr )
85- || meminfo .size != num_pages2 )
86- goto fail ;
97+ if (__dpmi_set_page_attributes (& meminfo , attr ))
98+ {
99+ switch (__dpmi_error )
100+ {
101+ case 0x0507 : /* Unsupported function (returned by DPMI 0.9 host, error number is same as DPMI function number) */
102+ case 0x8001 : /* Unsupported function (returned by DPMI 1.0 host) */
103+ errno = ENOSYS ;
104+ break ;
105+ case 0x8010 : /* Resource unavailable (DPMI host cannot allocate internal resources to complete an operation) */
106+ case 0x8013 : /* Physical memory unavailable */
107+ case 0x8014 : /* Backing store unavailable */
108+ errno = ENOMEM ;
109+ break ;
110+ case 0x8021 : /* Invalid value (illegal request in bits 0-2 of one or more page attribute words) */
111+ errno = EINVAL ;
112+ break ;
113+ case 0x8002 : /* Invalid state (page in wrong state for request) */
114+ case 0x8023 : /* Invalid handle (in ESI) */
115+ case 0x8025 : /* Invalid linear address (specified range is not within specified block) */
116+ errno = EFAULT ;
117+ break ;
118+ default : /* Other unspecified error */
119+ errno = EACCES ;
120+ break ;
121+ }
122+ goto fail ;
123+ }
87124
88125 /* Move on to the next memory handle. */
89126 p = handle_end_addr ;
@@ -93,6 +130,5 @@ __djgpp_set_page_attributes (void *_our_addr, unsigned long _num_bytes,
93130 return 0 ;
94131
95132 fail :
96- errno = EACCES ;
97133 return -1 ;
98134}
0 commit comments