Skip to content

Commit 19069e7

Browse files
committed
get strace.c to compile
1 parent 227cb42 commit 19069e7

File tree

4 files changed

+130
-59
lines changed

4 files changed

+130
-59
lines changed

darwin-user/shim_gettid.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include <sys/types.h>
2+
#include <pthread.h>
3+
4+
#include <shim_gettid.h>
5+
6+
7+
/* Implement this syscall based on:
8+
* http://elliotth.blogspot.com/2012/04/gettid-on-mac-os.html
9+
* Linux macro:
10+
* #define __NR_sys_gettid __NR_gettid
11+
* _syscall0(int, sys_gettid)
12+
* */
13+
int shim_gettid(void) {
14+
uintptr_t tid = (uintptr_t)pthread_self();
15+
16+
return (int)tid;
17+
}

darwin-user/shim_gettid.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#ifndef SHIM_GETTID_H
2+
#define SHIM_GETTID_H
3+
4+
int shim_gettid(void);
5+
6+
#endif /* SHIM_GETTID_H */

darwin-user/strace.c

Lines changed: 104 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@
1010
#include <unistd.h>
1111
#include <arpa/inet.h>
1212
#include <netinet/tcp.h>
13-
#include <linux/if_packet.h>
13+
//#include <linux/if_packet.h>
1414
#include <sched.h>
1515
#include "qemu.h"
16+
#include "shim_gettid.h"
1617

1718
int do_strace=0;
1819

