Upon deciding to write a simple "Hello World!" program in EDK2,
I stumbled upon the following problem:
As I am using a serial connection for debugging, the output of the debug functions like DebugPrint successfully get redirected to my serial terminal (PuTTY in this case), well sort of.
After compiling an executing the following program inside an UEFI shell, I simply get
an empty line as a result.
But after executing the same binary again, the line gets successfully printed in all it's beauty.
This is the source code of the program i ran:
#include <Uefi.h>
#include <Library/DebugLib.h>
EFI_STATUS
efi_main(EFI_HANDLE ImageHandle,
EFI_SYSTEM_TABLE* SystemTable
)
{
DebugPrint(DEBUG_INFO, "Hello World!\n");
return EFI_SUCCESS;
}
Serial output:
Note: I linked my program against IoLib, SerialPortLib and DebugLib
What could be causing this issue?
After a lot of fiddling around I realised, that I manually specified the entry point to my main-function (efi_main), which should instead point to _ModuleEntryPoint when using the UefiDriverEntryPoint library from EDK2.
This solved my problem instantly :)
Related
I am currently learning C, using CLion on Windows, and as so I am starting off with a very simple program using cURL.
I have finally successfully included the library in my code using CMake as performed in this question:
How do I link dynamically built cmake files on Windows?
The code now builds without error.
The issue is, as soon as I write the curl_easy_init(), the program outputs with an unusual exit code not referenced in the cURL docs and print functions fail to output like normal.
#include <stdio.h>
#include <curl/curl.h>
int main(void) {
printf("Hello world!\n");
CURL *curl;
CURLcode res;
curl = curl_easy_init(); // Line that changes program
return 0;
}
Whenever that dreadful line is written, the program no longer outputs a happy old "Hello World!" with an exit code of zero, and instead, outputs this:
Process finished with exit code -1073741515 (0xC0000135)
What even is that exit code??
Any information is much appreciated.
0xC0000135 is "application not correctly initialized", which generally indicates that the loader cannot find a dll required by your application. Most probably you linked the libcurl import library, but the corresponding dll (libcurl.dll) cannot be found in the same directory of the executable and isn't in the global dll search paths. Make sure the dll is available when you launch your application, or link libcurl statically.
I'm writing my first Linux LKM. It's a simple chardev that has some basic read, write, open, release functions with a mutex lock. It compiles successfully, but when I try to open the chardev by cat /dev/kbschar, I get the following error
cat: /dev/kbschar: Invalid argument
The source code is on gitlab. I've linked to the main.c file. You can find the Makefile in the repository
The output of dmesg is here. I also used ftrace's function_graph tracer and filtered by :mod:main. Here is the output of that. Finally, I also ran strace cat /dev/kbschar to see where I was getting the EINVAL error. Here is the output to that. We have the EINVAL error at line 32.
Thanks for the help in advance
The last line of your dev_open function:
return true;
is not good. You're supposed to return an error code (negative errno) or zero for success. Whatever true is (probably defined as 1 somewhere?) it's not valid.
When running gcc adventure.c -o adventure followed by adventure in a linux (Ubuntu) terminal will compile it for me, and execute it. When an error occurs (e.g. segmentation fault) during runtime it will report it in the terminal output.
In windows however a runtime error will only pop up a "adventure.c" has stopped working dialog box, and nothing is written to the output of the cmd.exe screen.
Is there some way that I can also get a reported error on Windows when one occurs?
Under Windows, you define the subsystem for which you build an executable (ref : /SUBSYSTEM (Specify Subsystem). The two more commons subsystems are CONSOLE for command line applications and WINDOWS for GUI ones.
As explained in referenced page, the subsystem is normally automatically set to CONSOLEby the presence of a standard C main function. Normally, the errors related to a CONSOLE application are displayed in the console attached to the application, and the errors related to a WINDOWS application open a message box.
But I do not know exactly what exists in your adventure version (many exists around ...) - Sniff, I was younger when I played adventure :-) . You should try to generate a minimal console program that SIGSGV (easy in C ..) and verify where the error is displayed.
Edit per comment :
Well after Andrew Medico comment (thanks to him), I did the test and ... he is right :-( ... even a console progam opens the message box by default and does not write anything. Sad ...
So you will have to use Microsoft structured exception handling to achieve what you want, but you need to slightly modify source code that way :
original source :
#include ...
...
int main(...) {
...
}
modified source
#include ...
#include <excpt.h>
#include <windows.h>
...
int real_main(...) {
...
}
int filter(DWORD code, LPEXCEPTION_POINTERS info) {
fprintf(stderr, "Fatal error %x at %x\n", code,
info->ExceptionRecord->ExceptionAddress);
return EXCEPTION_EXECUTE_HANDLER;
}
int main(int argc, char *argv[]){
int cr;
__try {
cr = real_main(...);
}
__except(filter(exception_code(), exception_info())) {
cr = 1;
}
return cr;
}
All that wraps the original code with a structured exception handler, that catches any fatal error and simply writes the code of the error and the address where the error occurs. As the error has been caught, Windows no longer opens the message box (except under debugger). Normally it would be better to use FormatMessage do display the error text, but I could not use it whatever I tried.
A cleaner way would be to use a modified crt0, but I do not like to touch to such a thing ...
I followed the instructions in this video:(See Docs)
What happened is that I created a very basic program in C, here is the code:
#include <stdio.h>
int main()
{
printf("Hey Buddy!\n");
return 0;
}
I compiled it using Mingw and an .exe file was created. Here the problem begins...
When simply opening the file in windows, a cmd window that says "Hey Buddy!" opens and closes immediately.
When trying to run the .exe file using the command line, the same thing happens, but the command line window then becomes stuck and it is impossible to close it - only shutting off the computer can do it.
Your help would be very appreciated, and I am sorry if I am doing something dumb and not realizing it:)
Your program is fine. The main declaration is wrong. It should be
int main(void)
but the declaration in your question won't cause any problems. I'm just telling you this to set you off on the right path.
Of course when you double click on the executable, then a new console window appears and immediately disappears. The program prints a single line of text and returns immediately. That behaviour is as expected.
The problem with the console window that cannot be closed is not down to an error in your code, at least the code that is shown in the question cannot explain that. That is presumably an environmental problem with your machine and/or compiler installation. Or perhaps you just have not yet worked out how to close a console window.
I am new to C programming. In my program below, I am simply trying to immediately, exit the C program without see any additional dialog, if the programs receives the input "quit".
I am trying to accomplish this using exit(0); however, before the program exits it outputs something like
success
process exited with return value 0
Press any key to continue...
I am trying to avoid this dialog and exit the program immediately. Is this possible?
I appreciate any help with this.
Many thanks in advance!
My C Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(void) {
char command1[256], command2[256];
printf("# ");
scanf("%s", command1);
if(strcmp(command1,"quit")==0){
printf("success");
exit(0);
}else{
printf("unknown command");
}
system("PAUSE");
return 0;
}
The message that you see is actually generated by the Visual Studio debugger. It's not really coming from your program.
If you would like to verify that your program is not actually displaying any message (nor waiting for a key press) just try running it from a windows command prompt. You may also try running the program in "Release" mode from withing Visual Studio. That will also confirm this.
The reason the debugger displays that information is just to help you understand what is going on with your program.
Can you post details of your execution environment? Seems like your process is being monitored for an exit code by another application (specialized shell perhaps) which is printing the "Press any key to continue" line
The process exited with return value 0 certainly isn't coming from your code, rather a program in the middle of your input and the output.
I compiled this on the command line (Mac OSX) and was presented with the following output:
James:Desktop iPhone$ gcc code.c
James:Desktop iPhone$ ./a.out
# quit
successJames:Desktop iPhone$
Note that I didn't reach the system("PAUSE"); either
That output doesn't come from YOUR program, it comes from the program that runs your program. Most likely "Visual Studio", but I expect some other types of IDE's may do similar things.
If you are using Dev-C++ and you would like to get rid of the message, do this:
Tools Menu -> Environment Options -> General tab
Then uncheck the Pause Program after return option.
Source: http://www.cplusplus.com/forum/general/89249/