Link to home
Start Free TrialLog in
Avatar of cdromes
cdromes

asked on

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:

/linux/arch/i386/kernel/entry.S:

.long SYMBOL_NAME(sys_hello_world)

/linux/include/asm/unistd.h:

#define __NR_hello_world

linux/include/linux/hello_world.h:

#ifndef __LINUX_HELLO_WORLD_H
#define __LINUX_HELLO_WORLD_H
#include <linux/linkage.h>
#endif

usr/include/sys/hello_world-usr.h:
#include <unistd.h>
_syscall1(void, hello_world, char*, buf);

linux/ipc/hello_world.c:
#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>

main()
  {
          char buf[25];
          hello_world(buf);
          puts(buf);
  }

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?

Jason
ASKER CERTIFIED SOLUTION
Avatar of ravenpl
ravenpl
Flag of Poland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cdromes
cdromes

ASKER

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.  

Jason