From 4c2df3b4dd280cc659a51dc8d77e47b5daaef668 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Tue, 25 Sep 2012 13:28:23 +0000 Subject: [PATCH] fixed gcc/fpic issue for x86 in syscall macros --- qse/lib/cmn/syscall.h | 126 ++++++++++++++++++++++++++-------------- qse/lib/net/httpd-std.c | 9 +++ 2 files changed, 91 insertions(+), 44 deletions(-) diff --git a/qse/lib/cmn/syscall.h b/qse/lib/cmn/syscall.h index f40cfe54..990327ed 100644 --- a/qse/lib/cmn/syscall.h +++ b/qse/lib/cmn/syscall.h @@ -381,29 +381,29 @@ typedef DIR qse_dir_t; #define QSE_SYSCALL0(ret,num) \ __asm__ volatile ( \ "movq %1, %%rax\n\t" \ - "syscall\n": \ - "=&a"(ret): \ - "g"((qse_uint64_t)num): \ - "%rcx", "%r11") + "syscall\n" \ + : "=&a"(ret) \ + : "g"((qse_uint64_t)num) \ + : "%rcx", "%r11") #define QSE_SYSCALL1(ret,num,arg1) \ __asm__ volatile ( \ "movq %1, %%rax\n\t" \ "movq %2, %%rdi\n\t" \ - "syscall\n": \ - "=&a"(ret): \ - "g"((qse_uint64_t)num), "g"((qse_uint64_t)arg1): \ - "%rdi", "%rcx", "%r11") + "syscall\n" \ + : "=&a"(ret) \ + : "g"((qse_uint64_t)num), "g"((qse_uint64_t)arg1) \ + : "%rdi", "%rcx", "%r11") #define QSE_SYSCALL2(ret,num,arg1,arg2) \ __asm__ volatile ( \ "movq %1, %%rax\n\t" \ "movq %2, %%rdi\n\t" \ "movq %3, %%rsi\n\t" \ - "syscall\n": \ - "=&a"(ret): \ - "g"((qse_uint64_t)num), "g"((qse_uint64_t)arg1), "g"((qse_uint64_t)arg2): \ - "%rdi", "%rsi", "%rcx", "%r11") + "syscall\n" \ + : "=&a"(ret) \ + : "g"((qse_uint64_t)num), "g"((qse_uint64_t)arg1), "g"((qse_uint64_t)arg2) \ + : "%rdi", "%rsi", "%rcx", "%r11") #define QSE_SYSCALL3(ret,num,arg1,arg2,arg3) \ __asm__ volatile ( \ @@ -411,39 +411,39 @@ typedef DIR qse_dir_t; "movq %2, %%rdi\n\t" \ "movq %3, %%rsi\n\t" \ "movq %4, %%rdx\n\t" \ - "syscall\n": \ - "=&a"(ret): \ - "g"((qse_uint64_t)num), "g"((qse_uint64_t)arg1), "g"((qse_uint64_t)arg2), "g"((qse_uint64_t)arg3): \ - "%rdi", "%rsi", "%rdx", "%rcx", "%r11") + "syscall\n" \ + : "=&a"(ret) \ + : "g"((qse_uint64_t)num), "g"((qse_uint64_t)arg1), "g"((qse_uint64_t)arg2), "g"((qse_uint64_t)arg3) \ + : "%rdi", "%rsi", "%rdx", "%rcx", "%r11") */ #define QSE_SYSCALL0(ret,num) \ __asm__ volatile ( \ - "syscall\n": \ - "=a"(ret): \ - "a"((qse_uint64_t)num) : \ - "%rcx", "%r11") + "syscall\n" \ + : "=a"(ret) \ + :"a"((qse_uint64_t)num) \ + : "%rcx", "%r11") #define QSE_SYSCALL1(ret,num,arg1) \ __asm__ volatile ( \ - "syscall\n": \ - "=a"(ret): \ - "a"((qse_uint64_t)num), "D"((qse_uint64_t)arg1): \ - "%rcx", "%r11") + "syscall\n" \ + : "=a"(ret) \ + : "a"((qse_uint64_t)num), "D"((qse_uint64_t)arg1) \ + : "%rcx", "%r11") #define QSE_SYSCALL2(ret,num,arg1,arg2) \ __asm__ volatile ( \ - "syscall\n": \ - "=a"(ret): \ - "a"((qse_uint64_t)num), "D"((qse_uint64_t)arg1), "S"((qse_uint64_t)arg2): \ - "%rcx", "%r11") + "syscall\n" \ + : "=a"(ret) \ + : "a"((qse_uint64_t)num), "D"((qse_uint64_t)arg1), "S"((qse_uint64_t)arg2) \ + : "%rcx", "%r11") #define QSE_SYSCALL3(ret,num,arg1,arg2,arg3) \ __asm__ volatile ( \ - "syscall\n": \ - "=a"(ret): \ - "a"((qse_uint64_t)num), "D"((qse_uint64_t)arg1), "S"((qse_uint64_t)arg2), "d"((qse_uint64_t)arg3): \ - "%rcx", "%r11") + "syscall\n" \ + : "=a"(ret) \ + : "a"((qse_uint64_t)num), "D"((qse_uint64_t)arg1), "S"((qse_uint64_t)arg2), "d"((qse_uint64_t)arg3) \ + : "%rcx", "%r11") #elif defined(__linux) && defined(__GNUC__) && defined(__i386) @@ -451,27 +451,65 @@ typedef DIR qse_dir_t; #define QSE_SYSCALL0(ret,num) \ __asm__ volatile ( \ - "int $0x80\n": \ - "=a"(ret): \ - "a"((qse_uint32_t)num)) + "int $0x80\n" \ + : "=a"(ret) \ + : "a"((qse_uint32_t)num) \ + : "memory") +/* #define QSE_SYSCALL1(ret,num,arg1) \ __asm__ volatile ( \ - "int $0x80\n": \ - "=a"(ret): \ - "a"((qse_uint32_t)num), "b"((qse_uint32_t)arg1)) + "int $0x80\n" \ + : "=a"(ret) \ + : "a"((qse_uint32_t)num), "b"((qse_uint32_t)arg1)) +GCC in x86 PIC mode uses ebx to store the GOT table. so the macro shouldn't +clobber the ebx register. this modified version stores ebx before interrupt +and restores it after interrupt. +*/ +#define QSE_SYSCALL1(ret,num,arg1) \ + __asm__ volatile ( \ + "push %%ebx\n" \ + "movl %2, %%ebx\n" \ + "int $0x80\n" \ + "pop %%ebx\n" \ + : "=a"(ret) \ + : "a"((qse_uint32_t)num), "r"((qse_uint32_t)arg1) \ + : "memory") + +/* #define QSE_SYSCALL2(ret,num,arg1,arg2) \ __asm__ volatile ( \ - "int $0x80\n": \ - "=a"(ret): \ - "a"((qse_uint32_t)num), "b"((qse_uint32_t)arg1), "c"((qse_uint32_t)arg2)) + "int $0x80\n" \ + : "=a"(ret) \ + : "a"((qse_uint32_t)num), "b"((qse_uint32_t)arg1), "c"((qse_uint32_t)arg2)) +*/ +#define QSE_SYSCALL2(ret,num,arg1,arg2) \ + __asm__ volatile ( \ + "push %%ebx\n" \ + "movl %2, %%ebx\n" \ + "int $0x80\n" \ + "pop %%ebx\n" \ + : "=a"(ret) \ + : "a"((qse_uint32_t)num), "r"((qse_uint32_t)arg1), "c"((qse_uint32_t)arg2) \ + : "memory") +/* #define QSE_SYSCALL3(ret,num,arg1,arg2,arg3) \ __asm__ volatile ( \ - "int $0x80\n": \ - "=a"(ret): \ - "a"((qse_uint32_t)num), "b"((qse_uint32_t)arg1), "c"((qse_uint32_t)arg2), "d"((qse_uint32_t)arg3)) + "int $0x80\n" \ + : "=a"(ret) \ + : "a"((qse_uint32_t)num), "b"((qse_uint32_t)arg1), "c"((qse_uint32_t)arg2), "d"((qse_uint32_t)arg3)) +*/ +#define QSE_SYSCALL3(ret,num,arg1,arg2,arg3) \ + __asm__ volatile ( \ + "push %%ebx\n" \ + "movl %2, %%ebx\n" \ + "int $0x80\n" \ + "pop %%ebx\n" \ + : "=a"(ret) \ + : "a"((qse_uint32_t)num), "r"((qse_uint32_t)arg1), "c"((qse_uint32_t)arg2), "d"((qse_uint32_t)arg3) \ + : "memory") #endif diff --git a/qse/lib/net/httpd-std.c b/qse/lib/net/httpd-std.c index f04a93bc..cc1608a8 100644 --- a/qse/lib/net/httpd-std.c +++ b/qse/lib/net/httpd-std.c @@ -47,6 +47,7 @@ # include # endif # if defined(__linux__) +# include # include /* SO_ORIGINAL_DST */ # endif #endif @@ -1737,27 +1738,35 @@ oops: static int peek_request ( qse_httpd_t* httpd, qse_httpd_client_t* client, qse_htre_t* req) { +/* if (QSE_MEMCMP (&client->local_addr, &client->orgdst_addr, sizeof(client->orgdst_addr)) == 0) { +*/ return process_request (httpd, client, req, 1); +/* } else { return proxy_request (httpd, client, req, 1); } +*/ } static int handle_request ( qse_httpd_t* httpd, qse_httpd_client_t* client, qse_htre_t* req) { +/* if (QSE_MEMCMP (&client->local_addr, &client->orgdst_addr, sizeof(client->orgdst_addr)) == 0) { +*/ return process_request (httpd, client, req, 0); +/* } else { return proxy_request (httpd, client, req, 0); } +*/ } static qse_httpd_scb_t httpd_system_callbacks =