I am trying to create a new system call in Minix 3.3. At first i just want to create simple printmsg() call that will write "Hello World" on screen.
I looked various tutorials on internet and still couldn't find out solution.
I defined my sys call number in callnr.h like this #define PM_PRINTMSG (PM BASE + 48) and i increased number of sys calls #define NR_PM_CALLS 49.
In table.c I added CALL(PM_PRINTMSG) = doprintmsg.
In proto.h I described function prototype `int do_printmsg(void);
Function implementation is written in misc.c. I added #include <stdio.h> and made Hello World function int do printmsg(){ printf("I am a system call"); return 0; }
When I test my system call in user program _syscall(PM_PROC_NR, PM_PRINTMSG, &m); I don't get any errors but no printf is displayed.
So, is it possible to printf messages from system calls since i had to add <stdio.h> myself in misc.c or i missed some steps. I forgot to mention that i go in /usr/src/releasetools and type make services and make install respectively to recompile kernel.
I figured out what was the problem, so i will post answer if someone needs this in future. I did everything well in this example but i failed to compile kernel.
The location was correct which is usr/src/releasetools, but command needed is make hdboot. Also i figured out my PC somehow wasnt working well with this virtual machines and i had many errors while compiling even though i didn't change anything. When i switched to laptop everything worked fine.
My conclusion is sometimes there is just something wrong on your machine so you should try and test problems on different ones
In my opinion, with the continuous evolution of MINIX 3 and its series, it will be wise to only follow the developer's guide directly from the minix3.org website here
Although you managed to solve the problem yourself, the latest version of MINIX3 (MINIX 3.4) will follow a more advanced and suitable approach.
Please visit the link to learn more.
Many regards.
Ola
Related
I am pulling my hear out for quite a while. I am trying to achieve position independent code on a microcontroller. It's quite a rabbit hole. I've gotten so far that I can bring my app online, and responsive for mqtt commands.
The only thing I can't seem to do, for to me completely unknown reasons, is 1 specific stdlib call: vsnprintf or any of its siblings. I am using the arm-none-eabi toolchain version 10.2. I have the source code, also of this specific function, but it goes sooo deep into stuff I just don't understand enough about, so I am stuck on every attempt to get around this problem.
I am using lwip (light weight IP) which makes calls into snprintf. It works fine, until I relocate my app to a different location in flash. The .got section and sram memory is properly patched with the lma_offset I calculate in my custom bootloader. Again, everything works, except this horrible single freaking call into the std lib.
For debugging purposes, I made a wrapper for snprintf in the hope I could drill down just a bit more to understand what the problem is. I am not getting much further.
int snprintf_override (
char *__restrict buffer,
size_t size,
const char *__restrict format,
...)
{
int result;
va_list args;
va_start(args, format);
// The next line calls into std lib, and hard faults, I wish I could share anything else that made any sense...
result = vsnprintf(buffer, sizeof(buffer), format, args);
va_end(args);
return result;
}
Question 1:
Is there anybody who can suggest another way to achieve functionally the same as vsnprintf? Is it even doable to write something from scratch? I have the feeling there is quite some complexity in that function?
Question 2:
Or, is there anybody, who has ANY idea what can be the problem in relocating code which causes svnprintf to fail? Digging through the stdlib code I come across REENT / impurepointers (?), and the implementation relies on a FILE instance. Still "just data" I would say in my naivety, but maybe it's more than that? Is there some assembly hidden somewhere which is simply not relocatable (I can't believe it's not possible, linux OS does nothing else than compile with -fpic...)?
I am afraid this question gets little attention, but maybe, just maybe, somebody with some severe understanding of std lib and/or position independent code clicks on it, and is willing to help me out...
I never found out exactly goes wrong in the libc-nano. But, I think I have proof enough that the problem I ran into has everything to do with libc-nano not being compiled with -fpic.
I reproduced the problem in a smaller test setup which consists of:
a bootloader (runs from 0x60000000) which copies vtor of app to sram,
an app (runs from 0x60020000 or 0x600a0000) which copies global offset table, data, and c++ constructors, to sram, during startup.
in the main of the app, I only make a call to stdlib's vsnprintf.
libc-nano
picolibc
picolibc recompiled with -fpic
app#0x60000000
works
works
works
app#0x600a0000
hard fault
hard fault
works
I integrated picolibc (recompiled with -fpic) into my original project. Now everything works perfectly.
I have never been good at reading and understanding C & C++ Library documentation, for some reason. It's drives me insane. If I see a working sample then I'm good for most other things.
I have installed libsmbios-dev and libsmbios-doc on my ubuntu based machine.
The Library docs are located at /usr/share/doc/libsmbios-doc/doxygen/libsmbios_c
Can anyone provide a working example of pulling the service tag number on a dell machine using libsmbios?
I've search and I can't seem to find what i'm looking for.
Thank you
Could this function be the one you're looking for?
char *sysinfo_get_service_tag();
Defined in service_tag.c, declared in system_info.h. I am unable to test this, but you would presumably include this file in your code.
#include <smbios_c/system_info.h>
at the top of your code:
#include <smbios_c/system_info.h>
when you want to obtain the service tag, in your program.
just call the function, from the library, that performs the desired operation. I.E.
sysinfo_get_dell_system_id();
which returns an int that is the system ID
There is no need to have the source code, as the executable function is in the library. libsmbios-def, which you will need to include in your link step.
I need to run a program that crawls websites and I already have an algorithm and some parts of the code. Problem is, I do not know how to insert wget into my source code. Our student assistant hinted that some kind of keyword or function shall be used before the wget( system, I think or something but I'm not so sure).
when to not use system:
1.) when you want to distribute the program to different environment, where the program you call via system is not available
2.) in a security relevant environment, where you have to make sure that the program you call is really the program you want it to be
3.) when the thing you want to do can easily be accomplished in 10-20 lines of C code
4.) in performance-critical applications
so, you should use system virtually never.
instead, to accomplish the same thing, you could use libcurl, as David suggested (his answer seems to be gone...), or do some socket programming (it's C, after all).
In a real-world scenario, I'd probably just default to writing the crawler in a different language. web requests and complex string processing are not necessarily the strong sides of C, and most definitely not very convenient to use :)
You can use the system() command.
In your case (possibly):
system("/bin/wget");
But if you want really call wget with parameters, so you should use execl().
execl("/bin/wget", "http://anyadress.com/file");
Whenever , you want to run shell commands from your C program , you use system("shell command").In your case
system("wget");
Note - wget is an executable , whose location is added to the path variable, so there is no need to specify the path explicitly.
-- Example --
#include <stdio.h>
#define BUFFLEN 2500
int main()
{
char web_address[BUFFLEN] = "www.google.com";
system("wget 'web_address' ");
return 0;
}
The system command is used to execute a shell command. man system
I am using the Windows 8 pro. I recently installed C-free professional 5 in it. When I compiled a simple hello world c program I got an error while compiling it called as dwarf error. It said something like this.
[Error] Dwarf Error: Offset (700) greater than or equal to (null) size (4954657).
The hello world program is as follows:
#include <stdio.h>
int main()
{
printf("Hello World!\n");
return 0;
}
There's absolutely nothing wrong with that code although it would be better with one of the two canonical forms of main:
int main (void) { ...
Therefore your problem lies with the environment. It appears from some investigation that:
the CFree web site and product haven't been updated any time in the last three+ years;
it only purports to support up to Windows 7;
it looks like it's run as one of those typical one or two-man operations, with little active support; and
it uses a proprietary licence.
Because of all that, I would strongly suggest switching to a product that will give you better support.
For example, Code::Blocks appears to have most, if not all, of the features claimed by C-Free. On top of that, it uses a GPL3 license, you can get it and use it for zero cost, and has a very active community behind it for support services, rather than a single email address somewhere in China that may or may not respond/exist :-)
Dwarf, by the way, is a debugging format, so my best guess at the problem would be that the IDE isn't very well matched to the underlying tools, a good reason to avoid it in my opinion.
I'm a newbie to kernel programming, and I'm stuck on something, so I'd appreciate some help. I appologize in advance if something similar was asked before, I did not find any relevant post, and could find explanations on the web which were simple enough for someone unexperienced as myself in this field to understand.
I want to experiment with my own version of ext2.
I've got the source files from kernel.org, and made the proper changes. Nothing fancy, just to check something I had in mind.
Now I want to insert it to my linux kernel (ubuntu 2.6.31-14-generic-pae if it matters).
How can I do this?
My (obviously naive) initial thought was to simply use the makefile that comes along with it (after manually setting various flags there so it has obj-m/obj-y where needed) and compile it as a kernel module.
However I keep getting errors during compile time about redifining macros, implicit declarations of functions etc. For example
ext2.h:181:1: warning: "ext2_find_first_zero_bit" redefined
balloc.c:574: error: implicit declaration of function dquot_free_block_nodirty
Obviously this is not the way to go. I guess worst case scenario is compiling the entire kernel again (with my modified ext2 code instead of the original) so it creates the relevant library with my own ext2, and rebooting from the new image. I find it hard to believe this is the best approach.
Is it even possible for a new file system to be inserted as a kernel module?
Myabe I should put my modified ext2 code in /usr/src and somehow compile only the relevant library which contains the current ext2 code?
Anyway, I'd appreciate any help on what should I be doing.
Thank you
Do a search and replace of ext2 with my_awesome_filesystem or some such.