File: enable-portability-beyond-i386-and-amd64.patch

package info (click to toggle)
udt 4.11%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,096 kB
  • sloc: cpp: 10,426; makefile: 64
file content (225 lines) | stat: -rw-r--r-- 5,849 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
From: Guillem Jover <guillem@debian.org>
Date: Fri, 24 Jan 2025 02:18:14 +0100
X-Dgit-Generated: 4.11+dfsg1-1.1 396fb9b55ee4e86741608cd4bddfdab41168a7a2
Subject: Enable portability beyond i386 and amd64

Closes: #646778

---

diff --git a/app/Makefile b/app/Makefile
index 9d16c0f..3a3275c 100644
--- a/app/Makefile
+++ b/app/Makefile
@@ -1,41 +1,8 @@
 C++ = g++
 
-ifndef os
-   os = LINUX
-endif
-
-ifndef arch
-   arch = IA32
-endif
-
-CCFLAGS = -Wall -D$(os) -I../src -finline-functions -O3
-
-ifeq ($(arch), IA32)
-   CCFLAGS += -DIA32 #-mcpu=pentiumpro -march=pentiumpro -mmmx -msse
-endif
-
-ifeq ($(arch), POWERPC)
-   CCFLAGS += -mcpu=powerpc
-endif
-
-ifeq ($(arch), IA64)
-   CCFLAGS += -DIA64
-endif
-
-ifeq ($(arch), SPARC)
-   CCFLAGS += -DSPARC
-endif
-
+CCFLAGS = -Wall -I../src -finline-functions -O3
 LDFLAGS = -L../src -ludt -lstdc++ -lpthread -lm
 
-ifeq ($(os), UNIX)
-   LDFLAGS += -lsocket
-endif
-
-ifeq ($(os), SUNOS)
-   LDFLAGS += -lrt -lsocket
-endif
-
 DIR = $(shell pwd)
 
 APP = appserver appclient sendfile recvfile test
diff --git a/src/Makefile b/src/Makefile
index fbe57bb..fdc92cf 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -1,34 +1,6 @@
 C++ = g++
 
-ifndef os
-   os = LINUX
-endif
-
-ifndef arch
-   arch = IA32
-endif
-
-CCFLAGS = -fPIC -Wall -Wextra -D$(os) -finline-functions -O3 -fno-strict-aliasing -fvisibility=hidden
-
-ifeq ($(arch), IA32)
-   CCFLAGS += -DIA32
-endif
-
-ifeq ($(arch), POWERPC)
-   CCFLAGS += -mcpu=powerpc
-endif
-
-ifeq ($(arch), SPARC)
-   CCFLAGS += -DSPARC
-endif
-
-ifeq ($(arch), IA64)
-   CCFLAGS += -DIA64
-endif
-
-ifeq ($(arch), AMD64)
-   CCFLAGS += -DAMD64
-endif
+CCFLAGS = -fPIC -Wall -Wextra -finline-functions -O3 -fno-strict-aliasing -fvisibility=hidden
 
 OBJS = api.o buffer.o cache.o ccc.o channel.o common.o core.o epoll.o list.o md5.o packet.o queue.o window.o
 DIR = $(shell pwd)
diff --git a/src/channel.cpp b/src/channel.cpp
index 7b010f0..13e8083 100644
--- a/src/channel.cpp
+++ b/src/channel.cpp
@@ -164,7 +164,7 @@ void CChannel::setUDPSockOpt()
       tv.tv_usec = 100;
    #endif
 
-   #ifdef UNIX
+   #ifdef __unix__
       // Set non-blocking I/O
       // UNIX does not support SO_RCVTIMEO
       int opts = ::fcntl(m_iSocket, F_GETFL);
@@ -292,7 +292,7 @@ int CChannel::recvfrom(sockaddr* addr, CPacket& packet) const
       mh.msg_controllen = 0;
       mh.msg_flags = 0;
 
-      #ifdef UNIX
+      #ifdef __unix__
          fd_set set;
          timeval tv;
          FD_ZERO(&set);
diff --git a/src/common.cpp b/src/common.cpp
index 3b6ffda..315c92d 100644
--- a/src/common.cpp
+++ b/src/common.cpp
@@ -101,7 +101,7 @@ void CTimer::rdtsc(uint64_t &x)
       return;
    }
 
-   #ifdef IA32
+   #if defined(__i386__)
       uint32_t lval, hval;
       //asm volatile ("push %eax; push %ebx; push %ecx; push %edx");
       //asm volatile ("xor %eax, %eax; cpuid");
@@ -109,9 +109,9 @@ void CTimer::rdtsc(uint64_t &x)
       //asm volatile ("pop %edx; pop %ecx; pop %ebx; pop %eax");
       x = hval;
       x = (x << 32) | lval;
-   #elif defined(IA64)
+   #elif defined(__ia64__)
       asm ("mov %0=ar.itc" : "=r"(x) :: "memory");
-   #elif defined(AMD64)
+   #elif defined(__amd64__)
       uint32_t lval, hval;
       asm ("rdtsc" : "=a" (lval), "=d" (hval));
       x = hval;
@@ -135,7 +135,7 @@ uint64_t CTimer::readCPUFrequency()
 {
    uint64_t frequency = 1;  // 1 tick per microsecond.
 
-   #if defined(IA32) || defined(IA64) || defined(AMD64)
+   #if defined(__unix__)
       uint64_t t1, t2;
 
       rdtsc(t1);
@@ -191,11 +191,11 @@ void CTimer::sleepto(uint64_t nexttime)
    while (t < m_ullSchedTime)
    {
       #ifndef NO_BUSY_WAITING
-         #ifdef IA32
+         #if defined(__i386__)
             __asm__ volatile ("pause; rep; nop; nop; nop; nop; nop;");
-         #elif IA64
+         #elif defined(__ia64__)
             __asm__ volatile ("nop 0; nop 0; nop 0; nop 0; nop 0;");
-         #elif AMD64
+         #elif defined(__amd64__)
             __asm__ volatile ("nop; nop; nop; nop; nop;");
          #endif
       #else
diff --git a/src/epoll.cpp b/src/epoll.cpp
index 0e7ddb1..ec1fe14 100644
--- a/src/epoll.cpp
+++ b/src/epoll.cpp
@@ -38,7 +38,7 @@ written by
    Yunhong Gu, last updated 01/01/2011
 *****************************************************************************/
 
-#ifdef LINUX
+#ifdef __linux__
    #include <sys/epoll.h>
    #include <unistd.h>
 #endif
@@ -70,7 +70,7 @@ int CEPoll::create()
 
    int localid = 0;
 
-   #ifdef LINUX
+   #ifdef __linux__
    localid = epoll_create(1024);
    if (localid < 0)
       throw CUDTException(-1, 0, errno);
@@ -115,7 +115,7 @@ int CEPoll::add_ssock(const int eid, const SYSSOCKET& s, const int* events)
    if (p == m_mPolls.end())
       throw CUDTException(5, 13);
 
-#ifdef LINUX
+#ifdef __linux__
    epoll_event ev;
    memset(&ev, 0, sizeof(epoll_event));
 
@@ -165,7 +165,7 @@ int CEPoll::remove_ssock(const int eid, const SYSSOCKET& s)
    if (p == m_mPolls.end())
       throw CUDTException(5, 13);
 
-#ifdef LINUX
+#ifdef __linux__
    epoll_event ev;  // ev is ignored, for compatibility with old Linux kernel only.
    if (::epoll_ctl(p->second.m_iLocalID, EPOLL_CTL_DEL, s, &ev) < 0)
       throw CUDTException();
@@ -227,7 +227,7 @@ int CEPoll::wait(const int eid, set<UDTSOCKET>* readfds, set<UDTSOCKET>* writefd
 
       if (lrfds || lwfds)
       {
-         #ifdef LINUX
+         #ifdef __linux__
          const int max_events = p->second.m_sLocals.size();
          epoll_event ev[max_events];
          int nfds = ::epoll_wait(p->second.m_iLocalID, ev, max_events, 0);
@@ -308,7 +308,7 @@ int CEPoll::release(const int eid)
    if (i == m_mPolls.end())
       throw CUDTException(5, 13);
 
-   #ifdef LINUX
+   #ifdef __linux__
    // release local/system epoll descriptor
    ::close(i->second.m_iLocalID);
    #endif