1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 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 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 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 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119
|
/*
Title: Operating Specific functions: Windows version.
Copyright (c) 2000, 2015, 2018, 2019 David C. J. Matthews
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License version 2.1 as published by the Free Software Foundation.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#elif defined(_WIN32)
#include "winconfig.h"
#else
#error "No configuration file"
#endif
#include <winsock2.h>
#include <windows.h>
#ifdef HAVE_STDIO_H
#include <stdio.h>
#endif
#ifdef HAVE_TCHAR_H
#include <tchar.h>
#endif
#ifdef HAVE_IO_H
#include <io.h>
#endif
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#endif
#ifdef HAVE_ERRNO_H
#include <errno.h>
#endif
#include <lmcons.h>
#ifdef HAVE_ASSERT_H
#include <assert.h>
#define ASSERT(x) assert(x)
#else
#define ASSERT(x) 0
#endif
#include <new>
#include "globals.h"
#include "arb.h"
#include "gc.h"
#include "run_time.h"
#include "io_internal.h"
#include "os_specific.h"
#include "sys.h"
#include "processes.h"
#include "winguiconsole.h"
#include "mpoly.h"
#include "diagnostics.h"
#include "scanaddrs.h"
#include "polystring.h"
#include "save_vec.h"
#include "rts_module.h"
#include "machine_dep.h"
#include "rtsentry.h"
#include "winstartup.h"
#define SAVE(x) taskData->saveVec.push(x)
#define SIZEOF(x) (sizeof(x)/sizeof(word))
extern "C" {
POLYEXTERNALSYMBOL POLYUNSIGNED PolyOSSpecificGeneral(PolyObject *threadId, PolyWord code, PolyWord arg);
POLYEXTERNALSYMBOL POLYUNSIGNED PolyGetOSType();
}
typedef enum
{
HE_UNUSED,
HE_PROCESS
} HANDENTRYTYPE;
typedef struct {
HANDLE hProcess, hInput, hOutput;
} PROCESSDATA;
static Handle execute(TaskData *taskData, Handle pname);
static Handle simpleExecute(TaskData *taskData, Handle args);
static Handle openProcessHandle(TaskData *taskData, Handle args, bool fIsRead, bool fIsText);
static Handle openRegistryKey(TaskData *taskData, Handle args, HKEY hkParent);
static Handle createRegistryKey(TaskData *taskData, Handle args, HKEY hkParent);
static Handle queryRegistryKey(TaskData *taskData, Handle args, HKEY hkParent);
static Handle setRegistryKey(TaskData *taskData, Handle args, HKEY hkParent);
static Handle deleteRegistryKey(TaskData *taskData, Handle args, HKEY hkParent);
static Handle deleteRegistryValue(TaskData *taskData, Handle args, HKEY hkParent);
static Handle enumerateRegistry(TaskData *taskData, Handle args, HKEY hkey, BOOL isKey);
// Vector of constants returned by call1006
static POLYUNSIGNED winConstVec[] =
{
KEY_ALL_ACCESS, // 0
KEY_CREATE_LINK,
KEY_CREATE_SUB_KEY,
KEY_ENUMERATE_SUB_KEYS,
KEY_EXECUTE,
KEY_NOTIFY,
KEY_QUERY_VALUE,
KEY_READ,
KEY_SET_VALUE,
KEY_WRITE, // 9
STATUS_ACCESS_VIOLATION, // 10
STATUS_ARRAY_BOUNDS_EXCEEDED,
STATUS_BREAKPOINT,
STATUS_CONTROL_C_EXIT,
STATUS_DATATYPE_MISALIGNMENT,
STATUS_FLOAT_DENORMAL_OPERAND,
STATUS_FLOAT_DIVIDE_BY_ZERO,
STATUS_FLOAT_INEXACT_RESULT,
STATUS_FLOAT_INVALID_OPERATION,
STATUS_FLOAT_OVERFLOW,
STATUS_FLOAT_STACK_CHECK,
STATUS_FLOAT_UNDERFLOW,
STATUS_GUARD_PAGE_VIOLATION,
STATUS_INTEGER_DIVIDE_BY_ZERO,
STATUS_INTEGER_OVERFLOW,
STATUS_ILLEGAL_INSTRUCTION,
STATUS_INVALID_DISPOSITION,
#ifdef STATUS_INVALID_HANDLE
STATUS_INVALID_HANDLE,
#else
0, // Not defined in Win CE
#endif
STATUS_IN_PAGE_ERROR,
STATUS_NONCONTINUABLE_EXCEPTION,
STATUS_PENDING,
STATUS_PRIVILEGED_INSTRUCTION,
STATUS_SINGLE_STEP,
STATUS_STACK_OVERFLOW,
STATUS_TIMEOUT,
STATUS_USER_APC, // 35
VER_PLATFORM_WIN32s, // 36
VER_PLATFORM_WIN32_WINDOWS,
VER_PLATFORM_WIN32_NT, // 38
// VER_PLATFORM_WIN32_CE is only defined in the Windows CE headers
#ifdef VER_PLATFORM_WIN32_CE
VER_PLATFORM_WIN32_CE, // 39
#else
3, // 39
#endif
};
HKEY hkPredefinedKeyTab[] =
{
HKEY_CLASSES_ROOT,
HKEY_CURRENT_USER,
HKEY_LOCAL_MACHINE,
HKEY_USERS,
#ifdef HKEY_PERFORMANCE_DATA
HKEY_PERFORMANCE_DATA,
#else
0, // Not defined in Win CE
#endif
#ifdef HKEY_CURRENT_CONFIG
HKEY_CURRENT_CONFIG,
#else
0,
#endif
#ifdef HKEY_DYN_DATA
HKEY_DYN_DATA
#else
0
#endif
};
Handle OS_spec_dispatch_c(TaskData *taskData, Handle args, Handle code)
{
unsigned c = get_C_unsigned(taskData, DEREFWORD(code));
switch (c)
{
case 0: /* Return our OS type. Not in any structure. */
return Make_fixed_precision(taskData, 1); /* 1 for Windows. */
/* Windows-specific functions. */
case 1000: /* execute */
return execute(taskData, args);
case 1001: /* Get input stream as text. */
return openProcessHandle(taskData, args, true, true);
case 1002: /* Get output stream as text. */
return openProcessHandle(taskData, args, false, true);
case 1003: /* Get input stream as binary. */
return openProcessHandle(taskData, args, true, false);
case 1004: /* Get output stream as binary. */
return openProcessHandle(taskData, args, false, false);
case 1005: /* Get result of process. */
{
PROCESSDATA *hnd = *(PROCESSDATA**)(args->WordP());
*(PROCESSDATA**)(args->WordP()) = 0; // Mark as inaccessible.
if (hnd == 0)
raise_syscall(taskData, "Process is closed", ERROR_INVALID_HANDLE);
// Close the streams. Either of them may have been
// passed to the stream package.
if (hnd->hInput != INVALID_HANDLE_VALUE)
CloseHandle(hnd->hInput);
hnd->hInput = INVALID_HANDLE_VALUE;
if (hnd->hOutput != INVALID_HANDLE_VALUE)
CloseHandle(hnd->hOutput);
hnd->hOutput = INVALID_HANDLE_VALUE;
// See if it's finished.
while (true) {
DWORD dwResult;
if (GetExitCodeProcess(hnd->hProcess, &dwResult) == 0)
raise_syscall(taskData, "GetExitCodeProcess failed", GetLastError());
if (dwResult != STILL_ACTIVE) {
// Finished - return the result.
// Remove the process object. The result is cached in ML.
free(hnd);
return Make_fixed_precision(taskData, dwResult);
}
// Block and try again.
WaitHandle waiter(hnd->hProcess);
processes->ThreadPauseForIO(taskData, &waiter);
}
}
case 1006: /* Return a constant. */
{
unsigned i = get_C_unsigned(taskData, DEREFWORD(args));
if (i >= sizeof(winConstVec)/sizeof(winConstVec[0]))
raise_syscall(taskData, "Invalid index", 0);
return Make_arbitrary_precision(taskData, winConstVec[i]);
}
/* Registry functions. */
case 1007: // Open a key within one of the roots.
{
unsigned keyIndex = get_C_unsigned(taskData, DEREFWORDHANDLE(args)->Get(0));
// This should only ever happen as a result of a fault in
// the Windows structure.
if (keyIndex >= sizeof(hkPredefinedKeyTab)/sizeof(hkPredefinedKeyTab[0]))
raise_syscall(taskData, "Invalid index", 0);
return openRegistryKey(taskData, args, hkPredefinedKeyTab[keyIndex]);
}
case 1008: // Open a subkey of an opened key.
{
HKEY hKey = *(HKEY*)(args->WordP()->Get(0).AsObjPtr());
if (hKey == 0)
raise_syscall(taskData, "Handle is closed", ERROR_INVALID_HANDLE);
return openRegistryKey(taskData, args, hKey);
}
case 1009: // Create a subkey within one of the roots.
{
unsigned keyIndex = get_C_unsigned(taskData, DEREFWORDHANDLE(args)->Get(0));
// This should only ever happen as a result of a fault in
// the Windows structure.
if (keyIndex >= sizeof(hkPredefinedKeyTab)/sizeof(hkPredefinedKeyTab[0]))
raise_syscall(taskData, "Invalid index", 0);
return createRegistryKey(taskData, args, hkPredefinedKeyTab[keyIndex]);
}
case 1010: // Create a subkey within an opened key.
{
HKEY hKey = *(HKEY*)(args->WordP()->Get(0).AsObjPtr());
if (hKey == 0)
raise_syscall(taskData, "Handle is closed", ERROR_INVALID_HANDLE);
return createRegistryKey(taskData, args, hKey);
}
case 1011: // Close a registry handle.
{
HKEY hKey = *(HKEY*)(args->WordP());
if (hKey != 0)
{
RegCloseKey(hKey);
*(void**)(args->WordP()) = 0;
}
return Make_fixed_precision(taskData, 0);
}
case 1012: // Get a value
{
unsigned keyIndex = get_C_unsigned(taskData, DEREFWORDHANDLE(args)->Get(0));
// This should only ever happen as a result of a fault in
// the Windows structure.
if (keyIndex >= sizeof(hkPredefinedKeyTab)/sizeof(hkPredefinedKeyTab[0]))
raise_syscall(taskData, "Invalid index", 0);
return queryRegistryKey(taskData, args, hkPredefinedKeyTab[keyIndex]);
}
case 1013: // Get a value
{
HKEY hKey = *(HKEY*)(args->WordP()->Get(0).AsObjPtr());
if (hKey == 0)
raise_syscall(taskData, "Handle is closed", ERROR_INVALID_HANDLE);
return queryRegistryKey(taskData, args, hKey);
}
case 1014: // Delete a subkey
{
unsigned keyIndex = get_C_unsigned(taskData, DEREFWORDHANDLE(args)->Get(0));
// This should only ever happen as a result of a fault in
// the Windows structure.
if (keyIndex >= sizeof(hkPredefinedKeyTab)/sizeof(hkPredefinedKeyTab[0]))
raise_syscall(taskData, "Invalid index", 0);
return deleteRegistryKey(taskData, args, hkPredefinedKeyTab[keyIndex]);
}
case 1015: // Delete a subkey
{
HKEY hKey = *(HKEY*)(args->WordP()->Get(0).AsObjPtr());
if (hKey == 0)
raise_syscall(taskData, "Handle is closed", ERROR_INVALID_HANDLE);
return deleteRegistryKey(taskData, args, hKey);
}
case 1016: // Set a value
{
unsigned keyIndex = get_C_unsigned(taskData, DEREFWORDHANDLE(args)->Get(0));
// This should only ever happen as a result of a fault in
// the Windows structure.
if (keyIndex >= sizeof(hkPredefinedKeyTab)/sizeof(hkPredefinedKeyTab[0]))
raise_syscall(taskData, "Invalid index", 0);
return setRegistryKey(taskData, args, hkPredefinedKeyTab[keyIndex]);
}
case 1017: // Set a value
{
HKEY hKey = *(HKEY*)(args->WordP()->Get(0).AsObjPtr());
if (hKey == 0)
raise_syscall(taskData, "Handle is closed", ERROR_INVALID_HANDLE);
return setRegistryKey(taskData, args, hKey);
}
case 1018: // Enumerate a key in the predefined keys
{
unsigned keyIndex = get_C_unsigned(taskData, DEREFWORDHANDLE(args)->Get(0));
if (keyIndex >= sizeof(hkPredefinedKeyTab)/sizeof(hkPredefinedKeyTab[0]))
raise_syscall(taskData, "Invalid index", 0);
return enumerateRegistry(taskData, args, hkPredefinedKeyTab[keyIndex], TRUE);
}
case 1019: // Enumerate a key in an opened key
{
HKEY hKey = *(HKEY*)(args->WordP()->Get(0).AsObjPtr());
if (hKey == 0)
raise_syscall(taskData, "Handle is closed", ERROR_INVALID_HANDLE);
return enumerateRegistry(taskData, args, hKey, TRUE);
}
case 1020: // Enumerate a value in the predefined keys
{
unsigned keyIndex = get_C_unsigned(taskData, DEREFWORDHANDLE(args)->Get(0));
if (keyIndex >= sizeof(hkPredefinedKeyTab)/sizeof(hkPredefinedKeyTab[0]))
raise_syscall(taskData, "Invalid index", 0);
return enumerateRegistry(taskData, args, hkPredefinedKeyTab[keyIndex], FALSE);
}
case 1021: // Enumerate a value in an opened key
{
HKEY hKey = *(HKEY*)(args->WordP()->Get(0).AsObjPtr());
if (hKey == 0)
raise_syscall(taskData, "Handle is closed", ERROR_INVALID_HANDLE);
return enumerateRegistry(taskData, args, hKey, FALSE);
}
case 1022: // Delete a value
{
unsigned keyIndex = get_C_unsigned(taskData, DEREFWORDHANDLE(args)->Get(0));
// This should only ever happen as a result of a fault in
// the Windows structure.
if (keyIndex >= sizeof(hkPredefinedKeyTab)/sizeof(hkPredefinedKeyTab[0]))
raise_syscall(taskData, "Invalid index", 0);
return deleteRegistryValue(taskData, args, hkPredefinedKeyTab[keyIndex]);
}
case 1023: // Delete a value
{
HKEY hKey = *(HKEY*)(args->WordP()->Get(0).AsObjPtr());
if (hKey == 0)
raise_syscall(taskData, "Handle is closed", ERROR_INVALID_HANDLE);
return deleteRegistryValue(taskData, args, hKey);
}
case 1030: // Convert UTC time values to local time. -- No longer used??
{
FILETIME ftUTC, ftLocal;
/* Get the file time. */
getFileTimeFromArb(taskData, args, &ftUTC);
if (! FileTimeToLocalFileTime(&ftUTC, &ftLocal))
raise_syscall(taskData, "FileTimeToLocalFileTime failed", GetLastError());
return Make_arb_from_Filetime(taskData, ftLocal);
}
case 1031: // Convert local time values to UTC. -- No longer used??
{
FILETIME ftUTC, ftLocal;
/* Get the file time. */
getFileTimeFromArb(taskData, args, &ftLocal);
if (! LocalFileTimeToFileTime(&ftLocal, &ftUTC))
raise_syscall(taskData, "LocalFileTimeToFileTime failed", GetLastError());
return Make_arb_from_Filetime(taskData, ftUTC);
}
case 1032: // Get volume information.
{
TCHAR rootName[MAX_PATH], volName[MAX_PATH], sysName[MAX_PATH];
DWORD dwVolSerial, dwMaxComponentLen, dwFlags;
Handle volHandle, sysHandle, serialHandle, maxCompHandle;
Handle resultHandle;
POLYUNSIGNED length = Poly_string_to_C(DEREFWORD(args), rootName, MAX_PATH);
if (length > MAX_PATH)
raise_syscall(taskData, "Root name too long", ERROR_BAD_LENGTH);
if (!GetVolumeInformation(rootName, volName, MAX_PATH,
&dwVolSerial, &dwMaxComponentLen, &dwFlags,
sysName, MAX_PATH))
raise_syscall(taskData, "GetVolumeInformation failed", GetLastError());
volHandle = SAVE(C_string_to_Poly(taskData, volName));
sysHandle = SAVE(C_string_to_Poly(taskData, sysName));
serialHandle = Make_arbitrary_precision(taskData, dwVolSerial);
maxCompHandle = Make_arbitrary_precision(taskData, dwMaxComponentLen);
resultHandle = alloc_and_save(taskData, 4);
DEREFHANDLE(resultHandle)->Set(0, volHandle->Word());
DEREFHANDLE(resultHandle)->Set(1, sysHandle->Word());
DEREFHANDLE(resultHandle)->Set(2, serialHandle->Word());
DEREFHANDLE(resultHandle)->Set(3, maxCompHandle->Word());
return resultHandle;
}
case 1033:
{
TCHAR fileName[MAX_PATH], execName[MAX_PATH];
POLYUNSIGNED length = Poly_string_to_C(DEREFWORD(args), fileName, MAX_PATH);
HINSTANCE hInst;
if (length > MAX_PATH)
raise_syscall(taskData, "File name too long", ERROR_BAD_LENGTH);
hInst = FindExecutable(fileName, NULL, execName);
if ((uintptr_t)hInst <= 32)
{
int error = 0;
switch ((uintptr_t)hInst) {
case SE_ERR_FNF: error = ERROR_FILE_NOT_FOUND; break;
case SE_ERR_PNF: error = ERROR_PATH_NOT_FOUND; break;
case SE_ERR_ACCESSDENIED: error = ERROR_ACCESS_DENIED; break;
case SE_ERR_OOM: error = ERROR_NOT_ENOUGH_MEMORY; break;
case SE_ERR_NOASSOC: error = ERROR_NO_ASSOCIATION; break;
}
raise_syscall(taskData, "FindExecutable failed", error);
}
return SAVE(C_string_to_Poly(taskData, execName));
}
case 1034: // Open a document
{
SHELLEXECUTEINFO shellEx;
memset(&shellEx, 0, sizeof(shellEx));
shellEx.cbSize = sizeof(shellEx);
shellEx.lpVerb = _T("open");
shellEx.lpFile = Poly_string_to_T_alloc(DEREFWORD(args));
shellEx.hwnd = hMainWindow;
shellEx.nShow = SW_SHOWNORMAL;
BOOL fRes = ShellExecuteEx(&shellEx);
free((void*)shellEx.lpFile);
if (! fRes)
raise_syscall(taskData, "ShellExecuteEx failed", GetLastError());
return Make_fixed_precision(taskData, 0);
}
case 1035: // Launch an application.
{
SHELLEXECUTEINFO shellEx;
memset(&shellEx, 0, sizeof(shellEx));
shellEx.cbSize = sizeof(shellEx);
shellEx.lpVerb = _T("open");
shellEx.lpFile = Poly_string_to_T_alloc(args->WordP()->Get(0));
shellEx.lpParameters = Poly_string_to_T_alloc(args->WordP()->Get(1));
shellEx.nShow = SW_SHOWNORMAL;
BOOL fRes = ShellExecuteEx(&shellEx);
free((void*)shellEx.lpFile);
free((void*)shellEx.lpParameters);
if (! fRes)
raise_syscall(taskData, "ShellExecuteEx failed", GetLastError());
return Make_fixed_precision(taskData, 0);
}
case 1036: // Does the process have its own console?
return Make_fixed_precision(taskData, hMainWindow != NULL ? 1: 0);
case 1037: // Simple execute.
return simpleExecute(taskData, args);
// DDE
case 1038: // Start DDE dialogue.
{
TCHAR *serviceName = Poly_string_to_T_alloc(args->WordP()->Get(0));
TCHAR *topicName = Poly_string_to_T_alloc(args->WordP()->Get(1));
/* Send a request to the main thread to do the work. */
HCONV hcDDEConv = StartDDEConversation(serviceName, topicName);
free(serviceName); free(topicName);
if (hcDDEConv == 0) raise_syscall(taskData, "DdeConnect failed", 0);
// Create an entry to return the conversation.
return MakeVolatileWord(taskData, hcDDEConv);
}
case 1039: // Send DDE execute request.
{
HCONV hcDDEConv = *(HCONV*)(args->WordP()->Get(0).AsObjPtr());
if (hcDDEConv == 0) raise_syscall(taskData, "DDE Conversation is closed", 0);
char *command = Poly_string_to_C_alloc(args->WordP()->Get(1));
/* Send a request to the main thread to do the work. */
LRESULT res = ExecuteDDE(command, hcDDEConv);
free(command);
if (res == -1) raise_syscall(taskData, "DdeClientTransaction failed", 0);
else return Make_arbitrary_precision(taskData, res);
}
case 1040: // Close a DDE conversation.
{
HCONV hcDDEConv = *(HCONV*)(args->WordP()->Get(0).AsObjPtr());
if (hcDDEConv != 0)
{
CloseDDEConversation(hcDDEConv);
*(void**)(args->WordP()->Get(0).AsObjPtr()) = 0;
}
return Make_fixed_precision(taskData, 0);
}
// Configuration functions.
case 1050: // Get version data
{
OSVERSIONINFO osver;
ZeroMemory(&osver, sizeof(OSVERSIONINFO));
osver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
// GetVersionEx is deprecated in Windows 8.1
#ifdef _MSC_VER
#pragma warning(disable: 4996)
#endif
if (! GetVersionEx(&osver))
raise_syscall(taskData, "GetVersionEx failed", GetLastError());
#ifdef _MSC_VER
#pragma warning(default: 4996)
#endif
Handle major = Make_fixed_precision(taskData, osver.dwMajorVersion);
Handle minor = Make_fixed_precision(taskData, osver.dwMinorVersion);
Handle build = Make_fixed_precision(taskData, osver.dwBuildNumber);
Handle platform = Make_fixed_precision(taskData, osver.dwPlatformId);
Handle version = SAVE(C_string_to_Poly(taskData, osver.szCSDVersion));
Handle resVal = alloc_and_save(taskData, 5);
DEREFHANDLE(resVal)->Set(0, major->Word());
DEREFHANDLE(resVal)->Set(1, minor->Word());
DEREFHANDLE(resVal)->Set(2, build->Word());
DEREFHANDLE(resVal)->Set(3, platform->Word());
DEREFHANDLE(resVal)->Set(4, version->Word());
return resVal;
}
case 1051: // Get windows directory
{
TCHAR path[MAX_PATH+1];
if (GetWindowsDirectory(path, sizeof(path)/sizeof(TCHAR)) == 0)
raise_syscall(taskData, "GetWindowsDirectory failed", GetLastError());
return SAVE(C_string_to_Poly(taskData, path));
}
case 1052: // Get system directory
{
TCHAR path[MAX_PATH+1];
if (GetSystemDirectory(path, sizeof(path)/sizeof(TCHAR)) == 0)
raise_syscall(taskData, "GetSystemDirectory failed", GetLastError());
return SAVE(C_string_to_Poly(taskData, path));
}
case 1053: // Get computer name
{
TCHAR name[MAX_COMPUTERNAME_LENGTH +1];
DWORD dwSize = MAX_COMPUTERNAME_LENGTH +1;
if (GetComputerName(name, &dwSize) == 0)
raise_syscall(taskData, "GetComputerName failed", GetLastError());
return SAVE(C_string_to_Poly(taskData, name));
}
case 1054: // Get user name
{
TCHAR name[UNLEN +1];
DWORD dwSize = UNLEN +1;
if (GetUserName(name, &dwSize) == 0)
raise_syscall(taskData, "GetUserName failed", GetLastError());
return SAVE(C_string_to_Poly(taskData, name));
}
case 1100: // Get the error result from the last call.
// This is saved when we make a call to a foreign function.
{
return(SAVE(TAGGED(taskData->lastError)));
}
case 1101: // Wait for a message.
{
HWND hwnd = *(HWND*)(DEREFWORDHANDLE(args)->Get(0).AsCodePtr());
UINT wMsgFilterMin = get_C_unsigned(taskData, DEREFWORDHANDLE(args)->Get(1));
UINT wMsgFilterMax = get_C_unsigned(taskData, DEREFWORDHANDLE(args)->Get(2));
while (1)
{
MSG msg;
processes->ThreadReleaseMLMemory(taskData);
// N.B. PeekMessage may directly call the window proc resulting in a
// callback to ML. For this to work a callback must not overwrite "args".
BOOL result = PeekMessage(&msg, hwnd, wMsgFilterMin, wMsgFilterMax, PM_NOREMOVE);
processes->ThreadUseMLMemory(taskData);
if (result) return Make_fixed_precision(taskData, 0);
// Pause until a message arrives.
processes->ThreadPause(taskData);
}
}
// case 1102: // Return the address of the window callback function.
case 1103: // Return the application instance.
{
Handle result = alloc_and_save(taskData, 1, F_BYTE_OBJ);
*(HINSTANCE*)(result->Word().AsCodePtr()) = hApplicationInstance;
return result;
}
case 1104: // Return the main window handle
{
Handle result = alloc_and_save(taskData, 1, F_BYTE_OBJ);
*(HWND*)(result->Word().AsCodePtr()) = hMainWindow;
return result;
}
// case 1105: // Set the callback function
default:
{
char msg[100];
sprintf(msg, "Unknown windows-specific function: %d", c);
raise_exception_string(taskData, EXC_Fail, msg);
return 0;
}
}
}
// General interface to Windows OS-specific. Ideally the various cases will be made into
// separate functions.
POLYUNSIGNED PolyOSSpecificGeneral(PolyObject *threadId, PolyWord code, PolyWord arg)
{
TaskData *taskData = TaskData::FindTaskForId(threadId);
ASSERT(taskData != 0);
taskData->PreRTSCall();
Handle reset = taskData->saveVec.mark();
Handle pushedCode = taskData->saveVec.push(code);
Handle pushedArg = taskData->saveVec.push(arg);
Handle result = 0;
try {
result = OS_spec_dispatch_c(taskData, pushedArg, pushedCode);
}
catch (KillException &) {
processes->ThreadExit(taskData); // Call 1005 may test for kill
}
catch (...) { } // If an ML exception is raised
taskData->saveVec.reset(reset); // Ensure the save vec is reset
taskData->PostRTSCall();
if (result == 0) return TAGGED(0).AsUnsigned();
else return result->Word().AsUnsigned();
}
POLYUNSIGNED PolyGetOSType()
{
return TAGGED(1).AsUnsigned(); // Return 1 for Windows
}
/*
The Windows version of this is more complicated than the Unix version because
we can't manipulate the pipe handles in the child process. Everything has to be
set up in the parent. As with Unix we create two pipes and pass one end of each
pipe to the child. The end we pass to the child is "inheritable" (i.e. duplicated
in the child as with Unix file descriptors) while the ends we keep in the parent
are non-inheritable (i.e. not duplicated in the child).
DCJM: December 1999.
This now uses overlapped IO for the streams.
*/
static Handle execute(TaskData *taskData, Handle args)
{
LPCSTR lpszError = "";
HANDLE hWriteToChild = INVALID_HANDLE_VALUE,
hReadFromParent = INVALID_HANDLE_VALUE,
hWriteToParent = INVALID_HANDLE_VALUE,
hReadFromChild = INVALID_HANDLE_VALUE;
STARTUPINFO startupInfo;
PROCESS_INFORMATION processInfo;
PROCESSDATA *pProcData = 0;
LPTSTR commandName = Poly_string_to_T_alloc(args->WordP()->Get(0));
LPTSTR arguments = Poly_string_to_T_alloc(args->WordP()->Get(1));
TCHAR toChildPipeName[MAX_PATH], fromChildPipeName[MAX_PATH];
newPipeName(toChildPipeName);
newPipeName(fromChildPipeName);
// Create the pipes as inheritable handles. These will be passed to the child.
SECURITY_ATTRIBUTES secure;
secure.nLength = sizeof(SECURITY_ATTRIBUTES);
secure.lpSecurityDescriptor = NULL;
secure.bInheritHandle = TRUE;
hReadFromParent =
CreateNamedPipe(toChildPipeName, PIPE_ACCESS_INBOUND | FILE_FLAG_FIRST_PIPE_INSTANCE,
PIPE_READMODE_BYTE | PIPE_WAIT | PIPE_REJECT_REMOTE_CLIENTS, 1, 4096, 4096, 0, &secure);
if (hReadFromParent == INVALID_HANDLE_VALUE)
{
lpszError = "CreateNamedPipe failed";
goto error;
}
hWriteToChild =
CreateFile(toChildPipeName, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, NULL);
if (hWriteToChild == INVALID_HANDLE_VALUE)
{
lpszError = "CreateFile failed";
goto error;
}
hWriteToParent =
CreateNamedPipe(fromChildPipeName, PIPE_ACCESS_OUTBOUND | FILE_FLAG_FIRST_PIPE_INSTANCE,
PIPE_READMODE_BYTE | PIPE_WAIT | PIPE_REJECT_REMOTE_CLIENTS, 1, 4096, 4096, 0, &secure);
if (hWriteToParent == INVALID_HANDLE_VALUE)
{
lpszError = "CreateNamedPipe failed";
goto error;
}
hReadFromChild =
CreateFile(fromChildPipeName, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, NULL);
if (hReadFromChild == INVALID_HANDLE_VALUE)
{
lpszError = "CreateFile failed";
goto error;
}
// Create a STARTUPINFO structure in which to pass the pipes as stdin
// and stdout to the new process.
memset(&startupInfo, 0, sizeof(startupInfo));
startupInfo.cb = sizeof(startupInfo);
startupInfo.dwFlags = STARTF_USESTDHANDLES;
startupInfo.hStdInput = hReadFromParent;
startupInfo.hStdOutput = hWriteToParent;
// What should we do about the stderr? For the moment, inherit the original.
startupInfo.hStdError = GetStdHandle(STD_ERROR_HANDLE);
// Treat the empty string as NULL. This is non-standard.
if (!CreateProcess(commandName[0] == 0 ? NULL: commandName,
arguments[0] == 0 ? NULL: arguments, // Command line
NULL, NULL, TRUE, // Security attributes. Inherit handles
CREATE_NO_WINDOW, // creation flags
NULL, NULL, // Inherit our environment and directory
&startupInfo,
&processInfo)) {
lpszError = "Could not create process";
goto error;
}
pProcData = (PROCESSDATA *)malloc(sizeof(PROCESSDATA));
if (pProcData == 0)
{
lpszError = "Insufficient memory";
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
goto error;
}
pProcData->hProcess = processInfo.hProcess;
pProcData->hInput = hReadFromChild;
pProcData->hOutput = hWriteToChild;
// Everything has gone well - remove what we don't want
free(commandName);
free(arguments);
/* Close thread handle since we don't need it. */
CloseHandle(processInfo.hThread);
/* Close the sides of the pipes we don't use in the parent. */
CloseHandle(hReadFromParent);
CloseHandle(hWriteToParent);
return(MakeVolatileWord(taskData, pProcData));
error:
{
int err = GetLastError();
free(commandName);
free(arguments);
free(pProcData);
// Close all the pipe handles.
if (hWriteToChild != INVALID_HANDLE_VALUE) CloseHandle(hWriteToChild);
if (hReadFromParent != INVALID_HANDLE_VALUE) CloseHandle(hReadFromParent);
if (hWriteToParent != INVALID_HANDLE_VALUE) CloseHandle(hWriteToParent);
if (hReadFromChild != INVALID_HANDLE_VALUE) CloseHandle(hReadFromChild);
raise_syscall(taskData, lpszError, err);
return NULL; // Never reached.
}
}
static Handle simpleExecute(TaskData *taskData, Handle args)
{
HANDLE hNull = INVALID_HANDLE_VALUE;
PROCESS_INFORMATION processInfo;
TCHAR *commandName = Poly_string_to_T_alloc(args->WordP()->Get(0));
TCHAR *arguments = Poly_string_to_T_alloc(args->WordP()->Get(1));
STARTUPINFO startupInfo;
// Open a handle to NUL for input and output.
hNull = CreateFile(_T("NUL"), GENERIC_READ|GENERIC_WRITE,
FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL, NULL);
// Create a STARTUPINFO structure in which to pass hNULL as stdin
// and stdout to the new process.
// TODO: The handles should really be open on "NUL".
memset(&startupInfo, 0, sizeof(startupInfo));
startupInfo.cb = sizeof(startupInfo);
startupInfo.dwFlags = STARTF_USESTDHANDLES;
startupInfo.hStdInput = hNull;
startupInfo.hStdOutput = hNull;
startupInfo.hStdError = hNull;
STARTUPINFO *start = &startupInfo;
// Treat the empty string as NULL. This is non-standard.
if (!CreateProcess(commandName[0] == 0 ? NULL : commandName,
arguments[0] == 0 ? NULL : arguments, // Command line
NULL, NULL, // Security attributes
TRUE, CREATE_NO_WINDOW, // Inherit handles, creation flags
NULL, NULL, // Inherit our environment and directory
start,
&processInfo)) {
int nErr = GetLastError();
// Clean up
free(commandName);
free(arguments);
CloseHandle(hNull);
raise_syscall(taskData, "CreateProcess failed", nErr);
}
free(commandName);
free(arguments);
/* Close thread handle since we don't need it. */
CloseHandle(processInfo.hThread);
#ifndef _WIN32_WCE
CloseHandle(hNull); // We no longer need this
#endif
PROCESSDATA *pProcData = (PROCESSDATA *)malloc(sizeof(PROCESSDATA));
if (pProcData == 0)
raise_syscall(taskData, "Insufficient memory", ERROR_NOT_ENOUGH_MEMORY);
pProcData->hProcess = processInfo.hProcess;
// We only use the process handle entry.
pProcData->hInput = INVALID_HANDLE_VALUE;
pProcData->hOutput = INVALID_HANDLE_VALUE;
return(MakeVolatileWord(taskData, pProcData));
}
/* Return a stream, either text or binary, connected to an open process. */
static Handle openProcessHandle(TaskData *taskData, Handle args, bool fIsRead, bool fIsText)
{
PROCESSDATA *hnd = *(PROCESSDATA**)(args->WordP());
if (hnd == 0)
raise_syscall(taskData, "Process is closed", ERROR_INVALID_HANDLE);
// We allow multiple streams on the handles. Since they are duplicated by openHandle that's safe.
// A consequence is that closing the stream does not close the pipe as far as the child is
// concerned. That only happens when we close the final handle in reap.
try
{
WinInOutStream *stream = new WinInOutStream;
bool result;
if (fIsRead) result = stream->openHandle(hnd->hInput, OPENREAD, fIsText);
else result = stream->openHandle(hnd->hOutput, OPENWRITE, fIsText);
if (!result)
{
delete(stream);
raise_syscall(taskData, "openHandle failed", GetLastError());
}
return MakeVolatileWord(taskData, stream);
}
catch (std::bad_alloc&)
{
raise_syscall(taskData, "Insufficient memory", ERROR_NOT_ENOUGH_MEMORY);
}
}
// Open a registry key and make an entry in the table for it.
static Handle openRegistryKey(TaskData *taskData, Handle args, HKEY hkParent)
{
TCHAR keyName[MAX_PATH];
REGSAM sam = get_C_unsigned(taskData, DEREFWORDHANDLE(args)->Get(2));
POLYUNSIGNED length = Poly_string_to_C(args->WordP()->Get(1), keyName, MAX_PATH);
if (length > MAX_PATH)
raise_syscall(taskData, "Key name too long", ERROR_BAD_LENGTH);
// Try opening the key.
HKEY hkey;
LONG lRes = RegOpenKeyEx(hkParent, keyName, 0, sam, &hkey);
if (lRes != ERROR_SUCCESS)
raise_syscall(taskData, "RegOpenKeyEx failed", lRes);
return MakeVolatileWord(taskData, hkey);
}
// Create a registry key and make an entry in the table for it.
static Handle createRegistryKey(TaskData *taskData, Handle args, HKEY hkParent)
{
TCHAR keyName[MAX_PATH];
HKEY hkey;
DWORD dwDisp;
REGSAM sam = get_C_unsigned(taskData, DEREFWORDHANDLE(args)->Get(3));
unsigned opt = get_C_unsigned(taskData, DEREFWORDHANDLE(args)->Get(2));
POLYUNSIGNED length = Poly_string_to_C(args->WordP()->Get(1), keyName, MAX_PATH);
if (length > MAX_PATH)
raise_syscall(taskData, "Key name too long", ERROR_BAD_LENGTH);
// Try opening the key.
LONG lRes = RegCreateKeyEx(hkParent, keyName, 0, NULL,
opt ? REG_OPTION_NON_VOLATILE : REG_OPTION_VOLATILE,
sam, NULL, &hkey, &dwDisp);
if (lRes != ERROR_SUCCESS)
raise_syscall(taskData, "RegCreateKeyEx failed", lRes);
// Make an entry in the table.
Handle keyResult = MakeVolatileWord(taskData, hkey);
// Record whether this was new or old.
Handle dispRes = Make_fixed_precision(taskData, dwDisp == REG_CREATED_NEW_KEY ? 0: 1);
/* Return a pair of the disposition and the token. */
Handle pair = alloc_and_save(taskData, 2);
DEREFHANDLE(pair)->Set(0, dispRes->Word());
DEREFHANDLE(pair)->Set(1, keyResult->Word());
return pair;
}
// Delete a key. Note that in Windows NT (but not 95) this will fail if
// the key has subkeys.
static Handle deleteRegistryKey(TaskData *taskData, Handle args, HKEY hkParent)
{
TCHAR keyName[MAX_PATH];
LONG lRes;
POLYUNSIGNED length = Poly_string_to_C(args->WordP()->Get(1), keyName, MAX_PATH);
if (length > MAX_PATH)
raise_syscall(taskData, "Key name too long", ERROR_BAD_LENGTH);
// Try deleting the key.
lRes = RegDeleteKey(hkParent, keyName);
if (lRes != ERROR_SUCCESS)
/* Return the error. */
raise_syscall(taskData, "RegDeleteKey failed", lRes);
return Make_fixed_precision(taskData, 0);
}
static Handle deleteRegistryValue(TaskData *taskData, Handle args, HKEY hkParent)
{
TCHAR keyName[MAX_PATH];
LONG lRes;
POLYUNSIGNED length = Poly_string_to_C(args->WordP()->Get(1), keyName, MAX_PATH);
if (length > MAX_PATH)
raise_syscall(taskData, "Key name too long", ERROR_BAD_LENGTH);
// Try deleting the value.
lRes = RegDeleteValue(hkParent, keyName);
if (lRes != ERROR_SUCCESS)
/* Return the original error. */
raise_syscall(taskData, "RegDeleteValue failed", lRes);
return Make_fixed_precision(taskData, 0);
}
static Handle queryRegistryKey(TaskData *taskData, Handle args, HKEY hkey)
{
TCHAR valName[MAX_PATH];
byte *keyValue = 0;
LONG lRes;
DWORD valSize;
Handle result, resVal, resType;
DWORD dwType;
POLYUNSIGNED length = Poly_string_to_C(args->WordP()->Get(1), valName, MAX_PATH);
if (length > MAX_PATH)
raise_syscall(taskData, "Value name too long", ERROR_BAD_LENGTH);
// How long is the entry?
lRes = RegQueryValueEx(hkey, valName, 0, NULL, NULL, &valSize);
// When opening HKEY_PERFORMANCE_DATA we don't get a sensible
// answer here.
if (lRes == ERROR_MORE_DATA) valSize = 1024; // Guess
else if (lRes != ERROR_SUCCESS)
raise_syscall(taskData, "RegQueryValueEx failed", lRes);
// Allocate that much store and get the value. We could
// try reading directly into ML store to save copying but
// it hardly seems worthwhile.
// Note: It seems that valSize can be zero for some items.
if (valSize == 0) resVal = SAVE(C_string_to_Poly(taskData, "", 0));
else
{
do {
byte *newAlloc = (byte*)realloc(keyValue, valSize);
if (newAlloc == 0)
{
free(keyValue);
raise_syscall(taskData, "Insufficient memory", ERROR_NOT_ENOUGH_MEMORY);
}
keyValue = newAlloc;
lRes = RegQueryValueEx(hkey, valName, 0, &dwType, keyValue, &valSize);
// In the special case of HKEY_PERFORMANCE_DATA we may need to keep
// growing the buffer.
if (lRes == ERROR_MORE_DATA) valSize = valSize + 1024;
} while (lRes == ERROR_MORE_DATA);
if (lRes != ERROR_SUCCESS)
{
free(keyValue);
raise_syscall(taskData, "RegQueryValue failed", lRes);
}
// If we have a string we have to convert this to ANSI/utf-8.
if (dwType == REG_SZ || dwType == REG_MULTI_SZ || dwType == REG_EXPAND_SZ)
resVal = SAVE(C_string_to_Poly(taskData, (TCHAR*)keyValue, valSize / sizeof(TCHAR)));
else resVal = SAVE(C_string_to_Poly(taskData, (char*)keyValue, valSize));
free(keyValue);
}
/* Create a pair containing the type and the value. */
resType = Make_fixed_precision(taskData, dwType);
result = alloc_and_save(taskData, 2);
DEREFHANDLE(result)->Set(0, resType->Word());
DEREFHANDLE(result)->Set(1, resVal->Word());
return result;
}
static Handle setRegistryKey(TaskData *taskData, Handle args, HKEY hkey)
{
TCHAR valName[MAX_PATH];
LONG lRes;
PolyWord str = args->WordP()->Get(3);
POLYUNSIGNED length = Poly_string_to_C(args->WordP()->Get(1), valName, MAX_PATH);
DWORD dwType = get_C_unsigned(taskData, DEREFWORDHANDLE(args)->Get(2));
if (length > MAX_PATH)
raise_syscall(taskData, "Value name too long", ERROR_BAD_LENGTH);
// The value is binary. Strings will already have had a null added.
if (IS_INT(str))
{
byte b = (byte)UNTAGGED(str);
// Single byte value.
lRes = RegSetValueEx(hkey, valName, 0, dwType, &b, 1);
}
else
{
PolyStringObject *ps = (PolyStringObject*)str.AsObjPtr();
lRes = RegSetValueEx(hkey, valName, 0, dwType,
(CONST BYTE *)ps->chars, (DWORD)ps->length);
}
if (lRes != ERROR_SUCCESS)
raise_syscall(taskData, "RegSetValue failed", lRes);
return Make_fixed_precision(taskData, 0);
}
// Enumerate a key or a value. Returns a string option containing NONE if
// no key/value could be found or SOME s where s is the name of the key/value.
static Handle enumerateRegistry(TaskData *taskData, Handle args, HKEY hkey, BOOL isKey)
{
DWORD num = get_C_unsigned(taskData, DEREFWORDHANDLE(args)->Get(1));
LONG lRes;
TCHAR keyName[MAX_PATH];
DWORD dwLength = sizeof(keyName)/sizeof(keyName[0]);
Handle result, resVal;
if (isKey)
{
FILETIME ftMod;
lRes = RegEnumKeyEx(hkey, num, keyName, &dwLength, NULL, NULL, NULL, &ftMod);
if (lRes != ERROR_SUCCESS && lRes != ERROR_NO_MORE_ITEMS)
raise_syscall(taskData, "RegEnumKeyEx failed", lRes);
}
else
{
lRes = RegEnumValue(hkey, num, keyName, &dwLength, NULL, NULL, NULL, NULL);
if (lRes != ERROR_SUCCESS && lRes != ERROR_NO_MORE_ITEMS)
raise_syscall(taskData, "RegEnumValue failed", lRes);
}
if (lRes == ERROR_NO_MORE_ITEMS)
return SAVE(NONE_VALUE); /* NONE. */
resVal = SAVE(C_string_to_Poly(taskData, keyName));
result = alloc_and_save(taskData, 1);
DEREFHANDLE(result)->Set(0, resVal->Word());
return result;
}
struct _entrypts osSpecificEPT[] =
{
{ "PolyGetOSType", (polyRTSFunction)&PolyGetOSType},
{ "PolyOSSpecificGeneral", (polyRTSFunction)&PolyOSSpecificGeneral},
{ NULL, NULL} // End of list.
};
|