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/en try.S:
.long SYMBOL_NAME(sys_hello_worl d)
/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_worl d-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
/linux/arch/i386/kernel/en
.long SYMBOL_NAME(sys_hello_worl
/linux/include/asm/unistd.
#define __NR_hello_world
linux/include/linux/hello_
#ifndef __LINUX_HELLO_WORLD_H
#define __LINUX_HELLO_WORLD_H
#include <linux/linkage.h>
#endif
usr/include/sys/hello_worl
#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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Yes, that's right, I AM a genius, thanks.
Jason