~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/metag/tbx/tbistring.c

Version: ~ [ linux-5.3-rc4 ] ~ [ linux-5.2.8 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.66 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.138 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.189 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.189 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.71 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-3.9.11 ] ~ [ linux-3.8.13 ] ~ [ linux-3.7.10 ] ~ [ linux-3.6.11 ] ~ [ linux-3.5.7 ] ~ [ linux-3.4.113 ] ~ [ linux-3.3.8 ] ~ [ linux-3.2.102 ] ~ [ linux-3.1.10 ] ~ [ linux-3.0.101 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  * tbistring.c
  3  *
  4  * Copyright (C) 2001, 2002, 2003, 2005, 2007, 2012 Imagination Technologies.
  5  *
  6  * This program is free software; you can redistribute it and/or modify it under
  7  * the terms of the GNU General Public License version 2 as published by the
  8  * Free Software Foundation.
  9  *
 10  * String table functions provided as part of the thread binary interface for
 11  * Meta processors
 12  */
 13 
 14 #include <linux/export.h>
 15 #include <linux/string.h>
 16 #include <asm/tbx.h>
 17 
 18 /*
 19  * There are not any functions to modify the string table currently, if these
 20  * are required at some later point I suggest having a seperate module and
 21  * ensuring that creating new entries does not interfere with reading old
 22  * entries in any way.
 23  */
 24 
 25 const TBISTR *__TBIFindStr(const TBISTR *start,
 26                            const char *str, int match_len)
 27 {
 28         const TBISTR *search = start;
 29         bool exact = true;
 30         const TBISEG *seg;
 31 
 32         if (match_len < 0) {
 33                 /* Make match_len always positive for the inner loop */
 34                 match_len = -match_len;
 35                 exact = false;
 36         } else {
 37                 /*
 38                  * Also support historic behaviour, which expected match_len to
 39                  * include null terminator
 40                  */
 41                 if (match_len && str[match_len-1] == '\0')
 42                         match_len--;
 43         }
 44 
 45         if (!search) {
 46                 /* Find global string table segment */
 47                 seg = __TBIFindSeg(NULL, TBID_SEG(TBID_THREAD_GLOBAL,
 48                                                   TBID_SEGSCOPE_GLOBAL,
 49                                                   TBID_SEGTYPE_STRING));
 50 
 51                 if (!seg || seg->Bytes < sizeof(TBISTR))
 52                         /* No string table! */
 53                         return NULL;
 54 
 55                 /* Start of string table */
 56                 search = seg->pGAddr;
 57         }
 58 
 59         for (;;) {
 60                 while (!search->Tag)
 61                         /* Allow simple gaps which are just zero initialised */
 62                         search = (const TBISTR *)((const char *)search + 8);
 63 
 64                 if (search->Tag == METAG_TBI_STRE) {
 65                         /* Reached the end of the table */
 66                         search = NULL;
 67                         break;
 68                 }
 69 
 70                 if ((search->Len >= match_len) &&
 71                     (!exact || (search->Len == match_len + 1)) &&
 72                     (search->Tag != METAG_TBI_STRG)) {
 73                         /* Worth searching */
 74                         if (!strncmp(str, (const char *)search->String,
 75                                      match_len))
 76                                 break;
 77                 }
 78 
 79                 /* Next entry */
 80                 search = (const TBISTR *)((const char *)search + search->Bytes);
 81         }
 82 
 83         return search;
 84 }
 85 
 86 const void *__TBITransStr(const char *str, int len)
 87 {
 88         const TBISTR *search = NULL;
 89         const void *res = NULL;
 90 
 91         for (;;) {
 92                 /* Search onwards */
 93                 search = __TBIFindStr(search, str, len);
 94 
 95                 /* No translation returns NULL */
 96                 if (!search)
 97                         break;
 98 
 99                 /* Skip matching entries with no translation data */
100                 if (search->TransLen != METAG_TBI_STRX) {
101                         /* Calculate base of translation string */
102                         res = (const char *)search->String +
103                                 ((search->Len + 7) & ~7);
104                         break;
105                 }
106 
107                 /* Next entry */
108                 search = (const TBISTR *)((const char *)search + search->Bytes);
109         }
110 
111         /* Return base address of translation data or NULL */
112         return res;
113 }
114 EXPORT_SYMBOL(__TBITransStr);
115 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp