Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

System Call Returns Gibberish

Posted on 2006-11-27
2
Medium Priority
?
232 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 600 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

Question has a verified solution.

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

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…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

971 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