Introduce a better error reporting, using mach error codes

It seems there is no need to use dynamic allocation in mach_host_info.
This commit is contained in:
manu 2002-11-11 01:18:44 +00:00
parent 20b98814a9
commit 293d243256
5 changed files with 253 additions and 24 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: files.mach,v 1.4 2002/11/10 21:53:40 manu Exp $
# $NetBSD: files.mach,v 1.5 2002/11/11 01:18:44 manu Exp $
#
# Config file description for machine-independent Mach compat code.
# Included by ports that need it.
@ -6,6 +6,7 @@
# ports should define any machine-specific files they need in their
# own file lists.
file compat/mach/mach_errno.c compat_mach
file compat/mach/mach_exec.c compat_mach
file compat/mach/mach_host.c compat_mach
file compat/mach/mach_misc.c compat_mach

View File

@ -0,0 +1,131 @@
/* $NetBSD: mach_errno.c,v 1.1 2002/11/11 01:18:44 manu Exp $ */
/*-
* Copyright (c) 2002 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Emmanuel Dreyfus
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the NetBSD
* Foundation, Inc. and its contributors.
* 4. Neither the name of The NetBSD Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: mach_errno.c,v 1.1 2002/11/11 01:18:44 manu Exp $");
#include <compat/mach/mach_errno.h>
int native_to_mach_errno[] = {
MACH_KERN_SUCCESS, /* 0 */
MACH_KERN_PROTECTION_FAILURE, /* EPERM */
MACH_KERN_FAILURE, /* ENOENT */
MACH_KERN_FAILURE, /* ESRCH */
MACH_KERN_FAILURE, /* EINTR */
MACH_KERN_FAILURE, /* EIO */ /* 5 */
MACH_KERN_FAILURE, /* ENXIO */
MACH_KERN_FAILURE, /* E2BIG */
MACH_KERN_FAILURE, /* ENOEXEC */
MACH_KERN_FAILURE, /* EBADF */
MACH_KERN_FAILURE, /* ECHILD */ /* 10 */
MACH_KERN_FAILURE, /* EDEADLK */
MACH_KERN_FAILURE, /* ENOMEM */
MACH_KERN_FAILURE, /* EACCES */
MACH_KERN_INVALID_ADDRESS, /* EFAULT */
MACH_KERN_FAILURE, /* ENOTBLK */ /* 15 */
MACH_KERN_FAILURE, /* EBUSY */
MACH_KERN_FAILURE, /* EEXIST */
MACH_KERN_FAILURE, /* EXDEV */
MACH_KERN_FAILURE, /* ENODEV */
MACH_KERN_FAILURE, /* ENOTDIR */ /* 20 */
MACH_KERN_FAILURE, /* EISDIR */
MACH_KERN_INVALID_ARGUMENT, /* EINVAL */
MACH_KERN_FAILURE, /* ENFILE */
MACH_KERN_FAILURE, /* EMFILE */
MACH_KERN_FAILURE, /* ENOTTY */ /* 25 */
MACH_KERN_FAILURE, /* ETXTBSY */
MACH_KERN_FAILURE, /* EFBIG */
MACH_KERN_FAILURE, /* ENOSPC */
MACH_KERN_FAILURE, /* ESPIPE */
MACH_KERN_FAILURE, /* EROFS */ /* 30 */
MACH_KERN_FAILURE, /* EMLINK */
MACH_KERN_FAILURE, /* EPIPE */
MACH_KERN_FAILURE, /* EDOM */
MACH_KERN_FAILURE, /* ERANGE */
MACH_KERN_FAILURE, /* EAGAIN */ /* 35 */
MACH_KERN_FAILURE, /* EWOULDBLOCK */
MACH_KERN_FAILURE, /* EINPROGRESS */
MACH_KERN_FAILURE, /* EALREADY */
MACH_KERN_FAILURE, /* ENOTSOCK */
MACH_KERN_FAILURE, /* EDESTADDRREQ */ /* 40 */
MACH_KERN_FAILURE, /* EMSGSIZE */
MACH_KERN_FAILURE, /* EPROTOTYPE */
MACH_KERN_FAILURE, /* ENOPROTOOPT */
MACH_KERN_FAILURE, /* ESOCKTNOSUPPORT */
MACH_KERN_FAILURE, /* EOPNOTSUPP */ /* 45 */
MACH_KERN_FAILURE, /* EPFNOSUPPORT */
MACH_KERN_FAILURE, /* EAFNOSUPPORT */
MACH_KERN_FAILURE, /* EADDRINUSE */
MACH_KERN_FAILURE, /* EADDRNOTAVAIL */
MACH_KERN_FAILURE, /* ENETDOWN */ /* 50 */
MACH_KERN_FAILURE, /* ENETUNREACH */
MACH_KERN_FAILURE, /* ENETRESET */
MACH_KERN_FAILURE, /* ECONNABORTED */
MACH_KERN_FAILURE, /* ECONNRESET */
MACH_KERN_FAILURE, /* ENOBUFS */ /* 55 */
MACH_KERN_FAILURE, /* EISCONN */
MACH_KERN_FAILURE, /* ENOTCONN */
MACH_KERN_FAILURE, /* ESHUTDOWN */
MACH_KERN_FAILURE, /* ETOOMANYREFS */
MACH_KERN_FAILURE, /* ETIMEDOUT */ /* 60 */
MACH_KERN_FAILURE, /* ECONNREFUSED */
MACH_KERN_FAILURE, /* ELOOP */
MACH_KERN_FAILURE, /* ENAMETOOLONG */
MACH_KERN_FAILURE, /* EHOSTDOWN */
MACH_KERN_FAILURE, /* EHOSTUNREACH */ /* 65 */
MACH_KERN_FAILURE, /* ENOTEMPTY */
MACH_KERN_FAILURE, /* EPROCLIM */
MACH_KERN_FAILURE, /* EUSERS */
MACH_KERN_FAILURE, /* EDQUOT */
MACH_KERN_FAILURE, /* ESTALE */ /* 70 */
MACH_KERN_FAILURE, /* EREMOTE */
MACH_KERN_FAILURE, /* EBADRPC */
MACH_KERN_FAILURE, /* ERPCMISMATCH */
MACH_KERN_FAILURE, /* EPROGUNAVAIL */
MACH_KERN_FAILURE, /* EPROGMISMATCH */ /* 75 */
MACH_KERN_FAILURE, /* EPROCUNAVAIL */
MACH_KERN_FAILURE, /* ENOLCK */
MACH_KERN_FAILURE, /* ENOSYS */
MACH_KERN_FAILURE, /* EFTYPE */
MACH_KERN_FAILURE, /* EAUTH */ /* 80 */
MACH_KERN_FAILURE, /* ENEEDAUTH */
MACH_KERN_FAILURE, /* EIDRM */
MACH_KERN_FAILURE, /* ENOMSG */
MACH_KERN_FAILURE, /* EOVERFLOW */
MACH_KERN_FAILURE, /* EILSEQ */ /* 85 */
};

