Sponsored Content
Top Forums Programming Adding custom ("Hello") system call: help Post 302486522 by courteous on Sunday 9th of January 2011 06:22:22 AM
Old 01-09-2011
Adding custom ("Hello") system call: help

I'm trying to add a custom ("Hello world" Smilie) system call.
In /usr/src/linux/hello/ I put simple hello.c ...
Code:
#include "linux/linkage.h" // for linking a system call
#include "linux/kernel.h" // for "printk"

asmlinkage int sys_hello() 
{
	printk(KERN_ALERT "Hello!");
	return 1;
}

... and in home directory helloTest.c:
Code:
#include <stdio.h>
#include <sys/syscall.h>
#include <linux/unistd.h>

#define __NR_hello	338

int main()
{
	syscall(__NR_hello);
	return 0;
}

I compiled helloTest.c and ran ./a.out: in /var/log/messages nothing gets written! Smilie

Before "compile & install & reboot" I did these steps (linux is symbolic link to linux-2.6.35.10):
  1. In /usr/src/linux/arch/x86/include/asm/unistd_32.h, I've added/changed:
    Code:
    #define __NR_hello	 338
    #define __NR_syscalls	 339

  2. In /usr/src/linux/arch/x86/kernel/syscall_table.S, I've added (on the last line):
    Code:
    .long sys_hello

  3. In /usr/src/linux/hello, I've created a Makefile:
    Code:
    obj-y += hello.o

    ... and in /usr/src/linux, I've modified Makefile and added hello/ directory:
    Code:
    core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ hello/

  4. In /usr/src/linux/include/linux/syscalls.h, I've added (on the last line):
    Code:
    asmlinkage long sys_hello(void)


Last edited by courteous; 01-09-2011 at 04:41 PM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies

2. Shell Programming and Scripting

Adding custom mesg. when redirecting "exec 2>stderr.err" ?

Doubt regarding using "exec" command to redirect the STDERR to a file. e.g I did it this way. mystage.sh #!/bin/sh exec 2>stage.err .... .... cat stage.err mv: cannot move `/root/stage' to a subdirectory of itself, `/root/stage_old/stage' ls: *.zDB: No such file or... (0 Replies)
Discussion started by: snurani
0 Replies

3. Programming

Problem with socket binding - "system" call

Hi, I am having an issue with using sockets. I have a program which binds to a socket and listen on it. Later I spawn a thread to handle some function. In the new thread created I need to call a shell script which executes the specified function. Here I am using a system command to call the... (5 Replies)
Discussion started by: Janardhanbr
5 Replies

4. IP Networking

Configure a range of ports to "socket" system call

Hello ; This what i want to do : I know that in the system call #include <sys/socket.h> int bind(int socket, const struct sockaddr *address, socklen_t address_len); you can specify the local port for your socket, but im using a private library , and im sure that in that library... (0 Replies)
Discussion started by: trutoman
0 Replies

5. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

6. Post Here to Contact Site Administrators and Moderators

Suggestion: adding two new groups "sed" and "awk"

Majority of the questions are pertaining file/string parsing w.r.t sed or awk It would be nice to have these two as their own sub category under shell-programming-scripting which can avoid lot of duplicate posts. (1 Reply)
Discussion started by: jville
1 Replies

7. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

8. Shell Programming and Scripting

awk "date" and "system" command

Hello experts! I need your help please I have a file.txt of which I want to extract 3rd and 4th columns with date with the form e.g.: 2016-11-25 03:14:50and pass them to "date" command, but also append the 9th column in a file as well. So I want to execute date -d '2016-11-25 03:14:50' ... (2 Replies)
Discussion started by: phaethon
2 Replies

9. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

10. UNIX for Beginners Questions & Answers

What does "force devmap reload" as in "multipath -r" means for my system and stability of my system?

Cannot present unpresented disks back again. On a test server tried this as a solution "multipath -r" and it worked. Too worried to try it in production before I know all the information. Any info would be appreciated! Also some links to the documentation on this specific issue could help a... (1 Reply)
Discussion started by: jsteppe
1 Replies
All times are GMT -4. The time now is 08:45 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy