Skip to content

Commit 33de2a4

Browse files
committed
Merge branch 'master' into jwt27
2 parents 43de7a4 + 0d8be0f commit 33de2a4

File tree

5 files changed

+84
-18
lines changed

5 files changed

+84
-18
lines changed

src/libc/dpmi/api/d0507.S

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,30 @@
1515
movl 8(%eax), %ebx
1616
movl ARG2, %edx
1717

18-
DPMI(0x0507)
18+
movw $0x0507, %ax
19+
int $0x31
1920

21+
jnc L_noerror
2022
movl ARG1, %edx
23+
24+
/*
25+
* Check if output ecx (number of modified pages) is valid.
26+
* It has to be less than input ecx (total number of pages)
27+
* as modification of some pages at this point failed. If
28+
* output ecx is invalid then set it to zero as in this case
29+
* probably no page was modified by DPMI host (otherwise it
30+
* would have set the valid number of modified pages).
31+
*/
32+
cmpl %ecx, 4(%edx)
33+
ja L_ecxvalid
34+
xorl %ecx, %ecx
35+
L_ecxvalid:
36+
2137
movl %ecx, 4(%edx)
38+
movw %ax, ___dpmi_error
39+
movl $-1, %eax
40+
jmp L_leave
41+
L_noerror:
2242

2343
xorl %eax,%eax
2444

src/libc/dpmi/api/d0507.txh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ words which specify the new attributes.
2525
@xref{__dpmi_get_page_attributes}, for the definition of the page
2626
attribute word.
2727

28+
On error this function changes @code{@var{info}->size} to the number
29+
of modified pages as reported by DPMI function AX = 0x0507. If DPMI
30+
function reports that all the input pages were modified, or more pages
31+
than the input number of pages were modified, then that is treated as
32+
invalid value reported by DPMI function, and so this functions changes
33+
@code{@var{info}->size} to 0, as probably no page was modified.
34+
2835
The DJGPP startup code calls this function to uncommit the so-called
2936
@dfn{null page}, the first 4KB of the program's address space. This
3037
causes @code{NULL} pointer dereferences, a frequent programmatic error,

src/libc/dpmi/helper/mapmem.txh

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,28 +60,28 @@ DPMI server rejected the mapping request.
6060
@example
6161
void *my_page_aligned_memory = valloc (16384);
6262
if (!my_page_aligned_memory)
63-
{
63+
@{
6464
printf ("Failed to allocate page-aligned memory!\n");
6565
return;
66-
}
66+
@}
6767

6868
if (__djgpp_map_physical_memory (my_page_aligned_memory, 16384,
6969
0x40000000))
70-
{
70+
@{
7171
printf ("Failed to map physical addresses!\n");
72-
}
72+
@}
7373
else
74-
{
74+
@{
7575
/* code which access mapped my_page_aligned_memory */
76-
}
76+
@}
7777

7878
if (__djgpp_set_page_attributes (my_page_aligned_memory, 16384,
7979
(0<<4) | (1<<3) | 1))
80-
{
80+
@{
8181
printf ("Failed to unmap physical addresses!\n");
82-
}
82+
@}
8383
else
84-
{
84+
@{
8585
free (my_page_aligned_memory);
86-
}
86+
@}
8787
@end example

src/libc/dpmi/helper/setattr.c

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

src/libc/pc_hw/nearptr/nearptr.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ int __djgpp_nearptr_enable(void)
1414
{
1515
if(!__dpmi_set_segment_limit(_my_ds(), 0xffffffffU)) {
1616
if(__dpmi_get_segment_limit(_my_ds()) != 0xffffffffU)
17+
{
18+
__dpmi_set_segment_limit(_my_ds(), __djgpp_selector_limit | 0xfff);
1719
return 0; /* We set it but DPMI ignored/truncated it */
20+
}
1821
__dpmi_set_segment_limit(__djgpp_ds_alias, 0xffffffffU);
1922
__dpmi_set_segment_limit(_my_cs(), 0xffffffffU);
2023
_crt0_startup_flags |= _CRT0_FLAG_NEARPTR;

0 commit comments

Comments
 (0)