Chameleon

Chameleon Commit Details

Date:2014-01-07 22:15:46 (10 years 3 months ago)
Author:ErmaC
Commit:2318
Parents: 2317
Message:Merge Improvements/Implementations and Fix from chucko branch. Credits and thx to Bit Shoveler (Chuck Fry)
Changes:
M/trunk/i386/config/confdata.c
M/trunk/i386/klibc/strlcpy.c
M/trunk/i386/boot2/picopng.c
M/trunk/i386/boot2/graphics.c
M/trunk/i386/libsaio/gma.c
M/trunk/i386/boot2/boot.c
M/trunk/i386/libsa/libsa.h
M/trunk/i386/libsaio/dram_controllers.c
M/trunk/i386/libsa/printf.c
M/trunk/i386/libsaio/ntfs.c
M/trunk/i386/libsaio/nvidia.c
M/trunk/i386/boot2/modules.c
M/trunk/i386/libsaio/pci.c
M/trunk/i386/libsaio/pci_root.c
M/trunk/i386/libsa/string.c
M/trunk/i386/boot2/drivers.c
M/trunk/i386/libsaio/acpi_patcher.c
M/trunk/i386/libsaio/allocate.c
M/trunk/i386/modules/Keylayout/layouts/cham-mklayout.c
M/trunk/i386/boot2/gui.c
M/trunk/i386/config/symbol.c
M/trunk/i386/libsaio/smbios_getters.c
M/trunk/i386/config/lex.zconf.c
M/trunk/i386/libsaio/device_inject.c
M/trunk/i386/boot2/ramdisk.c
M/trunk/i386/boot2/options.c
M/trunk/i386/libsaio/xml.c

File differences

