• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 244
  • Last Modified:

System Call Returns Gibberish

I attempting to add a system call to 2.4.18-3, but I keep getting garbage on the return from the system call instead of the correct and much friendlier "Howdy" that's supposed to show up.  Here's the code I've used in each of the directories:


.long SYMBOL_NAME(sys_hello_world)


#define __NR_hello_world


#include <linux/linkage.h>

#include <unistd.h>
_syscall1(void, hello_world, char*, buf);

#include <linux/kernel.h>
  #include <asm/uaccess.h>
  #include <linux/hello_world.h>

  asmlinkage void sys_hello_world(char *buf)
          int num_left;
          static char *hello = "Hello World";

          printk("Copy hello world to user space.\n");
          num_left = copy_to_user(buf, hello, 12);
          if (num_left)
                  printk("Number of bytes left, %d\n", num_left);

I added the following line to the Makefile in the Linux-2.4 directory:

obj-y   := util.o hello_world.o

This is my test file:

#include <stdio.h>
#include <linux/hello_world.h>

          char buf[25];

The output is some ASCII gibberish and I can't figure out why it would be ASCII (gibberish I can understand, but ASCII...no).  Any ideas?

1 Solution
You don't include /usr/include/sys/hello_world-usr.h - suppose just a typo, since it's compiling.
the problem might be that buf variable is not null delimited string. Try
#include <string.h>
int main()
 char buf[25];
 bzero(buf, 25);
 return 0;    
cdromesAuthor Commented:
I was forgetting to do a 'make install' in order to ensure I was running the modified kernel after every change.  

Yes, that's right, I AM a genius, thanks.  

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now