/* Set realtime priority for most threads to same as for biod's. */
afsd_set_afsd_rtpri();
-#ifdef AFS_SGI53_ENV
-#ifdef AFS_SGI61_ENV
- set_staticaddrs();
-#else /* AFS_SGI61_ENV */
- code = get_nfsstaticaddr();
- if (code)
- afsd_call_syscall(AFSOP_NFSSTATICADDR, code);
-#endif /* AFS_SGI61_ENV */
-#endif /* AFS_SGI_53_ENV */
-
/* Start listener, then callback listener. Lastly, start rx event daemon.
* Change in ordering is so that Linux port has socket fd in listener
* process.
return cmd_Dispatch(argc, argv);
}
-#ifdef AFS_SGI53_ENV
-#ifdef AFS_SGI61_ENV
-/* The dwarf structures are searched to find entry points of static functions
- * and the addresses of static variables. The file name as well as the
- * sybmol name is reaquired.
- */
-
-/* Contains list of names to find in given file. */
-typedef struct {
- char *name; /* Name of variable or function. */
- afs_hyper_t addr; /* Address of function, undefined if not found. */
- Dwarf_Half type; /* DW_AT_location for vars, DW_AT_lowpc for func's */
- char found; /* set if found. */
-} staticAddrList;
-
-typedef struct {
- char *file; /* Name of file containing vars or funcs */
- staticAddrList *addrList; /* List of vars and/or funcs. */
- int nAddrs; /* # of addrList's */
- int found; /* set if we've found this file already. */
-} staticNameList;
-
-/* routines used to find addresses in /unix */
-#if defined(AFS_SGI62_ENV) && !defined(AFS_SGI65_ENV)
-void findMDebugStaticAddresses(staticNameList *, int, int);
-#endif
-void findDwarfStaticAddresses(staticNameList *, int);
-void findElfAddresses(Dwarf_Debug, Dwarf_Die, staticNameList *);
-void getElfAddress(Dwarf_Debug, Dwarf_Die, staticAddrList *);
-
-#if defined(AFS_SGI62_ENV) && !defined(AFS_SGI65_ENV)
-#define AFS_N_FILELISTS 2
-#define AFS_SYMS_NEEDED 3
-#else /* AFS_SGI62_ENV */
-#define AFS_N_FILELISTS 1
-#endif /* AFS_SGI62_ENV */
-
-
-
-void
-set_staticaddrs(void)
-{
- staticNameList fileList[AFS_N_FILELISTS];
-
- fileList[0].addrList =
- (staticAddrList *) calloc(1, sizeof(staticAddrList));
- if (!fileList[0].addrList) {
- printf("set_staticaddrs: Can't calloc fileList[0].addrList\n");
- return;
- }
- fileList[0].file = "nfs_server.c";
- fileList[0].found = 0;
- fileList[0].nAddrs = 1;
- fileList[0].addrList[0].name = "rfsdisptab_v2";
- fileList[0].addrList[0].type = DW_AT_location;
- fileList[0].addrList[0].found = 0;
-
-#if defined(AFS_SGI62_ENV) && !defined(AFS_SGI65_ENV)
- fileList[1].addrList =
- (staticAddrList *) calloc(2, sizeof(staticAddrList));
- if (!fileList[1].addrList) {
- printf("set_staticaddrs: Can't malloc fileList[1].addrList\n");
- return;
- }
- fileList[1].file = "uipc_socket.c";
- fileList[1].found = 0;
- fileList[1].nAddrs = 2;
- fileList[1].addrList[0].name = "sblock";
- fileList[1].addrList[0].type = DW_AT_low_pc;
- fileList[1].addrList[0].found = 0;
- fileList[1].addrList[1].name = "sbunlock";
- fileList[1].addrList[1].type = DW_AT_low_pc;
- fileList[1].addrList[1].found = 0;
-
- if (64 != sysconf(_SC_KERN_POINTERS))
- findMDebugStaticAddresses(fileList, AFS_N_FILELISTS, AFS_SYMS_NEEDED);
- else
-#endif /* AFS_SGI62_ENV */
- findDwarfStaticAddresses(fileList, AFS_N_FILELISTS);
-
- if (fileList[0].addrList[0].found) {
- afsd_call_syscall(AFSOP_NFSSTATICADDR2, fileList[0].addrList[0].addr.high,
- fileList[0].addrList[0].addr.low);
- } else {
- if (afsd_verbose)
- printf("NFS V2 is not present in the kernel.\n");
- }
- free(fileList[0].addrList);
-#if defined(AFS_SGI62_ENV) && !defined(AFS_SGI65_ENV)
- if (fileList[1].addrList[0].found && fileList[1].addrList[1].found) {
- afsd_call_syscall(AFSOP_SBLOCKSTATICADDR2,
- fileList[1].addrList[0].addr.high,
- fileList[1].addrList[0].addr.low,
- fileList[1].addrList[1].addr.high,
- fileList[1].addrList[1].addr.low);
- } else {
- if (!fileList[1].addrList[0].found)
- printf("Can't find %s in kernel. Exiting.\n",
- fileList[1].addrList[0].name);
- if (!fileList[1].addrList[0].found)
- printf("Can't find %s in kernel. Exiting.\n",
- fileList[1].addrList[1].name);
- exit(1);
- }
- free(fileList[1].addrList);
-#endif /* AFS_SGI62_ENV */
-}
-
-
-/* Find addresses for static variables and functions. */
-void
-findDwarfStaticAddresses(staticNameList * nameList, int nLists)
-{
- int fd;
- int i;
- int found = 0;
- int code;
- char *s;
- char *hname = (char *)0;
- Dwarf_Unsigned dwarf_access = O_RDONLY;
- Dwarf_Debug dwarf_debug;
- Dwarf_Error dwarf_error;
- Dwarf_Unsigned dwarf_cu_header_length;
- Dwarf_Unsigned dwarf_abbrev_offset;
- Dwarf_Half dwarf_address_size;
- Dwarf_Unsigned next_cu_header;
- Dwarf_Die dwarf_die;
- Dwarf_Die dwarf_next_die;
- Dwarf_Die dwarf_child_die;
-
- if (elf_version(EV_CURRENT) == EV_NONE) {
- printf("findDwarfStaticAddresses: Bad elf version.\n");
- return;
- }
-
- if ((fd = open("/unix", O_RDONLY, 0)) < 0) {
- printf("findDwarfStaticAddresses: Failed to open /unix.\n");
- return;
- }
- code =
- dwarf_init(fd, dwarf_access, NULL, NULL, &dwarf_debug, &dwarf_error);
- if (code != DW_DLV_OK) {
- /* Nope hope for the elves and dwarves, try intermediate code. */
- close(fd);
- return;
- }
-
- found = 0;
- while (1) {
- /* Run through the headers until we find ones for files we've
- * specified in nameList.
- */
- code =
- dwarf_next_cu_header(dwarf_debug, &dwarf_cu_header_length, NULL,
- &dwarf_abbrev_offset, &dwarf_address_size,
- &next_cu_header, &dwarf_error);
- if (code == DW_DLV_NO_ENTRY) {
- break;
- } else if (code == DW_DLV_ERROR) {
- printf("findDwarfStaticAddresses: Error reading headers: %s\n",
- dwarf_errmsg(dwarf_error));
- break;
- }
-
- code = dwarf_siblingof(dwarf_debug, NULL, &dwarf_die, &dwarf_error);
- if (code != DW_DLV_OK) {
- printf("findDwarfStaticAddresses: Can't get first die. %s\n",
- (code == DW_DLV_ERROR) ? dwarf_errmsg(dwarf_error) : "");
- break;
- }
-
- /* This is the header, test the name. */
- code = dwarf_diename(dwarf_die, &hname, &dwarf_error);
- if (code == DW_DLV_OK) {
- s = strrchr(hname, '/');
- for (i = 0; i < nLists; i++) {
- if (s && !strcmp(s + 1, nameList[i].file)) {
- findElfAddresses(dwarf_debug, dwarf_die, &nameList[i]);
- found++;
- break;
- }
- }
- } else {
- printf
- ("findDwarfStaticAddresses: Can't get name of current header. %s\n",
- (code == DW_DLV_ERROR) ? dwarf_errmsg(dwarf_error) : "");
- break;
- }
- dwarf_dealloc(dwarf_debug, hname, DW_DLA_STRING);
- hname = (char *)0;
- if (found >= nLists) { /* we're done */
- break;
- }
- }
-
- /* Frees up all allocated space. */
- (void)dwarf_finish(dwarf_debug, &dwarf_error);
- close(fd);
-}
-
-void
-findElfAddresses(Dwarf_Debug dwarf_debug, Dwarf_Die dwarf_die,
- staticNameList * nameList)
-{
- int i;
- Dwarf_Error dwarf_error;
- Dwarf_Die dwarf_next_die;
- Dwarf_Die dwarf_child_die;
- Dwarf_Attribute dwarf_return_attr;
- char *vname = (char *)0;
- int found = 0;
- int code;
-
- /* Drop into this die to find names in addrList. */
- code = dwarf_child(dwarf_die, &dwarf_child_die, &dwarf_error);
- if (code != DW_DLV_OK) {
- printf("findElfAddresses: Can't get child die. %s\n",
- (code == DW_DLV_ERROR) ? dwarf_errmsg(dwarf_error) : "");
- return;
- }
-
- /* Try to find names in each sibling. */
- dwarf_next_die = (Dwarf_Die) 0;
- do {
- code = dwarf_diename(dwarf_child_die, &vname, &dwarf_error);
- /* It's possible that some siblings don't have names. */
- if (code == DW_DLV_OK) {
- for (i = 0; i < nameList->nAddrs; i++) {
- if (!nameList->addrList[i].found) {
- if (!strcmp(vname, nameList->addrList[i].name)) {
- getElfAddress(dwarf_debug, dwarf_child_die,
- &(nameList->addrList[i]));
- found++;
- break;
- }
- }
- }
- }
- if (dwarf_next_die)
- dwarf_dealloc(dwarf_debug, dwarf_next_die, DW_DLA_DIE);
-
- if (found >= nameList->nAddrs) { /* we're done. */
- break;
- }
-
- dwarf_next_die = dwarf_child_die;
- code =
- dwarf_siblingof(dwarf_debug, dwarf_next_die, &dwarf_child_die,
- &dwarf_error);
-
- } while (code == DW_DLV_OK);
-}
-
-/* Get address out of current die. */
-void
-getElfAddress(Dwarf_Debug dwarf_debug, Dwarf_Die dwarf_child_die,
- staticAddrList * addrList)
-{
- int i;
- Dwarf_Error dwarf_error;
- Dwarf_Attribute dwarf_return_attr;
- Dwarf_Bool dwarf_return_bool;
- Dwarf_Locdesc *llbuf = NULL;
- Dwarf_Signed listlen;
- off64_t addr = (off64_t) 0;
- int code;
-
- code =
- dwarf_hasattr(dwarf_child_die, addrList->type, &dwarf_return_bool,
- &dwarf_error);
- if ((code != DW_DLV_OK) || (!dwarf_return_bool)) {
- printf("getElfAddress: no address given for %s. %s\n", addrList->name,
- (code == DW_DLV_ERROR) ? dwarf_errmsg(dwarf_error) : "");
- return;
- }
- code =
- dwarf_attr(dwarf_child_die, addrList->type, &dwarf_return_attr,
- &dwarf_error);
- if (code != DW_DLV_OK) {
- printf("getElfAddress: Can't get attribute. %s\n",
- (code == DW_DLV_ERROR) ? dwarf_errmsg(dwarf_error) : "");
- return;
- }
-
- switch (addrList->type) {
- case DW_AT_location:
- code =
- dwarf_loclist(dwarf_return_attr, &llbuf, &listlen, &dwarf_error);
- if (code != DW_DLV_OK) {
- printf("getElfAddress: Can't get location for %s. %s\n",
- addrList->name,
- (code == DW_DLV_ERROR) ? dwarf_errmsg(dwarf_error) : "");
- return;
- }
- if ((listlen != 1) || (llbuf[0].ld_cents != 1)) {
- printf("getElfAddress: %s has more than one address.\n",
- addrList->name);
- return;
- }
- addr = llbuf[0].ld_s[0].lr_number;
- break;
-
- case DW_AT_low_pc:
- code =
- dwarf_lowpc(dwarf_child_die, (Dwarf_Addr *) & addr, &dwarf_error);
- if (code != DW_DLV_OK) {
- printf("getElfAddress: Can't get lowpc for %s. %s\n",
- addrList->name,
- (code == DW_DLV_ERROR) ? dwarf_errmsg(dwarf_error) : "");
- return;
- }
- break;
-
- default:
- printf("getElfAddress: Bad case %d in switch.\n", addrList->type);
- return;
- }
-
- addrList->addr.high = (addr >> 32) & 0xffffffff;
- addrList->addr.low = addr & 0xffffffff;
- addrList->found = 1;
-}
-
-#if defined(AFS_SGI62_ENV) && !defined(AFS_SGI65_ENV)
-/* Find symbols in the .mdebug section for 32 bit kernels. */
-/*
- * do_mdebug()
- * On 32bit platforms, we're still using the ucode compilers to build
- * the kernel, so we need to get our static text/data from the .mdebug
- * section instead of the .dwarf sections.
- */
-/* SearchNameList searches our bizarre structs for the given string.
- * If found, sets the found bit and the address and returns 1.
- * Not found returns 0.
- */
-int
-SearchNameList(char *name, afs_uint32 addr, staticNameList * nameList,
- int nLists)
-{
- int i, j;
- for (i = 0; i < nLists; i++) {
- for (j = 0; j < nameList[i].nAddrs; j++) {
- if (nameList[i].addrList[j].found)
- continue;
- if (!strcmp(name, nameList[i].addrList[j].name)) {
- nameList[i].addrList[j].addr.high = 0;
- nameList[i].addrList[j].addr.low = addr;
- nameList[i].addrList[j].found = 1;
- return 1;
- }
- }
- }
- return 0;
-}
-
-static void
-SearchMDebug(Elf_Scn * scnp, Elf32_Shdr * shdrp, staticNameList * nameList,
- int nLists, int needed)
-{
- long *buf = (long *)(elf_getdata(scnp, NULL)->d_buf);
- u_long addr, mdoff = shdrp->sh_offset;
- HDRR *hdrp;
- SYMR *symbase, *symp, *symend;
- FDR *fdrbase, *fdrp;
- int i, j;
- char *strbase, *str;
- int ifd;
- int nFound = 0;
-
- /* get header */
- addr = (__psunsigned_t) buf;
- hdrp = (HDRR *) addr;
-
- /* setup base addresses */
- addr = (u_long) buf + (u_long) (hdrp->cbFdOffset - mdoff);
- fdrbase = (FDR *) addr;
- addr = (u_long) buf + (u_long) (hdrp->cbSymOffset - mdoff);
- symbase = (SYMR *) addr;
- addr = (u_long) buf + (u_long) (hdrp->cbSsOffset - mdoff);
- strbase = (char *)addr;
-
-#define KEEPER(a,b) ((a == stStaticProc && b == scText) || \
- (a == stStatic && (b == scData || b == scBss || \
- b == scSBss || b == scSData)))
-
- for (fdrp = fdrbase; fdrp < &fdrbase[hdrp->ifdMax]; fdrp++) {
- str = strbase + fdrp->issBase + fdrp->rss;
-
- /* local symbols for each fd */
- for (symp = &symbase[fdrp->isymBase];
- symp < &symbase[fdrp->isymBase + fdrp->csym]; symp++) {
- if (KEEPER(symp->st, symp->sc)) {
- if (symp->value == 0)
- continue;
-
- str = strbase + fdrp->issBase + symp->iss;
- /* Look for AFS symbols of interest */
- if (SearchNameList(str, symp->value, nameList, nLists)) {
- nFound++;
- if (nFound >= needed)
- return;
- }
- }
- }
- }
-}
-
-/*
- * returns section with the name of scn_name, & puts its header in shdr64 or
- * shdr32 based on elf's file type
- *
- */
-Elf_Scn *
-findMDebugSection(Elf * elf, char *scn_name)
-{
- Elf64_Ehdr *ehdr64;
- Elf32_Ehdr *ehdr32;
- Elf_Scn *scn = NULL;
- Elf64_Shdr *shdr64;
- Elf32_Shdr *shdr32;
-
- if ((ehdr32 = elf32_getehdr(elf)) == NULL)
- return (NULL);
- do {
- if ((scn = elf_nextscn(elf, scn)) == NULL)
- break;
- if ((shdr32 = elf32_getshdr(scn)) == NULL)
- return (NULL);
- } while (strcmp
- (scn_name,
- elf_strptr(elf, ehdr32->e_shstrndx, shdr32->sh_name)));
-
- return (scn);
-}
-
-
-void
-findMDebugStaticAddresses(staticNameList * nameList, int nLists, int needed)
-{
- int fd;
- Elf *elf;
- Elf_Scn *mdebug_scn;
- Elf32_Shdr *mdebug_shdr;
- char *names;
-
- if ((fd = open("/unix", O_RDONLY)) == -1) {
- printf("findMDebugStaticAddresses: Failed to open /unix.\n");
- return;
- }
-
- (void)elf_version(EV_CURRENT);
- if ((elf = elf_begin(fd, ELF_C_READ, NULL)) == NULL) {
- printf
- ("findMDebugStaticAddresses: /unix doesn't seem to be an elf file\n");
- close(fd);
- return;
- }
- mdebug_scn = findMDebugSection(elf, ".mdebug");
- if (!mdebug_scn) {
- printf("findMDebugStaticAddresses: Can't find .mdebug section.\n");
- goto find_end;
- }
- mdebug_shdr = elf32_getshdr(mdebug_scn);
- if (!mdebug_shdr) {
- printf("findMDebugStaticAddresses: Can't find .mdebug header.\n");
- goto find_end;
- }
-
- (void)SearchMDebug(mdebug_scn, mdebug_shdr, nameList, nLists, needed);
-
- find_end:
- elf_end(elf);
- close(fd);
-}
-#endif /* AFS_SGI62_ENV */
-
-#else /* AFS_SGI61_ENV */
-#include <nlist.h>
-struct nlist nlunix[] = {
- {"rfsdisptab_v2"},
- {0},
-};
-
-get_nfsstaticaddr()
-{
- int i, j, kmem, count;
-
- if ((kmem = open("/dev/kmem", O_RDONLY)) < 0) {
- printf("Warning: can't open /dev/kmem\n");
- return 0;
- }
- if ((j = nlist("/unix", nlunix)) < 0) {
- printf("Warning: can't nlist /unix\n");
- return 0;
- }
- i = nlunix[0].n_value;
- if (lseek(kmem, i, L_SET /*0 */ ) != i) {
- printf("Warning: can't lseek to %x\n", i);
- return 0;
- }
- if ((j = read(kmem, &count, sizeof count)) != sizeof count) {
- printf("WARNING: kmem read at %x failed\n", i);
- return 0;
- }
- return i;
-}
-#endif /* AFS_SGI61_ENV */
-#endif /* AFS_SGI53_ENV */
-
struct afsd_syscall_args {
long syscall;
long param1;