Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/compat/mach Added vm_region_64 and thread_info



details:   https://anonhg.NetBSD.org/src/rev/ebd518012083
branches:  trunk
changeset: 551467:ebd518012083
user:      manu <manu%NetBSD.org@localhost>
date:      Sat Sep 06 23:52:25 2003 +0000

description:
Added vm_region_64 and thread_info

diffstat:

 sys/compat/mach/mach_thread.c |  97 ++++++++++++++++++++++++++++++++++++++++++-
 sys/compat/mach/mach_thread.h |  59 +++++++++++++++++++++++++-
 sys/compat/mach/mach_types.h  |   3 +-
 sys/compat/mach/mach_vm.c     |  63 +++++++++++++++++++++++++++-
 sys/compat/mach/mach_vm.h     |  37 +++++++++++++++-
 5 files changed, 252 insertions(+), 7 deletions(-)

diffs (truncated from 364 to 300 lines):

diff -r 7e7f5839939b -r ebd518012083 sys/compat/mach/mach_thread.c
--- a/sys/compat/mach/mach_thread.c     Sat Sep 06 23:52:24 2003 +0000
+++ b/sys/compat/mach/mach_thread.c     Sat Sep 06 23:52:25 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mach_thread.c,v 1.18 2003/01/30 19:14:19 manu Exp $ */
+/*     $NetBSD: mach_thread.c,v 1.19 2003/09/06 23:52:25 manu Exp $ */
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mach_thread.c,v 1.18 2003/01/30 19:14:19 manu Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mach_thread.c,v 1.19 2003/09/06 23:52:25 manu Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -191,3 +191,96 @@
        *msglen = sizeof(*rep);
        return 0;
 }
+
+int 
+mach_thread_info(args)
+       struct mach_trap_args *args;
+{
+       mach_thread_info_request_t *req = args->smsg;
+       mach_thread_info_reply_t *rep = args->rmsg;
+       size_t *msglen = args->rsize;
+       struct lwp *l = args->l;
+       struct proc *p = l->l_proc;
+
+
+       rep->rep_msgh.msgh_bits =
+           MACH_MSGH_REPLY_LOCAL_BITS(MACH_MSG_TYPE_MOVE_SEND_ONCE);
+       rep->rep_msgh.msgh_size = sizeof(*rep) - sizeof(rep->rep_trailer);
+       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_THREAD_BASIC_INFO: {
+               struct mach_thread_basic_info *tbi;
+
+               if (req->req_count != (sizeof(*tbi) / sizeof(int))) /* 10 */
+                       return mach_msg_error(args, EINVAL);
+
+               tbi = (struct mach_thread_basic_info *)rep->rep_out;
+               tbi->user_time.seconds = p->p_uticks * hz / 1000000;
+               tbi->user_time.microseconds = 
+                   (p->p_uticks) * hz - tbi->user_time.seconds;
+               tbi->system_time.seconds = p->p_sticks * hz / 1000000;
+               tbi->system_time.microseconds = 
+                   (p->p_sticks) * hz - tbi->system_time.seconds;
+               tbi->cpu_usage = p->p_pctcpu;
+               tbi->policy = MACH_THREAD_STANDARD_POLICY;
+
+               /* XXX this is not very accurate */
+               tbi->run_state = MACH_TH_STATE_RUNNING;
+               tbi->flags = 0;
+               switch (l->l_stat) {
+               case LSRUN:
+                       tbi->run_state = MACH_TH_STATE_RUNNING;
+                       break;
+               case LSSTOP:
+                       tbi->run_state = MACH_TH_STATE_STOPPED;
+                       break;
+               case LSSLEEP:
+                       tbi->run_state = MACH_TH_STATE_WAITING;
+                       break;
+               case LSIDL:
+                       tbi->run_state = MACH_TH_STATE_RUNNING;
+                       tbi->flags = MACH_TH_FLAGS_IDLE;
+                       break;
+               default:
+                       break;
+               }
+
+               tbi->suspend_count = l->l_swtime;
+               tbi->sleep_time = l->l_slptime;
+               break;
+       }
+
+       case MACH_THREAD_SCHED_TIMESHARE_INFO: {
+               struct mach_policy_timeshare_info *pti;
+
+               if (req->req_count != (sizeof(*pti) / sizeof(int))) /* 5 */
+                       return mach_msg_error(args, EINVAL);
+
+               pti = (struct mach_policy_timeshare_info *)rep->rep_out;
+
+               pti->max_priority = l->l_usrpri;
+               pti->base_priority = l->l_usrpri;
+               pti->cur_priority = l->l_usrpri;
+               pti->depressed = 0;
+               pti->depress_priority = l->l_usrpri;
+               break;
+       }
+
+       case MACH_THREAD_SCHED_RR_INFO:
+       case MACH_THREAD_SCHED_FIFO_INFO:
+               printf("Unimplemented thread_info flavor %d\n", 
+                   req->req_flavor);
+       default:
+               return mach_msg_error(args, EINVAL);
+               break;
+       }
+
+       rep->rep_count = req->req_count;
+       rep->rep_out[rep->rep_count + 1] = 8; /* This is the trailer */
+
+       *msglen = sizeof(*rep) + ((req->req_count - 12) * sizeof(int));
+
+       return 0;
+}
diff -r 7e7f5839939b -r ebd518012083 sys/compat/mach/mach_thread.h
--- a/sys/compat/mach/mach_thread.h     Sat Sep 06 23:52:24 2003 +0000
+++ b/sys/compat/mach/mach_thread.h     Sat Sep 06 23:52:25 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mach_thread.h,v 1.9 2003/04/05 21:18:02 manu Exp $ */
+/*     $NetBSD: mach_thread.h,v 1.10 2003/09/06 23:52:25 manu Exp $ */
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -62,6 +62,44 @@
 #define MACH_SWITCH_OPTION_WAIT        2
 #define MACH_SWITCH_OPTION_IDLE        3
 
