linux_util.c (38f1b189cd839bd8aa122ae06cc084810ca1e395) | linux_util.c (19e252baebe7a7466b33c27560420b7d95fe294d) |
---|---|
1/*- 2 * Copyright (c) 1994 Christos Zoulas 3 * Copyright (c) 1995 Frank van der Linden 4 * Copyright (c) 1995 Scott Bartram 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions --- 19 unchanged lines hidden (view full) --- 28 * 29 * from: svr4_util.c,v 1.5 1995/01/22 23:44:50 christos Exp 30 */ 31 32#include <sys/cdefs.h> 33__FBSDID("$FreeBSD$"); 34 35#include "opt_compat.h" | 1/*- 2 * Copyright (c) 1994 Christos Zoulas 3 * Copyright (c) 1995 Frank van der Linden 4 * Copyright (c) 1995 Scott Bartram 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions --- 19 unchanged lines hidden (view full) --- 28 * 29 * from: svr4_util.c,v 1.5 1995/01/22 23:44:50 christos Exp 30 */ 31 32#include <sys/cdefs.h> 33__FBSDID("$FreeBSD$"); 34 35#include "opt_compat.h" |
36#include "opt_kdtrace.h" |
|
36 37#include <sys/param.h> 38#include <sys/bus.h> 39#include <sys/fcntl.h> 40#include <sys/lock.h> 41#include <sys/malloc.h> | 37 38#include <sys/param.h> 39#include <sys/bus.h> 40#include <sys/fcntl.h> 41#include <sys/lock.h> 42#include <sys/malloc.h> |
43#include <sys/kernel.h> |
|
42#include <sys/linker_set.h> 43#include <sys/mutex.h> 44#include <sys/namei.h> 45#include <sys/proc.h> | 44#include <sys/linker_set.h> 45#include <sys/mutex.h> 46#include <sys/namei.h> 47#include <sys/proc.h> |
48#include <sys/sdt.h> |
|
46#include <sys/syscallsubr.h> 47#include <sys/systm.h> 48#include <sys/vnode.h> 49 50#include <machine/stdarg.h> 51 52#include <compat/linux/linux_util.h> 53#ifdef COMPAT_LINUX32 54#include <machine/../linux32/linux.h> 55#else 56#include <machine/../linux/linux.h> 57#endif 58 | 49#include <sys/syscallsubr.h> 50#include <sys/systm.h> 51#include <sys/vnode.h> 52 53#include <machine/stdarg.h> 54 55#include <compat/linux/linux_util.h> 56#ifdef COMPAT_LINUX32 57#include <machine/../linux32/linux.h> 58#else 59#include <machine/../linux/linux.h> 60#endif 61 |
62#include <compat/linux/linux_dtrace.h> 63 |
|
59const char linux_emul_path[] = "/compat/linux"; 60 | 64const char linux_emul_path[] = "/compat/linux"; 65 |
66/* DTrace init */ 67LIN_SDT_PROVIDER_DECLARE(LINUX_DTRACE); 68 69/** 70 * DTrace probes in this module. 71 */ 72LIN_SDT_PROBE_DEFINE5(util, linux_emul_convpath, entry, "const char *", 73 "enum uio_seg", "char **", "int", "int"); 74LIN_SDT_PROBE_DEFINE1(util, linux_emul_convpath, return, "int"); 75LIN_SDT_PROBE_DEFINE1(util, linux_msg, entry, "const char *"); 76LIN_SDT_PROBE_DEFINE0(util, linux_msg, return); 77LIN_SDT_PROBE_DEFINE2(util, linux_driver_get_name_dev, entry, "device_t", 78 "const char *"); 79LIN_SDT_PROBE_DEFINE0(util, linux_driver_get_name_dev, nullcall); 80LIN_SDT_PROBE_DEFINE1(util, linux_driver_get_name_dev, return, "char *"); 81LIN_SDT_PROBE_DEFINE3(util, linux_driver_get_major_minor, entry, "char *", 82 "int *", "int *"); 83LIN_SDT_PROBE_DEFINE0(util, linux_driver_get_major_minor, nullcall); 84LIN_SDT_PROBE_DEFINE1(util, linux_driver_get_major_minor, notfound, "char *"); 85LIN_SDT_PROBE_DEFINE3(util, linux_driver_get_major_minor, return, "int", 86 "int", "int"); 87LIN_SDT_PROBE_DEFINE0(util, linux_get_char_devices, entry); 88LIN_SDT_PROBE_DEFINE1(util, linux_get_char_devices, return, "char *"); 89LIN_SDT_PROBE_DEFINE1(util, linux_free_get_char_devices, entry, "char *"); 90LIN_SDT_PROBE_DEFINE0(util, linux_free_get_char_devices, return); 91LIN_SDT_PROBE_DEFINE1(util, linux_device_register_handler, entry, 92 "struct linux_device_handler *"); 93LIN_SDT_PROBE_DEFINE1(util, linux_device_register_handler, return, "int"); 94LIN_SDT_PROBE_DEFINE1(util, linux_device_unregister_handler, entry, 95 "struct linux_device_handler *"); 96LIN_SDT_PROBE_DEFINE1(util, linux_device_unregister_handler, return, "int"); 97 |
|
61/* 62 * Search an alternate path before passing pathname arguments on to 63 * system calls. Useful for keeping a separate 'emulation tree'. 64 * 65 * If cflag is set, we check if an attempt can be made to create the 66 * named file, i.e. we check if the directory it should be in exists. 67 */ 68int | 98/* 99 * Search an alternate path before passing pathname arguments on to 100 * system calls. Useful for keeping a separate 'emulation tree'. 101 * 102 * If cflag is set, we check if an attempt can be made to create the 103 * named file, i.e. we check if the directory it should be in exists. 104 */ 105int |
69linux_emul_convpath(td, path, pathseg, pbuf, cflag, dfd) 70 struct thread *td; 71 const char *path; 72 enum uio_seg pathseg; 73 char **pbuf; 74 int cflag; 75 int dfd; | 106linux_emul_convpath(struct thread *td, const char *path, enum uio_seg pathseg, 107 char **pbuf, int cflag, int dfd) |
76{ | 108{ |
109 int retval; |
|
77 | 110 |
78 return (kern_alternate_path(td, linux_emul_path, path, pathseg, pbuf, 79 cflag, dfd)); | 111 LIN_SDT_PROBE5(util, linux_emul_convpath, entry, path, pathseg, pbuf, 112 cflag, dfd); 113 114 retval = kern_alternate_path(td, linux_emul_path, path, pathseg, pbuf, 115 cflag, dfd); 116 117 LIN_SDT_PROBE1(util, linux_emul_convpath, return, retval); 118 return (retval); |
80} 81 82void 83linux_msg(const struct thread *td, const char *fmt, ...) 84{ 85 va_list ap; 86 struct proc *p; 87 | 119} 120 121void 122linux_msg(const struct thread *td, const char *fmt, ...) 123{ 124 va_list ap; 125 struct proc *p; 126 |
127 LIN_SDT_PROBE1(util, linux_msg, entry, fmt); 128 |
|
88 p = td->td_proc; 89 printf("linux: pid %d (%s): ", (int)p->p_pid, p->p_comm); 90 va_start(ap, fmt); 91 vprintf(fmt, ap); 92 va_end(ap); 93 printf("\n"); | 129 p = td->td_proc; 130 printf("linux: pid %d (%s): ", (int)p->p_pid, p->p_comm); 131 va_start(ap, fmt); 132 vprintf(fmt, ap); 133 va_end(ap); 134 printf("\n"); |
135 136 LIN_SDT_PROBE0(util, linux_msg, return); |
|
94} 95 96struct device_element 97{ 98 TAILQ_ENTRY(device_element) list; 99 struct linux_device_handler entry; 100}; 101 --- 6 unchanged lines hidden (view full) --- 108DATA_SET(linux_device_handler_set, null_handler); 109 110char * 111linux_driver_get_name_dev(device_t dev) 112{ 113 struct device_element *de; 114 const char *device_name = device_get_name(dev); 115 | 137} 138 139struct device_element 140{ 141 TAILQ_ENTRY(device_element) list; 142 struct linux_device_handler entry; 143}; 144 --- 6 unchanged lines hidden (view full) --- 151DATA_SET(linux_device_handler_set, null_handler); 152 153char * 154linux_driver_get_name_dev(device_t dev) 155{ 156 struct device_element *de; 157 const char *device_name = device_get_name(dev); 158 |
116 if (device_name == NULL) | 159 LIN_SDT_PROBE2(util, linux_driver_get_name_dev, entry, dev, 160 device_name); 161 162 if (device_name == NULL) { 163 LIN_SDT_PROBE0(util, linux_driver_get_name_dev, nullcall); 164 LIN_SDT_PROBE1(util, linux_driver_get_name_dev, return, NULL); |
117 return NULL; | 165 return NULL; |
166 } |
|
118 TAILQ_FOREACH(de, &devices, list) { | 167 TAILQ_FOREACH(de, &devices, list) { |
119 if (strcmp(device_name, de->entry.bsd_driver_name) == 0) | 168 if (strcmp(device_name, de->entry.bsd_driver_name) == 0) { 169 LIN_SDT_PROBE1(util, linux_driver_get_name_dev, return, 170 de->entry.linux_driver_name); |
120 return (de->entry.linux_driver_name); | 171 return (de->entry.linux_driver_name); |
172 } |
|
121 } 122 | 173 } 174 |
175 LIN_SDT_PROBE1(util, linux_driver_get_name_dev, return, NULL); |
|
123 return NULL; 124} 125 126int 127linux_driver_get_major_minor(const char *node, int *major, int *minor) 128{ 129 struct device_element *de; 130 | 176 return NULL; 177} 178 179int 180linux_driver_get_major_minor(const char *node, int *major, int *minor) 181{ 182 struct device_element *de; 183 |
131 if (node == NULL || major == NULL || minor == NULL) | 184 LIN_SDT_PROBE3(util, linux_driver_get_major_minor, entry, node, major, 185 minor); 186 187 if (node == NULL || major == NULL || minor == NULL) { 188 LIN_SDT_PROBE0(util, linux_driver_get_major_minor, nullcall); 189 LIN_SDT_PROBE3(util, linux_driver_get_major_minor, return, 1, 190 0, 0); |
132 return 1; | 191 return 1; |
192 } |
|
133 134 if (strlen(node) > strlen("pts/") && 135 strncmp(node, "pts/", strlen("pts/")) == 0) { 136 unsigned long devno; 137 138 /* 139 * Linux checks major and minors of the slave device 140 * to make sure it's a pty device, so let's make him 141 * believe it is. 142 */ 143 devno = strtoul(node + strlen("pts/"), NULL, 10); 144 *major = 136 + (devno / 256); 145 *minor = devno % 256; | 193 194 if (strlen(node) > strlen("pts/") && 195 strncmp(node, "pts/", strlen("pts/")) == 0) { 196 unsigned long devno; 197 198 /* 199 * Linux checks major and minors of the slave device 200 * to make sure it's a pty device, so let's make him 201 * believe it is. 202 */ 203 devno = strtoul(node + strlen("pts/"), NULL, 10); 204 *major = 136 + (devno / 256); 205 *minor = devno % 256; |
206 207 LIN_SDT_PROBE3(util, linux_driver_get_major_minor, return, 0, 208 *major, *minor); |
|
146 return 0; 147 } 148 149 TAILQ_FOREACH(de, &devices, list) { 150 if (strcmp(node, de->entry.bsd_device_name) == 0) { 151 *major = de->entry.linux_major; 152 *minor = de->entry.linux_minor; | 209 return 0; 210 } 211 212 TAILQ_FOREACH(de, &devices, list) { 213 if (strcmp(node, de->entry.bsd_device_name) == 0) { 214 *major = de->entry.linux_major; 215 *minor = de->entry.linux_minor; |
216 217 LIN_SDT_PROBE3(util, linux_driver_get_major_minor, 218 return, 0, *major, *minor); |
|
153 return 0; 154 } 155 } 156 | 219 return 0; 220 } 221 } 222 |
223 LIN_SDT_PROBE1(util, linux_driver_get_major_minor, notfound, node); 224 LIN_SDT_PROBE3(util, linux_driver_get_major_minor, return, 1, 0, 0); |
|
157 return 1; 158} 159 160char * 161linux_get_char_devices() 162{ 163 struct device_element *de; 164 char *temp, *string, *last; 165 char formated[256]; 166 int current_size = 0, string_size = 1024; 167 | 225 return 1; 226} 227 228char * 229linux_get_char_devices() 230{ 231 struct device_element *de; 232 char *temp, *string, *last; 233 char formated[256]; 234 int current_size = 0, string_size = 1024; 235 |
236 LIN_SDT_PROBE0(util, linux_get_char_devices, entry); 237 |
|
168 string = malloc(string_size, M_LINUX, M_WAITOK); 169 string[0] = '\000'; 170 last = ""; 171 TAILQ_FOREACH(de, &devices, list) { 172 if (!de->entry.linux_char_device) 173 continue; 174 temp = string; 175 if (strcmp(last, de->entry.bsd_driver_name) != 0) { --- 10 unchanged lines hidden (view full) --- 186 bcopy(temp, string, current_size); 187 free(temp, M_LINUX); 188 } 189 strcat(string, formated); 190 current_size = strlen(string); 191 } 192 } 193 | 238 string = malloc(string_size, M_LINUX, M_WAITOK); 239 string[0] = '\000'; 240 last = ""; 241 TAILQ_FOREACH(de, &devices, list) { 242 if (!de->entry.linux_char_device) 243 continue; 244 temp = string; 245 if (strcmp(last, de->entry.bsd_driver_name) != 0) { --- 10 unchanged lines hidden (view full) --- 256 bcopy(temp, string, current_size); 257 free(temp, M_LINUX); 258 } 259 strcat(string, formated); 260 current_size = strlen(string); 261 } 262 } 263 |
264 LIN_SDT_PROBE1(util, linux_get_char_devices, return, string); |
|
194 return string; 195} 196 197void 198linux_free_get_char_devices(char *string) 199{ | 265 return string; 266} 267 268void 269linux_free_get_char_devices(char *string) 270{ |
271 272 LIN_SDT_PROBE1(util, linux_get_char_devices, entry, string); 273 |
|
200 free(string, M_LINUX); | 274 free(string, M_LINUX); |
275 276 LIN_SDT_PROBE0(util, linux_get_char_devices, return); |
|
201} 202 203static int linux_major_starting = 200; 204 205int 206linux_device_register_handler(struct linux_device_handler *d) 207{ 208 struct device_element *de; 209 | 277} 278 279static int linux_major_starting = 200; 280 281int 282linux_device_register_handler(struct linux_device_handler *d) 283{ 284 struct device_element *de; 285 |
210 if (d == NULL) | 286 LIN_SDT_PROBE1(util, linux_device_register_handler, entry, d); 287 288 if (d == NULL) { 289 LIN_SDT_PROBE1(util, linux_device_register_handler, return, 290 EINVAL); |
211 return (EINVAL); | 291 return (EINVAL); |
292 } |
|
212 | 293 |
213 de = malloc(sizeof(*de), 214 M_LINUX, M_WAITOK); | 294 de = malloc(sizeof(*de), M_LINUX, M_WAITOK); |
215 if (d->linux_major < 0) { 216 d->linux_major = linux_major_starting++; 217 } 218 bcopy(d, &de->entry, sizeof(*d)); 219 220 /* Add the element to the list, sorted on span. */ 221 TAILQ_INSERT_TAIL(&devices, de, list); 222 | 295 if (d->linux_major < 0) { 296 d->linux_major = linux_major_starting++; 297 } 298 bcopy(d, &de->entry, sizeof(*d)); 299 300 /* Add the element to the list, sorted on span. */ 301 TAILQ_INSERT_TAIL(&devices, de, list); 302 |
303 LIN_SDT_PROBE1(util, linux_device_register_handler, return, 0); |
|
223 return (0); 224} 225 226int 227linux_device_unregister_handler(struct linux_device_handler *d) 228{ 229 struct device_element *de; 230 | 304 return (0); 305} 306 307int 308linux_device_unregister_handler(struct linux_device_handler *d) 309{ 310 struct device_element *de; 311 |
231 if (d == NULL) | 312 LIN_SDT_PROBE1(util, linux_device_unregister_handler, entry, d); 313 314 if (d == NULL) { 315 LIN_SDT_PROBE1(util, linux_device_unregister_handler, return, 316 EINVAL); |
232 return (EINVAL); | 317 return (EINVAL); |
318 } |
|
233 234 TAILQ_FOREACH(de, &devices, list) { 235 if (bcmp(d, &de->entry, sizeof(*d)) == 0) { 236 TAILQ_REMOVE(&devices, de, list); 237 free(de, M_LINUX); | 319 320 TAILQ_FOREACH(de, &devices, list) { 321 if (bcmp(d, &de->entry, sizeof(*d)) == 0) { 322 TAILQ_REMOVE(&devices, de, list); 323 free(de, M_LINUX); |
324 325 LIN_SDT_PROBE1(util, linux_device_unregister_handler, 326 return, 0); |
|
238 return (0); 239 } 240 } 241 | 327 return (0); 328 } 329 } 330 |
331 LIN_SDT_PROBE1(util, linux_device_unregister_handler, return, EINVAL); |
|
242 return (EINVAL); 243} | 332 return (EINVAL); 333} |