ec2ba5d85d
- TLS - complete - pid/tid mangling - complete - thread area - complete - futexes - complete with issues - clone() extension - complete with some possible minor issues - mq*/timer*/clock* stuff - complete but untested and the mq* stuff is disabled when not build as part of the kernel with native FreeBSD mq* support (module support for this will come later) Tested with: - linux-firefox - works, tested - linux-opera - works, tested - linux-realplay - doesnt work, issue with futexes - linux-skype - doesnt work, issue with futexes - linux-rt2-demo - works, tested - linux-acroread - doesnt work, unknown reason (coredump) and sometimes issue with futexes - various unix utilities in linux-base-gentoo3 and linux-base-fc4: everything tried worked On amd64 not everything is supported like on i386, the catchup is planned for later when the remaining bugs in the new functions are fixed. To test this new stuff, you have to run sysctl compat.linux.osrelease=2.6.16 to switch back use sysctl compat.linux.osrelease=2.4.2 Don't switch while running a linux program, strange things may or may not happen. Sponsored by: Google SoC 2006 Submitted by: rdivacky Some suggestions/help by: jhb, kib, manu@NetBSD.org, netchild
227 lines
5.5 KiB
C
227 lines
5.5 KiB
C
/*-
|
|
* Copyright (c) 1994 Christos Zoulas
|
|
* Copyright (c) 1995 Frank van der Linden
|
|
* Copyright (c) 1995 Scott Bartram
|
|
* All rights reserved.
|
|
*
|
|
* 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. The name of the author may not be used to endorse or promote products
|
|
* derived from this software without specific prior written permission
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
|
*
|
|
* from: svr4_util.c,v 1.5 1995/01/22 23:44:50 christos Exp
|
|
*/
|
|
|
|
#include <sys/cdefs.h>
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
#include "opt_compat.h"
|
|
|
|
#include <sys/param.h>
|
|
#include <sys/bus.h>
|
|
#include <sys/lock.h>
|
|
#include <sys/malloc.h>
|
|
#include <sys/linker_set.h>
|
|
#include <sys/mutex.h>
|
|
#include <sys/namei.h>
|
|
#include <sys/proc.h>
|
|
#include <sys/syscallsubr.h>
|
|
#include <sys/systm.h>
|
|
#include <sys/vnode.h>
|
|
|
|
#include <machine/stdarg.h>
|
|
|
|
#include <compat/linux/linux_util.h>
|
|
#ifdef COMPAT_LINUX32
|
|
#include <machine/../linux32/linux.h>
|
|
#else
|
|
#include <machine/../linux/linux.h>
|
|
#endif
|
|
|
|
const char linux_emul_path[] = "/compat/linux";
|
|
|
|
/*
|
|
* Search an alternate path before passing pathname arguments on
|
|
* to system calls. Useful for keeping a separate 'emulation tree'.
|
|
*
|
|
* If cflag is set, we check if an attempt can be made to create
|
|
* the named file, i.e. we check if the directory it should
|
|
* be in exists.
|
|
*/
|
|
int
|
|
linux_emul_convpath(td, path, pathseg, pbuf, cflag)
|
|
struct thread *td;
|
|
char *path;
|
|
enum uio_seg pathseg;
|
|
char **pbuf;
|
|
int cflag;
|
|
{
|
|
|
|
return (kern_alternate_path(td, linux_emul_path, path, pathseg, pbuf,
|
|
cflag));
|
|
}
|
|
|
|
void
|
|
linux_msg(const struct thread *td, const char *fmt, ...)
|
|
{
|
|
va_list ap;
|
|
struct proc *p;
|
|
|
|
p = td->td_proc;
|
|
printf("linux: pid %d (%s): ", (int)p->p_pid, p->p_comm);
|
|
va_start(ap, fmt);
|
|
vprintf(fmt, ap);
|
|
va_end(ap);
|
|
printf("\n");
|
|
}
|
|
|
|
struct device_element
|
|
{
|
|
TAILQ_ENTRY(device_element) list;
|
|
struct linux_device_handler entry;
|
|
};
|
|
|
|
static TAILQ_HEAD(, device_element) devices =
|
|
TAILQ_HEAD_INITIALIZER(devices);
|
|
|
|
static struct linux_device_handler null_handler =
|
|
{ "mem", "mem", "null", "null", 1, 3, 1};
|
|
|
|
DATA_SET(linux_device_handler_set, null_handler);
|
|
|
|
char *
|
|
linux_driver_get_name_dev(device_t dev)
|
|
{
|
|
struct device_element *de;
|
|
const char *device_name = device_get_name(dev);
|
|
|
|
if (device_name == NULL)
|
|
return NULL;
|
|
TAILQ_FOREACH(de, &devices, list) {
|
|
if (strcmp(device_name, de->entry.bsd_driver_name) == 0)
|
|
return (de->entry.linux_driver_name);
|
|
}
|
|
|
|
return NULL;
|
|
}
|
|
|
|
int
|
|
linux_driver_get_major_minor(char *node, int *major, int *minor)
|
|
{
|
|
struct device_element *de;
|
|
|
|
if (node == NULL || major == NULL || minor == NULL)
|
|
return 1;
|
|
TAILQ_FOREACH(de, &devices, list) {
|
|
if (strcmp(node, de->entry.bsd_device_name) == 0) {
|
|
*major = de->entry.linux_major;
|
|
*minor = de->entry.linux_minor;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
return 1;
|
|
}
|
|
|
|
char *
|
|
linux_get_char_devices()
|
|
{
|
|
struct device_element *de;
|
|
char *temp, *string, *last;
|
|
char formated[256];
|
|
int current_size = 0, string_size = 1024;
|
|
|
|
MALLOC(string, char *, string_size, M_LINUX, M_WAITOK);
|
|
string[0] = '\000';
|
|
last = "";
|
|
TAILQ_FOREACH(de, &devices, list) {
|
|
if (!de->entry.linux_char_device)
|
|
continue;
|
|
temp = string;
|
|
if (strcmp(last, de->entry.bsd_driver_name) != 0) {
|
|
last = de->entry.bsd_driver_name;
|
|
|
|
snprintf(formated, sizeof(formated), "%3d %s\n",
|
|
de->entry.linux_major,
|
|
de->entry.linux_device_name);
|
|
if (strlen(formated) + current_size
|
|
>= string_size) {
|
|
string_size *= 2;
|
|
MALLOC(string, char *, string_size,
|
|
M_LINUX, M_WAITOK);
|
|
bcopy(temp, string, current_size);
|
|
FREE(temp, M_LINUX);
|
|
}
|
|
strcat(string, formated);
|
|
current_size = strlen(string);
|
|
}
|
|
}
|
|
|
|
return string;
|
|
}
|
|
|
|
void
|
|
linux_free_get_char_devices(char *string)
|
|
{
|
|
FREE(string, M_LINUX);
|
|
}
|
|
|
|
static int linux_major_starting = 200;
|
|
|
|
int
|
|
linux_device_register_handler(struct linux_device_handler *d)
|
|
{
|
|
struct device_element *de;
|
|
|
|
if (d == NULL)
|
|
return (EINVAL);
|
|
|
|
MALLOC(de, struct device_element *, sizeof(*de),
|
|
M_LINUX, M_WAITOK);
|
|
if (d->linux_major < 0) {
|
|
d->linux_major = linux_major_starting++;
|
|
}
|
|
bcopy(d, &de->entry, sizeof(*d));
|
|
|
|
/* Add the element to the list, sorted on span. */
|
|
TAILQ_INSERT_TAIL(&devices, de, list);
|
|
|
|
return (0);
|
|
}
|
|
|
|
int
|
|
linux_device_unregister_handler(struct linux_device_handler *d)
|
|
{
|
|
struct device_element *de;
|
|
|
|
if (d == NULL)
|
|
return (EINVAL);
|
|
|
|
TAILQ_FOREACH(de, &devices, list) {
|
|
if (bcmp(d, &de->entry, sizeof(*d)) == 0) {
|
|
TAILQ_REMOVE(&devices, de, list);
|
|
FREE(de, M_LINUX);
|
|
return (0);
|
|
}
|
|
}
|
|
|
|
return (EINVAL);
|
|
}
|