View File

@ -0,0 +1,95 @@
/* $NetBSD: mach_errno.h,v 1.1 2002/11/11 01:18:44 manu Exp $ */
/*-
* Copyright (c) 2002 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Emmanuel Dreyfus
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the NetBSD
* Foundation, Inc. and its contributors.
* 4. Neither the name of The NetBSD Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _MACH_ERRNO_H_
#define _MACH_ERRNO_H_
extern int native_to_mach_errno[];
#define MACH_KERN_SUCCESS 0
#define MACH_KERN_INVALID_ADDRESS 1
#define MACH_KERN_PROTECTION_FAILURE 2
#define MACH_KERN_NO_SPACE 3
#define MACH_KERN_INVALID_ARGUMENT 4
#define MACH_KERN_FAILURE 5
#define MACH_KERN_RESOURCE_SHORTAGE 6
#define MACH_KERN_NOT_RECEIVER 7
#define MACH_KERN_NO_ACCESS 8
#define MACH_KERN_MEMORY_FAILURE 9
#define MACH_KERN_MEMORY_ERROR 10
#define MACH_KERN_ALREADY_IN_SET 11
#define MACH_KERN_NOT_IN_SET 12
#define MACH_KERN_NAME_EXISTS 13
#define MACH_KERN_ABORTED 14
#define MACH_KERN_INVALID_NAME 15
#define MACH_KERN_INVALID_TASK 16
#define MACH_KERN_INVALID_RIGHT 17
#define MACH_KERN_INVALID_VALUE 18
#define MACH_KERN_UREFS_OVERFLOW 19
#define MACH_KERN_INVALID_CAPABILITY 20
#define MACH_KERN_RIGHT_EXISTS 21
#define MACH_KERN_INVALID_HOST 22
#define MACH_KERN_MEMORY_PRESENT 23
#define MACH_KERN_MEMORY_DATA_MOVED 24
#define MACH_KERN_MEMORY_RESTART_COPY 25
#define MACH_KERN_INVALID_PROCESSOR_SET 26
#define MACH_KERN_POLICY_LIMIT 27
#define MACH_KERN_INVALID_POLICY 28
#define MACH_KERN_INVALID_OBJECT 29
#define MACH_KERN_ALREADY_WAITING 30
#define MACH_KERN_DEFAULT_SET 31
#define MACH_KERN_EXCEPTION_PROTECTED 32
#define MACH_KERN_INVALID_LEDGER 33
#define MACH_KERN_INVALID_MEMORY_CONTROL 34
#define MACH_KERN_INVALID_SECURITY 35
#define MACH_KERN_NOT_DEPRESSED 36
#define MACH_KERN_TERMINATED 37
#define MACH_KERN_LOCK_SET_DESTROYED 38
#define MACH_KERN_LOCK_UNSTABLE 39
#define MACH_KERN_LOCK_OWNED 40
#define MACH_KERN_LOCK_OWNED_SELF 41
#define MACH_KERN_SEMAPHORE_DESTROYED 42
#define MACH_KERN_RPC_SERVER_TERMINATED 43
#define MACH_KERN_RPC_TERMINATE_ORPHAN 44
#define MACH_KERN_RPC_CONTINUE_ORPHAN 45
#define MACH_KERN_NOT_SUPPORTED 46
#define MACH_KERN_NODE_DOWN 47
#define MACH_KERN_NOT_WAITING 48
#define MACH_KERN_OPERATION_TIMED_OUT 49
#endif /* _MACH_ERRNO_H_ */

