comparison src/ntproc.c @ 400:a86b2b5e0111 r21-2-30

Import from CVS: tag r21-2-30
author cvs
date Mon, 13 Aug 2007 11:14:34 +0200
parents 74fd4e045ea6
children 2f8bb876ab1d
comparison
equal deleted inserted replaced
399:376370fb5946 400:a86b2b5e0111
531 531
532 exe_header = (FILHDR*) executable.file_base; 532 exe_header = (FILHDR*) executable.file_base;
533 if (exe_header->e_magic != DOSMAGIC) 533 if (exe_header->e_magic != DOSMAGIC)
534 goto unwind; 534 goto unwind;
535 535
536 if ((char *) exe_header->e_lfanew > (char *) executable.size) 536 if ((char*) exe_header->e_lfanew > (char*) executable.size)
537 { 537 {
538 /* Some dos headers (pkunzip) have bogus e_lfanew fields. */ 538 /* Some dos headers (pkunzip) have bogus e_lfanew fields. */
539 *is_dos_app = TRUE; 539 *is_dos_app = TRUE;
540 } 540 }
541 else if (exe_header->nt_signature != NT_SIGNATURE) 541 else if (exe_header->nt_signature != NT_SIGNATURE)
548 548
549 dos_header = (PIMAGE_DOS_HEADER) executable.file_base; 549 dos_header = (PIMAGE_DOS_HEADER) executable.file_base;
550 if (dos_header->e_magic != IMAGE_DOS_SIGNATURE) 550 if (dos_header->e_magic != IMAGE_DOS_SIGNATURE)
551 goto unwind; 551 goto unwind;
552 552
553 nt_header = (PIMAGE_NT_HEADERS) ((char *) dos_header + dos_header->e_lfanew); 553 nt_header = (PIMAGE_NT_HEADERS) ((char*) dos_header + dos_header->e_lfanew);
554 554
555 if ((char *) nt_header > (char *) dos_header + executable.size) 555 if ((char*) nt_header > (char*) dos_header + executable.size)
556 { 556 {
557 /* Some dos headers (pkunzip) have bogus e_lfanew fields. */ 557 /* Some dos headers (pkunzip) have bogus e_lfanew fields. */
558 *is_dos_app = TRUE; 558 *is_dos_app = TRUE;
559 } 559 }
560 else if (nt_header->Signature != IMAGE_NT_SIGNATURE && 560 else if (nt_header->Signature != IMAGE_NT_SIGNATURE &&
569 nt_header->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT]; 569 nt_header->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT];
570 IMAGE_IMPORT_DESCRIPTOR * imports; 570 IMAGE_IMPORT_DESCRIPTOR * imports;
571 IMAGE_SECTION_HEADER * section; 571 IMAGE_SECTION_HEADER * section;
572 572
573 section = rva_to_section (import_dir.VirtualAddress, nt_header); 573 section = rva_to_section (import_dir.VirtualAddress, nt_header);
574 imports = RVA_TO_PTR (import_dir.VirtualAddress, section, executable); 574 imports = (IMAGE_IMPORT_DESCRIPTOR *) RVA_TO_PTR (import_dir.VirtualAddress,
575 section, executable);
575 576
576 for ( ; imports->Name; imports++) 577 for ( ; imports->Name; imports++)
577 { 578 {
578 char * dllname = RVA_TO_PTR (imports->Name, section, executable); 579 char *dllname = (char*) RVA_TO_PTR (imports->Name, section, executable);
579 580
580 if (strcmp (dllname, "cygwin.dll") == 0) 581 if (strcmp (dllname, "cygwin.dll") == 0)
581 { 582 {
582 *is_cygnus_app = TRUE; 583 *is_cygnus_app = TRUE;
583 break; 584 break;
628 optr = envp2; 629 optr = envp2;
629 while (*optr) 630 while (*optr)
630 *nptr++ = *optr++; 631 *nptr++ = *optr++;
631 num += optr - envp2; 632 num += optr - envp2;
632 633
633 qsort (new_envp, num, sizeof (char *), compare_env); 634 qsort (new_envp, num, sizeof (char*), compare_env);
634 635
635 *nptr = NULL; 636 *nptr = NULL;
636 } 637 }
637 638
638 /* When a new child process is created we need to register it in our list, 639 /* When a new child process is created we need to register it in our list,
679 C_STRING_ALLOCA, cmdname, 680 C_STRING_ALLOCA, cmdname,
680 Qfile_name); 681 Qfile_name);
681 } 682 }
682 else 683 else
683 { 684 {
684 (char*)cmdname = alloca (strlen (argv[0]) + 1); 685 cmdname = (char*)alloca (strlen (argv[0]) + 1);
685 strcpy ((char*)cmdname, argv[0]); 686 strcpy ((char*)cmdname, argv[0]);
686 } 687 }
687 UNGCPRO; 688 UNGCPRO;
688 689
689 /* make sure argv[0] and cmdname are both in DOS format */ 690 /* make sure argv[0] and cmdname are both in DOS format */
701 /* On Windows 95, if cmdname is a DOS app, we invoke a helper 702 /* On Windows 95, if cmdname is a DOS app, we invoke a helper
702 application to start it by specifying the helper app as cmdname, 703 application to start it by specifying the helper app as cmdname,
703 while leaving the real app name as argv[0]. */ 704 while leaving the real app name as argv[0]. */
704 if (is_dos_app) 705 if (is_dos_app)
705 { 706 {
706 cmdname = alloca (MAXPATHLEN); 707 cmdname = (char*) alloca (MAXPATHLEN);
707 if (egetenv ("CMDPROXY")) 708 if (egetenv ("CMDPROXY"))
708 strcpy ((char*)cmdname, egetenv ("CMDPROXY")); 709 strcpy ((char*)cmdname, egetenv ("CMDPROXY"));
709 else 710 else
710 { 711 {
711 strcpy ((char*)cmdname, XSTRING_DATA (Vinvocation_directory)); 712 strcpy ((char*)cmdname, XSTRING_DATA (Vinvocation_directory));
800 if (escape_char_run > 0) 801 if (escape_char_run > 0)
801 arglen += escape_char_run; 802 arglen += escape_char_run;
802 } 803 }
803 arglen += strlen (*targ++) + 1; 804 arglen += strlen (*targ++) + 1;
804 } 805 }
805 cmdline = alloca (arglen); 806 cmdline = (char*) alloca (arglen);
806 targ = (char**)argv; 807 targ = (char**)argv;
807 parg = cmdline; 808 parg = cmdline;
808 while (*targ) 809 while (*targ)
809 { 810 {
810 char * p = *targ; 811 char * p = *targ;
882 } 883 }
883 *--parg = '\0'; 884 *--parg = '\0';
884 885
885 /* and envp... */ 886 /* and envp... */
886 arglen = 1; 887 arglen = 1;
887 targ = (char**)envp; 888 targ = (char**) envp;
888 numenv = 1; /* for end null */ 889 numenv = 1; /* for end null */
889 while (*targ) 890 while (*targ)
890 { 891 {
891 arglen += strlen (*targ++) + 1; 892 arglen += strlen (*targ++) + 1;
892 numenv++; 893 numenv++;
896 GetCurrentProcessId ()); 897 GetCurrentProcessId ());
897 arglen += strlen (ppid_env_var_buffer) + 1; 898 arglen += strlen (ppid_env_var_buffer) + 1;
898 numenv++; 899 numenv++;
899 900
900 /* merge env passed in and extra env into one, and sort it. */ 901 /* merge env passed in and extra env into one, and sort it. */
901 targ = (char **) alloca (numenv * sizeof (char *)); 902 targ = (char **) alloca (numenv * sizeof (char*));
902 merge_and_sort_env ((char**)envp, extra_env, targ); 903 merge_and_sort_env ((char**) envp, extra_env, targ);
903 904
904 /* concatenate env entries. */ 905 /* concatenate env entries. */
905 env = alloca (arglen); 906 env = (char*) alloca (arglen);
906 parg = env; 907 parg = env;
907 while (*targ) 908 while (*targ)
908 { 909 {
909 strcpy (parg, *targ); 910 strcpy (parg, *targ);
910 parg += strlen (*targ++); 911 parg += strlen (*targ++);