trunk/i386/libsaio/xml.c
744744
745745
746746
747
747748
748749
749750
......
12401241
12411242
12421243
1244
1245
12431246
12441247
{
printf("ParseTagInteger hex error (0x%x) in buffer %s\n", *val, buffer);
getchar();
XMLFreeTag(tmpTag);
return -1;
}
}
tagList->tagNext = tmpTag;
return true;
}
XMLFreeTag(tmpTag);
return false;
}
trunk/i386/libsaio/acpi_patcher.c
9393
9494
9595
96
9697
9798
9899
99
100
100101
101102
102103
103
104
104105
105106
106
107
108
109
107
108
109
110
110111
111
112
113
112
113
114
114115
115
116
117
116
117
118
118119
119120
120121
121122
122
123
124
125
126
127
128
129
130
131123
132124
133125
......
870862
871863
872864
873
865
874866
875867
876868
}
/* The folowing ACPI Table search algo. should be reused anywhere needed:*/
/* WARNING: outDirspec string will be overwritten by subsequent calls! */
int search_and_get_acpi_fd(const char * filename, const char ** outDirspec)
{
int fd = 0;
char dirSpec[512];
static char dirSpec[512];
// Try finding 'filename' in the usual places
// Start searching any potential location for ACPI Table
sprintf(dirSpec, "%s", filename);
snprintf(dirSpec, sizeof(dirSpec), "%s", filename);
fd = open(dirSpec, 0);
if (fd < 0)
{
sprintf(dirSpec, "/Extra/%s", filename);
fd = open(dirSpec, 0);
if (fd < 0)
{
snprintf(dirSpec, sizeof(dirSpec), "/Extra/%s", filename);
fd = open(dirSpec, 0);
if (fd < 0)
{
sprintf(dirSpec, "bt(0,0)/Extra/%s", filename);
fd = open(dirSpec, 0);
if (fd < 0)
snprintf(dirSpec, sizeof(dirSpec), "bt(0,0)/Extra/%s", filename);
fd = open(dirSpec, 0);
if (fd < 0)
{
// NOT FOUND:
verbose("ACPI Table not found: %s\n", filename);
*dirSpec = '\0';
// NOT FOUND:
verbose("ACPI Table not found: %s\n", filename);
*dirSpec = '\0';
}
}
}
// Bungo
/*** Moved above
if (fd < 0)
{
// NOT FOUND:
verbose("ACPI Table not found: %s\n", filename);
*dirSpec = '\0';
}
***/
if (outDirspec) *outDirspec = dirSpec;
return fd;
}
/* Try using the file specified with the DSDT option */
if (getValueForKey(kDSDT, &filename, &len, &bootInfo->chameleonConfig))
{
sprintf(dirSpec, filename);
snprintf(dirSpec, sizeof(dirSpec), filename);
}
else
{
trunk/i386/libsaio/allocate.c
4141
4242
4343
44
4544
4645
47
46
47
48
49
4850
51
4952
5053
5154
nameBuf = malloc(strlen(rangeName) + 1);
if (nameBuf == 0) return -1;
strcpy(nameBuf, rangeName);
buffer = malloc(2 * sizeof(uint32_t));
if (buffer == 0) return -1;
if (buffer == 0) {
free(nameBuf);
return -1;
}
strcpy(nameBuf, rangeName);
buffer[0] = start;
buffer[1] = length;
trunk/i386/libsaio/gma.c
354354
355355
356356
357
358
357
359358
360359
361360
362
363
361
364362
365363
366364
......
395393
396394
397395
398
399
400
396
401397
402398
403399
{
if (intel_gfx_chipsets[i].model == ((device_id << 16) | vendor_id))
{
sprintf(desc, "%s %s", INTEL_NAME, intel_gfx_chipsets[i].label_info);
desc[sizeof(desc) - 1] = '\0';
snprintf(desc, sizeof(desc), "%s %s", INTEL_NAME, intel_gfx_chipsets[i].label_info);
return desc;
}
}
sprintf(desc, "Unknown %s Graphics card", INTEL_NAME);
desc[sizeof(desc) - 1] = '\0';
snprintf(desc, sizeof(desc), "Unknown %s Graphics card", INTEL_NAME);
return desc;
}
string = devprop_create_string();
}
struct DevPropDevice *device = malloc(sizeof(struct DevPropDevice));
device = devprop_add_device(string, devicepath);
struct DevPropDevice *device = devprop_add_device(string, devicepath);
if (!device)
{
printf("Failed initializing dev-prop string dev-entry.\n");
trunk/i386/libsaio/pci_root.c
7979
8080
8181
82
82
8383
8484
8585
......
9898
9999
100100
101
101
102102
103103
104104
105105
106106
107107
108
108109
109110
110111
// Try using the file specified with the DSDT option
if (getValueForKey(kDSDT, &dsdt_filename, &len, &bootInfo->chameleonConfig))
{
sprintf(dsdt_dirSpec, dsdt_filename);
snprintf(dsdt_dirSpec, sizeof(dsdt_dirSpec), dsdt_filename);
}
else
{
fsize = file_size(fd);
if ((new_dsdt = malloc(fsize)) == NULL) {
if (!(new_dsdt = malloc(fsize))) {
verbose("[ERROR] alloc DSDT memory failed\n");
close (fd);
goto out;
}
if (read (fd, new_dsdt, fsize) != fsize) {
verbose("[ERROR] read %s failed\n", dsdt_filename);
free(new_dsdt);
close (fd);
goto out;
}
trunk/i386/libsaio/device_inject.c
7575
7676
7777
78
79
7880
79
80
81
8281
8382
8483
......
8786
8887
8988
90
91
92
89
90
91
9392
9493
94
9595
9696
97
9897
9998
10099
101100
102101
103102
103
104
105
106
107
104108
105109
106110
......
144148
145149
146150
147
148
151
152
153
154
149155
150156
151157
......
172178
173179
174180
175
176181
177
178
179
182
183
184
185
186
180187
188
189
181190
182191
183192
......
397406
398407
399408
400
409
401410
402411
403412
404
405
413
414
406415
407
408
409
410
411
412
413
414
415
416
417
416
417
418
419
420
421
422
423
424
418425
419426
struct DevPropString *devprop_create_string(void)
{
string = (struct DevPropString*)malloc(sizeof(struct DevPropString));
if (string == NULL)
return NULL;
if(string == NULL)
return NULL;
memset(string, 0, sizeof(struct DevPropString));
string->length = 12;
string->WHAT2 = 0x01000000;
struct DevPropDevice *devprop_add_device(struct DevPropString *string, char *path)
{
struct DevPropDevice*device;
const charpciroot_string[] = "PciRoot(0x";
const charpci_device_string[] = "Pci(0x";
struct DevPropDevice*device = NULL;
static const charpciroot_string[] = "PciRoot(0x";
static const charpci_device_string[] = "Pci(0x";
if (string == NULL || path == NULL) {
printf("ERROR null device path\n");
return NULL;
}
device = malloc(sizeof(struct DevPropDevice));
if (strncmp(path, pciroot_string, strlen(pciroot_string))) {
printf("ERROR parsing device path\n");
return NULL;
}
if (!(device = malloc(sizeof(struct DevPropDevice)))) {
printf("ERROR malloc failed\n");
return NULL;
}
memset(device, 0, sizeof(struct DevPropDevice));
device->acpi_dev_path._UID = getPciRootUID();
}
}
if(!numpaths)
return NULL;
if (!numpaths) {
free(device);
return NULL;
}
device->numentries = 0x00;
device->string = string;
device->data = NULL;
string->length += device->length;
if(!string->entries)
if((string->entries = (struct DevPropDevice**)malloc(sizeof(device)*DEV_PROP_DEVICE_MAX_ENTRIES))== NULL)
return 0;
if (!string->entries)
if (!(string->entries = (struct DevPropDevice**) malloc(sizeof(device) * DEV_PROP_DEVICE_MAX_ENTRIES))) {
free(device);
return NULL;
}
/* FIXME: probably needs bounds checking, as well as error handling in event of malloc failure */
string->length += device->length;
string->entries[string->numentries++] = (struct DevPropDevice*)malloc(sizeof(device));
string->entries[string->numentries-1] = device;
void set_eth_builtin(pci_dt_t *eth_dev)
{
char *devicepath = get_pci_dev_path(eth_dev);
struct DevPropDevice *device = (struct DevPropDevice*)malloc(sizeof(struct DevPropDevice));
struct DevPropDevice *device = NULL;
verbose("LAN Controller [%04x:%04x] :: %s\n", eth_dev->vendor_id, eth_dev->device_id, devicepath);
if (!string)
string = devprop_create_string();
if(!string)
string = devprop_create_string();
device = devprop_add_device(string, devicepath);
if(device)
{
verbose("Setting up lan keys\n");
devprop_add_network_template(device, eth_dev->vendor_id);
stringdata = (uint8_t*)malloc(sizeof(uint8_t) * string->length);
if(stringdata)
{
memcpy(stringdata, (uint8_t*)devprop_generate_string(string), string->length);
stringlength = string->length;
}
device = devprop_add_device(string, devicepath);
if(device) {
verbose("Setting up lan keys\n");
devprop_add_network_template(device, eth_dev->vendor_id);
stringdata = (uint8_t*)malloc(sizeof(uint8_t) * string->length);
if(stringdata) {
memcpy(stringdata, (uint8_t*)devprop_generate_string(string), string->length);
stringlength = string->length;
}
}
}
trunk/i386/libsaio/dram_controllers.c
5757
5858
5959
60
60
6161
6262
6363
// Nehalem supports Scrubbing
// First, locate the PCI bus where the MCH is located
for(i = 0; i < sizeof(possible_nhm_bus); i++)
for(i = 0; i < (sizeof(possible_nhm_bus)/sizeof(possible_nhm_bus[0])); i++)
{
vid = pci_config_read16(PCIADDR(possible_nhm_bus[i], 3, 4), PCI_VENDOR_ID);
did = pci_config_read16(PCIADDR(possible_nhm_bus[i], 3, 4), PCI_DEVICE_ID);
trunk/i386/libsaio/nvidia.c
17021702
17031703
17041704
1705
1706
1707
1708
1705
1706
1707
17091708
17101709
17111710
......
20672066
20682067
20692068
2070
2069
20712070
20722071
20732072
......
21722171
21732172
21742173
2174
21752175
21762176
21772177
{
if (nvidia_card_vendors[j].device == (subsys_id & 0xffff0000))
{
sprintf(name_model, "%s %s",
nvidia_card_vendors[j].name, nvidia_card_generic[i].name);
name_model[sizeof(name_model) - 1] = '\0';
return name_model;
snprintf(name_model, sizeof(name_model), "%s %s",
nvidia_card_vendors[j].name, nvidia_card_generic[i].name);
return name_model;
}
}
}
}
}
sprintf(biosVersion, "%s", (nvBiosOveride > 0) ? nvFilename : version_str);
snprintf(biosVersion, sizeof(biosVersion), "%s", (nvBiosOveride > 0) ? nvFilename : version_str);
sprintf(kNVCAP, "NVCAP_%04x", nvda_dev->device_id);
if (getValueForKey(kNVCAP, &value, &len, &bootInfo->chameleonConfig) && len == NVCAP_LEN * 2)
memcpy(stringdata, (uint8_t*)devprop_generate_string(string), string->length);
stringlength = string->length;
free(version_str);
free(rom);
return true;
}
trunk/i386/libsaio/ntfs.c
272272
273273
274274
275
276
275
277276
278277
279278
}
if (read(fd, buf, mftRecordSize) != mftRecordSize)
{
//verbose("NTFS: error reading MFT $Volume record: %s\n",
strerror(errno));
//verbose("NTFS: error reading MFT $Volume record: %s\n", strerror(errno));
goto error;
}
#endif
trunk/i386/libsaio/pci.c
151151
152152
153153
154
154
155155
156156
157157
......
159159
160160
161161
162
163
164
165
166
167
168
169
170
171
172
173
174
162
163
164
165
166
167
168
169
170
171
172
173
174
175175
176176
177177
......
184184
185185
186186
187
187
188
188189
189190
190191
{
pci_dt_t*current;
pci_dt_t*end;
chartmp[64];
int dev_path_len = 0;
dev_path[0] = 0;
end = root_pci_dev;
int uid = getPciRootUID();
while (end != pci_dt)
{
current = pci_dt;
while (current->parent != end)
current = current->parent;
end = current;
if (current->parent == root_pci_dev)
{
sprintf(tmp, "PciRoot(0x%x)/Pci(0x%x,0x%x)", uid,
current->dev.bits.dev, current->dev.bits.func);
} else {
sprintf(tmp, "/Pci(0x%x,0x%x)",
current->dev.bits.dev, current->dev.bits.func);
}
strcat(dev_path, tmp);
current = pci_dt;
while (current->parent != end)
current = current->parent;
end = current;
if (current->parent == root_pci_dev) {
dev_path_len +=
snprintf(dev_path + dev_path_len, sizeof(dev_path) - dev_path_len, "PciRoot(0x%x)/Pci(0x%x,0x%x)", uid,
current->dev.bits.dev, current->dev.bits.func);
} else {
dev_path_len +=
snprintf(dev_path + dev_path_len, sizeof(dev_path) - dev_path_len, "/Pci(0x%x,0x%x)",
current->dev.bits.dev, current->dev.bits.func);
}
}
return dev_path;
}
while (current) {
printf("%02x:%02x.%x [%04x%02x] [%04x:%04x] (subsys [%04x:%04x]):: %s\n",
current->dev.bits.bus, current->dev.bits.dev, current->dev.bits.func,
current->class_id, current->vendor_id, current->device_id,
current->class_id, 0 /* FIXME: what should this be? */,
current->vendor_id, current->device_id,
current->subsys_id.subsys.vendor_id, current->subsys_id.subsys.device_id,
get_pci_dev_path(current));
dump_pci_dt(current->children);
trunk/i386/libsaio/smbios_getters.c
105105
106106
107107
108
108
109109
110110
111111
// Nehalem supports Scrubbing
// First, locate the PCI bus where the MCH is located
for(i = 0; i < sizeof(possible_nhm_bus); i++)
for(i = 0; i < (sizeof(possible_nhm_bus)/sizeof(possible_nhm_bus[0])); i++)
{
vid = pci_config_read16(PCIADDR(possible_nhm_bus[i], 3, 4), 0x00);
did = pci_config_read16(PCIADDR(possible_nhm_bus[i], 3, 4), 0x02);
trunk/i386/klibc/strlcpy.c
22
33
44
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
523
624
725
8
26
27
28
29
30
31
32
933
10
11
12
13
34
35
36
1437
15
16
17
38
39
40
41
42
43
44
1845
19
20
46
47
48
49
50
51
52
2153
22
23
24
25
26
54
2755
* strlcpy.c
*/
/* Use OpenBSD heritage source -- Chucko 2014-01-06 */
/*-
* Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <string.h>
#include <klibc/compiler.h>
size_t strlcpy(char *dst, const char *src, size_t size)
/*
* Copy src to string dst of size siz. At most siz-1 characters
* will be copied. Always NUL terminates (unless siz == 0).
* Returns strlen(src); if retval >= siz, truncation occurred.
*/
size_t
strlcpy(char * __restrict dst, const char * __restrict src, size_t siz)
{
size_t bytes = 0;
char *q = dst;
const char *p = src;
char ch;
char *d = dst;
const char *s = src;
size_t n = siz;
while ((ch = *p++)) {
if (bytes + 1 < size)
*q++ = ch;
/* Copy as many bytes as will fit */
if (n != 0) {
while (--n != 0) {
if ((*d++ = *s++) == '\0')
break;
}
}
bytes++;
}
/* Not enough room in dst, add NUL and traverse rest of src */
if (n == 0) {
if (siz != 0)
*d = '\0'; /* NUL-terminate dst */
while (*s++)
;
}
/* If size == 0 there is no space for a final null... */
if (size)
*q = '\0';
return bytes;
return(s - src - 1); /* count does not include NUL */
}
trunk/i386/boot2/picopng.c
10971097
10981098
10991099
1100
1101
11021100
11031101
11041102
11051103
1106
1104
1105
1106
1107
1108
1109
1110
1111
1112
11071113
1114
1115
11081116
11091117
11101118
printf("file empty\n");
return 1;
}
insize = (uint32_t) statbuf.st_size;
inbuf = malloc(insize);
infp = fopen(fname, "rb");
if (!infp) {
perror("fopen");
return 1;
} else if (fread(inbuf, 1, insize, infp) != insize) {
}
insize = (uint32_t) statbuf.st_size;
inbuf = malloc(insize);
if (!inbuf) {
perror("malloc");
fclose(infp);
return 1;
}
if (fread(inbuf, 1, insize, infp) != insize) {
perror("fread");
free(inbuf);
fclose(infp);
return 1;
}
fclose(infp);
trunk/i386/boot2/graphics.c
5050
5151
5252
53
54
5553
5654
5755
......
7472
7573
7674
77
78
79
75
76
8077
8178
8279
......
8683
8784
8885
86
87
88
89
8990
9091
91
92
93
94
95
96
92
93
94
95
96
97
98
9799
98100
99101
......
109111
110112
111113
114
112115
113116
114117
......
123126
124127
125128
126
129
130
131
132
133
134
135
136
137
127138
128139
129140
......
173184
174185
175186
187
176188
177189
178190
179
191
192
180193
181194
182195
......
187200
188201
189202
190
191
192
193
203
204
205
206
207
194208
195209
196210
{
VBEInfoBlock vbeInfo;
int err, small;
char *buff = malloc(sizeof(char)*256);
if(!buff) return 0;
bzero( &vbeInfo, sizeof(vbeInfo) );
strcpy( (char*)&vbeInfo, "VBE2" );
{
VBEInfoBlock vbeInfo;
int err, small;
char *buff = malloc(sizeof(char)*256);
if(!buff) return 0;
char* buff = NULL;
bzero( &vbeInfo, sizeof(vbeInfo) );
strcpy( (char*)&vbeInfo, "VBE2" );
err = getVBEInfo( &vbeInfo );
if ( strncmp( (char *)vbeInfo.VESASignature, "VESA", 4 ) )
return 0;
buff = malloc(sizeof(char) * 256);
if (!buff)
return 0;
small = (vbeInfo.TotalMemory < 16);
sprintf(buff, "VESA v%d.%d %d%s (%s)\n",
vbeInfo.VESAVersion >> 8,
vbeInfo.VESAVersion & 0xf,
small ? (vbeInfo.TotalMemory * 64) : (vbeInfo.TotalMemory / 16),
small ? "KB" : "MB",
VBEDecodeFP(const char *, vbeInfo.OEMStringPtr) );
snprintf(buff, 256,
"VESA v%d.%d %d%s (%s)\n",
vbeInfo.VESAVersion >> 8,
vbeInfo.VESAVersion & 0xf,
small ? (vbeInfo.TotalMemory * 64) : (vbeInfo.TotalMemory / 16),
small ? "KB" : "MB",
VBEDecodeFP(const char *, vbeInfo.OEMStringPtr) );
return buff;
}
VBEModeInfoBlock modeInfo;
int err;
int line;
char* vbeInfoString = NULL;
bzero( &vbeInfo, sizeof(vbeInfo) );
strcpy( (char*)&vbeInfo, "VBE2" );
clearScreenRows(0, 24);
setCursorPosition( 0, 0, 1 );
printf( getVBEInfoString() );
vbeInfoString = getVBEInfoString();
if (!vbeInfoString) {
printf("Error: getVBEInfoString failed\n");
return;
}
printf("%s", vbeInfoString);
free(vbeInfoString);
vbeInfoString = NULL;
printf("Video modes supported:\n", VBEDecodeFP(const char *, vbeInfo.OEMStringPtr));
// Loop through the mode list, and find the matching mode.
char *buff=malloc(sizeof(char)*3072);
if(!buff) return 0;
int bufflen = 0;
// Loop through the mode list, and find the matching mode.
for ( modePtr = VBEDecodeFP( unsigned short *, vbeInfo.VideoModePtr );
*modePtr != modeEndOfList; modePtr++ )
(*modePtr != modeEndOfList) && (bufflen < 3072); /* prevent buffer overrun */
modePtr++ )
{
// Get mode information.
continue;
}
sprintf(buff+strlen(buff), "Mode %x: %dx%dx%d mm:%d attr:%x\n",
*modePtr, modeInfo.XResolution, modeInfo.YResolution,
modeInfo.BitsPerPixel, modeInfo.MemoryModel,
modeInfo.ModeAttributes);
bufflen +=
snprintf(buff+bufflen, 3072-bufflen, "Mode %x: %dx%dx%d mm:%d attr:%x\n",
*modePtr, modeInfo.XResolution, modeInfo.YResolution,
modeInfo.BitsPerPixel, modeInfo.MemoryModel,
modeInfo.ModeAttributes);
}
return buff;
trunk/i386/boot2/drivers.c
244244
245245
246246
247
247
248248
249249
250250
251
251
252252
253253
254254
......
278278
279279
280280
281
281
282282
283283
284284
......
289289
290290
291291
292
292
293293
294294
295295
......
336336
337337
338338
339
339
340340
341341
342
342
343343
344344
345345
346346
347347
348
349
348
349
350350
351351
352352
......
383383
384384
385385
386
386
387387
388388
389389
......
436436
437437
438438
439
439
440440
441441
442442
......
460460
461461
462462
463
464
465
466
463
464
465
466
467
468
467469
468470
469471
470472
471473
472474
473
474
475
476
477
478
475479
476480
477481
......
481485
482486
483487
484
485
486
487
488
489
490
491
492
493
488494
489495
490496
......
574580
575581
576582
577
583
578584
579585
580586
......
629635
630636
631637
632
638
633639
634640
635641
else
{
if (gMacOSVersion[3] == '9') {
strcpy(gExtensionsSpec, dirSpec);
strlcpy(gExtensionsSpec, dirSpec, 4087); /* 4096 - sizeof("Library/") */
strcat(gExtensionsSpec, "Library/");
FileLoadDrivers(gExtensionsSpec, 0);
}
strcpy(gExtensionsSpec, dirSpec);
strlcpy(gExtensionsSpec, dirSpec, 4080); /* 4096 - sizeof("System/Library/") */
strcat(gExtensionsSpec, "System/Library/");
FileLoadDrivers(gExtensionsSpec, 0);
}
longret, flags, time, time2;
charaltDirSpec[512];
sprintf (altDirSpec, "%s%s", dirSpec, extDirSpec);
snprintf(altDirSpec, sizeof(altDirSpec), "%s%s", dirSpec, extDirSpec);
ret = GetFileInfo(altDirSpec, "Extensions.mkext", &flags, &time);
if ((ret == 0) && ((flags & kFileTypeMask) == kFileTypeFlat))
|| ((flags & kFileTypeMask) != kFileTypeDirectory)
|| (((gBootMode & kBootModeSafe) == 0) && (time == (time2 + 1))))
{
sprintf(gDriverSpec, "%sExtensions.mkext", altDirSpec);
snprintf(gDriverSpec, sizeof(altDirSpec) + 18, "%sExtensions.mkext", altDirSpec);
verbose("LoadDrivers: Loading from [%s]\n", gDriverSpec);
if (LoadDriverMKext(gDriverSpec) == 0)
if (strcmp(name + length - 5, ".kext")) continue;
// Save the file name.
strcpy(gFileName, name);
strlcpy(gFileName, name, 4096);
// Determine the bundle type.
sprintf(gTempSpec, "%s/%s", dirSpec, gFileName);
snprintf(gTempSpec, 4096, "%s/%s", dirSpec, gFileName);
ret = GetFileInfo(gTempSpec, "Contents", &flags, &time);
if (ret == 0) bundleType = kCFBundleType2;
else bundleType = kCFBundleType3;
if (!plugin)
sprintf(gDriverSpec, "%s/%s/%sPlugIns", dirSpec, gFileName,
(bundleType == kCFBundleType2) ? "Contents/" : "");
snprintf(gDriverSpec, 4096, "%s/%s/%sPlugIns", dirSpec, gFileName,
(bundleType == kCFBundleType2) ? "Contents/" : "");
ret = LoadDriverPList(dirSpec, gFileName, bundleType);
#endif
// INTEL modification
sprintf(gDriverSpec, "%s%s.mkext", dirSpec, bootInfo->bootFile);
snprintf(gDriverSpec, 4096, "%s%s.mkext", dirSpec, bootInfo->bootFile);
verbose("NetLoadDrivers: Loading from [%s]\n", gDriverSpec);
memcpy((void *)driversAddr, (void *)package, driversLength);
// Add the MKext to the memory map.
sprintf(segName, "DriversPackage-%lx", driversAddr);
snprintf(segName, sizeof(segName), "DriversPackage-%lx", driversAddr);
AllocateMemoryRange(segName, driversAddr, driversLength,
kBootDriverTypeMKEXT);
do {
// Save the driver path.
if(name) sprintf(gFileSpec, "%s/%s/%s", dirSpec, name,
(bundleType == kCFBundleType2) ? "Contents/MacOS/" : "");
else sprintf(gFileSpec, "%s/%s", dirSpec,
(bundleType == kCFBundleType2) ? "Contents/MacOS/" : "");
if(name)
snprintf(gFileSpec, 4096, "%s/%s/%s", dirSpec, name,
(bundleType == kCFBundleType2) ? "Contents/MacOS/" : "");
else
snprintf(gFileSpec, 4096, "%s/%s", dirSpec,
(bundleType == kCFBundleType2) ? "Contents/MacOS/" : "");
executablePathLength = strlen(gFileSpec) + 1;
tmpExecutablePath = malloc(executablePathLength);
if (tmpExecutablePath == 0) break;
strcpy(tmpExecutablePath, gFileSpec);
if(name) sprintf(gFileSpec, "%s/%s", dirSpec, name);
else sprintf(gFileSpec, "%s", dirSpec);
if(name)
snprintf(gFileSpec, 4096, "%s/%s", dirSpec, name);
else
snprintf(gFileSpec, 4096, "%s", dirSpec);
bundlePathLength = strlen(gFileSpec) + 1;
tmpBundlePath = malloc(bundlePathLength);
// Construct the file spec to the plist, then load it.
if(name) sprintf(gFileSpec, "%s/%s/%sInfo.plist", dirSpec, name,
(bundleType == kCFBundleType2) ? "Contents/" : "");
else sprintf(gFileSpec, "%s/%sInfo.plist", dirSpec,
(bundleType == kCFBundleType2) ? "Contents/" : "");
if(name)
snprintf(gFileSpec, 4096, "%s/%s/%sInfo.plist", dirSpec, name,
(bundleType == kCFBundleType2) ? "Contents/" : "");
else
snprintf(gFileSpec, 4096, "%s/%sInfo.plist", dirSpec,
(bundleType == kCFBundleType2) ? "Contents/" : "");
length = LoadFile(gFileSpec);
if (length == -1) break;
if (prop != 0)
{
fileName = prop->string;
sprintf(gFileSpec, "%s%s", module->executablePath, fileName);
snprintf(gFileSpec, 4096, "%s%s", module->executablePath, fileName);
length = LoadThinFatFile(gFileSpec, &executableAddr);
if (length == 0)
{
strcpy(driver->bundlePathAddr, module->bundlePath);
// Add an entry to the memory map.
sprintf(segName, "Driver-%lx", (unsigned long)driver);
snprintf(segName, sizeof(segName), "Driver-%lx", (unsigned long)driver);
AllocateMemoryRange(segName, driverAddr, driverLength,
kBootDriverTypeKEXT);
}
trunk/i386/boot2/boot.c
247247
248248
249249
250
250
251251
252252
253253
254
255
256
254
255
256
257257
258
259
258
259
260260
261
262
263
264
265
266
267
268
269
270
271
261
262
263
264
265
266
267
268
269
270
271
272
272273
273274
274
275
276
277
278
275
276
277
278
279
280
281
279282
280283
281284
......
284287
285288
286289
287
288
289
290
291
292
293
294
295
296
297
298
299
300
290
291
292
293
294
295
296
297
298
299
300
301
301302
302303
303304
304
305
306
307
305
306
307
308
308309
309310
310311
......
616617
617618
618619
619
620
621
620622
621623
622624
......
654656
655657
656658
657
659
658660
659661
660662
661663
662664
663665
664
666
665667
666668
667669
668
670
669671
670672
671673
672
674
673675
674676
675677
676678
677679
678680
679
681
680682
681683
682684
......
754756
755757
756758
757
759
758760
759761
760762
// Lion, Mountain Lion and Mavericks prelink kernel cache file
if ((checkOSVersion("10.7")) || (checkOSVersion("10.8")) || (checkOSVersion("10.9")))
{
sprintf(kernelCacheFile, "%skernelcache", kDefaultCachePathSnow);
snprintf(kernelCacheFile, sizeof(kernelCacheFile), "%skernelcache", kDefaultCachePathSnow);
}
// Snow Leopard prelink kernel cache file
else if (checkOSVersion("10.6")) {
sprintf(kernelCacheFile, "kernelcache_%s", (archCpuType == CPU_TYPE_I386)
? "i386" : "x86_64");
int lnam = strlen(kernelCacheFile) + 9; //with adler32
snprintf(kernelCacheFile, sizeof(kernelCacheFile), "kernelcache_%s",
(archCpuType == CPU_TYPE_I386) ? "i386" : "x86_64");
int lnam = strlen(kernelCacheFile) + 9; //with adler32
char* name;
long prev_time = 0;
char* name;
long prev_time = 0;
struct dirstuff* cacheDir = opendir(kDefaultCachePathSnow);
while(readdir(cacheDir, (const char**)&name, &flags, &time) >= 0)
{
if (((flags & kFileTypeMask) != kFileTypeDirectory) && time > prev_time
&& strstr(name, kernelCacheFile) && (name[lnam] != '.'))
{
sprintf(kernelCacheFile, "%s%s", kDefaultCachePathSnow, name);
prev_time = time;
}
}
struct dirstuff* cacheDir = opendir(kDefaultCachePathSnow);
/* TODO: handle error? */
if (cacheDir) {
while (readdir(cacheDir, (const char**)&name, &flags, &time) >= 0) {
if (((flags & kFileTypeMask) != kFileTypeDirectory) && time > prev_time
&& strstr(name, kernelCacheFile) && (name[lnam] != '.')) {
snprintf(kernelCacheFile, sizeof(kernelCacheFile), "%s%s", kDefaultCachePathSnow, name);
prev_time = time;
}
}
}
closedir(cacheDir);
}
else {
// Reset cache name.
bzero(gCacheNameAdler + 64, sizeof(gCacheNameAdler) - 64);
sprintf(gCacheNameAdler + 64, "%s,%s", gRootDevice, bootInfo->bootFile);
adler32 = Adler32((unsigned char *)gCacheNameAdler, sizeof(gCacheNameAdler));
sprintf(kernelCacheFile, "%s.%08lX", kDefaultCachePathLeo, adler32);
// Reset cache name.
bzero(gCacheNameAdler + 64, sizeof(gCacheNameAdler) - 64);
snprintf(gCacheNameAdler + 64, sizeof(gCacheNameAdler) - 64,
"%s,%s",
gRootDevice, bootInfo->bootFile);
adler32 = Adler32((unsigned char *)gCacheNameAdler, sizeof(gCacheNameAdler));
snprintf(kernelCacheFile, sizeof(kernelCacheFile), "%s.%08lX", kDefaultCachePathLeo, adler32);
}
}
// If boot from a boot helper partition check the kernel cache file on it
if (gBootVolume->flags & kBVFlagBooter) {
sprintf(kernelCachePath, "com.apple.boot.P%s", kernelCacheFile);
ret = GetFileInfo(NULL, kernelCachePath, &flags, &cachetime);
if ((ret == -1) || ((flags & kFileTypeMask) != kFileTypeFlat))
{
sprintf(kernelCachePath, "com.apple.boot.R%s", kernelCacheFile);
ret = GetFileInfo(NULL, kernelCachePath, &flags, &cachetime);
if ((ret == -1) || ((flags & kFileTypeMask) != kFileTypeFlat))
{
sprintf(kernelCachePath, "com.apple.boot.S%s", kernelCacheFile);
ret = GetFileInfo(NULL, kernelCachePath, &flags, &cachetime);
if ((flags & kFileTypeMask) != kFileTypeFlat)
ret = -1;
}
}
snprintf(kernelCachePath, sizeof(kernelCachePath), "com.apple.boot.P%s", kernelCacheFile);
ret = GetFileInfo(NULL, kernelCachePath, &flags, &cachetime);
if ((ret == -1) || ((flags & kFileTypeMask) != kFileTypeFlat)) {
snprintf(kernelCachePath, sizeof(kernelCachePath), "com.apple.boot.R%s", kernelCacheFile);
ret = GetFileInfo(NULL, kernelCachePath, &flags, &cachetime);
if ((ret == -1) || ((flags & kFileTypeMask) != kFileTypeFlat)) {
snprintf(kernelCachePath, sizeof(kernelCachePath), "com.apple.boot.S%s", kernelCacheFile);
ret = GetFileInfo(NULL, kernelCachePath, &flags, &cachetime);
if ((flags & kFileTypeMask) != kFileTypeFlat)
ret = -1;
}
}
}
// If not found, use the original kernel cache path.
if (ret == -1) {
strcpy(kernelCachePath, kernelCacheFile);
ret = GetFileInfo(NULL, kernelCachePath, &flags, &cachetime);
if ((flags & kFileTypeMask) != kFileTypeFlat)
ret = -1;
strlcpy(kernelCachePath, kernelCacheFile, sizeof(kernelCachePath));
ret = GetFileInfo(NULL, kernelCachePath, &flags, &cachetime);
if ((flags & kFileTypeMask) != kFileTypeFlat)
ret = -1;
}
// Exit if kernel cache file wasn't found
len--;
val++;
}
strlcpy(kernelCacheFile, val, len + 1);
/* FIXME: check len vs sizeof(kernelCacheFile) */
strlcpy(kernelCacheFile, val, len + 1);
} else {
kernelCacheFile[0] = 0; // Use default kernel cache file
}
// bootFile must start with a / if it not start with a device name
if (!bootFileWithDevice && (bootInfo->bootFile)[0] != '/')
sprintf(bootFile, "/%s", bootInfo->bootFile); // append a leading /
snprintf(bootFile, sizeof(bootFile), "/%s", bootInfo->bootFile); // append a leading /
else
strlcpy(bootFile, bootInfo->bootFile, sizeof(bootFile));
// Try to load kernel image from alternate locations on boot helper partitions.
ret = -1;
if ((gBootVolume->flags & kBVFlagBooter) && !bootFileWithDevice) {
sprintf(bootFilePath, "com.apple.boot.P%s", bootFile);
snprintf(bootFilePath, sizeof(bootFilePath), "com.apple.boot.P%s", bootFile);
ret = GetFileInfo(NULL, bootFilePath, &flags, &time);
if (ret == -1)
{
sprintf(bootFilePath, "com.apple.boot.R%s", bootFile);
snprintf(bootFilePath, sizeof(bootFilePath), "com.apple.boot.R%s", bootFile);
ret = GetFileInfo(NULL, bootFilePath, &flags, &time);
if (ret == -1)
{
sprintf(bootFilePath, "com.apple.boot.S%s", bootFile);
snprintf(bootFilePath, sizeof(bootFilePath), "com.apple.boot.S%s", bootFile);
ret = GetFileInfo(NULL, bootFilePath, &flags, &time);
}
}
}
if (ret == -1) {
// No alternate location found, using the original kernel image path.
strlcpy(bootFilePath, bootFile,sizeof(bootFilePath));
strlcpy(bootFilePath, bootFile, sizeof(bootFilePath));
}
verbose("Loading kernel %s\n", bootFilePath);
static void getOSVersion()
{
strlcpy(gMacOSVersion, gBootVolume->OSVersion, sizeof(gMacOSVersion));
strncpy(gMacOSVersion, gBootVolume->OSVersion, sizeof(gMacOSVersion));
}
#define BASE 65521L /* largest prime smaller than 65536 */
trunk/i386/boot2/modules.c
105105
106106
107107
108
108
109109
110
110
111111
112112
113113
114114
115
115
116116
117117
118118
......
122122
123123
124124
125
126125
126
127127
128128
129129
......
143143
144144
145145
146
146
147147
148148
149149
......
982982
983983
984984
985
986985
987
988
989986
990987
991
992
993
994
995
996
997
988
989
990
991
992
993
994
995
998996
999997
1000998
long flags;
long time;
struct dirstuff* moduleDir = opendir("/Extra/modules/");
while(readdir(moduleDir, (const char**)&name, &flags, &time) >= 0)
while (readdir(moduleDir, (const char**)&name, &flags, &time) >= 0)
{
if(strcmp(&name[strlen(name) - sizeof("dylib")], ".dylib") == 0)
if (strcmp(&name[strlen(name) - sizeof("dylib")], ".dylib") == 0)
{
char* tmp = malloc(strlen(name) + 1);
strcpy(tmp, name);
if(!load_module(tmp))
if (!load_module(tmp))
{
// failed to load
// free(tmp);
{
DBG("Ignoring %s\n", name);
}
}
closedir(moduleDir);
}
return 1;
}
sprintf(modString, MODULE_PATH "%s", module);
snprintf(modString, sizeof(modString), MODULE_PATH "%s", module);
fh = open(modString, 0);
if(fh < 0)
{
*/
int replace_function(const char* symbol, void* newAddress)
{
UInt32* jumpPointer = malloc(sizeof(UInt32*));
UInt32 addr = lookup_all_symbols(symbol);
char* binary = (char*)addr;
if(addr != 0xFFFFFFFF)
{
//DBG("Replacing %s to point to 0x%x\n", symbol, newAddress);
*binary++ = 0xFF;// Jump
*binary++ = 0x25;// Long Jump
*((UInt32*)binary) = (UInt32)jumpPointer;
*jumpPointer = (UInt32)newAddress;
return 1;
//DBG("Replacing %s to point to 0x%x\n", symbol, newAddress);
UInt32* jumpPointer = malloc(sizeof(UInt32*));
char* binary = (char*)addr;
*binary++ = 0xFF;// Jump
*binary++ = 0x25;// Long Jump
*((UInt32*)binary) = (UInt32)jumpPointer;
*jumpPointer = (UInt32)newAddress;
return 1;
}
return 0;
}
trunk/i386/boot2/gui.c
18111811
18121812
18131813
1814
18141815
18151816
18161817
currentline = lines - visiblelines;
}
}
free(text);
}
void animateProgressBar()
trunk/i386/boot2/ramdisk.c
2929
3030
3131
32
32
3333
3434
3535
3636
37
37
3838
3939
4040
4141
42
42
4343
4444
4545
......
151151
152152
153153
154
154
155155
156156
157157
......
182182
183183
184184
185
185
186186
187187
188188
&bootInfo->chameleonConfig))
{
// Use user specified md0 file
sprintf(filename, "%s", override_filename);
snprintf(filename, sizeof(filename), "%s", override_filename);
fh = open(filename, 0);
if(fh < 0)
{
sprintf(filename, "rd(0,0)/Extra/%s", override_filename);
snprintf(filename, sizeof(filename), "rd(0,0)/Extra/%s", override_filename);
fh = open(filename, 0);
if(fh < 0)
{
sprintf(filename, "/Extra/%s", override_filename);
snprintf(filename, sizeof(filename), "/Extra/%s", override_filename);
fh = open(filename, 0);
}
}
if (error == 0)
{
// Save filename in gRAMDiskFile to display information.
strcpy(gRAMDiskFile, param);
strlcpy(gRAMDiskFile, param, sizeof(gRAMDiskFile));
// Set gMI as well for the multiboot ramdisk driver hook.
gMI = gRAMDiskMI = malloc(sizeof(multiboot_info));
char dirSpec[128];
// Reading ramdisk configuration.
strcpy(dirSpec, RAMDISKCONFIG_FILENAME);
strlcpy(dirSpec, RAMDISKCONFIG_FILENAME, sizeof(dirSpec));
if (loadConfigFile(dirSpec, &bootInfo->ramdiskConfig) == 0)
{
trunk/i386/boot2/options.c
641641
642642
643643
644
645
646
647
644
645
646
647
648
648649
649
650
651
652
653
654
655
656
657
658
659
660
661
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
662666
663667
664668
char *getMemoryInfoString()
{
int i;
MemoryRange *mp = bootInfo->memoryMap;
char *buff = malloc(sizeof(char)*1024);
if(!buff) return 0;
int i, bufflen;
MemoryRange *mp = bootInfo->memoryMap;
char *buff = malloc(sizeof(char)*1024);
if (!buff)
return 0;
char info[] = "BIOS reported memory ranges:\n";
sprintf(buff, "%s", info);
for (i=0; i<bootInfo->memoryMapCount; i++) {
sprintf( buff+strlen(buff), "Base 0x%08x%08x, ",
(unsigned long)(mp->base >> 32),
(unsigned long)(mp->base));
sprintf( buff+strlen(buff), "length 0x%08x%08x, type %d\n",
(unsigned long)(mp->length >> 32),
(unsigned long)(mp->length),
mp->type);
mp++;
}
return buff;
static const char info[] = "BIOS reported memory ranges:\n";
bufflen = sprintf(buff, "%s", info);
for (i = 0;
(i < bootInfo->memoryMapCount) && (bufflen < 1024); /* prevent buffer overflow */
i++) {
bufflen += snprintf(buff+bufflen, 1024-bufflen, "Base 0x%08x%08x, ",
(unsigned long)(mp->base >> 32),
(unsigned long)(mp->base));
bufflen += snprintf(buff+bufflen, 1024-bufflen, "length 0x%08x%08x, type %d\n",
(unsigned long)(mp->length >> 32),
(unsigned long)(mp->length),
mp->type);
mp++;
}
return buff;
}
//==========================================================================
trunk/i386/config/symbol.c
881881
882882
883883
884
885
884
885
886
887
888
889
890
886891
887892
888893
newlen = strlen(res) + strlen(symval) + strlen(src) + 1;
if (newlen > reslen) {
reslen = newlen;
res = realloc(res, reslen);
char* newres = NULL;
if (!(newres = realloc(res, newlen))) {
/* TODO: handle error gracefully - for now, punt */
break;
}
res = newres;
reslen = newlen;
}
strcat(res, symval);
trunk/i386/config/lex.zconf.c
822822
823823
824824
825
826
827
828
825
826
827
828
829
829830
831
832
833
830834
831835
832836
{
int new_size = text_size + size + 1;
if (new_size > text_asize) {
new_size += START_STRSIZE - 1;
new_size &= -START_STRSIZE;
text = realloc(text, new_size);
text_asize = new_size;
char* new_text = NULL;
new_size += START_STRSIZE - 1;
new_size &= -START_STRSIZE;
if (!(new_text = realloc(text, new_size))) {
return;
}
text = new_text;
text_asize = new_size;
}
memcpy(text + text_size, str, size);
text_size += size;
text[text_size] = 0;
trunk/i386/config/confdata.c
810810
811811
812812
813
813
814814
815815
816816
......
902902
903903
904904
905
905906
906907
907908
}
out_inc = fopen(".tmpconfig.inc", "w");
if (!out_h) {
if (!out_inc) {
fclose(out);
fclose(out_h);
return 1;
}
fclose(out);
fclose(out_h);
fclose(out_inc);
name = getenv("CCONFIG_AUTOHEADER");
if (!name) name = "autoconf.h";
trunk/i386/modules/Keylayout/layouts/cham-mklayout.c
363363
364364
365365
366
366
367367
368
369
370
368371
369372
370373
}
struct keyboard_layout* new_layout = create_keylayout(in);
if (new_layout)
if (new_layout) {
write_layout(new_layout, out);
free(new_layout);
new_layout = NULL;
}
fclose(out);
fclose(in);
trunk/i386/libsa/libsa.h
136136
137137
138138
139
139140
140141
141142
* printf.c
*/
extern int sprintf(char *s, const char * format, ...);
extern int snprintf(char *s, size_t size, const char * format, ...);
extern int slvprintf(char * buffer, int len, const char * fmt, va_list arg);
/*
trunk/i386/libsa/printf.c
6363
6464
6565
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
6681
6782
6883
}
/*VARARGS1*/
int snprintf(char * str, size_t size, const char * fmt, ...)
{
va_list ap;
struct putc_info pi;
va_start(ap, fmt);
pi.str = str;
pi.last_str = str + size - 1;
prf(fmt, ap, sputc, &pi);
*pi.str = '\0';
va_end(ap);
return (pi.str - str);
}
/*VARARGS1*/
int slvprintf(char * str, int len, const char * fmt, va_list ap)
{
struct putc_info pi;
trunk/i386/libsa/string.c
161161
162162
163163
164
164
165
166
167
165168
166169
167170
{
register char *ret = s1;
while (n && (*s1++ = *s2++))
n--;
--n;
/* while (n--) *s1++ = '\0'; */
if (n > 0)
bzero(s1, n);
return ret;
}

Archive Download the corresponding diff file

Revision: 2318