Create directory using : _syscallX macro

Code junkies hangout here

Moderators: ChrisThornett, LXF moderators

Create directory using : _syscallX macro

Postby _cih_ » Wed Sep 20, 2006 8:01 pm

Please can anybody giv me any hints, how to create a directory using a :
_syscallX() , macro ?
_cih_
 
Posts: 10
Joined: Wed Sep 13, 2006 4:50 pm

Postby kunchok » Thu Sep 21, 2006 1:28 am

I suspect I'm doing your computer science homework for you!

Look at unistd.h.

The _syscallX macro takes no parameters by itself and is used to specify the architecture specific assembly language prologue needed to set up a transition from user space to kernel space. Some other 'standard' macros make use of _syscallX to give convenient access to the operations provided by the kernel (i.e. system calls). Each system call has a number and in Linux these numbers are given names beginning with __NR_. The name of the number for 'mkdir' is __NR_mkdir and happens to have the value 38.

#define _syscall2(type, name, type1, arg1, type2, arg2) \
type name(type1 arg1, type2 arg2) \
{ \
_syscallX(); \
return (type)syscall(__NR_ ## name, arg1, arg2); \
}

So if we want to create a function that implements the mkdir system call.

_syscall2(int, mkdir, char *, path, int, perms);

And without using the above macro.

int my_mkdir(char *path, int perms)
{
_syscallX(); /* system call prologue */
return (int) syscall(38, path, perms);
}

Hope this helps.
kunchok
 
Posts: 3
Joined: Thu Sep 21, 2006 12:18 am

Postby kunchok » Thu Sep 21, 2006 2:25 am

Sorry, I'm new here and just saw your earlier post. My message probably only relates to user space.

In a kernel module you might try :-

asmlinkage long sys_mkdir(const char __user *pathname, int mode);

Then you can call sys_mkdir() as if it was mkdir() in user space.

For more help.

http://packetstormsecurity.org/docs/hac ... CKING.html

google google google
kunchok
 
Posts: 3
Joined: Thu Sep 21, 2006 12:18 am


Return to Programming

Who is online

Users browsing this forum: No registered users and 0 guests