2
0
Fork 0

Added the devtrace module.

This commit is contained in:
mike 1994-08-25 07:50:37 +00:00
parent 8f9885dbec
commit ec77448df0
6 changed files with 190 additions and 4 deletions

1
.gitignore vendored
View file

@ -28,3 +28,4 @@ core
# CVS default ignores end
.depend
iBCS
devtrace

View file

@ -1,3 +1,10 @@
Tue Aug 23 17:21:45 BST 1994
* Added my device trace stub in case anyone needs to investigate
and emulate some special device.
-- Mike
Wed Aug 17 14:06:34 BST 1994
* Added an extern definition of the formats list needed by

View file

@ -1,7 +1,7 @@
#
# Makefile for the iBCS emulator files
#
# $Id: Makefile,v 1.21 1994/08/05 09:29:09 mike Exp $
# $Id: Makefile,v 1.22 1994/08/25 07:50:36 mike Exp $
# $Source: /nfs4/sophia/home/mjagdis/src/ibcs.cvs/ibcs/Makefile,v $
#
# Note! Dependencies are done automagically by 'make dep', which also
@ -115,6 +115,9 @@ emulate2.o: emulate.c
-DKVERSION=\"$(KVERSION)\" \
-c -o emulate2.o emulate.c
devtrace: devtrace.c
$(CC) $(CFLAGS) -DKVERSION=\"$(KVERSION)\" -c -o devtrace devtrace.c
clean:
rm -f core *.o *.a *.s .depend

18
README
View file

@ -107,7 +107,7 @@ INSTALLATION
available on all major Linux archive sites.
2. Apply the kernel patches if you are using a 1.0 kernel (read them
first - the patch file is annotated). Not patches are required for
first - the patch file is annotated). No patches are required for
kernels 1.1.15 and later. If you are using an earlier 1.1 kernel
you should upgrade it. The 1.1 series is a development kernel and
liable to frequent bug fixes. Non-current releases of 1.1 will *not*
@ -136,7 +136,7 @@ INSTALLATION
Instructions on how to make the kernel are included in the README file
in the Linux kernel source directory.
4. Install the kernel. Use either LILO or a separate diskette.
4. Install the kernel. Use either LILO or a seperate diskette.
5. The interfaces to some subsystems occur at the device layer and thus
you need to create some device files in order to use them:
@ -266,6 +266,20 @@ and kill the tail:
and examine the log.
If the program is trying to access a device that doesn't exist and whose
intended behaviour is not readily apparent (not all devices are devices,
take a look at /dev/socksys which implements the socket system calls
behind ioctls) you may wish to use the devtrace module. Firstly, if
you aren't using a recent (1.1.45+?) kernel you will need to edit the
file devtrace.c and define a fixed major number. Build the module
using 'make devtrace' and load it with insmod. If you left the major
number as zero look up the allocated number in /proc/devices then
create whatever device nodes your program is trying to access. The
devtrace module simply writes kernel syslog messages for all operations
performed on it and pretends that everything succeeds. This will
cause your program to die horribly but should leave you with enough
information to find out what was expected of the real device.
If you can fix the problem do so and post the fix to the IBCS2 mailing
list, otherwise post the *relevant* details you have - parts of the log
file, ioctl details, syscall details etc. Remember, it's better to post

158
devtrace/devtrace.c Normal file
View file

