[comp.unix.ultrix] Ultrix panic vstodb

janm@eliot.UUCP (Jan Morales) (09/08/88)

Reply-to: janm@eliot.UUCP (Jan Morales)

We have been getting panics on our machine and it seems to be
related to something in this code (probably shared memory)
because the system can be brought down reliably when it is
run.  This is the panic message on the console:

	panic vstodb

The machine then syncs the disks, dumps core, and reboots.

We are running Ultrix 1.2 on a DEC MicroVAX II.

Thanks.  Any help is really appreciated.

Jan
Unitech Software, Inc.
(703) 264-3301
uunet!pyrdc!eliot!janm


The following code brings the machine down.  The flower box
in the code marks the spot.  We added to the piece of code
that follows it, it produces a compilable module.

--BEGIN---------------------------------------------------------------
#include <stdio.h>

struct ourshm
{
	int level;
	int loglevel;
	char buffer[1024];
};

extern struct ourshm *shm;

main(argc, argv)
int argc;
char **argv;
{
	int subsys, level, out, in;
	char temp[128];

	if (startlog() == -1)	/* see below for code of this function */
	{
		printf("Unable to get to shared memory\n");
		exit(1);
	}
	if (argc < 2)
	{
		for (;;)
		{
			printf("1. XXX subsystem\n");
			printf("2. XXX subsystem\n");
			printf("3. XXX subsystem\n");
			printf("4. xxxxxxxx xxxxxxxxx subsystem\n");
			printf("Enter subsystem: ");
			gets(temp);
			subsys = atoi(temp);
			if (subsys > 0 && subsys < 5)
				break;
			printf("\nEnter 1 thru 4.\n\n");
		}
	}
	else
	{
		subsys = atoi(argv[1]);
		if (subsys < 1 || subsys > 4)
		{
			printf("Subsystem must be 1 thru 4.\n");
			exit(1);
		}
	}
	subsys--;
	if (argc < 3)
	{
		if (argc > 2)
			printf("\n");
		for (;;)
		{
			printf("Enter debug level (0 thru 3): ");
			gets(temp);
/****************************************************************
* "gets(temp);" is the last statement we can observe executing	*
* before the system crashes.  We are given the prompt, we type	*
* a response, we hit enter, then it dies.  However, this	*
* program may or may not prompt based on the number of		*
* arguments provided, but it always kills the system eventually	*
* regardless.							*
****************************************************************/
			level = atoi(temp);
			if (level >= 0 && level < 4)
				break;
			printf("\n");
		}
	}
	else
	{
		level = atoi(argv[2]);
		if (level < 0 || level > 3)
		{
			printf("Level must be 0 thru 3.\n");
			exit(1);
		}
	}
	subsys *= 3;
	out = -1 ^ (7 << subsys);
	if (level == 3)
		in = 7;
	else if (level == 2)
		in = 3;
	else if (level == 1)
		in = 1;
	else
		in = 0;
	in <<= subsys;
	shm->level &= out;
	shm->level |= in;
	exit(0);
}
--END-----------------------------------------------------------------

"ourshm" is a structure 1032 bytes big.  This code brought the
system down when this structure was 8 bytes big as well.

Here is the code for the function startlog() which creates and
attaches the shared memory segment.  It has failed when SHMKEY
was both 1 and 10.

--BEGIN---------------------------------------------------------------
#include <varargs.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>

#define SHMKEY		10
#define SHMMODE		(IPC_CREAT | 0644)

int shmid;
struct ourshm *shm;

startlog()
{
	extern errno;
	struct ourshm *shmat();

	if ((shmid = shmget(SHMKEY, sizeof(struct ourshm), SHMMODE)) == -1)
	{
		printf("unable to shmget: errno %d\n", errno);
		return -1;
	}
	if ((shm = shmat(shmid, 0, 0)) == (struct ourshm *) -1)
	{
		printf("unable to shmat: errno %d\n", errno);
		return -1;
	}
	return 0;
}
--END-----------------------------------------------------------------

Here is the output of "ipcs -mb" after the shared memory segment
is created but before any of the memory is accessed or altered
by our code.

--BEGIN---------------------------------------------------------------

IPC status from /dev/kmem as of Wed Aug 31 13:53:22 1988
Shared Memory
T     ID     KEY        MODE       OWNER    GROUP  SEGSZ
m      0         10 --rw-r--r--     janm  devlpmt   1032

--END-----------------------------------------------------------------