From owner-freebsd-hackers@FreeBSD.ORG Mon Mar 26 17:56:09 2012 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 8F89D1065673 for ; Mon, 26 Mar 2012 17:56:09 +0000 (UTC) (envelope-from maninya@gmail.com) Received: from mail-yx0-f182.google.com (mail-yx0-f182.google.com [209.85.213.182]) by mx1.freebsd.org (Postfix) with ESMTP id 4D5DC8FC0C for ; Mon, 26 Mar 2012 17:56:09 +0000 (UTC) Received: by yenl9 with SMTP id l9so4918689yen.13 for ; Mon, 26 Mar 2012 10:56:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=PkRgrZleL6OXqoDHlypGEnBEtSUTZ/yrjOdZsbLliVc=; b=qM+jxHgmMAp5Rp0LADzbrCt0nkuGt9gFzCAB/UiTWokHnCdJNf8a7+6FbCJjgTtJTW g8lJBHWrIe9Kp1jEpO7ezuDLupxmFlQlTe9o6SlsvICKt4Y5aL32HGfMOeeB3gKsb3nV 5676SvRhBmW8Tm9QUqUPEaXKSe87O6wbYyCF9wlRpxbTwplZRCWXaOYfCBgdUoJdXlad VSlkPZlDKvQvJ0pSXLpYj+rIpJI/zgKaT3WmFVye4FD5Yfv16dcQAjzztLTBeOvGBMKz j3+b0SVMQm/mrfU3BSnM2xzCt+5Din9H9hgP4ZKsu+j5exSSU0ucFFD8FPuxteYDJ+4R 9HMA== MIME-Version: 1.0 Received: by 10.101.176.8 with SMTP id d8mr7134155anp.56.1332784568687; Mon, 26 Mar 2012 10:56:08 -0700 (PDT) Received: by 10.146.238.13 with HTTP; Mon, 26 Mar 2012 10:56:08 -0700 (PDT) Date: Mon, 26 Mar 2012 23:26:08 +0530 Message-ID: From: Maninya M To: freebsd-hackers@freebsd.org Content-Type: text/plain; charset=ISO-8859-1 X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Subject: __NR_mmap2 in FreeBSD X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 26 Mar 2012 17:56:09 -0000 I am trying to convert a function written for Linux to FreeBSD. What is the equivalent of the __NR_mmap2 system call in FreeBSD? I keep getting the error because of this exception: warn("Wanted space at address 0x%.8x, mmap2 system call returned 0x%.8x. This could be a problem.",addr,temp_regs.eax); I changed temp_regs.eax = __NR_mmap2; to temp_regs.eax = 192; but it didn't work. I suppose I couldn't understand this function. Please help. This is the function: void map_memory(unsigned long addr, unsigned long size, int flags) { int status; struct user_regs_struct regs,temp_regs; unsigned long int_instr = 0x000080cd; /* INT 0x80 */ if (ptrace(PTRACE_GETREGS,exec_pid,NULL,®s) < 0) die_perror("ptrace(PTRACE_GETREGS,%d,NULL,®s)",exec_pid); /* mmap2 system call seems to take arguments as follows: * eax = __NR_mmap2 * ebx = (unsigned long) page aligned address * ecx = (unsigned long) page aligned file size * edx = protection * esi = flags * Other arguments (fd and pgoff) are not required for anonymous mapping */ temp_regs = regs; temp_regs.eax = __NR_mmap2; temp_regs.ebx = addr; temp_regs.ecx = size; temp_regs.edx = flags; temp_regs.esi = MAP_PRIVATE | MAP_ANONYMOUS; temp_regs.eip = temp_regs.esp - 4; if (ptrace(PTRACE_POKETEXT,exec_pid,(void *)(temp_regs.eip),(void*)int_instr) < 0) die_perror("ptrace(PTRACE_POKETEXT,%d,0x%.8x,INT 0x80) failed while allocating memory",exec_pid,temp_regs.eip); if (ptrace(PTRACE_SETREGS,exec_pid,NULL,&temp_regs) < 0) { die_perror("ptrace(PTRACE_SETREGS,%d,...) failed while allocating memory",exec_pid); } if (ptrace(PTRACE_SINGLESTEP,exec_pid,NULL,NULL) < 0) die_perror("ptrace(PTRACE_SINGLESTEP,...) failed while executing mmap2"); wait(&status); if (WIFEXITED(status)) die("Restarted process abrubtly (exited with value %d). Aborting Restart.",WEXITSTATUS(status)); else if (WIFSIGNALED(status)) die("Restarted process abrubtly exited because of uncaught signal (%d). Aborting Restart.",WTERMSIG(status)); if (ptrace(PTRACE_GETREGS,exec_pid,NULL,&temp_regs) < 0) { die_perror("ptrace(PTRACE_GETREGS,...) failed after executing mmap2 system call"); } if (temp_regs.eax != addr) warn("Wanted space at address 0x%.8x, mmap2 system call returned 0x%.8x. This could be a problem.",addr,temp_regs.eax); else if (cr_options.verbose) fprintf(stdout,"Successfully allocated [0x%.8lx - 0x%.8lx]\n",addr,addr+size); /* Restore original registers */ if (ptrace(PTRACE_SETREGS,exec_pid,NULL,®s) < 0) { die_perror("ptrace(PTRACE_SETREGS,...) when restoring registering after allocating memory (mmap2)"); } } -- Maninya