⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 kernel32.c

📁 freedos32的源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
/* Mini KERNEL32 * by Hanzac Chen * * This is free software; see GPL.txt */#include <stdio.h>#include <stdlib.h>#include <string.h>#include <fcntl.h>#include <unistd.h>#include <windows.h>#include "winb.h"static LPCSTR atomname = NULL;static ATOM WINAPI fd32_imp__AddAtomA( LPCSTR str ){  printf("AddAtomA: %s\n", str);  atomname = str;  return 1;}static ATOM WINAPI fd32_imp__FindAtomA( LPCSTR str ){  printf("FindAtomA: %s\n", str);  if (atomname != NULL)    return 1;  else    return 0;}static UINT WINAPI fd32_imp__GetAtomNameA( DWORD atom, LPSTR buffer, int nsize ){  if (atomname != 0)    strcpy(buffer, atomname);  else    nsize = 0;  return nsize;}static UINT WINAPI fd32_imp__SetErrorMode(UINT uMode){#ifdef __WINB_DEBUG__  fd32_log_printf("[WINB] SetErrorMode: %x, not implemented, always return 0!\n", uMode);#endif  return 0;}static DWORD errcode;static DWORD WINAPI fd32_imp__GetLastError(VOID){#ifdef __WINB_DEBUG__  fd32_log_printf("[WINB] GetLastError: %lx\n", errcode);#endif  return errcode;}static VOID WINAPI fd32_imp__SetLastError(DWORD dwErrCode){#ifdef __WINB_DEBUG__  fd32_log_printf("[WINB] SetLastError: %lx\n", errcode);#endif  errcode = dwErrCode;}static BOOL WINAPI fd32_imp__GetVersionExA(LPOSVERSIONINFOA lpVersionInformation){  /* TODO: Check the PlatformId since it's the minimum implementation of Win32 APIs */  if (lpVersionInformation != NULL && lpVersionInformation->dwOSVersionInfoSize == sizeof(OSVERSIONINFOA)) {    lpVersionInformation->dwMajorVersion = 0x05;    lpVersionInformation->dwMinorVersion = 0x01;    lpVersionInformation->dwBuildNumber  = 0x05;    lpVersionInformation->dwPlatformId   = VER_PLATFORM_WIN32_NT;    strcpy(lpVersionInformation->szCSDVersion, "FreeDOS-32 WINB 0.05 alpha");    return TRUE;  } else {    return FALSE;  }}static VOID WINAPI fd32_imp__GetSystemInfo(LPSYSTEM_INFO lpSystemInfo){  /* TODO: Check the memory limits, get the current processor type, level and revision */  if (lpSystemInfo != NULL) {    lpSystemInfo->dwOemId = PROCESSOR_ARCHITECTURE_INTEL;    lpSystemInfo->dwPageSize = sysconf(_SC_PAGESIZE);    lpSystemInfo->lpMinimumApplicationAddress = (LPVOID)0x10000;    lpSystemInfo->lpMaximumApplicationAddress = (LPVOID)0x7FFEFFFF;    lpSystemInfo->dwActiveProcessorMask = 1;    lpSystemInfo->dwNumberOfProcessors = 1;    lpSystemInfo->dwProcessorType = PROCESSOR_INTEL_386;    lpSystemInfo->dwAllocationGranularity = 0x10000;    lpSystemInfo->wProcessorLevel = 3;    lpSystemInfo->wProcessorRevision = 0;  }}static PTOP_LEVEL_EXCEPTION_FILTER top_filter;static LPVOID WINAPI fd32_imp__SetUnhandledExceptionFilter( LPTOP_LEVEL_EXCEPTION_FILTER filter ){  LPTOP_LEVEL_EXCEPTION_FILTER old = top_filter;#ifdef __WINB_DEBUG__  fd32_log_printf("[WINB] SetUnhandledExceptionFilter: %lx\n", (DWORD)filter);#endif  top_filter = filter;  return old;}static BOOL WINAPI fd32_imp__PeekNamedPipe(HANDLE hNamedPipe, LPVOID lpBuffer, DWORD nBufferSize, LPDWORD lpBytesRead, LPDWORD lpTotalBytesAvail, LPDWORD lpBytesLeftThisMessage){#ifdef __WINB_DEBUG__  fd32_log_printf("[WINB] PeekNamedPipe: %lx\n", (DWORD)hNamedPipe);#endif  return FALSE;}/* ______________________________ *\ *|                              |* *|Dynamic-Link Library Functions|*\*|______________________________|*/extern struct psp *current_psp;static DWORD WINAPI fd32_imp__GetModuleHandleA( LPCSTR module ){#ifdef __WINB_DEBUG__  fd32_log_printf("[WINB] GetModuleHandle: %s\n", module);#endif  return (DWORD)current_psp;}/* ______________________________ *\ *|                              |* *| Process and Thread Functions |*\*|______________________________|*/void restore_sp(DWORD s);static VOID WINAPI fd32_imp__ExitProcess( UINT ecode ){#ifdef __WINB_DEBUG__  fd32_log_printf("[WINB] ExitProcess: %x and do memory clear-up!\n", ecode);#endif  /* TODO: Remove the Atom? */  atomname = NULL;  if (current_psp->mem_clear_up != NULL)    current_psp->mem_clear_up();  restore_sp(ecode);}static LPSTR WINAPI fd32_imp__GetCommandLineA(VOID){  return current_psp->command_line;}static LPSTR WINAPI fd32_imp__GetEnvironmentStringsA(void){  /* NOTE: FD32 currently support GDT only */  return (LPSTR)gdt_read(current_psp->environment_selector, NULL, NULL, NULL);}static VOID WINAPI fd32_imp__GetStartupInfoA(LPSTARTUPINFOA lpStartupInfo){  /* TODO: Set StartupInfo title to be the program's name */  if (lpStartupInfo != NULL && lpStartupInfo->cb == sizeof(STARTUPINFOA)) {    lpStartupInfo->lpReserved = NULL;    lpStartupInfo->lpDesktop = "FD32-DESKTOP";    lpStartupInfo->lpTitle = NULL;    lpStartupInfo->dwX = 0;    lpStartupInfo->dwY = 0;    lpStartupInfo->dwXSize = 0;    lpStartupInfo->dwYSize = 0;    lpStartupInfo->dwXCountChars = 80;    lpStartupInfo->dwYCountChars = 25;    lpStartupInfo->dwFillAttribute = 0;    lpStartupInfo->dwFlags = STARTF_USESHOWWINDOW|STARTF_USECOUNTCHARS|STARTF_USECOUNTCHARS;    lpStartupInfo->wShowWindow = 5; /* SW_SHOW */    lpStartupInfo->cbReserved2 = 0;    lpStartupInfo->lpReserved2 = NULL;    lpStartupInfo->hStdInput = INVALID_HANDLE_VALUE; /* Not specified */    lpStartupInfo->hStdOutput = INVALID_HANDLE_VALUE;    lpStartupInfo->hStdError = INVALID_HANDLE_VALUE;  }}/* The GetCurrentProcessId function returns the process identifier of the calling process. * * Return Values * The return value is the process identifier of the calling process.  */static DWORD WINAPI fd32_imp__GetCurrentProcessId( void ){#ifdef __WINB_DEBUG__  fd32_log_printf("[WINB] GetCurrentProcessId ...\n");#endif  return (DWORD)current_psp;}/* The GetCurrentThreadId function returns the thread identifier of the calling thread.  * * Return Values * The return value is the thread identifier of the calling thread.  */static DWORD WINAPI fd32_imp__GetCurrentThreadId( void ){#ifdef __WINB_DEBUG__  fd32_log_printf("[WINB] GetCurrentThreadId ... not supported\n");#endif  /* FD32 currently no multi-threading */  return 0;}static void WINAPI fd32_imp__Sleep(DWORD dwMilliseconds){#ifdef __WINB_DEBUG__  fd32_log_printf("[WINB] Sleep ... not implemented\n");#endif  /* TODO: Using int nanosleep (const struct timespec *requested_time, struct timespec *remaining) in newlib */  /* int nanosleep(const struct timespec *rqtp, struct timespec *rmtp);     struct timespec rqt = {dwMilliseconds/1000, dwMilliseconds*1000000-(dwMilliseconds/1000)*1000000000};     struct timespec rmt;     nanosleep(&rqt, &rmt); */  // sleep(dwMilliseconds/1000);}/* ______________________________ *\ *|                              |* *|        Time Functions        |*\*|______________________________|*//* The GetSystemTimeAsFileTime function obtains the current system date and time. The information is in Coordinated Universal Time (UTC) format. * * Parameters * lpSystemTimeAsFileTime *   Pointer to a FILETIME structure to receive the current system date and time in UTC format.  */static void WINAPI fd32_imp__GetSystemTimeAsFileTime( LPFILETIME lpftime ){#ifdef __WINB_DEBUG__  fd32_log_printf("[WINB] GetSystemTimeAsFileTime: %lx ... not implemented\n", (DWORD)lpftime);#endif}/* The GetTickCount function retrieves the number of milliseconds that have elapsed since Windows was started.  * * Return Values * If the function succeeds, the return value is the number of milliseconds that have elapsed since Windows was started.  */static DWORD WINAPI fd32_imp__GetTickCount( VOID ){#ifdef __WINB_DEBUG__  fd32_log_printf("[WINB] GetTickCount ... not implemented\n");#endif  return 0;}/* The QueryPerformanceCounter function retrieves the current value of the high-resolution performance counter, if one exists.  * * Parameters * lpPerformanceCount *   Points to a variable that the function sets, in counts, to the current performance-counter value. If the installed hardware does not support a high-resolution performance counter, this parameter can be to zero.  * * Return Values * If the installed hardware supports a high-resolution performance counter, the return value is nonzero. * If the installed hardware does not support a high-resolution performance counter, the return value is zero.  */static BOOL WINAPI fd32_imp__QueryPerformanceCounter( PLARGE_INTEGER lpcount ){#ifdef __WINB_DEBUG__  fd32_log_printf("[WINB] QueryPerformanceCounter ... not implemented, return FALSE\n");#endif  return FALSE;}/* ______________________________ *\ *|                              |* *| Memory Management Functions  |*

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -