Changeset 80963
- Timestamp:
- 07/21/11 22:10:06 (4 years ago)
- Location:
- branches/gsoc11-post-destroot/base/src
- Files:
-
- 2 edited
-
pextlib1.0/macho.c (modified) (19 diffs)
-
port1.0/portcheckdestroot.tcl (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/gsoc11-post-destroot/base/src/pextlib1.0/macho.c
r80883 r80963 20 20 21 21 #include "macho.h" 22 Tcl_Interp *interp2;23 22 typedef struct macho_input { 24 23 const void *data; … … 58 57 59 58 /* Parse a Mach-O header */ 60 Tcl_Obj * list_macho_dlibs_l (macho_input_t *input, Tcl_Obj * dlibs) {59 Tcl_Obj * list_macho_dlibs_l(macho_input_t *input, Tcl_Interp * interp, Tcl_Obj * dlibs) { 61 60 /* Read the file type. */ 62 61 const uint32_t *magic = macho_read(input, input->data, sizeof(uint32_t)); … … 79 78 80 79 if (magic == NULL) 81 return TCL_ERROR;80 return (Tcl_Obj *)TCL_ERROR; 82 81 83 82 switch (*magic) { … … 118 117 119 118 default: 120 return TCL_ERROR;119 return (Tcl_Obj *)TCL_ERROR; 121 120 } 122 121 … … 142 141 143 142 /* Parse the architecture's Mach-O header */ 144 if (!list_macho_dlibs_l(&arch_input, dlibs))143 if (!list_macho_dlibs_l(&arch_input, interp, dlibs)) 145 144 return false; 146 145 } … … 155 154 cmd = macho_offset(input, header, header_size, sizeof(struct load_command)); 156 155 if (cmd == NULL) 157 return TCL_ERROR;156 return (Tcl_Obj *)TCL_ERROR; 158 157 ncmds = swap32(header->ncmds); 159 158 … … 162 161 /* Load the full command */ 163 162 uint32_t cmdsize = swap32(cmd->cmdsize); 163 uint32_t cmd_type = swap32(cmd->cmd); 164 size_t pathlen; 165 const void * pathptr; 166 char * path; 167 size_t namelen; 168 const void *nameptr; 169 char *name; 170 164 171 cmd = macho_read(input, cmd, cmdsize); 165 172 if (cmd == NULL) 166 return TCL_ERROR;173 return (Tcl_Obj *)TCL_ERROR; 167 174 168 175 /* Handle known types */ 169 uint32_t cmd_type = swap32(cmd->cmd);170 176 switch (cmd_type) { 171 177 case LC_RPATH: { 172 178 /* Fetch the path */ 173 179 if (cmdsize < sizeof(struct rpath_command)) { 174 return TCL_ERROR;180 return (Tcl_Obj *)TCL_ERROR; 175 181 } 176 182 177 size_tpathlen = cmdsize - sizeof(struct rpath_command);178 const void *pathptr = macho_offset(input, cmd, sizeof(struct rpath_command), pathlen);183 pathlen = cmdsize - sizeof(struct rpath_command); 184 pathptr = macho_offset(input, cmd, sizeof(struct rpath_command), pathlen); 179 185 if (pathptr == NULL) 180 return TCL_ERROR;181 182 char *path = malloc(pathlen);186 return (Tcl_Obj *)TCL_ERROR; 187 188 path = malloc(pathlen); 183 189 strlcpy(path, pathptr, pathlen); 184 190 free(path); … … 190 196 case LC_REEXPORT_DYLIB: 191 197 case LC_LOAD_DYLIB: { 192 const struct dylib_command *dylib_cmd = (const struct dylib_command *) cmd;193 194 198 /* Extract the install name */ 195 199 if (cmdsize < sizeof(struct dylib_command)) { 196 return TCL_ERROR;200 return (Tcl_Obj *)TCL_ERROR; 197 201 } 198 202 199 size_tnamelen = cmdsize - sizeof(struct dylib_command);200 const void *nameptr = macho_offset(input, cmd, sizeof(struct dylib_command), namelen);203 namelen = cmdsize - sizeof(struct dylib_command); 204 nameptr = macho_offset(input, cmd, sizeof(struct dylib_command), namelen); 201 205 if (nameptr == NULL) 202 return TCL_ERROR;203 204 char *name = malloc(namelen);206 return (Tcl_Obj *)TCL_ERROR; 207 208 name = malloc(namelen); 205 209 strlcpy(name, nameptr, namelen); 206 210 207 211 /* This is a dyld library identifier */ 208 Tcl_ListObjAppendElement(interp 2, dlibs, Tcl_NewStringObj(name, -1));212 Tcl_ListObjAppendElement(interp, dlibs, Tcl_NewStringObj(name, -1)); 209 213 210 214 free(name); … … 219 223 cmd = macho_offset(input, cmd, cmdsize, sizeof(struct load_command)); 220 224 if (cmd == NULL) 221 return TCL_ERROR;225 return (Tcl_Obj *)TCL_ERROR; 222 226 } 223 227 … … 225 229 } 226 230 227 Tcl_Obj * list_macho_dlibs(macho_input_t *input ) {228 return list_macho_dlibs_l(input, Tcl_NewListObj(0,NULL));231 Tcl_Obj * list_macho_dlibs(macho_input_t *input, Tcl_Interp *interp) { 232 return list_macho_dlibs_l(input, interp, Tcl_NewListObj(0,NULL)); 229 233 } 230 234 231 235 /* List Mach-O archs */ 232 Tcl_Obj * list_macho_archs_l(macho_input_t *input, Tcl_Obj * archs_list) { 236 Tcl_Obj * list_macho_archs_l(macho_input_t *input, Tcl_Interp *interp, Tcl_Obj * archs_list) { 237 const struct mach_header *header; 238 const struct mach_header_64 *header64; 239 size_t header_size; 240 const NXArchInfo *archInfo; 241 const struct fat_header *fat_header; 242 243 /* Parse the Mach-O header */ 244 bool universal = false; 245 uint32_t (*swap32)(uint32_t) = macho_nswap32; 246 233 247 /* Read the file type. */ 234 248 const uint32_t *magic = macho_read(input, input->data, sizeof(uint32_t)); … … 236 250 return false; 237 251 238 /* Parse the Mach-O header */ 239 bool universal = false; 240 uint32_t (*swap32)(uint32_t) = macho_nswap32; 241 242 const struct mach_header *header; 243 const struct mach_header_64 *header64; 244 size_t header_size; 245 const struct fat_header *fat_header; 252 246 253 247 254 switch (*magic) { … … 254 261 header = macho_read(input, input->data, header_size); 255 262 if (header == NULL) { 256 return TCL_ERROR;263 return (Tcl_Obj *)TCL_ERROR; 257 264 } 258 265 break; … … 267 274 header64 = macho_read(input, input->data, sizeof(*header64)); 268 275 if (header64 == NULL) 269 return TCL_ERROR;276 return (Tcl_Obj *)TCL_ERROR; 270 277 271 278 /* The 64-bit header is a direct superset of the 32-bit header */ … … 281 288 282 289 default: 283 return TCL_ERROR;290 return (Tcl_Obj *)TCL_ERROR; 284 291 } 285 292 … … 288 295 uint32_t nfat = OSSwapBigToHostInt32(fat_header->nfat_arch); 289 296 const struct fat_arch *archs = macho_offset(input, fat_header, sizeof(struct fat_header), sizeof(struct fat_arch)); 297 uint32_t i; 298 const struct fat_arch *arch; 299 macho_input_t arch_input; 300 290 301 if (archs == NULL) 291 return TCL_ERROR; 292 293 uint32_t i; 302 return (Tcl_Obj *)TCL_ERROR; 303 294 304 for (i = 0; i < nfat; i++) { 295 const struct fat_arch *arch = macho_read(input, archs + i, sizeof(struct fat_arch));305 arch = macho_read(input, archs + i, sizeof(struct fat_arch)); 296 306 if (arch == NULL) 297 return TCL_ERROR;307 return (Tcl_Obj *)TCL_ERROR; 298 308 299 309 /* Fetch a pointer to the architecture's Mach-O header. */ 300 macho_input_t arch_input;301 310 arch_input.length = OSSwapBigToHostInt32(arch->size); 302 311 arch_input.data = macho_offset(input, input->data, OSSwapBigToHostInt32(arch->offset), arch_input.length); 303 312 if (arch_input.data == NULL) 304 return TCL_ERROR;313 return (Tcl_Obj *)TCL_ERROR; 305 314 306 315 /* Parse the architecture's Mach-O header */ 307 if (!list_macho_archs_l(&arch_input, archs_list))308 return TCL_ERROR;316 if (!list_macho_archs_l(&arch_input, interp, archs_list)) 317 return (Tcl_Obj *)TCL_ERROR; 309 318 } 310 319 … … 313 322 314 323 /* Fetch the arch name */ 315 const NXArchInfo *archInfo = NXGetArchInfoFromCpuType(swap32(header->cputype), swap32(header->cpusubtype));324 archInfo = NXGetArchInfoFromCpuType(swap32(header->cputype), swap32(header->cpusubtype)); 316 325 if (archInfo != NULL) { 317 Tcl_ListObjAppendElement(interp 2, archs_list, Tcl_NewStringObj(archInfo->name,-1));326 Tcl_ListObjAppendElement(interp, archs_list, Tcl_NewStringObj(archInfo->name,-1)); 318 327 } 319 328 return archs_list; 320 329 } 321 330 322 Tcl_Obj * list_macho_archs(macho_input_t *input ) {323 return list_macho_archs_l(input, Tcl_NewListObj(0,NULL));324 } 325 326 int list_dlibs(ClientData clientData , Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]){331 Tcl_Obj * list_macho_archs(macho_input_t *input, Tcl_Interp *interp) { 332 return list_macho_archs_l(input, interp, Tcl_NewListObj(0,NULL)); 333 } 334 335 int list_dlibs(ClientData clientData __attribute__((unused)) , Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]){ 327 336 const char *path; 328 interp2 = interp; 337 int fd; 338 struct stat stbuf; 339 void * data; 340 Tcl_Obj * libs; 341 macho_input_t input_file; 342 343 329 344 330 345 if (objc != 2) { … … 335 350 path = Tcl_GetString(objv[1]); 336 351 337 intfd = open(path, O_RDONLY);352 fd = open(path, O_RDONLY); 338 353 if (fd < 0) { 339 354 return TCL_ERROR; 340 355 } 341 356 357 if (fstat(fd, &stbuf) != 0) { 358 return TCL_ERROR; 359 } 360 361 /* mmap */ 362 data = mmap(NULL, stbuf.st_size, PROT_READ, MAP_FILE|MAP_PRIVATE, fd, 0); 363 if (data != MAP_FAILED){ 364 /* Parse */ 365 input_file.data = data; 366 input_file.length = stbuf.st_size; 367 368 libs = list_macho_dlibs(&input_file, interp); 369 370 munmap(data, stbuf.st_size); 371 } 372 else{ 373 libs = (Tcl_Obj *)TCL_ERROR; 374 } 375 close(fd); 376 377 378 if(libs == (Tcl_Obj *)TCL_ERROR){ 379 Tcl_SetObjResult(interp, Tcl_NewListObj(0,NULL)); 380 } 381 else{ 382 Tcl_SetObjResult(interp, libs); 383 } 384 return TCL_OK; 385 } 386 387 388 int list_archs(ClientData clientData __attribute__((unused)), Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]){ 389 const char *path; 390 int fd; 342 391 struct stat stbuf; 343 if (fstat(fd, &stbuf) != 0) { 344 return TCL_ERROR; 345 } 346 347 /* mmap */ 348 void *data = mmap(NULL, stbuf.st_size, PROT_READ, MAP_FILE|MAP_PRIVATE, fd, 0); 349 if (data == MAP_FAILED) 350 return TCL_ERROR; 351 352 /* Parse */ 392 void * data; 393 Tcl_Obj * archs; 353 394 macho_input_t input_file; 354 input_file.data = data;355 input_file.length = stbuf.st_size;356 357 Tcl_Obj * libs = list_macho_dlibs(&input_file);358 359 munmap(data, stbuf.st_size);360 close(fd);361 Tcl_SetObjResult(interp, libs);362 return TCL_OK;363 }364 365 366 int list_archs(ClientData clientData , Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]){367 interp2 = interp;368 const char *path;369 395 370 396 if (objc != 2) { … … 375 401 path = Tcl_GetString(objv[1]); 376 402 377 intfd = open(path, O_RDONLY);403 fd = open(path, O_RDONLY); 378 404 if (fd < 0) { 379 405 return TCL_ERROR; 380 406 } 381 407 382 struct stat stbuf;383 408 if (fstat(fd, &stbuf) != 0) { 384 409 return TCL_ERROR; … … 386 411 387 412 /* mmap */ 388 void *data = mmap(NULL, stbuf.st_size, PROT_READ, MAP_FILE|MAP_PRIVATE, fd, 0); 389 if (data == MAP_FAILED) 390 return TCL_ERROR; 391 392 /* Parse */ 393 macho_input_t input_file; 394 input_file.data = data; 395 input_file.length = stbuf.st_size; 396 397 Tcl_Obj * archs = list_macho_archs(&input_file); 398 399 munmap(data, stbuf.st_size); 413 data = mmap(NULL, stbuf.st_size, PROT_READ, MAP_FILE|MAP_PRIVATE, fd, 0); 414 if (data != MAP_FAILED){ 415 /* Parse */ 416 input_file.data = data; 417 input_file.length = stbuf.st_size; 418 419 archs = list_macho_archs(&input_file, interp); 420 421 munmap(data, stbuf.st_size); 422 } 423 else{ 424 archs = (Tcl_Obj *)TCL_ERROR; 425 } 400 426 close(fd); 401 Tcl_SetObjResult(interp, archs); 427 428 if(archs == (Tcl_Obj *)TCL_ERROR) 429 Tcl_SetObjResult(interp, Tcl_NewListObj(0,NULL)); 430 else 431 Tcl_SetObjResult(interp, archs); 402 432 return TCL_OK; 403 433 } -
branches/gsoc11-post-destroot/base/src/port1.0/portcheckdestroot.tcl
r80618 r80963 39 39 proc portcheckdestroot::get_port_files {portname} { 40 40 } 41 42 # Check if a file is binary file43 # TODO: Somewhat probabilistic. Must be a better way.44 proc portcheckdestroot::binary? filename {45 set f [open $filename]46 set data [read $f 1024]47 close $f48 expr {[string first \x00 $data]>=0}49 }50 51 41 52 42 # escape chars in order to be usable as regexp. This function is for internal use. … … 249 239 #Get package files 250 240 foreach file [files_list $destroot] { 251 if { [binary? "$file"] }{252 foreach file_lib [list_dlibs $file]{241 foreach file_lib [list_dlibs $file] { 242 if { ! [regexp $file_lib $file] } { 253 243 if { [lsearch $dep_files $file_lib] != -1 } { 254 244 ui_debug "$file_lib binary dependency is met" … … 277 267 global destroot 278 268 foreach file [files_list $destroot] { 279 if { [binary? "$file"] } { 280 set file_archs [list_archs $file] 281 foreach arch $archs { 282 if { [lsearch $file_archs $arch] == -1 } { 283 return -code error "$file supports the arch $arch, and should not" 284 } 269 set file_archs [list_archs $file] 270 foreach arch $file_archs { 271 if { [lsearch $arch $archs] == -1 } { 272 return -code error "$file supports the arch $arch, and should not" 285 273 } 286 274 }
Note: See TracChangeset
for help on using the changeset viewer.

