Chameleon

Chameleon Commit Details

Date:2010-02-23 03:20:16 (14 years 1 month ago)
Author:Rekursor
Commit:112
Parents: 111
Message:restricted access to smbios tables orig new and cache construction, avoided recursive calls on smbios table find functions.
Changes:
M/trunk/i386/libsaio/smbios_patcher.c
M/trunk/i386/libsaio/smbios_patcher.h
M/trunk/i386/libsaio/fake_efi.c

File differences

trunk/i386/libsaio/smbios_patcher.c
297297
298298
299299
300
300
301301
302302
303303
......
445445
446446
447447
448
448
449449
450450
451451
......
743743
744744
745745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
763762
764763
765764
......
773772
774773
775774
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802775
803776
804777
805778
806
779
807780
808781
809782
810783
811784
812
813
814
785
815786
816787
817788
818
789
819790
820791
821792
......
846817
847818
848819
849
850820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
}
/** Compute necessary space requirements for new smbios */
struct SMBEntryPoint *smbios_dry_run(struct SMBEntryPoint *origsmbios)
static struct SMBEntryPoint *smbios_dry_run(struct SMBEntryPoint *origsmbios)
{
struct SMBEntryPoint*ret;
char*smbiostables;
* struct has been created by smbios_dry_run, update each table struct content of new smbios
* int the new allocated table address of size newsmbios->tablelength.
*/
void smbios_real_run(struct SMBEntryPoint * origsmbios, struct SMBEntryPoint * newsmbios)
static void smbios_real_run(struct SMBEntryPoint * origsmbios, struct SMBEntryPoint * newsmbios)
{
char *smbiostables;
char *tablesptr, *newtablesptr;
{
static struct SMBEntryPoint *orig = NULL; // cached
static struct SMBEntryPoint *patched = NULL; // cached
if (orig == NULL) orig = getAddressOfSmbiosTable();
switch (which) {
case SMBIOS_ORIGINAL:
return orig;
case SMBIOS_PATCHED:
if (patched == NULL) {
if (orig==NULL) orig = getAddressOfSmbiosTable();
patched = smbios_dry_run(orig);
smbios_real_run(orig, patched);
}
return patched;
default:
printf("ERROR: invalid option for getSmbios() !!\n");
return NULL;
}
// whatever we are called with orig or new flag, initialize asap both structures
if (orig == NULL) orig = getAddressOfSmbiosTable();
if (patched == NULL) {
patched = smbios_dry_run(orig);
smbios_real_run(orig, patched);
}
switch (which) {
case SMBIOS_ORIGINAL:
return orig;
case SMBIOS_PATCHED:
return patched;
default:
printf("ERROR: invalid option for getSmbios() !!\n");
return NULL;
}
}
#define MAX_DMI_TABLES 64
static int current_pos=0;
static bool ftTablePairInit = true;
/** Find first original dmi Table with a particular type */
struct DMIHeader* FindFirstDmiTableOfType(int type, int minlength)
{
if (ftTablePairInit)
return getSmbiosTableStructure(getSmbios(SMBIOS_ORIGINAL),
type, minlength);
current_pos = 0;
return FindNextDmiTableOfType(type, minlength);
};
/** Find next original dmi Table with a particular type */
struct DMIHeader* FindNextDmiTableOfType(int type, int minlength)
{
int i;
for (i=current_pos; i < DmiTablePairCount; i++) {
if (type == DmiTablePair[i].type &&
DmiTablePair[i].dmi &&
DmiTablePair[i].dmi->length >= minlength ) {
current_pos = i+1;
return DmiTablePair[i].dmi;
}
}
return NULL; // not found
};
/**
* Get a table structure entry from a type specification and a smbios address
* return NULL if table is not found
*/
struct DMIHeader *getSmbiosTableStructure(struct SMBEntryPoint*smbios, int type, int min_length)
static void getSmbiosTableStructure(struct SMBEntryPoint*smbios, int type, int min_length)
{
struct DMIHeader * dmihdr=NULL;
SMBByte* p;
int i;
if (!ftTablePairInit) {
return FindFirstDmiTableOfType(type, min_length);
} else {
if (ftTablePairInit) {
ftTablePairInit = false;
bzero(DmiTablePair, sizeof(DmiTablePair));
if (smbios == NULL || type < 0 ) return NULL;
if (smbios == NULL || type < 0 ) return;
#if DEBUG_SMBIOS
printf(">>> SMBIOSAddr=0x%08x\n", smbios);
printf(">>> DMI: addr=0x%08x, len=%d, count=%d\n", smbios->dmi.tableAddress,
}
}
return FindFirstDmiTableOfType(type, min_length);
}
/** Find first new dmi Table with a particular type */
struct DMIHeader* FindFirstDmiTableOfType(int type, int minlength)
{
if (ftTablePairInit)
getSmbiosTableStructure(getSmbios(SMBIOS_PATCHED),
type, minlength);
current_pos = 0;
return FindNextDmiTableOfType(type, minlength);
};
/** Find next new dmi Table with a particular type */
struct DMIHeader* FindNextDmiTableOfType(int type, int minlength)
{
int i;
for (i=current_pos; i < DmiTablePairCount; i++) {
if (type == DmiTablePair[i].type &&
DmiTablePair[i].dmi &&
DmiTablePair[i].dmi->length >= minlength ) {
current_pos = i+1;
return DmiTablePair[i].dmi;
}
}
return NULL; // not found
};
trunk/i386/libsaio/smbios_patcher.h
4949
5050
5151
52
5352
5453
5554
/** call with flag SMBIOS_ORIGINAL to get orig. entrypoint
or call with flag SMBIOS_PATCHED to get patched smbios entrypoint
*/
extern struct DMIHeader *getSmbiosTableStructure(struct SMBEntryPoint*smbios, int type, int min_length);
extern struct SMBEntryPoint*getSmbios(int);
extern struct DMIHeader* FindNextDmiTableOfType(int type, int minlen);
extern struct DMIHeader* FindFirstDmiTableOfType(int type, int minlen);
trunk/i386/libsaio/fake_efi.c
350350
351351
352352
353
353
354354
355355
356356
smbios = getSmbios(SMBIOS_PATCHED);/* checks for _SM_ anchor and table header checksum */
if (smbios==NULL) return 0; // getSmbios() return a non null value if smbios is found
p = (SMBByte *) getSmbiosTableStructure(smbios, 1, 0x19); /* Type 1: (3.3.2) System Information */
p = (SMBByte*) FindFirstDmiTableOfType(1, 0x19); /* Type 1: (3.3.2) System Information */
if (p==NULL) return NULL;
verbose("Found SMBIOS System Information Table 1\n");

Archive Download the corresponding diff file

Revision: 112