@ -0,0 +1,158 @@
#include <linux/types.h>
#include <linux/errno.h>
#include <linux/fs.h>
#include <linux/fcntl.h>
#include <linux/major.h>
#include <asm/segment.h>
#define __KERNEL__ 1
#include <linux/kernel.h>
#include <linux/net.h>
#include <linux/sched.h>
#include <linux/signal.h>
#include <linux/socket.h>
#include <linux/utsname.h>
#include <linux/time.h>
#include <linux/termios.h>
#include <linux/sys.h>
#include <linux/config.h>
#include <linux/module.h>
/* Zero for auto allocation. The major number allocated can be found
* by looking in /proc/devices after the module is loaded. Auto
* allocation of major numbers is a fairly new kernel feature. If you
* aren't using a recent 1.1.x kernel you may have to set an explicit
* major number here.
*/
#define DEVTRACE_MAJOR 0
char kernel_version[] = KVERSION;
static int
devtrace_lseek(struct inode *inode, struct file *file, off_t offset, int whence)
{
printk(KERN_DEBUG "devtrace: [%d] %lx: lseek to 0x%08lx whence=%d\n",
current->pid, (unsigned long)file,
offset, whence);
/* Easy way out. Most devices we wish to trace are either
* STREAMS devices or character devices which aren't seekable
* anyway.
*/
return -ESPIPE;
}
static int
devtrace_read(struct inode *inode, struct file *file, char *buf, int size)
{
printk(KERN_DEBUG "devtrace: [%d] %lx: read %d bytes to 0x%lx\n",
current->pid, (unsigned long)file,
size, (unsigned long)buf);
return size;
}
static int
devtrace_write(struct inode *inode, struct file *file, char *buf, int size)
{
printk(KERN_DEBUG "devtrace: [%d] %lx: write %d bytes from 0x%lx\n",
current->pid, (unsigned long)file,
size, (unsigned long)buf);
return size;
}
static int
devtrace_ioctl(struct inode *inode, struct file *file,
unsigned int cmd, unsigned long arg)
{
static char *code[] = {
"", "I_NREAD", "I_PUSH", "I_POP",
"I_LOOK", "I_FLUSH", "I_SRDOPT", "I_GRDOPT",
"I_STR", "I_SETSIG", "I_GETSIG", "I_FIND",
"I_LINK", "I_UNLINK", "I_PEEK", "I_FDINSERT",
"I_SENDFD", "I_RECVFD"
};
printk(KERN_DEBUG "devtrace: [%d] %lx: ioctl 0x%x (%s) with argument 0x%lx requested\n",
current->pid, (unsigned long)file,
cmd, (cmd & 0xff) <= 18 ? code[(cmd & 0xff)] : "????",
(unsigned long)arg);
return 0;
}
static int
devtrace_open(struct inode *ino, struct file *filep)
{
MOD_INC_USE_COUNT;
printk(KERN_DEBUG "devtrace: [%d] %lx opening\n",
current->pid, (unsigned long)filep);
return 0;
}
static void
devtrace_close(struct inode *ino, struct file *filep)
{
MOD_DEC_USE_COUNT;
printk(KERN_DEBUG "devtrace: [%d] %lx closed\n",
current->pid, (unsigned long)filep);
}
static struct file_operations devtrace_fops = {
devtrace_lseek, /* lseek */
devtrace_read, /* read */
devtrace_write, /* write */
NULL, /* readdir */
NULL, /* select */
devtrace_ioctl, /* ioctl */
NULL, /* mmap */
devtrace_open, /* open */
devtrace_close, /* close */
NULL /* fsync */
};
static int devtrace_major;
int
init_module(void)
{
devtrace_major = register_chrdev(DEVTRACE_MAJOR, "devtrace", &devtrace_fops);
if (devtrace_major < 0) {
printk(KERN_INFO "iBCS: couldn't register devtrace on character major %d\n",
DEVTRACE_MAJOR);
return 1;
} else {
if (!devtrace_major)
devtrace_major = DEVTRACE_MAJOR;
printk(KERN_INFO "iBCS: devtrace registered on character major %d\n", devtrace_major);
return 0;
}
}
void
cleanup_module(void)
{
if (MOD_IN_USE)
printk(KERN_INFO "iBCS: devtrace module is in use, remove delayed\n");
if (devtrace_major > 0 && unregister_chrdev(devtrace_major, "devtrace") != 0)
printk(KERN_NOTICE "iBCS: couldn't unregister devtrace device!\n");
}

View file

@ -1,7 +1,7 @@
#
# Makefile for the iBCS emulator files
#
# $Id: Makefile,v 1.21 1994/08/05 09:29:09 mike Exp $
# $Id: Makefile,v 1.22 1994/08/25 07:50:36 mike Exp $
# $Source: /nfs4/sophia/home/mjagdis/src/ibcs.cvs/ibcs/iBCSemul/Makefile,v $
#
# Note! Dependencies are done automagically by 'make dep', which also
@ -115,6 +115,9 @@ emulate2.o: emulate.c
-DKVERSION=\"$(KVERSION)\" \
-c -o emulate2.o emulate.c
devtrace: devtrace.c
$(CC) $(CFLAGS) -DKVERSION=\"$(KVERSION)\" -c -o devtrace devtrace.c
clean:
rm -f core *.o *.a *.s .depend