+/* For mach_thread_info */
+#define MACH_THREAD_BASIC_INFO 3
+struct mach_thread_basic_info {
+       mach_time_value_t       user_time;
+       mach_time_value_t       system_time;
+       mach_integer_t  cpu_usage;
+       mach_policy_t   policy;
+       mach_integer_t  run_state;
+       mach_integer_t  flags;
+       mach_integer_t  suspend_count;
+       mach_integer_t  sleep_time;
+};
+#define MACH_TH_STATE_RUNNING          1
+#define MACH_TH_STATE_STOPPED          2
+#define MACH_TH_STATE_WAITING          3
+#define MACH_TH_STATE_UNINTERRUPTIBLE  4
+#define MACH_TH_STATE_HALTED           5
+
+#define MACH_TH_FLAGS_SWAPPED  1
+#define MACH_TH_FLAGS_IDLE     2
+
+#define MACH_THREAD_SCHED_TIMESHARE_INFO 10
+struct mach_policy_timeshare_info {
+       mach_integer_t max_priority;
+       mach_integer_t base_priority;
+       mach_integer_t cur_priority;
+       mach_boolean_t depressed;
+       mach_integer_t depress_priority;
+};
+
+#define MACH_THREAD_SCHED_RR_INFO      11
+#define MACH_THREAD_SCHED_FIFO_INFO    12
+
+/* For mach_policy_t */
+#define MACH_THREAD_STANDARD_POLICY    1 
+#define MACH_THREAD_TIME_CONSTRAINT_POLICY 2 
+#define MACH_THREAD_PRECEDENCE_POLICY  3
+
 /* thread_policy */
 
 typedef struct {
@@ -96,9 +134,28 @@
        mach_msg_port_descriptor_t rep_child_act;
        mach_msg_trailer_t rep_trailer;
 } mach_thread_create_running_reply_t;
+
+/* mach_thread_info */
+
+typedef struct {
+       mach_msg_header_t req_msgh;
+       mach_ndr_record_t req_ndr;
+       mach_thread_flavor_t req_flavor;
+       mach_msg_type_number_t req_count;
+} mach_thread_info_request_t;
        
+typedef struct {
+       mach_msg_header_t rep_msgh;
+       mach_ndr_record_t rep_ndr;
+       mach_kern_return_t rep_retval;
+       mach_msg_type_number_t rep_count;
+       mach_integer_t rep_out[12];
+       mach_msg_trailer_t rep_trailer;
+} mach_thread_info_reply_t;
+
 int mach_thread_policy(struct mach_trap_args *);
 int mach_thread_create_running(struct mach_trap_args *);
+int mach_thread_info(struct mach_trap_args *);
 void mach_create_thread_child(void *);
 
 #endif /* _MACH_THREAD_H_ */
