From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18370 invoked by alias); 12 Nov 2013 22:47:22 -0000 Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org Received: (qmail 18359 invoked by uid 89); 12 Nov 2013 22:47:22 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.4 required=5.0 tests=AWL,BAYES_50,RDNS_NONE,SPF_PASS autolearn=no version=3.3.2 X-HELO: mail-ee0-f53.google.com Received: from Unknown (HELO mail-ee0-f53.google.com) (74.125.83.53) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Tue, 12 Nov 2013 22:47:21 +0000 Received: by mail-ee0-f53.google.com with SMTP id e51so3477031eek.40 for ; Tue, 12 Nov 2013 14:47:12 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=uX16eQ3q7KKrlM65VWWCopM/BpIgmqeZdt85hANmYYs=; b=myehuXkhCkeD3pRCtH1kPy1PqQkvmvCGdPxyEiQXPTLptL8K5GOeDo4j/lwhlW1VxR bZlCwxMJ0qzWrFkHC/Sf5ZGtxrCDg7OC78fxvMd8ynwrU7YrCJSe9CtGk/+FeEjWpn2c phEaIm8oaCfb3mpRMnSRmwlozMMIPRhTG9JZqQ+cm5fRuCs4bbv1bF3be4XT3L6KS7ZE HxsH17eJdNRIsSVKFdJDZK7cBKiFrKoxlfyibWjjsnXL7aYdL/JtprD2yPUYSD7aROUB QkQNKgz6KT/CEC7UJmP6lI4m/F1yg5l2dyoLBEJ881RBLCgQiONW3wZALWptcp2CgVIR gU7g== X-Gm-Message-State: ALoCoQkqiXbr+fG9X4rpExZ6A96sTxSCpx+vhuTL1MDd1b+cstgjCBoxKRkIrDUbfBYIS7nJRQIQOEafqs2HgtLsiFjwBU9p7cmCPJ9Wm7GGzZiGx8mxGC9jxL8gVq9hxTMZ22H2YbmFD7A4kodYc7k9ecHueRTu5ybo8xFFC2CY6BFogeSasBS+WX0X8jvRxneSLT9d4A5O MIME-Version: 1.0 X-Received: by 10.15.32.73 with SMTP id z49mr9742754eeu.27.1384296432096; Tue, 12 Nov 2013 14:47:12 -0800 (PST) Received: by 10.223.103.4 with HTTP; Tue, 12 Nov 2013 14:47:11 -0800 (PST) In-Reply-To: References: Date: Tue, 12 Nov 2013 22:47:00 -0000 Message-ID: Subject: Re: back into the thread.... From: Sterling Augustine To: Mark Manning Cc: gdb@sourceware.org Content-Type: text/plain; charset=ISO-8859-1 X-IsSubscribed: yes X-SW-Source: 2013-11/txt/msg00051.txt.bz2 On Tue, Nov 12, 2013 at 2:42 PM, Sterling Augustine wrote: > This feature clearly works. > .. This time with a couple of cleanups. The old example definitely works, this just eliminates an extraneous call to malloc and an uninitialized variable. include #include #include #include #include const char bytes[] = { 0x89, 0xf8, 0xc3 }; #define EXEC_BYTES sizeof(bytes) typedef int(*function_ptr)(int); int main(int argc, char *argv[]) { int test_val = 5; int return_val; function_ptr dst; if (posix_memalign((void **) &dst, 4096*8, EXEC_BYTES) != 0) { printf("can't allocate.\n"); exit (-1); } if (mprotect(dst, EXEC_BYTES, PROT_READ|PROT_WRITE|PROT_EXEC) != 0) { printf("can't mprotect\n"); exit (-1); } if (argc > 1) test_val = atoi(argv[1]); memcpy(dst, bytes, EXEC_BYTES); return_val = dst(test_val); printf("return val was %d\n", return_val); return 0; }