Link to home
Start Free TrialLog in
Avatar of Brian
Brian

asked on

Linux System Calls

When a user performs a system call such as ...  long enc_file(const char *filename, const char *data, long len)

How do you get those arguments inside kernel space?  Basically I have to creat(filename) with *data for as long as len
Avatar of arnold
arnold
Flag of United States of America image

Please clarify your question
Your code has to include the studio.h or applicable header for the commands  you use within your application/program

Commonly you would read the API...
If enc_file(predefined_ptr_file_variable,ptr_to_data,length_of-...)
Avatar of Brian
Brian

ASKER

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>

Working on the kernel version 4.4.1 for linux virtual machine.  I've read the API for creat() but I'm not sure how to implement in kernel space.
i am uncertain I understand what you are asking/trying to do.
You are creating a driver/module....that will run at ....
Avatar of Brian

ASKER

I'm trying to implement 4 new system calls if I can figure one out then the rest should be easy.  The system call should pass some arguments.  I want to know how to access those arguments once in kernel space.

unsigned long _copy_from_user (void * to, const void __user * from, unsigned n);

I understand with this function I can copy n bytes from user to a buffer in kernel space, but I don't know what to use for *from.
Thank you
*from is the pointer to the user's pace from which you want to copy.
Potentially this is used by a caching scheduler to copy user data out while paging.

You fair better instead of providing command system calls you want to use, to explain what the thing you are doing and how to get to it.
You reference tools, but it is unclear how they relate ...
Avatar of Brian

ASKER

I'm creating a system call with 3 arguments, a filename to create, pointer to a buffer, and a length.  I want the system call to create a file or overwrite an existing file with the same name, write from the buffer up to the length.  

Normally if I were to pass arguments I can obtain them like this.data or this->data but I don't know how to do that in kernel space.  Would it be in an argc array such as argc[1], argc[2], arg[3] etc..

I know they are stored in registers but how do I access those arguments from the system call, that's all I want to know
Avatar of Brian

ASKER

I'm not familar with caching scheduler
The kernel runs a scheduler that deals with managing resource allocation to processes, it has to move user process data from memory to disk, while granting another resource/process time to run. at which point it copies the data from disk into memory...


What the big picture of what you are trying to do? Usually programs have/use user space.
Avatar of Brian

ASKER

Ok, say I want to create a file from kernel space with just hello world and call it hello.txt

Now from user space I pass in a pointer to the buffer with the text 'hello world'.  If the system call were to invoke my custom system call and have arguments, shouldn't I be able to access them in kernel space?

There is no big picture, I'm learning how to make a system call for a linux kernel.
This process can be a bit complex.

Best to find one of the many guides, which provides each step.

Here are a few which jump out, as containing good info for structuring your syscall...

http://www.franksthinktank.com/howto/addsyscall/

https://tssurya.wordpress.com/2014/08/19/adding-a-hello-world-system-call-to-linux-kernel-3-16-0/

https://medium.com/@ssreehari/implementing-a-system-call-in-linux-kernel-4-7-1-6f98250a8c38
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.