diff -r 7e7f5839939b -r ebd518012083 sys/compat/mach/mach_types.h
--- a/sys/compat/mach/mach_types.h      Sat Sep 06 23:52:24 2003 +0000
+++ b/sys/compat/mach/mach_types.h      Sat Sep 06 23:52:25 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mach_types.h,v 1.14 2003/04/05 21:18:02 manu Exp $      */
+/*     $NetBSD: mach_types.h,v 1.15 2003/09/06 23:52:26 manu Exp $      */
 
 /*-
  * Copyright (c) 2001-2003 The NetBSD Foundation, Inc.
@@ -71,6 +71,7 @@
 typedef mach_natural_t mach_port_msgcount_t;
 typedef mach_natural_t mach_port_rights_t;
 typedef mach_natural_t mach_task_flavor_t;
+typedef mach_natural_t mach_thread_flavor_t;
 typedef int mach_policy_t;
 
 
diff -r 7e7f5839939b -r ebd518012083 sys/compat/mach/mach_vm.c
--- a/sys/compat/mach/mach_vm.c Sat Sep 06 23:52:24 2003 +0000
+++ b/sys/compat/mach/mach_vm.c Sat Sep 06 23:52:25 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mach_vm.c,v 1.30 2003/06/29 22:29:35 fvdl Exp $ */
+/*     $NetBSD: mach_vm.c,v 1.31 2003/09/06 23:52:27 manu Exp $ */
 
 /*-
  * Copyright (c) 2002-2003 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mach_vm.c,v 1.30 2003/06/29 22:29:35 fvdl Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mach_vm.c,v 1.31 2003/09/06 23:52:27 manu Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -561,6 +561,65 @@
 }
 
 int
+mach_vm_region_64(args) 
+       struct mach_trap_args *args;
+{
+       mach_vm_region_64_request_t *req = args->smsg;
+       mach_vm_region_64_reply_t *rep = args->rmsg;
+       size_t *msglen = args->rsize;
+       struct lwp *l = args->l;
+       struct mach_vm_region_basic_info_64 *rbi;
+       struct vm_map_entry *vme;
+       
+       /* 
+        * MACH_VM_REGION_BASIC_INFO is the only 
+        * supported flavor in Darwin.
+        */
+       if (req->req_flavor != MACH_VM_REGION_BASIC_INFO) 
+               return mach_msg_error(args, EINVAL);
+       if (req->req_count != (sizeof(*rbi) / sizeof(int))) /* This is 8 */
+               return mach_msg_error(args, EINVAL);
+       *msglen = sizeof(*rep) + ((req->req_count - 9) * sizeof(int));
+
+       vme = uvm_map_findspace(&l->l_proc->p_vmspace->vm_map, 
+                           req->req_addr, 1, (vaddr_t *)&rep->rep_addr, 
+                           NULL, 0, 0, UVM_FLAG_FIXED);
+       if (vme == NULL)
+               return mach_msg_error(args, ENOMEM);
+
+       rep->rep_msgh.msgh_bits =
+           MACH_MSGH_REPLY_LOCAL_BITS(MACH_MSG_TYPE_MOVE_SEND_ONCE) |
+           MACH_MSGH_BITS_COMPLEX;
+       rep->rep_msgh.msgh_size = *msglen - sizeof(rep->rep_trailer);
+       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_body.msgh_descriptor_count = 1;
+       rep->rep_obj.address = NULL;
+       rep->rep_obj.size = 0;
+       rep->rep_obj.deallocate = 0;
+       rep->rep_obj.copy = 0; 
+       rep->rep_obj.pad1 = 0x11; 
+       rep->rep_obj.type = 0;
+       rep->rep_size = PAGE_SIZE; /* XXX Why? */
+       rep->rep_count = req->req_count;
+
+       rbi = (struct mach_vm_region_basic_info_64 *)&rep->rep_info[0];
+       rbi->protection = vme->protection;
+       rbi->inheritance = 1; /* vme->inheritance */
+       rbi->shared = 0; /* XXX how can we know? */
+       rbi->offset = vme->offset;
+       rbi->behavior = MACH_VM_BEHAVIOR_DEFAULT; /* XXX What is it? */
+       rbi->user_wired_count = vme->wired_count;
+
+       /* XXX Why this? */
+       *(short *)((u_long)&rbi->user_wired_count + sizeof(short)) = 1;
+
+       rep->rep_info[rep->rep_count + 1] = 8; /* This is the trailer */
+
+       return 0;
+}
+
+int
 mach_vm_msync(args)
        struct mach_trap_args *args;
 {
diff -r 7e7f5839939b -r ebd518012083 sys/compat/mach/mach_vm.h



Home | Main Index | Thread Index | Old Index