Skip to content

Commit 17a0ff4

Browse files
committed
Merge branch 'master' into jwt27
2 parents 50a397f + 6b58b64 commit 17a0ff4

File tree

4 files changed

+46
-15
lines changed

4 files changed

+46
-15
lines changed

src/libc/dpmi/helper/mapmem.c

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

src/libc/dpmi/helper/mapmem.txh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ Even on failure, this routine may affect a subset of the pages specified.
4848
@subheading Return Value
4949

5050
0 on success, -1 on failure. On failure, @code{errno} will be set to
51-
@code{EINVAL} for illegal input parameters, or @code{EACCES} if the
52-
DPMI server rejected the mapping request.
51+
appropriate errno code and @code{__dpmi_error} to DPMI error code.
5352

5453
@subheading Portability
5554

src/libc/dpmi/helper/setattr.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@ __djgpp_set_page_attributes (void *_our_addr, unsigned long _num_bytes,
5151
d = __djgpp_memory_handle (p);
5252
if (d == NULL)
5353
{
54-
errno = EFAULT;
54+
errno = EINVAL;
5555
goto fail;
5656
}
5757

5858
/* Base address of the memory handle must be page aligned too. */
5959
if (d->address & 0xfff)
6060
{
61-
errno = EFAULT;
61+
errno = EINVAL;
6262
goto fail;
6363
}
6464

@@ -79,7 +79,7 @@ __djgpp_set_page_attributes (void *_our_addr, unsigned long _num_bytes,
7979
d2 = __djgpp_memory_handle (handle_end_addr);
8080
if (d2 == NULL)
8181
{
82-
errno = EFAULT;
82+
errno = EINVAL;
8383
goto fail;
8484
}
8585

@@ -107,13 +107,11 @@ __djgpp_set_page_attributes (void *_our_addr, unsigned long _num_bytes,
107107
case 0x8014: /* Backing store unavailable */
108108
errno = ENOMEM;
109109
break;
110-
case 0x8021: /* Invalid value (illegal request in bits 0-2 of one or more page attribute words) */
111-
errno = EINVAL;
112-
break;
113110
case 0x8002: /* Invalid state (page in wrong state for request) */
111+
case 0x8021: /* Invalid value (illegal request in bits 0-2 of one or more page attribute words) */
114112
case 0x8023: /* Invalid handle (in ESI) */
115113
case 0x8025: /* Invalid linear address (specified range is not within specified block) */
116-
errno = EFAULT;
114+
errno = EINVAL;
117115
break;
118116
default: /* Other unspecified error */
119117
errno = EACCES;

src/libc/dpmi/helper/setattr.txh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Every page in the specified address range that begins at @var{out_addr}
2020
must belong to some DPMI handle in @code{__djgpp_memory_handle_list} which
2121
is managed by @code{sbrk} allocator (memory pointer can be obtained by
2222
e.g.@: @code{valloc}). If some page does not belong to some DJGPP DPMI
23-
handle, @code{errno} will be set to @code{EFAULT} and the routine will fail.
23+
handle, @code{errno} will be set to @code{EINVAL} and the routine will fail.
2424

2525
Consult DPMI documentation on function 0507H for the meaning of the
2626
@var{attributes} argument. Note: since 0507H is a DPMI service new

0 commit comments

Comments
 (0)