View File

@ -1,4 +1,4 @@
/* $NetBSD: mach_host.c,v 1.4 2002/11/10 22:05:35 manu Exp $ */
/* $NetBSD: mach_host.c,v 1.5 2002/11/11 01:18:44 manu Exp $ */
/*-
* Copyright (c) 2002 The NetBSD Foundation, Inc.
@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: mach_host.c,v 1.4 2002/11/10 22:05:35 manu Exp $");
__KERNEL_RCSID(0, "$NetBSD: mach_host.c,v 1.5 2002/11/11 01:18:44 manu Exp $");
#include <sys/types.h>
#include <sys/malloc.h>
@ -51,6 +51,7 @@ __KERNEL_RCSID(0, "$NetBSD: mach_host.c,v 1.4 2002/11/10 22:05:35 manu Exp $");
#include <compat/mach/mach_types.h>
#include <compat/mach/mach_host.h>
#include <compat/mach/mach_errno.h>
int
mach_host_info(p, msgh)
@ -58,25 +59,25 @@ mach_host_info(p, msgh)
mach_msg_header_t *msgh;
{
mach_host_info_request_t req;
mach_host_info_reply_t *rep = NULL;
size_t msglen;
mach_host_info_reply_t rep;
int error;
if ((error = copyin(msgh, &req, sizeof(req))) != 0)
return error;
bzero(&rep, sizeof(rep));
rep.rep_msgh.msgh_size = sizeof(rep);
rep.rep_msgh.msgh_local_port = req.req_msgh.msgh_local_port;
rep.rep_msgh.msgh_id = req.req_msgh.msgh_id + 100;
switch(req.req_flavor) {
case MACH_HOST_BASIC_INFO: {
struct mach_host_basic_info *info;
msglen = sizeof(mach_host_info_reply_t);
rep = (mach_host_info_reply_t *)malloc(msglen,
M_TEMP, M_ZERO|M_WAITOK);
rep->rep_msgh.msgh_bits = 0x1200; /* XXX why? */
rep->rep_msgh.msgh_local_port = req.req_msgh.msgh_local_port;
rep->rep_msgh.msgh_id = req.req_msgh.msgh_id + 100;
rep.rep_msgh.msgh_bits = 0x1200; /* XXX why? */
info = (struct mach_host_basic_info *)&rep->rep_data[0];
info = (struct mach_host_basic_info *)&rep.rep_data[0];
info->max_cpus = 1; /* XXX fill this accurately */
info->avail_cpus = 1;
info->memory_size = uvmexp.active + uvmexp.inactive;
@ -86,12 +87,8 @@ mach_host_info(p, msgh)
}
case MACH_HOST_MACH_MSG_TRAP:
msglen = sizeof(mach_host_info_reply_t);
rep = (mach_host_info_reply_t *)malloc(msglen,
M_TEMP, M_ZERO|M_WAITOK);
rep->rep_msgh.msgh_bits = 0x1200; /* XXX why? */
rep->rep_msgh.msgh_local_port = req.req_msgh.msgh_local_port;
rep->rep_msgh.msgh_id = req.req_msgh.msgh_id + 100;
rep.rep_msgh.msgh_bits = 0x1200; /* XXX why? */
rep.rep_msgh.msgh_size = 0x28; /* only headers, no data */
break;
case MACH_HOST_SCHED_INFO:
@ -101,11 +98,11 @@ mach_host_info(p, msgh)
DPRINTF(("unimplemented host_info flavor %d\n",
req.req_flavor));
default:
return EINVAL;
rep.rep_retval = native_to_mach_errno[EINVAL];
break;
}
if (rep != NULL && (error = copyout(rep, msgh, msglen)) != 0)
if ((error = copyout(&rep, msgh, rep.rep_msgh.msgh_size)) != 0)
return error;
return 0;
@ -121,7 +118,11 @@ mach_host_page_size(p, msgh)
mach_host_page_size_reply_t rep;
int error;
if ((error = copyin(msgh, &req, sizeof(req))) != 0)
return error;
bzero(&rep, sizeof(rep));
rep.rep_msgh.msgh_bits = 0x1200; /* XXX why? */
rep.rep_msgh.msgh_size = sizeof(rep);
rep.rep_msgh.msgh_local_port = req.req_msgh.msgh_local_port;

