Solved

System Call Returns Gibberish

Posted on 2006-11-27
2
216 Views
Last Modified: 2010-04-22
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
0
Comment
Question by:cdromes
2 Comments
 
LVL 43

Accepted Solution

by:
ravenpl earned 200 total points
ID: 18026004
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);
 hello_world(buf);
 puts(buf);
 return 0;    
}
0
 

Author Comment

by:cdromes
ID: 18040931
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
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
shell script help 1 145
Expect & sshpass package for Solaris 10 x86 15 914
KVM vs  Qemu 4 111
busybox bash/ash - bash -x | grep 19 139
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now