source: trunk/minix/kernel/system/do_getinfo.c@ 11

Last change on this file since 11 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

File size: 4.8 KB
RevLine 
[9]1/* The kernel call implemented in this file:
2 * m_type: SYS_GETINFO
3 *
4 * The parameters for this kernel call are:
5 * m1_i3: I_REQUEST (what info to get)
6 * m1_p1: I_VAL_PTR (where to put it)
7 * m1_i1: I_VAL_LEN (maximum length expected, optional)
8 * m1_p2: I_VAL_PTR2 (second, optional pointer)
9 * m1_i2: I_VAL_LEN2_E (second length or process nr)
10 */
11
12#include "../system.h"
13
14static unsigned long bios_buf[1024]; /* 4K, what about alignment */
15static vir_bytes bios_buf_vir, bios_buf_len;
16
17#if USE_GETINFO
18
19/*===========================================================================*
20 * do_getinfo *
21 *===========================================================================*/
22PUBLIC int do_getinfo(m_ptr)
23register message *m_ptr; /* pointer to request message */
24{
25/* Request system information to be copied to caller's address space. This
26 * call simply copies entire data structures to the caller.
27 */
28 size_t length;
29 phys_bytes src_phys;
30 phys_bytes dst_phys;
31 int proc_nr, nr_e, nr;
32
33 /* Set source address and length based on request type. */
34 switch (m_ptr->I_REQUEST) {
35 case GET_MACHINE: {
36 length = sizeof(struct machine);
37 src_phys = vir2phys(&machine);
38 break;
39 }
40 case GET_KINFO: {
41 length = sizeof(struct kinfo);
42 src_phys = vir2phys(&kinfo);
43 break;
44 }
45 case GET_LOADINFO: {
46 length = sizeof(struct loadinfo);
47 src_phys = vir2phys(&kloadinfo);
48 break;
49 }
50 case GET_IMAGE: {
51 length = sizeof(struct boot_image) * NR_BOOT_PROCS;
52 src_phys = vir2phys(image);
53 break;
54 }
55 case GET_IRQHOOKS: {
56 length = sizeof(struct irq_hook) * NR_IRQ_HOOKS;
57 src_phys = vir2phys(irq_hooks);
58 break;
59 }
60 case GET_SCHEDINFO: {
61 /* This is slightly complicated because we need two data structures
62 * at once, otherwise the scheduling information may be incorrect.
63 * Copy the queue heads and fall through to copy the process table.
64 */
65 length = sizeof(struct proc *) * NR_SCHED_QUEUES;
66 src_phys = vir2phys(rdy_head);
67 okendpt(m_ptr->m_source, &proc_nr);
68 dst_phys = numap_local(proc_nr, (vir_bytes) m_ptr->I_VAL_PTR2,
69 length);
70 if (src_phys == 0 || dst_phys == 0) return(EFAULT);
71 phys_copy(src_phys, dst_phys, length);
72 /* fall through */
73 }
74 case GET_PROCTAB: {
75 length = sizeof(struct proc) * (NR_PROCS + NR_TASKS);
76 src_phys = vir2phys(proc);
77 break;
78 }
79 case GET_PRIVTAB: {
80 length = sizeof(struct priv) * (NR_SYS_PROCS);
81 src_phys = vir2phys(priv);
82 break;
83 }
84 case GET_PROC: {
85 nr_e = (m_ptr->I_VAL_LEN2_E == SELF) ?
86 m_ptr->m_source : m_ptr->I_VAL_LEN2_E;
87 if(!isokendpt(nr_e, &nr)) return EINVAL; /* validate request */
88 length = sizeof(struct proc);
89 src_phys = vir2phys(proc_addr(nr));
90 break;
91 }
92 case GET_MONPARAMS: {
93 src_phys = kinfo.params_base; /* already is a physical */
94 length = kinfo.params_size;
95 break;
96 }
97 case GET_RANDOMNESS: {
98 static struct randomness copy; /* copy to keep counters */
99 int i;
100
101 copy = krandom;
102 for (i= 0; i<RANDOM_SOURCES; i++) {
103 krandom.bin[i].r_size = 0; /* invalidate random data */
104 krandom.bin[i].r_next = 0;
105 }
106 length = sizeof(struct randomness);
107 src_phys = vir2phys(&copy);
108 break;
109 }
110 case GET_KMESSAGES: {
111 length = sizeof(struct kmessages);
112 src_phys = vir2phys(&kmess);
113 break;
114 }
115#if DEBUG_TIME_LOCKS
116 case GET_LOCKTIMING: {
117 length = sizeof(timingdata);
118 src_phys = vir2phys(timingdata);
119 break;
120 }
121#endif
122 case GET_BIOSBUFFER:
123 bios_buf_vir = (vir_bytes)bios_buf;
124 bios_buf_len = sizeof(bios_buf);
125
126 length = sizeof(bios_buf_len);
127 src_phys = vir2phys(&bios_buf_len);
128 if (length != m_ptr->I_VAL_LEN2_E) return (EINVAL);
129 if(!isokendpt(m_ptr->m_source, &proc_nr))
130 panic("bogus source", m_ptr->m_source);
131 dst_phys = numap_local(proc_nr, (vir_bytes) m_ptr->I_VAL_PTR2, length);
132 if (src_phys == 0 || dst_phys == 0) return(EFAULT);
133 phys_copy(src_phys, dst_phys, length);
134
135 length = sizeof(bios_buf_vir);
136 src_phys = vir2phys(&bios_buf_vir);
137 break;
138
139 case GET_IRQACTIDS: {
140 length = sizeof(irq_actids);
141 src_phys = vir2phys(irq_actids);
142 break;
143 }
144
145 default:
146 return(EINVAL);
147 }
148
149 /* Try to make the actual copy for the requested data. */
150 if (m_ptr->I_VAL_LEN > 0 && length > m_ptr->I_VAL_LEN) return (E2BIG);
151 if(!isokendpt(m_ptr->m_source, &proc_nr))
152 panic("bogus source", m_ptr->m_source);
153 dst_phys = numap_local(proc_nr, (vir_bytes) m_ptr->I_VAL_PTR, length);
154 if (src_phys == 0 || dst_phys == 0) return(EFAULT);
155 phys_copy(src_phys, dst_phys, length);
156 return(OK);
157}
158
159#endif /* USE_GETINFO */
160
Note: See TracBrowser for help on using the repository browser.