@@ -165,9 +166,9 @@ static void print_si_code(int arg)
165166
case SI_USER:
166167
codename = "SI_USER";
167168
break;
168-
case SI_KERNEL:
169-
codename = "SI_KERNEL";
170-
break;
169+
// case SI_KERNEL:
170+
// codename = "SI_KERNEL";
171+
// break;
171172
case SI_QUEUE:
172173
codename = "SI_QUEUE";
173174
break;
@@ -180,12 +181,12 @@ static void print_si_code(int arg)
180181
case SI_ASYNCIO:
181182
codename = "SI_ASYNCIO";
182183
break;
183-
case SI_SIGIO:
184-
codename = "SI_SIGIO";
185-
break;
186-
case SI_TKILL:
187-
codename = "SI_TKILL";
188-
break;
184+
// case SI_SIGIO:
185+
// codename = "SI_SIGIO";
186+
// break;
187+
// case SI_TKILL:
188+
// codename = "SI_TKILL";
189+
// break;
189190
default:
190191
gemu_log("%d", arg);
191192
return;
@@ -381,37 +382,37 @@ print_sockaddr(abi_ulong addr, abi_long addrlen)
381382
gemu_log("}");
382383
break;
383384
}
384-
case AF_PACKET: {
385-
struct target_sockaddr_ll *ll = (struct target_sockaddr_ll *)sa;
386-
uint8_t *c = (uint8_t *)&ll->sll_addr;
387-
gemu_log("{sll_family=AF_PACKET,"
388-
"sll_protocol=htons(0x%04x),if%d,pkttype=",
389-
ntohs(ll->sll_protocol), ll->sll_ifindex);
390-
switch (ll->sll_pkttype) {
391-
case PACKET_HOST:
392-
gemu_log("PACKET_HOST");
393-
break;
394-
case PACKET_BROADCAST:
395-
gemu_log("PACKET_BROADCAST");
396-
break;
397-
case PACKET_MULTICAST:
398-
gemu_log("PACKET_MULTICAST");
399-
break;
400-
case PACKET_OTHERHOST:
401-
gemu_log("PACKET_OTHERHOST");
402-
break;
403-
case PACKET_OUTGOING:
404-
gemu_log("PACKET_OUTGOING");
405-
break;
406-
default:
407-
gemu_log("%d", ll->sll_pkttype);
408-
break;
409-
}
410-
gemu_log(",sll_addr=%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
411-
c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7]);
412-
gemu_log("}");
413-
break;
414-
}
385+
// case AF_PACKET: {
386+
// struct target_sockaddr_ll *ll = (struct target_sockaddr_ll *)sa;
387+
// uint8_t *c = (uint8_t *)&ll->sll_addr;
388+
// gemu_log("{sll_family=AF_PACKET,"
389+
// "sll_protocol=htons(0x%04x),if%d,pkttype=",
390+
// ntohs(ll->sll_protocol), ll->sll_ifindex);
391+
// switch (ll->sll_pkttype) {
392+
// case PACKET_HOST:
393+
// gemu_log("PACKET_HOST");
394+
// break;
395+
// case PACKET_BROADCAST:
396+
// gemu_log("PACKET_BROADCAST");
397+
// break;
398+
// case PACKET_MULTICAST:
399+
// gemu_log("PACKET_MULTICAST");
400+
// break;
401+
// case PACKET_OTHERHOST:
402+
// gemu_log("PACKET_OTHERHOST");
403+
// break;
404+
// case PACKET_OUTGOING:
405+
// gemu_log("PACKET_OUTGOING");
406+
// break;
407+
// default:
408+
// gemu_log("%d", ll->sll_pkttype);
409+
// break;
410+
// }
411+
// gemu_log(",sll_addr=%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
412+
// c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7]);
413+
// gemu_log("}");
414+
// break;
415+
// }
415416
default:
416417
gemu_log("{sa_family=%d, sa_data={", sa->sa_family);
417418
for (i = 0; i < 13; i++) {
@@ -438,9 +439,9 @@ print_socket_domain(int domain)
438439
case PF_INET:
439440
gemu_log("PF_INET");
440441
break;
441-
case PF_PACKET:
442-
gemu_log("PF_PACKET");
443-
break;
442+
// case PF_PACKET:
443+
// gemu_log("PF_PACKET");
444+
// break;
444445
default:
445446
gemu_log("%d", domain);
446447
break;
@@ -477,6 +478,7 @@ print_socket_type(int type)
477478
static void
478479
print_socket_protocol(int domain, int type, int protocol)
479480
{
481+
/*
480482
if (domain == AF_PACKET
481483
#ifdef TARGET_SOCK_PACKET
482484
|| (domain == AF_INET && type == TARGET_SOCK_PACKET)
@@ -491,6 +493,7 @@ print_socket_protocol(int domain, int type, int protocol)
491493
}
492494
return;
493495
}
496+
*/
494497

495498
switch (protocol) {
496499
case IPPROTO_IP:
@@ -846,7 +849,9 @@ UNUSED static struct flags open_flags[] = {
846849
FLAG_TARGET(O_NOFOLLOW),
847850
FLAG_TARGET(O_NONBLOCK), /* also O_NDELAY */
848851
FLAG_TARGET(O_DSYNC),
852+
#ifdef __O_SYNC
849853
FLAG_TARGET(__O_SYNC),
854+
#endif
850855
FLAG_TARGET(O_TRUNC),
851856
#ifdef O_DIRECT
852857
FLAG_TARGET(O_DIRECT),
@@ -874,21 +879,39 @@ UNUSED static struct flags mount_flags[] = {
874879
#ifdef MS_DIRSYNC
875880
FLAG_GENERIC(MS_DIRSYNC),
876881
#endif
882+
#ifdef MS_MANDLOCK
877883
FLAG_GENERIC(MS_MANDLOCK),
884+
#endif
878885
#ifdef MS_MOVE
879886
FLAG_GENERIC(MS_MOVE),
880887
#endif
888+
#ifdef MS_NOATIME
881889
FLAG_GENERIC(MS_NOATIME),
890+
#endif
891+
#ifdef MS_NODEV
882892
FLAG_GENERIC(MS_NODEV),
893+
#endif
894+
#ifdef MS_NODIRATIME
883895
FLAG_GENERIC(MS_NODIRATIME),
896+
#endif
897+
#ifdef MS_NOEXEC
884898
FLAG_GENERIC(MS_NOEXEC),
899+
#endif
900+
#ifdef MS_NOSUID
885901
FLAG_GENERIC(MS_NOSUID),
902+
#endif
903+
#ifdef MS_RDONLY
886904
FLAG_GENERIC(MS_RDONLY),
905+
#endif
887906
#ifdef MS_RELATIME
888907
FLAG_GENERIC(MS_RELATIME),
889908
#endif
909+
#ifdef MS_REMOUNT
890910
FLAG_GENERIC(MS_REMOUNT),
911+
#endif
912+
#ifdef MS_SYNCHRONOUS
891913
FLAG_GENERIC(MS_SYNCHRONOUS),
914+
#endif
892915
FLAG_END,
893916
};
894917

@@ -910,9 +933,15 @@ UNUSED static struct flags mmap_prot_flags[] = {
910933
FLAG_GENERIC(PROT_EXEC),
911934
FLAG_GENERIC(PROT_READ),
912935
FLAG_GENERIC(PROT_WRITE),
936+
#ifdef PROT_SEM
913937
FLAG_TARGET(PROT_SEM),
938+
#endif
939+
#ifdef PROT_GROWSDOWN
914940
FLAG_GENERIC(PROT_GROWSDOWN),
941+
#endif
942+
#ifdef PROT_GROWSUP
915943
FLAG_GENERIC(PROT_GROWSUP),
944+
#endif
916945
FLAG_END,
917946
};
918947

@@ -940,6 +969,7 @@ UNUSED static struct flags mmap_flags[] = {
940969
FLAG_END,
941970
};
942971

972+
#ifdef TARGET_NR_clone
943973
UNUSED static struct flags clone_flags[] = {
944974
FLAG_GENERIC(CLONE_VM),
945975
FLAG_GENERIC(CLONE_FS),
@@ -977,24 +1007,51 @@ UNUSED static struct flags clone_flags[] = {
9771007
#endif
9781008
FLAG_END,
9791009
};
1010+
#endif /* TARGET_NR_clone */
9801011

9811012
UNUSED static struct flags msg_flags[] = {
9821013
/* send */
1014+
#ifdef MSG_CONFIRM
9831015
FLAG_GENERIC(MSG_CONFIRM),
1016+
#endif
1017+
#ifdef MSG_DONTROUTE
9841018
FLAG_GENERIC(MSG_DONTROUTE),
1019+
#endif
1020+
#ifdef MSG_DONTWAIT
9851021
FLAG_GENERIC(MSG_DONTWAIT),
1022+
#endif
1023+
#ifdef MSG_EOR
9861024
FLAG_GENERIC(MSG_EOR),
1025+
#endif
1026+
#ifdef MSG_MORE
9871027
FLAG_GENERIC(MSG_MORE),
1028+
#endif
1029+
#ifdef MSG_NOSIGNAL
9881030
FLAG_GENERIC(MSG_NOSIGNAL),
1031+
#endif
1032+
#ifdef MSG_OOB
9891033
FLAG_GENERIC(MSG_OOB),
1034+
#endif
9901035
/* recv */
1036+
#ifdef MSG_CMSG_CLOEXEC
9911037
FLAG_GENERIC(MSG_CMSG_CLOEXEC),
1038+
#endif
1039+
#ifdef MSG_ERRQUEUE
9921040
FLAG_GENERIC(MSG_ERRQUEUE),
1041+
#endif
1042+
#ifdef MSG_PEEK
9931043
FLAG_GENERIC(MSG_PEEK),
1044+
#endif
1045+
#ifdef MSG_TRUNC
9941046
FLAG_GENERIC(MSG_TRUNC),
1047+
#endif
1048+
#ifdef MSG_WAITALL
9951049
FLAG_GENERIC(MSG_WAITALL),
1050+
#endif
9961051
/* recvmsg */
1052+
#ifdef MSG_CTRUNC
9971053
FLAG_GENERIC(MSG_CTRUNC),
1054+
#endif
9981055
FLAG_END,
9991056
};
10001057

@@ -1567,13 +1624,15 @@ print_socket(const struct syscallname *name,
15671624
gemu_log(",");
15681625
print_socket_type(type);
15691626
gemu_log(",");
1627+
/*
15701628
if (domain == AF_PACKET
15711629
#ifdef TARGET_SOCK_PACKET
15721630
|| (domain == AF_INET && type == TARGET_SOCK_PACKET)
15731631
#endif
15741632
) {
15751633
protocol = tswap16(protocol);
15761634
}
1635+
*/
15771636
print_socket_protocol(domain, type, protocol);
15781637
print_syscall_epilogue(name);
15791638
}
@@ -2650,7 +2709,7 @@ print_syscall(int num,
26502709
int i;
26512710
const char *format="%s(" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ")";
26522711

2653-
gemu_log("%ld ", syscall(SYS_gettid) );
2712+
gemu_log("%d ", shim_gettid() );
26542713

26552714
for(i=0;i<nsyscalls;i++)
26562715
if( scnames[i].nr == num ) {

darwin-user/syscall.c

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@
130130
#include "qemu.h"
131131
#include "shim_fallocate.h"
132132
#include "shim_timers.h"
133+
#include "shim_gettid.h"
133134

134135

135136
// TODO: remove these clone flags, as macOS only has fork
@@ -271,18 +272,6 @@ static inline type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5,
271272
#define TARGET_NR__llseek TARGET_NR_llseek
272273
#endif
273274

274-
/* Implement this syscall based on:
275-
* http://elliotth.blogspot.com/2012/04/gettid-on-mac-os.html
276-
* Linux macro:
277-
* #define __NR_sys_gettid __NR_gettid
278-
* _syscall0(int, sys_gettid)
279-
* */
280-
int sys_gettid(void);
281-
int sys_gettid(void) {
282-
uintptr_t tid = (uintptr_t)pthread_self();
283-
284-
return (int)tid;
285-
}
286275

287276
#if defined(TARGET_NR_getdents) && defined(__NR_getdents)
288277
_syscall3(int, sys_getdents, uint, fd, struct linux_dirent *, dirp, uint, count);
@@ -6397,7 +6386,7 @@ static void *clone_func(void *arg)
63976386
cpu = ENV_GET_CPU(env);
63986387
thread_cpu = cpu;
63996388
ts = (TaskState *)cpu->opaque;
6400-
info->tid = sys_gettid();
6389+
info->tid = shim_gettid();
64016390
task_settid(ts);
64026391
#ifdef TARGET_ABI_IRIX
64036392
/* TODO: which fields in the PRDA are filled in by the IRIX kernel? */
@@ -12482,7 +12471,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
1248212471
#endif
1248312472
#ifdef TARGET_NR_gettid
1248412473
case TARGET_NR_gettid:
12485-
ret = get_errno(sys_gettid());
12474+
ret = get_errno(shim_gettid());
1248612475
break;
1248712476
#endif
1248812477
#ifdef TARGET_NR_readahead

0 commit comments

Comments
 (0)