4 * Copyright (C) 2001, 2002, 2003, 2005, 2007, 2012 Imagination Technologies.
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.
10 * String table functions provided as part of the thread binary interface for
14 #include <linux/export.h>
15 #include <linux/string.h>
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
25 const TBISTR
*__TBIFindStr(const TBISTR
*start
,
26 const char *str
, int match_len
)
28 const TBISTR
*search
= start
;
33 /* Make match_len always positive for the inner loop */
34 match_len
= -match_len
;
38 * Also support historic behaviour, which expected match_len to
39 * include null terminator
41 if (match_len
&& str
[match_len
-1] == '\0')
46 /* Find global string table segment */
47 seg
= __TBIFindSeg(NULL
, TBID_SEG(TBID_THREAD_GLOBAL
,
49 TBID_SEGTYPE_STRING
));
51 if (!seg
|| seg
->Bytes
< sizeof(TBISTR
))
52 /* No string table! */
55 /* Start of string table */
61 /* Allow simple gaps which are just zero initialised */
62 search
= (const TBISTR
*)((const char *)search
+ 8);
64 if (search
->Tag
== METAG_TBI_STRE
) {
65 /* Reached the end of the table */
70 if ((search
->Len
>= match_len
) &&
71 (!exact
|| (search
->Len
== match_len
+ 1)) &&
72 (search
->Tag
!= METAG_TBI_STRG
)) {
74 if (!strncmp(str
, (const char *)search
->String
,
80 search
= (const TBISTR
*)((const char *)search
+ search
->Bytes
);
86 const void *__TBITransStr(const char *str
, int len
)
88 const TBISTR
*search
= NULL
;
89 const void *res
= NULL
;
93 search
= __TBIFindStr(search
, str
, len
);
95 /* No translation returns NULL */
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);
108 search
= (const TBISTR
*)((const char *)search
+ search
->Bytes
);
111 /* Return base address of translation data or NULL */
114 EXPORT_SYMBOL(__TBITransStr
);