View File

@ -1,4 +1,4 @@
/* $NetBSD: mach_vm.c,v 1.2 2002/11/10 22:05:36 manu Exp $ */
/* $NetBSD: mach_vm.c,v 1.3 2002/11/11 01:18:44 manu Exp $ */
/*-
* Copyright (c) 2002 The NetBSD Foundation, Inc.
@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: mach_vm.c,v 1.2 2002/11/10 22:05:36 manu Exp $");
__KERNEL_RCSID(0, "$NetBSD: mach_vm.c,v 1.3 2002/11/11 01:18:44 manu Exp $");
#include <sys/types.h>
#include <sys/param.h>
@ -49,6 +49,7 @@ __KERNEL_RCSID(0, "$NetBSD: mach_vm.c,v 1.2 2002/11/10 22:05:36 manu Exp $");
#include <compat/mach/mach_types.h>
#include <compat/mach/mach_message.h>
#include <compat/mach/mach_vm.h>
#include <compat/mach/mach_errno.h>
#include <compat/mach/mach_syscallargs.h>
int
@ -74,7 +75,7 @@ mach_vm_map(p, msgh)
SCARG(&cup, pos) = (off_t)req.req_offset;
if ((error = sys_mmap(p, &cup, &rep.rep_retval)) != 0)
return error;
rep.rep_retval = native_to_mach_errno[error];
rep.rep_msgh.msgh_bits = 0x1200; /* XXX why? */
rep.rep_msgh.msgh_size = sizeof(rep);
@ -107,7 +108,7 @@ mach_vm_deallocate(p, msgh)
SCARG(&cup, len) = req.req_size;
if ((error = sys_munmap(p, &cup, &rep.rep_retval)) != 0)
return error;
rep.rep_retval = native_to_mach_errno[error];
rep.rep_msgh.msgh_bits = 0x1200; /* XXX why? */
rep.rep_msgh.msgh_size = sizeof(rep);