Solved

System Call Returns Gibberish

Posted on 2006-11-27
2
211 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

747 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

12 Experts available now in Live!

Get 1:1 Help Now