How to use system call in assembler

I write codes to display the dictionary using C,
and it can run well,and then I want to use system call
in assembler to realize the same function ,but it doesn't
display the dictionary,how to correct it?
Look:
//C
#include <stdio.h>
int main()
char *name[2];
name[0]="/bin/ls";
name[1]=NULL;
execve(name[0],name,NULL);
return 0;
//Assembler
.data
msg:.string "/bin/ls"
.text
.global _start
_start:
movl $0xb,%eax
movl $msg,%ebx
mov $msg,%ecx
movl $0,%edx
int $0x80
movl $1,%eax
movl $0,%ebx
int $0x80

If you compile with -Wwrite-strings, as I like to do for new code, you'll notice it warns about assigning the address of read-only memory to a plain char *. You might want to declare name as follows to avoid accidentally trying to modify it:
char const *name[2];
But as for your question. The execve system call requires a pointer to a list (array) of pointers to strings in %ecx. You are passing it a pointer to a single string, which means it will try to interpret the string ("/bin/ls")as a series of pointers to strings, with potentially disastrous (and certainly weird) results.
Last edited by Trent (2012-12-28 15:31:38)

Similar Messages

  • How to get the size of physical memory by using system call ?

    how to get the size of physical memory by using system call ?What system call can be used for me to get the size of physical memor? thanks.

    %vmstat 3
    procs memory page disk faults cpu
    r b w swap free re mf pi po fr de sr s0 -- -- -- in sy cs us sy id
    0 0 0 3025816 994456 4 19 6 0 0 0 0 8 0 0 0 459 253 139 1 1 99
    0 0 0 2864688 777408 0 2 0 0 0 0 0 3 0 0 0 428 134 175 0 1 99
    0 0 0 2864688 777408 0 0 0 0 0 0 0 7 0 0 0 448 112 166 0 0 100
    one interesting observation about vmstat I found out is (mostly on Solaris)
    the first line of information always off chart, so I usually do a few interval to get constant result.
    if you use linux
    just
    cat /proc/meminfo

  • How can I use system call in kernel loadable module?

    Hi,
    I want to use system call (shmat, mmap,...) in kernel module.
    When kernel module is loaded, it cause system error (undefined symbol name 'shmat', 'mmap').
    How can I use system call in kernel module ?
    Thanks in advance.
    david joo

    You cannot use system calls in the kernel modules.
    Read 'Writing Device Drivers' answerbook - it lists the set of interfaces (known as DDI/DDK) that are supposed to be used instead.
    Hope this helps...
    --I.

  • How to get physical memory by using system call ?

    how to get physical memory by using system call ?What system call can I use.thanks

    Use sysconf(3C) with SCPHYS_PAGES

  • How to execute a cvs command using System Call?

    hi all,
    how to execute a cvs login command using system call ?
    thanks,
    dam

    To anyone that reached this post and still dont have a hint, try this small sample - it logs on CVS using installed CVSNT and execute a fake update:
    package testeCVS;
    import java.io.BufferedReader;
    import java.io.File;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.io.OutputStreamWriter;
    import java.io.PrintWriter;
    public class execCMD
        String password="yourPassword";
        String directory="C:\\CVS\\yourPathToProject";
        //send commands to CVS and shows the resulting screen
        public int sendCMD(String[] command) throws IOException, InterruptedException
            ProcessBuilder pb = new ProcessBuilder(command);
            pb.directory(new File(directory));
            pb.redirectErrorStream(true); // merge stdout and stderr
            Process p = pb.start();
            InputStreamReader isr = new  InputStreamReader(p.getInputStream());
            BufferedReader br = new BufferedReader(isr);
            String lineRead;
            StringBuilder buffer=new StringBuilder();
            System.out.println("Return of shell:");
            while ((lineRead = br.readLine()) != null)
                buffer.append(lineRead + "\n");
            System.out.println(buffer.toString());
            return p.waitFor();
        //send commands to CVS, send the password after the prompt and show the resulting screen
        public int sendDialogCMD(String[] command) throws IOException, InterruptedException
            ProcessBuilder pb = new ProcessBuilder(command);
            pb.directory(new File(directory));
            pb.redirectErrorStream(true); // merge stdout and stderr
            Process p = pb.start();
            PrintWriter writer = new PrintWriter( new OutputStreamWriter( p.getOutputStream() ));
            writer.println( password );
            writer.flush();
            InputStreamReader isr = new  InputStreamReader(p.getInputStream());
            BufferedReader br = new BufferedReader(isr);
            String lineRead;
            StringBuilder buffer=new StringBuilder();
            System.out.println("Return of shell:");
            while ((lineRead = br.readLine()) != null)
                buffer.append(lineRead + "\n");
            System.out.println(buffer.toString());
            return  p.waitFor();
        public static void main(String a[]) throws IOException, InterruptedException
            execCMD e=new execCMD();
            String[] command = new String[5];
            command[0] = "cvs";
            command[1] = "-q";
            command[2] = "-d";
            command[3] = ":pserver:yourUserID@localhost:2402/path/of/yourProject"; //in this case using CVS port 2402
            command[4] = "login";
            System.out.println("exit value=" + e.sendDialogCMD(command));
            command = new String[8];
            command[0] = "cvs";
            command[1] = "-q";
            command[2] = "-d";
            command[3] = ":pserver:yourUserID@localhost:2402/path/of/yourProject";
            command[4] = "-n";
            command[5] = "-q";
            command[6] = "update";
            command[7] = "-dA";
            System.out.println("exit value=" + e.sendCMD(command));
    }It is possible to send the password on the same command, but I had problems when the password had the character '@' because CVSNT took it as the separator between the username and server name. In that case the command is: ":pserver:yourUserID:yourPassword@localhost:2402/path/of/yourProject"

  • How to make system call to execute command line in JAVA?

    Hi,
    I am new in JAVA. How to make system call to execute the following command line in JAVA in LINUX environment.
    rpm -qa jdkIn C programming, use as such:
    system ("rpm -qa jdk");
    How about JAVA?
    Thanks.

    Runtime.getRuntime().exec. But first read this:
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html

  • How to get swap size by using system call?

    How can I get the size of swap.What system call or library Routines can be used? please help me.

    Hi,
    Threre's an interface called swap_ctl by wich you can get more information related to virtual memory. Here's an example:
    #include <stdio.h>
    #include <stdlib.h>
    #include <unistd.h>
    #include <sys/stat.h>
    #include <sys/swap.h>
    #include <sys/param.h>
    int
    main(int argc, char*argv[])
    swaptbl_t *st;
    int swap_count, i;
    long long swap_total=0, swap_avail=0;
    long pgsize_in_kbytes = sysconf(_SC_PAGE_SIZE) / 1024L;
    if ((swap_count=swapctl(SC_GETNSWP, NULL)) == -1)
    perror("swapctl(SC_GETNSWP)"), exit(-1);
    if (swap_count == 0)
    (void)printf("No swap files/partitions allocated\n"), exit(0);
    * Although it's not particularly clear in the documentation, you're
    * responsible for creating a variable length structure (ie. the
    * array is within the struct rather than being pointed to
    * by the struct). Also, it is necessary for you to allocate space
    * for the path strings (see /usr/include/sys/swap.h).
    st = (swaptbl_t*)malloc(sizeof(int) + swap_count * sizeof(struct swapent));
    if (st == NULL)
    perror(argv[0]), exit(-1);
    st->swt_n = swap_count;
    for (i=0; i < swap_count; i++) {
    if ((st->swt_ent.ste_path = (char*)malloc(MAXPATHLEN)) == NULL)
    perror(argv[0]), exit(-1);
    if ((swap_count=swapctl(SC_LIST, (void*)st)) == -1)
    perror("swapctl(SC_LIST)"), exit(-1);
    for (i=0; i < swap_count; i++) {
    swap_total += st->swt_ent.ste_pages * pgsize_in_kbytes;
    swap_avail += st->swt_ent.ste_free * pgsize_in_kbytes;
    (void)printf("Total swap = %lld available swap = %lld\n",
    swap_total, swap_avail);
    return 0;
    There's a very interesting document about Solaris Kernel/Performance Stats available at http://www.idiom.com/~gford/admin/howto/perf.html. Very interesting.
    Hope this helps

  • "HOW to use Labview call Dll compiled by VC++"

    "hello,I use VC++ compile a DLL,and i want to call DLL Function in LABVIEW program.But there is a dll function
    when i call it in labview.There is error.The prototype of Dll Function that make error is "USHORT DLLFUN __stdcall IBWRT(unsigned short dev_address,const char *pstrWrite)",The second paramenter is a char pointer,
    and the paramenter pass a command which content is
    "MEASURE:CURRENTC? 1A,0.001MA".
    When i use VC++ to call this function,i program followed:
    CString m_wrt;
    int ReturnW;
    m_wrt="MEASURE:CURRENTC? 1A,0.001MA";
    char buffer[40];
    strcpy(buffer,m_wrt);
    ReturnW=IBWRT(4,buffer);
    and this call is correct.
    But when i use labview to call this function.ther
    e is
    error.So, who can help me,to tell me how to call this
    function.Thanks."

    Are you asking about porting code or calling C++ code in LabVIEW?  As far as porting code, there's no easy way to move code back and forth between LabVIEW and C++.  However, if you are trying to call C++ code in LabVIEW, you can compile it as a DLL and call it in LabVIEW using the Call Library Function node.
    Chad B. » National Instruments » ni.com

  • How to use RIDC calls in webcenter application

    hi,
    We have lot of portlets developed in weblogic portal and consuming content using RIDC calls. How to consume data from UCM repository (site studio pages) in Webcenter JSF pages.
    Thanks
    Manu

    Hi Manu,
    Take a look at our whitepaper - Integrating Oracle ECM with Portal Technologies.
    We showed this integration at the recent Collaborate Conference in April.
    link: http://www.fishbowlsolutions.com/StellentSolutions/ContentManagementResources/index.htm
    Warmly,
    Billy Cripe
    Fishbowl Solutions

  • How to intercept system calls in JVM?

    Hi, everyone. I am looking for a way to intercept system calls in JVM, a way do something like ptrace does in Linux. Because I wanna log all function calls a specified application made, and I may modify the arguments and the return value.
    And then i search the internet but nothing found except this article:
    [  http://java.sun.com/developer/technicalArticles/Programming/jvmti/#Authors|  http://java.sun.com/developer/technicalArticles/Programming/jvmti/#Authors]
    It's seems that JVMTI is a perfect tools to manipulate Java VM and i can achieve my goal with it. I download the sample code you written and modify a bit to adopt my environment (I use Linux and Sun JDK 6). It works well.
    And then I add a function to get stacktrace like the case in your article. I also read the sample code in JVMIT Refenerce, but it doesn't work.
    So, I am puzzled. I wanna know is there any way to intercept system calls in JVM? If JVMTI can do it, is there any tutorial or sample code to review? And, is that possible to use this way in J2ME?
    Thanks a lot :)
    Best Regard.

    jschell wrote:
    Nelly_Zeltser wrote:
    I do not know if there are any tools similar to solaris truss is available to trace system and library calls in j2me world.Well, I want to trace the jvm system calls to OS (UNIX), not java.Are you using j2me?No, to say more I'm not "using" java at all. My program (written on C) just monitors all system calls from another program that I define as the parameter.
    It may not be java. It may be any program:for example my simple .o file made by myself.
    Can we continue this topic at [http://forums.sun.com/thread.jspa?messageID=10746765&#10746765|http://forums.sun.com/thread.jspa?messageID=10746765&#10746765]
    I've written my shared library and defined LD_PRELOAD. But it doesn't help, cuz JVM, afaik, uses LD_PRELOAD for its own purposes, so
    I can't use my shared library.That of course is not what the poster of this thread wanted to do.

  • How to make system call remotely?

    i am working on client- server application i want to execute a system call on cllient machine from server how should i do it?

    If by "system call" you mean Runtime.exec(), then
    Runtime.getRuntime().exec(theCommand)The command needs to be sent from the client. And read this:
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html

  • ? how to use something called quicktime. i click on its icon and it does nothing! i just bought quicktime 7 pro and have a registration

    i just bought a macbook pro and never used apple before. i am trying to convert my movie clips and need to use something called quicktime. i click on its icon and it does nothing! i just bought quicktime 7 pro and have a registration # and it says open quicktime and enter the reg# - how do i do this?

    When you start QT 7 player, under the first menu there is a "Registration" menu item.
    Enter your name and Registration code, THEN hit the TAB KEY. Do not click the "Buy..." button.
    That should do it.
    Make sure you have the CORRECT version of QT 7:
    http://support.apple.com/kb/HT3678

  • How to access system calls from java program?

    i am having a doubt regarding accessing system calls from a Java program like accessing unix system calls from a c program.

    Runtime.getRuntime().exec("line command here");
    example:
    Runtime.getRuntime().exec("ls -la");

  • How to use System Variable SY_ROW in the Process Instruction Category

    Hi ,
    I want to assign a value of System variable SY_ROW to a Normal Variable in the Process Instruction Category and use it in the formula. Please help me with the Syntax in the Process Instruction Category to get the System Variable: SY_ROW value into a Variable.
    Thanks,
    SV

    Hello,
    You can use these variables in formulas or, for example, to pass on certain pieces of information to a function module. How the function called by the function module behaves depends on the type of information passed on.
    SY_ROW is used to view the current Table line.
    Please look into the below link for more details on syntax :
    http://help.sap.com/saphelp_46c/helpdata/en/1a/514e38493e4774e10000009b38f889/frameset.htm
    http://help.sap.com/saphelp_470/helpdata/en/1a/514e38493e4774e10000009b38f889/frameset.htm
    Hope the information is helpful
    Regards

  • How to use system date in filter?

    Hi experts,
    I'd like to use the system date on a filter using the query designer but I don't know how I should do it. I have two characteristics that represent the date and the time that I want to filter. I want to use the system date and time to filter those characteristics. Is it possible?
    Thanks.

    Create one Customer Exit Variable, and assign sy-datum as value to it in Exit Code.
    Current System date in report

Maybe you are looking for

  • How can i change my apple id primary address to my rescue email and vice versa

    I would like to change my primary email address that makes up my Apple ID. I want to use the email that I have listed as my rescue email, but it would let me change it that way. Help please

  • Couldn't upload

    Hi, Pls fin the error in this program. I am unable to upload. Regards, Karthik Program ID       : ZRFC_RUSHORDER Transaction Code : Z* Description      : RFC For Sales Process using        Transaction Method calling                    3 Transactions

  • CS6 timeline not redrawing properly

    I just installed the Premiere CS6 demo on my Mac Pro (Lion 10.7.3), and I've been playing with it for a couple days. So far it's worked like a dream, except for one really strange glitch: in one of my sequences, the timeline doesn't want to redraw wh

  • Flash Player 11.6.602.180: Firefox

    I have updated to this version as the newest available. However I am now unable to play any games (i.e. SimCity Social, Hidden Agenda) on Facebook using Firefox. Instead I have to try and use Chrome which is my least preferable browser. Any ideas tha

  • IPv6 Address in Internal Enterprise

    Hello All, I was looking at a Pilot deploment of IPv6 in our Labs. I was little confused with rgards to what should I use as IPv6 address on Internal Network Infrastructure and hosts. This is when I jumped across BRKRST-2301 where Shanon McFarland gi