bool IpcCallExtra(handle_t ipc, uint32_t code, const wnd_params_t *params, const void *extra, size_t extra_length) { ipc_packet_t packet = { 0 }; if (ipc == NULL) ipc = IpcGetDefault(); packet.code = code; if (params != NULL) packet.params = *params; packet.extra_length = extra_length; errno = 0; if (!FsWrite(ipc, &packet, 0, sizeof(packet), NULL)) { _wdprintf(L"%s: IpcCallExtra: FsWrite(1) failed: %s\n", ProcGetProcessInfo()->module_first->name, _wcserror(errno)); //return false; } if (extra_length > 0) { if (!FsWrite(ipc, extra, 0, extra_length, NULL)) { _wdprintf(L"%s: IpcCallExtra: FsWrite(2) failed: %s\n", ProcGetProcessInfo()->module_first->name, _wcserror(errno)); //return false; } } return true; }
bool GmgrInit(void) { params_vid_t params; handle_t device; LmuxInit(&gmgr_draw); LmuxInit(&gmgr_mux_gfxs); atexit(GmgrCleanup); device = FsOpen(SYS_DEVICES L"/Classes/video0", FILE_READ | FILE_WRITE); if (device == NULL) { _wdprintf(SYS_DEVICES L"/Classes/video0" L": %s\n", _wcserror(errno)); goto error0; } memset(¶ms.vid_setmode, 0, sizeof(params.vid_setmode)); if (!FsRequestSync(device, VID_SETMODE, ¶ms, sizeof(params), NULL)) { _wdprintf(L"VID_SETMODE: %s\n", _wcserror(errno)); goto error1; } gmgr_screen = GmgrCreateDeviceSurface(device, ¶ms.vid_setmode); if (gmgr_screen == NULL) { _wdprintf(L"GmgrCreateDeviceSurface: %s\n", _wcserror(errno)); goto error1; } gmgr_font = FontLoad(L"/Mobius/veramono.ttf", 12 * 64, gmgr_screen->mode.bitsPerPixel < 8 ? FB_FONT_MONO : FB_FONT_SMOOTH); if (gmgr_font == NULL) { _wdprintf(L"/Mobius/veramono.ttf: %s\n", _wcserror(errno)); goto error2; } if (!GmgrInitCursor()) goto error3; return true; error3: FontDelete(gmgr_font); gmgr_font = NULL; error2: GmgrCloseSurface(gmgr_screen); gmgr_screen = NULL; error1: HndClose(device); error0: return false; }
std::wstring ErrorMessage (errno_t err, const char* args, const wchar_t* ini_name, UINT line_no, const char* function_name, const char* file_name) { wchar_t wszFile [256]; wchar_t wszFunction [256]; wchar_t wszArgs [256]; wchar_t wszFormattedError [1024]; MultiByteToWideChar (CP_OEMCP, 0, file_name, -1, wszFile, 256); MultiByteToWideChar (CP_OEMCP, 0, function_name, -1, wszFunction, 256); MultiByteToWideChar (CP_OEMCP, 0, args, -1, wszArgs, 256); *wszFormattedError = L'\0'; swprintf (wszFormattedError, 1024, L"Line %u of %s (in %s (...)):\n" L"------------------------\n\n" L"%s\n\n File: %s\n\n" L"\t>> %s <<", line_no, wszFile, wszFunction, wszArgs, ini_name, _wcserror (err)); return wszFormattedError; }
std::wstring ErrorMessage (errno_t err, const char* args, const wchar_t* ini_name, UINT line_no, const char* function_name, const char* file_name) { wchar_t wszFormattedError [1024]; *wszFormattedError = L'\0'; swprintf ( wszFormattedError, 1024, L"\n" L"Line %u of %hs (in %hs (...)):\n" L"------------------------\n\n" L"%hs\n\n File: %s\n\n" L"\t>> %s <<", line_no, file_name, function_name, args, ini_name, _wcserror (err) ); return wszFormattedError; }
/* Retrieves a descriptive string of the error number * This function uses the POSIX strerror function or equivalent * Returns the string_length if successful or -1 on error */ int libcerror_system_copy_string_from_error_number( libcstring_system_character_t *string, size_t string_size, uint32_t error_number ) { #if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) const wchar_t *static_error_string = NULL; #else const char *static_error_string = NULL; #endif size_t static_error_string_length = 0; if( string == NULL ) { return( -1 ); } if( string_size > (size_t) INT_MAX ) { return( -1 ); } /* Sanity check */ #if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) && !defined( WINAPI ) #error Missing wide character strerror function #endif #if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) static_error_string = _wcserror( (int) error_number ); #else static_error_string = strerror( (int) error_number ); #endif if( static_error_string == NULL ) { return( -1 ); } static_error_string_length = libcstring_system_string_length( static_error_string ); if( libcstring_system_string_copy( string, static_error_string, static_error_string_length ) == NULL ) { return( -1 ); } string[ static_error_string_length ] = 0; return( (int) static_error_string_length ); }
/* Retrieves a descriptive string of the error number * This function uses the POSIX strerror function or equivalent * Returns the string_length if successful or -1 on error */ int libcerror_system_copy_string_from_error_number( system_character_t *string, size_t string_size, uint32_t error_number ) { #if defined( HAVE_WIDE_SYSTEM_CHARACTER ) const wchar_t *static_error_string = NULL; #else const char *static_error_string = NULL; #endif size_t static_error_string_length = 0; if( string == NULL ) { return( -1 ); } if( string_size > (size_t) INT_MAX ) { return( -1 ); } #if defined( HAVE_WIDE_SYSTEM_CHARACTER ) static_error_string = _wcserror( (int) error_number ); #else static_error_string = strerror( (int) error_number ); #endif if( static_error_string == NULL ) { return( -1 ); } static_error_string_length = system_string_length( static_error_string ); if( system_string_copy( string, static_error_string, static_error_string_length ) == NULL ) { return( -1 ); } string[ static_error_string_length ] = 0; return( (int) static_error_string_length ); }
static const char* s_StrErrorInternal(int error) { static const struct { int errnum; const char* errstr; } errmap[] = { # ifdef NCBI_OS_MSWIN {WSAEINTR, "Interrupted system call"}, {WSAEBADF, "Bad file number"}, {WSAEACCES, "Access denied"}, {WSAEFAULT, "Segmentation fault"}, {WSAEINVAL, "Invalid agrument"}, {WSAEMFILE, "Too many open files"}, /* * Windows Sockets definitions of regular Berkeley error constants */ {WSAEWOULDBLOCK, "Resource temporarily unavailable"}, {WSAEINPROGRESS, "Operation now in progress"}, {WSAEALREADY, "Operation already in progress"}, {WSAENOTSOCK, "Not a socket"}, {WSAEDESTADDRREQ, "Destination address required"}, {WSAEMSGSIZE, "Invalid message size"}, {WSAEPROTOTYPE, "Wrong protocol type"}, {WSAENOPROTOOPT, "Bad protocol option"}, {WSAEPROTONOSUPPORT, "Protocol not supported"}, {WSAESOCKTNOSUPPORT, "Socket type not supported"}, {WSAEOPNOTSUPP, "Operation not supported"}, {WSAEPFNOSUPPORT, "Protocol family not supported"}, {WSAEAFNOSUPPORT, "Address family not supported"}, {WSAEADDRINUSE, "Address already in use"}, {WSAEADDRNOTAVAIL, "Cannot assign requested address"}, {WSAENETDOWN, "Network is down"}, {WSAENETUNREACH, "Network is unreachable"}, {WSAENETRESET, "Connection dropped on network reset"}, {WSAECONNABORTED, "Software caused connection abort"}, {WSAECONNRESET, "Connection reset by peer"}, {WSAENOBUFS, "No buffer space available"}, {WSAEISCONN, "Socket is already connected"}, {WSAENOTCONN, "Socket is not connected"}, {WSAESHUTDOWN, "Cannot send after socket shutdown"}, {WSAETOOMANYREFS, "Too many references"}, {WSAETIMEDOUT, "Operation timed out"}, {WSAECONNREFUSED, "Connection refused"}, {WSAELOOP, "Infinite loop"}, {WSAENAMETOOLONG, "Name too long"}, {WSAEHOSTDOWN, "Host is down"}, {WSAEHOSTUNREACH, "Host unreachable"}, {WSAENOTEMPTY, "Not empty"}, {WSAEPROCLIM, "Too many processes"}, {WSAEUSERS, "Too many users"}, {WSAEDQUOT, "Quota exceeded"}, {WSAESTALE, "Stale descriptor"}, {WSAEREMOTE, "Remote error"}, /* * Extended Windows Sockets error constant definitions */ {WSASYSNOTREADY, "Network subsystem is unavailable"}, {WSAVERNOTSUPPORTED, "Winsock.dll version out of range"}, {WSANOTINITIALISED, "Not yet initialized"}, {WSAEDISCON, "Graceful shutdown in progress"}, # ifdef WSAENOMORE /*NB: replaced with WSA_E_NO_MORE*/ {WSAENOMORE, "No more data available"}, # endif /*WSAENOMORE*/ # ifdef WSA_E_NO_MORE {WSA_E_NO_MORE, "No more data available"}, # endif /*WSA_E_NO_MORE*/ # ifdef WSAECANCELLED /*NB: replaced with WSA_E_CANCELLED*/ {WSAECANCELLED, "Call has been cancelled"}, # endif /*WSAECANCELLED*/ # ifdef WSA_E_CANCELLED {WSA_E_CANCELLED, "Call has been cancelled"}, # endif /*WSA_E_CANCELLED*/ {WSAEINVALIDPROCTABLE, "Invalid procedure table"}, {WSAEINVALIDPROVIDER, "Invalid provider version number"}, {WSAEPROVIDERFAILEDINIT,"Cannot init provider"}, {WSASYSCALLFAILURE, "System call failed"}, {WSASERVICE_NOT_FOUND, "Service not found"}, {WSATYPE_NOT_FOUND, "Class type not found"}, {WSAEREFUSED, "Query refused"}, /* * WinSock 2 extension */ # ifdef WSA_IO_PENDING {WSA_IO_PENDING, "Operation has been queued"}, # endif /*WSA_IO_PENDING*/ # ifdef WSA_IO_INCOMPLETE {WSA_IO_INCOMPLETE, "Operation still in progress"}, # endif /*WSA_IO_INCOMPLETE*/ # ifdef WSA_INVALID_HANDLE {WSA_INVALID_HANDLE, "Invalid handle"}, # endif /*WSA_INVALID_HANDLE*/ # ifdef WSA_INVALID_PARAMETER {WSA_INVALID_PARAMETER, "Invalid parameter"}, # endif /*WSA_INVALID_PARAMETER*/ # ifdef WSA_NOT_ENOUGH_MEMORY {WSA_NOT_ENOUGH_MEMORY, "Out of memory"}, # endif /*WSA_NOT_ENOUGH_MEMORY*/ # ifdef WSA_OPERATION_ABORTED {WSA_OPERATION_ABORTED, "Operation aborted"}, # endif /*WSA_OPERATION_ABORTED*/ # endif /*NCBI_OS_MSWIN*/ # ifdef NCBI_OS_MSWIN # define EAI_BASE 0 # else # define EAI_BASE 100000 # endif /*NCBI_OS_MSWIN*/ # ifdef EAI_ADDRFAMILY {EAI_ADDRFAMILY + EAI_BASE, "Address family not supported"}, # endif /*EAI_ADDRFAMILY*/ # ifdef EAI_AGAIN {EAI_AGAIN + EAI_BASE, "Temporary failure in name resolution"}, # endif /*EAI_AGAIN*/ # ifdef EAI_BADFLAGS {EAI_BADFLAGS + EAI_BASE, "Invalid value for lookup flags"}, # endif /*EAI_BADFLAGS*/ # ifdef EAI_FAIL {EAI_FAIL + EAI_BASE, "Non-recoverable failure in name resolution"}, # endif /*EAI_FAIL*/ # ifdef EAI_FAMILY {EAI_FAMILY + EAI_BASE, "Address family not supported"}, # endif /*EAI_FAMILY*/ # ifdef EAI_MEMORY {EAI_MEMORY + EAI_BASE, "Memory allocation failure"}, # endif /*EAI_MEMORY*/ # ifdef EAI_NODATA {EAI_NODATA + EAI_BASE, "No address associated with nodename"}, # endif /*EAI_NODATA*/ # ifdef EAI_NONAME {EAI_NONAME + EAI_BASE, "Host/service name not known"}, # endif /*EAI_NONAME*/ # ifdef EAI_OVERFLOW {EAI_OVERFLOW + EAI_BASE, "Buffer overflow"}, # endif /*EAI_OVERFLOW*/ # ifdef EAI_SERVICE {EAI_SERVICE + EAI_BASE, "Service name not supported for socket type"}, # endif /*EAI_SERVICE*/ # ifdef EAI_SOCKTYPE {EAI_SOCKTYPE + EAI_BASE, "Socket type not supported"}, # endif /*EAI_SOCKTYPE*/ /* GNU extensions */ # ifdef EAI_ALLDONE {EAI_ALLDONE + EAI_BASE, "All requests done"}, # endif /*EAI_ALLDONE*/ # ifdef EAI_CANCELED {EAI_CANCELED + EAI_BASE, "Request canceled"}, # endif /*EAI_BADFLAGS*/ # ifdef EAI_INPROGRESS {EAI_INPROGRESS + EAI_BASE, "Processing request in progress"}, # endif /*EAI_INPROGRESS*/ # ifdef EAI_INTR {EAI_INTR + EAI_BASE, "Interrupted by a signal"}, # endif /*EAI_INTR*/ # ifdef EAI_NOTCANCELED {EAI_NOTCANCELED + EAI_BASE, "Request not canceled"}, # endif /*EAI_NOTCANCELED*/ # ifdef NCBI_OS_MSWIN # define DNS_BASE 0 # else # define DNS_BASE 200000 # endif /*NCBI_OS_MSWIN*/ # ifdef HOST_NOT_FOUND {HOST_NOT_FOUND + DNS_BASE, "Host not found"}, # endif /*HOST_NOT_FOUND*/ # ifdef TRY_AGAIN {TRY_AGAIN + DNS_BASE, "DNS server failure"}, # endif /*TRY_AGAIN*/ # ifdef NO_RECOVERY {NO_RECOVERY + DNS_BASE, "Unrecoverable DNS error"}, # endif /*NO_RECOVERY*/ # ifdef NO_ADDRESS {NO_ADDRESS + DNS_BASE, "No address record found in DNS"}, # endif /*NO_ADDRESS*/ # ifdef NO_DATA {NO_DATA + DNS_BASE, "No DNS data of requested type"}, # endif /*NO_DATA*/ /* Last dummy entry - must present */ {0, 0} }; #if defined(NCBI_OS_LINUX) || defined(NCBI_OS_CYGWIN) /* To work correctly, descending order of offsets is required here */ static const struct { int erroff; const char* (*errfun)(int errnum); } errsup[] = { # ifdef __GLIBC__ {DNS_BASE, hstrerror}, # endif /*__GLIBC__*/ # if defined(HAVE_GETADDRINFO) || defined(HAVE_GETNAMEINFO) {EAI_BASE, gai_strerror}, # endif /*HAVE_GETADDRINFO || HAVE_GETNAMEINFO*/ /* Last dummy entry - must present */ {0, 0} }; #endif /*NCBI_OS_LINUX || NCBI_OS_CYGWIN*/ size_t i; if (!error) return 0; #if defined(NCBI_OS_LINUX) || defined(NCBI_OS_CYGWIN) for (i = 0; i < sizeof(errsup) / sizeof(errsup[0]) - 1/*dummy*/; ++i) { if (errsup[i].erroff < error) { const char* errstr = errsup[i].errfun(error - errsup[i].erroff); if (errstr && *errstr) return ERR_STRDUP(errstr); } } #endif /*NCBI_OS_LINUX || NCBI_OS_CYGWIN*/ for (i = 0; i < sizeof(errmap) / sizeof(errmap[0]) - 1/*dummy*/; ++i) { if (errmap[i].errnum == error) return ERR_STRDUP(errmap[i].errstr); } # if defined(NCBI_OS_MSWIN) && defined(_UNICODE) return UTIL_TcharToUtf8(_wcserror(error)); # else return ERR_STRDUP(strerror(error)); # endif /*NCBI_OS_MSWIN && _UNICODE*/ }
/* Retrieves a descriptive string of the error number * Returns 1 if successful or -1 on error */ int libsmdev_error_string_copy_from_error_number( libcstring_system_character_t *string, size_t string_size, int error_number, liberror_error_t **error ) { static char *function = "libsmdev_error_string_copy_from_error_number"; #if ( defined( HAVE_STRERROR ) && !defined( HAVE_STRERROR_R ) && !defined( WINAPI ) ) || ( defined( WINAPI ) && defined( USE_CRT_FUNCTIONS ) && !defined( _MSC_VER ) ) #if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) const wchar_t *static_error_string = NULL; #else const char *static_error_string = NULL; #endif size_t static_error_string_length = 0; #endif if( string == NULL ) { liberror_error_set( error, LIBERROR_ERROR_DOMAIN_ARGUMENTS, LIBERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid string.", function ); return( -1 ); } if( string_size > (size_t) SSIZE_MAX ) { liberror_error_set( error, LIBERROR_ERROR_DOMAIN_ARGUMENTS, LIBERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, "%s: invalid string size value exceeds maximum.", function ); return( -1 ); } /* Use the WINAPI error string function */ #if defined( WINAPI ) && !defined( USE_CRT_FUNCTIONS ) #if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) if( FormatMessageW( FORMAT_MESSAGE_FROM_SYSTEM, NULL, (DWORD) error_number, MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT ), string, string_size, NULL ) == 0 ) #else if( FormatMessageA( FORMAT_MESSAGE_FROM_SYSTEM, NULL, (DWORD) error_number, MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT ), string, string_size, NULL ) == 0 ) #endif { liberror_error_set( error, LIBERROR_ERROR_DOMAIN_RUNTIME, LIBERROR_RUNTIME_ERROR_SET_FAILED, "%s: unable to set string.", function ); return( -1 ); } /* Use MSVSC++ specific CRT error string functions */ #elif defined( USE_CRT_FUNCTIONS ) && defined( _MSC_VER ) #if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) if( _wcserror_s( string, string_size, error_number ) != 0 ) #else if( strerror_s( string, string_size, error_number ) != 0 ) #endif { liberror_error_set( error, LIBERROR_ERROR_DOMAIN_RUNTIME, LIBERROR_RUNTIME_ERROR_SET_FAILED, "%s: unable to set string.", function ); return( -1 ); } /* Use POSIX specific error string functions */ #elif defined( HAVE_STRERROR_R ) /* Sanity check */ #if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) #error Missing wide character strerror_r function #endif #if defined( STRERROR_R_CHAR_P ) if( strerror_r( error_number, string, string_size ) == NULL ) #else if( strerror_r( error_number, string, string_size ) != 0 ) #endif { liberror_error_set( error, LIBERROR_ERROR_DOMAIN_RUNTIME, LIBERROR_RUNTIME_ERROR_SET_FAILED, "%s: unable to set string.", function ); return( -1 ); } /* Use the static error string function */ #elif defined( HAVE_STRERROR ) || defined( WINAPI ) /* Sanity check */ #if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) && !defined( WINAPI ) #error Missing wide character strerror function #endif #if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) static_error_string = _wcserror( error_number ); #else static_error_string = strerror( error_number ); #endif if( static_error_string == NULL ) { liberror_error_set( error, LIBERROR_ERROR_DOMAIN_RUNTIME, LIBERROR_RUNTIME_ERROR_SET_FAILED, "%s: unable to create static error string.", function ); return( -1 ); } static_error_string_length = libcstring_system_string_length( static_error_string ); if( libcstring_system_string_copy( string, static_error_string, static_error_string_length ) == NULL ) { liberror_error_set( error, LIBERROR_ERROR_DOMAIN_RUNTIME, LIBERROR_RUNTIME_ERROR_SET_FAILED, "%s: unable to set string.", function ); return( -1 ); } string[ static_error_string_length ] = 0; #else #error Missing strerror function #endif return( 1 ); }
std::string SystemException::GetErrorCodeString(int code) { std::wstring error(_wcserror(code)); return atom::ConvertUTF<char>(error); }
size_t getLastErrorString(char *utf8_jvmErrorMsg, size_t cbErrorMsg) { size_t n = 0; if (cbErrorMsg > 0) { BOOLEAN noError = FALSE; WCHAR *utf16_osErrorMsg = (WCHAR *)malloc(cbErrorMsg*sizeof(WCHAR)); if (utf16_osErrorMsg == NULL) { // OOM accident strncpy(utf8_jvmErrorMsg, "Out of memory", cbErrorMsg); // truncate if too long utf8_jvmErrorMsg[cbErrorMsg - 1] = '\0'; n = strlen(utf8_jvmErrorMsg); } else { DWORD errval = GetLastError(); if (errval != 0) { // WIN32 error n = (size_t)FormatMessageW( FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS, NULL, errval, 0, utf16_osErrorMsg, (DWORD)cbErrorMsg, NULL); if (n > 3) { // Drop final '.', CR, LF if (utf16_osErrorMsg[n - 1] == L'\n') --n; if (utf16_osErrorMsg[n - 1] == L'\r') --n; if (utf16_osErrorMsg[n - 1] == L'.') --n; utf16_osErrorMsg[n] = L'\0'; } } else if (errno != 0) { // C runtime error that has no corresponding WIN32 error code const WCHAR *rtError = _wcserror(errno); if (rtError != NULL) { wcsncpy(utf16_osErrorMsg, rtError, cbErrorMsg); // truncate if too long utf16_osErrorMsg[cbErrorMsg - 1] = L'\0'; n = wcslen(utf16_osErrorMsg); } } else noError = TRUE; //OS has no error to report if (!noError) { if (n > 0) { n = WideCharToMultiByte( CP_UTF8, 0, utf16_osErrorMsg, (int)n, utf8_jvmErrorMsg, (int)cbErrorMsg, NULL, NULL); // no way to die if (n > 0) utf8_jvmErrorMsg[min(cbErrorMsg - 1, n)] = '\0'; } if (n <= 0) { strncpy(utf8_jvmErrorMsg, "Secondary error while OS message extraction", cbErrorMsg); // truncate if too long utf8_jvmErrorMsg[cbErrorMsg - 1] = '\0'; n = strlen(utf8_jvmErrorMsg); } } free(utf16_osErrorMsg); } } return n; }
int mainCRTStartup(void) { handle_t server, client; unsigned i; params_vid_t params; font_t *font; vid = FsOpen(SYS_DEVICES L"/Classes/video0", FILE_READ | FILE_WRITE); if (vid == NULL) { _wdprintf(L"console: " SYS_DEVICES L"/Classes/video0: %s\n", _wcserror(errno)); return errno; } memset(&mode, 0, sizeof(mode)); params.vid_setmode = mode; if (!FsRequestSync(vid, VID_SETMODE, ¶ms, sizeof(params), NULL)) { _wdprintf(L"console: failed to set video mode: %s\n", _wcserror(errno)); HndClose(vid); return errno; } mode = params.vid_setmode; if (mode.flags & VIDEO_MODE_TEXT) { _wdprintf(L"console: text mode not supported\n"); return 0; } if (mode.bitsPerPixel == 4) { vidmem = NULL; if (!AccelCreateSurface(&mode, vid, &surf)) { _wdprintf(L"console: AccelCreateSurface failed\n"); return errno; } } else { handle_t handle_vidmem; handle_vidmem = HndOpen(mode.framebuffer); if (handle_vidmem == 0) { _wdprintf(L"console: unable to open framebuffer %s\n", mode.framebuffer); return errno; } vidmem = VmmMapSharedArea(handle_vidmem, 0, VM_MEM_USER | VM_MEM_READ | VM_MEM_WRITE); HndClose(handle_vidmem); if (!FramebufCreateSurface(&mode, vidmem, &surf)) { _wdprintf(L"console: video mode not supported: %u bits per pixel\n", mode.bitsPerPixel); return errno; } } FontInit(); font = FontLoad(font_name, 10 * 64, mode.bitsPerPixel < 8 ? FB_FONT_MONO : FB_FONT_SMOOTH); if (font == NULL) { _wdprintf(L"console: failed to load font %s\n", font_name); return errno; } cookies[0] = (void*) 0x12345678; num_buffers = 1; LmuxInit(&lmux_consoles); for (i = 0; i < _countof(consoles); i++) { LmuxInit(&consoles[i].lmux); consoles[i].width = consoles[i].height = 0; consoles[i].fg_colour = consoles[i].default_fg_colour = 0xc0c0c0; consoles[i].bg_colour = consoles[i].default_bg_colour = 0x000000; consoles[i].cookie = cookies[0]; consoles[i].buf_chars = NULL; consoles[i].font = font; FontGetMaxSize(consoles[i].font, &consoles[i].char_width, &consoles[i].char_height); } num_consoles = _countof(consoles); ConTileBuffer(0); num_consoles = 0; current = consoles; for (i = 0; i < _countof(consoles); i++) ConClear(consoles + i); server = FsCreate(server_name, 0); ThrCreateThread(ConKeyboardThread, NULL, 16, L"ConKeyboardThread"); ThrCreateThread(ConCursorThread, NULL, 16, L"ConCursorThread"); ConDisplaySignonMessage(); while ((client = PortAccept(server, FILE_READ | FILE_WRITE))) { if (num_consoles < _countof(consoles)) { consoles[num_consoles].client = client; ThrCreateThread(ConClientThread, consoles + num_consoles, 15, L"ConClientThread"); num_consoles++; } else HndClose(client); } for (i = 0; i < _countof(consoles); i++) { LmuxDelete(&consoles[i].lmux); free(consoles[i].buf_chars); } LmuxDelete(&lmux_consoles); FontDelete(font); HndClose(server); if (vidmem != NULL) VmmFree(vidmem); HndClose(vid); return EXIT_SUCCESS; }
int ConKeyboardThread(void *param) { uint32_t ch, code; handle_t keyboard; //void *old_buffer; //unsigned i; keyboard = FsOpen(SYS_DEVICES L"/keyboard", FILE_READ); while (FsRead(keyboard, &ch, 0, sizeof(ch), NULL)) { code = ch & ~KBD_BUCKY_ANY; if ((ch & KBD_BUCKY_ALT) != 0 && code >= KEY_F1 && code <= KEY_F12) { /*LmuxAcquire(&lmux_consoles); LmuxAcquire(¤t->lmux); ConDrawCursor(current, false); old_buffer = current->cookie; current = consoles + code - KEY_F1; if (old_buffer != current->buffer) for (i = 0; i < num_consoles; i++) if (consoles[i].buffer == current->buffer) ConRedraw(consoles + i); ConDrawCursor(current, true); LmuxRelease(¤t->lmux); LmuxRelease(&lmux_consoles);*/ } else if (ch == (KBD_BUCKY_CTRL | KBD_BUCKY_ALT | KEY_DEL)) SysShutdown(SHUTDOWN_REBOOT); else if (ch == (KBD_BUCKY_ALT | '\t') || ch == (KBD_BUCKY_ALT | KBD_BUCKY_SHIFT | '\t')) { LmuxAcquire(&lmux_consoles); LmuxAcquire(¤t->lmux); ConDrawCursor(current, false); LmuxRelease(¤t->lmux); if (ch & KBD_BUCKY_SHIFT) { if (current - consoles - 1 < 0) current = consoles + num_consoles - 1; else current--; } else { if (current - consoles + 1 >= num_consoles) current = consoles; else current++; } LmuxAcquire(¤t->lmux); ConDrawCursor(current, true); LmuxRelease(¤t->lmux); LmuxRelease(&lmux_consoles); } else { LmuxAcquire(&lmux_consoles); if (current != NULL && current->client != NULL) FsWrite(current->client, &ch, 0, sizeof(ch), NULL); LmuxRelease(&lmux_consoles); } } _wdprintf(L"console(keyboard): FsRead failed, %s\n", _wcserror(errno)); return errno; }