id
int32 0
27.3k
| func
stringlengths 26
142k
| target
bool 2
classes | project
stringclasses 2
values | commit_id
stringlengths 40
40
| func_clean
stringlengths 26
131k
| vul_lines
dict | normalized_func
stringlengths 24
132k
| lines
sequencelengths 1
2.8k
| label
sequencelengths 1
2.8k
| line_no
sequencelengths 1
2.8k
|
---|---|---|---|---|---|---|---|---|---|---|
21,363 | ssize_t nbd_wr_syncv(QIOChannel *ioc,
struct iovec *iov,
size_t niov,
size_t length,
bool do_read,
Error **errp)
{
ssize_t done = 0;
struct iovec *local_iov = g_new(struct iovec, niov);
struct iovec *local_iov_head = local_iov;
unsigned int nlocal_iov = niov;
nlocal_iov = iov_copy(local_iov, nlocal_iov, iov, niov, 0, length);
while (nlocal_iov > 0) {
ssize_t len;
if (do_read) {
len = qio_channel_readv(ioc, local_iov, nlocal_iov, errp);
} else {
len = qio_channel_writev(ioc, local_iov, nlocal_iov, errp);
}
if (len == QIO_CHANNEL_ERR_BLOCK) {
/* errp should not be set */
assert(qemu_in_coroutine());
qio_channel_yield(ioc, do_read ? G_IO_IN : G_IO_OUT);
continue;
}
if (len < 0) {
done = -EIO;
goto cleanup;
}
if (do_read && len == 0) {
break;
}
iov_discard_front(&local_iov, &nlocal_iov, len);
done += len;
}
cleanup:
g_free(local_iov_head);
return done;
}
| false | qemu | d1fdf257d52822695f5ace6c586e059aa17d4b79 | ssize_t nbd_wr_syncv(QIOChannel *ioc,
struct iovec *iov,
size_t niov,
size_t length,
bool do_read,
Error **errp)
{
ssize_t done = 0;
struct iovec *local_iov = g_new(struct iovec, niov);
struct iovec *local_iov_head = local_iov;
unsigned int nlocal_iov = niov;
nlocal_iov = iov_copy(local_iov, nlocal_iov, iov, niov, 0, length);
while (nlocal_iov > 0) {
ssize_t len;
if (do_read) {
len = qio_channel_readv(ioc, local_iov, nlocal_iov, errp);
} else {
len = qio_channel_writev(ioc, local_iov, nlocal_iov, errp);
}
if (len == QIO_CHANNEL_ERR_BLOCK) {
assert(qemu_in_coroutine());
qio_channel_yield(ioc, do_read ? G_IO_IN : G_IO_OUT);
continue;
}
if (len < 0) {
done = -EIO;
goto cleanup;
}
if (do_read && len == 0) {
break;
}
iov_discard_front(&local_iov, &nlocal_iov, len);
done += len;
}
cleanup:
g_free(local_iov_head);
return done;
}
| {
"code": [],
"line_no": []
} | ssize_t FUNC_0(QIOChannel *ioc,
struct iovec *iov,
size_t niov,
size_t length,
bool do_read,
Error **errp)
{
ssize_t done = 0;
struct iovec *VAR_0 = g_new(struct iovec, niov);
struct iovec *VAR_1 = VAR_0;
unsigned int VAR_2 = niov;
VAR_2 = iov_copy(VAR_0, VAR_2, iov, niov, 0, length);
while (VAR_2 > 0) {
ssize_t len;
if (do_read) {
len = qio_channel_readv(ioc, VAR_0, VAR_2, errp);
} else {
len = qio_channel_writev(ioc, VAR_0, VAR_2, errp);
}
if (len == QIO_CHANNEL_ERR_BLOCK) {
assert(qemu_in_coroutine());
qio_channel_yield(ioc, do_read ? G_IO_IN : G_IO_OUT);
continue;
}
if (len < 0) {
done = -EIO;
goto cleanup;
}
if (do_read && len == 0) {
break;
}
iov_discard_front(&VAR_0, &VAR_2, len);
done += len;
}
cleanup:
g_free(VAR_1);
return done;
}
| [
"ssize_t FUNC_0(QIOChannel *ioc,\nstruct iovec *iov,\nsize_t niov,\nsize_t length,\nbool do_read,\nError **errp)\n{",
"ssize_t done = 0;",
"struct iovec *VAR_0 = g_new(struct iovec, niov);",
"struct iovec *VAR_1 = VAR_0;",
"unsigned int VAR_2 = niov;",
"VAR_2 = iov_copy(VAR_0, VAR_2, iov, niov, 0, length);",
"while (VAR_2 > 0) {",
"ssize_t len;",
"if (do_read) {",
"len = qio_channel_readv(ioc, VAR_0, VAR_2, errp);",
"} else {",
"len = qio_channel_writev(ioc, VAR_0, VAR_2, errp);",
"}",
"if (len == QIO_CHANNEL_ERR_BLOCK) {",
"assert(qemu_in_coroutine());",
"qio_channel_yield(ioc, do_read ? G_IO_IN : G_IO_OUT);",
"continue;",
"}",
"if (len < 0) {",
"done = -EIO;",
"goto cleanup;",
"}",
"if (do_read && len == 0) {",
"break;",
"}",
"iov_discard_front(&VAR_0, &VAR_2, len);",
"done += len;",
"}",
"cleanup:\ng_free(VAR_1);",
"return done;",
"}"
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | [
[
1,
3,
5,
7,
9,
11,
13
],
[
15
],
[
17
],
[
19
],
[
21
],
[
25
],
[
29
],
[
31
],
[
33
],
[
35
],
[
37
],
[
39
],
[
41
],
[
43
],
[
47
],
[
49
],
[
51
],
[
53
],
[
55
],
[
57
],
[
59
],
[
61
],
[
65
],
[
67
],
[
69
],
[
73
],
[
75
],
[
77
],
[
81,
83
],
[
85
],
[
87
]
] |
21,364 | void qemu_init_vcpu(void *_env)
{
CPUState *env = _env;
if (kvm_enabled())
kvm_init_vcpu(env);
env->nr_cores = smp_cores;
env->nr_threads = smp_threads;
return;
}
| false | qemu | 3f7638ec4093100a63b18cbacd45dcd847f7c06b | void qemu_init_vcpu(void *_env)
{
CPUState *env = _env;
if (kvm_enabled())
kvm_init_vcpu(env);
env->nr_cores = smp_cores;
env->nr_threads = smp_threads;
return;
}
| {
"code": [],
"line_no": []
} | void FUNC_0(void *VAR_0)
{
CPUState *env = VAR_0;
if (kvm_enabled())
kvm_init_vcpu(env);
env->nr_cores = smp_cores;
env->nr_threads = smp_threads;
return;
}
| [
"void FUNC_0(void *VAR_0)\n{",
"CPUState *env = VAR_0;",
"if (kvm_enabled())\nkvm_init_vcpu(env);",
"env->nr_cores = smp_cores;",
"env->nr_threads = smp_threads;",
"return;",
"}"
] | [
0,
0,
0,
0,
0,
0,
0
] | [
[
1,
3
],
[
5
],
[
9,
11
],
[
13
],
[
15
],
[
17
],
[
19
]
] |
21,365 | void kvm_inject_x86_mce(CPUState *cenv, int bank, uint64_t status,
uint64_t mcg_status, uint64_t addr, uint64_t misc,
int flag)
{
#ifdef KVM_CAP_MCE
struct kvm_x86_mce mce = {
.bank = bank,
.status = status,
.mcg_status = mcg_status,
.addr = addr,
.misc = misc,
};
if (flag & MCE_BROADCAST) {
kvm_mce_broadcast_rest(cenv);
}
kvm_inject_x86_mce_on(cenv, &mce, flag);
#else /* !KVM_CAP_MCE*/
if (flag & ABORT_ON_ERROR) {
abort();
}
#endif /* !KVM_CAP_MCE*/
}
| false | qemu | c34d440a728fd3b5099d11dec122d440ef092c23 | void kvm_inject_x86_mce(CPUState *cenv, int bank, uint64_t status,
uint64_t mcg_status, uint64_t addr, uint64_t misc,
int flag)
{
#ifdef KVM_CAP_MCE
struct kvm_x86_mce mce = {
.bank = bank,
.status = status,
.mcg_status = mcg_status,
.addr = addr,
.misc = misc,
};
if (flag & MCE_BROADCAST) {
kvm_mce_broadcast_rest(cenv);
}
kvm_inject_x86_mce_on(cenv, &mce, flag);
#else
if (flag & ABORT_ON_ERROR) {
abort();
}
#endif
}
| {
"code": [],
"line_no": []
} | void FUNC_0(CPUState *VAR_0, int VAR_1, uint64_t VAR_2,
uint64_t VAR_3, uint64_t VAR_4, uint64_t VAR_5,
int VAR_6)
{
#ifdef KVM_CAP_MCE
struct kvm_x86_mce mce = {
.VAR_1 = VAR_1,
.VAR_2 = VAR_2,
.VAR_3 = VAR_3,
.VAR_4 = VAR_4,
.VAR_5 = VAR_5,
};
if (VAR_6 & MCE_BROADCAST) {
kvm_mce_broadcast_rest(VAR_0);
}
kvm_inject_x86_mce_on(VAR_0, &mce, VAR_6);
#else
if (VAR_6 & ABORT_ON_ERROR) {
abort();
}
#endif
}
| [
"void FUNC_0(CPUState *VAR_0, int VAR_1, uint64_t VAR_2,\nuint64_t VAR_3, uint64_t VAR_4, uint64_t VAR_5,\nint VAR_6)\n{",
"#ifdef KVM_CAP_MCE\nstruct kvm_x86_mce mce = {",
".VAR_1 = VAR_1,\n.VAR_2 = VAR_2,\n.VAR_3 = VAR_3,\n.VAR_4 = VAR_4,\n.VAR_5 = VAR_5,\n};",
"if (VAR_6 & MCE_BROADCAST) {",
"kvm_mce_broadcast_rest(VAR_0);",
"}",
"kvm_inject_x86_mce_on(VAR_0, &mce, VAR_6);",
"#else\nif (VAR_6 & ABORT_ON_ERROR) {",
"abort();",
"}",
"#endif\n}"
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | [
[
1,
3,
5,
7
],
[
9,
11
],
[
13,
15,
17,
19,
21,
23
],
[
27
],
[
29
],
[
31
],
[
35
],
[
37,
39
],
[
41
],
[
43
],
[
45,
47
]
] |
21,366 | readv_f(int argc, char **argv)
{
struct timeval t1, t2;
int Cflag = 0, qflag = 0, vflag = 0;
int c, cnt;
char *buf;
int64_t offset;
int total;
int nr_iov;
QEMUIOVector qiov;
int pattern = 0;
int Pflag = 0;
while ((c = getopt(argc, argv, "CP:qv")) != EOF) {
switch (c) {
case 'C':
Cflag = 1;
break;
case 'P':
Pflag = 1;
pattern = atoi(optarg);
break;
case 'q':
qflag = 1;
break;
case 'v':
vflag = 1;
break;
default:
return command_usage(&readv_cmd);
}
}
if (optind > argc - 2)
return command_usage(&readv_cmd);
offset = cvtnum(argv[optind]);
if (offset < 0) {
printf("non-numeric length argument -- %s\n", argv[optind]);
return 0;
}
optind++;
if (offset & 0x1ff) {
printf("offset %lld is not sector aligned\n",
(long long)offset);
return 0;
}
nr_iov = argc - optind;
buf = create_iovec(&qiov, &argv[optind], nr_iov, 0xab);
gettimeofday(&t1, NULL);
cnt = do_aio_readv(&qiov, offset, &total);
gettimeofday(&t2, NULL);
if (cnt < 0) {
printf("readv failed: %s\n", strerror(-cnt));
goto out;
}
if (Pflag) {
void* cmp_buf = malloc(qiov.size);
memset(cmp_buf, pattern, qiov.size);
if (memcmp(buf, cmp_buf, qiov.size)) {
printf("Pattern verification failed at offset %lld, "
"%zd bytes\n",
(long long) offset, qiov.size);
}
free(cmp_buf);
}
if (qflag)
goto out;
if (vflag)
dump_buffer(buf, offset, qiov.size);
/* Finally, report back -- -C gives a parsable format */
t2 = tsub(t2, t1);
print_report("read", &t2, offset, qiov.size, total, cnt, Cflag);
out:
qemu_io_free(buf);
return 0;
}
| false | qemu | cf070d7ec0b8fb21faa9a630ed5cc66f90844a08 | readv_f(int argc, char **argv)
{
struct timeval t1, t2;
int Cflag = 0, qflag = 0, vflag = 0;
int c, cnt;
char *buf;
int64_t offset;
int total;
int nr_iov;
QEMUIOVector qiov;
int pattern = 0;
int Pflag = 0;
while ((c = getopt(argc, argv, "CP:qv")) != EOF) {
switch (c) {
case 'C':
Cflag = 1;
break;
case 'P':
Pflag = 1;
pattern = atoi(optarg);
break;
case 'q':
qflag = 1;
break;
case 'v':
vflag = 1;
break;
default:
return command_usage(&readv_cmd);
}
}
if (optind > argc - 2)
return command_usage(&readv_cmd);
offset = cvtnum(argv[optind]);
if (offset < 0) {
printf("non-numeric length argument -- %s\n", argv[optind]);
return 0;
}
optind++;
if (offset & 0x1ff) {
printf("offset %lld is not sector aligned\n",
(long long)offset);
return 0;
}
nr_iov = argc - optind;
buf = create_iovec(&qiov, &argv[optind], nr_iov, 0xab);
gettimeofday(&t1, NULL);
cnt = do_aio_readv(&qiov, offset, &total);
gettimeofday(&t2, NULL);
if (cnt < 0) {
printf("readv failed: %s\n", strerror(-cnt));
goto out;
}
if (Pflag) {
void* cmp_buf = malloc(qiov.size);
memset(cmp_buf, pattern, qiov.size);
if (memcmp(buf, cmp_buf, qiov.size)) {
printf("Pattern verification failed at offset %lld, "
"%zd bytes\n",
(long long) offset, qiov.size);
}
free(cmp_buf);
}
if (qflag)
goto out;
if (vflag)
dump_buffer(buf, offset, qiov.size);
t2 = tsub(t2, t1);
print_report("read", &t2, offset, qiov.size, total, cnt, Cflag);
out:
qemu_io_free(buf);
return 0;
}
| {
"code": [],
"line_no": []
} | FUNC_0(int VAR_0, char **VAR_1)
{
struct timeval VAR_2, VAR_3;
int VAR_4 = 0, VAR_5 = 0, VAR_6 = 0;
int VAR_7, VAR_8;
char *VAR_9;
int64_t offset;
int VAR_10;
int VAR_11;
QEMUIOVector qiov;
int VAR_12 = 0;
int VAR_13 = 0;
while ((VAR_7 = getopt(VAR_0, VAR_1, "CP:qv")) != EOF) {
switch (VAR_7) {
case 'C':
VAR_4 = 1;
break;
case 'P':
VAR_13 = 1;
VAR_12 = atoi(optarg);
break;
case 'q':
VAR_5 = 1;
break;
case 'v':
VAR_6 = 1;
break;
default:
return command_usage(&readv_cmd);
}
}
if (optind > VAR_0 - 2)
return command_usage(&readv_cmd);
offset = cvtnum(VAR_1[optind]);
if (offset < 0) {
printf("non-numeric length argument -- %s\n", VAR_1[optind]);
return 0;
}
optind++;
if (offset & 0x1ff) {
printf("offset %lld is not sector aligned\n",
(long long)offset);
return 0;
}
VAR_11 = VAR_0 - optind;
VAR_9 = create_iovec(&qiov, &VAR_1[optind], VAR_11, 0xab);
gettimeofday(&VAR_2, NULL);
VAR_8 = do_aio_readv(&qiov, offset, &VAR_10);
gettimeofday(&VAR_3, NULL);
if (VAR_8 < 0) {
printf("readv failed: %s\n", strerror(-VAR_8));
goto out;
}
if (VAR_13) {
void* VAR_14 = malloc(qiov.size);
memset(VAR_14, VAR_12, qiov.size);
if (memcmp(VAR_9, VAR_14, qiov.size)) {
printf("Pattern verification failed at offset %lld, "
"%zd bytes\n",
(long long) offset, qiov.size);
}
free(VAR_14);
}
if (VAR_5)
goto out;
if (VAR_6)
dump_buffer(VAR_9, offset, qiov.size);
VAR_3 = tsub(VAR_3, VAR_2);
print_report("read", &VAR_3, offset, qiov.size, VAR_10, VAR_8, VAR_4);
out:
qemu_io_free(VAR_9);
return 0;
}
| [
"FUNC_0(int VAR_0, char **VAR_1)\n{",
"struct timeval VAR_2, VAR_3;",
"int VAR_4 = 0, VAR_5 = 0, VAR_6 = 0;",
"int VAR_7, VAR_8;",
"char *VAR_9;",
"int64_t offset;",
"int VAR_10;",
"int VAR_11;",
"QEMUIOVector qiov;",
"int VAR_12 = 0;",
"int VAR_13 = 0;",
"while ((VAR_7 = getopt(VAR_0, VAR_1, \"CP:qv\")) != EOF) {",
"switch (VAR_7) {",
"case 'C':\nVAR_4 = 1;",
"break;",
"case 'P':\nVAR_13 = 1;",
"VAR_12 = atoi(optarg);",
"break;",
"case 'q':\nVAR_5 = 1;",
"break;",
"case 'v':\nVAR_6 = 1;",
"break;",
"default:\nreturn command_usage(&readv_cmd);",
"}",
"}",
"if (optind > VAR_0 - 2)\nreturn command_usage(&readv_cmd);",
"offset = cvtnum(VAR_1[optind]);",
"if (offset < 0) {",
"printf(\"non-numeric length argument -- %s\\n\", VAR_1[optind]);",
"return 0;",
"}",
"optind++;",
"if (offset & 0x1ff) {",
"printf(\"offset %lld is not sector aligned\\n\",\n(long long)offset);",
"return 0;",
"}",
"VAR_11 = VAR_0 - optind;",
"VAR_9 = create_iovec(&qiov, &VAR_1[optind], VAR_11, 0xab);",
"gettimeofday(&VAR_2, NULL);",
"VAR_8 = do_aio_readv(&qiov, offset, &VAR_10);",
"gettimeofday(&VAR_3, NULL);",
"if (VAR_8 < 0) {",
"printf(\"readv failed: %s\\n\", strerror(-VAR_8));",
"goto out;",
"}",
"if (VAR_13) {",
"void* VAR_14 = malloc(qiov.size);",
"memset(VAR_14, VAR_12, qiov.size);",
"if (memcmp(VAR_9, VAR_14, qiov.size)) {",
"printf(\"Pattern verification failed at offset %lld, \"\n\"%zd bytes\\n\",\n(long long) offset, qiov.size);",
"}",
"free(VAR_14);",
"}",
"if (VAR_5)\ngoto out;",
"if (VAR_6)\ndump_buffer(VAR_9, offset, qiov.size);",
"VAR_3 = tsub(VAR_3, VAR_2);",
"print_report(\"read\", &VAR_3, offset, qiov.size, VAR_10, VAR_8, VAR_4);",
"out:\nqemu_io_free(VAR_9);",
"return 0;",
"}"
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | [
[
1,
3
],
[
5
],
[
7
],
[
9
],
[
11
],
[
13
],
[
15
],
[
17
],
[
19
],
[
21
],
[
23
],
[
27
],
[
29
],
[
31,
33
],
[
35
],
[
37,
39
],
[
41
],
[
43
],
[
45,
47
],
[
49
],
[
51,
53
],
[
55
],
[
57,
59
],
[
61
],
[
63
],
[
67,
69
],
[
75
],
[
77
],
[
79
],
[
81
],
[
83
],
[
85
],
[
89
],
[
91,
93
],
[
95
],
[
97
],
[
101
],
[
103
],
[
107
],
[
109
],
[
111
],
[
115
],
[
117
],
[
119
],
[
121
],
[
125
],
[
127
],
[
129
],
[
131
],
[
133,
135,
137
],
[
139
],
[
141
],
[
143
],
[
147,
149
],
[
153,
155
],
[
161
],
[
163
],
[
167,
169
],
[
171
],
[
173
]
] |
21,367 | static int init_directories(BDRVVVFATState* s,
const char *dirname, int heads, int secs)
{
bootsector_t* bootsector;
mapping_t* mapping;
unsigned int i;
unsigned int cluster;
memset(&(s->first_sectors[0]),0,0x40*0x200);
s->cluster_size=s->sectors_per_cluster*0x200;
s->cluster_buffer=g_malloc(s->cluster_size);
/*
* The formula: sc = spf+1+spf*spc*(512*8/fat_type),
* where sc is sector_count,
* spf is sectors_per_fat,
* spc is sectors_per_clusters, and
* fat_type = 12, 16 or 32.
*/
i = 1+s->sectors_per_cluster*0x200*8/s->fat_type;
s->sectors_per_fat=(s->sector_count+i)/i; /* round up */
array_init(&(s->mapping),sizeof(mapping_t));
array_init(&(s->directory),sizeof(direntry_t));
/* add volume label */
{
direntry_t* entry=array_get_next(&(s->directory));
entry->attributes=0x28; /* archive | volume label */
memcpy(entry->name,"QEMU VVF",8);
memcpy(entry->extension,"AT ",3);
}
/* Now build FAT, and write back information into directory */
init_fat(s);
s->faked_sectors=s->first_sectors_number+s->sectors_per_fat*2;
s->cluster_count=sector2cluster(s, s->sector_count);
mapping = array_get_next(&(s->mapping));
mapping->begin = 0;
mapping->dir_index = 0;
mapping->info.dir.parent_mapping_index = -1;
mapping->first_mapping_index = -1;
mapping->path = g_strdup(dirname);
i = strlen(mapping->path);
if (i > 0 && mapping->path[i - 1] == '/')
mapping->path[i - 1] = '\0';
mapping->mode = MODE_DIRECTORY;
mapping->read_only = 0;
s->path = mapping->path;
for (i = 0, cluster = 0; i < s->mapping.next; i++) {
/* MS-DOS expects the FAT to be 0 for the root directory
* (except for the media byte). */
/* LATER TODO: still true for FAT32? */
int fix_fat = (i != 0);
mapping = array_get(&(s->mapping), i);
if (mapping->mode & MODE_DIRECTORY) {
mapping->begin = cluster;
if(read_directory(s, i)) {
fprintf(stderr, "Could not read directory %s\n",
mapping->path);
return -1;
}
mapping = array_get(&(s->mapping), i);
} else {
assert(mapping->mode == MODE_UNDEFINED);
mapping->mode=MODE_NORMAL;
mapping->begin = cluster;
if (mapping->end > 0) {
direntry_t* direntry = array_get(&(s->directory),
mapping->dir_index);
mapping->end = cluster + 1 + (mapping->end-1)/s->cluster_size;
set_begin_of_direntry(direntry, mapping->begin);
} else {
mapping->end = cluster + 1;
fix_fat = 0;
}
}
assert(mapping->begin < mapping->end);
/* next free cluster */
cluster = mapping->end;
if(cluster > s->cluster_count) {
fprintf(stderr,"Directory does not fit in FAT%d (capacity %.2f MB)\n",
s->fat_type, s->sector_count / 2000.0);
return -EINVAL;
}
/* fix fat for entry */
if (fix_fat) {
int j;
for(j = mapping->begin; j < mapping->end - 1; j++)
fat_set(s, j, j+1);
fat_set(s, mapping->end - 1, s->max_fat_value);
}
}
mapping = array_get(&(s->mapping), 0);
s->sectors_of_root_directory = mapping->end * s->sectors_per_cluster;
s->last_cluster_of_root_directory = mapping->end;
/* the FAT signature */
fat_set(s,0,s->max_fat_value);
fat_set(s,1,s->max_fat_value);
s->current_mapping = NULL;
bootsector=(bootsector_t*)(s->first_sectors+(s->first_sectors_number-1)*0x200);
bootsector->jump[0]=0xeb;
bootsector->jump[1]=0x3e;
bootsector->jump[2]=0x90;
memcpy(bootsector->name,"QEMU ",8);
bootsector->sector_size=cpu_to_le16(0x200);
bootsector->sectors_per_cluster=s->sectors_per_cluster;
bootsector->reserved_sectors=cpu_to_le16(1);
bootsector->number_of_fats=0x2; /* number of FATs */
bootsector->root_entries=cpu_to_le16(s->sectors_of_root_directory*0x10);
bootsector->total_sectors16=s->sector_count>0xffff?0:cpu_to_le16(s->sector_count);
bootsector->media_type=(s->first_sectors_number>1?0xf8:0xf0); /* media descriptor (f8=hd, f0=3.5 fd)*/
s->fat.pointer[0] = bootsector->media_type;
bootsector->sectors_per_fat=cpu_to_le16(s->sectors_per_fat);
bootsector->sectors_per_track = cpu_to_le16(secs);
bootsector->number_of_heads = cpu_to_le16(heads);
bootsector->hidden_sectors=cpu_to_le32(s->first_sectors_number==1?0:0x3f);
bootsector->total_sectors=cpu_to_le32(s->sector_count>0xffff?s->sector_count:0);
/* LATER TODO: if FAT32, this is wrong */
bootsector->u.fat16.drive_number=s->first_sectors_number==1?0:0x80; /* fda=0, hda=0x80 */
bootsector->u.fat16.current_head=0;
bootsector->u.fat16.signature=0x29;
bootsector->u.fat16.id=cpu_to_le32(0xfabe1afd);
memcpy(bootsector->u.fat16.volume_label,"QEMU VVFAT ",11);
memcpy(bootsector->fat_type,(s->fat_type==12?"FAT12 ":s->fat_type==16?"FAT16 ":"FAT32 "),8);
bootsector->magic[0]=0x55; bootsector->magic[1]=0xaa;
return 0;
}
| false | qemu | f671d173c7e1da555b693e8b14f3ed0852601809 | static int init_directories(BDRVVVFATState* s,
const char *dirname, int heads, int secs)
{
bootsector_t* bootsector;
mapping_t* mapping;
unsigned int i;
unsigned int cluster;
memset(&(s->first_sectors[0]),0,0x40*0x200);
s->cluster_size=s->sectors_per_cluster*0x200;
s->cluster_buffer=g_malloc(s->cluster_size);
i = 1+s->sectors_per_cluster*0x200*8/s->fat_type;
s->sectors_per_fat=(s->sector_count+i)/i;
array_init(&(s->mapping),sizeof(mapping_t));
array_init(&(s->directory),sizeof(direntry_t));
{
direntry_t* entry=array_get_next(&(s->directory));
entry->attributes=0x28;
memcpy(entry->name,"QEMU VVF",8);
memcpy(entry->extension,"AT ",3);
}
init_fat(s);
s->faked_sectors=s->first_sectors_number+s->sectors_per_fat*2;
s->cluster_count=sector2cluster(s, s->sector_count);
mapping = array_get_next(&(s->mapping));
mapping->begin = 0;
mapping->dir_index = 0;
mapping->info.dir.parent_mapping_index = -1;
mapping->first_mapping_index = -1;
mapping->path = g_strdup(dirname);
i = strlen(mapping->path);
if (i > 0 && mapping->path[i - 1] == '/')
mapping->path[i - 1] = '\0';
mapping->mode = MODE_DIRECTORY;
mapping->read_only = 0;
s->path = mapping->path;
for (i = 0, cluster = 0; i < s->mapping.next; i++) {
int fix_fat = (i != 0);
mapping = array_get(&(s->mapping), i);
if (mapping->mode & MODE_DIRECTORY) {
mapping->begin = cluster;
if(read_directory(s, i)) {
fprintf(stderr, "Could not read directory %s\n",
mapping->path);
return -1;
}
mapping = array_get(&(s->mapping), i);
} else {
assert(mapping->mode == MODE_UNDEFINED);
mapping->mode=MODE_NORMAL;
mapping->begin = cluster;
if (mapping->end > 0) {
direntry_t* direntry = array_get(&(s->directory),
mapping->dir_index);
mapping->end = cluster + 1 + (mapping->end-1)/s->cluster_size;
set_begin_of_direntry(direntry, mapping->begin);
} else {
mapping->end = cluster + 1;
fix_fat = 0;
}
}
assert(mapping->begin < mapping->end);
cluster = mapping->end;
if(cluster > s->cluster_count) {
fprintf(stderr,"Directory does not fit in FAT%d (capacity %.2f MB)\n",
s->fat_type, s->sector_count / 2000.0);
return -EINVAL;
}
if (fix_fat) {
int j;
for(j = mapping->begin; j < mapping->end - 1; j++)
fat_set(s, j, j+1);
fat_set(s, mapping->end - 1, s->max_fat_value);
}
}
mapping = array_get(&(s->mapping), 0);
s->sectors_of_root_directory = mapping->end * s->sectors_per_cluster;
s->last_cluster_of_root_directory = mapping->end;
fat_set(s,0,s->max_fat_value);
fat_set(s,1,s->max_fat_value);
s->current_mapping = NULL;
bootsector=(bootsector_t*)(s->first_sectors+(s->first_sectors_number-1)*0x200);
bootsector->jump[0]=0xeb;
bootsector->jump[1]=0x3e;
bootsector->jump[2]=0x90;
memcpy(bootsector->name,"QEMU ",8);
bootsector->sector_size=cpu_to_le16(0x200);
bootsector->sectors_per_cluster=s->sectors_per_cluster;
bootsector->reserved_sectors=cpu_to_le16(1);
bootsector->number_of_fats=0x2;
bootsector->root_entries=cpu_to_le16(s->sectors_of_root_directory*0x10);
bootsector->total_sectors16=s->sector_count>0xffff?0:cpu_to_le16(s->sector_count);
bootsector->media_type=(s->first_sectors_number>1?0xf8:0xf0);
s->fat.pointer[0] = bootsector->media_type;
bootsector->sectors_per_fat=cpu_to_le16(s->sectors_per_fat);
bootsector->sectors_per_track = cpu_to_le16(secs);
bootsector->number_of_heads = cpu_to_le16(heads);
bootsector->hidden_sectors=cpu_to_le32(s->first_sectors_number==1?0:0x3f);
bootsector->total_sectors=cpu_to_le32(s->sector_count>0xffff?s->sector_count:0);
bootsector->u.fat16.drive_number=s->first_sectors_number==1?0:0x80;
bootsector->u.fat16.current_head=0;
bootsector->u.fat16.signature=0x29;
bootsector->u.fat16.id=cpu_to_le32(0xfabe1afd);
memcpy(bootsector->u.fat16.volume_label,"QEMU VVFAT ",11);
memcpy(bootsector->fat_type,(s->fat_type==12?"FAT12 ":s->fat_type==16?"FAT16 ":"FAT32 "),8);
bootsector->magic[0]=0x55; bootsector->magic[1]=0xaa;
return 0;
}
| {
"code": [],
"line_no": []
} | static int FUNC_0(BDRVVVFATState* VAR_0,
const char *VAR_1, int VAR_2, int VAR_3)
{
bootsector_t* bootsector;
mapping_t* mapping;
unsigned int VAR_4;
unsigned int VAR_5;
memset(&(VAR_0->first_sectors[0]),0,0x40*0x200);
VAR_0->cluster_size=VAR_0->sectors_per_cluster*0x200;
VAR_0->cluster_buffer=g_malloc(VAR_0->cluster_size);
VAR_4 = 1+VAR_0->sectors_per_cluster*0x200*8/VAR_0->fat_type;
VAR_0->sectors_per_fat=(VAR_0->sector_count+VAR_4)/VAR_4;
array_init(&(VAR_0->mapping),sizeof(mapping_t));
array_init(&(VAR_0->directory),sizeof(direntry_t));
{
direntry_t* entry=array_get_next(&(VAR_0->directory));
entry->attributes=0x28;
memcpy(entry->name,"QEMU VVF",8);
memcpy(entry->extension,"AT ",3);
}
init_fat(VAR_0);
VAR_0->faked_sectors=VAR_0->first_sectors_number+VAR_0->sectors_per_fat*2;
VAR_0->cluster_count=sector2cluster(VAR_0, VAR_0->sector_count);
mapping = array_get_next(&(VAR_0->mapping));
mapping->begin = 0;
mapping->dir_index = 0;
mapping->info.dir.parent_mapping_index = -1;
mapping->first_mapping_index = -1;
mapping->path = g_strdup(VAR_1);
VAR_4 = strlen(mapping->path);
if (VAR_4 > 0 && mapping->path[VAR_4 - 1] == '/')
mapping->path[VAR_4 - 1] = '\0';
mapping->mode = MODE_DIRECTORY;
mapping->read_only = 0;
VAR_0->path = mapping->path;
for (VAR_4 = 0, VAR_5 = 0; VAR_4 < VAR_0->mapping.next; VAR_4++) {
int fix_fat = (VAR_4 != 0);
mapping = array_get(&(VAR_0->mapping), VAR_4);
if (mapping->mode & MODE_DIRECTORY) {
mapping->begin = VAR_5;
if(read_directory(VAR_0, VAR_4)) {
fprintf(stderr, "Could not read directory %VAR_0\n",
mapping->path);
return -1;
}
mapping = array_get(&(VAR_0->mapping), VAR_4);
} else {
assert(mapping->mode == MODE_UNDEFINED);
mapping->mode=MODE_NORMAL;
mapping->begin = VAR_5;
if (mapping->end > 0) {
direntry_t* direntry = array_get(&(VAR_0->directory),
mapping->dir_index);
mapping->end = VAR_5 + 1 + (mapping->end-1)/VAR_0->cluster_size;
set_begin_of_direntry(direntry, mapping->begin);
} else {
mapping->end = VAR_5 + 1;
fix_fat = 0;
}
}
assert(mapping->begin < mapping->end);
VAR_5 = mapping->end;
if(VAR_5 > VAR_0->cluster_count) {
fprintf(stderr,"Directory does not fit in FAT%d (capacity %.2f MB)\n",
VAR_0->fat_type, VAR_0->sector_count / 2000.0);
return -EINVAL;
}
if (fix_fat) {
int j;
for(j = mapping->begin; j < mapping->end - 1; j++)
fat_set(VAR_0, j, j+1);
fat_set(VAR_0, mapping->end - 1, VAR_0->max_fat_value);
}
}
mapping = array_get(&(VAR_0->mapping), 0);
VAR_0->sectors_of_root_directory = mapping->end * VAR_0->sectors_per_cluster;
VAR_0->last_cluster_of_root_directory = mapping->end;
fat_set(VAR_0,0,VAR_0->max_fat_value);
fat_set(VAR_0,1,VAR_0->max_fat_value);
VAR_0->current_mapping = NULL;
bootsector=(bootsector_t*)(VAR_0->first_sectors+(VAR_0->first_sectors_number-1)*0x200);
bootsector->jump[0]=0xeb;
bootsector->jump[1]=0x3e;
bootsector->jump[2]=0x90;
memcpy(bootsector->name,"QEMU ",8);
bootsector->sector_size=cpu_to_le16(0x200);
bootsector->sectors_per_cluster=VAR_0->sectors_per_cluster;
bootsector->reserved_sectors=cpu_to_le16(1);
bootsector->number_of_fats=0x2;
bootsector->root_entries=cpu_to_le16(VAR_0->sectors_of_root_directory*0x10);
bootsector->total_sectors16=VAR_0->sector_count>0xffff?0:cpu_to_le16(VAR_0->sector_count);
bootsector->media_type=(VAR_0->first_sectors_number>1?0xf8:0xf0);
VAR_0->fat.pointer[0] = bootsector->media_type;
bootsector->sectors_per_fat=cpu_to_le16(VAR_0->sectors_per_fat);
bootsector->sectors_per_track = cpu_to_le16(VAR_3);
bootsector->number_of_heads = cpu_to_le16(VAR_2);
bootsector->hidden_sectors=cpu_to_le32(VAR_0->first_sectors_number==1?0:0x3f);
bootsector->total_sectors=cpu_to_le32(VAR_0->sector_count>0xffff?VAR_0->sector_count:0);
bootsector->u.fat16.drive_number=VAR_0->first_sectors_number==1?0:0x80;
bootsector->u.fat16.current_head=0;
bootsector->u.fat16.signature=0x29;
bootsector->u.fat16.id=cpu_to_le32(0xfabe1afd);
memcpy(bootsector->u.fat16.volume_label,"QEMU VVFAT ",11);
memcpy(bootsector->fat_type,(VAR_0->fat_type==12?"FAT12 ":VAR_0->fat_type==16?"FAT16 ":"FAT32 "),8);
bootsector->magic[0]=0x55; bootsector->magic[1]=0xaa;
return 0;
}
| [
"static int FUNC_0(BDRVVVFATState* VAR_0,\nconst char *VAR_1, int VAR_2, int VAR_3)\n{",
"bootsector_t* bootsector;",
"mapping_t* mapping;",
"unsigned int VAR_4;",
"unsigned int VAR_5;",
"memset(&(VAR_0->first_sectors[0]),0,0x40*0x200);",
"VAR_0->cluster_size=VAR_0->sectors_per_cluster*0x200;",
"VAR_0->cluster_buffer=g_malloc(VAR_0->cluster_size);",
"VAR_4 = 1+VAR_0->sectors_per_cluster*0x200*8/VAR_0->fat_type;",
"VAR_0->sectors_per_fat=(VAR_0->sector_count+VAR_4)/VAR_4;",
"array_init(&(VAR_0->mapping),sizeof(mapping_t));",
"array_init(&(VAR_0->directory),sizeof(direntry_t));",
"{",
"direntry_t* entry=array_get_next(&(VAR_0->directory));",
"entry->attributes=0x28;",
"memcpy(entry->name,\"QEMU VVF\",8);",
"memcpy(entry->extension,\"AT \",3);",
"}",
"init_fat(VAR_0);",
"VAR_0->faked_sectors=VAR_0->first_sectors_number+VAR_0->sectors_per_fat*2;",
"VAR_0->cluster_count=sector2cluster(VAR_0, VAR_0->sector_count);",
"mapping = array_get_next(&(VAR_0->mapping));",
"mapping->begin = 0;",
"mapping->dir_index = 0;",
"mapping->info.dir.parent_mapping_index = -1;",
"mapping->first_mapping_index = -1;",
"mapping->path = g_strdup(VAR_1);",
"VAR_4 = strlen(mapping->path);",
"if (VAR_4 > 0 && mapping->path[VAR_4 - 1] == '/')\nmapping->path[VAR_4 - 1] = '\\0';",
"mapping->mode = MODE_DIRECTORY;",
"mapping->read_only = 0;",
"VAR_0->path = mapping->path;",
"for (VAR_4 = 0, VAR_5 = 0; VAR_4 < VAR_0->mapping.next; VAR_4++) {",
"int fix_fat = (VAR_4 != 0);",
"mapping = array_get(&(VAR_0->mapping), VAR_4);",
"if (mapping->mode & MODE_DIRECTORY) {",
"mapping->begin = VAR_5;",
"if(read_directory(VAR_0, VAR_4)) {",
"fprintf(stderr, \"Could not read directory %VAR_0\\n\",\nmapping->path);",
"return -1;",
"}",
"mapping = array_get(&(VAR_0->mapping), VAR_4);",
"} else {",
"assert(mapping->mode == MODE_UNDEFINED);",
"mapping->mode=MODE_NORMAL;",
"mapping->begin = VAR_5;",
"if (mapping->end > 0) {",
"direntry_t* direntry = array_get(&(VAR_0->directory),\nmapping->dir_index);",
"mapping->end = VAR_5 + 1 + (mapping->end-1)/VAR_0->cluster_size;",
"set_begin_of_direntry(direntry, mapping->begin);",
"} else {",
"mapping->end = VAR_5 + 1;",
"fix_fat = 0;",
"}",
"}",
"assert(mapping->begin < mapping->end);",
"VAR_5 = mapping->end;",
"if(VAR_5 > VAR_0->cluster_count) {",
"fprintf(stderr,\"Directory does not fit in FAT%d (capacity %.2f MB)\\n\",\nVAR_0->fat_type, VAR_0->sector_count / 2000.0);",
"return -EINVAL;",
"}",
"if (fix_fat) {",
"int j;",
"for(j = mapping->begin; j < mapping->end - 1; j++)",
"fat_set(VAR_0, j, j+1);",
"fat_set(VAR_0, mapping->end - 1, VAR_0->max_fat_value);",
"}",
"}",
"mapping = array_get(&(VAR_0->mapping), 0);",
"VAR_0->sectors_of_root_directory = mapping->end * VAR_0->sectors_per_cluster;",
"VAR_0->last_cluster_of_root_directory = mapping->end;",
"fat_set(VAR_0,0,VAR_0->max_fat_value);",
"fat_set(VAR_0,1,VAR_0->max_fat_value);",
"VAR_0->current_mapping = NULL;",
"bootsector=(bootsector_t*)(VAR_0->first_sectors+(VAR_0->first_sectors_number-1)*0x200);",
"bootsector->jump[0]=0xeb;",
"bootsector->jump[1]=0x3e;",
"bootsector->jump[2]=0x90;",
"memcpy(bootsector->name,\"QEMU \",8);",
"bootsector->sector_size=cpu_to_le16(0x200);",
"bootsector->sectors_per_cluster=VAR_0->sectors_per_cluster;",
"bootsector->reserved_sectors=cpu_to_le16(1);",
"bootsector->number_of_fats=0x2;",
"bootsector->root_entries=cpu_to_le16(VAR_0->sectors_of_root_directory*0x10);",
"bootsector->total_sectors16=VAR_0->sector_count>0xffff?0:cpu_to_le16(VAR_0->sector_count);",
"bootsector->media_type=(VAR_0->first_sectors_number>1?0xf8:0xf0);",
"VAR_0->fat.pointer[0] = bootsector->media_type;",
"bootsector->sectors_per_fat=cpu_to_le16(VAR_0->sectors_per_fat);",
"bootsector->sectors_per_track = cpu_to_le16(VAR_3);",
"bootsector->number_of_heads = cpu_to_le16(VAR_2);",
"bootsector->hidden_sectors=cpu_to_le32(VAR_0->first_sectors_number==1?0:0x3f);",
"bootsector->total_sectors=cpu_to_le32(VAR_0->sector_count>0xffff?VAR_0->sector_count:0);",
"bootsector->u.fat16.drive_number=VAR_0->first_sectors_number==1?0:0x80;",
"bootsector->u.fat16.current_head=0;",
"bootsector->u.fat16.signature=0x29;",
"bootsector->u.fat16.id=cpu_to_le32(0xfabe1afd);",
"memcpy(bootsector->u.fat16.volume_label,\"QEMU VVFAT \",11);",
"memcpy(bootsector->fat_type,(VAR_0->fat_type==12?\"FAT12 \":VAR_0->fat_type==16?\"FAT16 \":\"FAT32 \"),8);",
"bootsector->magic[0]=0x55; bootsector->magic[1]=0xaa;",
"return 0;",
"}"
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | [
[
1,
3,
5
],
[
7
],
[
9
],
[
11
],
[
13
],
[
17
],
[
21
],
[
23
],
[
41
],
[
43
],
[
47
],
[
49
],
[
55
],
[
57
],
[
59
],
[
61
],
[
63
],
[
65
],
[
71
],
[
75
],
[
77
],
[
81
],
[
83
],
[
85
],
[
87
],
[
89
],
[
91
],
[
93
],
[
95,
97
],
[
99
],
[
101
],
[
103
],
[
107
],
[
115
],
[
117
],
[
121
],
[
123
],
[
125
],
[
127,
129
],
[
131
],
[
133
],
[
135
],
[
137
],
[
139
],
[
141
],
[
143
],
[
145
],
[
147,
149
],
[
153
],
[
155
],
[
157
],
[
159
],
[
161
],
[
163
],
[
165
],
[
169
],
[
175
],
[
179
],
[
181,
183
],
[
185
],
[
187
],
[
193
],
[
195
],
[
197
],
[
199
],
[
201
],
[
203
],
[
205
],
[
209
],
[
211
],
[
213
],
[
219
],
[
221
],
[
225
],
[
229
],
[
231
],
[
233
],
[
235
],
[
237
],
[
239
],
[
241
],
[
243
],
[
245
],
[
247
],
[
249
],
[
251
],
[
253
],
[
255
],
[
257
],
[
259
],
[
261
],
[
263
],
[
269
],
[
271
],
[
273
],
[
275
],
[
279
],
[
281
],
[
283
],
[
287
],
[
289
]
] |
21,368 | int kvm_vcpu_ioctl(CPUState *env, int type, ...)
{
int ret;
void *arg;
va_list ap;
va_start(ap, type);
arg = va_arg(ap, void *);
va_end(ap);
ret = ioctl(env->kvm_fd, type, arg);
if (ret == -1)
ret = -errno;
return ret;
}
| false | qemu | a426e122173f36f05ea2cb72dcff77b7408546ce | int kvm_vcpu_ioctl(CPUState *env, int type, ...)
{
int ret;
void *arg;
va_list ap;
va_start(ap, type);
arg = va_arg(ap, void *);
va_end(ap);
ret = ioctl(env->kvm_fd, type, arg);
if (ret == -1)
ret = -errno;
return ret;
}
| {
"code": [],
"line_no": []
} | int FUNC_0(CPUState *VAR_0, int VAR_1, ...)
{
int VAR_2;
void *VAR_3;
va_list ap;
va_start(ap, VAR_1);
VAR_3 = va_arg(ap, void *);
va_end(ap);
VAR_2 = ioctl(VAR_0->kvm_fd, VAR_1, VAR_3);
if (VAR_2 == -1)
VAR_2 = -errno;
return VAR_2;
}
| [
"int FUNC_0(CPUState *VAR_0, int VAR_1, ...)\n{",
"int VAR_2;",
"void *VAR_3;",
"va_list ap;",
"va_start(ap, VAR_1);",
"VAR_3 = va_arg(ap, void *);",
"va_end(ap);",
"VAR_2 = ioctl(VAR_0->kvm_fd, VAR_1, VAR_3);",
"if (VAR_2 == -1)\nVAR_2 = -errno;",
"return VAR_2;",
"}"
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | [
[
1,
3
],
[
5
],
[
7
],
[
9
],
[
13
],
[
15
],
[
17
],
[
21
],
[
23,
25
],
[
29
],
[
31
]
] |
21,370 | ssize_t qemu_put_compression_data(QEMUFile *f, const uint8_t *p, size_t size,
int level)
{
ssize_t blen = IO_BUF_SIZE - f->buf_index - sizeof(int32_t);
if (blen < compressBound(size)) {
return 0;
}
if (compress2(f->buf + f->buf_index + sizeof(int32_t), (uLongf *)&blen,
(Bytef *)p, size, level) != Z_OK) {
error_report("Compress Failed!");
return 0;
}
qemu_put_be32(f, blen);
f->buf_index += blen;
return blen + sizeof(int32_t);
}
| false | qemu | b3be28969b797b27d7f7f806827e9898e4ee08f0 | ssize_t qemu_put_compression_data(QEMUFile *f, const uint8_t *p, size_t size,
int level)
{
ssize_t blen = IO_BUF_SIZE - f->buf_index - sizeof(int32_t);
if (blen < compressBound(size)) {
return 0;
}
if (compress2(f->buf + f->buf_index + sizeof(int32_t), (uLongf *)&blen,
(Bytef *)p, size, level) != Z_OK) {
error_report("Compress Failed!");
return 0;
}
qemu_put_be32(f, blen);
f->buf_index += blen;
return blen + sizeof(int32_t);
}
| {
"code": [],
"line_no": []
} | ssize_t FUNC_0(QEMUFile *f, const uint8_t *p, size_t size,
int level)
{
ssize_t blen = IO_BUF_SIZE - f->buf_index - sizeof(int32_t);
if (blen < compressBound(size)) {
return 0;
}
if (compress2(f->buf + f->buf_index + sizeof(int32_t), (uLongf *)&blen,
(Bytef *)p, size, level) != Z_OK) {
error_report("Compress Failed!");
return 0;
}
qemu_put_be32(f, blen);
f->buf_index += blen;
return blen + sizeof(int32_t);
}
| [
"ssize_t FUNC_0(QEMUFile *f, const uint8_t *p, size_t size,\nint level)\n{",
"ssize_t blen = IO_BUF_SIZE - f->buf_index - sizeof(int32_t);",
"if (blen < compressBound(size)) {",
"return 0;",
"}",
"if (compress2(f->buf + f->buf_index + sizeof(int32_t), (uLongf *)&blen,\n(Bytef *)p, size, level) != Z_OK) {",
"error_report(\"Compress Failed!\");",
"return 0;",
"}",
"qemu_put_be32(f, blen);",
"f->buf_index += blen;",
"return blen + sizeof(int32_t);",
"}"
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | [
[
1,
3,
5
],
[
7
],
[
11
],
[
13
],
[
15
],
[
17,
19
],
[
21
],
[
23
],
[
25
],
[
27
],
[
29
],
[
31
],
[
33
]
] |
21,371 | static inline void vc1_pred_mv_intfr(VC1Context *v, int n, int dmv_x, int dmv_y,
int mvn, int r_x, int r_y, uint8_t* is_intra, int dir)
{
MpegEncContext *s = &v->s;
int xy, wrap, off = 0;
int A[2], B[2], C[2];
int px = 0, py = 0;
int a_valid = 0, b_valid = 0, c_valid = 0;
int field_a, field_b, field_c; // 0: same, 1: opposit
int total_valid, num_samefield, num_oppfield;
int pos_c, pos_b, n_adj;
wrap = s->b8_stride;
xy = s->block_index[n];
if (s->mb_intra) {
s->mv[0][n][0] = s->current_picture.motion_val[0][xy][0] = 0;
s->mv[0][n][1] = s->current_picture.motion_val[0][xy][1] = 0;
s->current_picture.motion_val[1][xy][0] = 0;
s->current_picture.motion_val[1][xy][1] = 0;
if (mvn == 1) { /* duplicate motion data for 1-MV block */
s->current_picture.motion_val[0][xy + 1][0] = 0;
s->current_picture.motion_val[0][xy + 1][1] = 0;
s->current_picture.motion_val[0][xy + wrap][0] = 0;
s->current_picture.motion_val[0][xy + wrap][1] = 0;
s->current_picture.motion_val[0][xy + wrap + 1][0] = 0;
s->current_picture.motion_val[0][xy + wrap + 1][1] = 0;
v->luma_mv[s->mb_x][0] = v->luma_mv[s->mb_x][1] = 0;
s->current_picture.motion_val[1][xy + 1][0] = 0;
s->current_picture.motion_val[1][xy + 1][1] = 0;
s->current_picture.motion_val[1][xy + wrap][0] = 0;
s->current_picture.motion_val[1][xy + wrap][1] = 0;
s->current_picture.motion_val[1][xy + wrap + 1][0] = 0;
s->current_picture.motion_val[1][xy + wrap + 1][1] = 0;
}
return;
}
off = ((n == 0) || (n == 1)) ? 1 : -1;
/* predict A */
if (s->mb_x || (n == 1) || (n == 3)) {
if ((v->blk_mv_type[xy]) // current block (MB) has a field MV
|| (!v->blk_mv_type[xy] && !v->blk_mv_type[xy - 1])) { // or both have frame MV
A[0] = s->current_picture.motion_val[dir][xy - 1][0];
A[1] = s->current_picture.motion_val[dir][xy - 1][1];
a_valid = 1;
} else { // current block has frame mv and cand. has field MV (so average)
A[0] = (s->current_picture.motion_val[dir][xy - 1][0]
+ s->current_picture.motion_val[dir][xy - 1 + off * wrap][0] + 1) >> 1;
A[1] = (s->current_picture.motion_val[dir][xy - 1][1]
+ s->current_picture.motion_val[dir][xy - 1 + off * wrap][1] + 1) >> 1;
a_valid = 1;
}
if (!(n & 1) && v->is_intra[s->mb_x - 1]) {
a_valid = 0;
A[0] = A[1] = 0;
}
} else
A[0] = A[1] = 0;
/* Predict B and C */
B[0] = B[1] = C[0] = C[1] = 0;
if (n == 0 || n == 1 || v->blk_mv_type[xy]) {
if (!s->first_slice_line) {
if (!v->is_intra[s->mb_x - s->mb_stride]) {
b_valid = 1;
n_adj = n | 2;
pos_b = s->block_index[n_adj] - 2 * wrap;
if (v->blk_mv_type[pos_b] && v->blk_mv_type[xy]) {
n_adj = (n & 2) | (n & 1);
}
B[0] = s->current_picture.motion_val[dir][s->block_index[n_adj] - 2 * wrap][0];
B[1] = s->current_picture.motion_val[dir][s->block_index[n_adj] - 2 * wrap][1];
if (v->blk_mv_type[pos_b] && !v->blk_mv_type[xy]) {
B[0] = (B[0] + s->current_picture.motion_val[dir][s->block_index[n_adj ^ 2] - 2 * wrap][0] + 1) >> 1;
B[1] = (B[1] + s->current_picture.motion_val[dir][s->block_index[n_adj ^ 2] - 2 * wrap][1] + 1) >> 1;
}
}
if (s->mb_width > 1) {
if (!v->is_intra[s->mb_x - s->mb_stride + 1]) {
c_valid = 1;
n_adj = 2;
pos_c = s->block_index[2] - 2 * wrap + 2;
if (v->blk_mv_type[pos_c] && v->blk_mv_type[xy]) {
n_adj = n & 2;
}
C[0] = s->current_picture.motion_val[dir][s->block_index[n_adj] - 2 * wrap + 2][0];
C[1] = s->current_picture.motion_val[dir][s->block_index[n_adj] - 2 * wrap + 2][1];
if (v->blk_mv_type[pos_c] && !v->blk_mv_type[xy]) {
C[0] = (1 + C[0] + (s->current_picture.motion_val[dir][s->block_index[n_adj ^ 2] - 2 * wrap + 2][0])) >> 1;
C[1] = (1 + C[1] + (s->current_picture.motion_val[dir][s->block_index[n_adj ^ 2] - 2 * wrap + 2][1])) >> 1;
}
if (s->mb_x == s->mb_width - 1) {
if (!v->is_intra[s->mb_x - s->mb_stride - 1]) {
c_valid = 1;
n_adj = 3;
pos_c = s->block_index[3] - 2 * wrap - 2;
if (v->blk_mv_type[pos_c] && v->blk_mv_type[xy]) {
n_adj = n | 1;
}
C[0] = s->current_picture.motion_val[dir][s->block_index[n_adj] - 2 * wrap - 2][0];
C[1] = s->current_picture.motion_val[dir][s->block_index[n_adj] - 2 * wrap - 2][1];
if (v->blk_mv_type[pos_c] && !v->blk_mv_type[xy]) {
C[0] = (1 + C[0] + s->current_picture.motion_val[dir][s->block_index[1] - 2 * wrap - 2][0]) >> 1;
C[1] = (1 + C[1] + s->current_picture.motion_val[dir][s->block_index[1] - 2 * wrap - 2][1]) >> 1;
}
} else
c_valid = 0;
}
}
}
}
} else {
pos_b = s->block_index[1];
b_valid = 1;
B[0] = s->current_picture.motion_val[dir][pos_b][0];
B[1] = s->current_picture.motion_val[dir][pos_b][1];
pos_c = s->block_index[0];
c_valid = 1;
C[0] = s->current_picture.motion_val[dir][pos_c][0];
C[1] = s->current_picture.motion_val[dir][pos_c][1];
}
total_valid = a_valid + b_valid + c_valid;
// check if predictor A is out of bounds
if (!s->mb_x && !(n == 1 || n == 3)) {
A[0] = A[1] = 0;
}
// check if predictor B is out of bounds
if ((s->first_slice_line && v->blk_mv_type[xy]) || (s->first_slice_line && !(n & 2))) {
B[0] = B[1] = C[0] = C[1] = 0;
}
if (!v->blk_mv_type[xy]) {
if (s->mb_width == 1) {
px = B[0];
py = B[1];
} else {
if (total_valid >= 2) {
px = mid_pred(A[0], B[0], C[0]);
py = mid_pred(A[1], B[1], C[1]);
} else if (total_valid) {
if (a_valid) { px = A[0]; py = A[1]; }
else if (b_valid) { px = B[0]; py = B[1]; }
else if (c_valid) { px = C[0]; py = C[1]; }
else av_assert2(0);
}
}
} else {
if (a_valid)
field_a = (A[1] & 4) ? 1 : 0;
else
field_a = 0;
if (b_valid)
field_b = (B[1] & 4) ? 1 : 0;
else
field_b = 0;
if (c_valid)
field_c = (C[1] & 4) ? 1 : 0;
else
field_c = 0;
num_oppfield = field_a + field_b + field_c;
num_samefield = total_valid - num_oppfield;
if (total_valid == 3) {
if ((num_samefield == 3) || (num_oppfield == 3)) {
px = mid_pred(A[0], B[0], C[0]);
py = mid_pred(A[1], B[1], C[1]);
} else if (num_samefield >= num_oppfield) {
/* take one MV from same field set depending on priority
the check for B may not be necessary */
px = !field_a ? A[0] : B[0];
py = !field_a ? A[1] : B[1];
} else {
px = field_a ? A[0] : B[0];
py = field_a ? A[1] : B[1];
}
} else if (total_valid == 2) {
if (num_samefield >= num_oppfield) {
if (!field_a && a_valid) {
px = A[0];
py = A[1];
} else if (!field_b && b_valid) {
px = B[0];
py = B[1];
} else if (c_valid) {
px = C[0];
py = C[1];
} else px = py = 0;
} else {
if (field_a && a_valid) {
px = A[0];
py = A[1];
} else if (field_b && b_valid) {
px = B[0];
py = B[1];
} else if (c_valid) {
px = C[0];
py = C[1];
}
}
} else if (total_valid == 1) {
px = (a_valid) ? A[0] : ((b_valid) ? B[0] : C[0]);
py = (a_valid) ? A[1] : ((b_valid) ? B[1] : C[1]);
}
}
/* store MV using signed modulus of MV range defined in 4.11 */
s->mv[dir][n][0] = s->current_picture.motion_val[dir][xy][0] = ((px + dmv_x + r_x) & ((r_x << 1) - 1)) - r_x;
s->mv[dir][n][1] = s->current_picture.motion_val[dir][xy][1] = ((py + dmv_y + r_y) & ((r_y << 1) - 1)) - r_y;
if (mvn == 1) { /* duplicate motion data for 1-MV block */
s->current_picture.motion_val[dir][xy + 1 ][0] = s->current_picture.motion_val[dir][xy][0];
s->current_picture.motion_val[dir][xy + 1 ][1] = s->current_picture.motion_val[dir][xy][1];
s->current_picture.motion_val[dir][xy + wrap ][0] = s->current_picture.motion_val[dir][xy][0];
s->current_picture.motion_val[dir][xy + wrap ][1] = s->current_picture.motion_val[dir][xy][1];
s->current_picture.motion_val[dir][xy + wrap + 1][0] = s->current_picture.motion_val[dir][xy][0];
s->current_picture.motion_val[dir][xy + wrap + 1][1] = s->current_picture.motion_val[dir][xy][1];
} else if (mvn == 2) { /* duplicate motion data for 2-Field MV block */
s->current_picture.motion_val[dir][xy + 1][0] = s->current_picture.motion_val[dir][xy][0];
s->current_picture.motion_val[dir][xy + 1][1] = s->current_picture.motion_val[dir][xy][1];
s->mv[dir][n + 1][0] = s->mv[dir][n][0];
s->mv[dir][n + 1][1] = s->mv[dir][n][1];
}
}
| false | FFmpeg | fca435fee167da981f024e35d9fef4e6179b8061 | static inline void vc1_pred_mv_intfr(VC1Context *v, int n, int dmv_x, int dmv_y,
int mvn, int r_x, int r_y, uint8_t* is_intra, int dir)
{
MpegEncContext *s = &v->s;
int xy, wrap, off = 0;
int A[2], B[2], C[2];
int px = 0, py = 0;
int a_valid = 0, b_valid = 0, c_valid = 0;
int field_a, field_b, field_c;
int total_valid, num_samefield, num_oppfield;
int pos_c, pos_b, n_adj;
wrap = s->b8_stride;
xy = s->block_index[n];
if (s->mb_intra) {
s->mv[0][n][0] = s->current_picture.motion_val[0][xy][0] = 0;
s->mv[0][n][1] = s->current_picture.motion_val[0][xy][1] = 0;
s->current_picture.motion_val[1][xy][0] = 0;
s->current_picture.motion_val[1][xy][1] = 0;
if (mvn == 1) {
s->current_picture.motion_val[0][xy + 1][0] = 0;
s->current_picture.motion_val[0][xy + 1][1] = 0;
s->current_picture.motion_val[0][xy + wrap][0] = 0;
s->current_picture.motion_val[0][xy + wrap][1] = 0;
s->current_picture.motion_val[0][xy + wrap + 1][0] = 0;
s->current_picture.motion_val[0][xy + wrap + 1][1] = 0;
v->luma_mv[s->mb_x][0] = v->luma_mv[s->mb_x][1] = 0;
s->current_picture.motion_val[1][xy + 1][0] = 0;
s->current_picture.motion_val[1][xy + 1][1] = 0;
s->current_picture.motion_val[1][xy + wrap][0] = 0;
s->current_picture.motion_val[1][xy + wrap][1] = 0;
s->current_picture.motion_val[1][xy + wrap + 1][0] = 0;
s->current_picture.motion_val[1][xy + wrap + 1][1] = 0;
}
return;
}
off = ((n == 0) || (n == 1)) ? 1 : -1;
if (s->mb_x || (n == 1) || (n == 3)) {
if ((v->blk_mv_type[xy])
|| (!v->blk_mv_type[xy] && !v->blk_mv_type[xy - 1])) {
A[0] = s->current_picture.motion_val[dir][xy - 1][0];
A[1] = s->current_picture.motion_val[dir][xy - 1][1];
a_valid = 1;
} else {
A[0] = (s->current_picture.motion_val[dir][xy - 1][0]
+ s->current_picture.motion_val[dir][xy - 1 + off * wrap][0] + 1) >> 1;
A[1] = (s->current_picture.motion_val[dir][xy - 1][1]
+ s->current_picture.motion_val[dir][xy - 1 + off * wrap][1] + 1) >> 1;
a_valid = 1;
}
if (!(n & 1) && v->is_intra[s->mb_x - 1]) {
a_valid = 0;
A[0] = A[1] = 0;
}
} else
A[0] = A[1] = 0;
B[0] = B[1] = C[0] = C[1] = 0;
if (n == 0 || n == 1 || v->blk_mv_type[xy]) {
if (!s->first_slice_line) {
if (!v->is_intra[s->mb_x - s->mb_stride]) {
b_valid = 1;
n_adj = n | 2;
pos_b = s->block_index[n_adj] - 2 * wrap;
if (v->blk_mv_type[pos_b] && v->blk_mv_type[xy]) {
n_adj = (n & 2) | (n & 1);
}
B[0] = s->current_picture.motion_val[dir][s->block_index[n_adj] - 2 * wrap][0];
B[1] = s->current_picture.motion_val[dir][s->block_index[n_adj] - 2 * wrap][1];
if (v->blk_mv_type[pos_b] && !v->blk_mv_type[xy]) {
B[0] = (B[0] + s->current_picture.motion_val[dir][s->block_index[n_adj ^ 2] - 2 * wrap][0] + 1) >> 1;
B[1] = (B[1] + s->current_picture.motion_val[dir][s->block_index[n_adj ^ 2] - 2 * wrap][1] + 1) >> 1;
}
}
if (s->mb_width > 1) {
if (!v->is_intra[s->mb_x - s->mb_stride + 1]) {
c_valid = 1;
n_adj = 2;
pos_c = s->block_index[2] - 2 * wrap + 2;
if (v->blk_mv_type[pos_c] && v->blk_mv_type[xy]) {
n_adj = n & 2;
}
C[0] = s->current_picture.motion_val[dir][s->block_index[n_adj] - 2 * wrap + 2][0];
C[1] = s->current_picture.motion_val[dir][s->block_index[n_adj] - 2 * wrap + 2][1];
if (v->blk_mv_type[pos_c] && !v->blk_mv_type[xy]) {
C[0] = (1 + C[0] + (s->current_picture.motion_val[dir][s->block_index[n_adj ^ 2] - 2 * wrap + 2][0])) >> 1;
C[1] = (1 + C[1] + (s->current_picture.motion_val[dir][s->block_index[n_adj ^ 2] - 2 * wrap + 2][1])) >> 1;
}
if (s->mb_x == s->mb_width - 1) {
if (!v->is_intra[s->mb_x - s->mb_stride - 1]) {
c_valid = 1;
n_adj = 3;
pos_c = s->block_index[3] - 2 * wrap - 2;
if (v->blk_mv_type[pos_c] && v->blk_mv_type[xy]) {
n_adj = n | 1;
}
C[0] = s->current_picture.motion_val[dir][s->block_index[n_adj] - 2 * wrap - 2][0];
C[1] = s->current_picture.motion_val[dir][s->block_index[n_adj] - 2 * wrap - 2][1];
if (v->blk_mv_type[pos_c] && !v->blk_mv_type[xy]) {
C[0] = (1 + C[0] + s->current_picture.motion_val[dir][s->block_index[1] - 2 * wrap - 2][0]) >> 1;
C[1] = (1 + C[1] + s->current_picture.motion_val[dir][s->block_index[1] - 2 * wrap - 2][1]) >> 1;
}
} else
c_valid = 0;
}
}
}
}
} else {
pos_b = s->block_index[1];
b_valid = 1;
B[0] = s->current_picture.motion_val[dir][pos_b][0];
B[1] = s->current_picture.motion_val[dir][pos_b][1];
pos_c = s->block_index[0];
c_valid = 1;
C[0] = s->current_picture.motion_val[dir][pos_c][0];
C[1] = s->current_picture.motion_val[dir][pos_c][1];
}
total_valid = a_valid + b_valid + c_valid;
if (!s->mb_x && !(n == 1 || n == 3)) {
A[0] = A[1] = 0;
}
if ((s->first_slice_line && v->blk_mv_type[xy]) || (s->first_slice_line && !(n & 2))) {
B[0] = B[1] = C[0] = C[1] = 0;
}
if (!v->blk_mv_type[xy]) {
if (s->mb_width == 1) {
px = B[0];
py = B[1];
} else {
if (total_valid >= 2) {
px = mid_pred(A[0], B[0], C[0]);
py = mid_pred(A[1], B[1], C[1]);
} else if (total_valid) {
if (a_valid) { px = A[0]; py = A[1]; }
else if (b_valid) { px = B[0]; py = B[1]; }
else if (c_valid) { px = C[0]; py = C[1]; }
else av_assert2(0);
}
}
} else {
if (a_valid)
field_a = (A[1] & 4) ? 1 : 0;
else
field_a = 0;
if (b_valid)
field_b = (B[1] & 4) ? 1 : 0;
else
field_b = 0;
if (c_valid)
field_c = (C[1] & 4) ? 1 : 0;
else
field_c = 0;
num_oppfield = field_a + field_b + field_c;
num_samefield = total_valid - num_oppfield;
if (total_valid == 3) {
if ((num_samefield == 3) || (num_oppfield == 3)) {
px = mid_pred(A[0], B[0], C[0]);
py = mid_pred(A[1], B[1], C[1]);
} else if (num_samefield >= num_oppfield) {
px = !field_a ? A[0] : B[0];
py = !field_a ? A[1] : B[1];
} else {
px = field_a ? A[0] : B[0];
py = field_a ? A[1] : B[1];
}
} else if (total_valid == 2) {
if (num_samefield >= num_oppfield) {
if (!field_a && a_valid) {
px = A[0];
py = A[1];
} else if (!field_b && b_valid) {
px = B[0];
py = B[1];
} else if (c_valid) {
px = C[0];
py = C[1];
} else px = py = 0;
} else {
if (field_a && a_valid) {
px = A[0];
py = A[1];
} else if (field_b && b_valid) {
px = B[0];
py = B[1];
} else if (c_valid) {
px = C[0];
py = C[1];
}
}
} else if (total_valid == 1) {
px = (a_valid) ? A[0] : ((b_valid) ? B[0] : C[0]);
py = (a_valid) ? A[1] : ((b_valid) ? B[1] : C[1]);
}
}
s->mv[dir][n][0] = s->current_picture.motion_val[dir][xy][0] = ((px + dmv_x + r_x) & ((r_x << 1) - 1)) - r_x;
s->mv[dir][n][1] = s->current_picture.motion_val[dir][xy][1] = ((py + dmv_y + r_y) & ((r_y << 1) - 1)) - r_y;
if (mvn == 1) {
s->current_picture.motion_val[dir][xy + 1 ][0] = s->current_picture.motion_val[dir][xy][0];
s->current_picture.motion_val[dir][xy + 1 ][1] = s->current_picture.motion_val[dir][xy][1];
s->current_picture.motion_val[dir][xy + wrap ][0] = s->current_picture.motion_val[dir][xy][0];
s->current_picture.motion_val[dir][xy + wrap ][1] = s->current_picture.motion_val[dir][xy][1];
s->current_picture.motion_val[dir][xy + wrap + 1][0] = s->current_picture.motion_val[dir][xy][0];
s->current_picture.motion_val[dir][xy + wrap + 1][1] = s->current_picture.motion_val[dir][xy][1];
} else if (mvn == 2) {
s->current_picture.motion_val[dir][xy + 1][0] = s->current_picture.motion_val[dir][xy][0];
s->current_picture.motion_val[dir][xy + 1][1] = s->current_picture.motion_val[dir][xy][1];
s->mv[dir][n + 1][0] = s->mv[dir][n][0];
s->mv[dir][n + 1][1] = s->mv[dir][n][1];
}
}
| {
"code": [],
"line_no": []
} | static inline void FUNC_0(VC1Context *VAR_0, int VAR_1, int VAR_2, int VAR_3,
int VAR_4, int VAR_5, int VAR_6, uint8_t* VAR_7, int VAR_8)
{
MpegEncContext *s = &VAR_0->s;
int VAR_9, VAR_10, VAR_11 = 0;
int VAR_12[2], VAR_13[2], VAR_14[2];
int VAR_15 = 0, VAR_16 = 0;
int VAR_17 = 0, VAR_18 = 0, VAR_19 = 0;
int VAR_20, VAR_21, VAR_22;
int VAR_23, VAR_24, VAR_25;
int VAR_26, VAR_27, VAR_28;
VAR_10 = s->b8_stride;
VAR_9 = s->block_index[VAR_1];
if (s->mb_intra) {
s->mv[0][VAR_1][0] = s->current_picture.motion_val[0][VAR_9][0] = 0;
s->mv[0][VAR_1][1] = s->current_picture.motion_val[0][VAR_9][1] = 0;
s->current_picture.motion_val[1][VAR_9][0] = 0;
s->current_picture.motion_val[1][VAR_9][1] = 0;
if (VAR_4 == 1) {
s->current_picture.motion_val[0][VAR_9 + 1][0] = 0;
s->current_picture.motion_val[0][VAR_9 + 1][1] = 0;
s->current_picture.motion_val[0][VAR_9 + VAR_10][0] = 0;
s->current_picture.motion_val[0][VAR_9 + VAR_10][1] = 0;
s->current_picture.motion_val[0][VAR_9 + VAR_10 + 1][0] = 0;
s->current_picture.motion_val[0][VAR_9 + VAR_10 + 1][1] = 0;
VAR_0->luma_mv[s->mb_x][0] = VAR_0->luma_mv[s->mb_x][1] = 0;
s->current_picture.motion_val[1][VAR_9 + 1][0] = 0;
s->current_picture.motion_val[1][VAR_9 + 1][1] = 0;
s->current_picture.motion_val[1][VAR_9 + VAR_10][0] = 0;
s->current_picture.motion_val[1][VAR_9 + VAR_10][1] = 0;
s->current_picture.motion_val[1][VAR_9 + VAR_10 + 1][0] = 0;
s->current_picture.motion_val[1][VAR_9 + VAR_10 + 1][1] = 0;
}
return;
}
VAR_11 = ((VAR_1 == 0) || (VAR_1 == 1)) ? 1 : -1;
if (s->mb_x || (VAR_1 == 1) || (VAR_1 == 3)) {
if ((VAR_0->blk_mv_type[VAR_9])
|| (!VAR_0->blk_mv_type[VAR_9] && !VAR_0->blk_mv_type[VAR_9 - 1])) {
VAR_12[0] = s->current_picture.motion_val[VAR_8][VAR_9 - 1][0];
VAR_12[1] = s->current_picture.motion_val[VAR_8][VAR_9 - 1][1];
VAR_17 = 1;
} else {
VAR_12[0] = (s->current_picture.motion_val[VAR_8][VAR_9 - 1][0]
+ s->current_picture.motion_val[VAR_8][VAR_9 - 1 + VAR_11 * VAR_10][0] + 1) >> 1;
VAR_12[1] = (s->current_picture.motion_val[VAR_8][VAR_9 - 1][1]
+ s->current_picture.motion_val[VAR_8][VAR_9 - 1 + VAR_11 * VAR_10][1] + 1) >> 1;
VAR_17 = 1;
}
if (!(VAR_1 & 1) && VAR_0->VAR_7[s->mb_x - 1]) {
VAR_17 = 0;
VAR_12[0] = VAR_12[1] = 0;
}
} else
VAR_12[0] = VAR_12[1] = 0;
VAR_13[0] = VAR_13[1] = VAR_14[0] = VAR_14[1] = 0;
if (VAR_1 == 0 || VAR_1 == 1 || VAR_0->blk_mv_type[VAR_9]) {
if (!s->first_slice_line) {
if (!VAR_0->VAR_7[s->mb_x - s->mb_stride]) {
VAR_18 = 1;
VAR_28 = VAR_1 | 2;
VAR_27 = s->block_index[VAR_28] - 2 * VAR_10;
if (VAR_0->blk_mv_type[VAR_27] && VAR_0->blk_mv_type[VAR_9]) {
VAR_28 = (VAR_1 & 2) | (VAR_1 & 1);
}
VAR_13[0] = s->current_picture.motion_val[VAR_8][s->block_index[VAR_28] - 2 * VAR_10][0];
VAR_13[1] = s->current_picture.motion_val[VAR_8][s->block_index[VAR_28] - 2 * VAR_10][1];
if (VAR_0->blk_mv_type[VAR_27] && !VAR_0->blk_mv_type[VAR_9]) {
VAR_13[0] = (VAR_13[0] + s->current_picture.motion_val[VAR_8][s->block_index[VAR_28 ^ 2] - 2 * VAR_10][0] + 1) >> 1;
VAR_13[1] = (VAR_13[1] + s->current_picture.motion_val[VAR_8][s->block_index[VAR_28 ^ 2] - 2 * VAR_10][1] + 1) >> 1;
}
}
if (s->mb_width > 1) {
if (!VAR_0->VAR_7[s->mb_x - s->mb_stride + 1]) {
VAR_19 = 1;
VAR_28 = 2;
VAR_26 = s->block_index[2] - 2 * VAR_10 + 2;
if (VAR_0->blk_mv_type[VAR_26] && VAR_0->blk_mv_type[VAR_9]) {
VAR_28 = VAR_1 & 2;
}
VAR_14[0] = s->current_picture.motion_val[VAR_8][s->block_index[VAR_28] - 2 * VAR_10 + 2][0];
VAR_14[1] = s->current_picture.motion_val[VAR_8][s->block_index[VAR_28] - 2 * VAR_10 + 2][1];
if (VAR_0->blk_mv_type[VAR_26] && !VAR_0->blk_mv_type[VAR_9]) {
VAR_14[0] = (1 + VAR_14[0] + (s->current_picture.motion_val[VAR_8][s->block_index[VAR_28 ^ 2] - 2 * VAR_10 + 2][0])) >> 1;
VAR_14[1] = (1 + VAR_14[1] + (s->current_picture.motion_val[VAR_8][s->block_index[VAR_28 ^ 2] - 2 * VAR_10 + 2][1])) >> 1;
}
if (s->mb_x == s->mb_width - 1) {
if (!VAR_0->VAR_7[s->mb_x - s->mb_stride - 1]) {
VAR_19 = 1;
VAR_28 = 3;
VAR_26 = s->block_index[3] - 2 * VAR_10 - 2;
if (VAR_0->blk_mv_type[VAR_26] && VAR_0->blk_mv_type[VAR_9]) {
VAR_28 = VAR_1 | 1;
}
VAR_14[0] = s->current_picture.motion_val[VAR_8][s->block_index[VAR_28] - 2 * VAR_10 - 2][0];
VAR_14[1] = s->current_picture.motion_val[VAR_8][s->block_index[VAR_28] - 2 * VAR_10 - 2][1];
if (VAR_0->blk_mv_type[VAR_26] && !VAR_0->blk_mv_type[VAR_9]) {
VAR_14[0] = (1 + VAR_14[0] + s->current_picture.motion_val[VAR_8][s->block_index[1] - 2 * VAR_10 - 2][0]) >> 1;
VAR_14[1] = (1 + VAR_14[1] + s->current_picture.motion_val[VAR_8][s->block_index[1] - 2 * VAR_10 - 2][1]) >> 1;
}
} else
VAR_19 = 0;
}
}
}
}
} else {
VAR_27 = s->block_index[1];
VAR_18 = 1;
VAR_13[0] = s->current_picture.motion_val[VAR_8][VAR_27][0];
VAR_13[1] = s->current_picture.motion_val[VAR_8][VAR_27][1];
VAR_26 = s->block_index[0];
VAR_19 = 1;
VAR_14[0] = s->current_picture.motion_val[VAR_8][VAR_26][0];
VAR_14[1] = s->current_picture.motion_val[VAR_8][VAR_26][1];
}
VAR_23 = VAR_17 + VAR_18 + VAR_19;
if (!s->mb_x && !(VAR_1 == 1 || VAR_1 == 3)) {
VAR_12[0] = VAR_12[1] = 0;
}
if ((s->first_slice_line && VAR_0->blk_mv_type[VAR_9]) || (s->first_slice_line && !(VAR_1 & 2))) {
VAR_13[0] = VAR_13[1] = VAR_14[0] = VAR_14[1] = 0;
}
if (!VAR_0->blk_mv_type[VAR_9]) {
if (s->mb_width == 1) {
VAR_15 = VAR_13[0];
VAR_16 = VAR_13[1];
} else {
if (VAR_23 >= 2) {
VAR_15 = mid_pred(VAR_12[0], VAR_13[0], VAR_14[0]);
VAR_16 = mid_pred(VAR_12[1], VAR_13[1], VAR_14[1]);
} else if (VAR_23) {
if (VAR_17) { VAR_15 = VAR_12[0]; VAR_16 = VAR_12[1]; }
else if (VAR_18) { VAR_15 = VAR_13[0]; VAR_16 = VAR_13[1]; }
else if (VAR_19) { VAR_15 = VAR_14[0]; VAR_16 = VAR_14[1]; }
else av_assert2(0);
}
}
} else {
if (VAR_17)
VAR_20 = (VAR_12[1] & 4) ? 1 : 0;
else
VAR_20 = 0;
if (VAR_18)
VAR_21 = (VAR_13[1] & 4) ? 1 : 0;
else
VAR_21 = 0;
if (VAR_19)
VAR_22 = (VAR_14[1] & 4) ? 1 : 0;
else
VAR_22 = 0;
VAR_25 = VAR_20 + VAR_21 + VAR_22;
VAR_24 = VAR_23 - VAR_25;
if (VAR_23 == 3) {
if ((VAR_24 == 3) || (VAR_25 == 3)) {
VAR_15 = mid_pred(VAR_12[0], VAR_13[0], VAR_14[0]);
VAR_16 = mid_pred(VAR_12[1], VAR_13[1], VAR_14[1]);
} else if (VAR_24 >= VAR_25) {
VAR_15 = !VAR_20 ? VAR_12[0] : VAR_13[0];
VAR_16 = !VAR_20 ? VAR_12[1] : VAR_13[1];
} else {
VAR_15 = VAR_20 ? VAR_12[0] : VAR_13[0];
VAR_16 = VAR_20 ? VAR_12[1] : VAR_13[1];
}
} else if (VAR_23 == 2) {
if (VAR_24 >= VAR_25) {
if (!VAR_20 && VAR_17) {
VAR_15 = VAR_12[0];
VAR_16 = VAR_12[1];
} else if (!VAR_21 && VAR_18) {
VAR_15 = VAR_13[0];
VAR_16 = VAR_13[1];
} else if (VAR_19) {
VAR_15 = VAR_14[0];
VAR_16 = VAR_14[1];
} else VAR_15 = VAR_16 = 0;
} else {
if (VAR_20 && VAR_17) {
VAR_15 = VAR_12[0];
VAR_16 = VAR_12[1];
} else if (VAR_21 && VAR_18) {
VAR_15 = VAR_13[0];
VAR_16 = VAR_13[1];
} else if (VAR_19) {
VAR_15 = VAR_14[0];
VAR_16 = VAR_14[1];
}
}
} else if (VAR_23 == 1) {
VAR_15 = (VAR_17) ? VAR_12[0] : ((VAR_18) ? VAR_13[0] : VAR_14[0]);
VAR_16 = (VAR_17) ? VAR_12[1] : ((VAR_18) ? VAR_13[1] : VAR_14[1]);
}
}
s->mv[VAR_8][VAR_1][0] = s->current_picture.motion_val[VAR_8][VAR_9][0] = ((VAR_15 + VAR_2 + VAR_5) & ((VAR_5 << 1) - 1)) - VAR_5;
s->mv[VAR_8][VAR_1][1] = s->current_picture.motion_val[VAR_8][VAR_9][1] = ((VAR_16 + VAR_3 + VAR_6) & ((VAR_6 << 1) - 1)) - VAR_6;
if (VAR_4 == 1) {
s->current_picture.motion_val[VAR_8][VAR_9 + 1 ][0] = s->current_picture.motion_val[VAR_8][VAR_9][0];
s->current_picture.motion_val[VAR_8][VAR_9 + 1 ][1] = s->current_picture.motion_val[VAR_8][VAR_9][1];
s->current_picture.motion_val[VAR_8][VAR_9 + VAR_10 ][0] = s->current_picture.motion_val[VAR_8][VAR_9][0];
s->current_picture.motion_val[VAR_8][VAR_9 + VAR_10 ][1] = s->current_picture.motion_val[VAR_8][VAR_9][1];
s->current_picture.motion_val[VAR_8][VAR_9 + VAR_10 + 1][0] = s->current_picture.motion_val[VAR_8][VAR_9][0];
s->current_picture.motion_val[VAR_8][VAR_9 + VAR_10 + 1][1] = s->current_picture.motion_val[VAR_8][VAR_9][1];
} else if (VAR_4 == 2) {
s->current_picture.motion_val[VAR_8][VAR_9 + 1][0] = s->current_picture.motion_val[VAR_8][VAR_9][0];
s->current_picture.motion_val[VAR_8][VAR_9 + 1][1] = s->current_picture.motion_val[VAR_8][VAR_9][1];
s->mv[VAR_8][VAR_1 + 1][0] = s->mv[VAR_8][VAR_1][0];
s->mv[VAR_8][VAR_1 + 1][1] = s->mv[VAR_8][VAR_1][1];
}
}
| [
"static inline void FUNC_0(VC1Context *VAR_0, int VAR_1, int VAR_2, int VAR_3,\nint VAR_4, int VAR_5, int VAR_6, uint8_t* VAR_7, int VAR_8)\n{",
"MpegEncContext *s = &VAR_0->s;",
"int VAR_9, VAR_10, VAR_11 = 0;",
"int VAR_12[2], VAR_13[2], VAR_14[2];",
"int VAR_15 = 0, VAR_16 = 0;",
"int VAR_17 = 0, VAR_18 = 0, VAR_19 = 0;",
"int VAR_20, VAR_21, VAR_22;",
"int VAR_23, VAR_24, VAR_25;",
"int VAR_26, VAR_27, VAR_28;",
"VAR_10 = s->b8_stride;",
"VAR_9 = s->block_index[VAR_1];",
"if (s->mb_intra) {",
"s->mv[0][VAR_1][0] = s->current_picture.motion_val[0][VAR_9][0] = 0;",
"s->mv[0][VAR_1][1] = s->current_picture.motion_val[0][VAR_9][1] = 0;",
"s->current_picture.motion_val[1][VAR_9][0] = 0;",
"s->current_picture.motion_val[1][VAR_9][1] = 0;",
"if (VAR_4 == 1) {",
"s->current_picture.motion_val[0][VAR_9 + 1][0] = 0;",
"s->current_picture.motion_val[0][VAR_9 + 1][1] = 0;",
"s->current_picture.motion_val[0][VAR_9 + VAR_10][0] = 0;",
"s->current_picture.motion_val[0][VAR_9 + VAR_10][1] = 0;",
"s->current_picture.motion_val[0][VAR_9 + VAR_10 + 1][0] = 0;",
"s->current_picture.motion_val[0][VAR_9 + VAR_10 + 1][1] = 0;",
"VAR_0->luma_mv[s->mb_x][0] = VAR_0->luma_mv[s->mb_x][1] = 0;",
"s->current_picture.motion_val[1][VAR_9 + 1][0] = 0;",
"s->current_picture.motion_val[1][VAR_9 + 1][1] = 0;",
"s->current_picture.motion_val[1][VAR_9 + VAR_10][0] = 0;",
"s->current_picture.motion_val[1][VAR_9 + VAR_10][1] = 0;",
"s->current_picture.motion_val[1][VAR_9 + VAR_10 + 1][0] = 0;",
"s->current_picture.motion_val[1][VAR_9 + VAR_10 + 1][1] = 0;",
"}",
"return;",
"}",
"VAR_11 = ((VAR_1 == 0) || (VAR_1 == 1)) ? 1 : -1;",
"if (s->mb_x || (VAR_1 == 1) || (VAR_1 == 3)) {",
"if ((VAR_0->blk_mv_type[VAR_9])\n|| (!VAR_0->blk_mv_type[VAR_9] && !VAR_0->blk_mv_type[VAR_9 - 1])) {",
"VAR_12[0] = s->current_picture.motion_val[VAR_8][VAR_9 - 1][0];",
"VAR_12[1] = s->current_picture.motion_val[VAR_8][VAR_9 - 1][1];",
"VAR_17 = 1;",
"} else {",
"VAR_12[0] = (s->current_picture.motion_val[VAR_8][VAR_9 - 1][0]\n+ s->current_picture.motion_val[VAR_8][VAR_9 - 1 + VAR_11 * VAR_10][0] + 1) >> 1;",
"VAR_12[1] = (s->current_picture.motion_val[VAR_8][VAR_9 - 1][1]\n+ s->current_picture.motion_val[VAR_8][VAR_9 - 1 + VAR_11 * VAR_10][1] + 1) >> 1;",
"VAR_17 = 1;",
"}",
"if (!(VAR_1 & 1) && VAR_0->VAR_7[s->mb_x - 1]) {",
"VAR_17 = 0;",
"VAR_12[0] = VAR_12[1] = 0;",
"}",
"} else",
"VAR_12[0] = VAR_12[1] = 0;",
"VAR_13[0] = VAR_13[1] = VAR_14[0] = VAR_14[1] = 0;",
"if (VAR_1 == 0 || VAR_1 == 1 || VAR_0->blk_mv_type[VAR_9]) {",
"if (!s->first_slice_line) {",
"if (!VAR_0->VAR_7[s->mb_x - s->mb_stride]) {",
"VAR_18 = 1;",
"VAR_28 = VAR_1 | 2;",
"VAR_27 = s->block_index[VAR_28] - 2 * VAR_10;",
"if (VAR_0->blk_mv_type[VAR_27] && VAR_0->blk_mv_type[VAR_9]) {",
"VAR_28 = (VAR_1 & 2) | (VAR_1 & 1);",
"}",
"VAR_13[0] = s->current_picture.motion_val[VAR_8][s->block_index[VAR_28] - 2 * VAR_10][0];",
"VAR_13[1] = s->current_picture.motion_val[VAR_8][s->block_index[VAR_28] - 2 * VAR_10][1];",
"if (VAR_0->blk_mv_type[VAR_27] && !VAR_0->blk_mv_type[VAR_9]) {",
"VAR_13[0] = (VAR_13[0] + s->current_picture.motion_val[VAR_8][s->block_index[VAR_28 ^ 2] - 2 * VAR_10][0] + 1) >> 1;",
"VAR_13[1] = (VAR_13[1] + s->current_picture.motion_val[VAR_8][s->block_index[VAR_28 ^ 2] - 2 * VAR_10][1] + 1) >> 1;",
"}",
"}",
"if (s->mb_width > 1) {",
"if (!VAR_0->VAR_7[s->mb_x - s->mb_stride + 1]) {",
"VAR_19 = 1;",
"VAR_28 = 2;",
"VAR_26 = s->block_index[2] - 2 * VAR_10 + 2;",
"if (VAR_0->blk_mv_type[VAR_26] && VAR_0->blk_mv_type[VAR_9]) {",
"VAR_28 = VAR_1 & 2;",
"}",
"VAR_14[0] = s->current_picture.motion_val[VAR_8][s->block_index[VAR_28] - 2 * VAR_10 + 2][0];",
"VAR_14[1] = s->current_picture.motion_val[VAR_8][s->block_index[VAR_28] - 2 * VAR_10 + 2][1];",
"if (VAR_0->blk_mv_type[VAR_26] && !VAR_0->blk_mv_type[VAR_9]) {",
"VAR_14[0] = (1 + VAR_14[0] + (s->current_picture.motion_val[VAR_8][s->block_index[VAR_28 ^ 2] - 2 * VAR_10 + 2][0])) >> 1;",
"VAR_14[1] = (1 + VAR_14[1] + (s->current_picture.motion_val[VAR_8][s->block_index[VAR_28 ^ 2] - 2 * VAR_10 + 2][1])) >> 1;",
"}",
"if (s->mb_x == s->mb_width - 1) {",
"if (!VAR_0->VAR_7[s->mb_x - s->mb_stride - 1]) {",
"VAR_19 = 1;",
"VAR_28 = 3;",
"VAR_26 = s->block_index[3] - 2 * VAR_10 - 2;",
"if (VAR_0->blk_mv_type[VAR_26] && VAR_0->blk_mv_type[VAR_9]) {",
"VAR_28 = VAR_1 | 1;",
"}",
"VAR_14[0] = s->current_picture.motion_val[VAR_8][s->block_index[VAR_28] - 2 * VAR_10 - 2][0];",
"VAR_14[1] = s->current_picture.motion_val[VAR_8][s->block_index[VAR_28] - 2 * VAR_10 - 2][1];",
"if (VAR_0->blk_mv_type[VAR_26] && !VAR_0->blk_mv_type[VAR_9]) {",
"VAR_14[0] = (1 + VAR_14[0] + s->current_picture.motion_val[VAR_8][s->block_index[1] - 2 * VAR_10 - 2][0]) >> 1;",
"VAR_14[1] = (1 + VAR_14[1] + s->current_picture.motion_val[VAR_8][s->block_index[1] - 2 * VAR_10 - 2][1]) >> 1;",
"}",
"} else",
"VAR_19 = 0;",
"}",
"}",
"}",
"}",
"} else {",
"VAR_27 = s->block_index[1];",
"VAR_18 = 1;",
"VAR_13[0] = s->current_picture.motion_val[VAR_8][VAR_27][0];",
"VAR_13[1] = s->current_picture.motion_val[VAR_8][VAR_27][1];",
"VAR_26 = s->block_index[0];",
"VAR_19 = 1;",
"VAR_14[0] = s->current_picture.motion_val[VAR_8][VAR_26][0];",
"VAR_14[1] = s->current_picture.motion_val[VAR_8][VAR_26][1];",
"}",
"VAR_23 = VAR_17 + VAR_18 + VAR_19;",
"if (!s->mb_x && !(VAR_1 == 1 || VAR_1 == 3)) {",
"VAR_12[0] = VAR_12[1] = 0;",
"}",
"if ((s->first_slice_line && VAR_0->blk_mv_type[VAR_9]) || (s->first_slice_line && !(VAR_1 & 2))) {",
"VAR_13[0] = VAR_13[1] = VAR_14[0] = VAR_14[1] = 0;",
"}",
"if (!VAR_0->blk_mv_type[VAR_9]) {",
"if (s->mb_width == 1) {",
"VAR_15 = VAR_13[0];",
"VAR_16 = VAR_13[1];",
"} else {",
"if (VAR_23 >= 2) {",
"VAR_15 = mid_pred(VAR_12[0], VAR_13[0], VAR_14[0]);",
"VAR_16 = mid_pred(VAR_12[1], VAR_13[1], VAR_14[1]);",
"} else if (VAR_23) {",
"if (VAR_17) { VAR_15 = VAR_12[0]; VAR_16 = VAR_12[1]; }",
"else if (VAR_18) { VAR_15 = VAR_13[0]; VAR_16 = VAR_13[1]; }",
"else if (VAR_19) { VAR_15 = VAR_14[0]; VAR_16 = VAR_14[1]; }",
"else av_assert2(0);",
"}",
"}",
"} else {",
"if (VAR_17)\nVAR_20 = (VAR_12[1] & 4) ? 1 : 0;",
"else\nVAR_20 = 0;",
"if (VAR_18)\nVAR_21 = (VAR_13[1] & 4) ? 1 : 0;",
"else\nVAR_21 = 0;",
"if (VAR_19)\nVAR_22 = (VAR_14[1] & 4) ? 1 : 0;",
"else\nVAR_22 = 0;",
"VAR_25 = VAR_20 + VAR_21 + VAR_22;",
"VAR_24 = VAR_23 - VAR_25;",
"if (VAR_23 == 3) {",
"if ((VAR_24 == 3) || (VAR_25 == 3)) {",
"VAR_15 = mid_pred(VAR_12[0], VAR_13[0], VAR_14[0]);",
"VAR_16 = mid_pred(VAR_12[1], VAR_13[1], VAR_14[1]);",
"} else if (VAR_24 >= VAR_25) {",
"VAR_15 = !VAR_20 ? VAR_12[0] : VAR_13[0];",
"VAR_16 = !VAR_20 ? VAR_12[1] : VAR_13[1];",
"} else {",
"VAR_15 = VAR_20 ? VAR_12[0] : VAR_13[0];",
"VAR_16 = VAR_20 ? VAR_12[1] : VAR_13[1];",
"}",
"} else if (VAR_23 == 2) {",
"if (VAR_24 >= VAR_25) {",
"if (!VAR_20 && VAR_17) {",
"VAR_15 = VAR_12[0];",
"VAR_16 = VAR_12[1];",
"} else if (!VAR_21 && VAR_18) {",
"VAR_15 = VAR_13[0];",
"VAR_16 = VAR_13[1];",
"} else if (VAR_19) {",
"VAR_15 = VAR_14[0];",
"VAR_16 = VAR_14[1];",
"} else VAR_15 = VAR_16 = 0;",
"} else {",
"if (VAR_20 && VAR_17) {",
"VAR_15 = VAR_12[0];",
"VAR_16 = VAR_12[1];",
"} else if (VAR_21 && VAR_18) {",
"VAR_15 = VAR_13[0];",
"VAR_16 = VAR_13[1];",
"} else if (VAR_19) {",
"VAR_15 = VAR_14[0];",
"VAR_16 = VAR_14[1];",
"}",
"}",
"} else if (VAR_23 == 1) {",
"VAR_15 = (VAR_17) ? VAR_12[0] : ((VAR_18) ? VAR_13[0] : VAR_14[0]);",
"VAR_16 = (VAR_17) ? VAR_12[1] : ((VAR_18) ? VAR_13[1] : VAR_14[1]);",
"}",
"}",
"s->mv[VAR_8][VAR_1][0] = s->current_picture.motion_val[VAR_8][VAR_9][0] = ((VAR_15 + VAR_2 + VAR_5) & ((VAR_5 << 1) - 1)) - VAR_5;",
"s->mv[VAR_8][VAR_1][1] = s->current_picture.motion_val[VAR_8][VAR_9][1] = ((VAR_16 + VAR_3 + VAR_6) & ((VAR_6 << 1) - 1)) - VAR_6;",
"if (VAR_4 == 1) {",
"s->current_picture.motion_val[VAR_8][VAR_9 + 1 ][0] = s->current_picture.motion_val[VAR_8][VAR_9][0];",
"s->current_picture.motion_val[VAR_8][VAR_9 + 1 ][1] = s->current_picture.motion_val[VAR_8][VAR_9][1];",
"s->current_picture.motion_val[VAR_8][VAR_9 + VAR_10 ][0] = s->current_picture.motion_val[VAR_8][VAR_9][0];",
"s->current_picture.motion_val[VAR_8][VAR_9 + VAR_10 ][1] = s->current_picture.motion_val[VAR_8][VAR_9][1];",
"s->current_picture.motion_val[VAR_8][VAR_9 + VAR_10 + 1][0] = s->current_picture.motion_val[VAR_8][VAR_9][0];",
"s->current_picture.motion_val[VAR_8][VAR_9 + VAR_10 + 1][1] = s->current_picture.motion_val[VAR_8][VAR_9][1];",
"} else if (VAR_4 == 2) {",
"s->current_picture.motion_val[VAR_8][VAR_9 + 1][0] = s->current_picture.motion_val[VAR_8][VAR_9][0];",
"s->current_picture.motion_val[VAR_8][VAR_9 + 1][1] = s->current_picture.motion_val[VAR_8][VAR_9][1];",
"s->mv[VAR_8][VAR_1 + 1][0] = s->mv[VAR_8][VAR_1][0];",
"s->mv[VAR_8][VAR_1 + 1][1] = s->mv[VAR_8][VAR_1][1];",
"}",
"}"
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | [
[
1,
3,
5
],
[
7
],
[
9
],
[
11
],
[
13
],
[
15
],
[
17
],
[
19
],
[
21
],
[
25
],
[
27
],
[
31
],
[
33
],
[
35
],
[
37
],
[
39
],
[
41
],
[
43
],
[
45
],
[
47
],
[
49
],
[
51
],
[
53
],
[
55
],
[
57
],
[
59
],
[
61
],
[
63
],
[
65
],
[
67
],
[
69
],
[
71
],
[
73
],
[
77
],
[
81
],
[
83,
85
],
[
87
],
[
89
],
[
91
],
[
93
],
[
95,
97
],
[
99,
101
],
[
103
],
[
105
],
[
107
],
[
109
],
[
111
],
[
113
],
[
115
],
[
117
],
[
121
],
[
123
],
[
125
],
[
127
],
[
129
],
[
131
],
[
133
],
[
135
],
[
137
],
[
139
],
[
141
],
[
143
],
[
145
],
[
147
],
[
149
],
[
151
],
[
153
],
[
155
],
[
157
],
[
159
],
[
161
],
[
163
],
[
165
],
[
167
],
[
169
],
[
171
],
[
173
],
[
175
],
[
177
],
[
179
],
[
181
],
[
183
],
[
185
],
[
187
],
[
189
],
[
191
],
[
193
],
[
195
],
[
197
],
[
199
],
[
201
],
[
203
],
[
205
],
[
207
],
[
209
],
[
211
],
[
213
],
[
215
],
[
217
],
[
219
],
[
221
],
[
223
],
[
225
],
[
227
],
[
229
],
[
231
],
[
233
],
[
235
],
[
237
],
[
239
],
[
241
],
[
245
],
[
249
],
[
251
],
[
253
],
[
257
],
[
259
],
[
261
],
[
263
],
[
265
],
[
267
],
[
269
],
[
271
],
[
273
],
[
275
],
[
277
],
[
279
],
[
281
],
[
283
],
[
285
],
[
287
],
[
289
],
[
291
],
[
293
],
[
295,
297
],
[
299,
301
],
[
303,
305
],
[
307,
309
],
[
311,
313
],
[
315,
317
],
[
321
],
[
323
],
[
325
],
[
327
],
[
329
],
[
331
],
[
333
],
[
339
],
[
341
],
[
343
],
[
345
],
[
347
],
[
349
],
[
351
],
[
353
],
[
355
],
[
357
],
[
359
],
[
361
],
[
363
],
[
365
],
[
367
],
[
369
],
[
371
],
[
373
],
[
375
],
[
377
],
[
379
],
[
381
],
[
383
],
[
385
],
[
387
],
[
389
],
[
391
],
[
393
],
[
395
],
[
397
],
[
399
],
[
401
],
[
403
],
[
405
],
[
407
],
[
413
],
[
415
],
[
417
],
[
419
],
[
421
],
[
423
],
[
425
],
[
427
],
[
429
],
[
431
],
[
433
],
[
435
],
[
437
],
[
439
],
[
441
],
[
443
]
] |
21,373 | static void free_buffers(VP8Context *s)
{
int i;
if (s->thread_data)
for (i = 0; i < MAX_THREADS; i++) {
av_freep(&s->thread_data[i].filter_strength);
av_freep(&s->thread_data[i].edge_emu_buffer);
}
av_freep(&s->thread_data);
av_freep(&s->macroblocks_base);
av_freep(&s->intra4x4_pred_mode_top);
av_freep(&s->top_nnz);
av_freep(&s->top_border);
s->macroblocks = NULL;
} | true | FFmpeg | 65340c976c664b94427ac50f5d03b0e77883c108 | static void free_buffers(VP8Context *s)
{
int i;
if (s->thread_data)
for (i = 0; i < MAX_THREADS; i++) {
av_freep(&s->thread_data[i].filter_strength);
av_freep(&s->thread_data[i].edge_emu_buffer);
}
av_freep(&s->thread_data);
av_freep(&s->macroblocks_base);
av_freep(&s->intra4x4_pred_mode_top);
av_freep(&s->top_nnz);
av_freep(&s->top_border);
s->macroblocks = NULL;
} | {
"code": [],
"line_no": []
} | static void FUNC_0(VP8Context *VAR_0)
{
int VAR_1;
if (VAR_0->thread_data)
for (VAR_1 = 0; VAR_1 < MAX_THREADS; VAR_1++) {
av_freep(&VAR_0->thread_data[VAR_1].filter_strength);
av_freep(&VAR_0->thread_data[VAR_1].edge_emu_buffer);
}
av_freep(&VAR_0->thread_data);
av_freep(&VAR_0->macroblocks_base);
av_freep(&VAR_0->intra4x4_pred_mode_top);
av_freep(&VAR_0->top_nnz);
av_freep(&VAR_0->top_border);
VAR_0->macroblocks = NULL;
} | [
"static void FUNC_0(VP8Context *VAR_0)\n{",
"int VAR_1;",
"if (VAR_0->thread_data)\nfor (VAR_1 = 0; VAR_1 < MAX_THREADS; VAR_1++) {",
"av_freep(&VAR_0->thread_data[VAR_1].filter_strength);",
"av_freep(&VAR_0->thread_data[VAR_1].edge_emu_buffer);",
"}",
"av_freep(&VAR_0->thread_data);",
"av_freep(&VAR_0->macroblocks_base);",
"av_freep(&VAR_0->intra4x4_pred_mode_top);",
"av_freep(&VAR_0->top_nnz);",
"av_freep(&VAR_0->top_border);",
"VAR_0->macroblocks = NULL;",
"}"
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | [
[
1,
3
],
[
5
],
[
7,
9
],
[
15
],
[
17
],
[
19
],
[
21
],
[
23
],
[
25
],
[
27
],
[
29
],
[
33
],
[
35
]
] |
21,375 | static void intel_hda_realize(PCIDevice *pci, Error **errp)
{
IntelHDAState *d = INTEL_HDA(pci);
uint8_t *conf = d->pci.config;
d->name = object_get_typename(OBJECT(d));
pci_config_set_interrupt_pin(conf, 1);
/* HDCTL off 0x40 bit 0 selects signaling mode (1-HDA, 0 - Ac97) 18.1.19 */
conf[0x40] = 0x01;
memory_region_init_io(&d->mmio, OBJECT(d), &intel_hda_mmio_ops, d,
"intel-hda", 0x4000);
pci_register_bar(&d->pci, 0, 0, &d->mmio);
if (d->msi != ON_OFF_AUTO_OFF) {
/* TODO check for errors */
msi_init(&d->pci, d->old_msi_addr ? 0x50 : 0x60, 1, true, false);
}
hda_codec_bus_init(DEVICE(pci), &d->codecs, sizeof(d->codecs),
intel_hda_response, intel_hda_xfer);
}
| true | qemu | 1108b2f8a939fb5778d384149e2f1b99062a72da | static void intel_hda_realize(PCIDevice *pci, Error **errp)
{
IntelHDAState *d = INTEL_HDA(pci);
uint8_t *conf = d->pci.config;
d->name = object_get_typename(OBJECT(d));
pci_config_set_interrupt_pin(conf, 1);
conf[0x40] = 0x01;
memory_region_init_io(&d->mmio, OBJECT(d), &intel_hda_mmio_ops, d,
"intel-hda", 0x4000);
pci_register_bar(&d->pci, 0, 0, &d->mmio);
if (d->msi != ON_OFF_AUTO_OFF) {
msi_init(&d->pci, d->old_msi_addr ? 0x50 : 0x60, 1, true, false);
}
hda_codec_bus_init(DEVICE(pci), &d->codecs, sizeof(d->codecs),
intel_hda_response, intel_hda_xfer);
}
| {
"code": [
" if (d->msi != ON_OFF_AUTO_OFF) {",
" msi_init(&d->pci, d->old_msi_addr ? 0x50 : 0x60, 1, true, false);"
],
"line_no": [
31,
35
]
} | static void FUNC_0(PCIDevice *VAR_0, Error **VAR_1)
{
IntelHDAState *d = INTEL_HDA(VAR_0);
uint8_t *conf = d->VAR_0.config;
d->name = object_get_typename(OBJECT(d));
pci_config_set_interrupt_pin(conf, 1);
conf[0x40] = 0x01;
memory_region_init_io(&d->mmio, OBJECT(d), &intel_hda_mmio_ops, d,
"intel-hda", 0x4000);
pci_register_bar(&d->VAR_0, 0, 0, &d->mmio);
if (d->msi != ON_OFF_AUTO_OFF) {
msi_init(&d->VAR_0, d->old_msi_addr ? 0x50 : 0x60, 1, true, false);
}
hda_codec_bus_init(DEVICE(VAR_0), &d->codecs, sizeof(d->codecs),
intel_hda_response, intel_hda_xfer);
}
| [
"static void FUNC_0(PCIDevice *VAR_0, Error **VAR_1)\n{",
"IntelHDAState *d = INTEL_HDA(VAR_0);",
"uint8_t *conf = d->VAR_0.config;",
"d->name = object_get_typename(OBJECT(d));",
"pci_config_set_interrupt_pin(conf, 1);",
"conf[0x40] = 0x01;",
"memory_region_init_io(&d->mmio, OBJECT(d), &intel_hda_mmio_ops, d,\n\"intel-hda\", 0x4000);",
"pci_register_bar(&d->VAR_0, 0, 0, &d->mmio);",
"if (d->msi != ON_OFF_AUTO_OFF) {",
"msi_init(&d->VAR_0, d->old_msi_addr ? 0x50 : 0x60, 1, true, false);",
"}",
"hda_codec_bus_init(DEVICE(VAR_0), &d->codecs, sizeof(d->codecs),\nintel_hda_response, intel_hda_xfer);",
"}"
] | [
0,
0,
0,
0,
0,
0,
0,
0,
1,
1,
0,
0,
0
] | [
[
1,
3
],
[
5
],
[
7
],
[
11
],
[
15
],
[
21
],
[
25,
27
],
[
29
],
[
31
],
[
35
],
[
37
],
[
41,
43
],
[
45
]
] |
21,376 | static void vnc_dpy_copy(DisplayChangeListener *dcl,
int src_x, int src_y,
int dst_x, int dst_y, int w, int h)
{
VncDisplay *vd = container_of(dcl, VncDisplay, dcl);
VncState *vs, *vn;
uint8_t *src_row;
uint8_t *dst_row;
int i, x, y, pitch, inc, w_lim, s;
int cmp_bytes;
vnc_refresh_server_surface(vd);
QTAILQ_FOREACH_SAFE(vs, &vd->clients, next, vn) {
if (vnc_has_feature(vs, VNC_FEATURE_COPYRECT)) {
vs->force_update = 1;
vnc_update_client(vs, 1, true);
/* vs might be free()ed here */
/* do bitblit op on the local surface too */
pitch = vnc_server_fb_stride(vd);
src_row = vnc_server_fb_ptr(vd, src_x, src_y);
dst_row = vnc_server_fb_ptr(vd, dst_x, dst_y);
y = dst_y;
inc = 1;
if (dst_y > src_y) {
/* copy backwards */
src_row += pitch * (h-1);
dst_row += pitch * (h-1);
pitch = -pitch;
y = dst_y + h - 1;
inc = -1;
w_lim = w - (VNC_DIRTY_PIXELS_PER_BIT - (dst_x % VNC_DIRTY_PIXELS_PER_BIT));
if (w_lim < 0) {
w_lim = w;
} else {
w_lim = w - (w_lim % VNC_DIRTY_PIXELS_PER_BIT);
for (i = 0; i < h; i++) {
for (x = 0; x <= w_lim;
x += s, src_row += cmp_bytes, dst_row += cmp_bytes) {
if (x == w_lim) {
if ((s = w - w_lim) == 0)
break;
} else if (!x) {
s = (VNC_DIRTY_PIXELS_PER_BIT -
(dst_x % VNC_DIRTY_PIXELS_PER_BIT));
s = MIN(s, w_lim);
} else {
s = VNC_DIRTY_PIXELS_PER_BIT;
cmp_bytes = s * VNC_SERVER_FB_BYTES;
if (memcmp(src_row, dst_row, cmp_bytes) == 0)
continue;
memmove(dst_row, src_row, cmp_bytes);
QTAILQ_FOREACH(vs, &vd->clients, next) {
if (!vnc_has_feature(vs, VNC_FEATURE_COPYRECT)) {
set_bit(((x + dst_x) / VNC_DIRTY_PIXELS_PER_BIT),
vs->dirty[y]);
src_row += pitch - w * VNC_SERVER_FB_BYTES;
dst_row += pitch - w * VNC_SERVER_FB_BYTES;
y += inc;
QTAILQ_FOREACH(vs, &vd->clients, next) {
if (vnc_has_feature(vs, VNC_FEATURE_COPYRECT)) {
vnc_copy(vs, src_x, src_y, dst_x, dst_y, w, h);
| true | qemu | 3e10c3ecfcaf604d8b400d6e463e1a186ce97d9b | static void vnc_dpy_copy(DisplayChangeListener *dcl,
int src_x, int src_y,
int dst_x, int dst_y, int w, int h)
{
VncDisplay *vd = container_of(dcl, VncDisplay, dcl);
VncState *vs, *vn;
uint8_t *src_row;
uint8_t *dst_row;
int i, x, y, pitch, inc, w_lim, s;
int cmp_bytes;
vnc_refresh_server_surface(vd);
QTAILQ_FOREACH_SAFE(vs, &vd->clients, next, vn) {
if (vnc_has_feature(vs, VNC_FEATURE_COPYRECT)) {
vs->force_update = 1;
vnc_update_client(vs, 1, true);
pitch = vnc_server_fb_stride(vd);
src_row = vnc_server_fb_ptr(vd, src_x, src_y);
dst_row = vnc_server_fb_ptr(vd, dst_x, dst_y);
y = dst_y;
inc = 1;
if (dst_y > src_y) {
src_row += pitch * (h-1);
dst_row += pitch * (h-1);
pitch = -pitch;
y = dst_y + h - 1;
inc = -1;
w_lim = w - (VNC_DIRTY_PIXELS_PER_BIT - (dst_x % VNC_DIRTY_PIXELS_PER_BIT));
if (w_lim < 0) {
w_lim = w;
} else {
w_lim = w - (w_lim % VNC_DIRTY_PIXELS_PER_BIT);
for (i = 0; i < h; i++) {
for (x = 0; x <= w_lim;
x += s, src_row += cmp_bytes, dst_row += cmp_bytes) {
if (x == w_lim) {
if ((s = w - w_lim) == 0)
break;
} else if (!x) {
s = (VNC_DIRTY_PIXELS_PER_BIT -
(dst_x % VNC_DIRTY_PIXELS_PER_BIT));
s = MIN(s, w_lim);
} else {
s = VNC_DIRTY_PIXELS_PER_BIT;
cmp_bytes = s * VNC_SERVER_FB_BYTES;
if (memcmp(src_row, dst_row, cmp_bytes) == 0)
continue;
memmove(dst_row, src_row, cmp_bytes);
QTAILQ_FOREACH(vs, &vd->clients, next) {
if (!vnc_has_feature(vs, VNC_FEATURE_COPYRECT)) {
set_bit(((x + dst_x) / VNC_DIRTY_PIXELS_PER_BIT),
vs->dirty[y]);
src_row += pitch - w * VNC_SERVER_FB_BYTES;
dst_row += pitch - w * VNC_SERVER_FB_BYTES;
y += inc;
QTAILQ_FOREACH(vs, &vd->clients, next) {
if (vnc_has_feature(vs, VNC_FEATURE_COPYRECT)) {
vnc_copy(vs, src_x, src_y, dst_x, dst_y, w, h);
| {
"code": [],
"line_no": []
} | static void FUNC_0(DisplayChangeListener *VAR_0,
int VAR_1, int VAR_2,
int VAR_3, int VAR_4, int VAR_5, int VAR_6)
{
VncDisplay *vd = container_of(VAR_0, VncDisplay, VAR_0);
VncState *vs, *vn;
uint8_t *src_row;
uint8_t *dst_row;
int VAR_7, VAR_8, VAR_9, VAR_10, VAR_11, VAR_12, VAR_13;
int VAR_14;
vnc_refresh_server_surface(vd);
QTAILQ_FOREACH_SAFE(vs, &vd->clients, next, vn) {
if (vnc_has_feature(vs, VNC_FEATURE_COPYRECT)) {
vs->force_update = 1;
vnc_update_client(vs, 1, true);
VAR_10 = vnc_server_fb_stride(vd);
src_row = vnc_server_fb_ptr(vd, VAR_1, VAR_2);
dst_row = vnc_server_fb_ptr(vd, VAR_3, VAR_4);
VAR_9 = VAR_4;
VAR_11 = 1;
if (VAR_4 > VAR_2) {
src_row += VAR_10 * (VAR_6-1);
dst_row += VAR_10 * (VAR_6-1);
VAR_10 = -VAR_10;
VAR_9 = VAR_4 + VAR_6 - 1;
VAR_11 = -1;
VAR_12 = VAR_5 - (VNC_DIRTY_PIXELS_PER_BIT - (VAR_3 % VNC_DIRTY_PIXELS_PER_BIT));
if (VAR_12 < 0) {
VAR_12 = VAR_5;
} else {
VAR_12 = VAR_5 - (VAR_12 % VNC_DIRTY_PIXELS_PER_BIT);
for (VAR_7 = 0; VAR_7 < VAR_6; VAR_7++) {
for (VAR_8 = 0; VAR_8 <= VAR_12;
VAR_8 += VAR_13, src_row += VAR_14, dst_row += VAR_14) {
if (VAR_8 == VAR_12) {
if ((VAR_13 = VAR_5 - VAR_12) == 0)
break;
} else if (!VAR_8) {
VAR_13 = (VNC_DIRTY_PIXELS_PER_BIT -
(VAR_3 % VNC_DIRTY_PIXELS_PER_BIT));
VAR_13 = MIN(VAR_13, VAR_12);
} else {
VAR_13 = VNC_DIRTY_PIXELS_PER_BIT;
VAR_14 = VAR_13 * VNC_SERVER_FB_BYTES;
if (memcmp(src_row, dst_row, VAR_14) == 0)
continue;
memmove(dst_row, src_row, VAR_14);
QTAILQ_FOREACH(vs, &vd->clients, next) {
if (!vnc_has_feature(vs, VNC_FEATURE_COPYRECT)) {
set_bit(((VAR_8 + VAR_3) / VNC_DIRTY_PIXELS_PER_BIT),
vs->dirty[VAR_9]);
src_row += VAR_10 - VAR_5 * VNC_SERVER_FB_BYTES;
dst_row += VAR_10 - VAR_5 * VNC_SERVER_FB_BYTES;
VAR_9 += VAR_11;
QTAILQ_FOREACH(vs, &vd->clients, next) {
if (vnc_has_feature(vs, VNC_FEATURE_COPYRECT)) {
vnc_copy(vs, VAR_1, VAR_2, VAR_3, VAR_4, VAR_5, VAR_6);
| [
"static void FUNC_0(DisplayChangeListener *VAR_0,\nint VAR_1, int VAR_2,\nint VAR_3, int VAR_4, int VAR_5, int VAR_6)\n{",
"VncDisplay *vd = container_of(VAR_0, VncDisplay, VAR_0);",
"VncState *vs, *vn;",
"uint8_t *src_row;",
"uint8_t *dst_row;",
"int VAR_7, VAR_8, VAR_9, VAR_10, VAR_11, VAR_12, VAR_13;",
"int VAR_14;",
"vnc_refresh_server_surface(vd);",
"QTAILQ_FOREACH_SAFE(vs, &vd->clients, next, vn) {",
"if (vnc_has_feature(vs, VNC_FEATURE_COPYRECT)) {",
"vs->force_update = 1;",
"vnc_update_client(vs, 1, true);",
"VAR_10 = vnc_server_fb_stride(vd);",
"src_row = vnc_server_fb_ptr(vd, VAR_1, VAR_2);",
"dst_row = vnc_server_fb_ptr(vd, VAR_3, VAR_4);",
"VAR_9 = VAR_4;",
"VAR_11 = 1;",
"if (VAR_4 > VAR_2) {",
"src_row += VAR_10 * (VAR_6-1);",
"dst_row += VAR_10 * (VAR_6-1);",
"VAR_10 = -VAR_10;",
"VAR_9 = VAR_4 + VAR_6 - 1;",
"VAR_11 = -1;",
"VAR_12 = VAR_5 - (VNC_DIRTY_PIXELS_PER_BIT - (VAR_3 % VNC_DIRTY_PIXELS_PER_BIT));",
"if (VAR_12 < 0) {",
"VAR_12 = VAR_5;",
"} else {",
"VAR_12 = VAR_5 - (VAR_12 % VNC_DIRTY_PIXELS_PER_BIT);",
"for (VAR_7 = 0; VAR_7 < VAR_6; VAR_7++) {",
"for (VAR_8 = 0; VAR_8 <= VAR_12;",
"VAR_8 += VAR_13, src_row += VAR_14, dst_row += VAR_14) {",
"if (VAR_8 == VAR_12) {",
"if ((VAR_13 = VAR_5 - VAR_12) == 0)\nbreak;",
"} else if (!VAR_8) {",
"VAR_13 = (VNC_DIRTY_PIXELS_PER_BIT -\n(VAR_3 % VNC_DIRTY_PIXELS_PER_BIT));",
"VAR_13 = MIN(VAR_13, VAR_12);",
"} else {",
"VAR_13 = VNC_DIRTY_PIXELS_PER_BIT;",
"VAR_14 = VAR_13 * VNC_SERVER_FB_BYTES;",
"if (memcmp(src_row, dst_row, VAR_14) == 0)\ncontinue;",
"memmove(dst_row, src_row, VAR_14);",
"QTAILQ_FOREACH(vs, &vd->clients, next) {",
"if (!vnc_has_feature(vs, VNC_FEATURE_COPYRECT)) {",
"set_bit(((VAR_8 + VAR_3) / VNC_DIRTY_PIXELS_PER_BIT),\nvs->dirty[VAR_9]);",
"src_row += VAR_10 - VAR_5 * VNC_SERVER_FB_BYTES;",
"dst_row += VAR_10 - VAR_5 * VNC_SERVER_FB_BYTES;",
"VAR_9 += VAR_11;",
"QTAILQ_FOREACH(vs, &vd->clients, next) {",
"if (vnc_has_feature(vs, VNC_FEATURE_COPYRECT)) {",
"vnc_copy(vs, VAR_1, VAR_2, VAR_3, VAR_4, VAR_5, VAR_6);"
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | [
[
1,
3,
5,
7
],
[
9
],
[
11
],
[
13
],
[
15
],
[
17
],
[
19
],
[
29
],
[
31
],
[
33
],
[
35
],
[
37
],
[
51
],
[
53
],
[
55
],
[
57
],
[
59
],
[
61
],
[
65
],
[
67
],
[
69
],
[
71
],
[
73
],
[
76
],
[
78
],
[
80
],
[
82
],
[
84
],
[
87
],
[
89
],
[
91
],
[
93
],
[
95,
97
],
[
99
],
[
101,
103
],
[
105
],
[
107
],
[
109
],
[
112
],
[
114,
116
],
[
118
],
[
120
],
[
122
],
[
124,
126
],
[
131
],
[
133
],
[
135
],
[
140
],
[
142
],
[
144
]
] |
21,377 | static int write_refcount_block_entries(BlockDriverState *bs,
int64_t refcount_block_offset, int first_index, int last_index)
{
BDRVQcowState *s = bs->opaque;
size_t size;
int ret;
if (cache_refcount_updates) {
first_index &= ~(REFCOUNTS_PER_SECTOR - 1);
last_index = (last_index + REFCOUNTS_PER_SECTOR)
& ~(REFCOUNTS_PER_SECTOR - 1);
size = (last_index - first_index) << REFCOUNT_SHIFT;
BLKDBG_EVENT(bs->file, BLKDBG_REFBLOCK_UPDATE_PART);
ret = bdrv_pwrite(bs->file,
refcount_block_offset + (first_index << REFCOUNT_SHIFT),
&s->refcount_block_cache[first_index], size);
if (ret < 0) {
return ret; | true | qemu | 86fa8da83771238de55dc44819a1a27bafef5353 | static int write_refcount_block_entries(BlockDriverState *bs,
int64_t refcount_block_offset, int first_index, int last_index)
{
BDRVQcowState *s = bs->opaque;
size_t size;
int ret;
if (cache_refcount_updates) {
first_index &= ~(REFCOUNTS_PER_SECTOR - 1);
last_index = (last_index + REFCOUNTS_PER_SECTOR)
& ~(REFCOUNTS_PER_SECTOR - 1);
size = (last_index - first_index) << REFCOUNT_SHIFT;
BLKDBG_EVENT(bs->file, BLKDBG_REFBLOCK_UPDATE_PART);
ret = bdrv_pwrite(bs->file,
refcount_block_offset + (first_index << REFCOUNT_SHIFT),
&s->refcount_block_cache[first_index], size);
if (ret < 0) {
return ret; | {
"code": [],
"line_no": []
} | static int FUNC_0(BlockDriverState *VAR_0,
int64_t VAR_1, int VAR_2, int VAR_3)
{
BDRVQcowState *s = VAR_0->opaque;
size_t size;
int VAR_4;
if (cache_refcount_updates) {
VAR_2 &= ~(REFCOUNTS_PER_SECTOR - 1);
VAR_3 = (VAR_3 + REFCOUNTS_PER_SECTOR)
& ~(REFCOUNTS_PER_SECTOR - 1);
size = (VAR_3 - VAR_2) << REFCOUNT_SHIFT;
BLKDBG_EVENT(VAR_0->file, BLKDBG_REFBLOCK_UPDATE_PART);
VAR_4 = bdrv_pwrite(VAR_0->file,
VAR_1 + (VAR_2 << REFCOUNT_SHIFT),
&s->refcount_block_cache[VAR_2], size);
if (VAR_4 < 0) {
return VAR_4; | [
"static int FUNC_0(BlockDriverState *VAR_0,\nint64_t VAR_1, int VAR_2, int VAR_3)\n{",
"BDRVQcowState *s = VAR_0->opaque;",
"size_t size;",
"int VAR_4;",
"if (cache_refcount_updates) {",
"VAR_2 &= ~(REFCOUNTS_PER_SECTOR - 1);",
"VAR_3 = (VAR_3 + REFCOUNTS_PER_SECTOR)\n& ~(REFCOUNTS_PER_SECTOR - 1);",
"size = (VAR_3 - VAR_2) << REFCOUNT_SHIFT;",
"BLKDBG_EVENT(VAR_0->file, BLKDBG_REFBLOCK_UPDATE_PART);",
"VAR_4 = bdrv_pwrite(VAR_0->file,\nVAR_1 + (VAR_2 << REFCOUNT_SHIFT),\n&s->refcount_block_cache[VAR_2], size);",
"if (VAR_4 < 0) {",
"return VAR_4;"
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | [
[
1,
2,
3
],
[
4
],
[
5
],
[
6
],
[
7
],
[
8
],
[
9,
10
],
[
11
],
[
12
],
[
13,
14,
15
],
[
16
],
[
17
]
] |
21,378 | static int qemu_rdma_source_init(RDMAContext *rdma, Error **errp, bool pin_all)
{
int ret, idx;
Error *local_err = NULL, **temp = &local_err;
/*
* Will be validated against destination's actual capabilities
* after the connect() completes.
*/
rdma->pin_all = pin_all;
ret = qemu_rdma_resolve_host(rdma, temp);
if (ret) {
goto err_rdma_source_init;
}
ret = qemu_rdma_alloc_pd_cq(rdma);
if (ret) {
ERROR(temp, "rdma migration: error allocating pd and cq! Your mlock()"
" limits may be too low. Please check $ ulimit -a # and "
"search for 'ulimit -l' in the output");
goto err_rdma_source_init;
}
ret = qemu_rdma_alloc_qp(rdma);
if (ret) {
ERROR(temp, "rdma migration: error allocating qp!");
goto err_rdma_source_init;
}
ret = qemu_rdma_init_ram_blocks(rdma);
if (ret) {
ERROR(temp, "rdma migration: error initializing ram blocks!");
goto err_rdma_source_init;
}
for (idx = 0; idx < RDMA_WRID_MAX; idx++) {
ret = qemu_rdma_reg_control(rdma, idx);
if (ret) {
ERROR(temp, "rdma migration: error registering %d control!",
idx);
goto err_rdma_source_init;
}
}
return 0;
err_rdma_source_init:
error_propagate(errp, local_err);
qemu_rdma_cleanup(rdma);
return -1;
}
| true | qemu | 60fe637bf0e4d7989e21e50f52526444765c63b4 | static int qemu_rdma_source_init(RDMAContext *rdma, Error **errp, bool pin_all)
{
int ret, idx;
Error *local_err = NULL, **temp = &local_err;
rdma->pin_all = pin_all;
ret = qemu_rdma_resolve_host(rdma, temp);
if (ret) {
goto err_rdma_source_init;
}
ret = qemu_rdma_alloc_pd_cq(rdma);
if (ret) {
ERROR(temp, "rdma migration: error allocating pd and cq! Your mlock()"
" limits may be too low. Please check $ ulimit -a # and "
"search for 'ulimit -l' in the output");
goto err_rdma_source_init;
}
ret = qemu_rdma_alloc_qp(rdma);
if (ret) {
ERROR(temp, "rdma migration: error allocating qp!");
goto err_rdma_source_init;
}
ret = qemu_rdma_init_ram_blocks(rdma);
if (ret) {
ERROR(temp, "rdma migration: error initializing ram blocks!");
goto err_rdma_source_init;
}
for (idx = 0; idx < RDMA_WRID_MAX; idx++) {
ret = qemu_rdma_reg_control(rdma, idx);
if (ret) {
ERROR(temp, "rdma migration: error registering %d control!",
idx);
goto err_rdma_source_init;
}
}
return 0;
err_rdma_source_init:
error_propagate(errp, local_err);
qemu_rdma_cleanup(rdma);
return -1;
}
| {
"code": [],
"line_no": []
} | static int FUNC_0(RDMAContext *VAR_0, Error **VAR_1, bool VAR_2)
{
int VAR_3, VAR_4;
Error *local_err = NULL, **temp = &local_err;
VAR_0->VAR_2 = VAR_2;
VAR_3 = qemu_rdma_resolve_host(VAR_0, temp);
if (VAR_3) {
goto err_rdma_source_init;
}
VAR_3 = qemu_rdma_alloc_pd_cq(VAR_0);
if (VAR_3) {
ERROR(temp, "VAR_0 migration: error allocating pd and cq! Your mlock()"
" limits may be too low. Please check $ ulimit -a # and "
"search for 'ulimit -l' in the output");
goto err_rdma_source_init;
}
VAR_3 = qemu_rdma_alloc_qp(VAR_0);
if (VAR_3) {
ERROR(temp, "VAR_0 migration: error allocating qp!");
goto err_rdma_source_init;
}
VAR_3 = qemu_rdma_init_ram_blocks(VAR_0);
if (VAR_3) {
ERROR(temp, "VAR_0 migration: error initializing ram blocks!");
goto err_rdma_source_init;
}
for (VAR_4 = 0; VAR_4 < RDMA_WRID_MAX; VAR_4++) {
VAR_3 = qemu_rdma_reg_control(VAR_0, VAR_4);
if (VAR_3) {
ERROR(temp, "VAR_0 migration: error registering %d control!",
VAR_4);
goto err_rdma_source_init;
}
}
return 0;
err_rdma_source_init:
error_propagate(VAR_1, local_err);
qemu_rdma_cleanup(VAR_0);
return -1;
}
| [
"static int FUNC_0(RDMAContext *VAR_0, Error **VAR_1, bool VAR_2)\n{",
"int VAR_3, VAR_4;",
"Error *local_err = NULL, **temp = &local_err;",
"VAR_0->VAR_2 = VAR_2;",
"VAR_3 = qemu_rdma_resolve_host(VAR_0, temp);",
"if (VAR_3) {",
"goto err_rdma_source_init;",
"}",
"VAR_3 = qemu_rdma_alloc_pd_cq(VAR_0);",
"if (VAR_3) {",
"ERROR(temp, \"VAR_0 migration: error allocating pd and cq! Your mlock()\"\n\" limits may be too low. Please check $ ulimit -a # and \"\n\"search for 'ulimit -l' in the output\");",
"goto err_rdma_source_init;",
"}",
"VAR_3 = qemu_rdma_alloc_qp(VAR_0);",
"if (VAR_3) {",
"ERROR(temp, \"VAR_0 migration: error allocating qp!\");",
"goto err_rdma_source_init;",
"}",
"VAR_3 = qemu_rdma_init_ram_blocks(VAR_0);",
"if (VAR_3) {",
"ERROR(temp, \"VAR_0 migration: error initializing ram blocks!\");",
"goto err_rdma_source_init;",
"}",
"for (VAR_4 = 0; VAR_4 < RDMA_WRID_MAX; VAR_4++) {",
"VAR_3 = qemu_rdma_reg_control(VAR_0, VAR_4);",
"if (VAR_3) {",
"ERROR(temp, \"VAR_0 migration: error registering %d control!\",\nVAR_4);",
"goto err_rdma_source_init;",
"}",
"}",
"return 0;",
"err_rdma_source_init:\nerror_propagate(VAR_1, local_err);",
"qemu_rdma_cleanup(VAR_0);",
"return -1;",
"}"
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | [
[
1,
3
],
[
5
],
[
7
],
[
19
],
[
23
],
[
25
],
[
27
],
[
29
],
[
33
],
[
35
],
[
37,
39,
41
],
[
43
],
[
45
],
[
49
],
[
51
],
[
53
],
[
55
],
[
57
],
[
61
],
[
63
],
[
65
],
[
67
],
[
69
],
[
73
],
[
75
],
[
77
],
[
79,
81
],
[
83
],
[
85
],
[
87
],
[
91
],
[
95,
97
],
[
99
],
[
101
],
[
103
]
] |
21,379 | static int curl_open(BlockDriverState *bs, QDict *options, int flags,
Error **errp)
{
BDRVCURLState *s = bs->opaque;
CURLState *state = NULL;
QemuOpts *opts;
Error *local_err = NULL;
const char *file;
double d;
static int inited = 0;
if (flags & BDRV_O_RDWR) {
error_setg(errp, "curl block device does not support writes");
return -EROFS;
}
opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort);
qemu_opts_absorb_qdict(opts, options, &local_err);
if (local_err) {
error_propagate(errp, local_err);
goto out_noclean;
}
s->readahead_size = qemu_opt_get_size(opts, CURL_BLOCK_OPT_READAHEAD,
READ_AHEAD_DEFAULT);
if ((s->readahead_size & 0x1ff) != 0) {
error_setg(errp, "HTTP_READAHEAD_SIZE %zd is not a multiple of 512",
s->readahead_size);
goto out_noclean;
}
file = qemu_opt_get(opts, CURL_BLOCK_OPT_URL);
if (file == NULL) {
error_setg(errp, "curl block driver requires an 'url' option");
goto out_noclean;
}
if (!inited) {
curl_global_init(CURL_GLOBAL_ALL);
inited = 1;
}
DPRINTF("CURL: Opening %s\n", file);
s->url = g_strdup(file);
state = curl_init_state(s);
if (!state)
goto out_noclean;
// Get file size
s->accept_range = false;
curl_easy_setopt(state->curl, CURLOPT_NOBODY, 1);
curl_easy_setopt(state->curl, CURLOPT_HEADERFUNCTION,
curl_header_cb);
curl_easy_setopt(state->curl, CURLOPT_HEADERDATA, s);
if (curl_easy_perform(state->curl))
goto out;
curl_easy_getinfo(state->curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &d);
if (d)
s->len = (size_t)d;
else if(!s->len)
goto out;
if ((!strncasecmp(s->url, "http://", strlen("http://"))
|| !strncasecmp(s->url, "https://", strlen("https://")))
&& !s->accept_range) {
pstrcpy(state->errmsg, CURL_ERROR_SIZE,
"Server does not support 'range' (byte ranges).");
goto out;
}
DPRINTF("CURL: Size = %zd\n", s->len);
curl_clean_state(state);
curl_easy_cleanup(state->curl);
state->curl = NULL;
aio_timer_init(bdrv_get_aio_context(bs), &s->timer,
QEMU_CLOCK_REALTIME, SCALE_NS,
curl_multi_timeout_do, s);
// Now we know the file exists and its size, so let's
// initialize the multi interface!
s->multi = curl_multi_init();
curl_multi_setopt(s->multi, CURLMOPT_SOCKETFUNCTION, curl_sock_cb);
#ifdef NEED_CURL_TIMER_CALLBACK
curl_multi_setopt(s->multi, CURLMOPT_TIMERDATA, s);
curl_multi_setopt(s->multi, CURLMOPT_TIMERFUNCTION, curl_timer_cb);
#endif
qemu_opts_del(opts);
return 0;
out:
error_setg(errp, "CURL: Error opening file: %s", state->errmsg);
curl_easy_cleanup(state->curl);
state->curl = NULL;
out_noclean:
g_free(s->url);
qemu_opts_del(opts);
return -EINVAL;
} | true | qemu | 97a3ea57198b39b8366cd2a7514707abdcd0a7bc | static int curl_open(BlockDriverState *bs, QDict *options, int flags,
Error **errp)
{
BDRVCURLState *s = bs->opaque;
CURLState *state = NULL;
QemuOpts *opts;
Error *local_err = NULL;
const char *file;
double d;
static int inited = 0;
if (flags & BDRV_O_RDWR) {
error_setg(errp, "curl block device does not support writes");
return -EROFS;
}
opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort);
qemu_opts_absorb_qdict(opts, options, &local_err);
if (local_err) {
error_propagate(errp, local_err);
goto out_noclean;
}
s->readahead_size = qemu_opt_get_size(opts, CURL_BLOCK_OPT_READAHEAD,
READ_AHEAD_DEFAULT);
if ((s->readahead_size & 0x1ff) != 0) {
error_setg(errp, "HTTP_READAHEAD_SIZE %zd is not a multiple of 512",
s->readahead_size);
goto out_noclean;
}
file = qemu_opt_get(opts, CURL_BLOCK_OPT_URL);
if (file == NULL) {
error_setg(errp, "curl block driver requires an 'url' option");
goto out_noclean;
}
if (!inited) {
curl_global_init(CURL_GLOBAL_ALL);
inited = 1;
}
DPRINTF("CURL: Opening %s\n", file);
s->url = g_strdup(file);
state = curl_init_state(s);
if (!state)
goto out_noclean;
s->accept_range = false;
curl_easy_setopt(state->curl, CURLOPT_NOBODY, 1);
curl_easy_setopt(state->curl, CURLOPT_HEADERFUNCTION,
curl_header_cb);
curl_easy_setopt(state->curl, CURLOPT_HEADERDATA, s);
if (curl_easy_perform(state->curl))
goto out;
curl_easy_getinfo(state->curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &d);
if (d)
s->len = (size_t)d;
else if(!s->len)
goto out;
if ((!strncasecmp(s->url, "http:
|| !strncasecmp(s->url, "https:
&& !s->accept_range) {
pstrcpy(state->errmsg, CURL_ERROR_SIZE,
"Server does not support 'range' (byte ranges).");
goto out;
}
DPRINTF("CURL: Size = %zd\n", s->len);
curl_clean_state(state);
curl_easy_cleanup(state->curl);
state->curl = NULL;
aio_timer_init(bdrv_get_aio_context(bs), &s->timer,
QEMU_CLOCK_REALTIME, SCALE_NS,
curl_multi_timeout_do, s);
s->multi = curl_multi_init();
curl_multi_setopt(s->multi, CURLMOPT_SOCKETFUNCTION, curl_sock_cb);
#ifdef NEED_CURL_TIMER_CALLBACK
curl_multi_setopt(s->multi, CURLMOPT_TIMERDATA, s);
curl_multi_setopt(s->multi, CURLMOPT_TIMERFUNCTION, curl_timer_cb);
#endif
qemu_opts_del(opts);
return 0;
out:
error_setg(errp, "CURL: Error opening file: %s", state->errmsg);
curl_easy_cleanup(state->curl);
state->curl = NULL;
out_noclean:
g_free(s->url);
qemu_opts_del(opts);
return -EINVAL;
} | {
"code": [],
"line_no": []
} | static int FUNC_0(BlockDriverState *VAR_0, QDict *VAR_1, int VAR_2,
Error **VAR_3)
{
BDRVCURLState *s = VAR_0->opaque;
CURLState *state = NULL;
QemuOpts *opts;
Error *local_err = NULL;
const char *VAR_4;
double VAR_5;
static int VAR_6 = 0;
if (VAR_2 & BDRV_O_RDWR) {
error_setg(VAR_3, "curl block device does not support writes");
return -EROFS;
}
opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort);
qemu_opts_absorb_qdict(opts, VAR_1, &local_err);
if (local_err) {
error_propagate(VAR_3, local_err);
goto out_noclean;
}
s->readahead_size = qemu_opt_get_size(opts, CURL_BLOCK_OPT_READAHEAD,
READ_AHEAD_DEFAULT);
if ((s->readahead_size & 0x1ff) != 0) {
error_setg(VAR_3, "HTTP_READAHEAD_SIZE %zd is not a multiple of 512",
s->readahead_size);
goto out_noclean;
}
VAR_4 = qemu_opt_get(opts, CURL_BLOCK_OPT_URL);
if (VAR_4 == NULL) {
error_setg(VAR_3, "curl block driver requires an 'url' option");
goto out_noclean;
}
if (!VAR_6) {
curl_global_init(CURL_GLOBAL_ALL);
VAR_6 = 1;
}
DPRINTF("CURL: Opening %s\n", VAR_4);
s->url = g_strdup(VAR_4);
state = curl_init_state(s);
if (!state)
goto out_noclean;
s->accept_range = false;
curl_easy_setopt(state->curl, CURLOPT_NOBODY, 1);
curl_easy_setopt(state->curl, CURLOPT_HEADERFUNCTION,
curl_header_cb);
curl_easy_setopt(state->curl, CURLOPT_HEADERDATA, s);
if (curl_easy_perform(state->curl))
goto out;
curl_easy_getinfo(state->curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &VAR_5);
if (VAR_5)
s->len = (size_t)VAR_5;
else if(!s->len)
goto out;
if ((!strncasecmp(s->url, "http:
|| !strncasecmp(s->url, "https:
&& !s->accept_range) {
pstrcpy(state->errmsg, CURL_ERROR_SIZE,
"Server does not support 'range' (byte ranges).");
goto out;
}
DPRINTF("CURL: Size = %zd\n", s->len);
curl_clean_state(state);
curl_easy_cleanup(state->curl);
state->curl = NULL;
aio_timer_init(bdrv_get_aio_context(VAR_0), &s->timer,
QEMU_CLOCK_REALTIME, SCALE_NS,
curl_multi_timeout_do, s);
s->multi = curl_multi_init();
curl_multi_setopt(s->multi, CURLMOPT_SOCKETFUNCTION, curl_sock_cb);
#ifdef NEED_CURL_TIMER_CALLBACK
curl_multi_setopt(s->multi, CURLMOPT_TIMERDATA, s);
curl_multi_setopt(s->multi, CURLMOPT_TIMERFUNCTION, curl_timer_cb);
#endif
qemu_opts_del(opts);
return 0;
out:
error_setg(VAR_3, "CURL: Error opening VAR_4: %s", state->errmsg);
curl_easy_cleanup(state->curl);
state->curl = NULL;
out_noclean:
g_free(s->url);
qemu_opts_del(opts);
return -EINVAL;
} | [
"static int FUNC_0(BlockDriverState *VAR_0, QDict *VAR_1, int VAR_2,\nError **VAR_3)\n{",
"BDRVCURLState *s = VAR_0->opaque;",
"CURLState *state = NULL;",
"QemuOpts *opts;",
"Error *local_err = NULL;",
"const char *VAR_4;",
"double VAR_5;",
"static int VAR_6 = 0;",
"if (VAR_2 & BDRV_O_RDWR) {",
"error_setg(VAR_3, \"curl block device does not support writes\");",
"return -EROFS;",
"}",
"opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort);",
"qemu_opts_absorb_qdict(opts, VAR_1, &local_err);",
"if (local_err) {",
"error_propagate(VAR_3, local_err);",
"goto out_noclean;",
"}",
"s->readahead_size = qemu_opt_get_size(opts, CURL_BLOCK_OPT_READAHEAD,\nREAD_AHEAD_DEFAULT);",
"if ((s->readahead_size & 0x1ff) != 0) {",
"error_setg(VAR_3, \"HTTP_READAHEAD_SIZE %zd is not a multiple of 512\",\ns->readahead_size);",
"goto out_noclean;",
"}",
"VAR_4 = qemu_opt_get(opts, CURL_BLOCK_OPT_URL);",
"if (VAR_4 == NULL) {",
"error_setg(VAR_3, \"curl block driver requires an 'url' option\");",
"goto out_noclean;",
"}",
"if (!VAR_6) {",
"curl_global_init(CURL_GLOBAL_ALL);",
"VAR_6 = 1;",
"}",
"DPRINTF(\"CURL: Opening %s\\n\", VAR_4);",
"s->url = g_strdup(VAR_4);",
"state = curl_init_state(s);",
"if (!state)\ngoto out_noclean;",
"s->accept_range = false;",
"curl_easy_setopt(state->curl, CURLOPT_NOBODY, 1);",
"curl_easy_setopt(state->curl, CURLOPT_HEADERFUNCTION,\ncurl_header_cb);",
"curl_easy_setopt(state->curl, CURLOPT_HEADERDATA, s);",
"if (curl_easy_perform(state->curl))\ngoto out;",
"curl_easy_getinfo(state->curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &VAR_5);",
"if (VAR_5)\ns->len = (size_t)VAR_5;",
"else if(!s->len)\ngoto out;",
"if ((!strncasecmp(s->url, \"http:\n|| !strncasecmp(s->url, \"https:\n&& !s->accept_range) {",
"pstrcpy(state->errmsg, CURL_ERROR_SIZE,\n\"Server does not support 'range' (byte ranges).\");",
"goto out;",
"}",
"DPRINTF(\"CURL: Size = %zd\\n\", s->len);",
"curl_clean_state(state);",
"curl_easy_cleanup(state->curl);",
"state->curl = NULL;",
"aio_timer_init(bdrv_get_aio_context(VAR_0), &s->timer,\nQEMU_CLOCK_REALTIME, SCALE_NS,\ncurl_multi_timeout_do, s);",
"s->multi = curl_multi_init();",
"curl_multi_setopt(s->multi, CURLMOPT_SOCKETFUNCTION, curl_sock_cb);",
"#ifdef NEED_CURL_TIMER_CALLBACK\ncurl_multi_setopt(s->multi, CURLMOPT_TIMERDATA, s);",
"curl_multi_setopt(s->multi, CURLMOPT_TIMERFUNCTION, curl_timer_cb);",
"#endif\nqemu_opts_del(opts);",
"return 0;",
"out:\nerror_setg(VAR_3, \"CURL: Error opening VAR_4: %s\", state->errmsg);",
"curl_easy_cleanup(state->curl);",
"state->curl = NULL;",
"out_noclean:\ng_free(s->url);",
"qemu_opts_del(opts);",
"return -EINVAL;",
"}"
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | [
[
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
],
[
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
],
[
71
],
[
72
],
[
73,
74
],
[
75
],
[
76,
77
],
[
78
],
[
79,
80
],
[
81
],
[
82
],
[
83,
84
],
[
85
],
[
86
],
[
87
]
] |
21,380 | static int compute_pkt_fields2(AVFormatContext *s, AVStream *st, AVPacket *pkt)
{
int delay = FFMAX(st->codec->has_b_frames, st->codec->max_b_frames > 0);
int num, den, frame_size, i;
av_dlog(s, "compute_pkt_fields2: pts:%s dts:%s cur_dts:%s b:%d size:%d st:%d\n",
av_ts2str(pkt->pts), av_ts2str(pkt->dts), av_ts2str(st->cur_dts), delay, pkt->size, pkt->stream_index);
/* duration field */
if (pkt->duration == 0) {
ff_compute_frame_duration(&num, &den, st, NULL, pkt);
if (den && num) {
pkt->duration = av_rescale(1, num * (int64_t)st->time_base.den * st->codec->ticks_per_frame, den * (int64_t)st->time_base.num);
if (pkt->pts == AV_NOPTS_VALUE && pkt->dts != AV_NOPTS_VALUE && delay == 0)
pkt->pts = pkt->dts;
//XXX/FIXME this is a temporary hack until all encoders output pts
if ((pkt->pts == 0 || pkt->pts == AV_NOPTS_VALUE) && pkt->dts == AV_NOPTS_VALUE && !delay) {
static int warned;
if (!warned) {
av_log(s, AV_LOG_WARNING, "Encoder did not produce proper pts, making some up.\n");
warned = 1;
pkt->dts =
// pkt->pts= st->cur_dts;
pkt->pts = st->pts.val;
//calculate dts from pts
if (pkt->pts != AV_NOPTS_VALUE && pkt->dts == AV_NOPTS_VALUE && delay <= MAX_REORDER_DELAY) {
st->pts_buffer[0] = pkt->pts;
for (i = 1; i < delay + 1 && st->pts_buffer[i] == AV_NOPTS_VALUE; i++)
st->pts_buffer[i] = pkt->pts + (i - delay - 1) * pkt->duration;
for (i = 0; i<delay && st->pts_buffer[i] > st->pts_buffer[i + 1]; i++)
FFSWAP(int64_t, st->pts_buffer[i], st->pts_buffer[i + 1]);
pkt->dts = st->pts_buffer[0];
if (st->cur_dts && st->cur_dts != AV_NOPTS_VALUE &&
((!(s->oformat->flags & AVFMT_TS_NONSTRICT) &&
st->cur_dts >= pkt->dts) || st->cur_dts > pkt->dts)) {
av_log(s, AV_LOG_ERROR,
"Application provided invalid, non monotonically increasing dts to muxer in stream %d: %s >= %s\n",
st->index, av_ts2str(st->cur_dts), av_ts2str(pkt->dts));
return AVERROR(EINVAL);
if (pkt->dts != AV_NOPTS_VALUE && pkt->pts != AV_NOPTS_VALUE && pkt->pts < pkt->dts) {
av_log(s, AV_LOG_ERROR, "pts (%s) < dts (%s) in stream %d\n",
av_ts2str(pkt->pts), av_ts2str(pkt->dts), st->index);
return AVERROR(EINVAL);
av_dlog(s, "av_write_frame: pts2:%s dts2:%s\n",
av_ts2str(pkt->pts), av_ts2str(pkt->dts));
st->cur_dts = pkt->dts;
st->pts.val = pkt->dts;
/* update pts */
switch (st->codec->codec_type) {
case AVMEDIA_TYPE_AUDIO:
frame_size = (pkt->flags & AV_PKT_FLAG_UNCODED_FRAME) ?
((AVFrame *)pkt->data)->nb_samples :
ff_get_audio_frame_size(st->codec, pkt->size, 1);
/* HACK/FIXME, we skip the initial 0 size packets as they are most
* likely equal to the encoder delay, but it would be better if we
* had the real timestamps from the encoder */
if (frame_size >= 0 && (pkt->size || st->pts.num != st->pts.den >> 1 || st->pts.val)) {
frac_add(&st->pts, (int64_t)st->time_base.den * frame_size);
break;
case AVMEDIA_TYPE_VIDEO:
frac_add(&st->pts, (int64_t)st->time_base.den * st->codec->time_base.num);
break;
default:
break;
return 0; | true | FFmpeg | dc6a17cf74a90e41d70ea1753cdb70c0a5b2ced8 | static int compute_pkt_fields2(AVFormatContext *s, AVStream *st, AVPacket *pkt)
{
int delay = FFMAX(st->codec->has_b_frames, st->codec->max_b_frames > 0);
int num, den, frame_size, i;
av_dlog(s, "compute_pkt_fields2: pts:%s dts:%s cur_dts:%s b:%d size:%d st:%d\n",
av_ts2str(pkt->pts), av_ts2str(pkt->dts), av_ts2str(st->cur_dts), delay, pkt->size, pkt->stream_index);
if (pkt->duration == 0) {
ff_compute_frame_duration(&num, &den, st, NULL, pkt);
if (den && num) {
pkt->duration = av_rescale(1, num * (int64_t)st->time_base.den * st->codec->ticks_per_frame, den * (int64_t)st->time_base.num);
if (pkt->pts == AV_NOPTS_VALUE && pkt->dts != AV_NOPTS_VALUE && delay == 0)
pkt->pts = pkt->dts;
if ((pkt->pts == 0 || pkt->pts == AV_NOPTS_VALUE) && pkt->dts == AV_NOPTS_VALUE && !delay) {
static int warned;
if (!warned) {
av_log(s, AV_LOG_WARNING, "Encoder did not produce proper pts, making some up.\n");
warned = 1;
pkt->dts =
pkt->pts = st->pts.val;
if (pkt->pts != AV_NOPTS_VALUE && pkt->dts == AV_NOPTS_VALUE && delay <= MAX_REORDER_DELAY) {
st->pts_buffer[0] = pkt->pts;
for (i = 1; i < delay + 1 && st->pts_buffer[i] == AV_NOPTS_VALUE; i++)
st->pts_buffer[i] = pkt->pts + (i - delay - 1) * pkt->duration;
for (i = 0; i<delay && st->pts_buffer[i] > st->pts_buffer[i + 1]; i++)
FFSWAP(int64_t, st->pts_buffer[i], st->pts_buffer[i + 1]);
pkt->dts = st->pts_buffer[0];
if (st->cur_dts && st->cur_dts != AV_NOPTS_VALUE &&
((!(s->oformat->flags & AVFMT_TS_NONSTRICT) &&
st->cur_dts >= pkt->dts) || st->cur_dts > pkt->dts)) {
av_log(s, AV_LOG_ERROR,
"Application provided invalid, non monotonically increasing dts to muxer in stream %d: %s >= %s\n",
st->index, av_ts2str(st->cur_dts), av_ts2str(pkt->dts));
return AVERROR(EINVAL);
if (pkt->dts != AV_NOPTS_VALUE && pkt->pts != AV_NOPTS_VALUE && pkt->pts < pkt->dts) {
av_log(s, AV_LOG_ERROR, "pts (%s) < dts (%s) in stream %d\n",
av_ts2str(pkt->pts), av_ts2str(pkt->dts), st->index);
return AVERROR(EINVAL);
av_dlog(s, "av_write_frame: pts2:%s dts2:%s\n",
av_ts2str(pkt->pts), av_ts2str(pkt->dts));
st->cur_dts = pkt->dts;
st->pts.val = pkt->dts;
switch (st->codec->codec_type) {
case AVMEDIA_TYPE_AUDIO:
frame_size = (pkt->flags & AV_PKT_FLAG_UNCODED_FRAME) ?
((AVFrame *)pkt->data)->nb_samples :
ff_get_audio_frame_size(st->codec, pkt->size, 1);
if (frame_size >= 0 && (pkt->size || st->pts.num != st->pts.den >> 1 || st->pts.val)) {
frac_add(&st->pts, (int64_t)st->time_base.den * frame_size);
break;
case AVMEDIA_TYPE_VIDEO:
frac_add(&st->pts, (int64_t)st->time_base.den * st->codec->time_base.num);
break;
default:
break;
return 0; | {
"code": [],
"line_no": []
} | static int FUNC_0(AVFormatContext *VAR_0, AVStream *VAR_1, AVPacket *VAR_2)
{
int VAR_3 = FFMAX(VAR_1->codec->has_b_frames, VAR_1->codec->max_b_frames > 0);
int VAR_4, VAR_5, VAR_6, VAR_7;
av_dlog(VAR_0, "FUNC_0: pts:%VAR_0 dts:%VAR_0 cur_dts:%VAR_0 b:%d size:%d VAR_1:%d\n",
av_ts2str(VAR_2->pts), av_ts2str(VAR_2->dts), av_ts2str(VAR_1->cur_dts), VAR_3, VAR_2->size, VAR_2->stream_index);
if (VAR_2->duration == 0) {
ff_compute_frame_duration(&VAR_4, &VAR_5, VAR_1, NULL, VAR_2);
if (VAR_5 && VAR_4) {
VAR_2->duration = av_rescale(1, VAR_4 * (int64_t)VAR_1->time_base.VAR_5 * VAR_1->codec->ticks_per_frame, VAR_5 * (int64_t)VAR_1->time_base.VAR_4);
if (VAR_2->pts == AV_NOPTS_VALUE && VAR_2->dts != AV_NOPTS_VALUE && VAR_3 == 0)
VAR_2->pts = VAR_2->dts;
if ((VAR_2->pts == 0 || VAR_2->pts == AV_NOPTS_VALUE) && VAR_2->dts == AV_NOPTS_VALUE && !VAR_3) {
static int VAR_8;
if (!VAR_8) {
av_log(VAR_0, AV_LOG_WARNING, "Encoder did not produce proper pts, making some up.\n");
VAR_8 = 1;
VAR_2->dts =
VAR_2->pts = VAR_1->pts.val;
if (VAR_2->pts != AV_NOPTS_VALUE && VAR_2->dts == AV_NOPTS_VALUE && VAR_3 <= MAX_REORDER_DELAY) {
VAR_1->pts_buffer[0] = VAR_2->pts;
for (VAR_7 = 1; VAR_7 < VAR_3 + 1 && VAR_1->pts_buffer[VAR_7] == AV_NOPTS_VALUE; VAR_7++)
VAR_1->pts_buffer[VAR_7] = VAR_2->pts + (VAR_7 - VAR_3 - 1) * VAR_2->duration;
for (VAR_7 = 0; VAR_7<VAR_3 && VAR_1->pts_buffer[VAR_7] > VAR_1->pts_buffer[VAR_7 + 1]; VAR_7++)
FFSWAP(int64_t, VAR_1->pts_buffer[VAR_7], VAR_1->pts_buffer[VAR_7 + 1]);
VAR_2->dts = VAR_1->pts_buffer[0];
if (VAR_1->cur_dts && VAR_1->cur_dts != AV_NOPTS_VALUE &&
((!(VAR_0->oformat->flags & AVFMT_TS_NONSTRICT) &&
VAR_1->cur_dts >= VAR_2->dts) || VAR_1->cur_dts > VAR_2->dts)) {
av_log(VAR_0, AV_LOG_ERROR,
"Application provided invalid, non monotonically increasing dts to muxer in stream %d: %VAR_0 >= %VAR_0\n",
VAR_1->index, av_ts2str(VAR_1->cur_dts), av_ts2str(VAR_2->dts));
return AVERROR(EINVAL);
if (VAR_2->dts != AV_NOPTS_VALUE && VAR_2->pts != AV_NOPTS_VALUE && VAR_2->pts < VAR_2->dts) {
av_log(VAR_0, AV_LOG_ERROR, "pts (%VAR_0) < dts (%VAR_0) in stream %d\n",
av_ts2str(VAR_2->pts), av_ts2str(VAR_2->dts), VAR_1->index);
return AVERROR(EINVAL);
av_dlog(VAR_0, "av_write_frame: pts2:%VAR_0 dts2:%VAR_0\n",
av_ts2str(VAR_2->pts), av_ts2str(VAR_2->dts));
VAR_1->cur_dts = VAR_2->dts;
VAR_1->pts.val = VAR_2->dts;
switch (VAR_1->codec->codec_type) {
case AVMEDIA_TYPE_AUDIO:
VAR_6 = (VAR_2->flags & AV_PKT_FLAG_UNCODED_FRAME) ?
((AVFrame *)VAR_2->data)->nb_samples :
ff_get_audio_frame_size(VAR_1->codec, VAR_2->size, 1);
if (VAR_6 >= 0 && (VAR_2->size || VAR_1->pts.VAR_4 != VAR_1->pts.VAR_5 >> 1 || VAR_1->pts.val)) {
frac_add(&VAR_1->pts, (int64_t)VAR_1->time_base.VAR_5 * VAR_6);
break;
case AVMEDIA_TYPE_VIDEO:
frac_add(&VAR_1->pts, (int64_t)VAR_1->time_base.VAR_5 * VAR_1->codec->time_base.VAR_4);
break;
default:
break;
return 0; | [
"static int FUNC_0(AVFormatContext *VAR_0, AVStream *VAR_1, AVPacket *VAR_2)\n{",
"int VAR_3 = FFMAX(VAR_1->codec->has_b_frames, VAR_1->codec->max_b_frames > 0);",
"int VAR_4, VAR_5, VAR_6, VAR_7;",
"av_dlog(VAR_0, \"FUNC_0: pts:%VAR_0 dts:%VAR_0 cur_dts:%VAR_0 b:%d size:%d VAR_1:%d\\n\",\nav_ts2str(VAR_2->pts), av_ts2str(VAR_2->dts), av_ts2str(VAR_1->cur_dts), VAR_3, VAR_2->size, VAR_2->stream_index);",
"if (VAR_2->duration == 0) {",
"ff_compute_frame_duration(&VAR_4, &VAR_5, VAR_1, NULL, VAR_2);",
"if (VAR_5 && VAR_4) {",
"VAR_2->duration = av_rescale(1, VAR_4 * (int64_t)VAR_1->time_base.VAR_5 * VAR_1->codec->ticks_per_frame, VAR_5 * (int64_t)VAR_1->time_base.VAR_4);",
"if (VAR_2->pts == AV_NOPTS_VALUE && VAR_2->dts != AV_NOPTS_VALUE && VAR_3 == 0)\nVAR_2->pts = VAR_2->dts;",
"if ((VAR_2->pts == 0 || VAR_2->pts == AV_NOPTS_VALUE) && VAR_2->dts == AV_NOPTS_VALUE && !VAR_3) {",
"static int VAR_8;",
"if (!VAR_8) {",
"av_log(VAR_0, AV_LOG_WARNING, \"Encoder did not produce proper pts, making some up.\\n\");",
"VAR_8 = 1;",
"VAR_2->dts =\nVAR_2->pts = VAR_1->pts.val;",
"if (VAR_2->pts != AV_NOPTS_VALUE && VAR_2->dts == AV_NOPTS_VALUE && VAR_3 <= MAX_REORDER_DELAY) {",
"VAR_1->pts_buffer[0] = VAR_2->pts;",
"for (VAR_7 = 1; VAR_7 < VAR_3 + 1 && VAR_1->pts_buffer[VAR_7] == AV_NOPTS_VALUE; VAR_7++)",
"VAR_1->pts_buffer[VAR_7] = VAR_2->pts + (VAR_7 - VAR_3 - 1) * VAR_2->duration;",
"for (VAR_7 = 0; VAR_7<VAR_3 && VAR_1->pts_buffer[VAR_7] > VAR_1->pts_buffer[VAR_7 + 1]; VAR_7++)",
"FFSWAP(int64_t, VAR_1->pts_buffer[VAR_7], VAR_1->pts_buffer[VAR_7 + 1]);",
"VAR_2->dts = VAR_1->pts_buffer[0];",
"if (VAR_1->cur_dts && VAR_1->cur_dts != AV_NOPTS_VALUE &&\n((!(VAR_0->oformat->flags & AVFMT_TS_NONSTRICT) &&\nVAR_1->cur_dts >= VAR_2->dts) || VAR_1->cur_dts > VAR_2->dts)) {",
"av_log(VAR_0, AV_LOG_ERROR,\n\"Application provided invalid, non monotonically increasing dts to muxer in stream %d: %VAR_0 >= %VAR_0\\n\",\nVAR_1->index, av_ts2str(VAR_1->cur_dts), av_ts2str(VAR_2->dts));",
"return AVERROR(EINVAL);",
"if (VAR_2->dts != AV_NOPTS_VALUE && VAR_2->pts != AV_NOPTS_VALUE && VAR_2->pts < VAR_2->dts) {",
"av_log(VAR_0, AV_LOG_ERROR, \"pts (%VAR_0) < dts (%VAR_0) in stream %d\\n\",\nav_ts2str(VAR_2->pts), av_ts2str(VAR_2->dts), VAR_1->index);",
"return AVERROR(EINVAL);",
"av_dlog(VAR_0, \"av_write_frame: pts2:%VAR_0 dts2:%VAR_0\\n\",\nav_ts2str(VAR_2->pts), av_ts2str(VAR_2->dts));",
"VAR_1->cur_dts = VAR_2->dts;",
"VAR_1->pts.val = VAR_2->dts;",
"switch (VAR_1->codec->codec_type) {",
"case AVMEDIA_TYPE_AUDIO:\nVAR_6 = (VAR_2->flags & AV_PKT_FLAG_UNCODED_FRAME) ?\n((AVFrame *)VAR_2->data)->nb_samples :\nff_get_audio_frame_size(VAR_1->codec, VAR_2->size, 1);",
"if (VAR_6 >= 0 && (VAR_2->size || VAR_1->pts.VAR_4 != VAR_1->pts.VAR_5 >> 1 || VAR_1->pts.val)) {",
"frac_add(&VAR_1->pts, (int64_t)VAR_1->time_base.VAR_5 * VAR_6);",
"break;",
"case AVMEDIA_TYPE_VIDEO:\nfrac_add(&VAR_1->pts, (int64_t)VAR_1->time_base.VAR_5 * VAR_1->codec->time_base.VAR_4);",
"break;",
"default:\nbreak;",
"return 0;"
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | [
[
1,
2
],
[
3
],
[
4
],
[
5,
6
],
[
8
],
[
9
],
[
10
],
[
11
],
[
12,
13
],
[
15
],
[
16
],
[
17
],
[
18
],
[
19
],
[
20,
22
],
[
24
],
[
25
],
[
26
],
[
27
],
[
28
],
[
29
],
[
30
],
[
31,
32,
33
],
[
34,
35,
36
],
[
37
],
[
38
],
[
39,
40
],
[
41
],
[
42,
43
],
[
44
],
[
45
],
[
47
],
[
48,
49,
50,
51
],
[
55
],
[
56
],
[
57
],
[
58,
59
],
[
60
],
[
61,
62
],
[
63
]
] |
21,381 | int qemu_get_fd(QEMUFile *f)
{
if (f->ops->get_fd) {
return f->ops->get_fd(f->opaque);
}
return -1;
}
| true | qemu | 60fe637bf0e4d7989e21e50f52526444765c63b4 | int qemu_get_fd(QEMUFile *f)
{
if (f->ops->get_fd) {
return f->ops->get_fd(f->opaque);
}
return -1;
}
| {
"code": [],
"line_no": []
} | int FUNC_0(QEMUFile *VAR_0)
{
if (VAR_0->ops->get_fd) {
return VAR_0->ops->get_fd(VAR_0->opaque);
}
return -1;
}
| [
"int FUNC_0(QEMUFile *VAR_0)\n{",
"if (VAR_0->ops->get_fd) {",
"return VAR_0->ops->get_fd(VAR_0->opaque);",
"}",
"return -1;",
"}"
] | [
0,
0,
0,
0,
0,
0
] | [
[
1,
3
],
[
5
],
[
7
],
[
9
],
[
11
],
[
13
]
] |
21,382 | static int bdrv_open_common(BlockDriverState *bs, BlockDriverState *file,
QDict *options, int flags, BlockDriver *drv, Error **errp)
{
int ret, open_flags;
const char *filename;
const char *node_name = NULL;
Error *local_err = NULL;
assert(drv != NULL);
assert(bs->file == NULL);
assert(options != NULL && bs->options != options);
if (file != NULL) {
filename = file->filename;
} else {
filename = qdict_get_try_str(options, "filename");
if (drv->bdrv_needs_filename && !filename) {
error_setg(errp, "The '%s' block driver requires a file name",
drv->format_name);
return -EINVAL;
trace_bdrv_open_common(bs, filename ?: "", flags, drv->format_name);
node_name = qdict_get_try_str(options, "node-name");
bdrv_assign_node_name(bs, node_name, &local_err);
if (local_err) {
error_propagate(errp, local_err);
return -EINVAL;
qdict_del(options, "node-name");
/* bdrv_open() with directly using a protocol as drv. This layer is already
* opened, so assign it to bs (while file becomes a closed BlockDriverState)
* and return immediately. */
if (file != NULL && drv->bdrv_file_open) {
bdrv_swap(file, bs);
return 0;
bs->open_flags = flags;
bs->guest_block_size = 512;
bs->request_alignment = 512;
bs->zero_beyond_eof = true;
open_flags = bdrv_open_flags(bs, flags);
bs->read_only = !(open_flags & BDRV_O_RDWR);
if (use_bdrv_whitelist && !bdrv_is_whitelisted(drv, bs->read_only)) {
error_setg(errp,
!bs->read_only && bdrv_is_whitelisted(drv, true)
? "Driver '%s' can only be used for read-only devices"
: "Driver '%s' is not whitelisted",
drv->format_name);
return -ENOTSUP;
assert(bs->copy_on_read == 0); /* bdrv_new() and bdrv_close() make it so */
if (flags & BDRV_O_COPY_ON_READ) {
if (!bs->read_only) {
bdrv_enable_copy_on_read(bs);
} else {
error_setg(errp, "Can't use copy-on-read on read-only device");
return -EINVAL;
if (filename != NULL) {
pstrcpy(bs->filename, sizeof(bs->filename), filename);
} else {
bs->filename[0] = '\0';
pstrcpy(bs->exact_filename, sizeof(bs->exact_filename), bs->filename);
bs->drv = drv;
bs->opaque = g_malloc0(drv->instance_size);
bs->enable_write_cache = !!(flags & BDRV_O_CACHE_WB);
/* Open the image, either directly or using a protocol */
if (drv->bdrv_file_open) {
assert(file == NULL);
assert(!drv->bdrv_needs_filename || filename != NULL);
ret = drv->bdrv_file_open(bs, options, open_flags, &local_err);
} else {
if (file == NULL) {
error_setg(errp, "Can't use '%s' as a block driver for the "
"protocol level", drv->format_name);
ret = -EINVAL;
goto free_and_fail;
bs->file = file;
ret = drv->bdrv_open(bs, options, open_flags, &local_err);
if (ret < 0) {
if (local_err) {
error_propagate(errp, local_err);
} else if (bs->filename[0]) {
error_setg_errno(errp, -ret, "Could not open '%s'", bs->filename);
} else {
error_setg_errno(errp, -ret, "Could not open image");
goto free_and_fail;
ret = refresh_total_sectors(bs, bs->total_sectors);
if (ret < 0) {
error_setg_errno(errp, -ret, "Could not refresh total sector count");
goto free_and_fail;
bdrv_refresh_limits(bs, &local_err);
if (local_err) {
error_propagate(errp, local_err);
ret = -EINVAL;
goto free_and_fail;
assert(bdrv_opt_mem_align(bs) != 0);
assert((bs->request_alignment != 0) || bs->sg);
return 0;
free_and_fail:
bs->file = NULL;
g_free(bs->opaque);
bs->opaque = NULL;
bs->drv = NULL;
return ret; | true | qemu | a1f688f4152e65260b94f37543521ceff8bfebe4 | static int bdrv_open_common(BlockDriverState *bs, BlockDriverState *file,
QDict *options, int flags, BlockDriver *drv, Error **errp)
{
int ret, open_flags;
const char *filename;
const char *node_name = NULL;
Error *local_err = NULL;
assert(drv != NULL);
assert(bs->file == NULL);
assert(options != NULL && bs->options != options);
if (file != NULL) {
filename = file->filename;
} else {
filename = qdict_get_try_str(options, "filename");
if (drv->bdrv_needs_filename && !filename) {
error_setg(errp, "The '%s' block driver requires a file name",
drv->format_name);
return -EINVAL;
trace_bdrv_open_common(bs, filename ?: "", flags, drv->format_name);
node_name = qdict_get_try_str(options, "node-name");
bdrv_assign_node_name(bs, node_name, &local_err);
if (local_err) {
error_propagate(errp, local_err);
return -EINVAL;
qdict_del(options, "node-name");
if (file != NULL && drv->bdrv_file_open) {
bdrv_swap(file, bs);
return 0;
bs->open_flags = flags;
bs->guest_block_size = 512;
bs->request_alignment = 512;
bs->zero_beyond_eof = true;
open_flags = bdrv_open_flags(bs, flags);
bs->read_only = !(open_flags & BDRV_O_RDWR);
if (use_bdrv_whitelist && !bdrv_is_whitelisted(drv, bs->read_only)) {
error_setg(errp,
!bs->read_only && bdrv_is_whitelisted(drv, true)
? "Driver '%s' can only be used for read-only devices"
: "Driver '%s' is not whitelisted",
drv->format_name);
return -ENOTSUP;
assert(bs->copy_on_read == 0);
if (flags & BDRV_O_COPY_ON_READ) {
if (!bs->read_only) {
bdrv_enable_copy_on_read(bs);
} else {
error_setg(errp, "Can't use copy-on-read on read-only device");
return -EINVAL;
if (filename != NULL) {
pstrcpy(bs->filename, sizeof(bs->filename), filename);
} else {
bs->filename[0] = '\0';
pstrcpy(bs->exact_filename, sizeof(bs->exact_filename), bs->filename);
bs->drv = drv;
bs->opaque = g_malloc0(drv->instance_size);
bs->enable_write_cache = !!(flags & BDRV_O_CACHE_WB);
if (drv->bdrv_file_open) {
assert(file == NULL);
assert(!drv->bdrv_needs_filename || filename != NULL);
ret = drv->bdrv_file_open(bs, options, open_flags, &local_err);
} else {
if (file == NULL) {
error_setg(errp, "Can't use '%s' as a block driver for the "
"protocol level", drv->format_name);
ret = -EINVAL;
goto free_and_fail;
bs->file = file;
ret = drv->bdrv_open(bs, options, open_flags, &local_err);
if (ret < 0) {
if (local_err) {
error_propagate(errp, local_err);
} else if (bs->filename[0]) {
error_setg_errno(errp, -ret, "Could not open '%s'", bs->filename);
} else {
error_setg_errno(errp, -ret, "Could not open image");
goto free_and_fail;
ret = refresh_total_sectors(bs, bs->total_sectors);
if (ret < 0) {
error_setg_errno(errp, -ret, "Could not refresh total sector count");
goto free_and_fail;
bdrv_refresh_limits(bs, &local_err);
if (local_err) {
error_propagate(errp, local_err);
ret = -EINVAL;
goto free_and_fail;
assert(bdrv_opt_mem_align(bs) != 0);
assert((bs->request_alignment != 0) || bs->sg);
return 0;
free_and_fail:
bs->file = NULL;
g_free(bs->opaque);
bs->opaque = NULL;
bs->drv = NULL;
return ret; | {
"code": [],
"line_no": []
} | static int FUNC_0(BlockDriverState *VAR_0, BlockDriverState *VAR_1,
QDict *VAR_2, int VAR_3, BlockDriver *VAR_4, Error **VAR_5)
{
int VAR_6, VAR_7;
const char *VAR_8;
const char *VAR_9 = NULL;
Error *local_err = NULL;
assert(VAR_4 != NULL);
assert(VAR_0->VAR_1 == NULL);
assert(VAR_2 != NULL && VAR_0->VAR_2 != VAR_2);
if (VAR_1 != NULL) {
VAR_8 = VAR_1->VAR_8;
} else {
VAR_8 = qdict_get_try_str(VAR_2, "VAR_8");
if (VAR_4->bdrv_needs_filename && !VAR_8) {
error_setg(VAR_5, "The '%s' block driver requires a VAR_1 name",
VAR_4->format_name);
return -EINVAL;
trace_bdrv_open_common(VAR_0, VAR_8 ?: "", VAR_3, VAR_4->format_name);
VAR_9 = qdict_get_try_str(VAR_2, "node-name");
bdrv_assign_node_name(VAR_0, VAR_9, &local_err);
if (local_err) {
error_propagate(VAR_5, local_err);
return -EINVAL;
qdict_del(VAR_2, "node-name");
if (VAR_1 != NULL && VAR_4->bdrv_file_open) {
bdrv_swap(VAR_1, VAR_0);
return 0;
VAR_0->VAR_7 = VAR_3;
VAR_0->guest_block_size = 512;
VAR_0->request_alignment = 512;
VAR_0->zero_beyond_eof = true;
VAR_7 = bdrv_open_flags(VAR_0, VAR_3);
VAR_0->read_only = !(VAR_7 & BDRV_O_RDWR);
if (use_bdrv_whitelist && !bdrv_is_whitelisted(VAR_4, VAR_0->read_only)) {
error_setg(VAR_5,
!VAR_0->read_only && bdrv_is_whitelisted(VAR_4, true)
? "Driver '%s' can only be used for read-only devices"
: "Driver '%s' is not whitelisted",
VAR_4->format_name);
return -ENOTSUP;
assert(VAR_0->copy_on_read == 0);
if (VAR_3 & BDRV_O_COPY_ON_READ) {
if (!VAR_0->read_only) {
bdrv_enable_copy_on_read(VAR_0);
} else {
error_setg(VAR_5, "Can't use copy-on-read on read-only device");
return -EINVAL;
if (VAR_8 != NULL) {
pstrcpy(VAR_0->VAR_8, sizeof(VAR_0->VAR_8), VAR_8);
} else {
VAR_0->VAR_8[0] = '\0';
pstrcpy(VAR_0->exact_filename, sizeof(VAR_0->exact_filename), VAR_0->VAR_8);
VAR_0->VAR_4 = VAR_4;
VAR_0->opaque = g_malloc0(VAR_4->instance_size);
VAR_0->enable_write_cache = !!(VAR_3 & BDRV_O_CACHE_WB);
if (VAR_4->bdrv_file_open) {
assert(VAR_1 == NULL);
assert(!VAR_4->bdrv_needs_filename || VAR_8 != NULL);
VAR_6 = VAR_4->bdrv_file_open(VAR_0, VAR_2, VAR_7, &local_err);
} else {
if (VAR_1 == NULL) {
error_setg(VAR_5, "Can't use '%s' as a block driver for the "
"protocol level", VAR_4->format_name);
VAR_6 = -EINVAL;
goto free_and_fail;
VAR_0->VAR_1 = VAR_1;
VAR_6 = VAR_4->bdrv_open(VAR_0, VAR_2, VAR_7, &local_err);
if (VAR_6 < 0) {
if (local_err) {
error_propagate(VAR_5, local_err);
} else if (VAR_0->VAR_8[0]) {
error_setg_errno(VAR_5, -VAR_6, "Could not open '%s'", VAR_0->VAR_8);
} else {
error_setg_errno(VAR_5, -VAR_6, "Could not open image");
goto free_and_fail;
VAR_6 = refresh_total_sectors(VAR_0, VAR_0->total_sectors);
if (VAR_6 < 0) {
error_setg_errno(VAR_5, -VAR_6, "Could not refresh total sector count");
goto free_and_fail;
bdrv_refresh_limits(VAR_0, &local_err);
if (local_err) {
error_propagate(VAR_5, local_err);
VAR_6 = -EINVAL;
goto free_and_fail;
assert(bdrv_opt_mem_align(VAR_0) != 0);
assert((VAR_0->request_alignment != 0) || VAR_0->sg);
return 0;
free_and_fail:
VAR_0->VAR_1 = NULL;
g_free(VAR_0->opaque);
VAR_0->opaque = NULL;
VAR_0->VAR_4 = NULL;
return VAR_6; | [
"static int FUNC_0(BlockDriverState *VAR_0, BlockDriverState *VAR_1,\nQDict *VAR_2, int VAR_3, BlockDriver *VAR_4, Error **VAR_5)\n{",
"int VAR_6, VAR_7;",
"const char *VAR_8;",
"const char *VAR_9 = NULL;",
"Error *local_err = NULL;",
"assert(VAR_4 != NULL);",
"assert(VAR_0->VAR_1 == NULL);",
"assert(VAR_2 != NULL && VAR_0->VAR_2 != VAR_2);",
"if (VAR_1 != NULL) {",
"VAR_8 = VAR_1->VAR_8;",
"} else {",
"VAR_8 = qdict_get_try_str(VAR_2, \"VAR_8\");",
"if (VAR_4->bdrv_needs_filename && !VAR_8) {",
"error_setg(VAR_5, \"The '%s' block driver requires a VAR_1 name\",\nVAR_4->format_name);",
"return -EINVAL;",
"trace_bdrv_open_common(VAR_0, VAR_8 ?: \"\", VAR_3, VAR_4->format_name);",
"VAR_9 = qdict_get_try_str(VAR_2, \"node-name\");",
"bdrv_assign_node_name(VAR_0, VAR_9, &local_err);",
"if (local_err) {",
"error_propagate(VAR_5, local_err);",
"return -EINVAL;",
"qdict_del(VAR_2, \"node-name\");",
"if (VAR_1 != NULL && VAR_4->bdrv_file_open) {",
"bdrv_swap(VAR_1, VAR_0);",
"return 0;",
"VAR_0->VAR_7 = VAR_3;",
"VAR_0->guest_block_size = 512;",
"VAR_0->request_alignment = 512;",
"VAR_0->zero_beyond_eof = true;",
"VAR_7 = bdrv_open_flags(VAR_0, VAR_3);",
"VAR_0->read_only = !(VAR_7 & BDRV_O_RDWR);",
"if (use_bdrv_whitelist && !bdrv_is_whitelisted(VAR_4, VAR_0->read_only)) {",
"error_setg(VAR_5,\n!VAR_0->read_only && bdrv_is_whitelisted(VAR_4, true)\n? \"Driver '%s' can only be used for read-only devices\"\n: \"Driver '%s' is not whitelisted\",\nVAR_4->format_name);",
"return -ENOTSUP;",
"assert(VAR_0->copy_on_read == 0);",
"if (VAR_3 & BDRV_O_COPY_ON_READ) {",
"if (!VAR_0->read_only) {",
"bdrv_enable_copy_on_read(VAR_0);",
"} else {",
"error_setg(VAR_5, \"Can't use copy-on-read on read-only device\");",
"return -EINVAL;",
"if (VAR_8 != NULL) {",
"pstrcpy(VAR_0->VAR_8, sizeof(VAR_0->VAR_8), VAR_8);",
"} else {",
"VAR_0->VAR_8[0] = '\\0';",
"pstrcpy(VAR_0->exact_filename, sizeof(VAR_0->exact_filename), VAR_0->VAR_8);",
"VAR_0->VAR_4 = VAR_4;",
"VAR_0->opaque = g_malloc0(VAR_4->instance_size);",
"VAR_0->enable_write_cache = !!(VAR_3 & BDRV_O_CACHE_WB);",
"if (VAR_4->bdrv_file_open) {",
"assert(VAR_1 == NULL);",
"assert(!VAR_4->bdrv_needs_filename || VAR_8 != NULL);",
"VAR_6 = VAR_4->bdrv_file_open(VAR_0, VAR_2, VAR_7, &local_err);",
"} else {",
"if (VAR_1 == NULL) {",
"error_setg(VAR_5, \"Can't use '%s' as a block driver for the \"\n\"protocol level\", VAR_4->format_name);",
"VAR_6 = -EINVAL;",
"goto free_and_fail;",
"VAR_0->VAR_1 = VAR_1;",
"VAR_6 = VAR_4->bdrv_open(VAR_0, VAR_2, VAR_7, &local_err);",
"if (VAR_6 < 0) {",
"if (local_err) {",
"error_propagate(VAR_5, local_err);",
"} else if (VAR_0->VAR_8[0]) {",
"error_setg_errno(VAR_5, -VAR_6, \"Could not open '%s'\", VAR_0->VAR_8);",
"} else {",
"error_setg_errno(VAR_5, -VAR_6, \"Could not open image\");",
"goto free_and_fail;",
"VAR_6 = refresh_total_sectors(VAR_0, VAR_0->total_sectors);",
"if (VAR_6 < 0) {",
"error_setg_errno(VAR_5, -VAR_6, \"Could not refresh total sector count\");",
"goto free_and_fail;",
"bdrv_refresh_limits(VAR_0, &local_err);",
"if (local_err) {",
"error_propagate(VAR_5, local_err);",
"VAR_6 = -EINVAL;",
"goto free_and_fail;",
"assert(bdrv_opt_mem_align(VAR_0) != 0);",
"assert((VAR_0->request_alignment != 0) || VAR_0->sg);",
"return 0;",
"free_and_fail:\nVAR_0->VAR_1 = NULL;",
"g_free(VAR_0->opaque);",
"VAR_0->opaque = NULL;",
"VAR_0->VAR_4 = NULL;",
"return VAR_6;"
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | [
[
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
],
[
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
],
[
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
]
] |
21,384 | static int virtio_serial_load(QEMUFile *f, void *opaque, int version_id)
{
VirtIOSerial *s = opaque;
VirtIOSerialPort *port;
uint32_t max_nr_ports, nr_active_ports, ports_map;
unsigned int i;
if (version_id > 3) {
/* The virtio device */
virtio_load(&s->vdev, f);
if (version_id < 2) {
return 0;
/* The config space */
qemu_get_be16s(f, &s->config.cols);
qemu_get_be16s(f, &s->config.rows);
qemu_get_be32s(f, &max_nr_ports);
if (max_nr_ports > s->config.max_nr_ports) {
/* Source could have had more ports than us. Fail migration. */
for (i = 0; i < (max_nr_ports + 31) / 32; i++) {
qemu_get_be32s(f, &ports_map);
if (ports_map != s->ports_map[i]) {
/*
* Ports active on source and destination don't
* match. Fail migration.
*/
qemu_get_be32s(f, &nr_active_ports);
/* Items in struct VirtIOSerialPort */
for (i = 0; i < nr_active_ports; i++) {
uint32_t id;
bool host_connected;
id = qemu_get_be32(f);
port = find_port_by_id(s, id);
port->guest_connected = qemu_get_byte(f);
host_connected = qemu_get_byte(f);
if (host_connected != port->host_connected) {
/*
* We have to let the guest know of the host connection
* status change
*/
send_control_event(port, VIRTIO_CONSOLE_PORT_OPEN,
port->host_connected);
if (version_id > 2) {
uint32_t elem_popped;
qemu_get_be32s(f, &elem_popped);
if (elem_popped) {
qemu_get_be32s(f, &port->iov_idx);
qemu_get_be64s(f, &port->iov_offset);
qemu_get_buffer(f, (unsigned char *)&port->elem,
sizeof(port->elem));
virtqueue_map_sg(port->elem.in_sg, port->elem.in_addr,
port->elem.in_num, 1);
virtqueue_map_sg(port->elem.out_sg, port->elem.out_addr,
port->elem.out_num, 1);
/*
* Port was throttled on source machine. Let's
* unthrottle it here so data starts flowing again.
*/
virtio_serial_throttle_port(port, false);
return 0;
| true | qemu | fbe0c5591077814eead05217fc96f087b254a6a8 | static int virtio_serial_load(QEMUFile *f, void *opaque, int version_id)
{
VirtIOSerial *s = opaque;
VirtIOSerialPort *port;
uint32_t max_nr_ports, nr_active_ports, ports_map;
unsigned int i;
if (version_id > 3) {
virtio_load(&s->vdev, f);
if (version_id < 2) {
return 0;
qemu_get_be16s(f, &s->config.cols);
qemu_get_be16s(f, &s->config.rows);
qemu_get_be32s(f, &max_nr_ports);
if (max_nr_ports > s->config.max_nr_ports) {
for (i = 0; i < (max_nr_ports + 31) / 32; i++) {
qemu_get_be32s(f, &ports_map);
if (ports_map != s->ports_map[i]) {
qemu_get_be32s(f, &nr_active_ports);
for (i = 0; i < nr_active_ports; i++) {
uint32_t id;
bool host_connected;
id = qemu_get_be32(f);
port = find_port_by_id(s, id);
port->guest_connected = qemu_get_byte(f);
host_connected = qemu_get_byte(f);
if (host_connected != port->host_connected) {
send_control_event(port, VIRTIO_CONSOLE_PORT_OPEN,
port->host_connected);
if (version_id > 2) {
uint32_t elem_popped;
qemu_get_be32s(f, &elem_popped);
if (elem_popped) {
qemu_get_be32s(f, &port->iov_idx);
qemu_get_be64s(f, &port->iov_offset);
qemu_get_buffer(f, (unsigned char *)&port->elem,
sizeof(port->elem));
virtqueue_map_sg(port->elem.in_sg, port->elem.in_addr,
port->elem.in_num, 1);
virtqueue_map_sg(port->elem.out_sg, port->elem.out_addr,
port->elem.out_num, 1);
virtio_serial_throttle_port(port, false);
return 0;
| {
"code": [],
"line_no": []
} | static int FUNC_0(QEMUFile *VAR_0, void *VAR_1, int VAR_2)
{
VirtIOSerial *s = VAR_1;
VirtIOSerialPort *port;
uint32_t max_nr_ports, nr_active_ports, ports_map;
unsigned int VAR_3;
if (VAR_2 > 3) {
virtio_load(&s->vdev, VAR_0);
if (VAR_2 < 2) {
return 0;
qemu_get_be16s(VAR_0, &s->config.cols);
qemu_get_be16s(VAR_0, &s->config.rows);
qemu_get_be32s(VAR_0, &max_nr_ports);
if (max_nr_ports > s->config.max_nr_ports) {
for (VAR_3 = 0; VAR_3 < (max_nr_ports + 31) / 32; VAR_3++) {
qemu_get_be32s(VAR_0, &ports_map);
if (ports_map != s->ports_map[VAR_3]) {
qemu_get_be32s(VAR_0, &nr_active_ports);
for (VAR_3 = 0; VAR_3 < nr_active_ports; VAR_3++) {
uint32_t id;
bool host_connected;
id = qemu_get_be32(VAR_0);
port = find_port_by_id(s, id);
port->guest_connected = qemu_get_byte(VAR_0);
host_connected = qemu_get_byte(VAR_0);
if (host_connected != port->host_connected) {
send_control_event(port, VIRTIO_CONSOLE_PORT_OPEN,
port->host_connected);
if (VAR_2 > 2) {
uint32_t elem_popped;
qemu_get_be32s(VAR_0, &elem_popped);
if (elem_popped) {
qemu_get_be32s(VAR_0, &port->iov_idx);
qemu_get_be64s(VAR_0, &port->iov_offset);
qemu_get_buffer(VAR_0, (unsigned char *)&port->elem,
sizeof(port->elem));
virtqueue_map_sg(port->elem.in_sg, port->elem.in_addr,
port->elem.in_num, 1);
virtqueue_map_sg(port->elem.out_sg, port->elem.out_addr,
port->elem.out_num, 1);
virtio_serial_throttle_port(port, false);
return 0;
| [
"static int FUNC_0(QEMUFile *VAR_0, void *VAR_1, int VAR_2)\n{",
"VirtIOSerial *s = VAR_1;",
"VirtIOSerialPort *port;",
"uint32_t max_nr_ports, nr_active_ports, ports_map;",
"unsigned int VAR_3;",
"if (VAR_2 > 3) {",
"virtio_load(&s->vdev, VAR_0);",
"if (VAR_2 < 2) {",
"return 0;",
"qemu_get_be16s(VAR_0, &s->config.cols);",
"qemu_get_be16s(VAR_0, &s->config.rows);",
"qemu_get_be32s(VAR_0, &max_nr_ports);",
"if (max_nr_ports > s->config.max_nr_ports) {",
"for (VAR_3 = 0; VAR_3 < (max_nr_ports + 31) / 32; VAR_3++) {",
"qemu_get_be32s(VAR_0, &ports_map);",
"if (ports_map != s->ports_map[VAR_3]) {",
"qemu_get_be32s(VAR_0, &nr_active_ports);",
"for (VAR_3 = 0; VAR_3 < nr_active_ports; VAR_3++) {",
"uint32_t id;",
"bool host_connected;",
"id = qemu_get_be32(VAR_0);",
"port = find_port_by_id(s, id);",
"port->guest_connected = qemu_get_byte(VAR_0);",
"host_connected = qemu_get_byte(VAR_0);",
"if (host_connected != port->host_connected) {",
"send_control_event(port, VIRTIO_CONSOLE_PORT_OPEN,\nport->host_connected);",
"if (VAR_2 > 2) {",
"uint32_t elem_popped;",
"qemu_get_be32s(VAR_0, &elem_popped);",
"if (elem_popped) {",
"qemu_get_be32s(VAR_0, &port->iov_idx);",
"qemu_get_be64s(VAR_0, &port->iov_offset);",
"qemu_get_buffer(VAR_0, (unsigned char *)&port->elem,\nsizeof(port->elem));",
"virtqueue_map_sg(port->elem.in_sg, port->elem.in_addr,\nport->elem.in_num, 1);",
"virtqueue_map_sg(port->elem.out_sg, port->elem.out_addr,\nport->elem.out_num, 1);",
"virtio_serial_throttle_port(port, false);",
"return 0;"
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | [
[
1,
3
],
[
5
],
[
7
],
[
9
],
[
11
],
[
15
],
[
23
],
[
27
],
[
29
],
[
36
],
[
38
],
[
42
],
[
44
],
[
52
],
[
54
],
[
58
],
[
73
],
[
79
],
[
81
],
[
83
],
[
87
],
[
89
],
[
96
],
[
98
],
[
100
],
[
110,
112
],
[
117
],
[
119
],
[
123
],
[
125
],
[
127
],
[
129
],
[
133,
135
],
[
137,
139
],
[
141,
143
],
[
155
],
[
160
]
] |
21,388 | static int cdg_decode_frame(AVCodecContext *avctx,
void *data, int *got_frame, AVPacket *avpkt)
{
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
int ret;
uint8_t command, inst;
uint8_t cdg_data[CDG_DATA_SIZE];
AVFrame *frame = data;
CDGraphicsContext *cc = avctx->priv_data;
if (buf_size < CDG_MINIMUM_PKT_SIZE) {
av_log(avctx, AV_LOG_ERROR, "buffer too small for decoder\n");
return AVERROR(EINVAL);
}
if (buf_size > CDG_HEADER_SIZE + CDG_DATA_SIZE) {
av_log(avctx, AV_LOG_ERROR, "buffer too big for decoder\n");
return AVERROR(EINVAL);
}
if ((ret = ff_reget_buffer(avctx, cc->frame)) < 0)
return ret;
if (!avctx->frame_number) {
memset(cc->frame->data[0], 0, cc->frame->linesize[0] * avctx->height);
memset(cc->frame->data[1], 0, AVPALETTE_SIZE);
}
command = bytestream_get_byte(&buf);
inst = bytestream_get_byte(&buf);
inst &= CDG_MASK;
buf += 2; /// skipping 2 unneeded bytes
if (buf_size > CDG_HEADER_SIZE)
bytestream_get_buffer(&buf, cdg_data, buf_size - CDG_HEADER_SIZE);
if ((command & CDG_MASK) == CDG_COMMAND) {
switch (inst) {
case CDG_INST_MEMORY_PRESET:
if (!(cdg_data[1] & 0x0F))
memset(cc->frame->data[0], cdg_data[0] & 0x0F,
cc->frame->linesize[0] * CDG_FULL_HEIGHT);
break;
case CDG_INST_LOAD_PAL_LO:
case CDG_INST_LOAD_PAL_HIGH:
if (buf_size - CDG_HEADER_SIZE < CDG_DATA_SIZE) {
av_log(avctx, AV_LOG_ERROR, "buffer too small for loading palette\n");
return AVERROR(EINVAL);
}
cdg_load_palette(cc, cdg_data, inst == CDG_INST_LOAD_PAL_LO);
break;
case CDG_INST_BORDER_PRESET:
cdg_border_preset(cc, cdg_data);
break;
case CDG_INST_TILE_BLOCK_XOR:
case CDG_INST_TILE_BLOCK:
if (buf_size - CDG_HEADER_SIZE < CDG_DATA_SIZE) {
av_log(avctx, AV_LOG_ERROR, "buffer too small for drawing tile\n");
return AVERROR(EINVAL);
}
ret = cdg_tile_block(cc, cdg_data, inst == CDG_INST_TILE_BLOCK_XOR);
if (ret) {
av_log(avctx, AV_LOG_ERROR, "tile is out of range\n");
return ret;
}
break;
case CDG_INST_SCROLL_PRESET:
case CDG_INST_SCROLL_COPY:
if (buf_size - CDG_HEADER_SIZE < CDG_MINIMUM_SCROLL_SIZE) {
av_log(avctx, AV_LOG_ERROR, "buffer too small for scrolling\n");
return AVERROR(EINVAL);
}
if ((ret = ff_get_buffer(avctx, frame, AV_GET_BUFFER_FLAG_REF)) < 0)
return ret;
cdg_scroll(cc, cdg_data, frame, inst == CDG_INST_SCROLL_COPY);
av_frame_unref(cc->frame);
ret = av_frame_ref(cc->frame, frame);
if (ret < 0)
return ret;
break;
default:
break;
}
if (!frame->data[0]) {
ret = av_frame_ref(frame, cc->frame);
if (ret < 0)
return ret;
}
*got_frame = 1;
} else {
*got_frame = 0;
buf_size = 0;
}
return buf_size;
}
| true | FFmpeg | f9db2fc84d3d061720ceb8e1b7425b48bdb1a119 | static int cdg_decode_frame(AVCodecContext *avctx,
void *data, int *got_frame, AVPacket *avpkt)
{
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
int ret;
uint8_t command, inst;
uint8_t cdg_data[CDG_DATA_SIZE];
AVFrame *frame = data;
CDGraphicsContext *cc = avctx->priv_data;
if (buf_size < CDG_MINIMUM_PKT_SIZE) {
av_log(avctx, AV_LOG_ERROR, "buffer too small for decoder\n");
return AVERROR(EINVAL);
}
if (buf_size > CDG_HEADER_SIZE + CDG_DATA_SIZE) {
av_log(avctx, AV_LOG_ERROR, "buffer too big for decoder\n");
return AVERROR(EINVAL);
}
if ((ret = ff_reget_buffer(avctx, cc->frame)) < 0)
return ret;
if (!avctx->frame_number) {
memset(cc->frame->data[0], 0, cc->frame->linesize[0] * avctx->height);
memset(cc->frame->data[1], 0, AVPALETTE_SIZE);
}
command = bytestream_get_byte(&buf);
inst = bytestream_get_byte(&buf);
inst &= CDG_MASK;
buf += 2;
if (buf_size > CDG_HEADER_SIZE)
bytestream_get_buffer(&buf, cdg_data, buf_size - CDG_HEADER_SIZE);
if ((command & CDG_MASK) == CDG_COMMAND) {
switch (inst) {
case CDG_INST_MEMORY_PRESET:
if (!(cdg_data[1] & 0x0F))
memset(cc->frame->data[0], cdg_data[0] & 0x0F,
cc->frame->linesize[0] * CDG_FULL_HEIGHT);
break;
case CDG_INST_LOAD_PAL_LO:
case CDG_INST_LOAD_PAL_HIGH:
if (buf_size - CDG_HEADER_SIZE < CDG_DATA_SIZE) {
av_log(avctx, AV_LOG_ERROR, "buffer too small for loading palette\n");
return AVERROR(EINVAL);
}
cdg_load_palette(cc, cdg_data, inst == CDG_INST_LOAD_PAL_LO);
break;
case CDG_INST_BORDER_PRESET:
cdg_border_preset(cc, cdg_data);
break;
case CDG_INST_TILE_BLOCK_XOR:
case CDG_INST_TILE_BLOCK:
if (buf_size - CDG_HEADER_SIZE < CDG_DATA_SIZE) {
av_log(avctx, AV_LOG_ERROR, "buffer too small for drawing tile\n");
return AVERROR(EINVAL);
}
ret = cdg_tile_block(cc, cdg_data, inst == CDG_INST_TILE_BLOCK_XOR);
if (ret) {
av_log(avctx, AV_LOG_ERROR, "tile is out of range\n");
return ret;
}
break;
case CDG_INST_SCROLL_PRESET:
case CDG_INST_SCROLL_COPY:
if (buf_size - CDG_HEADER_SIZE < CDG_MINIMUM_SCROLL_SIZE) {
av_log(avctx, AV_LOG_ERROR, "buffer too small for scrolling\n");
return AVERROR(EINVAL);
}
if ((ret = ff_get_buffer(avctx, frame, AV_GET_BUFFER_FLAG_REF)) < 0)
return ret;
cdg_scroll(cc, cdg_data, frame, inst == CDG_INST_SCROLL_COPY);
av_frame_unref(cc->frame);
ret = av_frame_ref(cc->frame, frame);
if (ret < 0)
return ret;
break;
default:
break;
}
if (!frame->data[0]) {
ret = av_frame_ref(frame, cc->frame);
if (ret < 0)
return ret;
}
*got_frame = 1;
} else {
*got_frame = 0;
buf_size = 0;
}
return buf_size;
}
| {
"code": [
" uint8_t cdg_data[CDG_DATA_SIZE];"
],
"line_no": [
15
]
} | static int FUNC_0(AVCodecContext *VAR_0,
void *VAR_1, int *VAR_2, AVPacket *VAR_3)
{
const uint8_t *VAR_4 = VAR_3->VAR_1;
int VAR_5 = VAR_3->size;
int VAR_6;
uint8_t command, inst;
uint8_t cdg_data[CDG_DATA_SIZE];
AVFrame *frame = VAR_1;
CDGraphicsContext *cc = VAR_0->priv_data;
if (VAR_5 < CDG_MINIMUM_PKT_SIZE) {
av_log(VAR_0, AV_LOG_ERROR, "buffer too small for decoder\n");
return AVERROR(EINVAL);
}
if (VAR_5 > CDG_HEADER_SIZE + CDG_DATA_SIZE) {
av_log(VAR_0, AV_LOG_ERROR, "buffer too big for decoder\n");
return AVERROR(EINVAL);
}
if ((VAR_6 = ff_reget_buffer(VAR_0, cc->frame)) < 0)
return VAR_6;
if (!VAR_0->frame_number) {
memset(cc->frame->VAR_1[0], 0, cc->frame->linesize[0] * VAR_0->height);
memset(cc->frame->VAR_1[1], 0, AVPALETTE_SIZE);
}
command = bytestream_get_byte(&VAR_4);
inst = bytestream_get_byte(&VAR_4);
inst &= CDG_MASK;
VAR_4 += 2;
if (VAR_5 > CDG_HEADER_SIZE)
bytestream_get_buffer(&VAR_4, cdg_data, VAR_5 - CDG_HEADER_SIZE);
if ((command & CDG_MASK) == CDG_COMMAND) {
switch (inst) {
case CDG_INST_MEMORY_PRESET:
if (!(cdg_data[1] & 0x0F))
memset(cc->frame->VAR_1[0], cdg_data[0] & 0x0F,
cc->frame->linesize[0] * CDG_FULL_HEIGHT);
break;
case CDG_INST_LOAD_PAL_LO:
case CDG_INST_LOAD_PAL_HIGH:
if (VAR_5 - CDG_HEADER_SIZE < CDG_DATA_SIZE) {
av_log(VAR_0, AV_LOG_ERROR, "buffer too small for loading palette\n");
return AVERROR(EINVAL);
}
cdg_load_palette(cc, cdg_data, inst == CDG_INST_LOAD_PAL_LO);
break;
case CDG_INST_BORDER_PRESET:
cdg_border_preset(cc, cdg_data);
break;
case CDG_INST_TILE_BLOCK_XOR:
case CDG_INST_TILE_BLOCK:
if (VAR_5 - CDG_HEADER_SIZE < CDG_DATA_SIZE) {
av_log(VAR_0, AV_LOG_ERROR, "buffer too small for drawing tile\n");
return AVERROR(EINVAL);
}
VAR_6 = cdg_tile_block(cc, cdg_data, inst == CDG_INST_TILE_BLOCK_XOR);
if (VAR_6) {
av_log(VAR_0, AV_LOG_ERROR, "tile is out of range\n");
return VAR_6;
}
break;
case CDG_INST_SCROLL_PRESET:
case CDG_INST_SCROLL_COPY:
if (VAR_5 - CDG_HEADER_SIZE < CDG_MINIMUM_SCROLL_SIZE) {
av_log(VAR_0, AV_LOG_ERROR, "buffer too small for scrolling\n");
return AVERROR(EINVAL);
}
if ((VAR_6 = ff_get_buffer(VAR_0, frame, AV_GET_BUFFER_FLAG_REF)) < 0)
return VAR_6;
cdg_scroll(cc, cdg_data, frame, inst == CDG_INST_SCROLL_COPY);
av_frame_unref(cc->frame);
VAR_6 = av_frame_ref(cc->frame, frame);
if (VAR_6 < 0)
return VAR_6;
break;
default:
break;
}
if (!frame->VAR_1[0]) {
VAR_6 = av_frame_ref(frame, cc->frame);
if (VAR_6 < 0)
return VAR_6;
}
*VAR_2 = 1;
} else {
*VAR_2 = 0;
VAR_5 = 0;
}
return VAR_5;
}
| [
"static int FUNC_0(AVCodecContext *VAR_0,\nvoid *VAR_1, int *VAR_2, AVPacket *VAR_3)\n{",
"const uint8_t *VAR_4 = VAR_3->VAR_1;",
"int VAR_5 = VAR_3->size;",
"int VAR_6;",
"uint8_t command, inst;",
"uint8_t cdg_data[CDG_DATA_SIZE];",
"AVFrame *frame = VAR_1;",
"CDGraphicsContext *cc = VAR_0->priv_data;",
"if (VAR_5 < CDG_MINIMUM_PKT_SIZE) {",
"av_log(VAR_0, AV_LOG_ERROR, \"buffer too small for decoder\\n\");",
"return AVERROR(EINVAL);",
"}",
"if (VAR_5 > CDG_HEADER_SIZE + CDG_DATA_SIZE) {",
"av_log(VAR_0, AV_LOG_ERROR, \"buffer too big for decoder\\n\");",
"return AVERROR(EINVAL);",
"}",
"if ((VAR_6 = ff_reget_buffer(VAR_0, cc->frame)) < 0)\nreturn VAR_6;",
"if (!VAR_0->frame_number) {",
"memset(cc->frame->VAR_1[0], 0, cc->frame->linesize[0] * VAR_0->height);",
"memset(cc->frame->VAR_1[1], 0, AVPALETTE_SIZE);",
"}",
"command = bytestream_get_byte(&VAR_4);",
"inst = bytestream_get_byte(&VAR_4);",
"inst &= CDG_MASK;",
"VAR_4 += 2;",
"if (VAR_5 > CDG_HEADER_SIZE)\nbytestream_get_buffer(&VAR_4, cdg_data, VAR_5 - CDG_HEADER_SIZE);",
"if ((command & CDG_MASK) == CDG_COMMAND) {",
"switch (inst) {",
"case CDG_INST_MEMORY_PRESET:\nif (!(cdg_data[1] & 0x0F))\nmemset(cc->frame->VAR_1[0], cdg_data[0] & 0x0F,\ncc->frame->linesize[0] * CDG_FULL_HEIGHT);",
"break;",
"case CDG_INST_LOAD_PAL_LO:\ncase CDG_INST_LOAD_PAL_HIGH:\nif (VAR_5 - CDG_HEADER_SIZE < CDG_DATA_SIZE) {",
"av_log(VAR_0, AV_LOG_ERROR, \"buffer too small for loading palette\\n\");",
"return AVERROR(EINVAL);",
"}",
"cdg_load_palette(cc, cdg_data, inst == CDG_INST_LOAD_PAL_LO);",
"break;",
"case CDG_INST_BORDER_PRESET:\ncdg_border_preset(cc, cdg_data);",
"break;",
"case CDG_INST_TILE_BLOCK_XOR:\ncase CDG_INST_TILE_BLOCK:\nif (VAR_5 - CDG_HEADER_SIZE < CDG_DATA_SIZE) {",
"av_log(VAR_0, AV_LOG_ERROR, \"buffer too small for drawing tile\\n\");",
"return AVERROR(EINVAL);",
"}",
"VAR_6 = cdg_tile_block(cc, cdg_data, inst == CDG_INST_TILE_BLOCK_XOR);",
"if (VAR_6) {",
"av_log(VAR_0, AV_LOG_ERROR, \"tile is out of range\\n\");",
"return VAR_6;",
"}",
"break;",
"case CDG_INST_SCROLL_PRESET:\ncase CDG_INST_SCROLL_COPY:\nif (VAR_5 - CDG_HEADER_SIZE < CDG_MINIMUM_SCROLL_SIZE) {",
"av_log(VAR_0, AV_LOG_ERROR, \"buffer too small for scrolling\\n\");",
"return AVERROR(EINVAL);",
"}",
"if ((VAR_6 = ff_get_buffer(VAR_0, frame, AV_GET_BUFFER_FLAG_REF)) < 0)\nreturn VAR_6;",
"cdg_scroll(cc, cdg_data, frame, inst == CDG_INST_SCROLL_COPY);",
"av_frame_unref(cc->frame);",
"VAR_6 = av_frame_ref(cc->frame, frame);",
"if (VAR_6 < 0)\nreturn VAR_6;",
"break;",
"default:\nbreak;",
"}",
"if (!frame->VAR_1[0]) {",
"VAR_6 = av_frame_ref(frame, cc->frame);",
"if (VAR_6 < 0)\nreturn VAR_6;",
"}",
"*VAR_2 = 1;",
"} else {",
"*VAR_2 = 0;",
"VAR_5 = 0;",
"}",
"return VAR_5;",
"}"
] | [
0,
0,
0,
0,
0,
1,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | [
[
1,
3,
5
],
[
7
],
[
9
],
[
11
],
[
13
],
[
15
],
[
17
],
[
19
],
[
23
],
[
25
],
[
27
],
[
29
],
[
31
],
[
33
],
[
35
],
[
37
],
[
41,
43
],
[
45
],
[
47
],
[
49
],
[
51
],
[
55
],
[
57
],
[
59
],
[
61
],
[
65,
67
],
[
71
],
[
73
],
[
75,
77,
79,
81
],
[
83
],
[
85,
87,
89
],
[
91
],
[
93
],
[
95
],
[
99
],
[
101
],
[
103,
105
],
[
107
],
[
109,
111,
113
],
[
115
],
[
117
],
[
119
],
[
123
],
[
125
],
[
127
],
[
129
],
[
131
],
[
133
],
[
135,
137,
139
],
[
141
],
[
143
],
[
145
],
[
149,
151
],
[
155
],
[
157
],
[
159
],
[
161,
163
],
[
165
],
[
167,
169
],
[
171
],
[
175
],
[
177
],
[
179,
181
],
[
183
],
[
185
],
[
187
],
[
189
],
[
191
],
[
193
],
[
197
],
[
199
]
] |
21,391 | static int nut_write_header(AVFormatContext *s)
{
NUTContext *nut = s->priv_data;
ByteIOContext *bc = &s->pb;
AVCodecContext *codec;
int i, j, tmp_time, tmp_flags,tmp_stream, tmp_mul, tmp_size, tmp_fields;
nut->avf= s;
nut->stream =
av_mallocz(sizeof(StreamContext)*s->nb_streams);
put_buffer(bc, ID_STRING, strlen(ID_STRING));
put_byte(bc, 0);
nut->packet_start[2]= url_ftell(bc);
/* main header */
put_be64(bc, MAIN_STARTCODE);
put_packetheader(nut, bc, 120+5*256, 1);
put_v(bc, 2); /* version */
put_v(bc, s->nb_streams);
put_v(bc, MAX_DISTANCE);
put_v(bc, MAX_SHORT_DISTANCE);
put_v(bc, nut->rate_num=1);
put_v(bc, nut->rate_den=2);
put_v(bc, nut->short_startcode=0x4EFE79);
build_frame_code(s);
assert(nut->frame_code['N'].flags == FLAG_INVALID);
tmp_time= tmp_flags= tmp_stream= tmp_mul= tmp_size= /*tmp_res=*/ INT_MAX;
for(i=0; i<256;){
tmp_fields=0;
tmp_size= 0;
if(tmp_time != nut->frame_code[i].timestamp_delta) tmp_fields=1;
if(tmp_mul != nut->frame_code[i].size_mul ) tmp_fields=2;
if(tmp_stream != nut->frame_code[i].stream_id_plus1) tmp_fields=3;
if(tmp_size != nut->frame_code[i].size_lsb ) tmp_fields=4;
// if(tmp_res != nut->frame_code[i].res ) tmp_fields=5;
tmp_time = nut->frame_code[i].timestamp_delta;
tmp_flags = nut->frame_code[i].flags;
tmp_stream= nut->frame_code[i].stream_id_plus1;
tmp_mul = nut->frame_code[i].size_mul;
tmp_size = nut->frame_code[i].size_lsb;
// tmp_res = nut->frame_code[i].res;
for(j=0; i<256; j++,i++){
if(nut->frame_code[i].timestamp_delta != tmp_time ) break;
if(nut->frame_code[i].flags != tmp_flags ) break;
if(nut->frame_code[i].stream_id_plus1 != tmp_stream) break;
if(nut->frame_code[i].size_mul != tmp_mul ) break;
if(nut->frame_code[i].size_lsb != tmp_size+j) break;
// if(nut->frame_code[i].res != tmp_res ) break;
}
if(j != tmp_mul - tmp_size) tmp_fields=6;
put_v(bc, tmp_flags);
put_v(bc, tmp_fields);
if(tmp_fields>0) put_s(bc, tmp_time);
if(tmp_fields>1) put_v(bc, tmp_mul);
if(tmp_fields>2) put_v(bc, tmp_stream);
if(tmp_fields>3) put_v(bc, tmp_size);
if(tmp_fields>4) put_v(bc, 0 /*tmp_res*/);
if(tmp_fields>5) put_v(bc, j);
}
update_packetheader(nut, bc, 0, 1);
/* stream headers */
for (i = 0; i < s->nb_streams; i++)
{
int nom, denom, gcd;
codec = &s->streams[i]->codec;
put_be64(bc, STREAM_STARTCODE);
put_packetheader(nut, bc, 120 + codec->extradata_size, 1);
put_v(bc, i /*s->streams[i]->index*/);
put_v(bc, (codec->codec_type == CODEC_TYPE_AUDIO) ? 32 : 0);
if (codec->codec_tag)
put_vb(bc, codec->codec_tag);
else if (codec->codec_type == CODEC_TYPE_VIDEO)
{
put_vb(bc, codec_get_bmp_tag(codec->codec_id));
}
else if (codec->codec_type == CODEC_TYPE_AUDIO)
{
put_vb(bc, codec_get_wav_tag(codec->codec_id));
}
else
put_vb(bc, 0);
if (codec->codec_type == CODEC_TYPE_VIDEO)
{
nom = codec->time_base.den;
denom = codec->time_base.num;
}
else
{
nom = codec->sample_rate;
if(codec->frame_size>0)
denom= codec->frame_size;
else
denom= 1; //unlucky
}
gcd= ff_gcd(nom, denom);
nom /= gcd;
denom /= gcd;
nut->stream[i].rate_num= nom;
nut->stream[i].rate_den= denom;
av_set_pts_info(s->streams[i], 60, denom, nom);
put_v(bc, codec->bit_rate);
put_vb(bc, 0); /* no language code */
put_v(bc, nom);
put_v(bc, denom);
if(nom / denom < 1000)
nut->stream[i].msb_timestamp_shift = 7;
else
nut->stream[i].msb_timestamp_shift = 14;
put_v(bc, nut->stream[i].msb_timestamp_shift);
put_v(bc, codec->has_b_frames);
put_byte(bc, 0); /* flags: 0x1 - fixed_fps, 0x2 - index_present */
if(codec->extradata_size){
put_v(bc, 1);
put_v(bc, codec->extradata_size);
put_buffer(bc, codec->extradata, codec->extradata_size);
}
put_v(bc, 0); /* end of codec specific headers */
switch(codec->codec_type)
{
case CODEC_TYPE_AUDIO:
put_v(bc, codec->sample_rate);
put_v(bc, 1);
put_v(bc, codec->channels);
break;
case CODEC_TYPE_VIDEO:
put_v(bc, codec->width);
put_v(bc, codec->height);
put_v(bc, codec->sample_aspect_ratio.num);
put_v(bc, codec->sample_aspect_ratio.den);
put_v(bc, 0); /* csp type -- unknown */
break;
default:
break;
}
update_packetheader(nut, bc, 0, 1);
}
/* info header */
put_be64(bc, INFO_STARTCODE);
put_packetheader(nut, bc, 30+strlen(s->author)+strlen(s->title)+
strlen(s->comment)+strlen(s->copyright)+strlen(LIBAVFORMAT_IDENT), 1);
if (s->author[0])
{
put_v(bc, 9); /* type */
put_str(bc, s->author);
}
if (s->title[0])
{
put_v(bc, 10); /* type */
put_str(bc, s->title);
}
if (s->comment[0])
{
put_v(bc, 11); /* type */
put_str(bc, s->comment);
}
if (s->copyright[0])
{
put_v(bc, 12); /* type */
put_str(bc, s->copyright);
}
/* encoder */
if(!(s->streams[0]->codec.flags & CODEC_FLAG_BITEXACT)){
put_v(bc, 13); /* type */
put_str(bc, LIBAVFORMAT_IDENT);
}
put_v(bc, 0); /* eof info */
update_packetheader(nut, bc, 0, 1);
put_flush_packet(bc);
return 0;
}
| true | FFmpeg | 01bd1ed2db53fa90a0512d65ad6c08170061dfdf | static int nut_write_header(AVFormatContext *s)
{
NUTContext *nut = s->priv_data;
ByteIOContext *bc = &s->pb;
AVCodecContext *codec;
int i, j, tmp_time, tmp_flags,tmp_stream, tmp_mul, tmp_size, tmp_fields;
nut->avf= s;
nut->stream =
av_mallocz(sizeof(StreamContext)*s->nb_streams);
put_buffer(bc, ID_STRING, strlen(ID_STRING));
put_byte(bc, 0);
nut->packet_start[2]= url_ftell(bc);
put_be64(bc, MAIN_STARTCODE);
put_packetheader(nut, bc, 120+5*256, 1);
put_v(bc, 2);
put_v(bc, s->nb_streams);
put_v(bc, MAX_DISTANCE);
put_v(bc, MAX_SHORT_DISTANCE);
put_v(bc, nut->rate_num=1);
put_v(bc, nut->rate_den=2);
put_v(bc, nut->short_startcode=0x4EFE79);
build_frame_code(s);
assert(nut->frame_code['N'].flags == FLAG_INVALID);
tmp_time= tmp_flags= tmp_stream= tmp_mul= tmp_size= INT_MAX;
for(i=0; i<256;){
tmp_fields=0;
tmp_size= 0;
if(tmp_time != nut->frame_code[i].timestamp_delta) tmp_fields=1;
if(tmp_mul != nut->frame_code[i].size_mul ) tmp_fields=2;
if(tmp_stream != nut->frame_code[i].stream_id_plus1) tmp_fields=3;
if(tmp_size != nut->frame_code[i].size_lsb ) tmp_fields=4;
tmp_time = nut->frame_code[i].timestamp_delta;
tmp_flags = nut->frame_code[i].flags;
tmp_stream= nut->frame_code[i].stream_id_plus1;
tmp_mul = nut->frame_code[i].size_mul;
tmp_size = nut->frame_code[i].size_lsb;
for(j=0; i<256; j++,i++){
if(nut->frame_code[i].timestamp_delta != tmp_time ) break;
if(nut->frame_code[i].flags != tmp_flags ) break;
if(nut->frame_code[i].stream_id_plus1 != tmp_stream) break;
if(nut->frame_code[i].size_mul != tmp_mul ) break;
if(nut->frame_code[i].size_lsb != tmp_size+j) break;
}
if(j != tmp_mul - tmp_size) tmp_fields=6;
put_v(bc, tmp_flags);
put_v(bc, tmp_fields);
if(tmp_fields>0) put_s(bc, tmp_time);
if(tmp_fields>1) put_v(bc, tmp_mul);
if(tmp_fields>2) put_v(bc, tmp_stream);
if(tmp_fields>3) put_v(bc, tmp_size);
if(tmp_fields>4) put_v(bc, 0 );
if(tmp_fields>5) put_v(bc, j);
}
update_packetheader(nut, bc, 0, 1);
for (i = 0; i < s->nb_streams; i++)
{
int nom, denom, gcd;
codec = &s->streams[i]->codec;
put_be64(bc, STREAM_STARTCODE);
put_packetheader(nut, bc, 120 + codec->extradata_size, 1);
put_v(bc, i );
put_v(bc, (codec->codec_type == CODEC_TYPE_AUDIO) ? 32 : 0);
if (codec->codec_tag)
put_vb(bc, codec->codec_tag);
else if (codec->codec_type == CODEC_TYPE_VIDEO)
{
put_vb(bc, codec_get_bmp_tag(codec->codec_id));
}
else if (codec->codec_type == CODEC_TYPE_AUDIO)
{
put_vb(bc, codec_get_wav_tag(codec->codec_id));
}
else
put_vb(bc, 0);
if (codec->codec_type == CODEC_TYPE_VIDEO)
{
nom = codec->time_base.den;
denom = codec->time_base.num;
}
else
{
nom = codec->sample_rate;
if(codec->frame_size>0)
denom= codec->frame_size;
else
denom= 1;
}
gcd= ff_gcd(nom, denom);
nom /= gcd;
denom /= gcd;
nut->stream[i].rate_num= nom;
nut->stream[i].rate_den= denom;
av_set_pts_info(s->streams[i], 60, denom, nom);
put_v(bc, codec->bit_rate);
put_vb(bc, 0);
put_v(bc, nom);
put_v(bc, denom);
if(nom / denom < 1000)
nut->stream[i].msb_timestamp_shift = 7;
else
nut->stream[i].msb_timestamp_shift = 14;
put_v(bc, nut->stream[i].msb_timestamp_shift);
put_v(bc, codec->has_b_frames);
put_byte(bc, 0);
if(codec->extradata_size){
put_v(bc, 1);
put_v(bc, codec->extradata_size);
put_buffer(bc, codec->extradata, codec->extradata_size);
}
put_v(bc, 0);
switch(codec->codec_type)
{
case CODEC_TYPE_AUDIO:
put_v(bc, codec->sample_rate);
put_v(bc, 1);
put_v(bc, codec->channels);
break;
case CODEC_TYPE_VIDEO:
put_v(bc, codec->width);
put_v(bc, codec->height);
put_v(bc, codec->sample_aspect_ratio.num);
put_v(bc, codec->sample_aspect_ratio.den);
put_v(bc, 0);
break;
default:
break;
}
update_packetheader(nut, bc, 0, 1);
}
put_be64(bc, INFO_STARTCODE);
put_packetheader(nut, bc, 30+strlen(s->author)+strlen(s->title)+
strlen(s->comment)+strlen(s->copyright)+strlen(LIBAVFORMAT_IDENT), 1);
if (s->author[0])
{
put_v(bc, 9);
put_str(bc, s->author);
}
if (s->title[0])
{
put_v(bc, 10);
put_str(bc, s->title);
}
if (s->comment[0])
{
put_v(bc, 11);
put_str(bc, s->comment);
}
if (s->copyright[0])
{
put_v(bc, 12);
put_str(bc, s->copyright);
}
if(!(s->streams[0]->codec.flags & CODEC_FLAG_BITEXACT)){
put_v(bc, 13);
put_str(bc, LIBAVFORMAT_IDENT);
}
put_v(bc, 0);
update_packetheader(nut, bc, 0, 1);
put_flush_packet(bc);
return 0;
}
| {
"code": [
"\tint nom, denom, gcd;",
"\tput_v(bc, (codec->codec_type == CODEC_TYPE_AUDIO) ? 32 : 0);",
"\tif (codec->codec_type == CODEC_TYPE_VIDEO)",
"\t nom = codec->time_base.den;",
"\t denom = codec->time_base.num;",
"\t nom = codec->sample_rate;",
" if(codec->frame_size>0)",
" denom= codec->frame_size;",
" gcd= ff_gcd(nom, denom);",
" nom /= gcd;",
" denom /= gcd;"
],
"line_no": [
149,
163,
191,
195,
197,
205,
207,
209,
217,
219,
221
]
} | static int FUNC_0(AVFormatContext *VAR_0)
{
NUTContext *nut = VAR_0->priv_data;
ByteIOContext *bc = &VAR_0->pb;
AVCodecContext *codec;
int VAR_1, VAR_2, VAR_3, VAR_4,VAR_5, VAR_6, VAR_7, VAR_8;
nut->avf= VAR_0;
nut->stream =
av_mallocz(sizeof(StreamContext)*VAR_0->nb_streams);
put_buffer(bc, ID_STRING, strlen(ID_STRING));
put_byte(bc, 0);
nut->packet_start[2]= url_ftell(bc);
put_be64(bc, MAIN_STARTCODE);
put_packetheader(nut, bc, 120+5*256, 1);
put_v(bc, 2);
put_v(bc, VAR_0->nb_streams);
put_v(bc, MAX_DISTANCE);
put_v(bc, MAX_SHORT_DISTANCE);
put_v(bc, nut->rate_num=1);
put_v(bc, nut->rate_den=2);
put_v(bc, nut->short_startcode=0x4EFE79);
build_frame_code(VAR_0);
assert(nut->frame_code['N'].flags == FLAG_INVALID);
VAR_3= VAR_4= VAR_5= VAR_6= VAR_7= INT_MAX;
for(VAR_1=0; VAR_1<256;){
VAR_8=0;
VAR_7= 0;
if(VAR_3 != nut->frame_code[VAR_1].timestamp_delta) VAR_8=1;
if(VAR_6 != nut->frame_code[VAR_1].size_mul ) VAR_8=2;
if(VAR_5 != nut->frame_code[VAR_1].stream_id_plus1) VAR_8=3;
if(VAR_7 != nut->frame_code[VAR_1].size_lsb ) VAR_8=4;
VAR_3 = nut->frame_code[VAR_1].timestamp_delta;
VAR_4 = nut->frame_code[VAR_1].flags;
VAR_5= nut->frame_code[VAR_1].stream_id_plus1;
VAR_6 = nut->frame_code[VAR_1].size_mul;
VAR_7 = nut->frame_code[VAR_1].size_lsb;
for(VAR_2=0; VAR_1<256; VAR_2++,VAR_1++){
if(nut->frame_code[VAR_1].timestamp_delta != VAR_3 ) break;
if(nut->frame_code[VAR_1].flags != VAR_4 ) break;
if(nut->frame_code[VAR_1].stream_id_plus1 != VAR_5) break;
if(nut->frame_code[VAR_1].size_mul != VAR_6 ) break;
if(nut->frame_code[VAR_1].size_lsb != VAR_7+VAR_2) break;
}
if(VAR_2 != VAR_6 - VAR_7) VAR_8=6;
put_v(bc, VAR_4);
put_v(bc, VAR_8);
if(VAR_8>0) put_s(bc, VAR_3);
if(VAR_8>1) put_v(bc, VAR_6);
if(VAR_8>2) put_v(bc, VAR_5);
if(VAR_8>3) put_v(bc, VAR_7);
if(VAR_8>4) put_v(bc, 0 );
if(VAR_8>5) put_v(bc, VAR_2);
}
update_packetheader(nut, bc, 0, 1);
for (VAR_1 = 0; VAR_1 < VAR_0->nb_streams; VAR_1++)
{
int nom, denom, gcd;
codec = &VAR_0->streams[VAR_1]->codec;
put_be64(bc, STREAM_STARTCODE);
put_packetheader(nut, bc, 120 + codec->extradata_size, 1);
put_v(bc, VAR_1 );
put_v(bc, (codec->codec_type == CODEC_TYPE_AUDIO) ? 32 : 0);
if (codec->codec_tag)
put_vb(bc, codec->codec_tag);
else if (codec->codec_type == CODEC_TYPE_VIDEO)
{
put_vb(bc, codec_get_bmp_tag(codec->codec_id));
}
else if (codec->codec_type == CODEC_TYPE_AUDIO)
{
put_vb(bc, codec_get_wav_tag(codec->codec_id));
}
else
put_vb(bc, 0);
if (codec->codec_type == CODEC_TYPE_VIDEO)
{
nom = codec->time_base.den;
denom = codec->time_base.num;
}
else
{
nom = codec->sample_rate;
if(codec->frame_size>0)
denom= codec->frame_size;
else
denom= 1;
}
gcd= ff_gcd(nom, denom);
nom /= gcd;
denom /= gcd;
nut->stream[VAR_1].rate_num= nom;
nut->stream[VAR_1].rate_den= denom;
av_set_pts_info(VAR_0->streams[VAR_1], 60, denom, nom);
put_v(bc, codec->bit_rate);
put_vb(bc, 0);
put_v(bc, nom);
put_v(bc, denom);
if(nom / denom < 1000)
nut->stream[VAR_1].msb_timestamp_shift = 7;
else
nut->stream[VAR_1].msb_timestamp_shift = 14;
put_v(bc, nut->stream[VAR_1].msb_timestamp_shift);
put_v(bc, codec->has_b_frames);
put_byte(bc, 0);
if(codec->extradata_size){
put_v(bc, 1);
put_v(bc, codec->extradata_size);
put_buffer(bc, codec->extradata, codec->extradata_size);
}
put_v(bc, 0);
switch(codec->codec_type)
{
case CODEC_TYPE_AUDIO:
put_v(bc, codec->sample_rate);
put_v(bc, 1);
put_v(bc, codec->channels);
break;
case CODEC_TYPE_VIDEO:
put_v(bc, codec->width);
put_v(bc, codec->height);
put_v(bc, codec->sample_aspect_ratio.num);
put_v(bc, codec->sample_aspect_ratio.den);
put_v(bc, 0);
break;
default:
break;
}
update_packetheader(nut, bc, 0, 1);
}
put_be64(bc, INFO_STARTCODE);
put_packetheader(nut, bc, 30+strlen(VAR_0->author)+strlen(VAR_0->title)+
strlen(VAR_0->comment)+strlen(VAR_0->copyright)+strlen(LIBAVFORMAT_IDENT), 1);
if (VAR_0->author[0])
{
put_v(bc, 9);
put_str(bc, VAR_0->author);
}
if (VAR_0->title[0])
{
put_v(bc, 10);
put_str(bc, VAR_0->title);
}
if (VAR_0->comment[0])
{
put_v(bc, 11);
put_str(bc, VAR_0->comment);
}
if (VAR_0->copyright[0])
{
put_v(bc, 12);
put_str(bc, VAR_0->copyright);
}
if(!(VAR_0->streams[0]->codec.flags & CODEC_FLAG_BITEXACT)){
put_v(bc, 13);
put_str(bc, LIBAVFORMAT_IDENT);
}
put_v(bc, 0);
update_packetheader(nut, bc, 0, 1);
put_flush_packet(bc);
return 0;
}
| [
"static int FUNC_0(AVFormatContext *VAR_0)\n{",
"NUTContext *nut = VAR_0->priv_data;",
"ByteIOContext *bc = &VAR_0->pb;",
"AVCodecContext *codec;",
"int VAR_1, VAR_2, VAR_3, VAR_4,VAR_5, VAR_6, VAR_7, VAR_8;",
"nut->avf= VAR_0;",
"nut->stream =\nav_mallocz(sizeof(StreamContext)*VAR_0->nb_streams);",
"put_buffer(bc, ID_STRING, strlen(ID_STRING));",
"put_byte(bc, 0);",
"nut->packet_start[2]= url_ftell(bc);",
"put_be64(bc, MAIN_STARTCODE);",
"put_packetheader(nut, bc, 120+5*256, 1);",
"put_v(bc, 2);",
"put_v(bc, VAR_0->nb_streams);",
"put_v(bc, MAX_DISTANCE);",
"put_v(bc, MAX_SHORT_DISTANCE);",
"put_v(bc, nut->rate_num=1);",
"put_v(bc, nut->rate_den=2);",
"put_v(bc, nut->short_startcode=0x4EFE79);",
"build_frame_code(VAR_0);",
"assert(nut->frame_code['N'].flags == FLAG_INVALID);",
"VAR_3= VAR_4= VAR_5= VAR_6= VAR_7= INT_MAX;",
"for(VAR_1=0; VAR_1<256;){",
"VAR_8=0;",
"VAR_7= 0;",
"if(VAR_3 != nut->frame_code[VAR_1].timestamp_delta) VAR_8=1;",
"if(VAR_6 != nut->frame_code[VAR_1].size_mul ) VAR_8=2;",
"if(VAR_5 != nut->frame_code[VAR_1].stream_id_plus1) VAR_8=3;",
"if(VAR_7 != nut->frame_code[VAR_1].size_lsb ) VAR_8=4;",
"VAR_3 = nut->frame_code[VAR_1].timestamp_delta;",
"VAR_4 = nut->frame_code[VAR_1].flags;",
"VAR_5= nut->frame_code[VAR_1].stream_id_plus1;",
"VAR_6 = nut->frame_code[VAR_1].size_mul;",
"VAR_7 = nut->frame_code[VAR_1].size_lsb;",
"for(VAR_2=0; VAR_1<256; VAR_2++,VAR_1++){",
"if(nut->frame_code[VAR_1].timestamp_delta != VAR_3 ) break;",
"if(nut->frame_code[VAR_1].flags != VAR_4 ) break;",
"if(nut->frame_code[VAR_1].stream_id_plus1 != VAR_5) break;",
"if(nut->frame_code[VAR_1].size_mul != VAR_6 ) break;",
"if(nut->frame_code[VAR_1].size_lsb != VAR_7+VAR_2) break;",
"}",
"if(VAR_2 != VAR_6 - VAR_7) VAR_8=6;",
"put_v(bc, VAR_4);",
"put_v(bc, VAR_8);",
"if(VAR_8>0) put_s(bc, VAR_3);",
"if(VAR_8>1) put_v(bc, VAR_6);",
"if(VAR_8>2) put_v(bc, VAR_5);",
"if(VAR_8>3) put_v(bc, VAR_7);",
"if(VAR_8>4) put_v(bc, 0 );",
"if(VAR_8>5) put_v(bc, VAR_2);",
"}",
"update_packetheader(nut, bc, 0, 1);",
"for (VAR_1 = 0; VAR_1 < VAR_0->nb_streams; VAR_1++)",
"{",
"int nom, denom, gcd;",
"codec = &VAR_0->streams[VAR_1]->codec;",
"put_be64(bc, STREAM_STARTCODE);",
"put_packetheader(nut, bc, 120 + codec->extradata_size, 1);",
"put_v(bc, VAR_1 );",
"put_v(bc, (codec->codec_type == CODEC_TYPE_AUDIO) ? 32 : 0);",
"if (codec->codec_tag)\nput_vb(bc, codec->codec_tag);",
"else if (codec->codec_type == CODEC_TYPE_VIDEO)\n{",
"put_vb(bc, codec_get_bmp_tag(codec->codec_id));",
"}",
"else if (codec->codec_type == CODEC_TYPE_AUDIO)\n{",
"put_vb(bc, codec_get_wav_tag(codec->codec_id));",
"}",
"else\nput_vb(bc, 0);",
"if (codec->codec_type == CODEC_TYPE_VIDEO)\n{",
"nom = codec->time_base.den;",
"denom = codec->time_base.num;",
"}",
"else\n{",
"nom = codec->sample_rate;",
"if(codec->frame_size>0)\ndenom= codec->frame_size;",
"else\ndenom= 1;",
"}",
"gcd= ff_gcd(nom, denom);",
"nom /= gcd;",
"denom /= gcd;",
"nut->stream[VAR_1].rate_num= nom;",
"nut->stream[VAR_1].rate_den= denom;",
"av_set_pts_info(VAR_0->streams[VAR_1], 60, denom, nom);",
"put_v(bc, codec->bit_rate);",
"put_vb(bc, 0);",
"put_v(bc, nom);",
"put_v(bc, denom);",
"if(nom / denom < 1000)\nnut->stream[VAR_1].msb_timestamp_shift = 7;",
"else\nnut->stream[VAR_1].msb_timestamp_shift = 14;",
"put_v(bc, nut->stream[VAR_1].msb_timestamp_shift);",
"put_v(bc, codec->has_b_frames);",
"put_byte(bc, 0);",
"if(codec->extradata_size){",
"put_v(bc, 1);",
"put_v(bc, codec->extradata_size);",
"put_buffer(bc, codec->extradata, codec->extradata_size);",
"}",
"put_v(bc, 0);",
"switch(codec->codec_type)\n{",
"case CODEC_TYPE_AUDIO:\nput_v(bc, codec->sample_rate);",
"put_v(bc, 1);",
"put_v(bc, codec->channels);",
"break;",
"case CODEC_TYPE_VIDEO:\nput_v(bc, codec->width);",
"put_v(bc, codec->height);",
"put_v(bc, codec->sample_aspect_ratio.num);",
"put_v(bc, codec->sample_aspect_ratio.den);",
"put_v(bc, 0);",
"break;",
"default:\nbreak;",
"}",
"update_packetheader(nut, bc, 0, 1);",
"}",
"put_be64(bc, INFO_STARTCODE);",
"put_packetheader(nut, bc, 30+strlen(VAR_0->author)+strlen(VAR_0->title)+\nstrlen(VAR_0->comment)+strlen(VAR_0->copyright)+strlen(LIBAVFORMAT_IDENT), 1);",
"if (VAR_0->author[0])\n{",
"put_v(bc, 9);",
"put_str(bc, VAR_0->author);",
"}",
"if (VAR_0->title[0])\n{",
"put_v(bc, 10);",
"put_str(bc, VAR_0->title);",
"}",
"if (VAR_0->comment[0])\n{",
"put_v(bc, 11);",
"put_str(bc, VAR_0->comment);",
"}",
"if (VAR_0->copyright[0])\n{",
"put_v(bc, 12);",
"put_str(bc, VAR_0->copyright);",
"}",
"if(!(VAR_0->streams[0]->codec.flags & CODEC_FLAG_BITEXACT)){",
"put_v(bc, 13);",
"put_str(bc, LIBAVFORMAT_IDENT);",
"}",
"put_v(bc, 0);",
"update_packetheader(nut, bc, 0, 1);",
"put_flush_packet(bc);",
"return 0;",
"}"
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
1,
0,
0,
0,
0,
1,
0,
0,
0,
0,
0,
0,
0,
0,
1,
1,
1,
0,
0,
1,
1,
0,
0,
1,
1,
1,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | [
[
1,
3
],
[
5
],
[
7
],
[
9
],
[
11
],
[
15
],
[
19,
21
],
[
27
],
[
29
],
[
31
],
[
37
],
[
39
],
[
41
],
[
43
],
[
45
],
[
47
],
[
51
],
[
53
],
[
55
],
[
59
],
[
61
],
[
65
],
[
67
],
[
69
],
[
71
],
[
73
],
[
75
],
[
77
],
[
79
],
[
85
],
[
87
],
[
89
],
[
91
],
[
93
],
[
99
],
[
101
],
[
103
],
[
105
],
[
107
],
[
109
],
[
113
],
[
115
],
[
119
],
[
121
],
[
123
],
[
125
],
[
127
],
[
129
],
[
131
],
[
133
],
[
135
],
[
139
],
[
145
],
[
147
],
[
149
],
[
153
],
[
157
],
[
159
],
[
161
],
[
163
],
[
165,
167
],
[
169,
171
],
[
173
],
[
175
],
[
177,
179
],
[
181
],
[
183
],
[
185,
187
],
[
191,
193
],
[
195
],
[
197
],
[
199
],
[
201,
203
],
[
205
],
[
207,
209
],
[
211,
213
],
[
215
],
[
217
],
[
219
],
[
221
],
[
223
],
[
225
],
[
227
],
[
231
],
[
233
],
[
235
],
[
237
],
[
239,
241
],
[
243,
245
],
[
247
],
[
249
],
[
251
],
[
255
],
[
257
],
[
259
],
[
261
],
[
263
],
[
265
],
[
269,
271
],
[
273,
275
],
[
277
],
[
279
],
[
281
],
[
283,
285
],
[
287
],
[
289
],
[
291
],
[
293
],
[
295
],
[
297,
299
],
[
301
],
[
303
],
[
305
],
[
311
],
[
313,
315
],
[
317,
319
],
[
321
],
[
323
],
[
325
],
[
327,
329
],
[
331
],
[
333
],
[
335
],
[
337,
339
],
[
341
],
[
343
],
[
345
],
[
347,
349
],
[
351
],
[
353
],
[
355
],
[
359
],
[
361
],
[
363
],
[
365
],
[
369
],
[
371
],
[
375
],
[
379
],
[
381
]
] |
21,393 | static inline int IRQ_testbit(IRQ_queue_t *q, int n_IRQ)
{
return test_bit(q->queue, n_IRQ);
}
| true | qemu | af7e9e74c6a62a5bcd911726a9e88d28b61490e0 | static inline int IRQ_testbit(IRQ_queue_t *q, int n_IRQ)
{
return test_bit(q->queue, n_IRQ);
}
| {
"code": [
"static inline int IRQ_testbit(IRQ_queue_t *q, int n_IRQ)"
],
"line_no": [
1
]
} | static inline int FUNC_0(IRQ_queue_t *VAR_0, int VAR_1)
{
return test_bit(VAR_0->queue, VAR_1);
}
| [
"static inline int FUNC_0(IRQ_queue_t *VAR_0, int VAR_1)\n{",
"return test_bit(VAR_0->queue, VAR_1);",
"}"
] | [
1,
0,
0
] | [
[
1,
3
],
[
5
],
[
7
]
] |
21,394 | static int vmdk_write_compressed(BlockDriverState *bs,
int64_t sector_num,
const uint8_t *buf,
int nb_sectors)
{
BDRVVmdkState *s = bs->opaque;
if (s->num_extents == 1 && s->extents[0].compressed) {
Coroutine *co;
AioContext *aio_context = bdrv_get_aio_context(bs);
VmdkWriteCompressedCo data = {
.bs = bs,
.sector_num = sector_num,
.buf = buf,
.nb_sectors = nb_sectors,
.ret = -EINPROGRESS,
};
co = qemu_coroutine_create(vmdk_co_write_compressed);
qemu_coroutine_enter(co, &data);
while (data.ret == -EINPROGRESS) {
aio_poll(aio_context, true);
}
return data.ret;
} else {
return -ENOTSUP;
}
}
| true | qemu | 0b8b8753e4d94901627b3e86431230f2319215c4 | static int vmdk_write_compressed(BlockDriverState *bs,
int64_t sector_num,
const uint8_t *buf,
int nb_sectors)
{
BDRVVmdkState *s = bs->opaque;
if (s->num_extents == 1 && s->extents[0].compressed) {
Coroutine *co;
AioContext *aio_context = bdrv_get_aio_context(bs);
VmdkWriteCompressedCo data = {
.bs = bs,
.sector_num = sector_num,
.buf = buf,
.nb_sectors = nb_sectors,
.ret = -EINPROGRESS,
};
co = qemu_coroutine_create(vmdk_co_write_compressed);
qemu_coroutine_enter(co, &data);
while (data.ret == -EINPROGRESS) {
aio_poll(aio_context, true);
}
return data.ret;
} else {
return -ENOTSUP;
}
}
| {
"code": [
" qemu_coroutine_enter(co, &data);",
" qemu_coroutine_enter(co, &data);",
" qemu_coroutine_enter(co, &data);",
" co = qemu_coroutine_create(vmdk_co_write_compressed);",
" qemu_coroutine_enter(co, &data);"
],
"line_no": [
37,
37,
37,
35,
37
]
} | static int FUNC_0(BlockDriverState *VAR_0,
int64_t VAR_1,
const uint8_t *VAR_2,
int VAR_3)
{
BDRVVmdkState *s = VAR_0->opaque;
if (s->num_extents == 1 && s->extents[0].compressed) {
Coroutine *co;
AioContext *aio_context = bdrv_get_aio_context(VAR_0);
VmdkWriteCompressedCo data = {
.VAR_0 = VAR_0,
.VAR_1 = VAR_1,
.VAR_2 = VAR_2,
.VAR_3 = VAR_3,
.ret = -EINPROGRESS,
};
co = qemu_coroutine_create(vmdk_co_write_compressed);
qemu_coroutine_enter(co, &data);
while (data.ret == -EINPROGRESS) {
aio_poll(aio_context, true);
}
return data.ret;
} else {
return -ENOTSUP;
}
}
| [
"static int FUNC_0(BlockDriverState *VAR_0,\nint64_t VAR_1,\nconst uint8_t *VAR_2,\nint VAR_3)\n{",
"BDRVVmdkState *s = VAR_0->opaque;",
"if (s->num_extents == 1 && s->extents[0].compressed) {",
"Coroutine *co;",
"AioContext *aio_context = bdrv_get_aio_context(VAR_0);",
"VmdkWriteCompressedCo data = {",
".VAR_0 = VAR_0,\n.VAR_1 = VAR_1,\n.VAR_2 = VAR_2,\n.VAR_3 = VAR_3,\n.ret = -EINPROGRESS,\n};",
"co = qemu_coroutine_create(vmdk_co_write_compressed);",
"qemu_coroutine_enter(co, &data);",
"while (data.ret == -EINPROGRESS) {",
"aio_poll(aio_context, true);",
"}",
"return data.ret;",
"} else {",
"return -ENOTSUP;",
"}",
"}"
] | [
0,
0,
0,
0,
0,
0,
0,
1,
1,
0,
0,
0,
0,
0,
0,
0,
0
] | [
[
1,
3,
5,
7,
9
],
[
11
],
[
15
],
[
17
],
[
19
],
[
21
],
[
23,
25,
27,
29,
31,
33
],
[
35
],
[
37
],
[
39
],
[
41
],
[
43
],
[
45
],
[
47
],
[
49
],
[
51
],
[
53
]
] |
21,395 | static int tight_compress_data(VncState *vs, int stream_id, size_t bytes,
int level, int strategy)
{
z_streamp zstream = &vs->tight.stream[stream_id];
int previous_out;
if (bytes < VNC_TIGHT_MIN_TO_COMPRESS) {
vnc_write(vs, vs->tight.tight.buffer, vs->tight.tight.offset);
return bytes;
}
if (tight_init_stream(vs, stream_id, level, strategy)) {
return -1;
}
/* reserve memory in output buffer */
buffer_reserve(&vs->tight.zlib, bytes + 64);
/* set pointers */
zstream->next_in = vs->tight.tight.buffer;
zstream->avail_in = vs->tight.tight.offset;
zstream->next_out = vs->tight.zlib.buffer + vs->tight.zlib.offset;
zstream->avail_out = vs->tight.zlib.capacity - vs->tight.zlib.offset;
zstream->data_type = Z_BINARY;
previous_out = zstream->total_out;
/* start encoding */
if (deflate(zstream, Z_SYNC_FLUSH) != Z_OK) {
fprintf(stderr, "VNC: error during tight compression\n");
return -1;
}
vs->tight.zlib.offset = vs->tight.zlib.capacity - zstream->avail_out;
bytes = zstream->total_out - previous_out;
tight_send_compact_size(vs, bytes);
vnc_write(vs, vs->tight.zlib.buffer, bytes);
buffer_reset(&vs->tight.zlib);
return bytes;
}
| true | qemu | 2caa9e9d2e0f356cc244bc41ce1d3e81663f6782 | static int tight_compress_data(VncState *vs, int stream_id, size_t bytes,
int level, int strategy)
{
z_streamp zstream = &vs->tight.stream[stream_id];
int previous_out;
if (bytes < VNC_TIGHT_MIN_TO_COMPRESS) {
vnc_write(vs, vs->tight.tight.buffer, vs->tight.tight.offset);
return bytes;
}
if (tight_init_stream(vs, stream_id, level, strategy)) {
return -1;
}
buffer_reserve(&vs->tight.zlib, bytes + 64);
zstream->next_in = vs->tight.tight.buffer;
zstream->avail_in = vs->tight.tight.offset;
zstream->next_out = vs->tight.zlib.buffer + vs->tight.zlib.offset;
zstream->avail_out = vs->tight.zlib.capacity - vs->tight.zlib.offset;
zstream->data_type = Z_BINARY;
previous_out = zstream->total_out;
if (deflate(zstream, Z_SYNC_FLUSH) != Z_OK) {
fprintf(stderr, "VNC: error during tight compression\n");
return -1;
}
vs->tight.zlib.offset = vs->tight.zlib.capacity - zstream->avail_out;
bytes = zstream->total_out - previous_out;
tight_send_compact_size(vs, bytes);
vnc_write(vs, vs->tight.zlib.buffer, bytes);
buffer_reset(&vs->tight.zlib);
return bytes;
}
| {
"code": [
" previous_out = zstream->total_out;",
" bytes = zstream->total_out - previous_out;",
" previous_out = zstream->total_out;"
],
"line_no": [
49,
67,
49
]
} | static int FUNC_0(VncState *VAR_0, int VAR_1, size_t VAR_2,
int VAR_3, int VAR_4)
{
z_streamp zstream = &VAR_0->tight.stream[VAR_1];
int VAR_5;
if (VAR_2 < VNC_TIGHT_MIN_TO_COMPRESS) {
vnc_write(VAR_0, VAR_0->tight.tight.buffer, VAR_0->tight.tight.offset);
return VAR_2;
}
if (tight_init_stream(VAR_0, VAR_1, VAR_3, VAR_4)) {
return -1;
}
buffer_reserve(&VAR_0->tight.zlib, VAR_2 + 64);
zstream->next_in = VAR_0->tight.tight.buffer;
zstream->avail_in = VAR_0->tight.tight.offset;
zstream->next_out = VAR_0->tight.zlib.buffer + VAR_0->tight.zlib.offset;
zstream->avail_out = VAR_0->tight.zlib.capacity - VAR_0->tight.zlib.offset;
zstream->data_type = Z_BINARY;
VAR_5 = zstream->total_out;
if (deflate(zstream, Z_SYNC_FLUSH) != Z_OK) {
fprintf(stderr, "VNC: error during tight compression\n");
return -1;
}
VAR_0->tight.zlib.offset = VAR_0->tight.zlib.capacity - zstream->avail_out;
VAR_2 = zstream->total_out - VAR_5;
tight_send_compact_size(VAR_0, VAR_2);
vnc_write(VAR_0, VAR_0->tight.zlib.buffer, VAR_2);
buffer_reset(&VAR_0->tight.zlib);
return VAR_2;
}
| [
"static int FUNC_0(VncState *VAR_0, int VAR_1, size_t VAR_2,\nint VAR_3, int VAR_4)\n{",
"z_streamp zstream = &VAR_0->tight.stream[VAR_1];",
"int VAR_5;",
"if (VAR_2 < VNC_TIGHT_MIN_TO_COMPRESS) {",
"vnc_write(VAR_0, VAR_0->tight.tight.buffer, VAR_0->tight.tight.offset);",
"return VAR_2;",
"}",
"if (tight_init_stream(VAR_0, VAR_1, VAR_3, VAR_4)) {",
"return -1;",
"}",
"buffer_reserve(&VAR_0->tight.zlib, VAR_2 + 64);",
"zstream->next_in = VAR_0->tight.tight.buffer;",
"zstream->avail_in = VAR_0->tight.tight.offset;",
"zstream->next_out = VAR_0->tight.zlib.buffer + VAR_0->tight.zlib.offset;",
"zstream->avail_out = VAR_0->tight.zlib.capacity - VAR_0->tight.zlib.offset;",
"zstream->data_type = Z_BINARY;",
"VAR_5 = zstream->total_out;",
"if (deflate(zstream, Z_SYNC_FLUSH) != Z_OK) {",
"fprintf(stderr, \"VNC: error during tight compression\\n\");",
"return -1;",
"}",
"VAR_0->tight.zlib.offset = VAR_0->tight.zlib.capacity - zstream->avail_out;",
"VAR_2 = zstream->total_out - VAR_5;",
"tight_send_compact_size(VAR_0, VAR_2);",
"vnc_write(VAR_0, VAR_0->tight.zlib.buffer, VAR_2);",
"buffer_reset(&VAR_0->tight.zlib);",
"return VAR_2;",
"}"
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
1,
0,
0,
0,
0,
0,
1,
0,
0,
0,
0,
0
] | [
[
1,
3,
5
],
[
7
],
[
9
],
[
13
],
[
15
],
[
17
],
[
19
],
[
23
],
[
25
],
[
27
],
[
33
],
[
39
],
[
41
],
[
43
],
[
45
],
[
47
],
[
49
],
[
55
],
[
57
],
[
59
],
[
61
],
[
65
],
[
67
],
[
71
],
[
73
],
[
77
],
[
81
],
[
83
]
] |
21,396 | static void do_tb_flush(CPUState *cpu, run_on_cpu_data tb_flush_count)
{
tb_lock();
/* If it is already been done on request of another CPU,
* just retry.
*/
if (tcg_ctx.tb_ctx.tb_flush_count != tb_flush_count.host_int) {
goto done;
}
#if defined(DEBUG_TB_FLUSH)
printf("qemu: flush code_size=%ld nb_tbs=%d avg_tb_size=%ld\n",
(unsigned long)(tcg_ctx.code_gen_ptr - tcg_ctx.code_gen_buffer),
tcg_ctx.tb_ctx.nb_tbs, tcg_ctx.tb_ctx.nb_tbs > 0 ?
((unsigned long)(tcg_ctx.code_gen_ptr - tcg_ctx.code_gen_buffer)) /
tcg_ctx.tb_ctx.nb_tbs : 0);
#endif
if ((unsigned long)(tcg_ctx.code_gen_ptr - tcg_ctx.code_gen_buffer)
> tcg_ctx.code_gen_buffer_size) {
cpu_abort(cpu, "Internal error: code buffer overflow\n");
}
CPU_FOREACH(cpu) {
int i;
for (i = 0; i < TB_JMP_CACHE_SIZE; ++i) {
atomic_set(&cpu->tb_jmp_cache[i], NULL);
}
}
tcg_ctx.tb_ctx.nb_tbs = 0;
qht_reset_size(&tcg_ctx.tb_ctx.htable, CODE_GEN_HTABLE_SIZE);
page_flush_tb();
tcg_ctx.code_gen_ptr = tcg_ctx.code_gen_buffer;
/* XXX: flush processor icache at this point if cache flush is
expensive */
atomic_mb_set(&tcg_ctx.tb_ctx.tb_flush_count,
tcg_ctx.tb_ctx.tb_flush_count + 1);
done:
tb_unlock();
}
| true | qemu | f3ced3c59287dabc253f83f0c70aa4934470c15e | static void do_tb_flush(CPUState *cpu, run_on_cpu_data tb_flush_count)
{
tb_lock();
if (tcg_ctx.tb_ctx.tb_flush_count != tb_flush_count.host_int) {
goto done;
}
#if defined(DEBUG_TB_FLUSH)
printf("qemu: flush code_size=%ld nb_tbs=%d avg_tb_size=%ld\n",
(unsigned long)(tcg_ctx.code_gen_ptr - tcg_ctx.code_gen_buffer),
tcg_ctx.tb_ctx.nb_tbs, tcg_ctx.tb_ctx.nb_tbs > 0 ?
((unsigned long)(tcg_ctx.code_gen_ptr - tcg_ctx.code_gen_buffer)) /
tcg_ctx.tb_ctx.nb_tbs : 0);
#endif
if ((unsigned long)(tcg_ctx.code_gen_ptr - tcg_ctx.code_gen_buffer)
> tcg_ctx.code_gen_buffer_size) {
cpu_abort(cpu, "Internal error: code buffer overflow\n");
}
CPU_FOREACH(cpu) {
int i;
for (i = 0; i < TB_JMP_CACHE_SIZE; ++i) {
atomic_set(&cpu->tb_jmp_cache[i], NULL);
}
}
tcg_ctx.tb_ctx.nb_tbs = 0;
qht_reset_size(&tcg_ctx.tb_ctx.htable, CODE_GEN_HTABLE_SIZE);
page_flush_tb();
tcg_ctx.code_gen_ptr = tcg_ctx.code_gen_buffer;
atomic_mb_set(&tcg_ctx.tb_ctx.tb_flush_count,
tcg_ctx.tb_ctx.tb_flush_count + 1);
done:
tb_unlock();
}
| {
"code": [
" int i;",
" for (i = 0; i < TB_JMP_CACHE_SIZE; ++i) {",
" atomic_set(&cpu->tb_jmp_cache[i], NULL);",
" for (i = 0; i < TB_JMP_CACHE_SIZE; ++i) {",
" atomic_set(&cpu->tb_jmp_cache[i], NULL);"
],
"line_no": [
49,
53,
55,
53,
55
]
} | static void FUNC_0(CPUState *VAR_0, run_on_cpu_data VAR_1)
{
tb_lock();
if (tcg_ctx.tb_ctx.VAR_1 != VAR_1.host_int) {
goto done;
}
#if defined(DEBUG_TB_FLUSH)
printf("qemu: flush code_size=%ld nb_tbs=%d avg_tb_size=%ld\n",
(unsigned long)(tcg_ctx.code_gen_ptr - tcg_ctx.code_gen_buffer),
tcg_ctx.tb_ctx.nb_tbs, tcg_ctx.tb_ctx.nb_tbs > 0 ?
((unsigned long)(tcg_ctx.code_gen_ptr - tcg_ctx.code_gen_buffer)) /
tcg_ctx.tb_ctx.nb_tbs : 0);
#endif
if ((unsigned long)(tcg_ctx.code_gen_ptr - tcg_ctx.code_gen_buffer)
> tcg_ctx.code_gen_buffer_size) {
cpu_abort(VAR_0, "Internal error: code buffer overflow\n");
}
CPU_FOREACH(VAR_0) {
int i;
for (i = 0; i < TB_JMP_CACHE_SIZE; ++i) {
atomic_set(&VAR_0->tb_jmp_cache[i], NULL);
}
}
tcg_ctx.tb_ctx.nb_tbs = 0;
qht_reset_size(&tcg_ctx.tb_ctx.htable, CODE_GEN_HTABLE_SIZE);
page_flush_tb();
tcg_ctx.code_gen_ptr = tcg_ctx.code_gen_buffer;
atomic_mb_set(&tcg_ctx.tb_ctx.VAR_1,
tcg_ctx.tb_ctx.VAR_1 + 1);
done:
tb_unlock();
}
| [
"static void FUNC_0(CPUState *VAR_0, run_on_cpu_data VAR_1)\n{",
"tb_lock();",
"if (tcg_ctx.tb_ctx.VAR_1 != VAR_1.host_int) {",
"goto done;",
"}",
"#if defined(DEBUG_TB_FLUSH)\nprintf(\"qemu: flush code_size=%ld nb_tbs=%d avg_tb_size=%ld\\n\",\n(unsigned long)(tcg_ctx.code_gen_ptr - tcg_ctx.code_gen_buffer),\ntcg_ctx.tb_ctx.nb_tbs, tcg_ctx.tb_ctx.nb_tbs > 0 ?\n((unsigned long)(tcg_ctx.code_gen_ptr - tcg_ctx.code_gen_buffer)) /\ntcg_ctx.tb_ctx.nb_tbs : 0);",
"#endif\nif ((unsigned long)(tcg_ctx.code_gen_ptr - tcg_ctx.code_gen_buffer)\n> tcg_ctx.code_gen_buffer_size) {",
"cpu_abort(VAR_0, \"Internal error: code buffer overflow\\n\");",
"}",
"CPU_FOREACH(VAR_0) {",
"int i;",
"for (i = 0; i < TB_JMP_CACHE_SIZE; ++i) {",
"atomic_set(&VAR_0->tb_jmp_cache[i], NULL);",
"}",
"}",
"tcg_ctx.tb_ctx.nb_tbs = 0;",
"qht_reset_size(&tcg_ctx.tb_ctx.htable, CODE_GEN_HTABLE_SIZE);",
"page_flush_tb();",
"tcg_ctx.code_gen_ptr = tcg_ctx.code_gen_buffer;",
"atomic_mb_set(&tcg_ctx.tb_ctx.VAR_1,\ntcg_ctx.tb_ctx.VAR_1 + 1);",
"done:\ntb_unlock();",
"}"
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
1,
1,
1,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | [
[
1,
3
],
[
5
],
[
15
],
[
17
],
[
19
],
[
23,
25,
27,
29,
31,
33
],
[
35,
37,
39
],
[
41
],
[
43
],
[
47
],
[
49
],
[
53
],
[
55
],
[
57
],
[
59
],
[
63
],
[
65
],
[
67
],
[
71
],
[
77,
79
],
[
83,
85
],
[
87
]
] |
21,397 | int v9fs_co_st_gen(V9fsPDU *pdu, V9fsPath *path, mode_t st_mode,
V9fsStatDotl *v9stat)
{
int err = 0;
V9fsState *s = pdu->s;
if (v9fs_request_cancelled(pdu)) {
return -EINTR;
if (s->ctx.exops.get_st_gen) {
v9fs_path_read_lock(s);
v9fs_co_run_in_worker(
{
err = s->ctx.exops.get_st_gen(&s->ctx, path, st_mode,
&v9stat->st_gen);
if (err < 0) {
err = -errno;
});
v9fs_path_unlock(s);
return err;
| true | qemu | db431f6adc881a0758512cd765b3108209013512 | int v9fs_co_st_gen(V9fsPDU *pdu, V9fsPath *path, mode_t st_mode,
V9fsStatDotl *v9stat)
{
int err = 0;
V9fsState *s = pdu->s;
if (v9fs_request_cancelled(pdu)) {
return -EINTR;
if (s->ctx.exops.get_st_gen) {
v9fs_path_read_lock(s);
v9fs_co_run_in_worker(
{
err = s->ctx.exops.get_st_gen(&s->ctx, path, st_mode,
&v9stat->st_gen);
if (err < 0) {
err = -errno;
});
v9fs_path_unlock(s);
return err;
| {
"code": [],
"line_no": []
} | int FUNC_0(V9fsPDU *VAR_0, V9fsPath *VAR_1, mode_t VAR_2,
V9fsStatDotl *VAR_3)
{
int VAR_4 = 0;
V9fsState *s = VAR_0->s;
if (v9fs_request_cancelled(VAR_0)) {
return -EINTR;
if (s->ctx.exops.get_st_gen) {
v9fs_path_read_lock(s);
v9fs_co_run_in_worker(
{
VAR_4 = s->ctx.exops.get_st_gen(&s->ctx, VAR_1, VAR_2,
&VAR_3->st_gen);
if (VAR_4 < 0) {
VAR_4 = -errno;
});
v9fs_path_unlock(s);
return VAR_4;
| [
"int FUNC_0(V9fsPDU *VAR_0, V9fsPath *VAR_1, mode_t VAR_2,\nV9fsStatDotl *VAR_3)\n{",
"int VAR_4 = 0;",
"V9fsState *s = VAR_0->s;",
"if (v9fs_request_cancelled(VAR_0)) {",
"return -EINTR;",
"if (s->ctx.exops.get_st_gen) {",
"v9fs_path_read_lock(s);",
"v9fs_co_run_in_worker(\n{",
"VAR_4 = s->ctx.exops.get_st_gen(&s->ctx, VAR_1, VAR_2,\n&VAR_3->st_gen);",
"if (VAR_4 < 0) {",
"VAR_4 = -errno;",
"});",
"v9fs_path_unlock(s);",
"return VAR_4;"
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | [
[
1,
3,
5
],
[
7
],
[
9
],
[
13
],
[
15
],
[
18
],
[
20
],
[
22,
24
],
[
26,
28
],
[
30
],
[
32
],
[
35
],
[
37
],
[
44
]
] |
21,398 | int avpicture_fill(AVPicture *picture, uint8_t *ptr,
enum AVPixelFormat pix_fmt, int width, int height)
{
int ret;
if ((ret = av_image_check_size(width, height, 0, NULL)) < 0)
return ret;
if ((ret = av_image_fill_linesizes(picture->linesize, pix_fmt, width)) < 0)
return ret;
return av_image_fill_pointers(picture->data, pix_fmt,
height, ptr, picture->linesize);
}
| false | FFmpeg | e2ad0b66fa273c5c823978e8f601f2c0d9ee42f8 | int avpicture_fill(AVPicture *picture, uint8_t *ptr,
enum AVPixelFormat pix_fmt, int width, int height)
{
int ret;
if ((ret = av_image_check_size(width, height, 0, NULL)) < 0)
return ret;
if ((ret = av_image_fill_linesizes(picture->linesize, pix_fmt, width)) < 0)
return ret;
return av_image_fill_pointers(picture->data, pix_fmt,
height, ptr, picture->linesize);
}
| {
"code": [],
"line_no": []
} | int FUNC_0(AVPicture *VAR_0, uint8_t *VAR_1,
enum AVPixelFormat VAR_2, int VAR_3, int VAR_4)
{
int VAR_5;
if ((VAR_5 = av_image_check_size(VAR_3, VAR_4, 0, NULL)) < 0)
return VAR_5;
if ((VAR_5 = av_image_fill_linesizes(VAR_0->linesize, VAR_2, VAR_3)) < 0)
return VAR_5;
return av_image_fill_pointers(VAR_0->data, VAR_2,
VAR_4, VAR_1, VAR_0->linesize);
}
| [
"int FUNC_0(AVPicture *VAR_0, uint8_t *VAR_1,\nenum AVPixelFormat VAR_2, int VAR_3, int VAR_4)\n{",
"int VAR_5;",
"if ((VAR_5 = av_image_check_size(VAR_3, VAR_4, 0, NULL)) < 0)\nreturn VAR_5;",
"if ((VAR_5 = av_image_fill_linesizes(VAR_0->linesize, VAR_2, VAR_3)) < 0)\nreturn VAR_5;",
"return av_image_fill_pointers(VAR_0->data, VAR_2,\nVAR_4, VAR_1, VAR_0->linesize);",
"}"
] | [
0,
0,
0,
0,
0,
0
] | [
[
1,
3,
5
],
[
7
],
[
11,
13
],
[
17,
19
],
[
23,
25
],
[
27
]
] |
21,400 | static int bdrv_open_driver(BlockDriverState *bs, BlockDriver *drv,
const char *node_name, QDict *options,
int open_flags, Error **errp)
{
Error *local_err = NULL;
int ret;
bdrv_assign_node_name(bs, node_name, &local_err);
if (local_err) {
error_propagate(errp, local_err);
return -EINVAL;
}
bs->drv = drv;
bs->read_only = !(bs->open_flags & BDRV_O_RDWR);
bs->opaque = g_malloc0(drv->instance_size);
if (drv->bdrv_file_open) {
assert(!drv->bdrv_needs_filename || bs->filename[0]);
ret = drv->bdrv_file_open(bs, options, open_flags, &local_err);
} else if (drv->bdrv_open) {
ret = drv->bdrv_open(bs, options, open_flags, &local_err);
} else {
ret = 0;
}
if (ret < 0) {
if (local_err) {
error_propagate(errp, local_err);
} else if (bs->filename[0]) {
error_setg_errno(errp, -ret, "Could not open '%s'", bs->filename);
} else {
error_setg_errno(errp, -ret, "Could not open image");
}
goto free_and_fail;
}
ret = refresh_total_sectors(bs, bs->total_sectors);
if (ret < 0) {
error_setg_errno(errp, -ret, "Could not refresh total sector count");
goto free_and_fail;
}
bdrv_refresh_limits(bs, &local_err);
if (local_err) {
error_propagate(errp, local_err);
ret = -EINVAL;
goto free_and_fail;
}
assert(bdrv_opt_mem_align(bs) != 0);
assert(bdrv_min_mem_align(bs) != 0);
assert(is_power_of_2(bs->bl.request_alignment));
return 0;
free_and_fail:
/* FIXME Close bs first if already opened*/
g_free(bs->opaque);
bs->opaque = NULL;
bs->drv = NULL;
return ret;
}
| true | qemu | 180ca19ae02be70f9b158bfd7dec1ff123b9cf8c | static int bdrv_open_driver(BlockDriverState *bs, BlockDriver *drv,
const char *node_name, QDict *options,
int open_flags, Error **errp)
{
Error *local_err = NULL;
int ret;
bdrv_assign_node_name(bs, node_name, &local_err);
if (local_err) {
error_propagate(errp, local_err);
return -EINVAL;
}
bs->drv = drv;
bs->read_only = !(bs->open_flags & BDRV_O_RDWR);
bs->opaque = g_malloc0(drv->instance_size);
if (drv->bdrv_file_open) {
assert(!drv->bdrv_needs_filename || bs->filename[0]);
ret = drv->bdrv_file_open(bs, options, open_flags, &local_err);
} else if (drv->bdrv_open) {
ret = drv->bdrv_open(bs, options, open_flags, &local_err);
} else {
ret = 0;
}
if (ret < 0) {
if (local_err) {
error_propagate(errp, local_err);
} else if (bs->filename[0]) {
error_setg_errno(errp, -ret, "Could not open '%s'", bs->filename);
} else {
error_setg_errno(errp, -ret, "Could not open image");
}
goto free_and_fail;
}
ret = refresh_total_sectors(bs, bs->total_sectors);
if (ret < 0) {
error_setg_errno(errp, -ret, "Could not refresh total sector count");
goto free_and_fail;
}
bdrv_refresh_limits(bs, &local_err);
if (local_err) {
error_propagate(errp, local_err);
ret = -EINVAL;
goto free_and_fail;
}
assert(bdrv_opt_mem_align(bs) != 0);
assert(bdrv_min_mem_align(bs) != 0);
assert(is_power_of_2(bs->bl.request_alignment));
return 0;
free_and_fail:
g_free(bs->opaque);
bs->opaque = NULL;
bs->drv = NULL;
return ret;
}
| {
"code": [
" goto free_and_fail;",
" goto free_and_fail;",
" ret = -EINVAL;",
" goto free_and_fail;",
"free_and_fail:",
" bs->drv = NULL;"
],
"line_no": [
69,
69,
93,
69,
113,
121
]
} | static int FUNC_0(BlockDriverState *VAR_0, BlockDriver *VAR_1,
const char *VAR_2, QDict *VAR_3,
int VAR_4, Error **VAR_5)
{
Error *local_err = NULL;
int VAR_6;
bdrv_assign_node_name(VAR_0, VAR_2, &local_err);
if (local_err) {
error_propagate(VAR_5, local_err);
return -EINVAL;
}
VAR_0->VAR_1 = VAR_1;
VAR_0->read_only = !(VAR_0->VAR_4 & BDRV_O_RDWR);
VAR_0->opaque = g_malloc0(VAR_1->instance_size);
if (VAR_1->bdrv_file_open) {
assert(!VAR_1->bdrv_needs_filename || VAR_0->filename[0]);
VAR_6 = VAR_1->bdrv_file_open(VAR_0, VAR_3, VAR_4, &local_err);
} else if (VAR_1->bdrv_open) {
VAR_6 = VAR_1->bdrv_open(VAR_0, VAR_3, VAR_4, &local_err);
} else {
VAR_6 = 0;
}
if (VAR_6 < 0) {
if (local_err) {
error_propagate(VAR_5, local_err);
} else if (VAR_0->filename[0]) {
error_setg_errno(VAR_5, -VAR_6, "Could not open '%s'", VAR_0->filename);
} else {
error_setg_errno(VAR_5, -VAR_6, "Could not open image");
}
goto free_and_fail;
}
VAR_6 = refresh_total_sectors(VAR_0, VAR_0->total_sectors);
if (VAR_6 < 0) {
error_setg_errno(VAR_5, -VAR_6, "Could not refresh total sector count");
goto free_and_fail;
}
bdrv_refresh_limits(VAR_0, &local_err);
if (local_err) {
error_propagate(VAR_5, local_err);
VAR_6 = -EINVAL;
goto free_and_fail;
}
assert(bdrv_opt_mem_align(VAR_0) != 0);
assert(bdrv_min_mem_align(VAR_0) != 0);
assert(is_power_of_2(VAR_0->bl.request_alignment));
return 0;
free_and_fail:
g_free(VAR_0->opaque);
VAR_0->opaque = NULL;
VAR_0->VAR_1 = NULL;
return VAR_6;
}
| [
"static int FUNC_0(BlockDriverState *VAR_0, BlockDriver *VAR_1,\nconst char *VAR_2, QDict *VAR_3,\nint VAR_4, Error **VAR_5)\n{",
"Error *local_err = NULL;",
"int VAR_6;",
"bdrv_assign_node_name(VAR_0, VAR_2, &local_err);",
"if (local_err) {",
"error_propagate(VAR_5, local_err);",
"return -EINVAL;",
"}",
"VAR_0->VAR_1 = VAR_1;",
"VAR_0->read_only = !(VAR_0->VAR_4 & BDRV_O_RDWR);",
"VAR_0->opaque = g_malloc0(VAR_1->instance_size);",
"if (VAR_1->bdrv_file_open) {",
"assert(!VAR_1->bdrv_needs_filename || VAR_0->filename[0]);",
"VAR_6 = VAR_1->bdrv_file_open(VAR_0, VAR_3, VAR_4, &local_err);",
"} else if (VAR_1->bdrv_open) {",
"VAR_6 = VAR_1->bdrv_open(VAR_0, VAR_3, VAR_4, &local_err);",
"} else {",
"VAR_6 = 0;",
"}",
"if (VAR_6 < 0) {",
"if (local_err) {",
"error_propagate(VAR_5, local_err);",
"} else if (VAR_0->filename[0]) {",
"error_setg_errno(VAR_5, -VAR_6, \"Could not open '%s'\", VAR_0->filename);",
"} else {",
"error_setg_errno(VAR_5, -VAR_6, \"Could not open image\");",
"}",
"goto free_and_fail;",
"}",
"VAR_6 = refresh_total_sectors(VAR_0, VAR_0->total_sectors);",
"if (VAR_6 < 0) {",
"error_setg_errno(VAR_5, -VAR_6, \"Could not refresh total sector count\");",
"goto free_and_fail;",
"}",
"bdrv_refresh_limits(VAR_0, &local_err);",
"if (local_err) {",
"error_propagate(VAR_5, local_err);",
"VAR_6 = -EINVAL;",
"goto free_and_fail;",
"}",
"assert(bdrv_opt_mem_align(VAR_0) != 0);",
"assert(bdrv_min_mem_align(VAR_0) != 0);",
"assert(is_power_of_2(VAR_0->bl.request_alignment));",
"return 0;",
"free_and_fail:\ng_free(VAR_0->opaque);",
"VAR_0->opaque = NULL;",
"VAR_0->VAR_1 = NULL;",
"return VAR_6;",
"}"
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
1,
0,
0,
0,
0,
0,
0,
0,
0,
0,
1,
0,
0,
0,
0,
0,
0,
1,
0,
1,
0,
0
] | [
[
1,
3,
5,
7
],
[
9
],
[
11
],
[
15
],
[
17
],
[
19
],
[
21
],
[
23
],
[
27
],
[
29
],
[
31
],
[
35
],
[
37
],
[
39
],
[
41
],
[
43
],
[
45
],
[
47
],
[
49
],
[
53
],
[
55
],
[
57
],
[
59
],
[
61
],
[
63
],
[
65
],
[
67
],
[
69
],
[
71
],
[
75
],
[
77
],
[
79
],
[
81
],
[
83
],
[
87
],
[
89
],
[
91
],
[
93
],
[
95
],
[
97
],
[
101
],
[
103
],
[
105
],
[
109
],
[
113,
117
],
[
119
],
[
121
],
[
123
],
[
125
]
] |
21,401 | static int set_params(AVFilterContext *ctx, const char *params)
{
Frei0rContext *frei0r = ctx->priv;
int i;
for (i = 0; i < frei0r->plugin_info.num_params; i++) {
f0r_param_info_t info;
char *param;
int ret;
frei0r->get_param_info(&info, i);
if (*params) {
if (!(param = av_get_token(¶ms, "|")))
return AVERROR(ENOMEM);
params++; /* skip ':' */
ret = set_param(ctx, info, i, param);
av_free(param);
if (ret < 0)
return ret;
}
av_log(ctx, AV_LOG_VERBOSE,
"idx:%d name:'%s' type:%s explanation:'%s' ",
i, info.name,
info.type == F0R_PARAM_BOOL ? "bool" :
info.type == F0R_PARAM_DOUBLE ? "double" :
info.type == F0R_PARAM_COLOR ? "color" :
info.type == F0R_PARAM_POSITION ? "position" :
info.type == F0R_PARAM_STRING ? "string" : "unknown",
info.explanation);
#ifdef DEBUG
av_log(ctx, AV_LOG_DEBUG, "value:");
switch (info.type) {
void *v;
double d;
char s[128];
f0r_param_color_t col;
f0r_param_position_t pos;
case F0R_PARAM_BOOL:
v = &d;
frei0r->get_param_value(frei0r->instance, v, i);
av_log(ctx, AV_LOG_DEBUG, "%s", d >= 0.5 && d <= 1.0 ? "y" : "n");
break;
case F0R_PARAM_DOUBLE:
v = &d;
frei0r->get_param_value(frei0r->instance, v, i);
av_log(ctx, AV_LOG_DEBUG, "%f", d);
break;
case F0R_PARAM_COLOR:
v = &col;
frei0r->get_param_value(frei0r->instance, v, i);
av_log(ctx, AV_LOG_DEBUG, "%f/%f/%f", col.r, col.g, col.b);
break;
case F0R_PARAM_POSITION:
v = &pos;
frei0r->get_param_value(frei0r->instance, v, i);
av_log(ctx, AV_LOG_DEBUG, "%f/%f", pos.x, pos.y);
break;
default: /* F0R_PARAM_STRING */
v = s;
frei0r->get_param_value(frei0r->instance, v, i);
av_log(ctx, AV_LOG_DEBUG, "'%s'\n", s);
break;
}
#endif
av_log(ctx, AV_LOG_VERBOSE, "\n");
}
} | true | FFmpeg | e85ea7d387a34328c44a2e06c7098ffca341e310 | static int set_params(AVFilterContext *ctx, const char *params)
{
Frei0rContext *frei0r = ctx->priv;
int i;
for (i = 0; i < frei0r->plugin_info.num_params; i++) {
f0r_param_info_t info;
char *param;
int ret;
frei0r->get_param_info(&info, i);
if (*params) {
if (!(param = av_get_token(¶ms, "|")))
return AVERROR(ENOMEM);
params++;
ret = set_param(ctx, info, i, param);
av_free(param);
if (ret < 0)
return ret;
}
av_log(ctx, AV_LOG_VERBOSE,
"idx:%d name:'%s' type:%s explanation:'%s' ",
i, info.name,
info.type == F0R_PARAM_BOOL ? "bool" :
info.type == F0R_PARAM_DOUBLE ? "double" :
info.type == F0R_PARAM_COLOR ? "color" :
info.type == F0R_PARAM_POSITION ? "position" :
info.type == F0R_PARAM_STRING ? "string" : "unknown",
info.explanation);
#ifdef DEBUG
av_log(ctx, AV_LOG_DEBUG, "value:");
switch (info.type) {
void *v;
double d;
char s[128];
f0r_param_color_t col;
f0r_param_position_t pos;
case F0R_PARAM_BOOL:
v = &d;
frei0r->get_param_value(frei0r->instance, v, i);
av_log(ctx, AV_LOG_DEBUG, "%s", d >= 0.5 && d <= 1.0 ? "y" : "n");
break;
case F0R_PARAM_DOUBLE:
v = &d;
frei0r->get_param_value(frei0r->instance, v, i);
av_log(ctx, AV_LOG_DEBUG, "%f", d);
break;
case F0R_PARAM_COLOR:
v = &col;
frei0r->get_param_value(frei0r->instance, v, i);
av_log(ctx, AV_LOG_DEBUG, "%f/%f/%f", col.r, col.g, col.b);
break;
case F0R_PARAM_POSITION:
v = &pos;
frei0r->get_param_value(frei0r->instance, v, i);
av_log(ctx, AV_LOG_DEBUG, "%f/%f", pos.x, pos.y);
break;
default:
v = s;
frei0r->get_param_value(frei0r->instance, v, i);
av_log(ctx, AV_LOG_DEBUG, "'%s'\n", s);
break;
}
#endif
av_log(ctx, AV_LOG_VERBOSE, "\n");
}
} | {
"code": [],
"line_no": []
} | static int FUNC_0(AVFilterContext *VAR_0, const char *VAR_1)
{
Frei0rContext *frei0r = VAR_0->priv;
int VAR_2;
for (VAR_2 = 0; VAR_2 < frei0r->plugin_info.num_params; VAR_2++) {
f0r_param_info_t info;
char *param;
int ret;
frei0r->get_param_info(&info, VAR_2);
if (*VAR_1) {
if (!(param = av_get_token(&VAR_1, "|")))
return AVERROR(ENOMEM);
VAR_1++;
ret = set_param(VAR_0, info, VAR_2, param);
av_free(param);
if (ret < 0)
return ret;
}
av_log(VAR_0, AV_LOG_VERBOSE,
"idx:%d name:'%s' type:%s explanation:'%s' ",
VAR_2, info.name,
info.type == F0R_PARAM_BOOL ? "bool" :
info.type == F0R_PARAM_DOUBLE ? "double" :
info.type == F0R_PARAM_COLOR ? "color" :
info.type == F0R_PARAM_POSITION ? "position" :
info.type == F0R_PARAM_STRING ? "string" : "unknown",
info.explanation);
#ifdef DEBUG
av_log(VAR_0, AV_LOG_DEBUG, "value:");
switch (info.type) {
void *v;
double d;
char s[128];
f0r_param_color_t col;
f0r_param_position_t pos;
case F0R_PARAM_BOOL:
v = &d;
frei0r->get_param_value(frei0r->instance, v, VAR_2);
av_log(VAR_0, AV_LOG_DEBUG, "%s", d >= 0.5 && d <= 1.0 ? "y" : "n");
break;
case F0R_PARAM_DOUBLE:
v = &d;
frei0r->get_param_value(frei0r->instance, v, VAR_2);
av_log(VAR_0, AV_LOG_DEBUG, "%f", d);
break;
case F0R_PARAM_COLOR:
v = &col;
frei0r->get_param_value(frei0r->instance, v, VAR_2);
av_log(VAR_0, AV_LOG_DEBUG, "%f/%f/%f", col.r, col.g, col.b);
break;
case F0R_PARAM_POSITION:
v = &pos;
frei0r->get_param_value(frei0r->instance, v, VAR_2);
av_log(VAR_0, AV_LOG_DEBUG, "%f/%f", pos.x, pos.y);
break;
default:
v = s;
frei0r->get_param_value(frei0r->instance, v, VAR_2);
av_log(VAR_0, AV_LOG_DEBUG, "'%s'\n", s);
break;
}
#endif
av_log(VAR_0, AV_LOG_VERBOSE, "\n");
}
} | [
"static int FUNC_0(AVFilterContext *VAR_0, const char *VAR_1)\n{",
"Frei0rContext *frei0r = VAR_0->priv;",
"int VAR_2;",
"for (VAR_2 = 0; VAR_2 < frei0r->plugin_info.num_params; VAR_2++) {",
"f0r_param_info_t info;",
"char *param;",
"int ret;",
"frei0r->get_param_info(&info, VAR_2);",
"if (*VAR_1) {",
"if (!(param = av_get_token(&VAR_1, \"|\")))\nreturn AVERROR(ENOMEM);",
"VAR_1++;",
"ret = set_param(VAR_0, info, VAR_2, param);",
"av_free(param);",
"if (ret < 0)\nreturn ret;",
"}",
"av_log(VAR_0, AV_LOG_VERBOSE,\n\"idx:%d name:'%s' type:%s explanation:'%s' \",\nVAR_2, info.name,\ninfo.type == F0R_PARAM_BOOL ? \"bool\" :\ninfo.type == F0R_PARAM_DOUBLE ? \"double\" :\ninfo.type == F0R_PARAM_COLOR ? \"color\" :\ninfo.type == F0R_PARAM_POSITION ? \"position\" :\ninfo.type == F0R_PARAM_STRING ? \"string\" : \"unknown\",\ninfo.explanation);",
"#ifdef DEBUG\nav_log(VAR_0, AV_LOG_DEBUG, \"value:\");",
"switch (info.type) {",
"void *v;",
"double d;",
"char s[128];",
"f0r_param_color_t col;",
"f0r_param_position_t pos;",
"case F0R_PARAM_BOOL:\nv = &d;",
"frei0r->get_param_value(frei0r->instance, v, VAR_2);",
"av_log(VAR_0, AV_LOG_DEBUG, \"%s\", d >= 0.5 && d <= 1.0 ? \"y\" : \"n\");",
"break;",
"case F0R_PARAM_DOUBLE:\nv = &d;",
"frei0r->get_param_value(frei0r->instance, v, VAR_2);",
"av_log(VAR_0, AV_LOG_DEBUG, \"%f\", d);",
"break;",
"case F0R_PARAM_COLOR:\nv = &col;",
"frei0r->get_param_value(frei0r->instance, v, VAR_2);",
"av_log(VAR_0, AV_LOG_DEBUG, \"%f/%f/%f\", col.r, col.g, col.b);",
"break;",
"case F0R_PARAM_POSITION:\nv = &pos;",
"frei0r->get_param_value(frei0r->instance, v, VAR_2);",
"av_log(VAR_0, AV_LOG_DEBUG, \"%f/%f\", pos.x, pos.y);",
"break;",
"default:\nv = s;",
"frei0r->get_param_value(frei0r->instance, v, VAR_2);",
"av_log(VAR_0, AV_LOG_DEBUG, \"'%s'\\n\", s);",
"break;",
"}",
"#endif\nav_log(VAR_0, AV_LOG_VERBOSE, \"\\n\");",
"}",
"}"
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | [
[
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
]
] |
21,402 | void do_load_fpscr (void)
{
/* The 32 MSB of the target fpr are undefined.
* They'll be zero...
*/
union {
float64 d;
struct {
uint32_t u[2];
} s;
} u;
int i;
#ifdef WORDS_BIGENDIAN
#define WORD0 0
#define WORD1 1
#else
#define WORD0 1
#define WORD1 0
#endif
u.s.u[WORD0] = 0;
u.s.u[WORD1] = 0;
for (i = 0; i < 8; i++)
u.s.u[WORD1] |= env->fpscr[i] << (4 * i);
FT0 = u.d;
}
| true | qemu | d9bce9d99f4656ae0b0127f7472db9067b8f84ab | void do_load_fpscr (void)
{
union {
float64 d;
struct {
uint32_t u[2];
} s;
} u;
int i;
#ifdef WORDS_BIGENDIAN
#define WORD0 0
#define WORD1 1
#else
#define WORD0 1
#define WORD1 0
#endif
u.s.u[WORD0] = 0;
u.s.u[WORD1] = 0;
for (i = 0; i < 8; i++)
u.s.u[WORD1] |= env->fpscr[i] << (4 * i);
FT0 = u.d;
}
| {
"code": [
"#else",
"#ifdef WORDS_BIGENDIAN",
"#endif",
"#else",
"#endif"
],
"line_no": [
33,
27,
39,
33,
39
]
} | void FUNC_0 (void)
{
union {
float64 d;
struct {
uint32_t VAR_0[2];
} s;
} VAR_0;
int VAR_1;
#ifdef WORDS_BIGENDIAN
#define WORD0 0
#define WORD1 1
#else
#define WORD0 1
#define WORD1 0
#endif
VAR_0.s.VAR_0[WORD0] = 0;
VAR_0.s.VAR_0[WORD1] = 0;
for (VAR_1 = 0; VAR_1 < 8; VAR_1++)
VAR_0.s.VAR_0[WORD1] |= env->fpscr[VAR_1] << (4 * VAR_1);
FT0 = VAR_0.d;
}
| [
"void FUNC_0 (void)\n{",
"union {",
"float64 d;",
"struct {",
"uint32_t VAR_0[2];",
"} s;",
"} VAR_0;",
"int VAR_1;",
"#ifdef WORDS_BIGENDIAN\n#define WORD0 0\n#define WORD1 1\n#else\n#define WORD0 1\n#define WORD1 0\n#endif\nVAR_0.s.VAR_0[WORD0] = 0;",
"VAR_0.s.VAR_0[WORD1] = 0;",
"for (VAR_1 = 0; VAR_1 < 8; VAR_1++)",
"VAR_0.s.VAR_0[WORD1] |= env->fpscr[VAR_1] << (4 * VAR_1);",
"FT0 = VAR_0.d;",
"}"
] | [
0,
0,
0,
0,
0,
0,
0,
0,
1,
0,
0,
0,
0,
0
] | [
[
1,
3
],
[
11
],
[
13
],
[
15
],
[
17
],
[
19
],
[
21
],
[
23
],
[
27,
29,
31,
33,
35,
37,
39,
41
],
[
43
],
[
45
],
[
47
],
[
49
],
[
51
]
] |
21,403 | static int prepare_sdp_description(FFStream *stream, uint8_t **pbuffer,
struct in_addr my_ip)
{
AVFormatContext *avc;
AVStream *avs = NULL;
AVOutputFormat *rtp_format = av_guess_format("rtp", NULL, NULL);
AVDictionaryEntry *entry = av_dict_get(stream->metadata, "title", NULL, 0);
int i;
avc = avformat_alloc_context();
if (avc == NULL || !rtp_format) {
return -1;
}
avc->oformat = rtp_format;
av_dict_set(&avc->metadata, "title",
entry ? entry->value : "No Title", 0);
avc->nb_streams = stream->nb_streams;
if (stream->is_multicast) {
snprintf(avc->filename, 1024, "rtp://%s:%d?multicast=1?ttl=%d",
inet_ntoa(stream->multicast_ip),
stream->multicast_port, stream->multicast_ttl);
} else {
snprintf(avc->filename, 1024, "rtp://0.0.0.0");
}
if (avc->nb_streams >= INT_MAX/sizeof(*avc->streams) ||
!(avc->streams = av_malloc(avc->nb_streams * sizeof(*avc->streams))))
goto sdp_done;
if (avc->nb_streams >= INT_MAX/sizeof(*avs) ||
!(avs = av_malloc(avc->nb_streams * sizeof(*avs))))
goto sdp_done;
for(i = 0; i < stream->nb_streams; i++) {
avc->streams[i] = &avs[i];
avc->streams[i]->codec = stream->streams[i]->codec;
}
*pbuffer = av_mallocz(2048);
av_sdp_create(&avc, 1, *pbuffer, 2048);
sdp_done:
av_free(avc->streams);
av_dict_free(&avc->metadata);
av_free(avc);
av_free(avs);
return strlen(*pbuffer);
}
| false | FFmpeg | 1d8d21b90ab91aa471f369e0f9d1ea20fb40733b | static int prepare_sdp_description(FFStream *stream, uint8_t **pbuffer,
struct in_addr my_ip)
{
AVFormatContext *avc;
AVStream *avs = NULL;
AVOutputFormat *rtp_format = av_guess_format("rtp", NULL, NULL);
AVDictionaryEntry *entry = av_dict_get(stream->metadata, "title", NULL, 0);
int i;
avc = avformat_alloc_context();
if (avc == NULL || !rtp_format) {
return -1;
}
avc->oformat = rtp_format;
av_dict_set(&avc->metadata, "title",
entry ? entry->value : "No Title", 0);
avc->nb_streams = stream->nb_streams;
if (stream->is_multicast) {
snprintf(avc->filename, 1024, "rtp:
inet_ntoa(stream->multicast_ip),
stream->multicast_port, stream->multicast_ttl);
} else {
snprintf(avc->filename, 1024, "rtp:
}
if (avc->nb_streams >= INT_MAX/sizeof(*avc->streams) ||
!(avc->streams = av_malloc(avc->nb_streams * sizeof(*avc->streams))))
goto sdp_done;
if (avc->nb_streams >= INT_MAX/sizeof(*avs) ||
!(avs = av_malloc(avc->nb_streams * sizeof(*avs))))
goto sdp_done;
for(i = 0; i < stream->nb_streams; i++) {
avc->streams[i] = &avs[i];
avc->streams[i]->codec = stream->streams[i]->codec;
}
*pbuffer = av_mallocz(2048);
av_sdp_create(&avc, 1, *pbuffer, 2048);
sdp_done:
av_free(avc->streams);
av_dict_free(&avc->metadata);
av_free(avc);
av_free(avs);
return strlen(*pbuffer);
}
| {
"code": [],
"line_no": []
} | static int FUNC_0(FFStream *VAR_0, uint8_t **VAR_1,
struct in_addr VAR_2)
{
AVFormatContext *avc;
AVStream *avs = NULL;
AVOutputFormat *rtp_format = av_guess_format("rtp", NULL, NULL);
AVDictionaryEntry *entry = av_dict_get(VAR_0->metadata, "title", NULL, 0);
int VAR_3;
avc = avformat_alloc_context();
if (avc == NULL || !rtp_format) {
return -1;
}
avc->oformat = rtp_format;
av_dict_set(&avc->metadata, "title",
entry ? entry->value : "No Title", 0);
avc->nb_streams = VAR_0->nb_streams;
if (VAR_0->is_multicast) {
snprintf(avc->filename, 1024, "rtp:
inet_ntoa(VAR_0->multicast_ip),
VAR_0->multicast_port, VAR_0->multicast_ttl);
} else {
snprintf(avc->filename, 1024, "rtp:
}
if (avc->nb_streams >= INT_MAX/sizeof(*avc->streams) ||
!(avc->streams = av_malloc(avc->nb_streams * sizeof(*avc->streams))))
goto sdp_done;
if (avc->nb_streams >= INT_MAX/sizeof(*avs) ||
!(avs = av_malloc(avc->nb_streams * sizeof(*avs))))
goto sdp_done;
for(VAR_3 = 0; VAR_3 < VAR_0->nb_streams; VAR_3++) {
avc->streams[VAR_3] = &avs[VAR_3];
avc->streams[VAR_3]->codec = VAR_0->streams[VAR_3]->codec;
}
*VAR_1 = av_mallocz(2048);
av_sdp_create(&avc, 1, *VAR_1, 2048);
sdp_done:
av_free(avc->streams);
av_dict_free(&avc->metadata);
av_free(avc);
av_free(avs);
return strlen(*VAR_1);
}
| [
"static int FUNC_0(FFStream *VAR_0, uint8_t **VAR_1,\nstruct in_addr VAR_2)\n{",
"AVFormatContext *avc;",
"AVStream *avs = NULL;",
"AVOutputFormat *rtp_format = av_guess_format(\"rtp\", NULL, NULL);",
"AVDictionaryEntry *entry = av_dict_get(VAR_0->metadata, \"title\", NULL, 0);",
"int VAR_3;",
"avc = avformat_alloc_context();",
"if (avc == NULL || !rtp_format) {",
"return -1;",
"}",
"avc->oformat = rtp_format;",
"av_dict_set(&avc->metadata, \"title\",\nentry ? entry->value : \"No Title\", 0);",
"avc->nb_streams = VAR_0->nb_streams;",
"if (VAR_0->is_multicast) {",
"snprintf(avc->filename, 1024, \"rtp:\ninet_ntoa(VAR_0->multicast_ip),\nVAR_0->multicast_port, VAR_0->multicast_ttl);",
"} else {",
"snprintf(avc->filename, 1024, \"rtp:\n}",
"if (avc->nb_streams >= INT_MAX/sizeof(*avc->streams) ||\n!(avc->streams = av_malloc(avc->nb_streams * sizeof(*avc->streams))))\ngoto sdp_done;",
"if (avc->nb_streams >= INT_MAX/sizeof(*avs) ||\n!(avs = av_malloc(avc->nb_streams * sizeof(*avs))))\ngoto sdp_done;",
"for(VAR_3 = 0; VAR_3 < VAR_0->nb_streams; VAR_3++) {",
"avc->streams[VAR_3] = &avs[VAR_3];",
"avc->streams[VAR_3]->codec = VAR_0->streams[VAR_3]->codec;",
"}",
"*VAR_1 = av_mallocz(2048);",
"av_sdp_create(&avc, 1, *VAR_1, 2048);",
"sdp_done:\nav_free(avc->streams);",
"av_dict_free(&avc->metadata);",
"av_free(avc);",
"av_free(avs);",
"return strlen(*VAR_1);",
"}"
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | [
[
1,
3,
5
],
[
7
],
[
9
],
[
11
],
[
13
],
[
15
],
[
19
],
[
21
],
[
23
],
[
25
],
[
27
],
[
29,
31
],
[
33
],
[
35
],
[
37,
39,
41
],
[
43
],
[
45,
47
],
[
51,
53,
55
],
[
57,
59,
61
],
[
65
],
[
67
],
[
69
],
[
71
],
[
73
],
[
75
],
[
79,
81
],
[
83
],
[
85
],
[
87
],
[
91
],
[
93
]
] |
21,404 | static void decode_init_vlc(H264Context *h){
static int done = 0;
if (!done) {
int i;
done = 1;
init_vlc(&chroma_dc_coeff_token_vlc, CHROMA_DC_COEFF_TOKEN_VLC_BITS, 4*5,
&chroma_dc_coeff_token_len [0], 1, 1,
&chroma_dc_coeff_token_bits[0], 1, 1);
for(i=0; i<4; i++){
init_vlc(&coeff_token_vlc[i], COEFF_TOKEN_VLC_BITS, 4*17,
&coeff_token_len [i][0], 1, 1,
&coeff_token_bits[i][0], 1, 1);
}
for(i=0; i<3; i++){
init_vlc(&chroma_dc_total_zeros_vlc[i], CHROMA_DC_TOTAL_ZEROS_VLC_BITS, 4,
&chroma_dc_total_zeros_len [i][0], 1, 1,
&chroma_dc_total_zeros_bits[i][0], 1, 1);
}
for(i=0; i<15; i++){
init_vlc(&total_zeros_vlc[i], TOTAL_ZEROS_VLC_BITS, 16,
&total_zeros_len [i][0], 1, 1,
&total_zeros_bits[i][0], 1, 1);
}
for(i=0; i<6; i++){
init_vlc(&run_vlc[i], RUN_VLC_BITS, 7,
&run_len [i][0], 1, 1,
&run_bits[i][0], 1, 1);
}
init_vlc(&run7_vlc, RUN7_VLC_BITS, 16,
&run_len [6][0], 1, 1,
&run_bits[6][0], 1, 1);
}
}
| true | FFmpeg | 073c2593c9f0aa4445a6fc1b9b24e6e52a8cc2c1 | static void decode_init_vlc(H264Context *h){
static int done = 0;
if (!done) {
int i;
done = 1;
init_vlc(&chroma_dc_coeff_token_vlc, CHROMA_DC_COEFF_TOKEN_VLC_BITS, 4*5,
&chroma_dc_coeff_token_len [0], 1, 1,
&chroma_dc_coeff_token_bits[0], 1, 1);
for(i=0; i<4; i++){
init_vlc(&coeff_token_vlc[i], COEFF_TOKEN_VLC_BITS, 4*17,
&coeff_token_len [i][0], 1, 1,
&coeff_token_bits[i][0], 1, 1);
}
for(i=0; i<3; i++){
init_vlc(&chroma_dc_total_zeros_vlc[i], CHROMA_DC_TOTAL_ZEROS_VLC_BITS, 4,
&chroma_dc_total_zeros_len [i][0], 1, 1,
&chroma_dc_total_zeros_bits[i][0], 1, 1);
}
for(i=0; i<15; i++){
init_vlc(&total_zeros_vlc[i], TOTAL_ZEROS_VLC_BITS, 16,
&total_zeros_len [i][0], 1, 1,
&total_zeros_bits[i][0], 1, 1);
}
for(i=0; i<6; i++){
init_vlc(&run_vlc[i], RUN_VLC_BITS, 7,
&run_len [i][0], 1, 1,
&run_bits[i][0], 1, 1);
}
init_vlc(&run7_vlc, RUN7_VLC_BITS, 16,
&run_len [6][0], 1, 1,
&run_bits[6][0], 1, 1);
}
}
| {
"code": [
" static int done = 0;",
" if (!done) {",
" done = 1;",
" for(i=0; i<4; i++){",
" &chroma_dc_coeff_token_bits[0], 1, 1);",
" &coeff_token_bits[i][0], 1, 1);",
" &chroma_dc_total_zeros_bits[i][0], 1, 1);",
" &total_zeros_bits[i][0], 1, 1);",
" &run_bits[i][0], 1, 1);",
" &run_bits[6][0], 1, 1);"
],
"line_no": [
3,
7,
11,
23,
19,
29,
41,
51,
63,
71
]
} | static void FUNC_0(H264Context *VAR_0){
static int VAR_1 = 0;
if (!VAR_1) {
int VAR_2;
VAR_1 = 1;
init_vlc(&chroma_dc_coeff_token_vlc, CHROMA_DC_COEFF_TOKEN_VLC_BITS, 4*5,
&chroma_dc_coeff_token_len [0], 1, 1,
&chroma_dc_coeff_token_bits[0], 1, 1);
for(VAR_2=0; VAR_2<4; VAR_2++){
init_vlc(&coeff_token_vlc[VAR_2], COEFF_TOKEN_VLC_BITS, 4*17,
&coeff_token_len [VAR_2][0], 1, 1,
&coeff_token_bits[VAR_2][0], 1, 1);
}
for(VAR_2=0; VAR_2<3; VAR_2++){
init_vlc(&chroma_dc_total_zeros_vlc[VAR_2], CHROMA_DC_TOTAL_ZEROS_VLC_BITS, 4,
&chroma_dc_total_zeros_len [VAR_2][0], 1, 1,
&chroma_dc_total_zeros_bits[VAR_2][0], 1, 1);
}
for(VAR_2=0; VAR_2<15; VAR_2++){
init_vlc(&total_zeros_vlc[VAR_2], TOTAL_ZEROS_VLC_BITS, 16,
&total_zeros_len [VAR_2][0], 1, 1,
&total_zeros_bits[VAR_2][0], 1, 1);
}
for(VAR_2=0; VAR_2<6; VAR_2++){
init_vlc(&run_vlc[VAR_2], RUN_VLC_BITS, 7,
&run_len [VAR_2][0], 1, 1,
&run_bits[VAR_2][0], 1, 1);
}
init_vlc(&run7_vlc, RUN7_VLC_BITS, 16,
&run_len [6][0], 1, 1,
&run_bits[6][0], 1, 1);
}
}
| [
"static void FUNC_0(H264Context *VAR_0){",
"static int VAR_1 = 0;",
"if (!VAR_1) {",
"int VAR_2;",
"VAR_1 = 1;",
"init_vlc(&chroma_dc_coeff_token_vlc, CHROMA_DC_COEFF_TOKEN_VLC_BITS, 4*5,\n&chroma_dc_coeff_token_len [0], 1, 1,\n&chroma_dc_coeff_token_bits[0], 1, 1);",
"for(VAR_2=0; VAR_2<4; VAR_2++){",
"init_vlc(&coeff_token_vlc[VAR_2], COEFF_TOKEN_VLC_BITS, 4*17,\n&coeff_token_len [VAR_2][0], 1, 1,\n&coeff_token_bits[VAR_2][0], 1, 1);",
"}",
"for(VAR_2=0; VAR_2<3; VAR_2++){",
"init_vlc(&chroma_dc_total_zeros_vlc[VAR_2], CHROMA_DC_TOTAL_ZEROS_VLC_BITS, 4,\n&chroma_dc_total_zeros_len [VAR_2][0], 1, 1,\n&chroma_dc_total_zeros_bits[VAR_2][0], 1, 1);",
"}",
"for(VAR_2=0; VAR_2<15; VAR_2++){",
"init_vlc(&total_zeros_vlc[VAR_2], TOTAL_ZEROS_VLC_BITS, 16,\n&total_zeros_len [VAR_2][0], 1, 1,\n&total_zeros_bits[VAR_2][0], 1, 1);",
"}",
"for(VAR_2=0; VAR_2<6; VAR_2++){",
"init_vlc(&run_vlc[VAR_2], RUN_VLC_BITS, 7,\n&run_len [VAR_2][0], 1, 1,\n&run_bits[VAR_2][0], 1, 1);",
"}",
"init_vlc(&run7_vlc, RUN7_VLC_BITS, 16,\n&run_len [6][0], 1, 1,\n&run_bits[6][0], 1, 1);",
"}",
"}"
] | [
0,
1,
1,
0,
1,
1,
1,
1,
0,
0,
1,
0,
0,
1,
0,
0,
1,
0,
1,
0,
0
] | [
[
1
],
[
3
],
[
7
],
[
9
],
[
11
],
[
15,
17,
19
],
[
23
],
[
25,
27,
29
],
[
31
],
[
35
],
[
37,
39,
41
],
[
43
],
[
45
],
[
47,
49,
51
],
[
53
],
[
57
],
[
59,
61,
63
],
[
65
],
[
67,
69,
71
],
[
73
],
[
75
]
] |
21,405 | int av_buffersink_poll_frame(AVFilterContext *ctx)
{
BufferSinkContext *buf = ctx->priv;
AVFilterLink *inlink = ctx->inputs[0];
av_assert0(!strcmp(ctx->filter->name, "buffersink") || !strcmp(ctx->filter->name, "abuffersink"));
return av_fifo_size(buf->fifo)/sizeof(AVFilterBufferRef *) + ff_poll_frame(inlink);
}
| true | FFmpeg | e4e02a7d4726e9370127741eb2873d6671d3f0c3 | int av_buffersink_poll_frame(AVFilterContext *ctx)
{
BufferSinkContext *buf = ctx->priv;
AVFilterLink *inlink = ctx->inputs[0];
av_assert0(!strcmp(ctx->filter->name, "buffersink") || !strcmp(ctx->filter->name, "abuffersink"));
return av_fifo_size(buf->fifo)/sizeof(AVFilterBufferRef *) + ff_poll_frame(inlink);
}
| {
"code": [
" av_assert0(!strcmp(ctx->filter->name, \"buffersink\") || !strcmp(ctx->filter->name, \"abuffersink\"));",
" av_assert0(!strcmp(ctx->filter->name, \"buffersink\") || !strcmp(ctx->filter->name, \"abuffersink\"));"
],
"line_no": [
11,
11
]
} | int FUNC_0(AVFilterContext *VAR_0)
{
BufferSinkContext *buf = VAR_0->priv;
AVFilterLink *inlink = VAR_0->inputs[0];
av_assert0(!strcmp(VAR_0->filter->name, "buffersink") || !strcmp(VAR_0->filter->name, "abuffersink"));
return av_fifo_size(buf->fifo)/sizeof(AVFilterBufferRef *) + ff_poll_frame(inlink);
}
| [
"int FUNC_0(AVFilterContext *VAR_0)\n{",
"BufferSinkContext *buf = VAR_0->priv;",
"AVFilterLink *inlink = VAR_0->inputs[0];",
"av_assert0(!strcmp(VAR_0->filter->name, \"buffersink\") || !strcmp(VAR_0->filter->name, \"abuffersink\"));",
"return av_fifo_size(buf->fifo)/sizeof(AVFilterBufferRef *) + ff_poll_frame(inlink);",
"}"
] | [
0,
0,
0,
1,
0,
0
] | [
[
1,
3
],
[
5
],
[
7
],
[
11
],
[
15
],
[
17
]
] |
21,406 | int ff_h263_decode_frame(AVCodecContext *avctx,
void *data, int *data_size,
AVPacket *avpkt)
{
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
MpegEncContext *s = avctx->priv_data;
int ret;
AVFrame *pict = data;
#ifdef PRINT_FRAME_TIME
uint64_t time= rdtsc();
#endif
s->flags= avctx->flags;
s->flags2= avctx->flags2;
/* no supplementary picture */
if (buf_size == 0) {
/* special case for last picture */
if (s->low_delay==0 && s->next_picture_ptr) {
*pict = s->next_picture_ptr->f;
s->next_picture_ptr= NULL;
*data_size = sizeof(AVFrame);
}
return 0;
}
if(s->flags&CODEC_FLAG_TRUNCATED){
int next;
if(CONFIG_MPEG4_DECODER && s->codec_id==CODEC_ID_MPEG4){
next= ff_mpeg4_find_frame_end(&s->parse_context, buf, buf_size);
}else if(CONFIG_H263_DECODER && s->codec_id==CODEC_ID_H263){
next= ff_h263_find_frame_end(&s->parse_context, buf, buf_size);
}else{
av_log(s->avctx, AV_LOG_ERROR, "this codec does not support truncated bitstreams\n");
return -1;
}
if( ff_combine_frame(&s->parse_context, next, (const uint8_t **)&buf, &buf_size) < 0 )
return buf_size;
}
retry:
if(s->bitstream_buffer_size && (s->divx_packed || buf_size<20)){ //divx 5.01+/xvid frame reorder
init_get_bits(&s->gb, s->bitstream_buffer, s->bitstream_buffer_size*8);
}else
init_get_bits(&s->gb, buf, buf_size*8);
s->bitstream_buffer_size=0;
if (!s->context_initialized) {
if (ff_MPV_common_init(s) < 0) //we need the idct permutaton for reading a custom matrix
return -1;
}
/* We need to set current_picture_ptr before reading the header,
* otherwise we cannot store anyting in there */
if (s->current_picture_ptr == NULL || s->current_picture_ptr->f.data[0]) {
int i= ff_find_unused_picture(s, 0);
if (i < 0)
return i;
s->current_picture_ptr= &s->picture[i];
}
/* let's go :-) */
if (CONFIG_WMV2_DECODER && s->msmpeg4_version==5) {
ret= ff_wmv2_decode_picture_header(s);
} else if (CONFIG_MSMPEG4_DECODER && s->msmpeg4_version) {
ret = ff_msmpeg4_decode_picture_header(s);
} else if (CONFIG_MPEG4_DECODER && s->h263_pred) {
if(s->avctx->extradata_size && s->picture_number==0){
GetBitContext gb;
init_get_bits(&gb, s->avctx->extradata, s->avctx->extradata_size*8);
ret = ff_mpeg4_decode_picture_header(s, &gb);
}
ret = ff_mpeg4_decode_picture_header(s, &s->gb);
} else if (CONFIG_H263I_DECODER && s->codec_id == CODEC_ID_H263I) {
ret = ff_intel_h263_decode_picture_header(s);
} else if (CONFIG_FLV_DECODER && s->h263_flv) {
ret = ff_flv_decode_picture_header(s);
} else {
ret = ff_h263_decode_picture_header(s);
}
if(ret==FRAME_SKIPPED) return get_consumed_bytes(s, buf_size);
/* skip if the header was thrashed */
if (ret < 0){
av_log(s->avctx, AV_LOG_ERROR, "header damaged\n");
return -1;
}
avctx->has_b_frames= !s->low_delay;
if(s->xvid_build==-1 && s->divx_version==-1 && s->lavc_build==-1){
if(s->stream_codec_tag == AV_RL32("XVID") ||
s->codec_tag == AV_RL32("XVID") || s->codec_tag == AV_RL32("XVIX") ||
s->codec_tag == AV_RL32("RMP4") ||
s->codec_tag == AV_RL32("SIPP")
)
s->xvid_build= 0;
#if 0
if(s->codec_tag == AV_RL32("DIVX") && s->vo_type==0 && s->vol_control_parameters==1
&& s->padding_bug_score > 0 && s->low_delay) // XVID with modified fourcc
s->xvid_build= 0;
#endif
}
if(s->xvid_build==-1 && s->divx_version==-1 && s->lavc_build==-1){
if(s->codec_tag == AV_RL32("DIVX") && s->vo_type==0 && s->vol_control_parameters==0)
s->divx_version= 400; //divx 4
}
if(s->xvid_build>=0 && s->divx_version>=0){
s->divx_version=
s->divx_build= -1;
}
if(s->workaround_bugs&FF_BUG_AUTODETECT){
if(s->codec_tag == AV_RL32("XVIX"))
s->workaround_bugs|= FF_BUG_XVID_ILACE;
if(s->codec_tag == AV_RL32("UMP4")){
s->workaround_bugs|= FF_BUG_UMP4;
}
if(s->divx_version>=500 && s->divx_build<1814){
s->workaround_bugs|= FF_BUG_QPEL_CHROMA;
}
if(s->divx_version>502 && s->divx_build<1814){
s->workaround_bugs|= FF_BUG_QPEL_CHROMA2;
}
if(s->xvid_build<=3U)
s->padding_bug_score= 256*256*256*64;
if(s->xvid_build<=1U)
s->workaround_bugs|= FF_BUG_QPEL_CHROMA;
if(s->xvid_build<=12U)
s->workaround_bugs|= FF_BUG_EDGE;
if(s->xvid_build<=32U)
s->workaround_bugs|= FF_BUG_DC_CLIP;
#define SET_QPEL_FUNC(postfix1, postfix2) \
s->dsp.put_ ## postfix1 = ff_put_ ## postfix2;\
s->dsp.put_no_rnd_ ## postfix1 = ff_put_no_rnd_ ## postfix2;\
s->dsp.avg_ ## postfix1 = ff_avg_ ## postfix2;
if(s->lavc_build<4653U)
s->workaround_bugs|= FF_BUG_STD_QPEL;
if(s->lavc_build<4655U)
s->workaround_bugs|= FF_BUG_DIRECT_BLOCKSIZE;
if(s->lavc_build<4670U){
s->workaround_bugs|= FF_BUG_EDGE;
}
if(s->lavc_build<=4712U)
s->workaround_bugs|= FF_BUG_DC_CLIP;
if(s->divx_version>=0)
s->workaround_bugs|= FF_BUG_DIRECT_BLOCKSIZE;
//printf("padding_bug_score: %d\n", s->padding_bug_score);
if(s->divx_version==501 && s->divx_build==20020416)
s->padding_bug_score= 256*256*256*64;
if(s->divx_version<500U){
s->workaround_bugs|= FF_BUG_EDGE;
}
if(s->divx_version>=0)
s->workaround_bugs|= FF_BUG_HPEL_CHROMA;
#if 0
if(s->divx_version==500)
s->padding_bug_score= 256*256*256*64;
/* very ugly XVID padding bug detection FIXME/XXX solve this differently
* Let us hope this at least works.
*/
if( s->resync_marker==0 && s->data_partitioning==0 && s->divx_version==-1
&& s->codec_id==CODEC_ID_MPEG4 && s->vo_type==0)
s->workaround_bugs|= FF_BUG_NO_PADDING;
if(s->lavc_build<4609U) //FIXME not sure about the version num but a 4609 file seems ok
s->workaround_bugs|= FF_BUG_NO_PADDING;
#endif
}
if(s->workaround_bugs& FF_BUG_STD_QPEL){
SET_QPEL_FUNC(qpel_pixels_tab[0][ 5], qpel16_mc11_old_c)
SET_QPEL_FUNC(qpel_pixels_tab[0][ 7], qpel16_mc31_old_c)
SET_QPEL_FUNC(qpel_pixels_tab[0][ 9], qpel16_mc12_old_c)
SET_QPEL_FUNC(qpel_pixels_tab[0][11], qpel16_mc32_old_c)
SET_QPEL_FUNC(qpel_pixels_tab[0][13], qpel16_mc13_old_c)
SET_QPEL_FUNC(qpel_pixels_tab[0][15], qpel16_mc33_old_c)
SET_QPEL_FUNC(qpel_pixels_tab[1][ 5], qpel8_mc11_old_c)
SET_QPEL_FUNC(qpel_pixels_tab[1][ 7], qpel8_mc31_old_c)
SET_QPEL_FUNC(qpel_pixels_tab[1][ 9], qpel8_mc12_old_c)
SET_QPEL_FUNC(qpel_pixels_tab[1][11], qpel8_mc32_old_c)
SET_QPEL_FUNC(qpel_pixels_tab[1][13], qpel8_mc13_old_c)
SET_QPEL_FUNC(qpel_pixels_tab[1][15], qpel8_mc33_old_c)
}
if(avctx->debug & FF_DEBUG_BUGS)
av_log(s->avctx, AV_LOG_DEBUG, "bugs: %X lavc_build:%d xvid_build:%d divx_version:%d divx_build:%d %s\n",
s->workaround_bugs, s->lavc_build, s->xvid_build, s->divx_version, s->divx_build,
s->divx_packed ? "p" : "");
#if HAVE_MMX
if (s->codec_id == CODEC_ID_MPEG4 && s->xvid_build>=0 && avctx->idct_algo == FF_IDCT_AUTO && (av_get_cpu_flags() & AV_CPU_FLAG_MMX)) {
avctx->idct_algo= FF_IDCT_XVIDMMX;
avctx->coded_width= 0; // force reinit
// ff_dsputil_init(&s->dsp, avctx);
s->picture_number=0;
}
#endif
/* After H263 & mpeg4 header decode we have the height, width,*/
/* and other parameters. So then we could init the picture */
/* FIXME: By the way H263 decoder is evolving it should have */
/* an H263EncContext */
if ( s->width != avctx->coded_width
|| s->height != avctx->coded_height) {
/* H.263 could change picture size any time */
ParseContext pc= s->parse_context; //FIXME move these demuxng hack to avformat
s->parse_context.buffer=0;
ff_MPV_common_end(s);
s->parse_context= pc;
}
if (!s->context_initialized) {
avcodec_set_dimensions(avctx, s->width, s->height);
goto retry;
}
if((s->codec_id==CODEC_ID_H263 || s->codec_id==CODEC_ID_H263P || s->codec_id == CODEC_ID_H263I))
s->gob_index = ff_h263_get_gob_height(s);
// for skipping the frame
s->current_picture.f.pict_type = s->pict_type;
s->current_picture.f.key_frame = s->pict_type == AV_PICTURE_TYPE_I;
/* skip B-frames if we don't have reference frames */
if(s->last_picture_ptr==NULL && (s->pict_type==AV_PICTURE_TYPE_B || s->dropable)) return get_consumed_bytes(s, buf_size);
if( (avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type==AV_PICTURE_TYPE_B)
|| (avctx->skip_frame >= AVDISCARD_NONKEY && s->pict_type!=AV_PICTURE_TYPE_I)
|| avctx->skip_frame >= AVDISCARD_ALL)
return get_consumed_bytes(s, buf_size);
if(s->next_p_frame_damaged){
if(s->pict_type==AV_PICTURE_TYPE_B)
return get_consumed_bytes(s, buf_size);
else
s->next_p_frame_damaged=0;
}
if((s->avctx->flags2 & CODEC_FLAG2_FAST) && s->pict_type==AV_PICTURE_TYPE_B){
s->me.qpel_put= s->dsp.put_2tap_qpel_pixels_tab;
s->me.qpel_avg= s->dsp.avg_2tap_qpel_pixels_tab;
}else if((!s->no_rounding) || s->pict_type==AV_PICTURE_TYPE_B){
s->me.qpel_put= s->dsp.put_qpel_pixels_tab;
s->me.qpel_avg= s->dsp.avg_qpel_pixels_tab;
}else{
s->me.qpel_put= s->dsp.put_no_rnd_qpel_pixels_tab;
s->me.qpel_avg= s->dsp.avg_qpel_pixels_tab;
}
if(ff_MPV_frame_start(s, avctx) < 0)
return -1;
if (!s->divx_packed) ff_thread_finish_setup(avctx);
if (CONFIG_MPEG4_VDPAU_DECODER && (s->avctx->codec->capabilities & CODEC_CAP_HWACCEL_VDPAU)) {
ff_vdpau_mpeg4_decode_picture(s, s->gb.buffer, s->gb.buffer_end - s->gb.buffer);
goto frame_end;
}
if (avctx->hwaccel) {
if (avctx->hwaccel->start_frame(avctx, s->gb.buffer, s->gb.buffer_end - s->gb.buffer) < 0)
return -1;
}
ff_er_frame_start(s);
//the second part of the wmv2 header contains the MB skip bits which are stored in current_picture->mb_type
//which is not available before ff_MPV_frame_start()
if (CONFIG_WMV2_DECODER && s->msmpeg4_version==5){
ret = ff_wmv2_decode_secondary_picture_header(s);
if(ret<0) return ret;
if(ret==1) goto intrax8_decoded;
}
/* decode each macroblock */
s->mb_x=0;
s->mb_y=0;
ret = decode_slice(s);
while(s->mb_y<s->mb_height){
if(s->msmpeg4_version){
if(s->slice_height==0 || s->mb_x!=0 || (s->mb_y%s->slice_height)!=0 || get_bits_count(&s->gb) > s->gb.size_in_bits)
break;
}else{
int prev_x=s->mb_x, prev_y=s->mb_y;
if(ff_h263_resync(s)<0)
break;
if (prev_y * s->mb_width + prev_x < s->mb_y * s->mb_width + s->mb_x)
s->error_occurred = 1;
}
if(s->msmpeg4_version<4 && s->h263_pred)
ff_mpeg4_clean_buffers(s);
if (decode_slice(s) < 0) ret = AVERROR_INVALIDDATA;
}
if (s->msmpeg4_version && s->msmpeg4_version<4 && s->pict_type==AV_PICTURE_TYPE_I)
if(!CONFIG_MSMPEG4_DECODER || ff_msmpeg4_decode_ext_header(s, buf_size) < 0){
s->error_status_table[s->mb_num-1]= ER_MB_ERROR;
}
assert(s->bitstream_buffer_size==0);
frame_end:
/* divx 5.01+ bistream reorder stuff */
if(s->codec_id==CODEC_ID_MPEG4 && s->divx_packed){
int current_pos= get_bits_count(&s->gb)>>3;
int startcode_found=0;
if(buf_size - current_pos > 5){
int i;
for(i=current_pos; i<buf_size-3; i++){
if(buf[i]==0 && buf[i+1]==0 && buf[i+2]==1 && buf[i+3]==0xB6){
startcode_found=1;
break;
}
}
}
if(s->gb.buffer == s->bitstream_buffer && buf_size>7 && s->xvid_build>=0){ //xvid style
startcode_found=1;
current_pos=0;
}
if(startcode_found){
av_fast_malloc(
&s->bitstream_buffer,
&s->allocated_bitstream_buffer_size,
buf_size - current_pos + FF_INPUT_BUFFER_PADDING_SIZE);
if (!s->bitstream_buffer)
return AVERROR(ENOMEM);
memcpy(s->bitstream_buffer, buf + current_pos, buf_size - current_pos);
s->bitstream_buffer_size= buf_size - current_pos;
}
}
intrax8_decoded:
ff_er_frame_end(s);
if (avctx->hwaccel) {
if (avctx->hwaccel->end_frame(avctx) < 0)
return -1;
}
ff_MPV_frame_end(s);
assert(s->current_picture.f.pict_type == s->current_picture_ptr->f.pict_type);
assert(s->current_picture.f.pict_type == s->pict_type);
if (s->pict_type == AV_PICTURE_TYPE_B || s->low_delay) {
*pict = s->current_picture_ptr->f;
} else if (s->last_picture_ptr != NULL) {
*pict = s->last_picture_ptr->f;
}
if(s->last_picture_ptr || s->low_delay){
*data_size = sizeof(AVFrame);
ff_print_debug_info(s, pict);
}
#ifdef PRINT_FRAME_TIME
av_log(avctx, AV_LOG_DEBUG, "%"PRId64"\n", rdtsc()-time);
#endif
return (ret && (avctx->err_recognition & AV_EF_EXPLODE))?ret:get_consumed_bytes(s, buf_size);
}
| true | FFmpeg | 71db86d53b5c6872cea31bf714a1a38ec78feaba | int ff_h263_decode_frame(AVCodecContext *avctx,
void *data, int *data_size,
AVPacket *avpkt)
{
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
MpegEncContext *s = avctx->priv_data;
int ret;
AVFrame *pict = data;
#ifdef PRINT_FRAME_TIME
uint64_t time= rdtsc();
#endif
s->flags= avctx->flags;
s->flags2= avctx->flags2;
if (buf_size == 0) {
if (s->low_delay==0 && s->next_picture_ptr) {
*pict = s->next_picture_ptr->f;
s->next_picture_ptr= NULL;
*data_size = sizeof(AVFrame);
}
return 0;
}
if(s->flags&CODEC_FLAG_TRUNCATED){
int next;
if(CONFIG_MPEG4_DECODER && s->codec_id==CODEC_ID_MPEG4){
next= ff_mpeg4_find_frame_end(&s->parse_context, buf, buf_size);
}else if(CONFIG_H263_DECODER && s->codec_id==CODEC_ID_H263){
next= ff_h263_find_frame_end(&s->parse_context, buf, buf_size);
}else{
av_log(s->avctx, AV_LOG_ERROR, "this codec does not support truncated bitstreams\n");
return -1;
}
if( ff_combine_frame(&s->parse_context, next, (const uint8_t **)&buf, &buf_size) < 0 )
return buf_size;
}
retry:
if(s->bitstream_buffer_size && (s->divx_packed || buf_size<20)){
init_get_bits(&s->gb, s->bitstream_buffer, s->bitstream_buffer_size*8);
}else
init_get_bits(&s->gb, buf, buf_size*8);
s->bitstream_buffer_size=0;
if (!s->context_initialized) {
if (ff_MPV_common_init(s) < 0)
return -1;
}
if (s->current_picture_ptr == NULL || s->current_picture_ptr->f.data[0]) {
int i= ff_find_unused_picture(s, 0);
if (i < 0)
return i;
s->current_picture_ptr= &s->picture[i];
}
if (CONFIG_WMV2_DECODER && s->msmpeg4_version==5) {
ret= ff_wmv2_decode_picture_header(s);
} else if (CONFIG_MSMPEG4_DECODER && s->msmpeg4_version) {
ret = ff_msmpeg4_decode_picture_header(s);
} else if (CONFIG_MPEG4_DECODER && s->h263_pred) {
if(s->avctx->extradata_size && s->picture_number==0){
GetBitContext gb;
init_get_bits(&gb, s->avctx->extradata, s->avctx->extradata_size*8);
ret = ff_mpeg4_decode_picture_header(s, &gb);
}
ret = ff_mpeg4_decode_picture_header(s, &s->gb);
} else if (CONFIG_H263I_DECODER && s->codec_id == CODEC_ID_H263I) {
ret = ff_intel_h263_decode_picture_header(s);
} else if (CONFIG_FLV_DECODER && s->h263_flv) {
ret = ff_flv_decode_picture_header(s);
} else {
ret = ff_h263_decode_picture_header(s);
}
if(ret==FRAME_SKIPPED) return get_consumed_bytes(s, buf_size);
if (ret < 0){
av_log(s->avctx, AV_LOG_ERROR, "header damaged\n");
return -1;
}
avctx->has_b_frames= !s->low_delay;
if(s->xvid_build==-1 && s->divx_version==-1 && s->lavc_build==-1){
if(s->stream_codec_tag == AV_RL32("XVID") ||
s->codec_tag == AV_RL32("XVID") || s->codec_tag == AV_RL32("XVIX") ||
s->codec_tag == AV_RL32("RMP4") ||
s->codec_tag == AV_RL32("SIPP")
)
s->xvid_build= 0;
#if 0
if(s->codec_tag == AV_RL32("DIVX") && s->vo_type==0 && s->vol_control_parameters==1
&& s->padding_bug_score > 0 && s->low_delay)
s->xvid_build= 0;
#endif
}
if(s->xvid_build==-1 && s->divx_version==-1 && s->lavc_build==-1){
if(s->codec_tag == AV_RL32("DIVX") && s->vo_type==0 && s->vol_control_parameters==0)
s->divx_version= 400;
}
if(s->xvid_build>=0 && s->divx_version>=0){
s->divx_version=
s->divx_build= -1;
}
if(s->workaround_bugs&FF_BUG_AUTODETECT){
if(s->codec_tag == AV_RL32("XVIX"))
s->workaround_bugs|= FF_BUG_XVID_ILACE;
if(s->codec_tag == AV_RL32("UMP4")){
s->workaround_bugs|= FF_BUG_UMP4;
}
if(s->divx_version>=500 && s->divx_build<1814){
s->workaround_bugs|= FF_BUG_QPEL_CHROMA;
}
if(s->divx_version>502 && s->divx_build<1814){
s->workaround_bugs|= FF_BUG_QPEL_CHROMA2;
}
if(s->xvid_build<=3U)
s->padding_bug_score= 256*256*256*64;
if(s->xvid_build<=1U)
s->workaround_bugs|= FF_BUG_QPEL_CHROMA;
if(s->xvid_build<=12U)
s->workaround_bugs|= FF_BUG_EDGE;
if(s->xvid_build<=32U)
s->workaround_bugs|= FF_BUG_DC_CLIP;
#define SET_QPEL_FUNC(postfix1, postfix2) \
s->dsp.put_ ## postfix1 = ff_put_ ## postfix2;\
s->dsp.put_no_rnd_ ## postfix1 = ff_put_no_rnd_ ## postfix2;\
s->dsp.avg_ ## postfix1 = ff_avg_ ## postfix2;
if(s->lavc_build<4653U)
s->workaround_bugs|= FF_BUG_STD_QPEL;
if(s->lavc_build<4655U)
s->workaround_bugs|= FF_BUG_DIRECT_BLOCKSIZE;
if(s->lavc_build<4670U){
s->workaround_bugs|= FF_BUG_EDGE;
}
if(s->lavc_build<=4712U)
s->workaround_bugs|= FF_BUG_DC_CLIP;
if(s->divx_version>=0)
s->workaround_bugs|= FF_BUG_DIRECT_BLOCKSIZE;
if(s->divx_version==501 && s->divx_build==20020416)
s->padding_bug_score= 256*256*256*64;
if(s->divx_version<500U){
s->workaround_bugs|= FF_BUG_EDGE;
}
if(s->divx_version>=0)
s->workaround_bugs|= FF_BUG_HPEL_CHROMA;
#if 0
if(s->divx_version==500)
s->padding_bug_score= 256*256*256*64;
if( s->resync_marker==0 && s->data_partitioning==0 && s->divx_version==-1
&& s->codec_id==CODEC_ID_MPEG4 && s->vo_type==0)
s->workaround_bugs|= FF_BUG_NO_PADDING;
if(s->lavc_build<4609U)
s->workaround_bugs|= FF_BUG_NO_PADDING;
#endif
}
if(s->workaround_bugs& FF_BUG_STD_QPEL){
SET_QPEL_FUNC(qpel_pixels_tab[0][ 5], qpel16_mc11_old_c)
SET_QPEL_FUNC(qpel_pixels_tab[0][ 7], qpel16_mc31_old_c)
SET_QPEL_FUNC(qpel_pixels_tab[0][ 9], qpel16_mc12_old_c)
SET_QPEL_FUNC(qpel_pixels_tab[0][11], qpel16_mc32_old_c)
SET_QPEL_FUNC(qpel_pixels_tab[0][13], qpel16_mc13_old_c)
SET_QPEL_FUNC(qpel_pixels_tab[0][15], qpel16_mc33_old_c)
SET_QPEL_FUNC(qpel_pixels_tab[1][ 5], qpel8_mc11_old_c)
SET_QPEL_FUNC(qpel_pixels_tab[1][ 7], qpel8_mc31_old_c)
SET_QPEL_FUNC(qpel_pixels_tab[1][ 9], qpel8_mc12_old_c)
SET_QPEL_FUNC(qpel_pixels_tab[1][11], qpel8_mc32_old_c)
SET_QPEL_FUNC(qpel_pixels_tab[1][13], qpel8_mc13_old_c)
SET_QPEL_FUNC(qpel_pixels_tab[1][15], qpel8_mc33_old_c)
}
if(avctx->debug & FF_DEBUG_BUGS)
av_log(s->avctx, AV_LOG_DEBUG, "bugs: %X lavc_build:%d xvid_build:%d divx_version:%d divx_build:%d %s\n",
s->workaround_bugs, s->lavc_build, s->xvid_build, s->divx_version, s->divx_build,
s->divx_packed ? "p" : "");
#if HAVE_MMX
if (s->codec_id == CODEC_ID_MPEG4 && s->xvid_build>=0 && avctx->idct_algo == FF_IDCT_AUTO && (av_get_cpu_flags() & AV_CPU_FLAG_MMX)) {
avctx->idct_algo= FF_IDCT_XVIDMMX;
avctx->coded_width= 0;
s->picture_number=0;
}
#endif
if ( s->width != avctx->coded_width
|| s->height != avctx->coded_height) {
ParseContext pc= s->parse_context;
s->parse_context.buffer=0;
ff_MPV_common_end(s);
s->parse_context= pc;
}
if (!s->context_initialized) {
avcodec_set_dimensions(avctx, s->width, s->height);
goto retry;
}
if((s->codec_id==CODEC_ID_H263 || s->codec_id==CODEC_ID_H263P || s->codec_id == CODEC_ID_H263I))
s->gob_index = ff_h263_get_gob_height(s);
s->current_picture.f.pict_type = s->pict_type;
s->current_picture.f.key_frame = s->pict_type == AV_PICTURE_TYPE_I;
if(s->last_picture_ptr==NULL && (s->pict_type==AV_PICTURE_TYPE_B || s->dropable)) return get_consumed_bytes(s, buf_size);
if( (avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type==AV_PICTURE_TYPE_B)
|| (avctx->skip_frame >= AVDISCARD_NONKEY && s->pict_type!=AV_PICTURE_TYPE_I)
|| avctx->skip_frame >= AVDISCARD_ALL)
return get_consumed_bytes(s, buf_size);
if(s->next_p_frame_damaged){
if(s->pict_type==AV_PICTURE_TYPE_B)
return get_consumed_bytes(s, buf_size);
else
s->next_p_frame_damaged=0;
}
if((s->avctx->flags2 & CODEC_FLAG2_FAST) && s->pict_type==AV_PICTURE_TYPE_B){
s->me.qpel_put= s->dsp.put_2tap_qpel_pixels_tab;
s->me.qpel_avg= s->dsp.avg_2tap_qpel_pixels_tab;
}else if((!s->no_rounding) || s->pict_type==AV_PICTURE_TYPE_B){
s->me.qpel_put= s->dsp.put_qpel_pixels_tab;
s->me.qpel_avg= s->dsp.avg_qpel_pixels_tab;
}else{
s->me.qpel_put= s->dsp.put_no_rnd_qpel_pixels_tab;
s->me.qpel_avg= s->dsp.avg_qpel_pixels_tab;
}
if(ff_MPV_frame_start(s, avctx) < 0)
return -1;
if (!s->divx_packed) ff_thread_finish_setup(avctx);
if (CONFIG_MPEG4_VDPAU_DECODER && (s->avctx->codec->capabilities & CODEC_CAP_HWACCEL_VDPAU)) {
ff_vdpau_mpeg4_decode_picture(s, s->gb.buffer, s->gb.buffer_end - s->gb.buffer);
goto frame_end;
}
if (avctx->hwaccel) {
if (avctx->hwaccel->start_frame(avctx, s->gb.buffer, s->gb.buffer_end - s->gb.buffer) < 0)
return -1;
}
ff_er_frame_start(s);
if (CONFIG_WMV2_DECODER && s->msmpeg4_version==5){
ret = ff_wmv2_decode_secondary_picture_header(s);
if(ret<0) return ret;
if(ret==1) goto intrax8_decoded;
}
s->mb_x=0;
s->mb_y=0;
ret = decode_slice(s);
while(s->mb_y<s->mb_height){
if(s->msmpeg4_version){
if(s->slice_height==0 || s->mb_x!=0 || (s->mb_y%s->slice_height)!=0 || get_bits_count(&s->gb) > s->gb.size_in_bits)
break;
}else{
int prev_x=s->mb_x, prev_y=s->mb_y;
if(ff_h263_resync(s)<0)
break;
if (prev_y * s->mb_width + prev_x < s->mb_y * s->mb_width + s->mb_x)
s->error_occurred = 1;
}
if(s->msmpeg4_version<4 && s->h263_pred)
ff_mpeg4_clean_buffers(s);
if (decode_slice(s) < 0) ret = AVERROR_INVALIDDATA;
}
if (s->msmpeg4_version && s->msmpeg4_version<4 && s->pict_type==AV_PICTURE_TYPE_I)
if(!CONFIG_MSMPEG4_DECODER || ff_msmpeg4_decode_ext_header(s, buf_size) < 0){
s->error_status_table[s->mb_num-1]= ER_MB_ERROR;
}
assert(s->bitstream_buffer_size==0);
frame_end:
if(s->codec_id==CODEC_ID_MPEG4 && s->divx_packed){
int current_pos= get_bits_count(&s->gb)>>3;
int startcode_found=0;
if(buf_size - current_pos > 5){
int i;
for(i=current_pos; i<buf_size-3; i++){
if(buf[i]==0 && buf[i+1]==0 && buf[i+2]==1 && buf[i+3]==0xB6){
startcode_found=1;
break;
}
}
}
if(s->gb.buffer == s->bitstream_buffer && buf_size>7 && s->xvid_build>=0){
startcode_found=1;
current_pos=0;
}
if(startcode_found){
av_fast_malloc(
&s->bitstream_buffer,
&s->allocated_bitstream_buffer_size,
buf_size - current_pos + FF_INPUT_BUFFER_PADDING_SIZE);
if (!s->bitstream_buffer)
return AVERROR(ENOMEM);
memcpy(s->bitstream_buffer, buf + current_pos, buf_size - current_pos);
s->bitstream_buffer_size= buf_size - current_pos;
}
}
intrax8_decoded:
ff_er_frame_end(s);
if (avctx->hwaccel) {
if (avctx->hwaccel->end_frame(avctx) < 0)
return -1;
}
ff_MPV_frame_end(s);
assert(s->current_picture.f.pict_type == s->current_picture_ptr->f.pict_type);
assert(s->current_picture.f.pict_type == s->pict_type);
if (s->pict_type == AV_PICTURE_TYPE_B || s->low_delay) {
*pict = s->current_picture_ptr->f;
} else if (s->last_picture_ptr != NULL) {
*pict = s->last_picture_ptr->f;
}
if(s->last_picture_ptr || s->low_delay){
*data_size = sizeof(AVFrame);
ff_print_debug_info(s, pict);
}
#ifdef PRINT_FRAME_TIME
av_log(avctx, AV_LOG_DEBUG, "%"PRId64"\n", rdtsc()-time);
#endif
return (ret && (avctx->err_recognition & AV_EF_EXPLODE))?ret:get_consumed_bytes(s, buf_size);
}
| {
"code": [],
"line_no": []
} | int FUNC_0(AVCodecContext *VAR_0,
void *VAR_1, int *VAR_2,
AVPacket *VAR_3)
{
const uint8_t *VAR_4 = VAR_3->VAR_1;
int VAR_5 = VAR_3->size;
MpegEncContext *s = VAR_0->priv_data;
int VAR_6;
AVFrame *pict = VAR_1;
#ifdef PRINT_FRAME_TIME
uint64_t time= rdtsc();
#endif
s->flags= VAR_0->flags;
s->flags2= VAR_0->flags2;
if (VAR_5 == 0) {
if (s->low_delay==0 && s->next_picture_ptr) {
*pict = s->next_picture_ptr->f;
s->next_picture_ptr= NULL;
*VAR_2 = sizeof(AVFrame);
}
return 0;
}
if(s->flags&CODEC_FLAG_TRUNCATED){
int VAR_7;
if(CONFIG_MPEG4_DECODER && s->codec_id==CODEC_ID_MPEG4){
VAR_7= ff_mpeg4_find_frame_end(&s->parse_context, VAR_4, VAR_5);
}else if(CONFIG_H263_DECODER && s->codec_id==CODEC_ID_H263){
VAR_7= ff_h263_find_frame_end(&s->parse_context, VAR_4, VAR_5);
}else{
av_log(s->VAR_0, AV_LOG_ERROR, "this codec does not support truncated bitstreams\n");
return -1;
}
if( ff_combine_frame(&s->parse_context, VAR_7, (const uint8_t **)&VAR_4, &VAR_5) < 0 )
return VAR_5;
}
retry:
if(s->bitstream_buffer_size && (s->divx_packed || VAR_5<20)){
init_get_bits(&s->gb, s->bitstream_buffer, s->bitstream_buffer_size*8);
}else
init_get_bits(&s->gb, VAR_4, VAR_5*8);
s->bitstream_buffer_size=0;
if (!s->context_initialized) {
if (ff_MPV_common_init(s) < 0)
return -1;
}
if (s->current_picture_ptr == NULL || s->current_picture_ptr->f.VAR_1[0]) {
int VAR_13= ff_find_unused_picture(s, 0);
if (VAR_13 < 0)
return VAR_13;
s->current_picture_ptr= &s->picture[VAR_13];
}
if (CONFIG_WMV2_DECODER && s->msmpeg4_version==5) {
VAR_6= ff_wmv2_decode_picture_header(s);
} else if (CONFIG_MSMPEG4_DECODER && s->msmpeg4_version) {
VAR_6 = ff_msmpeg4_decode_picture_header(s);
} else if (CONFIG_MPEG4_DECODER && s->h263_pred) {
if(s->VAR_0->extradata_size && s->picture_number==0){
GetBitContext gb;
init_get_bits(&gb, s->VAR_0->extradata, s->VAR_0->extradata_size*8);
VAR_6 = ff_mpeg4_decode_picture_header(s, &gb);
}
VAR_6 = ff_mpeg4_decode_picture_header(s, &s->gb);
} else if (CONFIG_H263I_DECODER && s->codec_id == CODEC_ID_H263I) {
VAR_6 = ff_intel_h263_decode_picture_header(s);
} else if (CONFIG_FLV_DECODER && s->h263_flv) {
VAR_6 = ff_flv_decode_picture_header(s);
} else {
VAR_6 = ff_h263_decode_picture_header(s);
}
if(VAR_6==FRAME_SKIPPED) return get_consumed_bytes(s, VAR_5);
if (VAR_6 < 0){
av_log(s->VAR_0, AV_LOG_ERROR, "header damaged\n");
return -1;
}
VAR_0->has_b_frames= !s->low_delay;
if(s->xvid_build==-1 && s->divx_version==-1 && s->lavc_build==-1){
if(s->stream_codec_tag == AV_RL32("XVID") ||
s->codec_tag == AV_RL32("XVID") || s->codec_tag == AV_RL32("XVIX") ||
s->codec_tag == AV_RL32("RMP4") ||
s->codec_tag == AV_RL32("SIPP")
)
s->xvid_build= 0;
#if 0
if(s->codec_tag == AV_RL32("DIVX") && s->vo_type==0 && s->vol_control_parameters==1
&& s->padding_bug_score > 0 && s->low_delay)
s->xvid_build= 0;
#endif
}
if(s->xvid_build==-1 && s->divx_version==-1 && s->lavc_build==-1){
if(s->codec_tag == AV_RL32("DIVX") && s->vo_type==0 && s->vol_control_parameters==0)
s->divx_version= 400;
}
if(s->xvid_build>=0 && s->divx_version>=0){
s->divx_version=
s->divx_build= -1;
}
if(s->workaround_bugs&FF_BUG_AUTODETECT){
if(s->codec_tag == AV_RL32("XVIX"))
s->workaround_bugs|= FF_BUG_XVID_ILACE;
if(s->codec_tag == AV_RL32("UMP4")){
s->workaround_bugs|= FF_BUG_UMP4;
}
if(s->divx_version>=500 && s->divx_build<1814){
s->workaround_bugs|= FF_BUG_QPEL_CHROMA;
}
if(s->divx_version>502 && s->divx_build<1814){
s->workaround_bugs|= FF_BUG_QPEL_CHROMA2;
}
if(s->xvid_build<=3U)
s->padding_bug_score= 256*256*256*64;
if(s->xvid_build<=1U)
s->workaround_bugs|= FF_BUG_QPEL_CHROMA;
if(s->xvid_build<=12U)
s->workaround_bugs|= FF_BUG_EDGE;
if(s->xvid_build<=32U)
s->workaround_bugs|= FF_BUG_DC_CLIP;
#define SET_QPEL_FUNC(postfix1, postfix2) \
s->dsp.put_ ## postfix1 = ff_put_ ## postfix2;\
s->dsp.put_no_rnd_ ## postfix1 = ff_put_no_rnd_ ## postfix2;\
s->dsp.avg_ ## postfix1 = ff_avg_ ## postfix2;
if(s->lavc_build<4653U)
s->workaround_bugs|= FF_BUG_STD_QPEL;
if(s->lavc_build<4655U)
s->workaround_bugs|= FF_BUG_DIRECT_BLOCKSIZE;
if(s->lavc_build<4670U){
s->workaround_bugs|= FF_BUG_EDGE;
}
if(s->lavc_build<=4712U)
s->workaround_bugs|= FF_BUG_DC_CLIP;
if(s->divx_version>=0)
s->workaround_bugs|= FF_BUG_DIRECT_BLOCKSIZE;
if(s->divx_version==501 && s->divx_build==20020416)
s->padding_bug_score= 256*256*256*64;
if(s->divx_version<500U){
s->workaround_bugs|= FF_BUG_EDGE;
}
if(s->divx_version>=0)
s->workaround_bugs|= FF_BUG_HPEL_CHROMA;
#if 0
if(s->divx_version==500)
s->padding_bug_score= 256*256*256*64;
if( s->resync_marker==0 && s->data_partitioning==0 && s->divx_version==-1
&& s->codec_id==CODEC_ID_MPEG4 && s->vo_type==0)
s->workaround_bugs|= FF_BUG_NO_PADDING;
if(s->lavc_build<4609U)
s->workaround_bugs|= FF_BUG_NO_PADDING;
#endif
}
if(s->workaround_bugs& FF_BUG_STD_QPEL){
SET_QPEL_FUNC(qpel_pixels_tab[0][ 5], qpel16_mc11_old_c)
SET_QPEL_FUNC(qpel_pixels_tab[0][ 7], qpel16_mc31_old_c)
SET_QPEL_FUNC(qpel_pixels_tab[0][ 9], qpel16_mc12_old_c)
SET_QPEL_FUNC(qpel_pixels_tab[0][11], qpel16_mc32_old_c)
SET_QPEL_FUNC(qpel_pixels_tab[0][13], qpel16_mc13_old_c)
SET_QPEL_FUNC(qpel_pixels_tab[0][15], qpel16_mc33_old_c)
SET_QPEL_FUNC(qpel_pixels_tab[1][ 5], qpel8_mc11_old_c)
SET_QPEL_FUNC(qpel_pixels_tab[1][ 7], qpel8_mc31_old_c)
SET_QPEL_FUNC(qpel_pixels_tab[1][ 9], qpel8_mc12_old_c)
SET_QPEL_FUNC(qpel_pixels_tab[1][11], qpel8_mc32_old_c)
SET_QPEL_FUNC(qpel_pixels_tab[1][13], qpel8_mc13_old_c)
SET_QPEL_FUNC(qpel_pixels_tab[1][15], qpel8_mc33_old_c)
}
if(VAR_0->debug & FF_DEBUG_BUGS)
av_log(s->VAR_0, AV_LOG_DEBUG, "bugs: %X lavc_build:%d xvid_build:%d divx_version:%d divx_build:%d %s\n",
s->workaround_bugs, s->lavc_build, s->xvid_build, s->divx_version, s->divx_build,
s->divx_packed ? "p" : "");
#if HAVE_MMX
if (s->codec_id == CODEC_ID_MPEG4 && s->xvid_build>=0 && VAR_0->idct_algo == FF_IDCT_AUTO && (av_get_cpu_flags() & AV_CPU_FLAG_MMX)) {
VAR_0->idct_algo= FF_IDCT_XVIDMMX;
VAR_0->coded_width= 0;
s->picture_number=0;
}
#endif
if ( s->width != VAR_0->coded_width
|| s->height != VAR_0->coded_height) {
ParseContext pc= s->parse_context;
s->parse_context.buffer=0;
ff_MPV_common_end(s);
s->parse_context= pc;
}
if (!s->context_initialized) {
avcodec_set_dimensions(VAR_0, s->width, s->height);
goto retry;
}
if((s->codec_id==CODEC_ID_H263 || s->codec_id==CODEC_ID_H263P || s->codec_id == CODEC_ID_H263I))
s->gob_index = ff_h263_get_gob_height(s);
s->current_picture.f.pict_type = s->pict_type;
s->current_picture.f.key_frame = s->pict_type == AV_PICTURE_TYPE_I;
if(s->last_picture_ptr==NULL && (s->pict_type==AV_PICTURE_TYPE_B || s->dropable)) return get_consumed_bytes(s, VAR_5);
if( (VAR_0->skip_frame >= AVDISCARD_NONREF && s->pict_type==AV_PICTURE_TYPE_B)
|| (VAR_0->skip_frame >= AVDISCARD_NONKEY && s->pict_type!=AV_PICTURE_TYPE_I)
|| VAR_0->skip_frame >= AVDISCARD_ALL)
return get_consumed_bytes(s, VAR_5);
if(s->next_p_frame_damaged){
if(s->pict_type==AV_PICTURE_TYPE_B)
return get_consumed_bytes(s, VAR_5);
else
s->next_p_frame_damaged=0;
}
if((s->VAR_0->flags2 & CODEC_FLAG2_FAST) && s->pict_type==AV_PICTURE_TYPE_B){
s->me.qpel_put= s->dsp.put_2tap_qpel_pixels_tab;
s->me.qpel_avg= s->dsp.avg_2tap_qpel_pixels_tab;
}else if((!s->no_rounding) || s->pict_type==AV_PICTURE_TYPE_B){
s->me.qpel_put= s->dsp.put_qpel_pixels_tab;
s->me.qpel_avg= s->dsp.avg_qpel_pixels_tab;
}else{
s->me.qpel_put= s->dsp.put_no_rnd_qpel_pixels_tab;
s->me.qpel_avg= s->dsp.avg_qpel_pixels_tab;
}
if(ff_MPV_frame_start(s, VAR_0) < 0)
return -1;
if (!s->divx_packed) ff_thread_finish_setup(VAR_0);
if (CONFIG_MPEG4_VDPAU_DECODER && (s->VAR_0->codec->capabilities & CODEC_CAP_HWACCEL_VDPAU)) {
ff_vdpau_mpeg4_decode_picture(s, s->gb.buffer, s->gb.buffer_end - s->gb.buffer);
goto frame_end;
}
if (VAR_0->hwaccel) {
if (VAR_0->hwaccel->start_frame(VAR_0, s->gb.buffer, s->gb.buffer_end - s->gb.buffer) < 0)
return -1;
}
ff_er_frame_start(s);
if (CONFIG_WMV2_DECODER && s->msmpeg4_version==5){
VAR_6 = ff_wmv2_decode_secondary_picture_header(s);
if(VAR_6<0) return VAR_6;
if(VAR_6==1) goto intrax8_decoded;
}
s->mb_x=0;
s->mb_y=0;
VAR_6 = decode_slice(s);
while(s->mb_y<s->mb_height){
if(s->msmpeg4_version){
if(s->slice_height==0 || s->mb_x!=0 || (s->mb_y%s->slice_height)!=0 || get_bits_count(&s->gb) > s->gb.size_in_bits)
break;
}else{
int VAR_9=s->mb_x, VAR_10=s->mb_y;
if(ff_h263_resync(s)<0)
break;
if (VAR_10 * s->mb_width + VAR_9 < s->mb_y * s->mb_width + s->mb_x)
s->error_occurred = 1;
}
if(s->msmpeg4_version<4 && s->h263_pred)
ff_mpeg4_clean_buffers(s);
if (decode_slice(s) < 0) VAR_6 = AVERROR_INVALIDDATA;
}
if (s->msmpeg4_version && s->msmpeg4_version<4 && s->pict_type==AV_PICTURE_TYPE_I)
if(!CONFIG_MSMPEG4_DECODER || ff_msmpeg4_decode_ext_header(s, VAR_5) < 0){
s->error_status_table[s->mb_num-1]= ER_MB_ERROR;
}
assert(s->bitstream_buffer_size==0);
frame_end:
if(s->codec_id==CODEC_ID_MPEG4 && s->divx_packed){
int VAR_11= get_bits_count(&s->gb)>>3;
int VAR_12=0;
if(VAR_5 - VAR_11 > 5){
int VAR_13;
for(VAR_13=VAR_11; VAR_13<VAR_5-3; VAR_13++){
if(VAR_4[VAR_13]==0 && VAR_4[VAR_13+1]==0 && VAR_4[VAR_13+2]==1 && VAR_4[VAR_13+3]==0xB6){
VAR_12=1;
break;
}
}
}
if(s->gb.buffer == s->bitstream_buffer && VAR_5>7 && s->xvid_build>=0){
VAR_12=1;
VAR_11=0;
}
if(VAR_12){
av_fast_malloc(
&s->bitstream_buffer,
&s->allocated_bitstream_buffer_size,
VAR_5 - VAR_11 + FF_INPUT_BUFFER_PADDING_SIZE);
if (!s->bitstream_buffer)
return AVERROR(ENOMEM);
memcpy(s->bitstream_buffer, VAR_4 + VAR_11, VAR_5 - VAR_11);
s->bitstream_buffer_size= VAR_5 - VAR_11;
}
}
intrax8_decoded:
ff_er_frame_end(s);
if (VAR_0->hwaccel) {
if (VAR_0->hwaccel->end_frame(VAR_0) < 0)
return -1;
}
ff_MPV_frame_end(s);
assert(s->current_picture.f.pict_type == s->current_picture_ptr->f.pict_type);
assert(s->current_picture.f.pict_type == s->pict_type);
if (s->pict_type == AV_PICTURE_TYPE_B || s->low_delay) {
*pict = s->current_picture_ptr->f;
} else if (s->last_picture_ptr != NULL) {
*pict = s->last_picture_ptr->f;
}
if(s->last_picture_ptr || s->low_delay){
*VAR_2 = sizeof(AVFrame);
ff_print_debug_info(s, pict);
}
#ifdef PRINT_FRAME_TIME
av_log(VAR_0, AV_LOG_DEBUG, "%"PRId64"\n", rdtsc()-time);
#endif
return (VAR_6 && (VAR_0->err_recognition & AV_EF_EXPLODE))?VAR_6:get_consumed_bytes(s, VAR_5);
}
| [
"int FUNC_0(AVCodecContext *VAR_0,\nvoid *VAR_1, int *VAR_2,\nAVPacket *VAR_3)\n{",
"const uint8_t *VAR_4 = VAR_3->VAR_1;",
"int VAR_5 = VAR_3->size;",
"MpegEncContext *s = VAR_0->priv_data;",
"int VAR_6;",
"AVFrame *pict = VAR_1;",
"#ifdef PRINT_FRAME_TIME\nuint64_t time= rdtsc();",
"#endif\ns->flags= VAR_0->flags;",
"s->flags2= VAR_0->flags2;",
"if (VAR_5 == 0) {",
"if (s->low_delay==0 && s->next_picture_ptr) {",
"*pict = s->next_picture_ptr->f;",
"s->next_picture_ptr= NULL;",
"*VAR_2 = sizeof(AVFrame);",
"}",
"return 0;",
"}",
"if(s->flags&CODEC_FLAG_TRUNCATED){",
"int VAR_7;",
"if(CONFIG_MPEG4_DECODER && s->codec_id==CODEC_ID_MPEG4){",
"VAR_7= ff_mpeg4_find_frame_end(&s->parse_context, VAR_4, VAR_5);",
"}else if(CONFIG_H263_DECODER && s->codec_id==CODEC_ID_H263){",
"VAR_7= ff_h263_find_frame_end(&s->parse_context, VAR_4, VAR_5);",
"}else{",
"av_log(s->VAR_0, AV_LOG_ERROR, \"this codec does not support truncated bitstreams\\n\");",
"return -1;",
"}",
"if( ff_combine_frame(&s->parse_context, VAR_7, (const uint8_t **)&VAR_4, &VAR_5) < 0 )\nreturn VAR_5;",
"}",
"retry:\nif(s->bitstream_buffer_size && (s->divx_packed || VAR_5<20)){",
"init_get_bits(&s->gb, s->bitstream_buffer, s->bitstream_buffer_size*8);",
"}else",
"init_get_bits(&s->gb, VAR_4, VAR_5*8);",
"s->bitstream_buffer_size=0;",
"if (!s->context_initialized) {",
"if (ff_MPV_common_init(s) < 0)\nreturn -1;",
"}",
"if (s->current_picture_ptr == NULL || s->current_picture_ptr->f.VAR_1[0]) {",
"int VAR_13= ff_find_unused_picture(s, 0);",
"if (VAR_13 < 0)\nreturn VAR_13;",
"s->current_picture_ptr= &s->picture[VAR_13];",
"}",
"if (CONFIG_WMV2_DECODER && s->msmpeg4_version==5) {",
"VAR_6= ff_wmv2_decode_picture_header(s);",
"} else if (CONFIG_MSMPEG4_DECODER && s->msmpeg4_version) {",
"VAR_6 = ff_msmpeg4_decode_picture_header(s);",
"} else if (CONFIG_MPEG4_DECODER && s->h263_pred) {",
"if(s->VAR_0->extradata_size && s->picture_number==0){",
"GetBitContext gb;",
"init_get_bits(&gb, s->VAR_0->extradata, s->VAR_0->extradata_size*8);",
"VAR_6 = ff_mpeg4_decode_picture_header(s, &gb);",
"}",
"VAR_6 = ff_mpeg4_decode_picture_header(s, &s->gb);",
"} else if (CONFIG_H263I_DECODER && s->codec_id == CODEC_ID_H263I) {",
"VAR_6 = ff_intel_h263_decode_picture_header(s);",
"} else if (CONFIG_FLV_DECODER && s->h263_flv) {",
"VAR_6 = ff_flv_decode_picture_header(s);",
"} else {",
"VAR_6 = ff_h263_decode_picture_header(s);",
"}",
"if(VAR_6==FRAME_SKIPPED) return get_consumed_bytes(s, VAR_5);",
"if (VAR_6 < 0){",
"av_log(s->VAR_0, AV_LOG_ERROR, \"header damaged\\n\");",
"return -1;",
"}",
"VAR_0->has_b_frames= !s->low_delay;",
"if(s->xvid_build==-1 && s->divx_version==-1 && s->lavc_build==-1){",
"if(s->stream_codec_tag == AV_RL32(\"XVID\") ||\ns->codec_tag == AV_RL32(\"XVID\") || s->codec_tag == AV_RL32(\"XVIX\") ||\ns->codec_tag == AV_RL32(\"RMP4\") ||\ns->codec_tag == AV_RL32(\"SIPP\")\n)\ns->xvid_build= 0;",
"#if 0\nif(s->codec_tag == AV_RL32(\"DIVX\") && s->vo_type==0 && s->vol_control_parameters==1\n&& s->padding_bug_score > 0 && s->low_delay)\ns->xvid_build= 0;",
"#endif\n}",
"if(s->xvid_build==-1 && s->divx_version==-1 && s->lavc_build==-1){",
"if(s->codec_tag == AV_RL32(\"DIVX\") && s->vo_type==0 && s->vol_control_parameters==0)\ns->divx_version= 400;",
"}",
"if(s->xvid_build>=0 && s->divx_version>=0){",
"s->divx_version=\ns->divx_build= -1;",
"}",
"if(s->workaround_bugs&FF_BUG_AUTODETECT){",
"if(s->codec_tag == AV_RL32(\"XVIX\"))\ns->workaround_bugs|= FF_BUG_XVID_ILACE;",
"if(s->codec_tag == AV_RL32(\"UMP4\")){",
"s->workaround_bugs|= FF_BUG_UMP4;",
"}",
"if(s->divx_version>=500 && s->divx_build<1814){",
"s->workaround_bugs|= FF_BUG_QPEL_CHROMA;",
"}",
"if(s->divx_version>502 && s->divx_build<1814){",
"s->workaround_bugs|= FF_BUG_QPEL_CHROMA2;",
"}",
"if(s->xvid_build<=3U)\ns->padding_bug_score= 256*256*256*64;",
"if(s->xvid_build<=1U)\ns->workaround_bugs|= FF_BUG_QPEL_CHROMA;",
"if(s->xvid_build<=12U)\ns->workaround_bugs|= FF_BUG_EDGE;",
"if(s->xvid_build<=32U)\ns->workaround_bugs|= FF_BUG_DC_CLIP;",
"#define SET_QPEL_FUNC(postfix1, postfix2) \\\ns->dsp.put_ ## postfix1 = ff_put_ ## postfix2;\\",
"s->dsp.put_no_rnd_ ## postfix1 = ff_put_no_rnd_ ## postfix2;\\",
"s->dsp.avg_ ## postfix1 = ff_avg_ ## postfix2;",
"if(s->lavc_build<4653U)\ns->workaround_bugs|= FF_BUG_STD_QPEL;",
"if(s->lavc_build<4655U)\ns->workaround_bugs|= FF_BUG_DIRECT_BLOCKSIZE;",
"if(s->lavc_build<4670U){",
"s->workaround_bugs|= FF_BUG_EDGE;",
"}",
"if(s->lavc_build<=4712U)\ns->workaround_bugs|= FF_BUG_DC_CLIP;",
"if(s->divx_version>=0)\ns->workaround_bugs|= FF_BUG_DIRECT_BLOCKSIZE;",
"if(s->divx_version==501 && s->divx_build==20020416)\ns->padding_bug_score= 256*256*256*64;",
"if(s->divx_version<500U){",
"s->workaround_bugs|= FF_BUG_EDGE;",
"}",
"if(s->divx_version>=0)\ns->workaround_bugs|= FF_BUG_HPEL_CHROMA;",
"#if 0\nif(s->divx_version==500)\ns->padding_bug_score= 256*256*256*64;",
"if( s->resync_marker==0 && s->data_partitioning==0 && s->divx_version==-1\n&& s->codec_id==CODEC_ID_MPEG4 && s->vo_type==0)\ns->workaround_bugs|= FF_BUG_NO_PADDING;",
"if(s->lavc_build<4609U)\ns->workaround_bugs|= FF_BUG_NO_PADDING;",
"#endif\n}",
"if(s->workaround_bugs& FF_BUG_STD_QPEL){",
"SET_QPEL_FUNC(qpel_pixels_tab[0][ 5], qpel16_mc11_old_c)\nSET_QPEL_FUNC(qpel_pixels_tab[0][ 7], qpel16_mc31_old_c)\nSET_QPEL_FUNC(qpel_pixels_tab[0][ 9], qpel16_mc12_old_c)\nSET_QPEL_FUNC(qpel_pixels_tab[0][11], qpel16_mc32_old_c)\nSET_QPEL_FUNC(qpel_pixels_tab[0][13], qpel16_mc13_old_c)\nSET_QPEL_FUNC(qpel_pixels_tab[0][15], qpel16_mc33_old_c)\nSET_QPEL_FUNC(qpel_pixels_tab[1][ 5], qpel8_mc11_old_c)\nSET_QPEL_FUNC(qpel_pixels_tab[1][ 7], qpel8_mc31_old_c)\nSET_QPEL_FUNC(qpel_pixels_tab[1][ 9], qpel8_mc12_old_c)\nSET_QPEL_FUNC(qpel_pixels_tab[1][11], qpel8_mc32_old_c)\nSET_QPEL_FUNC(qpel_pixels_tab[1][13], qpel8_mc13_old_c)\nSET_QPEL_FUNC(qpel_pixels_tab[1][15], qpel8_mc33_old_c)\n}",
"if(VAR_0->debug & FF_DEBUG_BUGS)\nav_log(s->VAR_0, AV_LOG_DEBUG, \"bugs: %X lavc_build:%d xvid_build:%d divx_version:%d divx_build:%d %s\\n\",\ns->workaround_bugs, s->lavc_build, s->xvid_build, s->divx_version, s->divx_build,\ns->divx_packed ? \"p\" : \"\");",
"#if HAVE_MMX\nif (s->codec_id == CODEC_ID_MPEG4 && s->xvid_build>=0 && VAR_0->idct_algo == FF_IDCT_AUTO && (av_get_cpu_flags() & AV_CPU_FLAG_MMX)) {",
"VAR_0->idct_algo= FF_IDCT_XVIDMMX;",
"VAR_0->coded_width= 0;",
"s->picture_number=0;",
"}",
"#endif\nif ( s->width != VAR_0->coded_width\n|| s->height != VAR_0->coded_height) {",
"ParseContext pc= s->parse_context;",
"s->parse_context.buffer=0;",
"ff_MPV_common_end(s);",
"s->parse_context= pc;",
"}",
"if (!s->context_initialized) {",
"avcodec_set_dimensions(VAR_0, s->width, s->height);",
"goto retry;",
"}",
"if((s->codec_id==CODEC_ID_H263 || s->codec_id==CODEC_ID_H263P || s->codec_id == CODEC_ID_H263I))\ns->gob_index = ff_h263_get_gob_height(s);",
"s->current_picture.f.pict_type = s->pict_type;",
"s->current_picture.f.key_frame = s->pict_type == AV_PICTURE_TYPE_I;",
"if(s->last_picture_ptr==NULL && (s->pict_type==AV_PICTURE_TYPE_B || s->dropable)) return get_consumed_bytes(s, VAR_5);",
"if( (VAR_0->skip_frame >= AVDISCARD_NONREF && s->pict_type==AV_PICTURE_TYPE_B)\n|| (VAR_0->skip_frame >= AVDISCARD_NONKEY && s->pict_type!=AV_PICTURE_TYPE_I)\n|| VAR_0->skip_frame >= AVDISCARD_ALL)\nreturn get_consumed_bytes(s, VAR_5);",
"if(s->next_p_frame_damaged){",
"if(s->pict_type==AV_PICTURE_TYPE_B)\nreturn get_consumed_bytes(s, VAR_5);",
"else\ns->next_p_frame_damaged=0;",
"}",
"if((s->VAR_0->flags2 & CODEC_FLAG2_FAST) && s->pict_type==AV_PICTURE_TYPE_B){",
"s->me.qpel_put= s->dsp.put_2tap_qpel_pixels_tab;",
"s->me.qpel_avg= s->dsp.avg_2tap_qpel_pixels_tab;",
"}else if((!s->no_rounding) || s->pict_type==AV_PICTURE_TYPE_B){",
"s->me.qpel_put= s->dsp.put_qpel_pixels_tab;",
"s->me.qpel_avg= s->dsp.avg_qpel_pixels_tab;",
"}else{",
"s->me.qpel_put= s->dsp.put_no_rnd_qpel_pixels_tab;",
"s->me.qpel_avg= s->dsp.avg_qpel_pixels_tab;",
"}",
"if(ff_MPV_frame_start(s, VAR_0) < 0)\nreturn -1;",
"if (!s->divx_packed) ff_thread_finish_setup(VAR_0);",
"if (CONFIG_MPEG4_VDPAU_DECODER && (s->VAR_0->codec->capabilities & CODEC_CAP_HWACCEL_VDPAU)) {",
"ff_vdpau_mpeg4_decode_picture(s, s->gb.buffer, s->gb.buffer_end - s->gb.buffer);",
"goto frame_end;",
"}",
"if (VAR_0->hwaccel) {",
"if (VAR_0->hwaccel->start_frame(VAR_0, s->gb.buffer, s->gb.buffer_end - s->gb.buffer) < 0)\nreturn -1;",
"}",
"ff_er_frame_start(s);",
"if (CONFIG_WMV2_DECODER && s->msmpeg4_version==5){",
"VAR_6 = ff_wmv2_decode_secondary_picture_header(s);",
"if(VAR_6<0) return VAR_6;",
"if(VAR_6==1) goto intrax8_decoded;",
"}",
"s->mb_x=0;",
"s->mb_y=0;",
"VAR_6 = decode_slice(s);",
"while(s->mb_y<s->mb_height){",
"if(s->msmpeg4_version){",
"if(s->slice_height==0 || s->mb_x!=0 || (s->mb_y%s->slice_height)!=0 || get_bits_count(&s->gb) > s->gb.size_in_bits)\nbreak;",
"}else{",
"int VAR_9=s->mb_x, VAR_10=s->mb_y;",
"if(ff_h263_resync(s)<0)\nbreak;",
"if (VAR_10 * s->mb_width + VAR_9 < s->mb_y * s->mb_width + s->mb_x)\ns->error_occurred = 1;",
"}",
"if(s->msmpeg4_version<4 && s->h263_pred)\nff_mpeg4_clean_buffers(s);",
"if (decode_slice(s) < 0) VAR_6 = AVERROR_INVALIDDATA;",
"}",
"if (s->msmpeg4_version && s->msmpeg4_version<4 && s->pict_type==AV_PICTURE_TYPE_I)\nif(!CONFIG_MSMPEG4_DECODER || ff_msmpeg4_decode_ext_header(s, VAR_5) < 0){",
"s->error_status_table[s->mb_num-1]= ER_MB_ERROR;",
"}",
"assert(s->bitstream_buffer_size==0);",
"frame_end:\nif(s->codec_id==CODEC_ID_MPEG4 && s->divx_packed){",
"int VAR_11= get_bits_count(&s->gb)>>3;",
"int VAR_12=0;",
"if(VAR_5 - VAR_11 > 5){",
"int VAR_13;",
"for(VAR_13=VAR_11; VAR_13<VAR_5-3; VAR_13++){",
"if(VAR_4[VAR_13]==0 && VAR_4[VAR_13+1]==0 && VAR_4[VAR_13+2]==1 && VAR_4[VAR_13+3]==0xB6){",
"VAR_12=1;",
"break;",
"}",
"}",
"}",
"if(s->gb.buffer == s->bitstream_buffer && VAR_5>7 && s->xvid_build>=0){",
"VAR_12=1;",
"VAR_11=0;",
"}",
"if(VAR_12){",
"av_fast_malloc(\n&s->bitstream_buffer,\n&s->allocated_bitstream_buffer_size,\nVAR_5 - VAR_11 + FF_INPUT_BUFFER_PADDING_SIZE);",
"if (!s->bitstream_buffer)\nreturn AVERROR(ENOMEM);",
"memcpy(s->bitstream_buffer, VAR_4 + VAR_11, VAR_5 - VAR_11);",
"s->bitstream_buffer_size= VAR_5 - VAR_11;",
"}",
"}",
"intrax8_decoded:\nff_er_frame_end(s);",
"if (VAR_0->hwaccel) {",
"if (VAR_0->hwaccel->end_frame(VAR_0) < 0)\nreturn -1;",
"}",
"ff_MPV_frame_end(s);",
"assert(s->current_picture.f.pict_type == s->current_picture_ptr->f.pict_type);",
"assert(s->current_picture.f.pict_type == s->pict_type);",
"if (s->pict_type == AV_PICTURE_TYPE_B || s->low_delay) {",
"*pict = s->current_picture_ptr->f;",
"} else if (s->last_picture_ptr != NULL) {",
"*pict = s->last_picture_ptr->f;",
"}",
"if(s->last_picture_ptr || s->low_delay){",
"*VAR_2 = sizeof(AVFrame);",
"ff_print_debug_info(s, pict);",
"}",
"#ifdef PRINT_FRAME_TIME\nav_log(VAR_0, AV_LOG_DEBUG, \"%\"PRId64\"\\n\", rdtsc()-time);",
"#endif\nreturn (VAR_6 && (VAR_0->err_recognition & AV_EF_EXPLODE))?VAR_6:get_consumed_bytes(s, VAR_5);",
"}"
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | [
[
1,
3,
5,
7
],
[
9
],
[
11
],
[
13
],
[
15
],
[
17
],
[
21,
23
],
[
25,
27
],
[
29
],
[
35
],
[
39
],
[
41
],
[
43
],
[
47
],
[
49
],
[
53
],
[
55
],
[
59
],
[
61
],
[
65
],
[
67
],
[
69
],
[
71
],
[
73
],
[
75
],
[
77
],
[
79
],
[
83,
85
],
[
87
],
[
93,
97
],
[
99
],
[
101
],
[
103
],
[
105
],
[
109
],
[
111,
113
],
[
115
],
[
123
],
[
125
],
[
127,
129
],
[
131
],
[
133
],
[
139
],
[
141
],
[
143
],
[
145
],
[
147
],
[
149
],
[
151
],
[
155
],
[
157
],
[
159
],
[
161
],
[
163
],
[
165
],
[
167
],
[
169
],
[
171
],
[
173
],
[
175
],
[
179
],
[
185
],
[
187
],
[
189
],
[
191
],
[
195
],
[
199
],
[
201,
203,
205,
207,
209,
211
],
[
213,
215,
217,
219
],
[
221,
223
],
[
227
],
[
229,
231
],
[
233
],
[
237
],
[
239,
241
],
[
243
],
[
247
],
[
249,
251
],
[
255
],
[
257
],
[
259
],
[
263
],
[
265
],
[
267
],
[
271
],
[
273
],
[
275
],
[
279,
281
],
[
285,
287
],
[
291,
293
],
[
297,
299
],
[
303,
305
],
[
307
],
[
309
],
[
313,
315
],
[
319,
321
],
[
325
],
[
327
],
[
329
],
[
333,
335
],
[
339,
341
],
[
345,
347
],
[
351
],
[
353
],
[
355
],
[
359,
361
],
[
363,
365,
367
],
[
377,
379,
381
],
[
385,
387
],
[
389,
391
],
[
395
],
[
397,
399,
401,
403,
405,
407,
411,
413,
415,
417,
419,
421,
423
],
[
427,
429,
431,
433
],
[
437,
439
],
[
441
],
[
443
],
[
447
],
[
449
],
[
451,
465,
467
],
[
471
],
[
473
],
[
475
],
[
477
],
[
479
],
[
481
],
[
483
],
[
487
],
[
489
],
[
493,
495
],
[
501
],
[
503
],
[
509
],
[
511,
513,
515,
517
],
[
521
],
[
523,
525
],
[
527,
529
],
[
531
],
[
535
],
[
537
],
[
539
],
[
541
],
[
543
],
[
545
],
[
547
],
[
549
],
[
551
],
[
553
],
[
557,
559
],
[
563
],
[
567
],
[
569
],
[
571
],
[
573
],
[
577
],
[
579,
581
],
[
583
],
[
587
],
[
595
],
[
597
],
[
599
],
[
601
],
[
603
],
[
609
],
[
611
],
[
615
],
[
617
],
[
619
],
[
621,
623
],
[
625
],
[
627
],
[
629,
631
],
[
633,
635
],
[
637
],
[
641,
643
],
[
647
],
[
649
],
[
653,
655
],
[
657
],
[
659
],
[
663
],
[
665,
669
],
[
671
],
[
673
],
[
677
],
[
679
],
[
681
],
[
683
],
[
685
],
[
687
],
[
689
],
[
691
],
[
693
],
[
695
],
[
697
],
[
699
],
[
701
],
[
705
],
[
707,
709,
711,
713
],
[
715,
717
],
[
719
],
[
721
],
[
723
],
[
725
],
[
729,
731
],
[
735
],
[
737,
739
],
[
741
],
[
745
],
[
749
],
[
751
],
[
753
],
[
755
],
[
757
],
[
759
],
[
761
],
[
765
],
[
767
],
[
769
],
[
771
],
[
775,
777
],
[
779,
783
],
[
785
]
] |
21,408 | static void mmap_release_buffer(AVPacket *pkt)
{
struct v4l2_buffer buf;
int res, fd;
struct buff_data *buf_descriptor = pkt->priv;
memset(&buf, 0, sizeof(struct v4l2_buffer));
buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
buf.memory = V4L2_MEMORY_MMAP;
buf.index = buf_descriptor->index;
fd = buf_descriptor->fd;
av_free(buf_descriptor);
res = ioctl (fd, VIDIOC_QBUF, &buf);
if (res < 0) {
av_log(NULL, AV_LOG_ERROR, "ioctl(VIDIOC_QBUF)\n");
pkt->data = NULL;
pkt->size = 0; | true | FFmpeg | 5449a787c953f40f0f4312e6f5897775904ffc45 | static void mmap_release_buffer(AVPacket *pkt)
{
struct v4l2_buffer buf;
int res, fd;
struct buff_data *buf_descriptor = pkt->priv;
memset(&buf, 0, sizeof(struct v4l2_buffer));
buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
buf.memory = V4L2_MEMORY_MMAP;
buf.index = buf_descriptor->index;
fd = buf_descriptor->fd;
av_free(buf_descriptor);
res = ioctl (fd, VIDIOC_QBUF, &buf);
if (res < 0) {
av_log(NULL, AV_LOG_ERROR, "ioctl(VIDIOC_QBUF)\n");
pkt->data = NULL;
pkt->size = 0; | {
"code": [],
"line_no": []
} | static void FUNC_0(AVPacket *VAR_0)
{
struct v4l2_buffer VAR_1;
int VAR_2, VAR_3;
struct buff_data *VAR_4 = VAR_0->priv;
memset(&VAR_1, 0, sizeof(struct v4l2_buffer));
VAR_1.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
VAR_1.memory = V4L2_MEMORY_MMAP;
VAR_1.index = VAR_4->index;
VAR_3 = VAR_4->VAR_3;
av_free(VAR_4);
VAR_2 = ioctl (VAR_3, VIDIOC_QBUF, &VAR_1);
if (VAR_2 < 0) {
av_log(NULL, AV_LOG_ERROR, "ioctl(VIDIOC_QBUF)\n");
VAR_0->data = NULL;
VAR_0->size = 0; | [
"static void FUNC_0(AVPacket *VAR_0)\n{",
"struct v4l2_buffer VAR_1;",
"int VAR_2, VAR_3;",
"struct buff_data *VAR_4 = VAR_0->priv;",
"memset(&VAR_1, 0, sizeof(struct v4l2_buffer));",
"VAR_1.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;",
"VAR_1.memory = V4L2_MEMORY_MMAP;",
"VAR_1.index = VAR_4->index;",
"VAR_3 = VAR_4->VAR_3;",
"av_free(VAR_4);",
"VAR_2 = ioctl (VAR_3, VIDIOC_QBUF, &VAR_1);",
"if (VAR_2 < 0) {",
"av_log(NULL, AV_LOG_ERROR, \"ioctl(VIDIOC_QBUF)\\n\");",
"VAR_0->data = NULL;",
"VAR_0->size = 0;"
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | [
[
1,
2
],
[
3
],
[
4
],
[
5
],
[
6
],
[
7
],
[
8
],
[
9
],
[
10
],
[
11
],
[
12
],
[
13
],
[
14
],
[
15
],
[
16
]
] |
21,409 | static int configure_video_filters(FilterGraph *fg)
{
InputStream *ist = fg->inputs[0]->ist;
OutputStream *ost = fg->outputs[0]->ost;
AVFilterContext *in_filter, *out_filter, *filter;
AVCodecContext *codec = ost->st->codec;
AVBufferSinkParams *buffersink_params = av_buffersink_params_alloc();
char *pix_fmts;
AVRational sample_aspect_ratio;
char args[255];
int ret;
avfilter_graph_free(&fg->graph);
fg->graph = avfilter_graph_alloc();
if (!fg->graph)
return AVERROR(ENOMEM);
if (ist->st->sample_aspect_ratio.num) {
sample_aspect_ratio = ist->st->sample_aspect_ratio;
} else
sample_aspect_ratio = ist->st->codec->sample_aspect_ratio;
snprintf(args, 255, "%d:%d:%d:%d:%d:%d:%d:flags=%d", ist->st->codec->width,
ist->st->codec->height, ist->st->codec->pix_fmt, 1, AV_TIME_BASE,
sample_aspect_ratio.num, sample_aspect_ratio.den, SWS_BILINEAR + ((ist->st->codec->flags&CODEC_FLAG_BITEXACT) ? SWS_BITEXACT:0));
ret = avfilter_graph_create_filter(&fg->inputs[0]->filter,
avfilter_get_by_name("buffer"),
"src", args, NULL, fg->graph);
if (ret < 0)
return ret;
#if FF_API_OLD_VSINK_API
ret = avfilter_graph_create_filter(&fg->outputs[0]->filter,
avfilter_get_by_name("buffersink"),
"out", NULL, NULL, fg->graph);
#else
ret = avfilter_graph_create_filter(&fg->outputs[0]->filter,
avfilter_get_by_name("buffersink"),
"out", NULL, buffersink_params, fg->graph);
#endif
av_freep(&buffersink_params);
if (ret < 0)
return ret;
in_filter = fg->inputs[0]->filter;
out_filter = fg->outputs[0]->filter;
if (codec->width || codec->height) {
snprintf(args, 255, "%d:%d:flags=0x%X",
codec->width,
codec->height,
(unsigned)ost->sws_flags);
if ((ret = avfilter_graph_create_filter(&filter, avfilter_get_by_name("scale"),
NULL, args, NULL, fg->graph)) < 0)
return ret;
if ((ret = avfilter_link(in_filter, 0, filter, 0)) < 0)
return ret;
in_filter = filter;
}
if ((pix_fmts = choose_pixel_fmts(ost))) {
if ((ret = avfilter_graph_create_filter(&filter,
avfilter_get_by_name("format"),
"format", pix_fmts, NULL,
fg->graph)) < 0)
return ret;
if ((ret = avfilter_link(filter, 0, out_filter, 0)) < 0)
return ret;
out_filter = filter;
av_freep(&pix_fmts);
}
snprintf(args, sizeof(args), "flags=0x%X", (unsigned)ost->sws_flags);
fg->graph->scale_sws_opts = av_strdup(args);
if (ost->avfilter) {
AVFilterInOut *outputs = avfilter_inout_alloc();
AVFilterInOut *inputs = avfilter_inout_alloc();
outputs->name = av_strdup("in");
outputs->filter_ctx = in_filter;
outputs->pad_idx = 0;
outputs->next = NULL;
inputs->name = av_strdup("out");
inputs->filter_ctx = out_filter;
inputs->pad_idx = 0;
inputs->next = NULL;
if ((ret = avfilter_graph_parse(fg->graph, ost->avfilter, &inputs, &outputs, NULL)) < 0)
return ret;
av_freep(&ost->avfilter);
} else {
if ((ret = avfilter_link(in_filter, 0, out_filter, 0)) < 0)
return ret;
}
if (ost->keep_pix_fmt)
avfilter_graph_set_auto_convert(fg->graph,
AVFILTER_AUTO_CONVERT_NONE);
if ((ret = avfilter_graph_config(fg->graph, NULL)) < 0)
return ret;
ost->filter = fg->outputs[0];
return 0;
}
| true | FFmpeg | fc49f22c3b735db5aaac5f98e40b7124a2be13b8 | static int configure_video_filters(FilterGraph *fg)
{
InputStream *ist = fg->inputs[0]->ist;
OutputStream *ost = fg->outputs[0]->ost;
AVFilterContext *in_filter, *out_filter, *filter;
AVCodecContext *codec = ost->st->codec;
AVBufferSinkParams *buffersink_params = av_buffersink_params_alloc();
char *pix_fmts;
AVRational sample_aspect_ratio;
char args[255];
int ret;
avfilter_graph_free(&fg->graph);
fg->graph = avfilter_graph_alloc();
if (!fg->graph)
return AVERROR(ENOMEM);
if (ist->st->sample_aspect_ratio.num) {
sample_aspect_ratio = ist->st->sample_aspect_ratio;
} else
sample_aspect_ratio = ist->st->codec->sample_aspect_ratio;
snprintf(args, 255, "%d:%d:%d:%d:%d:%d:%d:flags=%d", ist->st->codec->width,
ist->st->codec->height, ist->st->codec->pix_fmt, 1, AV_TIME_BASE,
sample_aspect_ratio.num, sample_aspect_ratio.den, SWS_BILINEAR + ((ist->st->codec->flags&CODEC_FLAG_BITEXACT) ? SWS_BITEXACT:0));
ret = avfilter_graph_create_filter(&fg->inputs[0]->filter,
avfilter_get_by_name("buffer"),
"src", args, NULL, fg->graph);
if (ret < 0)
return ret;
#if FF_API_OLD_VSINK_API
ret = avfilter_graph_create_filter(&fg->outputs[0]->filter,
avfilter_get_by_name("buffersink"),
"out", NULL, NULL, fg->graph);
#else
ret = avfilter_graph_create_filter(&fg->outputs[0]->filter,
avfilter_get_by_name("buffersink"),
"out", NULL, buffersink_params, fg->graph);
#endif
av_freep(&buffersink_params);
if (ret < 0)
return ret;
in_filter = fg->inputs[0]->filter;
out_filter = fg->outputs[0]->filter;
if (codec->width || codec->height) {
snprintf(args, 255, "%d:%d:flags=0x%X",
codec->width,
codec->height,
(unsigned)ost->sws_flags);
if ((ret = avfilter_graph_create_filter(&filter, avfilter_get_by_name("scale"),
NULL, args, NULL, fg->graph)) < 0)
return ret;
if ((ret = avfilter_link(in_filter, 0, filter, 0)) < 0)
return ret;
in_filter = filter;
}
if ((pix_fmts = choose_pixel_fmts(ost))) {
if ((ret = avfilter_graph_create_filter(&filter,
avfilter_get_by_name("format"),
"format", pix_fmts, NULL,
fg->graph)) < 0)
return ret;
if ((ret = avfilter_link(filter, 0, out_filter, 0)) < 0)
return ret;
out_filter = filter;
av_freep(&pix_fmts);
}
snprintf(args, sizeof(args), "flags=0x%X", (unsigned)ost->sws_flags);
fg->graph->scale_sws_opts = av_strdup(args);
if (ost->avfilter) {
AVFilterInOut *outputs = avfilter_inout_alloc();
AVFilterInOut *inputs = avfilter_inout_alloc();
outputs->name = av_strdup("in");
outputs->filter_ctx = in_filter;
outputs->pad_idx = 0;
outputs->next = NULL;
inputs->name = av_strdup("out");
inputs->filter_ctx = out_filter;
inputs->pad_idx = 0;
inputs->next = NULL;
if ((ret = avfilter_graph_parse(fg->graph, ost->avfilter, &inputs, &outputs, NULL)) < 0)
return ret;
av_freep(&ost->avfilter);
} else {
if ((ret = avfilter_link(in_filter, 0, out_filter, 0)) < 0)
return ret;
}
if (ost->keep_pix_fmt)
avfilter_graph_set_auto_convert(fg->graph,
AVFILTER_AUTO_CONVERT_NONE);
if ((ret = avfilter_graph_config(fg->graph, NULL)) < 0)
return ret;
ost->filter = fg->outputs[0];
return 0;
}
| {
"code": [
"static int configure_video_filters(FilterGraph *fg)",
" AVFilterContext *in_filter, *out_filter, *filter;",
" avfilter_graph_free(&fg->graph);",
" fg->graph = avfilter_graph_alloc();",
" if (!fg->graph)",
" return AVERROR(ENOMEM);",
" in_filter = fg->inputs[0]->filter;",
" out_filter = fg->outputs[0]->filter;",
" if ((ret = avfilter_link(in_filter, 0, filter, 0)) < 0)",
" in_filter = filter;",
" if ((pix_fmts = choose_pixel_fmts(ost))) {",
" if ((ret = avfilter_link(filter, 0, out_filter, 0)) < 0)",
" out_filter = filter;",
" return AVERROR(ENOMEM);",
" return 0;",
" } else {",
" } else {"
],
"line_no": [
1,
9,
25,
27,
29,
31,
91,
93,
113,
117,
123,
135,
141,
31,
217,
189,
189
]
} | static int FUNC_0(FilterGraph *VAR_0)
{
InputStream *ist = VAR_0->inputs[0]->ist;
OutputStream *ost = VAR_0->outputs[0]->ost;
AVFilterContext *in_filter, *out_filter, *filter;
AVCodecContext *codec = ost->st->codec;
AVBufferSinkParams *buffersink_params = av_buffersink_params_alloc();
char *VAR_1;
AVRational sample_aspect_ratio;
char VAR_2[255];
int VAR_3;
avfilter_graph_free(&VAR_0->graph);
VAR_0->graph = avfilter_graph_alloc();
if (!VAR_0->graph)
return AVERROR(ENOMEM);
if (ist->st->sample_aspect_ratio.num) {
sample_aspect_ratio = ist->st->sample_aspect_ratio;
} else
sample_aspect_ratio = ist->st->codec->sample_aspect_ratio;
snprintf(VAR_2, 255, "%d:%d:%d:%d:%d:%d:%d:flags=%d", ist->st->codec->width,
ist->st->codec->height, ist->st->codec->pix_fmt, 1, AV_TIME_BASE,
sample_aspect_ratio.num, sample_aspect_ratio.den, SWS_BILINEAR + ((ist->st->codec->flags&CODEC_FLAG_BITEXACT) ? SWS_BITEXACT:0));
VAR_3 = avfilter_graph_create_filter(&VAR_0->inputs[0]->filter,
avfilter_get_by_name("buffer"),
"src", VAR_2, NULL, VAR_0->graph);
if (VAR_3 < 0)
return VAR_3;
#if FF_API_OLD_VSINK_API
VAR_3 = avfilter_graph_create_filter(&VAR_0->outputs[0]->filter,
avfilter_get_by_name("buffersink"),
"out", NULL, NULL, VAR_0->graph);
#else
VAR_3 = avfilter_graph_create_filter(&VAR_0->outputs[0]->filter,
avfilter_get_by_name("buffersink"),
"out", NULL, buffersink_params, VAR_0->graph);
#endif
av_freep(&buffersink_params);
if (VAR_3 < 0)
return VAR_3;
in_filter = VAR_0->inputs[0]->filter;
out_filter = VAR_0->outputs[0]->filter;
if (codec->width || codec->height) {
snprintf(VAR_2, 255, "%d:%d:flags=0x%X",
codec->width,
codec->height,
(unsigned)ost->sws_flags);
if ((VAR_3 = avfilter_graph_create_filter(&filter, avfilter_get_by_name("scale"),
NULL, VAR_2, NULL, VAR_0->graph)) < 0)
return VAR_3;
if ((VAR_3 = avfilter_link(in_filter, 0, filter, 0)) < 0)
return VAR_3;
in_filter = filter;
}
if ((VAR_1 = choose_pixel_fmts(ost))) {
if ((VAR_3 = avfilter_graph_create_filter(&filter,
avfilter_get_by_name("format"),
"format", VAR_1, NULL,
VAR_0->graph)) < 0)
return VAR_3;
if ((VAR_3 = avfilter_link(filter, 0, out_filter, 0)) < 0)
return VAR_3;
out_filter = filter;
av_freep(&VAR_1);
}
snprintf(VAR_2, sizeof(VAR_2), "flags=0x%X", (unsigned)ost->sws_flags);
VAR_0->graph->scale_sws_opts = av_strdup(VAR_2);
if (ost->avfilter) {
AVFilterInOut *outputs = avfilter_inout_alloc();
AVFilterInOut *inputs = avfilter_inout_alloc();
outputs->name = av_strdup("in");
outputs->filter_ctx = in_filter;
outputs->pad_idx = 0;
outputs->next = NULL;
inputs->name = av_strdup("out");
inputs->filter_ctx = out_filter;
inputs->pad_idx = 0;
inputs->next = NULL;
if ((VAR_3 = avfilter_graph_parse(VAR_0->graph, ost->avfilter, &inputs, &outputs, NULL)) < 0)
return VAR_3;
av_freep(&ost->avfilter);
} else {
if ((VAR_3 = avfilter_link(in_filter, 0, out_filter, 0)) < 0)
return VAR_3;
}
if (ost->keep_pix_fmt)
avfilter_graph_set_auto_convert(VAR_0->graph,
AVFILTER_AUTO_CONVERT_NONE);
if ((VAR_3 = avfilter_graph_config(VAR_0->graph, NULL)) < 0)
return VAR_3;
ost->filter = VAR_0->outputs[0];
return 0;
}
| [
"static int FUNC_0(FilterGraph *VAR_0)\n{",
"InputStream *ist = VAR_0->inputs[0]->ist;",
"OutputStream *ost = VAR_0->outputs[0]->ost;",
"AVFilterContext *in_filter, *out_filter, *filter;",
"AVCodecContext *codec = ost->st->codec;",
"AVBufferSinkParams *buffersink_params = av_buffersink_params_alloc();",
"char *VAR_1;",
"AVRational sample_aspect_ratio;",
"char VAR_2[255];",
"int VAR_3;",
"avfilter_graph_free(&VAR_0->graph);",
"VAR_0->graph = avfilter_graph_alloc();",
"if (!VAR_0->graph)\nreturn AVERROR(ENOMEM);",
"if (ist->st->sample_aspect_ratio.num) {",
"sample_aspect_ratio = ist->st->sample_aspect_ratio;",
"} else",
"sample_aspect_ratio = ist->st->codec->sample_aspect_ratio;",
"snprintf(VAR_2, 255, \"%d:%d:%d:%d:%d:%d:%d:flags=%d\", ist->st->codec->width,\nist->st->codec->height, ist->st->codec->pix_fmt, 1, AV_TIME_BASE,\nsample_aspect_ratio.num, sample_aspect_ratio.den, SWS_BILINEAR + ((ist->st->codec->flags&CODEC_FLAG_BITEXACT) ? SWS_BITEXACT:0));",
"VAR_3 = avfilter_graph_create_filter(&VAR_0->inputs[0]->filter,\navfilter_get_by_name(\"buffer\"),\n\"src\", VAR_2, NULL, VAR_0->graph);",
"if (VAR_3 < 0)\nreturn VAR_3;",
"#if FF_API_OLD_VSINK_API\nVAR_3 = avfilter_graph_create_filter(&VAR_0->outputs[0]->filter,\navfilter_get_by_name(\"buffersink\"),\n\"out\", NULL, NULL, VAR_0->graph);",
"#else\nVAR_3 = avfilter_graph_create_filter(&VAR_0->outputs[0]->filter,\navfilter_get_by_name(\"buffersink\"),\n\"out\", NULL, buffersink_params, VAR_0->graph);",
"#endif\nav_freep(&buffersink_params);",
"if (VAR_3 < 0)\nreturn VAR_3;",
"in_filter = VAR_0->inputs[0]->filter;",
"out_filter = VAR_0->outputs[0]->filter;",
"if (codec->width || codec->height) {",
"snprintf(VAR_2, 255, \"%d:%d:flags=0x%X\",\ncodec->width,\ncodec->height,\n(unsigned)ost->sws_flags);",
"if ((VAR_3 = avfilter_graph_create_filter(&filter, avfilter_get_by_name(\"scale\"),\nNULL, VAR_2, NULL, VAR_0->graph)) < 0)\nreturn VAR_3;",
"if ((VAR_3 = avfilter_link(in_filter, 0, filter, 0)) < 0)\nreturn VAR_3;",
"in_filter = filter;",
"}",
"if ((VAR_1 = choose_pixel_fmts(ost))) {",
"if ((VAR_3 = avfilter_graph_create_filter(&filter,\navfilter_get_by_name(\"format\"),\n\"format\", VAR_1, NULL,\nVAR_0->graph)) < 0)\nreturn VAR_3;",
"if ((VAR_3 = avfilter_link(filter, 0, out_filter, 0)) < 0)\nreturn VAR_3;",
"out_filter = filter;",
"av_freep(&VAR_1);",
"}",
"snprintf(VAR_2, sizeof(VAR_2), \"flags=0x%X\", (unsigned)ost->sws_flags);",
"VAR_0->graph->scale_sws_opts = av_strdup(VAR_2);",
"if (ost->avfilter) {",
"AVFilterInOut *outputs = avfilter_inout_alloc();",
"AVFilterInOut *inputs = avfilter_inout_alloc();",
"outputs->name = av_strdup(\"in\");",
"outputs->filter_ctx = in_filter;",
"outputs->pad_idx = 0;",
"outputs->next = NULL;",
"inputs->name = av_strdup(\"out\");",
"inputs->filter_ctx = out_filter;",
"inputs->pad_idx = 0;",
"inputs->next = NULL;",
"if ((VAR_3 = avfilter_graph_parse(VAR_0->graph, ost->avfilter, &inputs, &outputs, NULL)) < 0)\nreturn VAR_3;",
"av_freep(&ost->avfilter);",
"} else {",
"if ((VAR_3 = avfilter_link(in_filter, 0, out_filter, 0)) < 0)\nreturn VAR_3;",
"}",
"if (ost->keep_pix_fmt)\navfilter_graph_set_auto_convert(VAR_0->graph,\nAVFILTER_AUTO_CONVERT_NONE);",
"if ((VAR_3 = avfilter_graph_config(VAR_0->graph, NULL)) < 0)\nreturn VAR_3;",
"ost->filter = VAR_0->outputs[0];",
"return 0;",
"}"
] | [
1,
0,
0,
1,
0,
0,
0,
0,
0,
0,
1,
1,
1,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
1,
1,
0,
0,
0,
1,
1,
0,
1,
0,
1,
1,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
1,
0
] | [
[
1,
3
],
[
5
],
[
7
],
[
9
],
[
11
],
[
13
],
[
15
],
[
17
],
[
19
],
[
21
],
[
25
],
[
27
],
[
29,
31
],
[
35
],
[
37
],
[
39
],
[
41
],
[
45,
47,
49
],
[
53,
55,
57
],
[
59,
61
],
[
65,
67,
69,
71
],
[
73,
75,
77,
79
],
[
81,
83
],
[
87,
89
],
[
91
],
[
93
],
[
97
],
[
99,
101,
103,
105
],
[
107,
109,
111
],
[
113,
115
],
[
117
],
[
119
],
[
123
],
[
125,
127,
129,
131,
133
],
[
135,
137
],
[
141
],
[
143
],
[
145
],
[
149
],
[
151
],
[
155
],
[
157
],
[
159
],
[
163
],
[
165
],
[
167
],
[
169
],
[
173
],
[
175
],
[
177
],
[
179
],
[
183,
185
],
[
187
],
[
189
],
[
191,
193
],
[
195
],
[
199,
201,
203
],
[
207,
209
],
[
213
],
[
217
],
[
219
]
] |
21,410 | static inline void RET_STOP (DisasContext *ctx)
{
gen_update_nip(ctx, ctx->nip);
ctx->exception = EXCP_MTMSR;
}
| false | qemu | e1833e1f96456fd8fc17463246fe0b2050e68efb | static inline void RET_STOP (DisasContext *ctx)
{
gen_update_nip(ctx, ctx->nip);
ctx->exception = EXCP_MTMSR;
}
| {
"code": [],
"line_no": []
} | static inline void FUNC_0 (DisasContext *VAR_0)
{
gen_update_nip(VAR_0, VAR_0->nip);
VAR_0->exception = EXCP_MTMSR;
}
| [
"static inline void FUNC_0 (DisasContext *VAR_0)\n{",
"gen_update_nip(VAR_0, VAR_0->nip);",
"VAR_0->exception = EXCP_MTMSR;",
"}"
] | [
0,
0,
0,
0
] | [
[
1,
3
],
[
5
],
[
7
],
[
9
]
] |
21,412 | void qdev_property_add_legacy(DeviceState *dev, Property *prop,
Error **errp)
{
gchar *type;
type = g_strdup_printf("legacy<%s>", prop->info->name);
qdev_property_add(dev, prop->name, type,
qdev_get_legacy_property,
qdev_set_legacy_property,
NULL,
prop, errp);
g_free(type);
}
| false | qemu | e3cb6ba65d265f2cc1313ee26e879407ff24663c | void qdev_property_add_legacy(DeviceState *dev, Property *prop,
Error **errp)
{
gchar *type;
type = g_strdup_printf("legacy<%s>", prop->info->name);
qdev_property_add(dev, prop->name, type,
qdev_get_legacy_property,
qdev_set_legacy_property,
NULL,
prop, errp);
g_free(type);
}
| {
"code": [],
"line_no": []
} | void FUNC_0(DeviceState *VAR_0, Property *VAR_1,
Error **VAR_2)
{
gchar *type;
type = g_strdup_printf("legacy<%s>", VAR_1->info->name);
qdev_property_add(VAR_0, VAR_1->name, type,
qdev_get_legacy_property,
qdev_set_legacy_property,
NULL,
VAR_1, VAR_2);
g_free(type);
}
| [
"void FUNC_0(DeviceState *VAR_0, Property *VAR_1,\nError **VAR_2)\n{",
"gchar *type;",
"type = g_strdup_printf(\"legacy<%s>\", VAR_1->info->name);",
"qdev_property_add(VAR_0, VAR_1->name, type,\nqdev_get_legacy_property,\nqdev_set_legacy_property,\nNULL,\nVAR_1, VAR_2);",
"g_free(type);",
"}"
] | [
0,
0,
0,
0,
0,
0
] | [
[
1,
3,
5
],
[
7
],
[
11
],
[
15,
17,
19,
21,
23
],
[
27
],
[
29
]
] |
21,414 | uint64_t helper_fmadd(CPUPPCState *env, uint64_t arg1, uint64_t arg2,
uint64_t arg3)
{
CPU_DoubleU farg1, farg2, farg3;
farg1.ll = arg1;
farg2.ll = arg2;
farg3.ll = arg3;
if (unlikely((float64_is_infinity(farg1.d) && float64_is_zero(farg2.d)) ||
(float64_is_zero(farg1.d) && float64_is_infinity(farg2.d)))) {
/* Multiplication of zero by infinity */
farg1.ll = fload_invalid_op_excp(env, POWERPC_EXCP_FP_VXIMZ);
} else {
if (unlikely(float64_is_signaling_nan(farg1.d) ||
float64_is_signaling_nan(farg2.d) ||
float64_is_signaling_nan(farg3.d))) {
/* sNaN operation */
fload_invalid_op_excp(env, POWERPC_EXCP_FP_VXSNAN);
}
/* This is the way the PowerPC specification defines it */
float128 ft0_128, ft1_128;
ft0_128 = float64_to_float128(farg1.d, &env->fp_status);
ft1_128 = float64_to_float128(farg2.d, &env->fp_status);
ft0_128 = float128_mul(ft0_128, ft1_128, &env->fp_status);
if (unlikely(float128_is_infinity(ft0_128) &&
float64_is_infinity(farg3.d) &&
float128_is_neg(ft0_128) != float64_is_neg(farg3.d))) {
/* Magnitude subtraction of infinities */
farg1.ll = fload_invalid_op_excp(env, POWERPC_EXCP_FP_VXISI);
} else {
ft1_128 = float64_to_float128(farg3.d, &env->fp_status);
ft0_128 = float128_add(ft0_128, ft1_128, &env->fp_status);
farg1.d = float128_to_float64(ft0_128, &env->fp_status);
}
}
return farg1.ll;
}
| false | qemu | 59800ec8e52bcfa271fa61fb0aae19205ef1b7f1 | uint64_t helper_fmadd(CPUPPCState *env, uint64_t arg1, uint64_t arg2,
uint64_t arg3)
{
CPU_DoubleU farg1, farg2, farg3;
farg1.ll = arg1;
farg2.ll = arg2;
farg3.ll = arg3;
if (unlikely((float64_is_infinity(farg1.d) && float64_is_zero(farg2.d)) ||
(float64_is_zero(farg1.d) && float64_is_infinity(farg2.d)))) {
farg1.ll = fload_invalid_op_excp(env, POWERPC_EXCP_FP_VXIMZ);
} else {
if (unlikely(float64_is_signaling_nan(farg1.d) ||
float64_is_signaling_nan(farg2.d) ||
float64_is_signaling_nan(farg3.d))) {
fload_invalid_op_excp(env, POWERPC_EXCP_FP_VXSNAN);
}
float128 ft0_128, ft1_128;
ft0_128 = float64_to_float128(farg1.d, &env->fp_status);
ft1_128 = float64_to_float128(farg2.d, &env->fp_status);
ft0_128 = float128_mul(ft0_128, ft1_128, &env->fp_status);
if (unlikely(float128_is_infinity(ft0_128) &&
float64_is_infinity(farg3.d) &&
float128_is_neg(ft0_128) != float64_is_neg(farg3.d))) {
farg1.ll = fload_invalid_op_excp(env, POWERPC_EXCP_FP_VXISI);
} else {
ft1_128 = float64_to_float128(farg3.d, &env->fp_status);
ft0_128 = float128_add(ft0_128, ft1_128, &env->fp_status);
farg1.d = float128_to_float64(ft0_128, &env->fp_status);
}
}
return farg1.ll;
}
| {
"code": [],
"line_no": []
} | uint64_t FUNC_0(CPUPPCState *env, uint64_t arg1, uint64_t arg2,
uint64_t arg3)
{
CPU_DoubleU farg1, farg2, farg3;
farg1.ll = arg1;
farg2.ll = arg2;
farg3.ll = arg3;
if (unlikely((float64_is_infinity(farg1.d) && float64_is_zero(farg2.d)) ||
(float64_is_zero(farg1.d) && float64_is_infinity(farg2.d)))) {
farg1.ll = fload_invalid_op_excp(env, POWERPC_EXCP_FP_VXIMZ);
} else {
if (unlikely(float64_is_signaling_nan(farg1.d) ||
float64_is_signaling_nan(farg2.d) ||
float64_is_signaling_nan(farg3.d))) {
fload_invalid_op_excp(env, POWERPC_EXCP_FP_VXSNAN);
}
float128 ft0_128, ft1_128;
ft0_128 = float64_to_float128(farg1.d, &env->fp_status);
ft1_128 = float64_to_float128(farg2.d, &env->fp_status);
ft0_128 = float128_mul(ft0_128, ft1_128, &env->fp_status);
if (unlikely(float128_is_infinity(ft0_128) &&
float64_is_infinity(farg3.d) &&
float128_is_neg(ft0_128) != float64_is_neg(farg3.d))) {
farg1.ll = fload_invalid_op_excp(env, POWERPC_EXCP_FP_VXISI);
} else {
ft1_128 = float64_to_float128(farg3.d, &env->fp_status);
ft0_128 = float128_add(ft0_128, ft1_128, &env->fp_status);
farg1.d = float128_to_float64(ft0_128, &env->fp_status);
}
}
return farg1.ll;
}
| [
"uint64_t FUNC_0(CPUPPCState *env, uint64_t arg1, uint64_t arg2,\nuint64_t arg3)\n{",
"CPU_DoubleU farg1, farg2, farg3;",
"farg1.ll = arg1;",
"farg2.ll = arg2;",
"farg3.ll = arg3;",
"if (unlikely((float64_is_infinity(farg1.d) && float64_is_zero(farg2.d)) ||\n(float64_is_zero(farg1.d) && float64_is_infinity(farg2.d)))) {",
"farg1.ll = fload_invalid_op_excp(env, POWERPC_EXCP_FP_VXIMZ);",
"} else {",
"if (unlikely(float64_is_signaling_nan(farg1.d) ||\nfloat64_is_signaling_nan(farg2.d) ||\nfloat64_is_signaling_nan(farg3.d))) {",
"fload_invalid_op_excp(env, POWERPC_EXCP_FP_VXSNAN);",
"}",
"float128 ft0_128, ft1_128;",
"ft0_128 = float64_to_float128(farg1.d, &env->fp_status);",
"ft1_128 = float64_to_float128(farg2.d, &env->fp_status);",
"ft0_128 = float128_mul(ft0_128, ft1_128, &env->fp_status);",
"if (unlikely(float128_is_infinity(ft0_128) &&\nfloat64_is_infinity(farg3.d) &&\nfloat128_is_neg(ft0_128) != float64_is_neg(farg3.d))) {",
"farg1.ll = fload_invalid_op_excp(env, POWERPC_EXCP_FP_VXISI);",
"} else {",
"ft1_128 = float64_to_float128(farg3.d, &env->fp_status);",
"ft0_128 = float128_add(ft0_128, ft1_128, &env->fp_status);",
"farg1.d = float128_to_float64(ft0_128, &env->fp_status);",
"}",
"}",
"return farg1.ll;",
"}"
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | [
[
1,
3,
5
],
[
7
],
[
11
],
[
13
],
[
15
],
[
19,
21
],
[
25
],
[
27
],
[
29,
31,
33
],
[
37
],
[
39
],
[
43
],
[
47
],
[
49
],
[
51
],
[
53,
55,
57
],
[
61
],
[
63
],
[
65
],
[
67
],
[
69
],
[
71
],
[
73
],
[
77
],
[
79
]
] |
21,415 | static void tcg_out_andi64(TCGContext *s, TCGReg dst, TCGReg src, uint64_t c)
{
int mb, me;
assert(TCG_TARGET_REG_BITS == 64);
if (mask64_operand(c, &mb, &me)) {
if (mb == 0) {
tcg_out_rld(s, RLDICR, dst, src, 0, me);
} else {
tcg_out_rld(s, RLDICL, dst, src, 0, mb);
}
} else if ((c & 0xffff) == c) {
tcg_out32(s, ANDI | SAI(src, dst, c));
return;
} else if ((c & 0xffff0000) == c) {
tcg_out32(s, ANDIS | SAI(src, dst, c >> 16));
return;
} else {
tcg_out_movi(s, TCG_TYPE_I64, TCG_REG_R0, c);
tcg_out32(s, AND | SAB(src, dst, TCG_REG_R0));
}
}
| false | qemu | eabb7b91b36b202b4dac2df2d59d698e3aff197a | static void tcg_out_andi64(TCGContext *s, TCGReg dst, TCGReg src, uint64_t c)
{
int mb, me;
assert(TCG_TARGET_REG_BITS == 64);
if (mask64_operand(c, &mb, &me)) {
if (mb == 0) {
tcg_out_rld(s, RLDICR, dst, src, 0, me);
} else {
tcg_out_rld(s, RLDICL, dst, src, 0, mb);
}
} else if ((c & 0xffff) == c) {
tcg_out32(s, ANDI | SAI(src, dst, c));
return;
} else if ((c & 0xffff0000) == c) {
tcg_out32(s, ANDIS | SAI(src, dst, c >> 16));
return;
} else {
tcg_out_movi(s, TCG_TYPE_I64, TCG_REG_R0, c);
tcg_out32(s, AND | SAB(src, dst, TCG_REG_R0));
}
}
| {
"code": [],
"line_no": []
} | static void FUNC_0(TCGContext *VAR_0, TCGReg VAR_1, TCGReg VAR_2, uint64_t VAR_3)
{
int VAR_4, VAR_5;
assert(TCG_TARGET_REG_BITS == 64);
if (mask64_operand(VAR_3, &VAR_4, &VAR_5)) {
if (VAR_4 == 0) {
tcg_out_rld(VAR_0, RLDICR, VAR_1, VAR_2, 0, VAR_5);
} else {
tcg_out_rld(VAR_0, RLDICL, VAR_1, VAR_2, 0, VAR_4);
}
} else if ((VAR_3 & 0xffff) == VAR_3) {
tcg_out32(VAR_0, ANDI | SAI(VAR_2, VAR_1, VAR_3));
return;
} else if ((VAR_3 & 0xffff0000) == VAR_3) {
tcg_out32(VAR_0, ANDIS | SAI(VAR_2, VAR_1, VAR_3 >> 16));
return;
} else {
tcg_out_movi(VAR_0, TCG_TYPE_I64, TCG_REG_R0, VAR_3);
tcg_out32(VAR_0, AND | SAB(VAR_2, VAR_1, TCG_REG_R0));
}
}
| [
"static void FUNC_0(TCGContext *VAR_0, TCGReg VAR_1, TCGReg VAR_2, uint64_t VAR_3)\n{",
"int VAR_4, VAR_5;",
"assert(TCG_TARGET_REG_BITS == 64);",
"if (mask64_operand(VAR_3, &VAR_4, &VAR_5)) {",
"if (VAR_4 == 0) {",
"tcg_out_rld(VAR_0, RLDICR, VAR_1, VAR_2, 0, VAR_5);",
"} else {",
"tcg_out_rld(VAR_0, RLDICL, VAR_1, VAR_2, 0, VAR_4);",
"}",
"} else if ((VAR_3 & 0xffff) == VAR_3) {",
"tcg_out32(VAR_0, ANDI | SAI(VAR_2, VAR_1, VAR_3));",
"return;",
"} else if ((VAR_3 & 0xffff0000) == VAR_3) {",
"tcg_out32(VAR_0, ANDIS | SAI(VAR_2, VAR_1, VAR_3 >> 16));",
"return;",
"} else {",
"tcg_out_movi(VAR_0, TCG_TYPE_I64, TCG_REG_R0, VAR_3);",
"tcg_out32(VAR_0, AND | SAB(VAR_2, VAR_1, TCG_REG_R0));",
"}",
"}"
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | [
[
1,
3
],
[
5
],
[
9
],
[
11
],
[
13
],
[
15
],
[
17
],
[
19
],
[
21
],
[
23
],
[
25
],
[
27
],
[
29
],
[
31
],
[
33
],
[
35
],
[
37
],
[
39
],
[
41
],
[
43
]
] |
21,416 | static void eth_cleanup(NetClientState *nc)
{
ETRAXFSEthState *eth = qemu_get_nic_opaque(nc);
/* Disconnect the client. */
eth->dma_out->client.push = NULL;
eth->dma_out->client.opaque = NULL;
eth->dma_in->client.opaque = NULL;
eth->dma_in->client.pull = NULL;
g_free(eth);
}
| false | qemu | 57407ea44cc0a3d630b9b89a2be011f1955ce5c1 | static void eth_cleanup(NetClientState *nc)
{
ETRAXFSEthState *eth = qemu_get_nic_opaque(nc);
eth->dma_out->client.push = NULL;
eth->dma_out->client.opaque = NULL;
eth->dma_in->client.opaque = NULL;
eth->dma_in->client.pull = NULL;
g_free(eth);
}
| {
"code": [],
"line_no": []
} | static void FUNC_0(NetClientState *VAR_0)
{
ETRAXFSEthState *eth = qemu_get_nic_opaque(VAR_0);
eth->dma_out->client.push = NULL;
eth->dma_out->client.opaque = NULL;
eth->dma_in->client.opaque = NULL;
eth->dma_in->client.pull = NULL;
g_free(eth);
}
| [
"static void FUNC_0(NetClientState *VAR_0)\n{",
"ETRAXFSEthState *eth = qemu_get_nic_opaque(VAR_0);",
"eth->dma_out->client.push = NULL;",
"eth->dma_out->client.opaque = NULL;",
"eth->dma_in->client.opaque = NULL;",
"eth->dma_in->client.pull = NULL;",
"g_free(eth);",
"}"
] | [
0,
0,
0,
0,
0,
0,
0,
0
] | [
[
1,
3
],
[
5
],
[
11
],
[
13
],
[
15
],
[
17
],
[
19
],
[
21
]
] |
21,418 | long do_sigreturn(CPUCRISState *env)
{
struct target_signal_frame *frame;
abi_ulong frame_addr;
target_sigset_t target_set;
sigset_t set;
int i;
frame_addr = env->regs[R_SP];
/* Make sure the guest isn't playing games. */
if (!lock_user_struct(VERIFY_WRITE, frame, frame_addr, 1))
goto badframe;
/* Restore blocked signals */
if (__get_user(target_set.sig[0], &frame->sc.oldmask))
goto badframe;
for(i = 1; i < TARGET_NSIG_WORDS; i++) {
if (__get_user(target_set.sig[i], &frame->extramask[i - 1]))
goto badframe;
}
target_to_host_sigset_internal(&set, &target_set);
sigprocmask(SIG_SETMASK, &set, NULL);
restore_sigcontext(&frame->sc, env);
unlock_user_struct(frame, frame_addr, 0);
return env->regs[10];
badframe:
unlock_user_struct(frame, frame_addr, 0);
force_sig(TARGET_SIGSEGV);
}
| false | qemu | 1c275925bfbbc2de84a8f0e09d1dd70bbefb6da3 | long do_sigreturn(CPUCRISState *env)
{
struct target_signal_frame *frame;
abi_ulong frame_addr;
target_sigset_t target_set;
sigset_t set;
int i;
frame_addr = env->regs[R_SP];
if (!lock_user_struct(VERIFY_WRITE, frame, frame_addr, 1))
goto badframe;
if (__get_user(target_set.sig[0], &frame->sc.oldmask))
goto badframe;
for(i = 1; i < TARGET_NSIG_WORDS; i++) {
if (__get_user(target_set.sig[i], &frame->extramask[i - 1]))
goto badframe;
}
target_to_host_sigset_internal(&set, &target_set);
sigprocmask(SIG_SETMASK, &set, NULL);
restore_sigcontext(&frame->sc, env);
unlock_user_struct(frame, frame_addr, 0);
return env->regs[10];
badframe:
unlock_user_struct(frame, frame_addr, 0);
force_sig(TARGET_SIGSEGV);
}
| {
"code": [],
"line_no": []
} | long FUNC_0(CPUCRISState *VAR_0)
{
struct target_signal_frame *VAR_1;
abi_ulong frame_addr;
target_sigset_t target_set;
sigset_t set;
int VAR_2;
frame_addr = VAR_0->regs[R_SP];
if (!lock_user_struct(VERIFY_WRITE, VAR_1, frame_addr, 1))
goto badframe;
if (__get_user(target_set.sig[0], &VAR_1->sc.oldmask))
goto badframe;
for(VAR_2 = 1; VAR_2 < TARGET_NSIG_WORDS; VAR_2++) {
if (__get_user(target_set.sig[VAR_2], &VAR_1->extramask[VAR_2 - 1]))
goto badframe;
}
target_to_host_sigset_internal(&set, &target_set);
sigprocmask(SIG_SETMASK, &set, NULL);
restore_sigcontext(&VAR_1->sc, VAR_0);
unlock_user_struct(VAR_1, frame_addr, 0);
return VAR_0->regs[10];
badframe:
unlock_user_struct(VAR_1, frame_addr, 0);
force_sig(TARGET_SIGSEGV);
}
| [
"long FUNC_0(CPUCRISState *VAR_0)\n{",
"struct target_signal_frame *VAR_1;",
"abi_ulong frame_addr;",
"target_sigset_t target_set;",
"sigset_t set;",
"int VAR_2;",
"frame_addr = VAR_0->regs[R_SP];",
"if (!lock_user_struct(VERIFY_WRITE, VAR_1, frame_addr, 1))\ngoto badframe;",
"if (__get_user(target_set.sig[0], &VAR_1->sc.oldmask))\ngoto badframe;",
"for(VAR_2 = 1; VAR_2 < TARGET_NSIG_WORDS; VAR_2++) {",
"if (__get_user(target_set.sig[VAR_2], &VAR_1->extramask[VAR_2 - 1]))\ngoto badframe;",
"}",
"target_to_host_sigset_internal(&set, &target_set);",
"sigprocmask(SIG_SETMASK, &set, NULL);",
"restore_sigcontext(&VAR_1->sc, VAR_0);",
"unlock_user_struct(VAR_1, frame_addr, 0);",
"return VAR_0->regs[10];",
"badframe:\nunlock_user_struct(VAR_1, frame_addr, 0);",
"force_sig(TARGET_SIGSEGV);",
"}"
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | [
[
1,
3
],
[
5
],
[
7
],
[
9
],
[
11
],
[
13
],
[
17
],
[
21,
23
],
[
29,
31
],
[
33
],
[
35,
37
],
[
39
],
[
41
],
[
43
],
[
47
],
[
49
],
[
51
],
[
53,
55
],
[
57
],
[
59
]
] |
21,419 | static inline int epoll_events_from_pfd(int pfd_events)
{
return (pfd_events & G_IO_IN ? EPOLLIN : 0) |
(pfd_events & G_IO_OUT ? EPOLLOUT : 0) |
(pfd_events & G_IO_HUP ? EPOLLHUP : 0) |
(pfd_events & G_IO_ERR ? EPOLLERR : 0);
}
| false | qemu | c2b38b277a7882a592f4f2ec955084b2b756daaa | static inline int epoll_events_from_pfd(int pfd_events)
{
return (pfd_events & G_IO_IN ? EPOLLIN : 0) |
(pfd_events & G_IO_OUT ? EPOLLOUT : 0) |
(pfd_events & G_IO_HUP ? EPOLLHUP : 0) |
(pfd_events & G_IO_ERR ? EPOLLERR : 0);
}
| {
"code": [],
"line_no": []
} | static inline int FUNC_0(int VAR_0)
{
return (VAR_0 & G_IO_IN ? EPOLLIN : 0) |
(VAR_0 & G_IO_OUT ? EPOLLOUT : 0) |
(VAR_0 & G_IO_HUP ? EPOLLHUP : 0) |
(VAR_0 & G_IO_ERR ? EPOLLERR : 0);
}
| [
"static inline int FUNC_0(int VAR_0)\n{",
"return (VAR_0 & G_IO_IN ? EPOLLIN : 0) |\n(VAR_0 & G_IO_OUT ? EPOLLOUT : 0) |\n(VAR_0 & G_IO_HUP ? EPOLLHUP : 0) |\n(VAR_0 & G_IO_ERR ? EPOLLERR : 0);",
"}"
] | [
0,
0,
0
] | [
[
1,
3
],
[
5,
7,
9,
11
],
[
13
]
] |
21,420 | static int mov_write_moov_tag(ByteIOContext *pb, MOVContext *mov)
{
int pos, i;
pos = url_ftell(pb);
put_be32(pb, 0); /* size placeholder*/
put_tag(pb, "moov");
mov->timescale = globalTimescale;
for (i=0; i<MAX_STREAMS; i++) {
if(mov->tracks[i].entry <= 0) continue;
if(mov->tracks[i].enc->codec_type == CODEC_TYPE_VIDEO) {
mov->tracks[i].timescale = mov->tracks[i].enc->frame_rate;
mov->tracks[i].sampleDuration = mov->tracks[i].enc->frame_rate_base;
}
else if(mov->tracks[i].enc->codec_type == CODEC_TYPE_AUDIO) {
/* If AMR, track timescale = 8000, AMR_WB = 16000 */
if(mov->tracks[i].enc->codec_id == CODEC_ID_AMR_NB) {
mov->tracks[i].sampleDuration = 160; // Bytes per chunk
mov->tracks[i].timescale = 8000;
}
else {
mov->tracks[i].timescale = mov->tracks[i].enc->sample_rate;
mov->tracks[i].sampleDuration = mov->tracks[i].enc->frame_size;
}
}
mov->tracks[i].trackDuration =
mov->tracks[i].sampleCount * mov->tracks[i].sampleDuration;
mov->tracks[i].time = mov->time;
mov->tracks[i].trackID = i+1;
}
mov_write_mvhd_tag(pb, mov);
//mov_write_iods_tag(pb, mov);
for (i=0; i<MAX_STREAMS; i++) {
if(mov->tracks[i].entry > 0) {
mov_write_trak_tag(pb, &(mov->tracks[i]));
}
}
return updateSize(pb, pos);
}
| false | FFmpeg | 69dde1ad36b7d95b8b9268f414aa6c076212ed41 | static int mov_write_moov_tag(ByteIOContext *pb, MOVContext *mov)
{
int pos, i;
pos = url_ftell(pb);
put_be32(pb, 0);
put_tag(pb, "moov");
mov->timescale = globalTimescale;
for (i=0; i<MAX_STREAMS; i++) {
if(mov->tracks[i].entry <= 0) continue;
if(mov->tracks[i].enc->codec_type == CODEC_TYPE_VIDEO) {
mov->tracks[i].timescale = mov->tracks[i].enc->frame_rate;
mov->tracks[i].sampleDuration = mov->tracks[i].enc->frame_rate_base;
}
else if(mov->tracks[i].enc->codec_type == CODEC_TYPE_AUDIO) {
if(mov->tracks[i].enc->codec_id == CODEC_ID_AMR_NB) {
mov->tracks[i].sampleDuration = 160;
mov->tracks[i].timescale = 8000;
}
else {
mov->tracks[i].timescale = mov->tracks[i].enc->sample_rate;
mov->tracks[i].sampleDuration = mov->tracks[i].enc->frame_size;
}
}
mov->tracks[i].trackDuration =
mov->tracks[i].sampleCount * mov->tracks[i].sampleDuration;
mov->tracks[i].time = mov->time;
mov->tracks[i].trackID = i+1;
}
mov_write_mvhd_tag(pb, mov);
for (i=0; i<MAX_STREAMS; i++) {
if(mov->tracks[i].entry > 0) {
mov_write_trak_tag(pb, &(mov->tracks[i]));
}
}
return updateSize(pb, pos);
}
| {
"code": [],
"line_no": []
} | static int FUNC_0(ByteIOContext *VAR_0, MOVContext *VAR_1)
{
int VAR_2, VAR_3;
VAR_2 = url_ftell(VAR_0);
put_be32(VAR_0, 0);
put_tag(VAR_0, "moov");
VAR_1->timescale = globalTimescale;
for (VAR_3=0; VAR_3<MAX_STREAMS; VAR_3++) {
if(VAR_1->tracks[VAR_3].entry <= 0) continue;
if(VAR_1->tracks[VAR_3].enc->codec_type == CODEC_TYPE_VIDEO) {
VAR_1->tracks[VAR_3].timescale = VAR_1->tracks[VAR_3].enc->frame_rate;
VAR_1->tracks[VAR_3].sampleDuration = VAR_1->tracks[VAR_3].enc->frame_rate_base;
}
else if(VAR_1->tracks[VAR_3].enc->codec_type == CODEC_TYPE_AUDIO) {
if(VAR_1->tracks[VAR_3].enc->codec_id == CODEC_ID_AMR_NB) {
VAR_1->tracks[VAR_3].sampleDuration = 160;
VAR_1->tracks[VAR_3].timescale = 8000;
}
else {
VAR_1->tracks[VAR_3].timescale = VAR_1->tracks[VAR_3].enc->sample_rate;
VAR_1->tracks[VAR_3].sampleDuration = VAR_1->tracks[VAR_3].enc->frame_size;
}
}
VAR_1->tracks[VAR_3].trackDuration =
VAR_1->tracks[VAR_3].sampleCount * VAR_1->tracks[VAR_3].sampleDuration;
VAR_1->tracks[VAR_3].time = VAR_1->time;
VAR_1->tracks[VAR_3].trackID = VAR_3+1;
}
mov_write_mvhd_tag(VAR_0, VAR_1);
for (VAR_3=0; VAR_3<MAX_STREAMS; VAR_3++) {
if(VAR_1->tracks[VAR_3].entry > 0) {
mov_write_trak_tag(VAR_0, &(VAR_1->tracks[VAR_3]));
}
}
return updateSize(VAR_0, VAR_2);
}
| [
"static int FUNC_0(ByteIOContext *VAR_0, MOVContext *VAR_1)\n{",
"int VAR_2, VAR_3;",
"VAR_2 = url_ftell(VAR_0);",
"put_be32(VAR_0, 0);",
"put_tag(VAR_0, \"moov\");",
"VAR_1->timescale = globalTimescale;",
"for (VAR_3=0; VAR_3<MAX_STREAMS; VAR_3++) {",
"if(VAR_1->tracks[VAR_3].entry <= 0) continue;",
"if(VAR_1->tracks[VAR_3].enc->codec_type == CODEC_TYPE_VIDEO) {",
"VAR_1->tracks[VAR_3].timescale = VAR_1->tracks[VAR_3].enc->frame_rate;",
"VAR_1->tracks[VAR_3].sampleDuration = VAR_1->tracks[VAR_3].enc->frame_rate_base;",
"}",
"else if(VAR_1->tracks[VAR_3].enc->codec_type == CODEC_TYPE_AUDIO) {",
"if(VAR_1->tracks[VAR_3].enc->codec_id == CODEC_ID_AMR_NB) {",
"VAR_1->tracks[VAR_3].sampleDuration = 160;",
"VAR_1->tracks[VAR_3].timescale = 8000;",
"}",
"else {",
"VAR_1->tracks[VAR_3].timescale = VAR_1->tracks[VAR_3].enc->sample_rate;",
"VAR_1->tracks[VAR_3].sampleDuration = VAR_1->tracks[VAR_3].enc->frame_size;",
"}",
"}",
"VAR_1->tracks[VAR_3].trackDuration =\nVAR_1->tracks[VAR_3].sampleCount * VAR_1->tracks[VAR_3].sampleDuration;",
"VAR_1->tracks[VAR_3].time = VAR_1->time;",
"VAR_1->tracks[VAR_3].trackID = VAR_3+1;",
"}",
"mov_write_mvhd_tag(VAR_0, VAR_1);",
"for (VAR_3=0; VAR_3<MAX_STREAMS; VAR_3++) {",
"if(VAR_1->tracks[VAR_3].entry > 0) {",
"mov_write_trak_tag(VAR_0, &(VAR_1->tracks[VAR_3]));",
"}",
"}",
"return updateSize(VAR_0, VAR_2);",
"}"
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | [
[
1,
3
],
[
5
],
[
7
],
[
9
],
[
11
],
[
13
],
[
17
],
[
19
],
[
23
],
[
25
],
[
27
],
[
29
],
[
31
],
[
35
],
[
37
],
[
39
],
[
41
],
[
43
],
[
45
],
[
47
],
[
49
],
[
51
],
[
55,
57
],
[
59
],
[
61
],
[
63
],
[
67
],
[
71
],
[
73
],
[
75
],
[
77
],
[
79
],
[
83
],
[
85
]
] |
21,421 | static void mips_cps_realize(DeviceState *dev, Error **errp)
{
MIPSCPSState *s = MIPS_CPS(dev);
CPUMIPSState *env;
MIPSCPU *cpu;
int i;
Error *err = NULL;
target_ulong gcr_base;
bool itu_present = false;
for (i = 0; i < s->num_vp; i++) {
cpu = cpu_mips_init(s->cpu_model);
if (cpu == NULL) {
error_setg(errp, "%s: CPU initialization failed\n", __func__);
return;
}
/* Init internal devices */
cpu_mips_irq_init_cpu(cpu);
cpu_mips_clock_init(cpu);
env = &cpu->env;
if (cpu_mips_itu_supported(env)) {
itu_present = true;
/* Attach ITC Tag to the VP */
env->itc_tag = mips_itu_get_tag_region(&s->itu);
}
qemu_register_reset(main_cpu_reset, cpu);
}
cpu = MIPS_CPU(first_cpu);
env = &cpu->env;
/* Inter-Thread Communication Unit */
if (itu_present) {
object_initialize(&s->itu, sizeof(s->itu), TYPE_MIPS_ITU);
qdev_set_parent_bus(DEVICE(&s->itu), sysbus_get_default());
object_property_set_int(OBJECT(&s->itu), 16, "num-fifo", &err);
object_property_set_int(OBJECT(&s->itu), 16, "num-semaphores", &err);
object_property_set_bool(OBJECT(&s->itu), true, "realized", &err);
if (err != NULL) {
error_propagate(errp, err);
return;
}
memory_region_add_subregion(&s->container, 0,
sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->itu), 0));
}
/* Cluster Power Controller */
object_initialize(&s->cpc, sizeof(s->cpc), TYPE_MIPS_CPC);
qdev_set_parent_bus(DEVICE(&s->cpc), sysbus_get_default());
object_property_set_int(OBJECT(&s->cpc), s->num_vp, "num-vp", &err);
object_property_set_int(OBJECT(&s->cpc), 1, "vp-start-running", &err);
object_property_set_bool(OBJECT(&s->cpc), true, "realized", &err);
if (err != NULL) {
error_propagate(errp, err);
return;
}
memory_region_add_subregion(&s->container, 0,
sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->cpc), 0));
/* Global Interrupt Controller */
object_initialize(&s->gic, sizeof(s->gic), TYPE_MIPS_GIC);
qdev_set_parent_bus(DEVICE(&s->gic), sysbus_get_default());
object_property_set_int(OBJECT(&s->gic), s->num_vp, "num-vp", &err);
object_property_set_int(OBJECT(&s->gic), 128, "num-irq", &err);
object_property_set_bool(OBJECT(&s->gic), true, "realized", &err);
if (err != NULL) {
error_propagate(errp, err);
return;
}
memory_region_add_subregion(&s->container, 0,
sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->gic), 0));
/* Global Configuration Registers */
gcr_base = env->CP0_CMGCRBase << 4;
object_initialize(&s->gcr, sizeof(s->gcr), TYPE_MIPS_GCR);
qdev_set_parent_bus(DEVICE(&s->gcr), sysbus_get_default());
object_property_set_int(OBJECT(&s->gcr), s->num_vp, "num-vp", &err);
object_property_set_int(OBJECT(&s->gcr), 0x800, "gcr-rev", &err);
object_property_set_int(OBJECT(&s->gcr), gcr_base, "gcr-base", &err);
object_property_set_link(OBJECT(&s->gcr), OBJECT(&s->gic.mr), "gic", &err);
object_property_set_link(OBJECT(&s->gcr), OBJECT(&s->cpc.mr), "cpc", &err);
object_property_set_bool(OBJECT(&s->gcr), true, "realized", &err);
if (err != NULL) {
error_propagate(errp, err);
return;
}
memory_region_add_subregion(&s->container, gcr_base,
sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->gcr), 0));
}
| false | qemu | df3c286c53ac51e7267f2761c7a0c62e11b6e815 | static void mips_cps_realize(DeviceState *dev, Error **errp)
{
MIPSCPSState *s = MIPS_CPS(dev);
CPUMIPSState *env;
MIPSCPU *cpu;
int i;
Error *err = NULL;
target_ulong gcr_base;
bool itu_present = false;
for (i = 0; i < s->num_vp; i++) {
cpu = cpu_mips_init(s->cpu_model);
if (cpu == NULL) {
error_setg(errp, "%s: CPU initialization failed\n", __func__);
return;
}
cpu_mips_irq_init_cpu(cpu);
cpu_mips_clock_init(cpu);
env = &cpu->env;
if (cpu_mips_itu_supported(env)) {
itu_present = true;
env->itc_tag = mips_itu_get_tag_region(&s->itu);
}
qemu_register_reset(main_cpu_reset, cpu);
}
cpu = MIPS_CPU(first_cpu);
env = &cpu->env;
if (itu_present) {
object_initialize(&s->itu, sizeof(s->itu), TYPE_MIPS_ITU);
qdev_set_parent_bus(DEVICE(&s->itu), sysbus_get_default());
object_property_set_int(OBJECT(&s->itu), 16, "num-fifo", &err);
object_property_set_int(OBJECT(&s->itu), 16, "num-semaphores", &err);
object_property_set_bool(OBJECT(&s->itu), true, "realized", &err);
if (err != NULL) {
error_propagate(errp, err);
return;
}
memory_region_add_subregion(&s->container, 0,
sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->itu), 0));
}
object_initialize(&s->cpc, sizeof(s->cpc), TYPE_MIPS_CPC);
qdev_set_parent_bus(DEVICE(&s->cpc), sysbus_get_default());
object_property_set_int(OBJECT(&s->cpc), s->num_vp, "num-vp", &err);
object_property_set_int(OBJECT(&s->cpc), 1, "vp-start-running", &err);
object_property_set_bool(OBJECT(&s->cpc), true, "realized", &err);
if (err != NULL) {
error_propagate(errp, err);
return;
}
memory_region_add_subregion(&s->container, 0,
sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->cpc), 0));
object_initialize(&s->gic, sizeof(s->gic), TYPE_MIPS_GIC);
qdev_set_parent_bus(DEVICE(&s->gic), sysbus_get_default());
object_property_set_int(OBJECT(&s->gic), s->num_vp, "num-vp", &err);
object_property_set_int(OBJECT(&s->gic), 128, "num-irq", &err);
object_property_set_bool(OBJECT(&s->gic), true, "realized", &err);
if (err != NULL) {
error_propagate(errp, err);
return;
}
memory_region_add_subregion(&s->container, 0,
sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->gic), 0));
gcr_base = env->CP0_CMGCRBase << 4;
object_initialize(&s->gcr, sizeof(s->gcr), TYPE_MIPS_GCR);
qdev_set_parent_bus(DEVICE(&s->gcr), sysbus_get_default());
object_property_set_int(OBJECT(&s->gcr), s->num_vp, "num-vp", &err);
object_property_set_int(OBJECT(&s->gcr), 0x800, "gcr-rev", &err);
object_property_set_int(OBJECT(&s->gcr), gcr_base, "gcr-base", &err);
object_property_set_link(OBJECT(&s->gcr), OBJECT(&s->gic.mr), "gic", &err);
object_property_set_link(OBJECT(&s->gcr), OBJECT(&s->cpc.mr), "cpc", &err);
object_property_set_bool(OBJECT(&s->gcr), true, "realized", &err);
if (err != NULL) {
error_propagate(errp, err);
return;
}
memory_region_add_subregion(&s->container, gcr_base,
sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->gcr), 0));
}
| {
"code": [],
"line_no": []
} | static void FUNC_0(DeviceState *VAR_0, Error **VAR_1)
{
MIPSCPSState *s = MIPS_CPS(VAR_0);
CPUMIPSState *env;
MIPSCPU *cpu;
int VAR_2;
Error *err = NULL;
target_ulong gcr_base;
bool itu_present = false;
for (VAR_2 = 0; VAR_2 < s->num_vp; VAR_2++) {
cpu = cpu_mips_init(s->cpu_model);
if (cpu == NULL) {
error_setg(VAR_1, "%s: CPU initialization failed\n", __func__);
return;
}
cpu_mips_irq_init_cpu(cpu);
cpu_mips_clock_init(cpu);
env = &cpu->env;
if (cpu_mips_itu_supported(env)) {
itu_present = true;
env->itc_tag = mips_itu_get_tag_region(&s->itu);
}
qemu_register_reset(main_cpu_reset, cpu);
}
cpu = MIPS_CPU(first_cpu);
env = &cpu->env;
if (itu_present) {
object_initialize(&s->itu, sizeof(s->itu), TYPE_MIPS_ITU);
qdev_set_parent_bus(DEVICE(&s->itu), sysbus_get_default());
object_property_set_int(OBJECT(&s->itu), 16, "num-fifo", &err);
object_property_set_int(OBJECT(&s->itu), 16, "num-semaphores", &err);
object_property_set_bool(OBJECT(&s->itu), true, "realized", &err);
if (err != NULL) {
error_propagate(VAR_1, err);
return;
}
memory_region_add_subregion(&s->container, 0,
sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->itu), 0));
}
object_initialize(&s->cpc, sizeof(s->cpc), TYPE_MIPS_CPC);
qdev_set_parent_bus(DEVICE(&s->cpc), sysbus_get_default());
object_property_set_int(OBJECT(&s->cpc), s->num_vp, "num-vp", &err);
object_property_set_int(OBJECT(&s->cpc), 1, "vp-start-running", &err);
object_property_set_bool(OBJECT(&s->cpc), true, "realized", &err);
if (err != NULL) {
error_propagate(VAR_1, err);
return;
}
memory_region_add_subregion(&s->container, 0,
sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->cpc), 0));
object_initialize(&s->gic, sizeof(s->gic), TYPE_MIPS_GIC);
qdev_set_parent_bus(DEVICE(&s->gic), sysbus_get_default());
object_property_set_int(OBJECT(&s->gic), s->num_vp, "num-vp", &err);
object_property_set_int(OBJECT(&s->gic), 128, "num-irq", &err);
object_property_set_bool(OBJECT(&s->gic), true, "realized", &err);
if (err != NULL) {
error_propagate(VAR_1, err);
return;
}
memory_region_add_subregion(&s->container, 0,
sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->gic), 0));
gcr_base = env->CP0_CMGCRBase << 4;
object_initialize(&s->gcr, sizeof(s->gcr), TYPE_MIPS_GCR);
qdev_set_parent_bus(DEVICE(&s->gcr), sysbus_get_default());
object_property_set_int(OBJECT(&s->gcr), s->num_vp, "num-vp", &err);
object_property_set_int(OBJECT(&s->gcr), 0x800, "gcr-rev", &err);
object_property_set_int(OBJECT(&s->gcr), gcr_base, "gcr-base", &err);
object_property_set_link(OBJECT(&s->gcr), OBJECT(&s->gic.mr), "gic", &err);
object_property_set_link(OBJECT(&s->gcr), OBJECT(&s->cpc.mr), "cpc", &err);
object_property_set_bool(OBJECT(&s->gcr), true, "realized", &err);
if (err != NULL) {
error_propagate(VAR_1, err);
return;
}
memory_region_add_subregion(&s->container, gcr_base,
sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->gcr), 0));
}
| [
"static void FUNC_0(DeviceState *VAR_0, Error **VAR_1)\n{",
"MIPSCPSState *s = MIPS_CPS(VAR_0);",
"CPUMIPSState *env;",
"MIPSCPU *cpu;",
"int VAR_2;",
"Error *err = NULL;",
"target_ulong gcr_base;",
"bool itu_present = false;",
"for (VAR_2 = 0; VAR_2 < s->num_vp; VAR_2++) {",
"cpu = cpu_mips_init(s->cpu_model);",
"if (cpu == NULL) {",
"error_setg(VAR_1, \"%s: CPU initialization failed\\n\", __func__);",
"return;",
"}",
"cpu_mips_irq_init_cpu(cpu);",
"cpu_mips_clock_init(cpu);",
"env = &cpu->env;",
"if (cpu_mips_itu_supported(env)) {",
"itu_present = true;",
"env->itc_tag = mips_itu_get_tag_region(&s->itu);",
"}",
"qemu_register_reset(main_cpu_reset, cpu);",
"}",
"cpu = MIPS_CPU(first_cpu);",
"env = &cpu->env;",
"if (itu_present) {",
"object_initialize(&s->itu, sizeof(s->itu), TYPE_MIPS_ITU);",
"qdev_set_parent_bus(DEVICE(&s->itu), sysbus_get_default());",
"object_property_set_int(OBJECT(&s->itu), 16, \"num-fifo\", &err);",
"object_property_set_int(OBJECT(&s->itu), 16, \"num-semaphores\", &err);",
"object_property_set_bool(OBJECT(&s->itu), true, \"realized\", &err);",
"if (err != NULL) {",
"error_propagate(VAR_1, err);",
"return;",
"}",
"memory_region_add_subregion(&s->container, 0,\nsysbus_mmio_get_region(SYS_BUS_DEVICE(&s->itu), 0));",
"}",
"object_initialize(&s->cpc, sizeof(s->cpc), TYPE_MIPS_CPC);",
"qdev_set_parent_bus(DEVICE(&s->cpc), sysbus_get_default());",
"object_property_set_int(OBJECT(&s->cpc), s->num_vp, \"num-vp\", &err);",
"object_property_set_int(OBJECT(&s->cpc), 1, \"vp-start-running\", &err);",
"object_property_set_bool(OBJECT(&s->cpc), true, \"realized\", &err);",
"if (err != NULL) {",
"error_propagate(VAR_1, err);",
"return;",
"}",
"memory_region_add_subregion(&s->container, 0,\nsysbus_mmio_get_region(SYS_BUS_DEVICE(&s->cpc), 0));",
"object_initialize(&s->gic, sizeof(s->gic), TYPE_MIPS_GIC);",
"qdev_set_parent_bus(DEVICE(&s->gic), sysbus_get_default());",
"object_property_set_int(OBJECT(&s->gic), s->num_vp, \"num-vp\", &err);",
"object_property_set_int(OBJECT(&s->gic), 128, \"num-irq\", &err);",
"object_property_set_bool(OBJECT(&s->gic), true, \"realized\", &err);",
"if (err != NULL) {",
"error_propagate(VAR_1, err);",
"return;",
"}",
"memory_region_add_subregion(&s->container, 0,\nsysbus_mmio_get_region(SYS_BUS_DEVICE(&s->gic), 0));",
"gcr_base = env->CP0_CMGCRBase << 4;",
"object_initialize(&s->gcr, sizeof(s->gcr), TYPE_MIPS_GCR);",
"qdev_set_parent_bus(DEVICE(&s->gcr), sysbus_get_default());",
"object_property_set_int(OBJECT(&s->gcr), s->num_vp, \"num-vp\", &err);",
"object_property_set_int(OBJECT(&s->gcr), 0x800, \"gcr-rev\", &err);",
"object_property_set_int(OBJECT(&s->gcr), gcr_base, \"gcr-base\", &err);",
"object_property_set_link(OBJECT(&s->gcr), OBJECT(&s->gic.mr), \"gic\", &err);",
"object_property_set_link(OBJECT(&s->gcr), OBJECT(&s->cpc.mr), \"cpc\", &err);",
"object_property_set_bool(OBJECT(&s->gcr), true, \"realized\", &err);",
"if (err != NULL) {",
"error_propagate(VAR_1, err);",
"return;",
"}",
"memory_region_add_subregion(&s->container, gcr_base,\nsysbus_mmio_get_region(SYS_BUS_DEVICE(&s->gcr), 0));",
"}"
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | [
[
1,
3
],
[
5
],
[
7
],
[
9
],
[
11
],
[
13
],
[
15
],
[
17
],
[
21
],
[
23
],
[
25
],
[
27
],
[
29
],
[
31
],
[
37
],
[
39
],
[
43
],
[
45
],
[
47
],
[
51
],
[
53
],
[
55
],
[
57
],
[
61
],
[
63
],
[
69
],
[
71
],
[
73
],
[
77
],
[
79
],
[
81
],
[
83
],
[
85
],
[
87
],
[
89
],
[
93,
95
],
[
97
],
[
103
],
[
105
],
[
109
],
[
111
],
[
113
],
[
115
],
[
117
],
[
119
],
[
121
],
[
125,
127
],
[
133
],
[
135
],
[
139
],
[
141
],
[
143
],
[
145
],
[
147
],
[
149
],
[
151
],
[
155,
157
],
[
163
],
[
167
],
[
169
],
[
173
],
[
175
],
[
177
],
[
179
],
[
181
],
[
183
],
[
185
],
[
187
],
[
189
],
[
191
],
[
195,
197
],
[
199
]
] |
21,422 | void cpu_loop(CPUM68KState *env)
{
CPUState *cs = CPU(m68k_env_get_cpu(env));
int trapnr;
unsigned int n;
target_siginfo_t info;
TaskState *ts = cs->opaque;
for(;;) {
cpu_exec_start(cs);
trapnr = cpu_m68k_exec(cs);
cpu_exec_end(cs);
switch(trapnr) {
case EXCP_ILLEGAL:
{
if (ts->sim_syscalls) {
uint16_t nr;
get_user_u16(nr, env->pc + 2);
env->pc += 4;
do_m68k_simcall(env, nr);
} else {
goto do_sigill;
}
}
break;
case EXCP_HALT_INSN:
/* Semihosing syscall. */
env->pc += 4;
do_m68k_semihosting(env, env->dregs[0]);
break;
case EXCP_LINEA:
case EXCP_LINEF:
case EXCP_UNSUPPORTED:
do_sigill:
info.si_signo = TARGET_SIGILL;
info.si_errno = 0;
info.si_code = TARGET_ILL_ILLOPN;
info._sifields._sigfault._addr = env->pc;
queue_signal(env, info.si_signo, &info);
break;
case EXCP_TRAP0:
{
ts->sim_syscalls = 0;
n = env->dregs[0];
env->pc += 2;
env->dregs[0] = do_syscall(env,
n,
env->dregs[1],
env->dregs[2],
env->dregs[3],
env->dregs[4],
env->dregs[5],
env->aregs[0],
0, 0);
}
break;
case EXCP_INTERRUPT:
/* just indicate that signals should be handled asap */
break;
case EXCP_ACCESS:
{
info.si_signo = TARGET_SIGSEGV;
info.si_errno = 0;
/* XXX: check env->error_code */
info.si_code = TARGET_SEGV_MAPERR;
info._sifields._sigfault._addr = env->mmu.ar;
queue_signal(env, info.si_signo, &info);
}
break;
case EXCP_DEBUG:
{
int sig;
sig = gdb_handlesig(cs, TARGET_SIGTRAP);
if (sig)
{
info.si_signo = sig;
info.si_errno = 0;
info.si_code = TARGET_TRAP_BRKPT;
queue_signal(env, info.si_signo, &info);
}
}
break;
default:
fprintf(stderr, "qemu: unhandled CPU exception 0x%x - aborting\n",
trapnr);
cpu_dump_state(cs, stderr, fprintf, 0);
abort();
}
process_pending_signals(env);
}
}
| false | qemu | 120a9848c2f667bf8f1a06772dc9cde064d92a7d | void cpu_loop(CPUM68KState *env)
{
CPUState *cs = CPU(m68k_env_get_cpu(env));
int trapnr;
unsigned int n;
target_siginfo_t info;
TaskState *ts = cs->opaque;
for(;;) {
cpu_exec_start(cs);
trapnr = cpu_m68k_exec(cs);
cpu_exec_end(cs);
switch(trapnr) {
case EXCP_ILLEGAL:
{
if (ts->sim_syscalls) {
uint16_t nr;
get_user_u16(nr, env->pc + 2);
env->pc += 4;
do_m68k_simcall(env, nr);
} else {
goto do_sigill;
}
}
break;
case EXCP_HALT_INSN:
env->pc += 4;
do_m68k_semihosting(env, env->dregs[0]);
break;
case EXCP_LINEA:
case EXCP_LINEF:
case EXCP_UNSUPPORTED:
do_sigill:
info.si_signo = TARGET_SIGILL;
info.si_errno = 0;
info.si_code = TARGET_ILL_ILLOPN;
info._sifields._sigfault._addr = env->pc;
queue_signal(env, info.si_signo, &info);
break;
case EXCP_TRAP0:
{
ts->sim_syscalls = 0;
n = env->dregs[0];
env->pc += 2;
env->dregs[0] = do_syscall(env,
n,
env->dregs[1],
env->dregs[2],
env->dregs[3],
env->dregs[4],
env->dregs[5],
env->aregs[0],
0, 0);
}
break;
case EXCP_INTERRUPT:
break;
case EXCP_ACCESS:
{
info.si_signo = TARGET_SIGSEGV;
info.si_errno = 0;
info.si_code = TARGET_SEGV_MAPERR;
info._sifields._sigfault._addr = env->mmu.ar;
queue_signal(env, info.si_signo, &info);
}
break;
case EXCP_DEBUG:
{
int sig;
sig = gdb_handlesig(cs, TARGET_SIGTRAP);
if (sig)
{
info.si_signo = sig;
info.si_errno = 0;
info.si_code = TARGET_TRAP_BRKPT;
queue_signal(env, info.si_signo, &info);
}
}
break;
default:
fprintf(stderr, "qemu: unhandled CPU exception 0x%x - aborting\n",
trapnr);
cpu_dump_state(cs, stderr, fprintf, 0);
abort();
}
process_pending_signals(env);
}
}
| {
"code": [],
"line_no": []
} | void FUNC_0(CPUM68KState *VAR_0)
{
CPUState *cs = CPU(m68k_env_get_cpu(VAR_0));
int VAR_1;
unsigned int VAR_2;
target_siginfo_t info;
TaskState *ts = cs->opaque;
for(;;) {
cpu_exec_start(cs);
VAR_1 = cpu_m68k_exec(cs);
cpu_exec_end(cs);
switch(VAR_1) {
case EXCP_ILLEGAL:
{
if (ts->sim_syscalls) {
uint16_t nr;
get_user_u16(nr, VAR_0->pc + 2);
VAR_0->pc += 4;
do_m68k_simcall(VAR_0, nr);
} else {
goto do_sigill;
}
}
break;
case EXCP_HALT_INSN:
VAR_0->pc += 4;
do_m68k_semihosting(VAR_0, VAR_0->dregs[0]);
break;
case EXCP_LINEA:
case EXCP_LINEF:
case EXCP_UNSUPPORTED:
do_sigill:
info.si_signo = TARGET_SIGILL;
info.si_errno = 0;
info.si_code = TARGET_ILL_ILLOPN;
info._sifields._sigfault._addr = VAR_0->pc;
queue_signal(VAR_0, info.si_signo, &info);
break;
case EXCP_TRAP0:
{
ts->sim_syscalls = 0;
VAR_2 = VAR_0->dregs[0];
VAR_0->pc += 2;
VAR_0->dregs[0] = do_syscall(VAR_0,
VAR_2,
VAR_0->dregs[1],
VAR_0->dregs[2],
VAR_0->dregs[3],
VAR_0->dregs[4],
VAR_0->dregs[5],
VAR_0->aregs[0],
0, 0);
}
break;
case EXCP_INTERRUPT:
break;
case EXCP_ACCESS:
{
info.si_signo = TARGET_SIGSEGV;
info.si_errno = 0;
info.si_code = TARGET_SEGV_MAPERR;
info._sifields._sigfault._addr = VAR_0->mmu.ar;
queue_signal(VAR_0, info.si_signo, &info);
}
break;
case EXCP_DEBUG:
{
int VAR_3;
VAR_3 = gdb_handlesig(cs, TARGET_SIGTRAP);
if (VAR_3)
{
info.si_signo = VAR_3;
info.si_errno = 0;
info.si_code = TARGET_TRAP_BRKPT;
queue_signal(VAR_0, info.si_signo, &info);
}
}
break;
default:
fprintf(stderr, "qemu: unhandled CPU exception 0x%x - aborting\VAR_2",
VAR_1);
cpu_dump_state(cs, stderr, fprintf, 0);
abort();
}
process_pending_signals(VAR_0);
}
}
| [
"void FUNC_0(CPUM68KState *VAR_0)\n{",
"CPUState *cs = CPU(m68k_env_get_cpu(VAR_0));",
"int VAR_1;",
"unsigned int VAR_2;",
"target_siginfo_t info;",
"TaskState *ts = cs->opaque;",
"for(;;) {",
"cpu_exec_start(cs);",
"VAR_1 = cpu_m68k_exec(cs);",
"cpu_exec_end(cs);",
"switch(VAR_1) {",
"case EXCP_ILLEGAL:\n{",
"if (ts->sim_syscalls) {",
"uint16_t nr;",
"get_user_u16(nr, VAR_0->pc + 2);",
"VAR_0->pc += 4;",
"do_m68k_simcall(VAR_0, nr);",
"} else {",
"goto do_sigill;",
"}",
"}",
"break;",
"case EXCP_HALT_INSN:\nVAR_0->pc += 4;",
"do_m68k_semihosting(VAR_0, VAR_0->dregs[0]);",
"break;",
"case EXCP_LINEA:\ncase EXCP_LINEF:\ncase EXCP_UNSUPPORTED:\ndo_sigill:\ninfo.si_signo = TARGET_SIGILL;",
"info.si_errno = 0;",
"info.si_code = TARGET_ILL_ILLOPN;",
"info._sifields._sigfault._addr = VAR_0->pc;",
"queue_signal(VAR_0, info.si_signo, &info);",
"break;",
"case EXCP_TRAP0:\n{",
"ts->sim_syscalls = 0;",
"VAR_2 = VAR_0->dregs[0];",
"VAR_0->pc += 2;",
"VAR_0->dregs[0] = do_syscall(VAR_0,\nVAR_2,\nVAR_0->dregs[1],\nVAR_0->dregs[2],\nVAR_0->dregs[3],\nVAR_0->dregs[4],\nVAR_0->dregs[5],\nVAR_0->aregs[0],\n0, 0);",
"}",
"break;",
"case EXCP_INTERRUPT:\nbreak;",
"case EXCP_ACCESS:\n{",
"info.si_signo = TARGET_SIGSEGV;",
"info.si_errno = 0;",
"info.si_code = TARGET_SEGV_MAPERR;",
"info._sifields._sigfault._addr = VAR_0->mmu.ar;",
"queue_signal(VAR_0, info.si_signo, &info);",
"}",
"break;",
"case EXCP_DEBUG:\n{",
"int VAR_3;",
"VAR_3 = gdb_handlesig(cs, TARGET_SIGTRAP);",
"if (VAR_3)\n{",
"info.si_signo = VAR_3;",
"info.si_errno = 0;",
"info.si_code = TARGET_TRAP_BRKPT;",
"queue_signal(VAR_0, info.si_signo, &info);",
"}",
"}",
"break;",
"default:\nfprintf(stderr, \"qemu: unhandled CPU exception 0x%x - aborting\\VAR_2\",\nVAR_1);",
"cpu_dump_state(cs, stderr, fprintf, 0);",
"abort();",
"}",
"process_pending_signals(VAR_0);",
"}",
"}"
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | [
[
1,
3
],
[
5
],
[
7
],
[
9
],
[
11
],
[
13
],
[
17
],
[
19
],
[
21
],
[
23
],
[
25
],
[
27,
29
],
[
31
],
[
33
],
[
35
],
[
37
],
[
39
],
[
41
],
[
43
],
[
45
],
[
47
],
[
49
],
[
51,
55
],
[
57
],
[
59
],
[
61,
63,
65,
67,
69
],
[
71
],
[
73
],
[
75
],
[
77
],
[
79
],
[
81,
83
],
[
85
],
[
87
],
[
89
],
[
91,
93,
95,
97,
99,
101,
103,
105,
107
],
[
109
],
[
111
],
[
113,
117
],
[
119,
121
],
[
123
],
[
125
],
[
129
],
[
131
],
[
133
],
[
135
],
[
137
],
[
139,
141
],
[
143
],
[
147
],
[
149,
151
],
[
153
],
[
155
],
[
157
],
[
159
],
[
161
],
[
163
],
[
165
],
[
167,
169,
171
],
[
173
],
[
175
],
[
177
],
[
179
],
[
181
],
[
183
]
] |
21,423 | void usb_attach(USBPort *port, USBDevice *dev)
{
if (dev != NULL) {
/* attach */
if (port->dev) {
usb_attach(port, NULL);
}
dev->port = port;
port->dev = dev;
port->ops->attach(port);
usb_send_msg(dev, USB_MSG_ATTACH);
} else {
/* detach */
dev = port->dev;
port->ops->detach(port);
if (dev) {
usb_send_msg(dev, USB_MSG_DETACH);
dev->port = NULL;
port->dev = NULL;
}
}
}
| false | qemu | 45b9fd348061ab793cf4521bb3621f07a5bd7bf6 | void usb_attach(USBPort *port, USBDevice *dev)
{
if (dev != NULL) {
if (port->dev) {
usb_attach(port, NULL);
}
dev->port = port;
port->dev = dev;
port->ops->attach(port);
usb_send_msg(dev, USB_MSG_ATTACH);
} else {
dev = port->dev;
port->ops->detach(port);
if (dev) {
usb_send_msg(dev, USB_MSG_DETACH);
dev->port = NULL;
port->dev = NULL;
}
}
}
| {
"code": [],
"line_no": []
} | void FUNC_0(USBPort *VAR_0, USBDevice *VAR_1)
{
if (VAR_1 != NULL) {
if (VAR_0->VAR_1) {
FUNC_0(VAR_0, NULL);
}
VAR_1->VAR_0 = VAR_0;
VAR_0->VAR_1 = VAR_1;
VAR_0->ops->attach(VAR_0);
usb_send_msg(VAR_1, USB_MSG_ATTACH);
} else {
VAR_1 = VAR_0->VAR_1;
VAR_0->ops->detach(VAR_0);
if (VAR_1) {
usb_send_msg(VAR_1, USB_MSG_DETACH);
VAR_1->VAR_0 = NULL;
VAR_0->VAR_1 = NULL;
}
}
}
| [
"void FUNC_0(USBPort *VAR_0, USBDevice *VAR_1)\n{",
"if (VAR_1 != NULL) {",
"if (VAR_0->VAR_1) {",
"FUNC_0(VAR_0, NULL);",
"}",
"VAR_1->VAR_0 = VAR_0;",
"VAR_0->VAR_1 = VAR_1;",
"VAR_0->ops->attach(VAR_0);",
"usb_send_msg(VAR_1, USB_MSG_ATTACH);",
"} else {",
"VAR_1 = VAR_0->VAR_1;",
"VAR_0->ops->detach(VAR_0);",
"if (VAR_1) {",
"usb_send_msg(VAR_1, USB_MSG_DETACH);",
"VAR_1->VAR_0 = NULL;",
"VAR_0->VAR_1 = NULL;",
"}",
"}",
"}"
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | [
[
1,
3
],
[
5
],
[
9
],
[
11
],
[
13
],
[
15
],
[
17
],
[
19
],
[
21
],
[
23
],
[
27
],
[
29
],
[
31
],
[
33
],
[
35
],
[
37
],
[
39
],
[
41
],
[
43
]
] |
21,424 | static void qerror_set_data(QError *qerr, const char *fmt, va_list *va)
{
QObject *obj;
obj = qobject_from_jsonv(fmt, va);
if (!obj) {
qerror_abort(qerr, "invalid format '%s'", fmt);
}
if (qobject_type(obj) != QTYPE_QDICT) {
qerror_abort(qerr, "error format is not a QDict '%s'", fmt);
}
qerr->error = qobject_to_qdict(obj);
obj = qdict_get(qerr->error, "class");
if (!obj) {
qerror_abort(qerr, "missing 'class' key in '%s'", fmt);
}
if (qobject_type(obj) != QTYPE_QSTRING) {
qerror_abort(qerr, "'class' key value should be a QString");
}
obj = qdict_get(qerr->error, "data");
if (!obj) {
qerror_abort(qerr, "missing 'data' key in '%s'", fmt);
}
if (qobject_type(obj) != QTYPE_QDICT) {
qerror_abort(qerr, "'data' key value should be a QDICT");
}
}
| false | qemu | 8b7968f7c4ac8c07cad6a1a0891d38cf239a2839 | static void qerror_set_data(QError *qerr, const char *fmt, va_list *va)
{
QObject *obj;
obj = qobject_from_jsonv(fmt, va);
if (!obj) {
qerror_abort(qerr, "invalid format '%s'", fmt);
}
if (qobject_type(obj) != QTYPE_QDICT) {
qerror_abort(qerr, "error format is not a QDict '%s'", fmt);
}
qerr->error = qobject_to_qdict(obj);
obj = qdict_get(qerr->error, "class");
if (!obj) {
qerror_abort(qerr, "missing 'class' key in '%s'", fmt);
}
if (qobject_type(obj) != QTYPE_QSTRING) {
qerror_abort(qerr, "'class' key value should be a QString");
}
obj = qdict_get(qerr->error, "data");
if (!obj) {
qerror_abort(qerr, "missing 'data' key in '%s'", fmt);
}
if (qobject_type(obj) != QTYPE_QDICT) {
qerror_abort(qerr, "'data' key value should be a QDICT");
}
}
| {
"code": [],
"line_no": []
} | static void FUNC_0(QError *VAR_0, const char *VAR_1, va_list *VAR_2)
{
QObject *obj;
obj = qobject_from_jsonv(VAR_1, VAR_2);
if (!obj) {
qerror_abort(VAR_0, "invalid format '%s'", VAR_1);
}
if (qobject_type(obj) != QTYPE_QDICT) {
qerror_abort(VAR_0, "error format is not a QDict '%s'", VAR_1);
}
VAR_0->error = qobject_to_qdict(obj);
obj = qdict_get(VAR_0->error, "class");
if (!obj) {
qerror_abort(VAR_0, "missing 'class' key in '%s'", VAR_1);
}
if (qobject_type(obj) != QTYPE_QSTRING) {
qerror_abort(VAR_0, "'class' key value should be a QString");
}
obj = qdict_get(VAR_0->error, "data");
if (!obj) {
qerror_abort(VAR_0, "missing 'data' key in '%s'", VAR_1);
}
if (qobject_type(obj) != QTYPE_QDICT) {
qerror_abort(VAR_0, "'data' key value should be a QDICT");
}
}
| [
"static void FUNC_0(QError *VAR_0, const char *VAR_1, va_list *VAR_2)\n{",
"QObject *obj;",
"obj = qobject_from_jsonv(VAR_1, VAR_2);",
"if (!obj) {",
"qerror_abort(VAR_0, \"invalid format '%s'\", VAR_1);",
"}",
"if (qobject_type(obj) != QTYPE_QDICT) {",
"qerror_abort(VAR_0, \"error format is not a QDict '%s'\", VAR_1);",
"}",
"VAR_0->error = qobject_to_qdict(obj);",
"obj = qdict_get(VAR_0->error, \"class\");",
"if (!obj) {",
"qerror_abort(VAR_0, \"missing 'class' key in '%s'\", VAR_1);",
"}",
"if (qobject_type(obj) != QTYPE_QSTRING) {",
"qerror_abort(VAR_0, \"'class' key value should be a QString\");",
"}",
"obj = qdict_get(VAR_0->error, \"data\");",
"if (!obj) {",
"qerror_abort(VAR_0, \"missing 'data' key in '%s'\", VAR_1);",
"}",
"if (qobject_type(obj) != QTYPE_QDICT) {",
"qerror_abort(VAR_0, \"'data' key value should be a QDICT\");",
"}",
"}"
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | [
[
1,
3
],
[
5
],
[
9
],
[
11
],
[
13
],
[
15
],
[
17
],
[
19
],
[
21
],
[
25
],
[
29
],
[
31
],
[
33
],
[
35
],
[
37
],
[
39
],
[
41
],
[
45
],
[
47
],
[
49
],
[
51
],
[
53
],
[
55
],
[
57
],
[
59
]
] |
21,425 | udp_emu(struct socket *so, struct mbuf *m)
{
struct sockaddr_in addr;
int addrlen = sizeof(addr);
#ifdef EMULATE_TALK
CTL_MSG_OLD *omsg;
CTL_MSG *nmsg;
char buff[sizeof(CTL_MSG)];
u_char type;
struct talk_request {
struct talk_request *next;
struct socket *udp_so;
struct socket *tcp_so;
} *req;
static struct talk_request *req_tbl = 0;
#endif
struct cu_header {
uint16_t d_family; // destination family
uint16_t d_port; // destination port
uint32_t d_addr; // destination address
uint16_t s_family; // source family
uint16_t s_port; // source port
uint32_t so_addr; // source address
uint32_t seqn; // sequence number
uint16_t message; // message
uint16_t data_type; // data type
uint16_t pkt_len; // packet length
} *cu_head;
switch(so->so_emu) {
#ifdef EMULATE_TALK
case EMU_TALK:
case EMU_NTALK:
/*
* Talk emulation. We always change the ctl_addr to get
* some answers from the daemon. When an ANNOUNCE comes,
* we send LEAVE_INVITE to the local daemons. Also when a
* DELETE comes, we send copies to the local daemons.
*/
if (getsockname(so->s, (struct sockaddr *)&addr, &addrlen) < 0)
return;
#define IS_OLD (so->so_emu == EMU_TALK)
#define COPY_MSG(dest, src) { dest->type = src->type; \
dest->id_num = src->id_num; \
dest->pid = src->pid; \
dest->addr = src->addr; \
dest->ctl_addr = src->ctl_addr; \
memcpy(&dest->l_name, &src->l_name, NAME_SIZE_OLD); \
memcpy(&dest->r_name, &src->r_name, NAME_SIZE_OLD); \
memcpy(&dest->r_tty, &src->r_tty, TTY_SIZE); }
#define OTOSIN(ptr, field) ((struct sockaddr_in *)&ptr->field)
/* old_sockaddr to sockaddr_in */
if (IS_OLD) { /* old talk */
omsg = mtod(m, CTL_MSG_OLD*);
nmsg = (CTL_MSG *) buff;
type = omsg->type;
OTOSIN(omsg, ctl_addr)->sin_port = addr.sin_port;
OTOSIN(omsg, ctl_addr)->sin_addr = our_addr;
strncpy(omsg->l_name, getlogin(), NAME_SIZE_OLD);
} else { /* new talk */
omsg = (CTL_MSG_OLD *) buff;
nmsg = mtod(m, CTL_MSG *);
type = nmsg->type;
OTOSIN(nmsg, ctl_addr)->sin_port = addr.sin_port;
OTOSIN(nmsg, ctl_addr)->sin_addr = our_addr;
strncpy(nmsg->l_name, getlogin(), NAME_SIZE_OLD);
}
if (type == LOOK_UP)
return; /* for LOOK_UP this is enough */
if (IS_OLD) { /* make a copy of the message */
COPY_MSG(nmsg, omsg);
nmsg->vers = 1;
nmsg->answer = 0;
} else
COPY_MSG(omsg, nmsg);
/*
* If if is an ANNOUNCE message, we go through the
* request table to see if a tcp port has already
* been redirected for this socket. If not, we solisten()
* a new socket and add this entry to the table.
* The port number of the tcp socket and our IP
* are put to the addr field of the message structures.
* Then a LEAVE_INVITE is sent to both local daemon
* ports, 517 and 518. This is why we have two copies
* of the message, one in old talk and one in new talk
* format.
*/
if (type == ANNOUNCE) {
int s;
u_short temp_port;
for(req = req_tbl; req; req = req->next)
if (so == req->udp_so)
break; /* found it */
if (!req) { /* no entry for so, create new */
req = (struct talk_request *)
malloc(sizeof(struct talk_request));
req->udp_so = so;
req->tcp_so = solisten(0,
OTOSIN(omsg, addr)->sin_addr.s_addr,
OTOSIN(omsg, addr)->sin_port,
SS_FACCEPTONCE);
req->next = req_tbl;
req_tbl = req;
}
/* replace port number in addr field */
addrlen = sizeof(addr);
getsockname(req->tcp_so->s,
(struct sockaddr *) &addr,
&addrlen);
OTOSIN(omsg, addr)->sin_port = addr.sin_port;
OTOSIN(omsg, addr)->sin_addr = our_addr;
OTOSIN(nmsg, addr)->sin_port = addr.sin_port;
OTOSIN(nmsg, addr)->sin_addr = our_addr;
/* send LEAVE_INVITEs */
temp_port = OTOSIN(omsg, ctl_addr)->sin_port;
OTOSIN(omsg, ctl_addr)->sin_port = 0;
OTOSIN(nmsg, ctl_addr)->sin_port = 0;
omsg->type = nmsg->type = LEAVE_INVITE;
s = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
addr.sin_addr = our_addr;
addr.sin_family = AF_INET;
addr.sin_port = htons(517);
sendto(s, (char *)omsg, sizeof(*omsg), 0,
(struct sockaddr *)&addr, sizeof(addr));
addr.sin_port = htons(518);
sendto(s, (char *)nmsg, sizeof(*nmsg), 0,
(struct sockaddr *) &addr, sizeof(addr));
closesocket(s) ;
omsg->type = nmsg->type = ANNOUNCE;
OTOSIN(omsg, ctl_addr)->sin_port = temp_port;
OTOSIN(nmsg, ctl_addr)->sin_port = temp_port;
}
/*
* If it is a DELETE message, we send a copy to the
* local daemons. Then we delete the entry corresponding
* to our socket from the request table.
*/
if (type == DELETE) {
struct talk_request *temp_req, *req_next;
int s;
u_short temp_port;
temp_port = OTOSIN(omsg, ctl_addr)->sin_port;
OTOSIN(omsg, ctl_addr)->sin_port = 0;
OTOSIN(nmsg, ctl_addr)->sin_port = 0;
s = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
addr.sin_addr = our_addr;
addr.sin_family = AF_INET;
addr.sin_port = htons(517);
sendto(s, (char *)omsg, sizeof(*omsg), 0,
(struct sockaddr *)&addr, sizeof(addr));
addr.sin_port = htons(518);
sendto(s, (char *)nmsg, sizeof(*nmsg), 0,
(struct sockaddr *)&addr, sizeof(addr));
closesocket(s);
OTOSIN(omsg, ctl_addr)->sin_port = temp_port;
OTOSIN(nmsg, ctl_addr)->sin_port = temp_port;
/* delete table entry */
if (so == req_tbl->udp_so) {
temp_req = req_tbl;
req_tbl = req_tbl->next;
free(temp_req);
} else {
temp_req = req_tbl;
for(req = req_tbl->next; req; req = req_next) {
req_next = req->next;
if (so == req->udp_so) {
temp_req->next = req_next;
free(req);
break;
} else {
temp_req = req;
}
}
}
}
return;
#endif
case EMU_CUSEEME:
/*
* Cu-SeeMe emulation.
* Hopefully the packet is more that 16 bytes long. We don't
* do any other tests, just replace the address and port
* fields.
*/
if (m->m_len >= sizeof (*cu_head)) {
if (getsockname(so->s, (struct sockaddr *)&addr, &addrlen) < 0)
return;
cu_head = mtod(m, struct cu_header *);
cu_head->s_port = addr.sin_port;
cu_head->so_addr = our_addr.s_addr;
}
return;
}
}
| false | qemu | 242acf3af4605adce933906bdc053b2414181ec7 | udp_emu(struct socket *so, struct mbuf *m)
{
struct sockaddr_in addr;
int addrlen = sizeof(addr);
#ifdef EMULATE_TALK
CTL_MSG_OLD *omsg;
CTL_MSG *nmsg;
char buff[sizeof(CTL_MSG)];
u_char type;
struct talk_request {
struct talk_request *next;
struct socket *udp_so;
struct socket *tcp_so;
} *req;
static struct talk_request *req_tbl = 0;
#endif
struct cu_header {
uint16_t d_family;
uint16_t d_port;
uint32_t d_addr;
uint16_t s_family;
uint16_t s_port;
uint32_t so_addr;
uint32_t seqn;
uint16_t message;
uint16_t data_type;
uint16_t pkt_len;
} *cu_head;
switch(so->so_emu) {
#ifdef EMULATE_TALK
case EMU_TALK:
case EMU_NTALK:
if (getsockname(so->s, (struct sockaddr *)&addr, &addrlen) < 0)
return;
#define IS_OLD (so->so_emu == EMU_TALK)
#define COPY_MSG(dest, src) { dest->type = src->type; \
dest->id_num = src->id_num; \
dest->pid = src->pid; \
dest->addr = src->addr; \
dest->ctl_addr = src->ctl_addr; \
memcpy(&dest->l_name, &src->l_name, NAME_SIZE_OLD); \
memcpy(&dest->r_name, &src->r_name, NAME_SIZE_OLD); \
memcpy(&dest->r_tty, &src->r_tty, TTY_SIZE); }
#define OTOSIN(ptr, field) ((struct sockaddr_in *)&ptr->field)
if (IS_OLD) {
omsg = mtod(m, CTL_MSG_OLD*);
nmsg = (CTL_MSG *) buff;
type = omsg->type;
OTOSIN(omsg, ctl_addr)->sin_port = addr.sin_port;
OTOSIN(omsg, ctl_addr)->sin_addr = our_addr;
strncpy(omsg->l_name, getlogin(), NAME_SIZE_OLD);
} else {
omsg = (CTL_MSG_OLD *) buff;
nmsg = mtod(m, CTL_MSG *);
type = nmsg->type;
OTOSIN(nmsg, ctl_addr)->sin_port = addr.sin_port;
OTOSIN(nmsg, ctl_addr)->sin_addr = our_addr;
strncpy(nmsg->l_name, getlogin(), NAME_SIZE_OLD);
}
if (type == LOOK_UP)
return;
if (IS_OLD) {
COPY_MSG(nmsg, omsg);
nmsg->vers = 1;
nmsg->answer = 0;
} else
COPY_MSG(omsg, nmsg);
if (type == ANNOUNCE) {
int s;
u_short temp_port;
for(req = req_tbl; req; req = req->next)
if (so == req->udp_so)
break;
if (!req) {
req = (struct talk_request *)
malloc(sizeof(struct talk_request));
req->udp_so = so;
req->tcp_so = solisten(0,
OTOSIN(omsg, addr)->sin_addr.s_addr,
OTOSIN(omsg, addr)->sin_port,
SS_FACCEPTONCE);
req->next = req_tbl;
req_tbl = req;
}
addrlen = sizeof(addr);
getsockname(req->tcp_so->s,
(struct sockaddr *) &addr,
&addrlen);
OTOSIN(omsg, addr)->sin_port = addr.sin_port;
OTOSIN(omsg, addr)->sin_addr = our_addr;
OTOSIN(nmsg, addr)->sin_port = addr.sin_port;
OTOSIN(nmsg, addr)->sin_addr = our_addr;
temp_port = OTOSIN(omsg, ctl_addr)->sin_port;
OTOSIN(omsg, ctl_addr)->sin_port = 0;
OTOSIN(nmsg, ctl_addr)->sin_port = 0;
omsg->type = nmsg->type = LEAVE_INVITE;
s = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
addr.sin_addr = our_addr;
addr.sin_family = AF_INET;
addr.sin_port = htons(517);
sendto(s, (char *)omsg, sizeof(*omsg), 0,
(struct sockaddr *)&addr, sizeof(addr));
addr.sin_port = htons(518);
sendto(s, (char *)nmsg, sizeof(*nmsg), 0,
(struct sockaddr *) &addr, sizeof(addr));
closesocket(s) ;
omsg->type = nmsg->type = ANNOUNCE;
OTOSIN(omsg, ctl_addr)->sin_port = temp_port;
OTOSIN(nmsg, ctl_addr)->sin_port = temp_port;
}
if (type == DELETE) {
struct talk_request *temp_req, *req_next;
int s;
u_short temp_port;
temp_port = OTOSIN(omsg, ctl_addr)->sin_port;
OTOSIN(omsg, ctl_addr)->sin_port = 0;
OTOSIN(nmsg, ctl_addr)->sin_port = 0;
s = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
addr.sin_addr = our_addr;
addr.sin_family = AF_INET;
addr.sin_port = htons(517);
sendto(s, (char *)omsg, sizeof(*omsg), 0,
(struct sockaddr *)&addr, sizeof(addr));
addr.sin_port = htons(518);
sendto(s, (char *)nmsg, sizeof(*nmsg), 0,
(struct sockaddr *)&addr, sizeof(addr));
closesocket(s);
OTOSIN(omsg, ctl_addr)->sin_port = temp_port;
OTOSIN(nmsg, ctl_addr)->sin_port = temp_port;
if (so == req_tbl->udp_so) {
temp_req = req_tbl;
req_tbl = req_tbl->next;
free(temp_req);
} else {
temp_req = req_tbl;
for(req = req_tbl->next; req; req = req_next) {
req_next = req->next;
if (so == req->udp_so) {
temp_req->next = req_next;
free(req);
break;
} else {
temp_req = req;
}
}
}
}
return;
#endif
case EMU_CUSEEME:
if (m->m_len >= sizeof (*cu_head)) {
if (getsockname(so->s, (struct sockaddr *)&addr, &addrlen) < 0)
return;
cu_head = mtod(m, struct cu_header *);
cu_head->s_port = addr.sin_port;
cu_head->so_addr = our_addr.s_addr;
}
return;
}
}
| {
"code": [],
"line_no": []
} | FUNC_0(struct socket *VAR_0, struct mbuf *VAR_1)
{
struct sockaddr_in VAR_2;
int VAR_3 = sizeof(VAR_2);
#ifdef EMULATE_TALK
CTL_MSG_OLD *omsg;
CTL_MSG *nmsg;
char buff[sizeof(CTL_MSG)];
u_char type;
struct talk_request {
struct talk_request *next;
struct socket *udp_so;
struct socket *tcp_so;
} *req;
static struct talk_request *req_tbl = 0;
#endif
struct cu_header {
uint16_t d_family;
uint16_t d_port;
uint32_t d_addr;
uint16_t s_family;
uint16_t s_port;
uint32_t so_addr;
uint32_t seqn;
uint16_t message;
uint16_t data_type;
uint16_t pkt_len;
} *VAR_4;
switch(VAR_0->so_emu) {
#ifdef EMULATE_TALK
case EMU_TALK:
case EMU_NTALK:
if (getsockname(VAR_0->s, (struct sockaddr *)&VAR_2, &VAR_3) < 0)
return;
#define IS_OLD (VAR_0->so_emu == EMU_TALK)
#define COPY_MSG(dest, src) { dest->type = src->type; \
dest->id_num = src->id_num; \
dest->pid = src->pid; \
dest->VAR_2 = src->VAR_2; \
dest->ctl_addr = src->ctl_addr; \
memcpy(&dest->l_name, &src->l_name, NAME_SIZE_OLD); \
memcpy(&dest->r_name, &src->r_name, NAME_SIZE_OLD); \
memcpy(&dest->r_tty, &src->r_tty, TTY_SIZE); }
#define OTOSIN(ptr, field) ((struct sockaddr_in *)&ptr->field)
if (IS_OLD) {
omsg = mtod(VAR_1, CTL_MSG_OLD*);
nmsg = (CTL_MSG *) buff;
type = omsg->type;
OTOSIN(omsg, ctl_addr)->sin_port = VAR_2.sin_port;
OTOSIN(omsg, ctl_addr)->sin_addr = our_addr;
strncpy(omsg->l_name, getlogin(), NAME_SIZE_OLD);
} else {
omsg = (CTL_MSG_OLD *) buff;
nmsg = mtod(VAR_1, CTL_MSG *);
type = nmsg->type;
OTOSIN(nmsg, ctl_addr)->sin_port = VAR_2.sin_port;
OTOSIN(nmsg, ctl_addr)->sin_addr = our_addr;
strncpy(nmsg->l_name, getlogin(), NAME_SIZE_OLD);
}
if (type == LOOK_UP)
return;
if (IS_OLD) {
COPY_MSG(nmsg, omsg);
nmsg->vers = 1;
nmsg->answer = 0;
} else
COPY_MSG(omsg, nmsg);
if (type == ANNOUNCE) {
int s;
u_short temp_port;
for(req = req_tbl; req; req = req->next)
if (VAR_0 == req->udp_so)
break;
if (!req) {
req = (struct talk_request *)
malloc(sizeof(struct talk_request));
req->udp_so = VAR_0;
req->tcp_so = solisten(0,
OTOSIN(omsg, VAR_2)->sin_addr.s_addr,
OTOSIN(omsg, VAR_2)->sin_port,
SS_FACCEPTONCE);
req->next = req_tbl;
req_tbl = req;
}
VAR_3 = sizeof(VAR_2);
getsockname(req->tcp_so->s,
(struct sockaddr *) &VAR_2,
&VAR_3);
OTOSIN(omsg, VAR_2)->sin_port = VAR_2.sin_port;
OTOSIN(omsg, VAR_2)->sin_addr = our_addr;
OTOSIN(nmsg, VAR_2)->sin_port = VAR_2.sin_port;
OTOSIN(nmsg, VAR_2)->sin_addr = our_addr;
temp_port = OTOSIN(omsg, ctl_addr)->sin_port;
OTOSIN(omsg, ctl_addr)->sin_port = 0;
OTOSIN(nmsg, ctl_addr)->sin_port = 0;
omsg->type = nmsg->type = LEAVE_INVITE;
s = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
VAR_2.sin_addr = our_addr;
VAR_2.sin_family = AF_INET;
VAR_2.sin_port = htons(517);
sendto(s, (char *)omsg, sizeof(*omsg), 0,
(struct sockaddr *)&VAR_2, sizeof(VAR_2));
VAR_2.sin_port = htons(518);
sendto(s, (char *)nmsg, sizeof(*nmsg), 0,
(struct sockaddr *) &VAR_2, sizeof(VAR_2));
closesocket(s) ;
omsg->type = nmsg->type = ANNOUNCE;
OTOSIN(omsg, ctl_addr)->sin_port = temp_port;
OTOSIN(nmsg, ctl_addr)->sin_port = temp_port;
}
if (type == DELETE) {
struct talk_request *temp_req, *req_next;
int s;
u_short temp_port;
temp_port = OTOSIN(omsg, ctl_addr)->sin_port;
OTOSIN(omsg, ctl_addr)->sin_port = 0;
OTOSIN(nmsg, ctl_addr)->sin_port = 0;
s = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
VAR_2.sin_addr = our_addr;
VAR_2.sin_family = AF_INET;
VAR_2.sin_port = htons(517);
sendto(s, (char *)omsg, sizeof(*omsg), 0,
(struct sockaddr *)&VAR_2, sizeof(VAR_2));
VAR_2.sin_port = htons(518);
sendto(s, (char *)nmsg, sizeof(*nmsg), 0,
(struct sockaddr *)&VAR_2, sizeof(VAR_2));
closesocket(s);
OTOSIN(omsg, ctl_addr)->sin_port = temp_port;
OTOSIN(nmsg, ctl_addr)->sin_port = temp_port;
if (VAR_0 == req_tbl->udp_so) {
temp_req = req_tbl;
req_tbl = req_tbl->next;
free(temp_req);
} else {
temp_req = req_tbl;
for(req = req_tbl->next; req; req = req_next) {
req_next = req->next;
if (VAR_0 == req->udp_so) {
temp_req->next = req_next;
free(req);
break;
} else {
temp_req = req;
}
}
}
}
return;
#endif
case EMU_CUSEEME:
if (VAR_1->m_len >= sizeof (*VAR_4)) {
if (getsockname(VAR_0->s, (struct sockaddr *)&VAR_2, &VAR_3) < 0)
return;
VAR_4 = mtod(VAR_1, struct cu_header *);
VAR_4->s_port = VAR_2.sin_port;
VAR_4->so_addr = our_addr.s_addr;
}
return;
}
}
| [
"FUNC_0(struct socket *VAR_0, struct mbuf *VAR_1)\n{",
"struct sockaddr_in VAR_2;",
"int VAR_3 = sizeof(VAR_2);",
"#ifdef EMULATE_TALK\nCTL_MSG_OLD *omsg;",
"CTL_MSG *nmsg;",
"char buff[sizeof(CTL_MSG)];",
"u_char type;",
"struct talk_request {",
"struct talk_request *next;",
"struct socket *udp_so;",
"struct socket *tcp_so;",
"} *req;",
"static struct talk_request *req_tbl = 0;",
"#endif\nstruct cu_header {",
"uint16_t\td_family;",
"uint16_t\td_port;",
"uint32_t\td_addr;",
"uint16_t\ts_family;",
"uint16_t\ts_port;",
"uint32_t\tso_addr;",
"uint32_t\tseqn;",
"uint16_t\tmessage;",
"uint16_t\tdata_type;",
"uint16_t\tpkt_len;",
"} *VAR_4;",
"switch(VAR_0->so_emu) {",
"#ifdef EMULATE_TALK\ncase EMU_TALK:\ncase EMU_NTALK:\nif (getsockname(VAR_0->s, (struct sockaddr *)&VAR_2, &VAR_3) < 0)\nreturn;",
"#define\tIS_OLD\t(VAR_0->so_emu == EMU_TALK)\n#define COPY_MSG(dest, src) { dest->type = src->type; \\",
"dest->id_num = src->id_num; \\",
"dest->pid = src->pid; \\",
"dest->VAR_2 = src->VAR_2; \\",
"dest->ctl_addr = src->ctl_addr; \\",
"memcpy(&dest->l_name, &src->l_name, NAME_SIZE_OLD); \\",
"memcpy(&dest->r_name, &src->r_name, NAME_SIZE_OLD); \\",
"memcpy(&dest->r_tty, &src->r_tty, TTY_SIZE); }",
"#define OTOSIN(ptr, field) ((struct sockaddr_in *)&ptr->field)\nif (IS_OLD) {",
"omsg = mtod(VAR_1, CTL_MSG_OLD*);",
"nmsg = (CTL_MSG *) buff;",
"type = omsg->type;",
"OTOSIN(omsg, ctl_addr)->sin_port = VAR_2.sin_port;",
"OTOSIN(omsg, ctl_addr)->sin_addr = our_addr;",
"strncpy(omsg->l_name, getlogin(), NAME_SIZE_OLD);",
"} else {",
"omsg = (CTL_MSG_OLD *) buff;",
"nmsg = mtod(VAR_1, CTL_MSG *);",
"type = nmsg->type;",
"OTOSIN(nmsg, ctl_addr)->sin_port = VAR_2.sin_port;",
"OTOSIN(nmsg, ctl_addr)->sin_addr = our_addr;",
"strncpy(nmsg->l_name, getlogin(), NAME_SIZE_OLD);",
"}",
"if (type == LOOK_UP)\nreturn;",
"if (IS_OLD) {",
"COPY_MSG(nmsg, omsg);",
"nmsg->vers = 1;",
"nmsg->answer = 0;",
"} else",
"COPY_MSG(omsg, nmsg);",
"if (type == ANNOUNCE) {",
"int s;",
"u_short temp_port;",
"for(req = req_tbl; req; req = req->next)",
"if (VAR_0 == req->udp_so)\nbreak;",
"if (!req) {",
"req = (struct talk_request *)\nmalloc(sizeof(struct talk_request));",
"req->udp_so = VAR_0;",
"req->tcp_so = solisten(0,\nOTOSIN(omsg, VAR_2)->sin_addr.s_addr,\nOTOSIN(omsg, VAR_2)->sin_port,\nSS_FACCEPTONCE);",
"req->next = req_tbl;",
"req_tbl = req;",
"}",
"VAR_3 = sizeof(VAR_2);",
"getsockname(req->tcp_so->s,\n(struct sockaddr *) &VAR_2,\n&VAR_3);",
"OTOSIN(omsg, VAR_2)->sin_port = VAR_2.sin_port;",
"OTOSIN(omsg, VAR_2)->sin_addr = our_addr;",
"OTOSIN(nmsg, VAR_2)->sin_port = VAR_2.sin_port;",
"OTOSIN(nmsg, VAR_2)->sin_addr = our_addr;",
"temp_port = OTOSIN(omsg, ctl_addr)->sin_port;",
"OTOSIN(omsg, ctl_addr)->sin_port = 0;",
"OTOSIN(nmsg, ctl_addr)->sin_port = 0;",
"omsg->type = nmsg->type = LEAVE_INVITE;",
"s = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);",
"VAR_2.sin_addr = our_addr;",
"VAR_2.sin_family = AF_INET;",
"VAR_2.sin_port = htons(517);",
"sendto(s, (char *)omsg, sizeof(*omsg), 0,\n(struct sockaddr *)&VAR_2, sizeof(VAR_2));",
"VAR_2.sin_port = htons(518);",
"sendto(s, (char *)nmsg, sizeof(*nmsg), 0,\n(struct sockaddr *) &VAR_2, sizeof(VAR_2));",
"closesocket(s) ;",
"omsg->type = nmsg->type = ANNOUNCE;",
"OTOSIN(omsg, ctl_addr)->sin_port = temp_port;",
"OTOSIN(nmsg, ctl_addr)->sin_port = temp_port;",
"}",
"if (type == DELETE) {",
"struct talk_request *temp_req, *req_next;",
"int s;",
"u_short temp_port;",
"temp_port = OTOSIN(omsg, ctl_addr)->sin_port;",
"OTOSIN(omsg, ctl_addr)->sin_port = 0;",
"OTOSIN(nmsg, ctl_addr)->sin_port = 0;",
"s = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);",
"VAR_2.sin_addr = our_addr;",
"VAR_2.sin_family = AF_INET;",
"VAR_2.sin_port = htons(517);",
"sendto(s, (char *)omsg, sizeof(*omsg), 0,\n(struct sockaddr *)&VAR_2, sizeof(VAR_2));",
"VAR_2.sin_port = htons(518);",
"sendto(s, (char *)nmsg, sizeof(*nmsg), 0,\n(struct sockaddr *)&VAR_2, sizeof(VAR_2));",
"closesocket(s);",
"OTOSIN(omsg, ctl_addr)->sin_port = temp_port;",
"OTOSIN(nmsg, ctl_addr)->sin_port = temp_port;",
"if (VAR_0 == req_tbl->udp_so) {",
"temp_req = req_tbl;",
"req_tbl = req_tbl->next;",
"free(temp_req);",
"} else {",
"temp_req = req_tbl;",
"for(req = req_tbl->next; req; req = req_next) {",
"req_next = req->next;",
"if (VAR_0 == req->udp_so) {",
"temp_req->next = req_next;",
"free(req);",
"break;",
"} else {",
"temp_req = req;",
"}",
"}",
"}",
"}",
"return;",
"#endif\ncase EMU_CUSEEME:\nif (VAR_1->m_len >= sizeof (*VAR_4)) {",
"if (getsockname(VAR_0->s, (struct sockaddr *)&VAR_2, &VAR_3) < 0)\nreturn;",
"VAR_4 = mtod(VAR_1, struct cu_header *);",
"VAR_4->s_port = VAR_2.sin_port;",
"VAR_4->so_addr = our_addr.s_addr;",
"}",
"return;",
"}",
"}"
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | [
[
1,
3
],
[
5
],
[
7
],
[
9,
11
],
[
13
],
[
15
],
[
17
],
[
21
],
[
23
],
[
25
],
[
27
],
[
29
],
[
33
],
[
37,
41
],
[
43
],
[
45
],
[
47
],
[
49
],
[
51
],
[
53
],
[
55
],
[
57
],
[
59
],
[
61
],
[
63
],
[
67
],
[
71,
73,
75,
89,
91
],
[
95,
99
],
[
101
],
[
103
],
[
105
],
[
107
],
[
109
],
[
111
],
[
113
],
[
117,
125
],
[
127
],
[
129
],
[
131
],
[
133
],
[
135
],
[
137
],
[
139
],
[
141
],
[
143
],
[
145
],
[
147
],
[
149
],
[
151
],
[
153
],
[
157,
159
],
[
163
],
[
165
],
[
167
],
[
169
],
[
171
],
[
173
],
[
203
],
[
205
],
[
207
],
[
211
],
[
213,
215
],
[
219
],
[
221,
223
],
[
225
],
[
227,
229,
231,
233
],
[
235
],
[
237
],
[
239
],
[
245
],
[
247,
249,
251
],
[
253
],
[
255
],
[
257
],
[
259
],
[
265
],
[
267
],
[
269
],
[
271
],
[
275
],
[
277
],
[
279
],
[
281
],
[
283,
285
],
[
287
],
[
289,
291
],
[
293
],
[
297
],
[
299
],
[
301
],
[
303
],
[
319
],
[
321
],
[
323
],
[
325
],
[
329
],
[
331
],
[
333
],
[
337
],
[
339
],
[
341
],
[
343
],
[
345,
347
],
[
349
],
[
351,
353
],
[
355
],
[
359
],
[
361
],
[
367
],
[
369
],
[
371
],
[
373
],
[
375
],
[
377
],
[
379
],
[
381
],
[
383
],
[
385
],
[
387
],
[
389
],
[
391
],
[
393
],
[
395
],
[
397
],
[
399
],
[
401
],
[
405
],
[
407,
411,
427
],
[
429,
431
],
[
433
],
[
435
],
[
437
],
[
439
],
[
443
],
[
445
],
[
447
]
] |
21,426 | static ssize_t usbnet_receive(VLANClientState *nc, const uint8_t *buf, size_t size)
{
USBNetState *s = DO_UPCAST(NICState, nc, nc)->opaque;
struct rndis_packet_msg_type *msg;
if (s->rndis) {
msg = (struct rndis_packet_msg_type *) s->in_buf;
if (!s->rndis_state == RNDIS_DATA_INITIALIZED)
return -1;
if (size + sizeof(struct rndis_packet_msg_type) > sizeof(s->in_buf))
return -1;
memset(msg, 0, sizeof(struct rndis_packet_msg_type));
msg->MessageType = cpu_to_le32(RNDIS_PACKET_MSG);
msg->MessageLength = cpu_to_le32(size + sizeof(struct rndis_packet_msg_type));
msg->DataOffset = cpu_to_le32(sizeof(struct rndis_packet_msg_type) - 8);
msg->DataLength = cpu_to_le32(size);
/* msg->OOBDataOffset;
* msg->OOBDataLength;
* msg->NumOOBDataElements;
* msg->PerPacketInfoOffset;
* msg->PerPacketInfoLength;
* msg->VcHandle;
* msg->Reserved;
*/
memcpy(msg + 1, buf, size);
s->in_len = size + sizeof(struct rndis_packet_msg_type);
} else {
if (size > sizeof(s->in_buf))
return -1;
memcpy(s->in_buf, buf, size);
s->in_len = size;
}
s->in_ptr = 0;
return size;
}
| false | qemu | a980a065fb5e86d6dec337e6cb6ff432f1a143c9 | static ssize_t usbnet_receive(VLANClientState *nc, const uint8_t *buf, size_t size)
{
USBNetState *s = DO_UPCAST(NICState, nc, nc)->opaque;
struct rndis_packet_msg_type *msg;
if (s->rndis) {
msg = (struct rndis_packet_msg_type *) s->in_buf;
if (!s->rndis_state == RNDIS_DATA_INITIALIZED)
return -1;
if (size + sizeof(struct rndis_packet_msg_type) > sizeof(s->in_buf))
return -1;
memset(msg, 0, sizeof(struct rndis_packet_msg_type));
msg->MessageType = cpu_to_le32(RNDIS_PACKET_MSG);
msg->MessageLength = cpu_to_le32(size + sizeof(struct rndis_packet_msg_type));
msg->DataOffset = cpu_to_le32(sizeof(struct rndis_packet_msg_type) - 8);
msg->DataLength = cpu_to_le32(size);
memcpy(msg + 1, buf, size);
s->in_len = size + sizeof(struct rndis_packet_msg_type);
} else {
if (size > sizeof(s->in_buf))
return -1;
memcpy(s->in_buf, buf, size);
s->in_len = size;
}
s->in_ptr = 0;
return size;
}
| {
"code": [],
"line_no": []
} | static ssize_t FUNC_0(VLANClientState *nc, const uint8_t *buf, size_t size)
{
USBNetState *s = DO_UPCAST(NICState, nc, nc)->opaque;
struct rndis_packet_msg_type *VAR_0;
if (s->rndis) {
VAR_0 = (struct rndis_packet_msg_type *) s->in_buf;
if (!s->rndis_state == RNDIS_DATA_INITIALIZED)
return -1;
if (size + sizeof(struct rndis_packet_msg_type) > sizeof(s->in_buf))
return -1;
memset(VAR_0, 0, sizeof(struct rndis_packet_msg_type));
VAR_0->MessageType = cpu_to_le32(RNDIS_PACKET_MSG);
VAR_0->MessageLength = cpu_to_le32(size + sizeof(struct rndis_packet_msg_type));
VAR_0->DataOffset = cpu_to_le32(sizeof(struct rndis_packet_msg_type) - 8);
VAR_0->DataLength = cpu_to_le32(size);
memcpy(VAR_0 + 1, buf, size);
s->in_len = size + sizeof(struct rndis_packet_msg_type);
} else {
if (size > sizeof(s->in_buf))
return -1;
memcpy(s->in_buf, buf, size);
s->in_len = size;
}
s->in_ptr = 0;
return size;
}
| [
"static ssize_t FUNC_0(VLANClientState *nc, const uint8_t *buf, size_t size)\n{",
"USBNetState *s = DO_UPCAST(NICState, nc, nc)->opaque;",
"struct rndis_packet_msg_type *VAR_0;",
"if (s->rndis) {",
"VAR_0 = (struct rndis_packet_msg_type *) s->in_buf;",
"if (!s->rndis_state == RNDIS_DATA_INITIALIZED)\nreturn -1;",
"if (size + sizeof(struct rndis_packet_msg_type) > sizeof(s->in_buf))\nreturn -1;",
"memset(VAR_0, 0, sizeof(struct rndis_packet_msg_type));",
"VAR_0->MessageType = cpu_to_le32(RNDIS_PACKET_MSG);",
"VAR_0->MessageLength = cpu_to_le32(size + sizeof(struct rndis_packet_msg_type));",
"VAR_0->DataOffset = cpu_to_le32(sizeof(struct rndis_packet_msg_type) - 8);",
"VAR_0->DataLength = cpu_to_le32(size);",
"memcpy(VAR_0 + 1, buf, size);",
"s->in_len = size + sizeof(struct rndis_packet_msg_type);",
"} else {",
"if (size > sizeof(s->in_buf))\nreturn -1;",
"memcpy(s->in_buf, buf, size);",
"s->in_len = size;",
"}",
"s->in_ptr = 0;",
"return size;",
"}"
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | [
[
1,
3
],
[
5
],
[
7
],
[
11
],
[
13
],
[
15,
17
],
[
19,
21
],
[
25
],
[
27
],
[
29
],
[
31
],
[
33
],
[
51
],
[
53
],
[
55
],
[
57,
59
],
[
61
],
[
63
],
[
65
],
[
67
],
[
69
],
[
71
]
] |
21,428 | static void mpcore_priv_map_setup(mpcore_priv_state *s)
{
int i;
SysBusDevice *gicbusdev = sysbus_from_qdev(s->gic);
SysBusDevice *busdev = sysbus_from_qdev(s->mptimer);
memory_region_init(&s->container, "mpcode-priv-container", 0x2000);
memory_region_init_io(&s->iomem, &mpcore_scu_ops, s, "mpcore-scu", 0x100);
memory_region_add_subregion(&s->container, 0, &s->iomem);
/* GIC CPU interfaces: "current CPU" at 0x100, then specific CPUs
* at 0x200, 0x300...
*/
for (i = 0; i < (s->num_cpu + 1); i++) {
target_phys_addr_t offset = 0x100 + (i * 0x100);
memory_region_add_subregion(&s->container, offset,
sysbus_mmio_get_region(gicbusdev, i + 1));
}
/* Add the regions for timer and watchdog for "current CPU" and
* for each specific CPU.
*/
for (i = 0; i < (s->num_cpu + 1) * 2; i++) {
/* Timers at 0x600, 0x700, ...; watchdogs at 0x620, 0x720, ... */
target_phys_addr_t offset = 0x600 + (i >> 1) * 0x100 + (i & 1) * 0x20;
memory_region_add_subregion(&s->container, offset,
sysbus_mmio_get_region(busdev, i));
}
memory_region_add_subregion(&s->container, 0x1000,
sysbus_mmio_get_region(gicbusdev, 0));
/* Wire up the interrupt from each watchdog and timer.
* For each core the timer is PPI 29 and the watchdog PPI 30.
*/
for (i = 0; i < s->num_cpu; i++) {
int ppibase = (s->num_irq - 32) + i * 32;
sysbus_connect_irq(busdev, i * 2,
qdev_get_gpio_in(s->gic, ppibase + 29));
sysbus_connect_irq(busdev, i * 2 + 1,
qdev_get_gpio_in(s->gic, ppibase + 30));
}
}
| false | qemu | a8170e5e97ad17ca169c64ba87ae2f53850dab4c | static void mpcore_priv_map_setup(mpcore_priv_state *s)
{
int i;
SysBusDevice *gicbusdev = sysbus_from_qdev(s->gic);
SysBusDevice *busdev = sysbus_from_qdev(s->mptimer);
memory_region_init(&s->container, "mpcode-priv-container", 0x2000);
memory_region_init_io(&s->iomem, &mpcore_scu_ops, s, "mpcore-scu", 0x100);
memory_region_add_subregion(&s->container, 0, &s->iomem);
for (i = 0; i < (s->num_cpu + 1); i++) {
target_phys_addr_t offset = 0x100 + (i * 0x100);
memory_region_add_subregion(&s->container, offset,
sysbus_mmio_get_region(gicbusdev, i + 1));
}
for (i = 0; i < (s->num_cpu + 1) * 2; i++) {
target_phys_addr_t offset = 0x600 + (i >> 1) * 0x100 + (i & 1) * 0x20;
memory_region_add_subregion(&s->container, offset,
sysbus_mmio_get_region(busdev, i));
}
memory_region_add_subregion(&s->container, 0x1000,
sysbus_mmio_get_region(gicbusdev, 0));
for (i = 0; i < s->num_cpu; i++) {
int ppibase = (s->num_irq - 32) + i * 32;
sysbus_connect_irq(busdev, i * 2,
qdev_get_gpio_in(s->gic, ppibase + 29));
sysbus_connect_irq(busdev, i * 2 + 1,
qdev_get_gpio_in(s->gic, ppibase + 30));
}
}
| {
"code": [],
"line_no": []
} | static void FUNC_0(mpcore_priv_state *VAR_0)
{
int VAR_1;
SysBusDevice *gicbusdev = sysbus_from_qdev(VAR_0->gic);
SysBusDevice *busdev = sysbus_from_qdev(VAR_0->mptimer);
memory_region_init(&VAR_0->container, "mpcode-priv-container", 0x2000);
memory_region_init_io(&VAR_0->iomem, &mpcore_scu_ops, VAR_0, "mpcore-scu", 0x100);
memory_region_add_subregion(&VAR_0->container, 0, &VAR_0->iomem);
for (VAR_1 = 0; VAR_1 < (VAR_0->num_cpu + 1); VAR_1++) {
target_phys_addr_t offset = 0x100 + (VAR_1 * 0x100);
memory_region_add_subregion(&VAR_0->container, offset,
sysbus_mmio_get_region(gicbusdev, VAR_1 + 1));
}
for (VAR_1 = 0; VAR_1 < (VAR_0->num_cpu + 1) * 2; VAR_1++) {
target_phys_addr_t offset = 0x600 + (VAR_1 >> 1) * 0x100 + (VAR_1 & 1) * 0x20;
memory_region_add_subregion(&VAR_0->container, offset,
sysbus_mmio_get_region(busdev, VAR_1));
}
memory_region_add_subregion(&VAR_0->container, 0x1000,
sysbus_mmio_get_region(gicbusdev, 0));
for (VAR_1 = 0; VAR_1 < VAR_0->num_cpu; VAR_1++) {
int ppibase = (VAR_0->num_irq - 32) + VAR_1 * 32;
sysbus_connect_irq(busdev, VAR_1 * 2,
qdev_get_gpio_in(VAR_0->gic, ppibase + 29));
sysbus_connect_irq(busdev, VAR_1 * 2 + 1,
qdev_get_gpio_in(VAR_0->gic, ppibase + 30));
}
}
| [
"static void FUNC_0(mpcore_priv_state *VAR_0)\n{",
"int VAR_1;",
"SysBusDevice *gicbusdev = sysbus_from_qdev(VAR_0->gic);",
"SysBusDevice *busdev = sysbus_from_qdev(VAR_0->mptimer);",
"memory_region_init(&VAR_0->container, \"mpcode-priv-container\", 0x2000);",
"memory_region_init_io(&VAR_0->iomem, &mpcore_scu_ops, VAR_0, \"mpcore-scu\", 0x100);",
"memory_region_add_subregion(&VAR_0->container, 0, &VAR_0->iomem);",
"for (VAR_1 = 0; VAR_1 < (VAR_0->num_cpu + 1); VAR_1++) {",
"target_phys_addr_t offset = 0x100 + (VAR_1 * 0x100);",
"memory_region_add_subregion(&VAR_0->container, offset,\nsysbus_mmio_get_region(gicbusdev, VAR_1 + 1));",
"}",
"for (VAR_1 = 0; VAR_1 < (VAR_0->num_cpu + 1) * 2; VAR_1++) {",
"target_phys_addr_t offset = 0x600 + (VAR_1 >> 1) * 0x100 + (VAR_1 & 1) * 0x20;",
"memory_region_add_subregion(&VAR_0->container, offset,\nsysbus_mmio_get_region(busdev, VAR_1));",
"}",
"memory_region_add_subregion(&VAR_0->container, 0x1000,\nsysbus_mmio_get_region(gicbusdev, 0));",
"for (VAR_1 = 0; VAR_1 < VAR_0->num_cpu; VAR_1++) {",
"int ppibase = (VAR_0->num_irq - 32) + VAR_1 * 32;",
"sysbus_connect_irq(busdev, VAR_1 * 2,\nqdev_get_gpio_in(VAR_0->gic, ppibase + 29));",
"sysbus_connect_irq(busdev, VAR_1 * 2 + 1,\nqdev_get_gpio_in(VAR_0->gic, ppibase + 30));",
"}",
"}"
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | [
[
1,
3
],
[
5
],
[
7
],
[
9
],
[
11
],
[
13
],
[
15
],
[
23
],
[
25
],
[
27,
29
],
[
31
],
[
39
],
[
43
],
[
45,
47
],
[
49
],
[
51,
53
],
[
61
],
[
63
],
[
65,
67
],
[
69,
71
],
[
73
],
[
75
]
] |
21,429 | static int proxy_readdir_r(FsContext *ctx, V9fsFidOpenState *fs,
struct dirent *entry,
struct dirent **result)
{
return readdir_r(fs->dir, entry, result);
}
| false | qemu | 494a8ebe713055d3946183f4b395f85a18b43e9e | static int proxy_readdir_r(FsContext *ctx, V9fsFidOpenState *fs,
struct dirent *entry,
struct dirent **result)
{
return readdir_r(fs->dir, entry, result);
}
| {
"code": [],
"line_no": []
} | static int FUNC_0(FsContext *VAR_0, V9fsFidOpenState *VAR_1,
struct dirent *VAR_2,
struct dirent **VAR_3)
{
return readdir_r(VAR_1->dir, VAR_2, VAR_3);
}
| [
"static int FUNC_0(FsContext *VAR_0, V9fsFidOpenState *VAR_1,\nstruct dirent *VAR_2,\nstruct dirent **VAR_3)\n{",
"return readdir_r(VAR_1->dir, VAR_2, VAR_3);",
"}"
] | [
0,
0,
0
] | [
[
1,
3,
5,
7
],
[
9
],
[
11
]
] |
21,431 | int ff_h264_decode_slice_header(H264Context *h, H264SliceContext *sl)
{
const SPS *sps;
const PPS *pps;
unsigned int first_mb_in_slice;
unsigned int pps_id;
int ret;
unsigned int slice_type, tmp, i, j;
int last_pic_structure, last_pic_droppable;
int needs_reinit = 0;
int field_pic_flag, bottom_field_flag;
int frame_num, droppable, picture_structure;
int mb_aff_frame = 0;
h->qpel_put = h->h264qpel.put_h264_qpel_pixels_tab;
h->qpel_avg = h->h264qpel.avg_h264_qpel_pixels_tab;
first_mb_in_slice = get_ue_golomb(&sl->gb);
if (first_mb_in_slice == 0) { // FIXME better field boundary detection
if (h->current_slice && h->cur_pic_ptr && FIELD_PICTURE(h)) {
ff_h264_field_end(h, sl, 1);
}
h->current_slice = 0;
if (!h->first_field) {
if (h->cur_pic_ptr && !h->droppable) {
ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX,
h->picture_structure == PICT_BOTTOM_FIELD);
}
h->cur_pic_ptr = NULL;
}
}
slice_type = get_ue_golomb_31(&sl->gb);
if (slice_type > 9) {
av_log(h->avctx, AV_LOG_ERROR,
"slice type %d too large at %d\n",
slice_type, first_mb_in_slice);
return AVERROR_INVALIDDATA;
}
if (slice_type > 4) {
slice_type -= 5;
sl->slice_type_fixed = 1;
} else
sl->slice_type_fixed = 0;
slice_type = ff_h264_golomb_to_pict_type[slice_type];
sl->slice_type = slice_type;
sl->slice_type_nos = slice_type & 3;
if (h->nal_unit_type == NAL_IDR_SLICE &&
sl->slice_type_nos != AV_PICTURE_TYPE_I) {
av_log(h->avctx, AV_LOG_ERROR, "A non-intra slice in an IDR NAL unit.\n");
return AVERROR_INVALIDDATA;
}
// to make a few old functions happy, it's wrong though
if (!h->setup_finished)
h->pict_type = sl->slice_type;
pps_id = get_ue_golomb(&sl->gb);
if (pps_id >= MAX_PPS_COUNT) {
av_log(h->avctx, AV_LOG_ERROR, "pps_id %u out of range\n", pps_id);
return AVERROR_INVALIDDATA;
}
if (!h->ps.pps_list[pps_id]) {
av_log(h->avctx, AV_LOG_ERROR,
"non-existing PPS %u referenced\n",
pps_id);
return AVERROR_INVALIDDATA;
}
if (!h->setup_finished) {
h->ps.pps = (const PPS*)h->ps.pps_list[pps_id]->data;
} else if (h->ps.pps != (const PPS*)h->ps.pps_list[pps_id]->data) {
av_log(h->avctx, AV_LOG_ERROR, "PPS changed between slices\n");
return AVERROR_INVALIDDATA;
}
if (!h->ps.sps_list[h->ps.pps->sps_id]) {
av_log(h->avctx, AV_LOG_ERROR,
"non-existing SPS %u referenced\n",
h->ps.pps->sps_id);
return AVERROR_INVALIDDATA;
}
if (h->ps.sps != (const SPS*)h->ps.sps_list[h->ps.pps->sps_id]->data) {
h->ps.sps = (SPS*)h->ps.sps_list[h->ps.pps->sps_id]->data;
if (h->bit_depth_luma != h->ps.sps->bit_depth_luma ||
h->chroma_format_idc != h->ps.sps->chroma_format_idc)
needs_reinit = 1;
if (h->flags & AV_CODEC_FLAG_LOW_DELAY ||
(h->ps.sps->bitstream_restriction_flag &&
!h->ps.sps->num_reorder_frames)) {
if (h->avctx->has_b_frames > 1 || h->delayed_pic[0])
av_log(h->avctx, AV_LOG_WARNING, "Delayed frames seen. "
"Reenabling low delay requires a codec flush.\n");
else
h->low_delay = 1;
}
if (h->avctx->has_b_frames < 2)
h->avctx->has_b_frames = !h->low_delay;
}
pps = h->ps.pps;
sps = h->ps.sps;
if (!h->setup_finished) {
h->avctx->profile = ff_h264_get_profile(sps);
h->avctx->level = sps->level_idc;
h->avctx->refs = sps->ref_frame_count;
if (h->mb_width != sps->mb_width ||
h->mb_height != sps->mb_height * (2 - sps->frame_mbs_only_flag))
needs_reinit = 1;
h->mb_width = sps->mb_width;
h->mb_height = sps->mb_height * (2 - sps->frame_mbs_only_flag);
h->mb_num = h->mb_width * h->mb_height;
h->mb_stride = h->mb_width + 1;
h->b_stride = h->mb_width * 4;
h->chroma_y_shift = sps->chroma_format_idc <= 1; // 400 uses yuv420p
h->width = 16 * h->mb_width;
h->height = 16 * h->mb_height;
ret = init_dimensions(h);
if (ret < 0)
return ret;
if (sps->video_signal_type_present_flag) {
h->avctx->color_range = sps->full_range ? AVCOL_RANGE_JPEG
: AVCOL_RANGE_MPEG;
if (sps->colour_description_present_flag) {
if (h->avctx->colorspace != sps->colorspace)
needs_reinit = 1;
h->avctx->color_primaries = sps->color_primaries;
h->avctx->color_trc = sps->color_trc;
h->avctx->colorspace = sps->colorspace;
}
}
}
if (h->context_initialized && needs_reinit) {
h->context_initialized = 0;
if (sl != h->slice_ctx) {
av_log(h->avctx, AV_LOG_ERROR,
"changing width %d -> %d / height %d -> %d on "
"slice %d\n",
h->width, h->avctx->coded_width,
h->height, h->avctx->coded_height,
h->current_slice + 1);
return AVERROR_INVALIDDATA;
}
ff_h264_flush_change(h);
if ((ret = get_pixel_format(h)) < 0)
return ret;
h->avctx->pix_fmt = ret;
av_log(h->avctx, AV_LOG_INFO, "Reinit context to %dx%d, "
"pix_fmt: %d\n", h->width, h->height, h->avctx->pix_fmt);
if ((ret = h264_slice_header_init(h)) < 0) {
av_log(h->avctx, AV_LOG_ERROR,
"h264_slice_header_init() failed\n");
return ret;
}
}
if (!h->context_initialized) {
if (sl != h->slice_ctx) {
av_log(h->avctx, AV_LOG_ERROR,
"Cannot (re-)initialize context during parallel decoding.\n");
return AVERROR_PATCHWELCOME;
}
if ((ret = get_pixel_format(h)) < 0)
return ret;
h->avctx->pix_fmt = ret;
if ((ret = h264_slice_header_init(h)) < 0) {
av_log(h->avctx, AV_LOG_ERROR,
"h264_slice_header_init() failed\n");
return ret;
}
}
frame_num = get_bits(&sl->gb, sps->log2_max_frame_num);
if (!h->setup_finished)
h->frame_num = frame_num;
sl->mb_mbaff = 0;
last_pic_structure = h->picture_structure;
last_pic_droppable = h->droppable;
droppable = h->nal_ref_idc == 0;
if (sps->frame_mbs_only_flag) {
picture_structure = PICT_FRAME;
} else {
field_pic_flag = get_bits1(&sl->gb);
if (field_pic_flag) {
bottom_field_flag = get_bits1(&sl->gb);
picture_structure = PICT_TOP_FIELD + bottom_field_flag;
} else {
picture_structure = PICT_FRAME;
mb_aff_frame = sps->mb_aff;
}
}
if (!h->setup_finished) {
h->droppable = droppable;
h->picture_structure = picture_structure;
h->mb_aff_frame = mb_aff_frame;
}
sl->mb_field_decoding_flag = h->picture_structure != PICT_FRAME;
if (h->current_slice != 0) {
if (last_pic_structure != picture_structure ||
last_pic_droppable != droppable) {
av_log(h->avctx, AV_LOG_ERROR,
"Changing field mode (%d -> %d) between slices is not allowed\n",
last_pic_structure, h->picture_structure);
return AVERROR_INVALIDDATA;
} else if (!h->cur_pic_ptr) {
av_log(h->avctx, AV_LOG_ERROR,
"unset cur_pic_ptr on slice %d\n",
h->current_slice + 1);
return AVERROR_INVALIDDATA;
}
} else {
/* Shorten frame num gaps so we don't have to allocate reference
* frames just to throw them away */
if (h->frame_num != h->prev_frame_num) {
int unwrap_prev_frame_num = h->prev_frame_num;
int max_frame_num = 1 << sps->log2_max_frame_num;
if (unwrap_prev_frame_num > h->frame_num)
unwrap_prev_frame_num -= max_frame_num;
if ((h->frame_num - unwrap_prev_frame_num) > sps->ref_frame_count) {
unwrap_prev_frame_num = (h->frame_num - sps->ref_frame_count) - 1;
if (unwrap_prev_frame_num < 0)
unwrap_prev_frame_num += max_frame_num;
h->prev_frame_num = unwrap_prev_frame_num;
}
}
/* See if we have a decoded first field looking for a pair...
* Here, we're using that to see if we should mark previously
* decode frames as "finished".
* We have to do that before the "dummy" in-between frame allocation,
* since that can modify s->current_picture_ptr. */
if (h->first_field) {
assert(h->cur_pic_ptr);
assert(h->cur_pic_ptr->f->buf[0]);
assert(h->cur_pic_ptr->reference != DELAYED_PIC_REF);
/* figure out if we have a complementary field pair */
if (!FIELD_PICTURE(h) || h->picture_structure == last_pic_structure) {
/* Previous field is unmatched. Don't display it, but let it
* remain for reference if marked as such. */
if (!last_pic_droppable && last_pic_structure != PICT_FRAME) {
ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX,
last_pic_structure == PICT_TOP_FIELD);
}
} else {
if (h->cur_pic_ptr->frame_num != h->frame_num) {
/* This and previous field were reference, but had
* different frame_nums. Consider this field first in
* pair. Throw away previous field except for reference
* purposes. */
if (!last_pic_droppable && last_pic_structure != PICT_FRAME) {
ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX,
last_pic_structure == PICT_TOP_FIELD);
}
} else {
/* Second field in complementary pair */
if (!((last_pic_structure == PICT_TOP_FIELD &&
h->picture_structure == PICT_BOTTOM_FIELD) ||
(last_pic_structure == PICT_BOTTOM_FIELD &&
h->picture_structure == PICT_TOP_FIELD))) {
av_log(h->avctx, AV_LOG_ERROR,
"Invalid field mode combination %d/%d\n",
last_pic_structure, h->picture_structure);
h->picture_structure = last_pic_structure;
h->droppable = last_pic_droppable;
return AVERROR_INVALIDDATA;
} else if (last_pic_droppable != h->droppable) {
avpriv_request_sample(h->avctx,
"Found reference and non-reference fields in the same frame, which");
h->picture_structure = last_pic_structure;
h->droppable = last_pic_droppable;
return AVERROR_PATCHWELCOME;
}
}
}
}
while (h->frame_num != h->prev_frame_num &&
h->frame_num != (h->prev_frame_num + 1) % (1 << sps->log2_max_frame_num)) {
H264Picture *prev = h->short_ref_count ? h->short_ref[0] : NULL;
av_log(h->avctx, AV_LOG_DEBUG, "Frame num gap %d %d\n",
h->frame_num, h->prev_frame_num);
ret = initialize_cur_frame(h);
if (ret < 0) {
h->first_field = 0;
return ret;
}
h->prev_frame_num++;
h->prev_frame_num %= 1 << sps->log2_max_frame_num;
h->cur_pic_ptr->frame_num = h->prev_frame_num;
ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX, 0);
ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX, 1);
ret = ff_generate_sliding_window_mmcos(h, 1);
if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE))
return ret;
ret = ff_h264_execute_ref_pic_marking(h, h->mmco, h->mmco_index);
if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE))
return ret;
/* Error concealment: If a ref is missing, copy the previous ref
* in its place.
* FIXME: Avoiding a memcpy would be nice, but ref handling makes
* many assumptions about there being no actual duplicates.
* FIXME: This does not copy padding for out-of-frame motion
* vectors. Given we are concealing a lost frame, this probably
* is not noticeable by comparison, but it should be fixed. */
if (h->short_ref_count) {
if (prev &&
h->short_ref[0]->f->width == prev->f->width &&
h->short_ref[0]->f->height == prev->f->height &&
h->short_ref[0]->f->format == prev->f->format) {
av_image_copy(h->short_ref[0]->f->data,
h->short_ref[0]->f->linesize,
(const uint8_t **)prev->f->data,
prev->f->linesize,
prev->f->format,
h->mb_width * 16,
h->mb_height * 16);
h->short_ref[0]->poc = prev->poc + 2;
}
h->short_ref[0]->frame_num = h->prev_frame_num;
}
}
/* See if we have a decoded first field looking for a pair...
* We're using that to see whether to continue decoding in that
* frame, or to allocate a new one. */
if (h->first_field) {
assert(h->cur_pic_ptr);
assert(h->cur_pic_ptr->f->buf[0]);
assert(h->cur_pic_ptr->reference != DELAYED_PIC_REF);
/* figure out if we have a complementary field pair */
if (!FIELD_PICTURE(h) || h->picture_structure == last_pic_structure) {
/* Previous field is unmatched. Don't display it, but let it
* remain for reference if marked as such. */
h->cur_pic_ptr = NULL;
h->first_field = FIELD_PICTURE(h);
} else {
if (h->cur_pic_ptr->frame_num != h->frame_num) {
/* This and the previous field had different frame_nums.
* Consider this field first in pair. Throw away previous
* one except for reference purposes. */
h->first_field = 1;
h->cur_pic_ptr = NULL;
} else {
/* Second field in complementary pair */
h->first_field = 0;
}
}
} else {
/* Frame or first field in a potentially complementary pair */
h->first_field = FIELD_PICTURE(h);
}
if (!FIELD_PICTURE(h) || h->first_field) {
if (h264_frame_start(h) < 0) {
h->first_field = 0;
return AVERROR_INVALIDDATA;
}
} else {
release_unused_pictures(h, 0);
}
}
assert(h->mb_num == h->mb_width * h->mb_height);
if (first_mb_in_slice << FIELD_OR_MBAFF_PICTURE(h) >= h->mb_num ||
first_mb_in_slice >= h->mb_num) {
av_log(h->avctx, AV_LOG_ERROR, "first_mb_in_slice overflow\n");
return AVERROR_INVALIDDATA;
}
sl->resync_mb_x = sl->mb_x = first_mb_in_slice % h->mb_width;
sl->resync_mb_y = sl->mb_y = (first_mb_in_slice / h->mb_width) <<
FIELD_OR_MBAFF_PICTURE(h);
if (h->picture_structure == PICT_BOTTOM_FIELD)
sl->resync_mb_y = sl->mb_y = sl->mb_y + 1;
assert(sl->mb_y < h->mb_height);
if (h->picture_structure == PICT_FRAME) {
h->curr_pic_num = h->frame_num;
h->max_pic_num = 1 << sps->log2_max_frame_num;
} else {
h->curr_pic_num = 2 * h->frame_num + 1;
h->max_pic_num = 1 << (sps->log2_max_frame_num + 1);
}
if (h->nal_unit_type == NAL_IDR_SLICE)
get_ue_golomb(&sl->gb); /* idr_pic_id */
if (sps->poc_type == 0) {
int poc_lsb = get_bits(&sl->gb, sps->log2_max_poc_lsb);
if (!h->setup_finished)
h->poc_lsb = poc_lsb;
if (pps->pic_order_present == 1 && h->picture_structure == PICT_FRAME) {
int delta_poc_bottom = get_se_golomb(&sl->gb);
if (!h->setup_finished)
h->delta_poc_bottom = delta_poc_bottom;
}
}
if (sps->poc_type == 1 && !sps->delta_pic_order_always_zero_flag) {
int delta_poc = get_se_golomb(&sl->gb);
if (!h->setup_finished)
h->delta_poc[0] = delta_poc;
if (pps->pic_order_present == 1 && h->picture_structure == PICT_FRAME) {
delta_poc = get_se_golomb(&sl->gb);
if (!h->setup_finished)
h->delta_poc[1] = delta_poc;
}
}
if (!h->setup_finished)
ff_init_poc(h, h->cur_pic_ptr->field_poc, &h->cur_pic_ptr->poc);
if (pps->redundant_pic_cnt_present)
sl->redundant_pic_count = get_ue_golomb(&sl->gb);
if (sl->slice_type_nos == AV_PICTURE_TYPE_B)
sl->direct_spatial_mv_pred = get_bits1(&sl->gb);
ret = ff_h264_parse_ref_count(&sl->list_count, sl->ref_count,
&sl->gb, pps, sl->slice_type_nos,
h->picture_structure);
if (ret < 0)
return ret;
if (sl->slice_type_nos != AV_PICTURE_TYPE_I) {
ret = ff_h264_decode_ref_pic_list_reordering(h, sl);
if (ret < 0) {
sl->ref_count[1] = sl->ref_count[0] = 0;
return ret;
}
}
if ((pps->weighted_pred && sl->slice_type_nos == AV_PICTURE_TYPE_P) ||
(pps->weighted_bipred_idc == 1 &&
sl->slice_type_nos == AV_PICTURE_TYPE_B))
ff_h264_pred_weight_table(&sl->gb, sps, sl->ref_count,
sl->slice_type_nos, &sl->pwt);
else if (pps->weighted_bipred_idc == 2 &&
sl->slice_type_nos == AV_PICTURE_TYPE_B) {
implicit_weight_table(h, sl, -1);
} else {
sl->pwt.use_weight = 0;
for (i = 0; i < 2; i++) {
sl->pwt.luma_weight_flag[i] = 0;
sl->pwt.chroma_weight_flag[i] = 0;
}
}
// If frame-mt is enabled, only update mmco tables for the first slice
// in a field. Subsequent slices can temporarily clobber h->mmco_index
// or h->mmco, which will cause ref list mix-ups and decoding errors
// further down the line. This may break decoding if the first slice is
// corrupt, thus we only do this if frame-mt is enabled.
if (h->nal_ref_idc) {
ret = ff_h264_decode_ref_pic_marking(h, &sl->gb,
!(h->avctx->active_thread_type & FF_THREAD_FRAME) ||
h->current_slice == 0);
if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE))
return AVERROR_INVALIDDATA;
}
if (FRAME_MBAFF(h)) {
ff_h264_fill_mbaff_ref_list(h, sl);
if (pps->weighted_bipred_idc == 2 && sl->slice_type_nos == AV_PICTURE_TYPE_B) {
implicit_weight_table(h, sl, 0);
implicit_weight_table(h, sl, 1);
}
}
if (sl->slice_type_nos == AV_PICTURE_TYPE_B && !sl->direct_spatial_mv_pred)
ff_h264_direct_dist_scale_factor(h, sl);
ff_h264_direct_ref_list_init(h, sl);
if (sl->slice_type_nos != AV_PICTURE_TYPE_I && pps->cabac) {
tmp = get_ue_golomb_31(&sl->gb);
if (tmp > 2) {
av_log(h->avctx, AV_LOG_ERROR, "cabac_init_idc %u overflow\n", tmp);
return AVERROR_INVALIDDATA;
}
sl->cabac_init_idc = tmp;
}
sl->last_qscale_diff = 0;
tmp = pps->init_qp + get_se_golomb(&sl->gb);
if (tmp > 51 + 6 * (sps->bit_depth_luma - 8)) {
av_log(h->avctx, AV_LOG_ERROR, "QP %u out of range\n", tmp);
return AVERROR_INVALIDDATA;
}
sl->qscale = tmp;
sl->chroma_qp[0] = get_chroma_qp(h, 0, sl->qscale);
sl->chroma_qp[1] = get_chroma_qp(h, 1, sl->qscale);
// FIXME qscale / qp ... stuff
if (sl->slice_type == AV_PICTURE_TYPE_SP)
get_bits1(&sl->gb); /* sp_for_switch_flag */
if (sl->slice_type == AV_PICTURE_TYPE_SP ||
sl->slice_type == AV_PICTURE_TYPE_SI)
get_se_golomb(&sl->gb); /* slice_qs_delta */
sl->deblocking_filter = 1;
sl->slice_alpha_c0_offset = 0;
sl->slice_beta_offset = 0;
if (pps->deblocking_filter_parameters_present) {
tmp = get_ue_golomb_31(&sl->gb);
if (tmp > 2) {
av_log(h->avctx, AV_LOG_ERROR,
"deblocking_filter_idc %u out of range\n", tmp);
return AVERROR_INVALIDDATA;
}
sl->deblocking_filter = tmp;
if (sl->deblocking_filter < 2)
sl->deblocking_filter ^= 1; // 1<->0
if (sl->deblocking_filter) {
sl->slice_alpha_c0_offset = get_se_golomb(&sl->gb) * 2;
sl->slice_beta_offset = get_se_golomb(&sl->gb) * 2;
if (sl->slice_alpha_c0_offset > 12 ||
sl->slice_alpha_c0_offset < -12 ||
sl->slice_beta_offset > 12 ||
sl->slice_beta_offset < -12) {
av_log(h->avctx, AV_LOG_ERROR,
"deblocking filter parameters %d %d out of range\n",
sl->slice_alpha_c0_offset, sl->slice_beta_offset);
return AVERROR_INVALIDDATA;
}
}
}
if (h->avctx->skip_loop_filter >= AVDISCARD_ALL ||
(h->avctx->skip_loop_filter >= AVDISCARD_NONKEY &&
sl->slice_type_nos != AV_PICTURE_TYPE_I) ||
(h->avctx->skip_loop_filter >= AVDISCARD_BIDIR &&
sl->slice_type_nos == AV_PICTURE_TYPE_B) ||
(h->avctx->skip_loop_filter >= AVDISCARD_NONREF &&
h->nal_ref_idc == 0))
sl->deblocking_filter = 0;
if (sl->deblocking_filter == 1 && h->max_contexts > 1) {
if (h->avctx->flags2 & AV_CODEC_FLAG2_FAST) {
/* Cheat slightly for speed:
* Do not bother to deblock across slices. */
sl->deblocking_filter = 2;
} else {
h->max_contexts = 1;
if (!h->single_decode_warning) {
av_log(h->avctx, AV_LOG_INFO,
"Cannot parallelize deblocking type 1, decoding such frames in sequential order\n");
h->single_decode_warning = 1;
}
if (sl != h->slice_ctx) {
av_log(h->avctx, AV_LOG_ERROR,
"Deblocking switched inside frame.\n");
return 1;
}
}
}
sl->qp_thresh = 15 -
FFMIN(sl->slice_alpha_c0_offset, sl->slice_beta_offset) -
FFMAX3(0,
pps->chroma_qp_index_offset[0],
pps->chroma_qp_index_offset[1]) +
6 * (sps->bit_depth_luma - 8);
sl->slice_num = ++h->current_slice;
if (sl->slice_num >= MAX_SLICES) {
av_log(h->avctx, AV_LOG_ERROR,
"Too many slices, increase MAX_SLICES and recompile\n");
}
for (j = 0; j < 2; j++) {
int id_list[16];
int *ref2frm = sl->ref2frm[sl->slice_num & (MAX_SLICES - 1)][j];
for (i = 0; i < 16; i++) {
id_list[i] = 60;
if (j < sl->list_count && i < sl->ref_count[j] &&
sl->ref_list[j][i].parent->f->buf[0]) {
int k;
AVBuffer *buf = sl->ref_list[j][i].parent->f->buf[0]->buffer;
for (k = 0; k < h->short_ref_count; k++)
if (h->short_ref[k]->f->buf[0]->buffer == buf) {
id_list[i] = k;
break;
}
for (k = 0; k < h->long_ref_count; k++)
if (h->long_ref[k] && h->long_ref[k]->f->buf[0]->buffer == buf) {
id_list[i] = h->short_ref_count + k;
break;
}
}
}
ref2frm[0] =
ref2frm[1] = -1;
for (i = 0; i < 16; i++)
ref2frm[i + 2] = 4 * id_list[i] + (sl->ref_list[j][i].reference & 3);
ref2frm[18 + 0] =
ref2frm[18 + 1] = -1;
for (i = 16; i < 48; i++)
ref2frm[i + 4] = 4 * id_list[(i - 16) >> 1] +
(sl->ref_list[j][i].reference & 3);
}
if (h->avctx->debug & FF_DEBUG_PICT_INFO) {
av_log(h->avctx, AV_LOG_DEBUG,
"slice:%d %s mb:%d %c%s%s pps:%u frame:%d poc:%d/%d ref:%d/%d qp:%d loop:%d:%d:%d weight:%d%s %s\n",
sl->slice_num,
(h->picture_structure == PICT_FRAME ? "F" : h->picture_structure == PICT_TOP_FIELD ? "T" : "B"),
first_mb_in_slice,
av_get_picture_type_char(sl->slice_type),
sl->slice_type_fixed ? " fix" : "",
h->nal_unit_type == NAL_IDR_SLICE ? " IDR" : "",
pps_id, h->frame_num,
h->cur_pic_ptr->field_poc[0],
h->cur_pic_ptr->field_poc[1],
sl->ref_count[0], sl->ref_count[1],
sl->qscale,
sl->deblocking_filter,
sl->slice_alpha_c0_offset, sl->slice_beta_offset,
sl->pwt.use_weight,
sl->pwt.use_weight == 1 && sl->pwt.use_weight_chroma ? "c" : "",
sl->slice_type == AV_PICTURE_TYPE_B ? (sl->direct_spatial_mv_pred ? "SPAT" : "TEMP") : "");
}
return 0;
}
| false | FFmpeg | c8dcff0cdb17d0aa03ac729eba12d1a20f1f59c8 | int ff_h264_decode_slice_header(H264Context *h, H264SliceContext *sl)
{
const SPS *sps;
const PPS *pps;
unsigned int first_mb_in_slice;
unsigned int pps_id;
int ret;
unsigned int slice_type, tmp, i, j;
int last_pic_structure, last_pic_droppable;
int needs_reinit = 0;
int field_pic_flag, bottom_field_flag;
int frame_num, droppable, picture_structure;
int mb_aff_frame = 0;
h->qpel_put = h->h264qpel.put_h264_qpel_pixels_tab;
h->qpel_avg = h->h264qpel.avg_h264_qpel_pixels_tab;
first_mb_in_slice = get_ue_golomb(&sl->gb);
if (first_mb_in_slice == 0) {
if (h->current_slice && h->cur_pic_ptr && FIELD_PICTURE(h)) {
ff_h264_field_end(h, sl, 1);
}
h->current_slice = 0;
if (!h->first_field) {
if (h->cur_pic_ptr && !h->droppable) {
ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX,
h->picture_structure == PICT_BOTTOM_FIELD);
}
h->cur_pic_ptr = NULL;
}
}
slice_type = get_ue_golomb_31(&sl->gb);
if (slice_type > 9) {
av_log(h->avctx, AV_LOG_ERROR,
"slice type %d too large at %d\n",
slice_type, first_mb_in_slice);
return AVERROR_INVALIDDATA;
}
if (slice_type > 4) {
slice_type -= 5;
sl->slice_type_fixed = 1;
} else
sl->slice_type_fixed = 0;
slice_type = ff_h264_golomb_to_pict_type[slice_type];
sl->slice_type = slice_type;
sl->slice_type_nos = slice_type & 3;
if (h->nal_unit_type == NAL_IDR_SLICE &&
sl->slice_type_nos != AV_PICTURE_TYPE_I) {
av_log(h->avctx, AV_LOG_ERROR, "A non-intra slice in an IDR NAL unit.\n");
return AVERROR_INVALIDDATA;
}
if (!h->setup_finished)
h->pict_type = sl->slice_type;
pps_id = get_ue_golomb(&sl->gb);
if (pps_id >= MAX_PPS_COUNT) {
av_log(h->avctx, AV_LOG_ERROR, "pps_id %u out of range\n", pps_id);
return AVERROR_INVALIDDATA;
}
if (!h->ps.pps_list[pps_id]) {
av_log(h->avctx, AV_LOG_ERROR,
"non-existing PPS %u referenced\n",
pps_id);
return AVERROR_INVALIDDATA;
}
if (!h->setup_finished) {
h->ps.pps = (const PPS*)h->ps.pps_list[pps_id]->data;
} else if (h->ps.pps != (const PPS*)h->ps.pps_list[pps_id]->data) {
av_log(h->avctx, AV_LOG_ERROR, "PPS changed between slices\n");
return AVERROR_INVALIDDATA;
}
if (!h->ps.sps_list[h->ps.pps->sps_id]) {
av_log(h->avctx, AV_LOG_ERROR,
"non-existing SPS %u referenced\n",
h->ps.pps->sps_id);
return AVERROR_INVALIDDATA;
}
if (h->ps.sps != (const SPS*)h->ps.sps_list[h->ps.pps->sps_id]->data) {
h->ps.sps = (SPS*)h->ps.sps_list[h->ps.pps->sps_id]->data;
if (h->bit_depth_luma != h->ps.sps->bit_depth_luma ||
h->chroma_format_idc != h->ps.sps->chroma_format_idc)
needs_reinit = 1;
if (h->flags & AV_CODEC_FLAG_LOW_DELAY ||
(h->ps.sps->bitstream_restriction_flag &&
!h->ps.sps->num_reorder_frames)) {
if (h->avctx->has_b_frames > 1 || h->delayed_pic[0])
av_log(h->avctx, AV_LOG_WARNING, "Delayed frames seen. "
"Reenabling low delay requires a codec flush.\n");
else
h->low_delay = 1;
}
if (h->avctx->has_b_frames < 2)
h->avctx->has_b_frames = !h->low_delay;
}
pps = h->ps.pps;
sps = h->ps.sps;
if (!h->setup_finished) {
h->avctx->profile = ff_h264_get_profile(sps);
h->avctx->level = sps->level_idc;
h->avctx->refs = sps->ref_frame_count;
if (h->mb_width != sps->mb_width ||
h->mb_height != sps->mb_height * (2 - sps->frame_mbs_only_flag))
needs_reinit = 1;
h->mb_width = sps->mb_width;
h->mb_height = sps->mb_height * (2 - sps->frame_mbs_only_flag);
h->mb_num = h->mb_width * h->mb_height;
h->mb_stride = h->mb_width + 1;
h->b_stride = h->mb_width * 4;
h->chroma_y_shift = sps->chroma_format_idc <= 1;
h->width = 16 * h->mb_width;
h->height = 16 * h->mb_height;
ret = init_dimensions(h);
if (ret < 0)
return ret;
if (sps->video_signal_type_present_flag) {
h->avctx->color_range = sps->full_range ? AVCOL_RANGE_JPEG
: AVCOL_RANGE_MPEG;
if (sps->colour_description_present_flag) {
if (h->avctx->colorspace != sps->colorspace)
needs_reinit = 1;
h->avctx->color_primaries = sps->color_primaries;
h->avctx->color_trc = sps->color_trc;
h->avctx->colorspace = sps->colorspace;
}
}
}
if (h->context_initialized && needs_reinit) {
h->context_initialized = 0;
if (sl != h->slice_ctx) {
av_log(h->avctx, AV_LOG_ERROR,
"changing width %d -> %d / height %d -> %d on "
"slice %d\n",
h->width, h->avctx->coded_width,
h->height, h->avctx->coded_height,
h->current_slice + 1);
return AVERROR_INVALIDDATA;
}
ff_h264_flush_change(h);
if ((ret = get_pixel_format(h)) < 0)
return ret;
h->avctx->pix_fmt = ret;
av_log(h->avctx, AV_LOG_INFO, "Reinit context to %dx%d, "
"pix_fmt: %d\n", h->width, h->height, h->avctx->pix_fmt);
if ((ret = h264_slice_header_init(h)) < 0) {
av_log(h->avctx, AV_LOG_ERROR,
"h264_slice_header_init() failed\n");
return ret;
}
}
if (!h->context_initialized) {
if (sl != h->slice_ctx) {
av_log(h->avctx, AV_LOG_ERROR,
"Cannot (re-)initialize context during parallel decoding.\n");
return AVERROR_PATCHWELCOME;
}
if ((ret = get_pixel_format(h)) < 0)
return ret;
h->avctx->pix_fmt = ret;
if ((ret = h264_slice_header_init(h)) < 0) {
av_log(h->avctx, AV_LOG_ERROR,
"h264_slice_header_init() failed\n");
return ret;
}
}
frame_num = get_bits(&sl->gb, sps->log2_max_frame_num);
if (!h->setup_finished)
h->frame_num = frame_num;
sl->mb_mbaff = 0;
last_pic_structure = h->picture_structure;
last_pic_droppable = h->droppable;
droppable = h->nal_ref_idc == 0;
if (sps->frame_mbs_only_flag) {
picture_structure = PICT_FRAME;
} else {
field_pic_flag = get_bits1(&sl->gb);
if (field_pic_flag) {
bottom_field_flag = get_bits1(&sl->gb);
picture_structure = PICT_TOP_FIELD + bottom_field_flag;
} else {
picture_structure = PICT_FRAME;
mb_aff_frame = sps->mb_aff;
}
}
if (!h->setup_finished) {
h->droppable = droppable;
h->picture_structure = picture_structure;
h->mb_aff_frame = mb_aff_frame;
}
sl->mb_field_decoding_flag = h->picture_structure != PICT_FRAME;
if (h->current_slice != 0) {
if (last_pic_structure != picture_structure ||
last_pic_droppable != droppable) {
av_log(h->avctx, AV_LOG_ERROR,
"Changing field mode (%d -> %d) between slices is not allowed\n",
last_pic_structure, h->picture_structure);
return AVERROR_INVALIDDATA;
} else if (!h->cur_pic_ptr) {
av_log(h->avctx, AV_LOG_ERROR,
"unset cur_pic_ptr on slice %d\n",
h->current_slice + 1);
return AVERROR_INVALIDDATA;
}
} else {
if (h->frame_num != h->prev_frame_num) {
int unwrap_prev_frame_num = h->prev_frame_num;
int max_frame_num = 1 << sps->log2_max_frame_num;
if (unwrap_prev_frame_num > h->frame_num)
unwrap_prev_frame_num -= max_frame_num;
if ((h->frame_num - unwrap_prev_frame_num) > sps->ref_frame_count) {
unwrap_prev_frame_num = (h->frame_num - sps->ref_frame_count) - 1;
if (unwrap_prev_frame_num < 0)
unwrap_prev_frame_num += max_frame_num;
h->prev_frame_num = unwrap_prev_frame_num;
}
}
if (h->first_field) {
assert(h->cur_pic_ptr);
assert(h->cur_pic_ptr->f->buf[0]);
assert(h->cur_pic_ptr->reference != DELAYED_PIC_REF);
if (!FIELD_PICTURE(h) || h->picture_structure == last_pic_structure) {
if (!last_pic_droppable && last_pic_structure != PICT_FRAME) {
ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX,
last_pic_structure == PICT_TOP_FIELD);
}
} else {
if (h->cur_pic_ptr->frame_num != h->frame_num) {
if (!last_pic_droppable && last_pic_structure != PICT_FRAME) {
ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX,
last_pic_structure == PICT_TOP_FIELD);
}
} else {
if (!((last_pic_structure == PICT_TOP_FIELD &&
h->picture_structure == PICT_BOTTOM_FIELD) ||
(last_pic_structure == PICT_BOTTOM_FIELD &&
h->picture_structure == PICT_TOP_FIELD))) {
av_log(h->avctx, AV_LOG_ERROR,
"Invalid field mode combination %d/%d\n",
last_pic_structure, h->picture_structure);
h->picture_structure = last_pic_structure;
h->droppable = last_pic_droppable;
return AVERROR_INVALIDDATA;
} else if (last_pic_droppable != h->droppable) {
avpriv_request_sample(h->avctx,
"Found reference and non-reference fields in the same frame, which");
h->picture_structure = last_pic_structure;
h->droppable = last_pic_droppable;
return AVERROR_PATCHWELCOME;
}
}
}
}
while (h->frame_num != h->prev_frame_num &&
h->frame_num != (h->prev_frame_num + 1) % (1 << sps->log2_max_frame_num)) {
H264Picture *prev = h->short_ref_count ? h->short_ref[0] : NULL;
av_log(h->avctx, AV_LOG_DEBUG, "Frame num gap %d %d\n",
h->frame_num, h->prev_frame_num);
ret = initialize_cur_frame(h);
if (ret < 0) {
h->first_field = 0;
return ret;
}
h->prev_frame_num++;
h->prev_frame_num %= 1 << sps->log2_max_frame_num;
h->cur_pic_ptr->frame_num = h->prev_frame_num;
ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX, 0);
ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX, 1);
ret = ff_generate_sliding_window_mmcos(h, 1);
if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE))
return ret;
ret = ff_h264_execute_ref_pic_marking(h, h->mmco, h->mmco_index);
if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE))
return ret;
if (h->short_ref_count) {
if (prev &&
h->short_ref[0]->f->width == prev->f->width &&
h->short_ref[0]->f->height == prev->f->height &&
h->short_ref[0]->f->format == prev->f->format) {
av_image_copy(h->short_ref[0]->f->data,
h->short_ref[0]->f->linesize,
(const uint8_t **)prev->f->data,
prev->f->linesize,
prev->f->format,
h->mb_width * 16,
h->mb_height * 16);
h->short_ref[0]->poc = prev->poc + 2;
}
h->short_ref[0]->frame_num = h->prev_frame_num;
}
}
if (h->first_field) {
assert(h->cur_pic_ptr);
assert(h->cur_pic_ptr->f->buf[0]);
assert(h->cur_pic_ptr->reference != DELAYED_PIC_REF);
if (!FIELD_PICTURE(h) || h->picture_structure == last_pic_structure) {
h->cur_pic_ptr = NULL;
h->first_field = FIELD_PICTURE(h);
} else {
if (h->cur_pic_ptr->frame_num != h->frame_num) {
h->first_field = 1;
h->cur_pic_ptr = NULL;
} else {
h->first_field = 0;
}
}
} else {
h->first_field = FIELD_PICTURE(h);
}
if (!FIELD_PICTURE(h) || h->first_field) {
if (h264_frame_start(h) < 0) {
h->first_field = 0;
return AVERROR_INVALIDDATA;
}
} else {
release_unused_pictures(h, 0);
}
}
assert(h->mb_num == h->mb_width * h->mb_height);
if (first_mb_in_slice << FIELD_OR_MBAFF_PICTURE(h) >= h->mb_num ||
first_mb_in_slice >= h->mb_num) {
av_log(h->avctx, AV_LOG_ERROR, "first_mb_in_slice overflow\n");
return AVERROR_INVALIDDATA;
}
sl->resync_mb_x = sl->mb_x = first_mb_in_slice % h->mb_width;
sl->resync_mb_y = sl->mb_y = (first_mb_in_slice / h->mb_width) <<
FIELD_OR_MBAFF_PICTURE(h);
if (h->picture_structure == PICT_BOTTOM_FIELD)
sl->resync_mb_y = sl->mb_y = sl->mb_y + 1;
assert(sl->mb_y < h->mb_height);
if (h->picture_structure == PICT_FRAME) {
h->curr_pic_num = h->frame_num;
h->max_pic_num = 1 << sps->log2_max_frame_num;
} else {
h->curr_pic_num = 2 * h->frame_num + 1;
h->max_pic_num = 1 << (sps->log2_max_frame_num + 1);
}
if (h->nal_unit_type == NAL_IDR_SLICE)
get_ue_golomb(&sl->gb);
if (sps->poc_type == 0) {
int poc_lsb = get_bits(&sl->gb, sps->log2_max_poc_lsb);
if (!h->setup_finished)
h->poc_lsb = poc_lsb;
if (pps->pic_order_present == 1 && h->picture_structure == PICT_FRAME) {
int delta_poc_bottom = get_se_golomb(&sl->gb);
if (!h->setup_finished)
h->delta_poc_bottom = delta_poc_bottom;
}
}
if (sps->poc_type == 1 && !sps->delta_pic_order_always_zero_flag) {
int delta_poc = get_se_golomb(&sl->gb);
if (!h->setup_finished)
h->delta_poc[0] = delta_poc;
if (pps->pic_order_present == 1 && h->picture_structure == PICT_FRAME) {
delta_poc = get_se_golomb(&sl->gb);
if (!h->setup_finished)
h->delta_poc[1] = delta_poc;
}
}
if (!h->setup_finished)
ff_init_poc(h, h->cur_pic_ptr->field_poc, &h->cur_pic_ptr->poc);
if (pps->redundant_pic_cnt_present)
sl->redundant_pic_count = get_ue_golomb(&sl->gb);
if (sl->slice_type_nos == AV_PICTURE_TYPE_B)
sl->direct_spatial_mv_pred = get_bits1(&sl->gb);
ret = ff_h264_parse_ref_count(&sl->list_count, sl->ref_count,
&sl->gb, pps, sl->slice_type_nos,
h->picture_structure);
if (ret < 0)
return ret;
if (sl->slice_type_nos != AV_PICTURE_TYPE_I) {
ret = ff_h264_decode_ref_pic_list_reordering(h, sl);
if (ret < 0) {
sl->ref_count[1] = sl->ref_count[0] = 0;
return ret;
}
}
if ((pps->weighted_pred && sl->slice_type_nos == AV_PICTURE_TYPE_P) ||
(pps->weighted_bipred_idc == 1 &&
sl->slice_type_nos == AV_PICTURE_TYPE_B))
ff_h264_pred_weight_table(&sl->gb, sps, sl->ref_count,
sl->slice_type_nos, &sl->pwt);
else if (pps->weighted_bipred_idc == 2 &&
sl->slice_type_nos == AV_PICTURE_TYPE_B) {
implicit_weight_table(h, sl, -1);
} else {
sl->pwt.use_weight = 0;
for (i = 0; i < 2; i++) {
sl->pwt.luma_weight_flag[i] = 0;
sl->pwt.chroma_weight_flag[i] = 0;
}
}
if (h->nal_ref_idc) {
ret = ff_h264_decode_ref_pic_marking(h, &sl->gb,
!(h->avctx->active_thread_type & FF_THREAD_FRAME) ||
h->current_slice == 0);
if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE))
return AVERROR_INVALIDDATA;
}
if (FRAME_MBAFF(h)) {
ff_h264_fill_mbaff_ref_list(h, sl);
if (pps->weighted_bipred_idc == 2 && sl->slice_type_nos == AV_PICTURE_TYPE_B) {
implicit_weight_table(h, sl, 0);
implicit_weight_table(h, sl, 1);
}
}
if (sl->slice_type_nos == AV_PICTURE_TYPE_B && !sl->direct_spatial_mv_pred)
ff_h264_direct_dist_scale_factor(h, sl);
ff_h264_direct_ref_list_init(h, sl);
if (sl->slice_type_nos != AV_PICTURE_TYPE_I && pps->cabac) {
tmp = get_ue_golomb_31(&sl->gb);
if (tmp > 2) {
av_log(h->avctx, AV_LOG_ERROR, "cabac_init_idc %u overflow\n", tmp);
return AVERROR_INVALIDDATA;
}
sl->cabac_init_idc = tmp;
}
sl->last_qscale_diff = 0;
tmp = pps->init_qp + get_se_golomb(&sl->gb);
if (tmp > 51 + 6 * (sps->bit_depth_luma - 8)) {
av_log(h->avctx, AV_LOG_ERROR, "QP %u out of range\n", tmp);
return AVERROR_INVALIDDATA;
}
sl->qscale = tmp;
sl->chroma_qp[0] = get_chroma_qp(h, 0, sl->qscale);
sl->chroma_qp[1] = get_chroma_qp(h, 1, sl->qscale);
if (sl->slice_type == AV_PICTURE_TYPE_SP)
get_bits1(&sl->gb);
if (sl->slice_type == AV_PICTURE_TYPE_SP ||
sl->slice_type == AV_PICTURE_TYPE_SI)
get_se_golomb(&sl->gb);
sl->deblocking_filter = 1;
sl->slice_alpha_c0_offset = 0;
sl->slice_beta_offset = 0;
if (pps->deblocking_filter_parameters_present) {
tmp = get_ue_golomb_31(&sl->gb);
if (tmp > 2) {
av_log(h->avctx, AV_LOG_ERROR,
"deblocking_filter_idc %u out of range\n", tmp);
return AVERROR_INVALIDDATA;
}
sl->deblocking_filter = tmp;
if (sl->deblocking_filter < 2)
sl->deblocking_filter ^= 1;
if (sl->deblocking_filter) {
sl->slice_alpha_c0_offset = get_se_golomb(&sl->gb) * 2;
sl->slice_beta_offset = get_se_golomb(&sl->gb) * 2;
if (sl->slice_alpha_c0_offset > 12 ||
sl->slice_alpha_c0_offset < -12 ||
sl->slice_beta_offset > 12 ||
sl->slice_beta_offset < -12) {
av_log(h->avctx, AV_LOG_ERROR,
"deblocking filter parameters %d %d out of range\n",
sl->slice_alpha_c0_offset, sl->slice_beta_offset);
return AVERROR_INVALIDDATA;
}
}
}
if (h->avctx->skip_loop_filter >= AVDISCARD_ALL ||
(h->avctx->skip_loop_filter >= AVDISCARD_NONKEY &&
sl->slice_type_nos != AV_PICTURE_TYPE_I) ||
(h->avctx->skip_loop_filter >= AVDISCARD_BIDIR &&
sl->slice_type_nos == AV_PICTURE_TYPE_B) ||
(h->avctx->skip_loop_filter >= AVDISCARD_NONREF &&
h->nal_ref_idc == 0))
sl->deblocking_filter = 0;
if (sl->deblocking_filter == 1 && h->max_contexts > 1) {
if (h->avctx->flags2 & AV_CODEC_FLAG2_FAST) {
sl->deblocking_filter = 2;
} else {
h->max_contexts = 1;
if (!h->single_decode_warning) {
av_log(h->avctx, AV_LOG_INFO,
"Cannot parallelize deblocking type 1, decoding such frames in sequential order\n");
h->single_decode_warning = 1;
}
if (sl != h->slice_ctx) {
av_log(h->avctx, AV_LOG_ERROR,
"Deblocking switched inside frame.\n");
return 1;
}
}
}
sl->qp_thresh = 15 -
FFMIN(sl->slice_alpha_c0_offset, sl->slice_beta_offset) -
FFMAX3(0,
pps->chroma_qp_index_offset[0],
pps->chroma_qp_index_offset[1]) +
6 * (sps->bit_depth_luma - 8);
sl->slice_num = ++h->current_slice;
if (sl->slice_num >= MAX_SLICES) {
av_log(h->avctx, AV_LOG_ERROR,
"Too many slices, increase MAX_SLICES and recompile\n");
}
for (j = 0; j < 2; j++) {
int id_list[16];
int *ref2frm = sl->ref2frm[sl->slice_num & (MAX_SLICES - 1)][j];
for (i = 0; i < 16; i++) {
id_list[i] = 60;
if (j < sl->list_count && i < sl->ref_count[j] &&
sl->ref_list[j][i].parent->f->buf[0]) {
int k;
AVBuffer *buf = sl->ref_list[j][i].parent->f->buf[0]->buffer;
for (k = 0; k < h->short_ref_count; k++)
if (h->short_ref[k]->f->buf[0]->buffer == buf) {
id_list[i] = k;
break;
}
for (k = 0; k < h->long_ref_count; k++)
if (h->long_ref[k] && h->long_ref[k]->f->buf[0]->buffer == buf) {
id_list[i] = h->short_ref_count + k;
break;
}
}
}
ref2frm[0] =
ref2frm[1] = -1;
for (i = 0; i < 16; i++)
ref2frm[i + 2] = 4 * id_list[i] + (sl->ref_list[j][i].reference & 3);
ref2frm[18 + 0] =
ref2frm[18 + 1] = -1;
for (i = 16; i < 48; i++)
ref2frm[i + 4] = 4 * id_list[(i - 16) >> 1] +
(sl->ref_list[j][i].reference & 3);
}
if (h->avctx->debug & FF_DEBUG_PICT_INFO) {
av_log(h->avctx, AV_LOG_DEBUG,
"slice:%d %s mb:%d %c%s%s pps:%u frame:%d poc:%d/%d ref:%d/%d qp:%d loop:%d:%d:%d weight:%d%s %s\n",
sl->slice_num,
(h->picture_structure == PICT_FRAME ? "F" : h->picture_structure == PICT_TOP_FIELD ? "T" : "B"),
first_mb_in_slice,
av_get_picture_type_char(sl->slice_type),
sl->slice_type_fixed ? " fix" : "",
h->nal_unit_type == NAL_IDR_SLICE ? " IDR" : "",
pps_id, h->frame_num,
h->cur_pic_ptr->field_poc[0],
h->cur_pic_ptr->field_poc[1],
sl->ref_count[0], sl->ref_count[1],
sl->qscale,
sl->deblocking_filter,
sl->slice_alpha_c0_offset, sl->slice_beta_offset,
sl->pwt.use_weight,
sl->pwt.use_weight == 1 && sl->pwt.use_weight_chroma ? "c" : "",
sl->slice_type == AV_PICTURE_TYPE_B ? (sl->direct_spatial_mv_pred ? "SPAT" : "TEMP") : "");
}
return 0;
}
| {
"code": [],
"line_no": []
} | int FUNC_0(H264Context *VAR_0, H264SliceContext *VAR_1)
{
const SPS *VAR_2;
const PPS *VAR_3;
unsigned int VAR_4;
unsigned int VAR_5;
int VAR_6;
unsigned int VAR_7, VAR_8, VAR_9, VAR_10;
int VAR_11, VAR_12;
int VAR_13 = 0;
int VAR_14, VAR_15;
int VAR_16, VAR_17, VAR_18;
int VAR_19 = 0;
VAR_0->qpel_put = VAR_0->h264qpel.put_h264_qpel_pixels_tab;
VAR_0->qpel_avg = VAR_0->h264qpel.avg_h264_qpel_pixels_tab;
VAR_4 = get_ue_golomb(&VAR_1->gb);
if (VAR_4 == 0) {
if (VAR_0->current_slice && VAR_0->cur_pic_ptr && FIELD_PICTURE(VAR_0)) {
ff_h264_field_end(VAR_0, VAR_1, 1);
}
VAR_0->current_slice = 0;
if (!VAR_0->first_field) {
if (VAR_0->cur_pic_ptr && !VAR_0->VAR_17) {
ff_thread_report_progress(&VAR_0->cur_pic_ptr->tf, INT_MAX,
VAR_0->VAR_18 == PICT_BOTTOM_FIELD);
}
VAR_0->cur_pic_ptr = NULL;
}
}
VAR_7 = get_ue_golomb_31(&VAR_1->gb);
if (VAR_7 > 9) {
av_log(VAR_0->avctx, AV_LOG_ERROR,
"slice type %d too large at %d\n",
VAR_7, VAR_4);
return AVERROR_INVALIDDATA;
}
if (VAR_7 > 4) {
VAR_7 -= 5;
VAR_1->slice_type_fixed = 1;
} else
VAR_1->slice_type_fixed = 0;
VAR_7 = ff_h264_golomb_to_pict_type[VAR_7];
VAR_1->VAR_7 = VAR_7;
VAR_1->slice_type_nos = VAR_7 & 3;
if (VAR_0->nal_unit_type == NAL_IDR_SLICE &&
VAR_1->slice_type_nos != AV_PICTURE_TYPE_I) {
av_log(VAR_0->avctx, AV_LOG_ERROR, "A non-intra slice in an IDR NAL unit.\n");
return AVERROR_INVALIDDATA;
}
if (!VAR_0->setup_finished)
VAR_0->pict_type = VAR_1->VAR_7;
VAR_5 = get_ue_golomb(&VAR_1->gb);
if (VAR_5 >= MAX_PPS_COUNT) {
av_log(VAR_0->avctx, AV_LOG_ERROR, "VAR_5 %u out of range\n", VAR_5);
return AVERROR_INVALIDDATA;
}
if (!VAR_0->ps.pps_list[VAR_5]) {
av_log(VAR_0->avctx, AV_LOG_ERROR,
"non-existing PPS %u referenced\n",
VAR_5);
return AVERROR_INVALIDDATA;
}
if (!VAR_0->setup_finished) {
VAR_0->ps.VAR_3 = (const PPS*)VAR_0->ps.pps_list[VAR_5]->data;
} else if (VAR_0->ps.VAR_3 != (const PPS*)VAR_0->ps.pps_list[VAR_5]->data) {
av_log(VAR_0->avctx, AV_LOG_ERROR, "PPS changed between slices\n");
return AVERROR_INVALIDDATA;
}
if (!VAR_0->ps.sps_list[VAR_0->ps.VAR_3->sps_id]) {
av_log(VAR_0->avctx, AV_LOG_ERROR,
"non-existing SPS %u referenced\n",
VAR_0->ps.VAR_3->sps_id);
return AVERROR_INVALIDDATA;
}
if (VAR_0->ps.VAR_2 != (const SPS*)VAR_0->ps.sps_list[VAR_0->ps.VAR_3->sps_id]->data) {
VAR_0->ps.VAR_2 = (SPS*)VAR_0->ps.sps_list[VAR_0->ps.VAR_3->sps_id]->data;
if (VAR_0->bit_depth_luma != VAR_0->ps.VAR_2->bit_depth_luma ||
VAR_0->chroma_format_idc != VAR_0->ps.VAR_2->chroma_format_idc)
VAR_13 = 1;
if (VAR_0->flags & AV_CODEC_FLAG_LOW_DELAY ||
(VAR_0->ps.VAR_2->bitstream_restriction_flag &&
!VAR_0->ps.VAR_2->num_reorder_frames)) {
if (VAR_0->avctx->has_b_frames > 1 || VAR_0->delayed_pic[0])
av_log(VAR_0->avctx, AV_LOG_WARNING, "Delayed frames seen. "
"Reenabling low delay requires a codec flush.\n");
else
VAR_0->low_delay = 1;
}
if (VAR_0->avctx->has_b_frames < 2)
VAR_0->avctx->has_b_frames = !VAR_0->low_delay;
}
VAR_3 = VAR_0->ps.VAR_3;
VAR_2 = VAR_0->ps.VAR_2;
if (!VAR_0->setup_finished) {
VAR_0->avctx->profile = ff_h264_get_profile(VAR_2);
VAR_0->avctx->level = VAR_2->level_idc;
VAR_0->avctx->refs = VAR_2->ref_frame_count;
if (VAR_0->mb_width != VAR_2->mb_width ||
VAR_0->mb_height != VAR_2->mb_height * (2 - VAR_2->frame_mbs_only_flag))
VAR_13 = 1;
VAR_0->mb_width = VAR_2->mb_width;
VAR_0->mb_height = VAR_2->mb_height * (2 - VAR_2->frame_mbs_only_flag);
VAR_0->mb_num = VAR_0->mb_width * VAR_0->mb_height;
VAR_0->mb_stride = VAR_0->mb_width + 1;
VAR_0->b_stride = VAR_0->mb_width * 4;
VAR_0->chroma_y_shift = VAR_2->chroma_format_idc <= 1;
VAR_0->width = 16 * VAR_0->mb_width;
VAR_0->height = 16 * VAR_0->mb_height;
VAR_6 = init_dimensions(VAR_0);
if (VAR_6 < 0)
return VAR_6;
if (VAR_2->video_signal_type_present_flag) {
VAR_0->avctx->color_range = VAR_2->full_range ? AVCOL_RANGE_JPEG
: AVCOL_RANGE_MPEG;
if (VAR_2->colour_description_present_flag) {
if (VAR_0->avctx->colorspace != VAR_2->colorspace)
VAR_13 = 1;
VAR_0->avctx->color_primaries = VAR_2->color_primaries;
VAR_0->avctx->color_trc = VAR_2->color_trc;
VAR_0->avctx->colorspace = VAR_2->colorspace;
}
}
}
if (VAR_0->context_initialized && VAR_13) {
VAR_0->context_initialized = 0;
if (VAR_1 != VAR_0->slice_ctx) {
av_log(VAR_0->avctx, AV_LOG_ERROR,
"changing width %d -> %d / height %d -> %d on "
"slice %d\n",
VAR_0->width, VAR_0->avctx->coded_width,
VAR_0->height, VAR_0->avctx->coded_height,
VAR_0->current_slice + 1);
return AVERROR_INVALIDDATA;
}
ff_h264_flush_change(VAR_0);
if ((VAR_6 = get_pixel_format(VAR_0)) < 0)
return VAR_6;
VAR_0->avctx->pix_fmt = VAR_6;
av_log(VAR_0->avctx, AV_LOG_INFO, "Reinit context to %dx%d, "
"pix_fmt: %d\n", VAR_0->width, VAR_0->height, VAR_0->avctx->pix_fmt);
if ((VAR_6 = h264_slice_header_init(VAR_0)) < 0) {
av_log(VAR_0->avctx, AV_LOG_ERROR,
"h264_slice_header_init() failed\n");
return VAR_6;
}
}
if (!VAR_0->context_initialized) {
if (VAR_1 != VAR_0->slice_ctx) {
av_log(VAR_0->avctx, AV_LOG_ERROR,
"Cannot (re-)initialize context during parallel decoding.\n");
return AVERROR_PATCHWELCOME;
}
if ((VAR_6 = get_pixel_format(VAR_0)) < 0)
return VAR_6;
VAR_0->avctx->pix_fmt = VAR_6;
if ((VAR_6 = h264_slice_header_init(VAR_0)) < 0) {
av_log(VAR_0->avctx, AV_LOG_ERROR,
"h264_slice_header_init() failed\n");
return VAR_6;
}
}
VAR_16 = get_bits(&VAR_1->gb, VAR_2->log2_max_frame_num);
if (!VAR_0->setup_finished)
VAR_0->VAR_16 = VAR_16;
VAR_1->mb_mbaff = 0;
VAR_11 = VAR_0->VAR_18;
VAR_12 = VAR_0->VAR_17;
VAR_17 = VAR_0->nal_ref_idc == 0;
if (VAR_2->frame_mbs_only_flag) {
VAR_18 = PICT_FRAME;
} else {
VAR_14 = get_bits1(&VAR_1->gb);
if (VAR_14) {
VAR_15 = get_bits1(&VAR_1->gb);
VAR_18 = PICT_TOP_FIELD + VAR_15;
} else {
VAR_18 = PICT_FRAME;
VAR_19 = VAR_2->mb_aff;
}
}
if (!VAR_0->setup_finished) {
VAR_0->VAR_17 = VAR_17;
VAR_0->VAR_18 = VAR_18;
VAR_0->VAR_19 = VAR_19;
}
VAR_1->mb_field_decoding_flag = VAR_0->VAR_18 != PICT_FRAME;
if (VAR_0->current_slice != 0) {
if (VAR_11 != VAR_18 ||
VAR_12 != VAR_17) {
av_log(VAR_0->avctx, AV_LOG_ERROR,
"Changing field mode (%d -> %d) between slices is not allowed\n",
VAR_11, VAR_0->VAR_18);
return AVERROR_INVALIDDATA;
} else if (!VAR_0->cur_pic_ptr) {
av_log(VAR_0->avctx, AV_LOG_ERROR,
"unset cur_pic_ptr on slice %d\n",
VAR_0->current_slice + 1);
return AVERROR_INVALIDDATA;
}
} else {
if (VAR_0->VAR_16 != VAR_0->prev_frame_num) {
int VAR_20 = VAR_0->prev_frame_num;
int VAR_21 = 1 << VAR_2->log2_max_frame_num;
if (VAR_20 > VAR_0->VAR_16)
VAR_20 -= VAR_21;
if ((VAR_0->VAR_16 - VAR_20) > VAR_2->ref_frame_count) {
VAR_20 = (VAR_0->VAR_16 - VAR_2->ref_frame_count) - 1;
if (VAR_20 < 0)
VAR_20 += VAR_21;
VAR_0->prev_frame_num = VAR_20;
}
}
if (VAR_0->first_field) {
assert(VAR_0->cur_pic_ptr);
assert(VAR_0->cur_pic_ptr->f->buf[0]);
assert(VAR_0->cur_pic_ptr->reference != DELAYED_PIC_REF);
if (!FIELD_PICTURE(VAR_0) || VAR_0->VAR_18 == VAR_11) {
if (!VAR_12 && VAR_11 != PICT_FRAME) {
ff_thread_report_progress(&VAR_0->cur_pic_ptr->tf, INT_MAX,
VAR_11 == PICT_TOP_FIELD);
}
} else {
if (VAR_0->cur_pic_ptr->VAR_16 != VAR_0->VAR_16) {
if (!VAR_12 && VAR_11 != PICT_FRAME) {
ff_thread_report_progress(&VAR_0->cur_pic_ptr->tf, INT_MAX,
VAR_11 == PICT_TOP_FIELD);
}
} else {
if (!((VAR_11 == PICT_TOP_FIELD &&
VAR_0->VAR_18 == PICT_BOTTOM_FIELD) ||
(VAR_11 == PICT_BOTTOM_FIELD &&
VAR_0->VAR_18 == PICT_TOP_FIELD))) {
av_log(VAR_0->avctx, AV_LOG_ERROR,
"Invalid field mode combination %d/%d\n",
VAR_11, VAR_0->VAR_18);
VAR_0->VAR_18 = VAR_11;
VAR_0->VAR_17 = VAR_12;
return AVERROR_INVALIDDATA;
} else if (VAR_12 != VAR_0->VAR_17) {
avpriv_request_sample(VAR_0->avctx,
"Found reference and non-reference fields in the same frame, which");
VAR_0->VAR_18 = VAR_11;
VAR_0->VAR_17 = VAR_12;
return AVERROR_PATCHWELCOME;
}
}
}
}
while (VAR_0->VAR_16 != VAR_0->prev_frame_num &&
VAR_0->VAR_16 != (VAR_0->prev_frame_num + 1) % (1 << VAR_2->log2_max_frame_num)) {
H264Picture *prev = VAR_0->short_ref_count ? VAR_0->short_ref[0] : NULL;
av_log(VAR_0->avctx, AV_LOG_DEBUG, "Frame num gap %d %d\n",
VAR_0->VAR_16, VAR_0->prev_frame_num);
VAR_6 = initialize_cur_frame(VAR_0);
if (VAR_6 < 0) {
VAR_0->first_field = 0;
return VAR_6;
}
VAR_0->prev_frame_num++;
VAR_0->prev_frame_num %= 1 << VAR_2->log2_max_frame_num;
VAR_0->cur_pic_ptr->VAR_16 = VAR_0->prev_frame_num;
ff_thread_report_progress(&VAR_0->cur_pic_ptr->tf, INT_MAX, 0);
ff_thread_report_progress(&VAR_0->cur_pic_ptr->tf, INT_MAX, 1);
VAR_6 = ff_generate_sliding_window_mmcos(VAR_0, 1);
if (VAR_6 < 0 && (VAR_0->avctx->err_recognition & AV_EF_EXPLODE))
return VAR_6;
VAR_6 = ff_h264_execute_ref_pic_marking(VAR_0, VAR_0->mmco, VAR_0->mmco_index);
if (VAR_6 < 0 && (VAR_0->avctx->err_recognition & AV_EF_EXPLODE))
return VAR_6;
if (VAR_0->short_ref_count) {
if (prev &&
VAR_0->short_ref[0]->f->width == prev->f->width &&
VAR_0->short_ref[0]->f->height == prev->f->height &&
VAR_0->short_ref[0]->f->format == prev->f->format) {
av_image_copy(VAR_0->short_ref[0]->f->data,
VAR_0->short_ref[0]->f->linesize,
(const uint8_t **)prev->f->data,
prev->f->linesize,
prev->f->format,
VAR_0->mb_width * 16,
VAR_0->mb_height * 16);
VAR_0->short_ref[0]->poc = prev->poc + 2;
}
VAR_0->short_ref[0]->VAR_16 = VAR_0->prev_frame_num;
}
}
if (VAR_0->first_field) {
assert(VAR_0->cur_pic_ptr);
assert(VAR_0->cur_pic_ptr->f->buf[0]);
assert(VAR_0->cur_pic_ptr->reference != DELAYED_PIC_REF);
if (!FIELD_PICTURE(VAR_0) || VAR_0->VAR_18 == VAR_11) {
VAR_0->cur_pic_ptr = NULL;
VAR_0->first_field = FIELD_PICTURE(VAR_0);
} else {
if (VAR_0->cur_pic_ptr->VAR_16 != VAR_0->VAR_16) {
VAR_0->first_field = 1;
VAR_0->cur_pic_ptr = NULL;
} else {
VAR_0->first_field = 0;
}
}
} else {
VAR_0->first_field = FIELD_PICTURE(VAR_0);
}
if (!FIELD_PICTURE(VAR_0) || VAR_0->first_field) {
if (h264_frame_start(VAR_0) < 0) {
VAR_0->first_field = 0;
return AVERROR_INVALIDDATA;
}
} else {
release_unused_pictures(VAR_0, 0);
}
}
assert(VAR_0->mb_num == VAR_0->mb_width * VAR_0->mb_height);
if (VAR_4 << FIELD_OR_MBAFF_PICTURE(VAR_0) >= VAR_0->mb_num ||
VAR_4 >= VAR_0->mb_num) {
av_log(VAR_0->avctx, AV_LOG_ERROR, "VAR_4 overflow\n");
return AVERROR_INVALIDDATA;
}
VAR_1->resync_mb_x = VAR_1->mb_x = VAR_4 % VAR_0->mb_width;
VAR_1->resync_mb_y = VAR_1->mb_y = (VAR_4 / VAR_0->mb_width) <<
FIELD_OR_MBAFF_PICTURE(VAR_0);
if (VAR_0->VAR_18 == PICT_BOTTOM_FIELD)
VAR_1->resync_mb_y = VAR_1->mb_y = VAR_1->mb_y + 1;
assert(VAR_1->mb_y < VAR_0->mb_height);
if (VAR_0->VAR_18 == PICT_FRAME) {
VAR_0->curr_pic_num = VAR_0->VAR_16;
VAR_0->max_pic_num = 1 << VAR_2->log2_max_frame_num;
} else {
VAR_0->curr_pic_num = 2 * VAR_0->VAR_16 + 1;
VAR_0->max_pic_num = 1 << (VAR_2->log2_max_frame_num + 1);
}
if (VAR_0->nal_unit_type == NAL_IDR_SLICE)
get_ue_golomb(&VAR_1->gb);
if (VAR_2->poc_type == 0) {
int VAR_22 = get_bits(&VAR_1->gb, VAR_2->log2_max_poc_lsb);
if (!VAR_0->setup_finished)
VAR_0->VAR_22 = VAR_22;
if (VAR_3->pic_order_present == 1 && VAR_0->VAR_18 == PICT_FRAME) {
int VAR_23 = get_se_golomb(&VAR_1->gb);
if (!VAR_0->setup_finished)
VAR_0->VAR_23 = VAR_23;
}
}
if (VAR_2->poc_type == 1 && !VAR_2->delta_pic_order_always_zero_flag) {
int VAR_24 = get_se_golomb(&VAR_1->gb);
if (!VAR_0->setup_finished)
VAR_0->VAR_24[0] = VAR_24;
if (VAR_3->pic_order_present == 1 && VAR_0->VAR_18 == PICT_FRAME) {
VAR_24 = get_se_golomb(&VAR_1->gb);
if (!VAR_0->setup_finished)
VAR_0->VAR_24[1] = VAR_24;
}
}
if (!VAR_0->setup_finished)
ff_init_poc(VAR_0, VAR_0->cur_pic_ptr->field_poc, &VAR_0->cur_pic_ptr->poc);
if (VAR_3->redundant_pic_cnt_present)
VAR_1->redundant_pic_count = get_ue_golomb(&VAR_1->gb);
if (VAR_1->slice_type_nos == AV_PICTURE_TYPE_B)
VAR_1->direct_spatial_mv_pred = get_bits1(&VAR_1->gb);
VAR_6 = ff_h264_parse_ref_count(&VAR_1->list_count, VAR_1->ref_count,
&VAR_1->gb, VAR_3, VAR_1->slice_type_nos,
VAR_0->VAR_18);
if (VAR_6 < 0)
return VAR_6;
if (VAR_1->slice_type_nos != AV_PICTURE_TYPE_I) {
VAR_6 = ff_h264_decode_ref_pic_list_reordering(VAR_0, VAR_1);
if (VAR_6 < 0) {
VAR_1->ref_count[1] = VAR_1->ref_count[0] = 0;
return VAR_6;
}
}
if ((VAR_3->weighted_pred && VAR_1->slice_type_nos == AV_PICTURE_TYPE_P) ||
(VAR_3->weighted_bipred_idc == 1 &&
VAR_1->slice_type_nos == AV_PICTURE_TYPE_B))
ff_h264_pred_weight_table(&VAR_1->gb, VAR_2, VAR_1->ref_count,
VAR_1->slice_type_nos, &VAR_1->pwt);
else if (VAR_3->weighted_bipred_idc == 2 &&
VAR_1->slice_type_nos == AV_PICTURE_TYPE_B) {
implicit_weight_table(VAR_0, VAR_1, -1);
} else {
VAR_1->pwt.use_weight = 0;
for (VAR_9 = 0; VAR_9 < 2; VAR_9++) {
VAR_1->pwt.luma_weight_flag[VAR_9] = 0;
VAR_1->pwt.chroma_weight_flag[VAR_9] = 0;
}
}
if (VAR_0->nal_ref_idc) {
VAR_6 = ff_h264_decode_ref_pic_marking(VAR_0, &VAR_1->gb,
!(VAR_0->avctx->active_thread_type & FF_THREAD_FRAME) ||
VAR_0->current_slice == 0);
if (VAR_6 < 0 && (VAR_0->avctx->err_recognition & AV_EF_EXPLODE))
return AVERROR_INVALIDDATA;
}
if (FRAME_MBAFF(VAR_0)) {
ff_h264_fill_mbaff_ref_list(VAR_0, VAR_1);
if (VAR_3->weighted_bipred_idc == 2 && VAR_1->slice_type_nos == AV_PICTURE_TYPE_B) {
implicit_weight_table(VAR_0, VAR_1, 0);
implicit_weight_table(VAR_0, VAR_1, 1);
}
}
if (VAR_1->slice_type_nos == AV_PICTURE_TYPE_B && !VAR_1->direct_spatial_mv_pred)
ff_h264_direct_dist_scale_factor(VAR_0, VAR_1);
ff_h264_direct_ref_list_init(VAR_0, VAR_1);
if (VAR_1->slice_type_nos != AV_PICTURE_TYPE_I && VAR_3->cabac) {
VAR_8 = get_ue_golomb_31(&VAR_1->gb);
if (VAR_8 > 2) {
av_log(VAR_0->avctx, AV_LOG_ERROR, "cabac_init_idc %u overflow\n", VAR_8);
return AVERROR_INVALIDDATA;
}
VAR_1->cabac_init_idc = VAR_8;
}
VAR_1->last_qscale_diff = 0;
VAR_8 = VAR_3->init_qp + get_se_golomb(&VAR_1->gb);
if (VAR_8 > 51 + 6 * (VAR_2->bit_depth_luma - 8)) {
av_log(VAR_0->avctx, AV_LOG_ERROR, "QP %u out of range\n", VAR_8);
return AVERROR_INVALIDDATA;
}
VAR_1->qscale = VAR_8;
VAR_1->chroma_qp[0] = get_chroma_qp(VAR_0, 0, VAR_1->qscale);
VAR_1->chroma_qp[1] = get_chroma_qp(VAR_0, 1, VAR_1->qscale);
if (VAR_1->VAR_7 == AV_PICTURE_TYPE_SP)
get_bits1(&VAR_1->gb);
if (VAR_1->VAR_7 == AV_PICTURE_TYPE_SP ||
VAR_1->VAR_7 == AV_PICTURE_TYPE_SI)
get_se_golomb(&VAR_1->gb);
VAR_1->deblocking_filter = 1;
VAR_1->slice_alpha_c0_offset = 0;
VAR_1->slice_beta_offset = 0;
if (VAR_3->deblocking_filter_parameters_present) {
VAR_8 = get_ue_golomb_31(&VAR_1->gb);
if (VAR_8 > 2) {
av_log(VAR_0->avctx, AV_LOG_ERROR,
"deblocking_filter_idc %u out of range\n", VAR_8);
return AVERROR_INVALIDDATA;
}
VAR_1->deblocking_filter = VAR_8;
if (VAR_1->deblocking_filter < 2)
VAR_1->deblocking_filter ^= 1;
if (VAR_1->deblocking_filter) {
VAR_1->slice_alpha_c0_offset = get_se_golomb(&VAR_1->gb) * 2;
VAR_1->slice_beta_offset = get_se_golomb(&VAR_1->gb) * 2;
if (VAR_1->slice_alpha_c0_offset > 12 ||
VAR_1->slice_alpha_c0_offset < -12 ||
VAR_1->slice_beta_offset > 12 ||
VAR_1->slice_beta_offset < -12) {
av_log(VAR_0->avctx, AV_LOG_ERROR,
"deblocking filter parameters %d %d out of range\n",
VAR_1->slice_alpha_c0_offset, VAR_1->slice_beta_offset);
return AVERROR_INVALIDDATA;
}
}
}
if (VAR_0->avctx->skip_loop_filter >= AVDISCARD_ALL ||
(VAR_0->avctx->skip_loop_filter >= AVDISCARD_NONKEY &&
VAR_1->slice_type_nos != AV_PICTURE_TYPE_I) ||
(VAR_0->avctx->skip_loop_filter >= AVDISCARD_BIDIR &&
VAR_1->slice_type_nos == AV_PICTURE_TYPE_B) ||
(VAR_0->avctx->skip_loop_filter >= AVDISCARD_NONREF &&
VAR_0->nal_ref_idc == 0))
VAR_1->deblocking_filter = 0;
if (VAR_1->deblocking_filter == 1 && VAR_0->max_contexts > 1) {
if (VAR_0->avctx->flags2 & AV_CODEC_FLAG2_FAST) {
VAR_1->deblocking_filter = 2;
} else {
VAR_0->max_contexts = 1;
if (!VAR_0->single_decode_warning) {
av_log(VAR_0->avctx, AV_LOG_INFO,
"Cannot parallelize deblocking type 1, decoding such frames in sequential order\n");
VAR_0->single_decode_warning = 1;
}
if (VAR_1 != VAR_0->slice_ctx) {
av_log(VAR_0->avctx, AV_LOG_ERROR,
"Deblocking switched inside frame.\n");
return 1;
}
}
}
VAR_1->qp_thresh = 15 -
FFMIN(VAR_1->slice_alpha_c0_offset, VAR_1->slice_beta_offset) -
FFMAX3(0,
VAR_3->chroma_qp_index_offset[0],
VAR_3->chroma_qp_index_offset[1]) +
6 * (VAR_2->bit_depth_luma - 8);
VAR_1->slice_num = ++VAR_0->current_slice;
if (VAR_1->slice_num >= MAX_SLICES) {
av_log(VAR_0->avctx, AV_LOG_ERROR,
"Too many slices, increase MAX_SLICES and recompile\n");
}
for (VAR_10 = 0; VAR_10 < 2; VAR_10++) {
int VAR_25[16];
int *VAR_26 = VAR_1->VAR_26[VAR_1->slice_num & (MAX_SLICES - 1)][VAR_10];
for (VAR_9 = 0; VAR_9 < 16; VAR_9++) {
VAR_25[VAR_9] = 60;
if (VAR_10 < VAR_1->list_count && VAR_9 < VAR_1->ref_count[VAR_10] &&
VAR_1->ref_list[VAR_10][VAR_9].parent->f->buf[0]) {
int VAR_27;
AVBuffer *buf = VAR_1->ref_list[VAR_10][VAR_9].parent->f->buf[0]->buffer;
for (VAR_27 = 0; VAR_27 < VAR_0->short_ref_count; VAR_27++)
if (VAR_0->short_ref[VAR_27]->f->buf[0]->buffer == buf) {
VAR_25[VAR_9] = VAR_27;
break;
}
for (VAR_27 = 0; VAR_27 < VAR_0->long_ref_count; VAR_27++)
if (VAR_0->long_ref[VAR_27] && VAR_0->long_ref[VAR_27]->f->buf[0]->buffer == buf) {
VAR_25[VAR_9] = VAR_0->short_ref_count + VAR_27;
break;
}
}
}
VAR_26[0] =
VAR_26[1] = -1;
for (VAR_9 = 0; VAR_9 < 16; VAR_9++)
VAR_26[VAR_9 + 2] = 4 * VAR_25[VAR_9] + (VAR_1->ref_list[VAR_10][VAR_9].reference & 3);
VAR_26[18 + 0] =
VAR_26[18 + 1] = -1;
for (VAR_9 = 16; VAR_9 < 48; VAR_9++)
VAR_26[VAR_9 + 4] = 4 * VAR_25[(VAR_9 - 16) >> 1] +
(VAR_1->ref_list[VAR_10][VAR_9].reference & 3);
}
if (VAR_0->avctx->debug & FF_DEBUG_PICT_INFO) {
av_log(VAR_0->avctx, AV_LOG_DEBUG,
"slice:%d %s mb:%d %c%s%s VAR_3:%u frame:%d poc:%d/%d ref:%d/%d qp:%d loop:%d:%d:%d weight:%d%s %s\n",
VAR_1->slice_num,
(VAR_0->VAR_18 == PICT_FRAME ? "F" : VAR_0->VAR_18 == PICT_TOP_FIELD ? "T" : "B"),
VAR_4,
av_get_picture_type_char(VAR_1->VAR_7),
VAR_1->slice_type_fixed ? " fix" : "",
VAR_0->nal_unit_type == NAL_IDR_SLICE ? " IDR" : "",
VAR_5, VAR_0->VAR_16,
VAR_0->cur_pic_ptr->field_poc[0],
VAR_0->cur_pic_ptr->field_poc[1],
VAR_1->ref_count[0], VAR_1->ref_count[1],
VAR_1->qscale,
VAR_1->deblocking_filter,
VAR_1->slice_alpha_c0_offset, VAR_1->slice_beta_offset,
VAR_1->pwt.use_weight,
VAR_1->pwt.use_weight == 1 && VAR_1->pwt.use_weight_chroma ? "c" : "",
VAR_1->VAR_7 == AV_PICTURE_TYPE_B ? (VAR_1->direct_spatial_mv_pred ? "SPAT" : "TEMP") : "");
}
return 0;
}
| [
"int FUNC_0(H264Context *VAR_0, H264SliceContext *VAR_1)\n{",
"const SPS *VAR_2;",
"const PPS *VAR_3;",
"unsigned int VAR_4;",
"unsigned int VAR_5;",
"int VAR_6;",
"unsigned int VAR_7, VAR_8, VAR_9, VAR_10;",
"int VAR_11, VAR_12;",
"int VAR_13 = 0;",
"int VAR_14, VAR_15;",
"int VAR_16, VAR_17, VAR_18;",
"int VAR_19 = 0;",
"VAR_0->qpel_put = VAR_0->h264qpel.put_h264_qpel_pixels_tab;",
"VAR_0->qpel_avg = VAR_0->h264qpel.avg_h264_qpel_pixels_tab;",
"VAR_4 = get_ue_golomb(&VAR_1->gb);",
"if (VAR_4 == 0) {",
"if (VAR_0->current_slice && VAR_0->cur_pic_ptr && FIELD_PICTURE(VAR_0)) {",
"ff_h264_field_end(VAR_0, VAR_1, 1);",
"}",
"VAR_0->current_slice = 0;",
"if (!VAR_0->first_field) {",
"if (VAR_0->cur_pic_ptr && !VAR_0->VAR_17) {",
"ff_thread_report_progress(&VAR_0->cur_pic_ptr->tf, INT_MAX,\nVAR_0->VAR_18 == PICT_BOTTOM_FIELD);",
"}",
"VAR_0->cur_pic_ptr = NULL;",
"}",
"}",
"VAR_7 = get_ue_golomb_31(&VAR_1->gb);",
"if (VAR_7 > 9) {",
"av_log(VAR_0->avctx, AV_LOG_ERROR,\n\"slice type %d too large at %d\\n\",\nVAR_7, VAR_4);",
"return AVERROR_INVALIDDATA;",
"}",
"if (VAR_7 > 4) {",
"VAR_7 -= 5;",
"VAR_1->slice_type_fixed = 1;",
"} else",
"VAR_1->slice_type_fixed = 0;",
"VAR_7 = ff_h264_golomb_to_pict_type[VAR_7];",
"VAR_1->VAR_7 = VAR_7;",
"VAR_1->slice_type_nos = VAR_7 & 3;",
"if (VAR_0->nal_unit_type == NAL_IDR_SLICE &&\nVAR_1->slice_type_nos != AV_PICTURE_TYPE_I) {",
"av_log(VAR_0->avctx, AV_LOG_ERROR, \"A non-intra slice in an IDR NAL unit.\\n\");",
"return AVERROR_INVALIDDATA;",
"}",
"if (!VAR_0->setup_finished)\nVAR_0->pict_type = VAR_1->VAR_7;",
"VAR_5 = get_ue_golomb(&VAR_1->gb);",
"if (VAR_5 >= MAX_PPS_COUNT) {",
"av_log(VAR_0->avctx, AV_LOG_ERROR, \"VAR_5 %u out of range\\n\", VAR_5);",
"return AVERROR_INVALIDDATA;",
"}",
"if (!VAR_0->ps.pps_list[VAR_5]) {",
"av_log(VAR_0->avctx, AV_LOG_ERROR,\n\"non-existing PPS %u referenced\\n\",\nVAR_5);",
"return AVERROR_INVALIDDATA;",
"}",
"if (!VAR_0->setup_finished) {",
"VAR_0->ps.VAR_3 = (const PPS*)VAR_0->ps.pps_list[VAR_5]->data;",
"} else if (VAR_0->ps.VAR_3 != (const PPS*)VAR_0->ps.pps_list[VAR_5]->data) {",
"av_log(VAR_0->avctx, AV_LOG_ERROR, \"PPS changed between slices\\n\");",
"return AVERROR_INVALIDDATA;",
"}",
"if (!VAR_0->ps.sps_list[VAR_0->ps.VAR_3->sps_id]) {",
"av_log(VAR_0->avctx, AV_LOG_ERROR,\n\"non-existing SPS %u referenced\\n\",\nVAR_0->ps.VAR_3->sps_id);",
"return AVERROR_INVALIDDATA;",
"}",
"if (VAR_0->ps.VAR_2 != (const SPS*)VAR_0->ps.sps_list[VAR_0->ps.VAR_3->sps_id]->data) {",
"VAR_0->ps.VAR_2 = (SPS*)VAR_0->ps.sps_list[VAR_0->ps.VAR_3->sps_id]->data;",
"if (VAR_0->bit_depth_luma != VAR_0->ps.VAR_2->bit_depth_luma ||\nVAR_0->chroma_format_idc != VAR_0->ps.VAR_2->chroma_format_idc)\nVAR_13 = 1;",
"if (VAR_0->flags & AV_CODEC_FLAG_LOW_DELAY ||\n(VAR_0->ps.VAR_2->bitstream_restriction_flag &&\n!VAR_0->ps.VAR_2->num_reorder_frames)) {",
"if (VAR_0->avctx->has_b_frames > 1 || VAR_0->delayed_pic[0])\nav_log(VAR_0->avctx, AV_LOG_WARNING, \"Delayed frames seen. \"\n\"Reenabling low delay requires a codec flush.\\n\");",
"else\nVAR_0->low_delay = 1;",
"}",
"if (VAR_0->avctx->has_b_frames < 2)\nVAR_0->avctx->has_b_frames = !VAR_0->low_delay;",
"}",
"VAR_3 = VAR_0->ps.VAR_3;",
"VAR_2 = VAR_0->ps.VAR_2;",
"if (!VAR_0->setup_finished) {",
"VAR_0->avctx->profile = ff_h264_get_profile(VAR_2);",
"VAR_0->avctx->level = VAR_2->level_idc;",
"VAR_0->avctx->refs = VAR_2->ref_frame_count;",
"if (VAR_0->mb_width != VAR_2->mb_width ||\nVAR_0->mb_height != VAR_2->mb_height * (2 - VAR_2->frame_mbs_only_flag))\nVAR_13 = 1;",
"VAR_0->mb_width = VAR_2->mb_width;",
"VAR_0->mb_height = VAR_2->mb_height * (2 - VAR_2->frame_mbs_only_flag);",
"VAR_0->mb_num = VAR_0->mb_width * VAR_0->mb_height;",
"VAR_0->mb_stride = VAR_0->mb_width + 1;",
"VAR_0->b_stride = VAR_0->mb_width * 4;",
"VAR_0->chroma_y_shift = VAR_2->chroma_format_idc <= 1;",
"VAR_0->width = 16 * VAR_0->mb_width;",
"VAR_0->height = 16 * VAR_0->mb_height;",
"VAR_6 = init_dimensions(VAR_0);",
"if (VAR_6 < 0)\nreturn VAR_6;",
"if (VAR_2->video_signal_type_present_flag) {",
"VAR_0->avctx->color_range = VAR_2->full_range ? AVCOL_RANGE_JPEG\n: AVCOL_RANGE_MPEG;",
"if (VAR_2->colour_description_present_flag) {",
"if (VAR_0->avctx->colorspace != VAR_2->colorspace)\nVAR_13 = 1;",
"VAR_0->avctx->color_primaries = VAR_2->color_primaries;",
"VAR_0->avctx->color_trc = VAR_2->color_trc;",
"VAR_0->avctx->colorspace = VAR_2->colorspace;",
"}",
"}",
"}",
"if (VAR_0->context_initialized && VAR_13) {",
"VAR_0->context_initialized = 0;",
"if (VAR_1 != VAR_0->slice_ctx) {",
"av_log(VAR_0->avctx, AV_LOG_ERROR,\n\"changing width %d -> %d / height %d -> %d on \"\n\"slice %d\\n\",\nVAR_0->width, VAR_0->avctx->coded_width,\nVAR_0->height, VAR_0->avctx->coded_height,\nVAR_0->current_slice + 1);",
"return AVERROR_INVALIDDATA;",
"}",
"ff_h264_flush_change(VAR_0);",
"if ((VAR_6 = get_pixel_format(VAR_0)) < 0)\nreturn VAR_6;",
"VAR_0->avctx->pix_fmt = VAR_6;",
"av_log(VAR_0->avctx, AV_LOG_INFO, \"Reinit context to %dx%d, \"\n\"pix_fmt: %d\\n\", VAR_0->width, VAR_0->height, VAR_0->avctx->pix_fmt);",
"if ((VAR_6 = h264_slice_header_init(VAR_0)) < 0) {",
"av_log(VAR_0->avctx, AV_LOG_ERROR,\n\"h264_slice_header_init() failed\\n\");",
"return VAR_6;",
"}",
"}",
"if (!VAR_0->context_initialized) {",
"if (VAR_1 != VAR_0->slice_ctx) {",
"av_log(VAR_0->avctx, AV_LOG_ERROR,\n\"Cannot (re-)initialize context during parallel decoding.\\n\");",
"return AVERROR_PATCHWELCOME;",
"}",
"if ((VAR_6 = get_pixel_format(VAR_0)) < 0)\nreturn VAR_6;",
"VAR_0->avctx->pix_fmt = VAR_6;",
"if ((VAR_6 = h264_slice_header_init(VAR_0)) < 0) {",
"av_log(VAR_0->avctx, AV_LOG_ERROR,\n\"h264_slice_header_init() failed\\n\");",
"return VAR_6;",
"}",
"}",
"VAR_16 = get_bits(&VAR_1->gb, VAR_2->log2_max_frame_num);",
"if (!VAR_0->setup_finished)\nVAR_0->VAR_16 = VAR_16;",
"VAR_1->mb_mbaff = 0;",
"VAR_11 = VAR_0->VAR_18;",
"VAR_12 = VAR_0->VAR_17;",
"VAR_17 = VAR_0->nal_ref_idc == 0;",
"if (VAR_2->frame_mbs_only_flag) {",
"VAR_18 = PICT_FRAME;",
"} else {",
"VAR_14 = get_bits1(&VAR_1->gb);",
"if (VAR_14) {",
"VAR_15 = get_bits1(&VAR_1->gb);",
"VAR_18 = PICT_TOP_FIELD + VAR_15;",
"} else {",
"VAR_18 = PICT_FRAME;",
"VAR_19 = VAR_2->mb_aff;",
"}",
"}",
"if (!VAR_0->setup_finished) {",
"VAR_0->VAR_17 = VAR_17;",
"VAR_0->VAR_18 = VAR_18;",
"VAR_0->VAR_19 = VAR_19;",
"}",
"VAR_1->mb_field_decoding_flag = VAR_0->VAR_18 != PICT_FRAME;",
"if (VAR_0->current_slice != 0) {",
"if (VAR_11 != VAR_18 ||\nVAR_12 != VAR_17) {",
"av_log(VAR_0->avctx, AV_LOG_ERROR,\n\"Changing field mode (%d -> %d) between slices is not allowed\\n\",\nVAR_11, VAR_0->VAR_18);",
"return AVERROR_INVALIDDATA;",
"} else if (!VAR_0->cur_pic_ptr) {",
"av_log(VAR_0->avctx, AV_LOG_ERROR,\n\"unset cur_pic_ptr on slice %d\\n\",\nVAR_0->current_slice + 1);",
"return AVERROR_INVALIDDATA;",
"}",
"} else {",
"if (VAR_0->VAR_16 != VAR_0->prev_frame_num) {",
"int VAR_20 = VAR_0->prev_frame_num;",
"int VAR_21 = 1 << VAR_2->log2_max_frame_num;",
"if (VAR_20 > VAR_0->VAR_16)\nVAR_20 -= VAR_21;",
"if ((VAR_0->VAR_16 - VAR_20) > VAR_2->ref_frame_count) {",
"VAR_20 = (VAR_0->VAR_16 - VAR_2->ref_frame_count) - 1;",
"if (VAR_20 < 0)\nVAR_20 += VAR_21;",
"VAR_0->prev_frame_num = VAR_20;",
"}",
"}",
"if (VAR_0->first_field) {",
"assert(VAR_0->cur_pic_ptr);",
"assert(VAR_0->cur_pic_ptr->f->buf[0]);",
"assert(VAR_0->cur_pic_ptr->reference != DELAYED_PIC_REF);",
"if (!FIELD_PICTURE(VAR_0) || VAR_0->VAR_18 == VAR_11) {",
"if (!VAR_12 && VAR_11 != PICT_FRAME) {",
"ff_thread_report_progress(&VAR_0->cur_pic_ptr->tf, INT_MAX,\nVAR_11 == PICT_TOP_FIELD);",
"}",
"} else {",
"if (VAR_0->cur_pic_ptr->VAR_16 != VAR_0->VAR_16) {",
"if (!VAR_12 && VAR_11 != PICT_FRAME) {",
"ff_thread_report_progress(&VAR_0->cur_pic_ptr->tf, INT_MAX,\nVAR_11 == PICT_TOP_FIELD);",
"}",
"} else {",
"if (!((VAR_11 == PICT_TOP_FIELD &&\nVAR_0->VAR_18 == PICT_BOTTOM_FIELD) ||\n(VAR_11 == PICT_BOTTOM_FIELD &&\nVAR_0->VAR_18 == PICT_TOP_FIELD))) {",
"av_log(VAR_0->avctx, AV_LOG_ERROR,\n\"Invalid field mode combination %d/%d\\n\",\nVAR_11, VAR_0->VAR_18);",
"VAR_0->VAR_18 = VAR_11;",
"VAR_0->VAR_17 = VAR_12;",
"return AVERROR_INVALIDDATA;",
"} else if (VAR_12 != VAR_0->VAR_17) {",
"avpriv_request_sample(VAR_0->avctx,\n\"Found reference and non-reference fields in the same frame, which\");",
"VAR_0->VAR_18 = VAR_11;",
"VAR_0->VAR_17 = VAR_12;",
"return AVERROR_PATCHWELCOME;",
"}",
"}",
"}",
"}",
"while (VAR_0->VAR_16 != VAR_0->prev_frame_num &&\nVAR_0->VAR_16 != (VAR_0->prev_frame_num + 1) % (1 << VAR_2->log2_max_frame_num)) {",
"H264Picture *prev = VAR_0->short_ref_count ? VAR_0->short_ref[0] : NULL;",
"av_log(VAR_0->avctx, AV_LOG_DEBUG, \"Frame num gap %d %d\\n\",\nVAR_0->VAR_16, VAR_0->prev_frame_num);",
"VAR_6 = initialize_cur_frame(VAR_0);",
"if (VAR_6 < 0) {",
"VAR_0->first_field = 0;",
"return VAR_6;",
"}",
"VAR_0->prev_frame_num++;",
"VAR_0->prev_frame_num %= 1 << VAR_2->log2_max_frame_num;",
"VAR_0->cur_pic_ptr->VAR_16 = VAR_0->prev_frame_num;",
"ff_thread_report_progress(&VAR_0->cur_pic_ptr->tf, INT_MAX, 0);",
"ff_thread_report_progress(&VAR_0->cur_pic_ptr->tf, INT_MAX, 1);",
"VAR_6 = ff_generate_sliding_window_mmcos(VAR_0, 1);",
"if (VAR_6 < 0 && (VAR_0->avctx->err_recognition & AV_EF_EXPLODE))\nreturn VAR_6;",
"VAR_6 = ff_h264_execute_ref_pic_marking(VAR_0, VAR_0->mmco, VAR_0->mmco_index);",
"if (VAR_6 < 0 && (VAR_0->avctx->err_recognition & AV_EF_EXPLODE))\nreturn VAR_6;",
"if (VAR_0->short_ref_count) {",
"if (prev &&\nVAR_0->short_ref[0]->f->width == prev->f->width &&\nVAR_0->short_ref[0]->f->height == prev->f->height &&\nVAR_0->short_ref[0]->f->format == prev->f->format) {",
"av_image_copy(VAR_0->short_ref[0]->f->data,\nVAR_0->short_ref[0]->f->linesize,\n(const uint8_t **)prev->f->data,\nprev->f->linesize,\nprev->f->format,\nVAR_0->mb_width * 16,\nVAR_0->mb_height * 16);",
"VAR_0->short_ref[0]->poc = prev->poc + 2;",
"}",
"VAR_0->short_ref[0]->VAR_16 = VAR_0->prev_frame_num;",
"}",
"}",
"if (VAR_0->first_field) {",
"assert(VAR_0->cur_pic_ptr);",
"assert(VAR_0->cur_pic_ptr->f->buf[0]);",
"assert(VAR_0->cur_pic_ptr->reference != DELAYED_PIC_REF);",
"if (!FIELD_PICTURE(VAR_0) || VAR_0->VAR_18 == VAR_11) {",
"VAR_0->cur_pic_ptr = NULL;",
"VAR_0->first_field = FIELD_PICTURE(VAR_0);",
"} else {",
"if (VAR_0->cur_pic_ptr->VAR_16 != VAR_0->VAR_16) {",
"VAR_0->first_field = 1;",
"VAR_0->cur_pic_ptr = NULL;",
"} else {",
"VAR_0->first_field = 0;",
"}",
"}",
"} else {",
"VAR_0->first_field = FIELD_PICTURE(VAR_0);",
"}",
"if (!FIELD_PICTURE(VAR_0) || VAR_0->first_field) {",
"if (h264_frame_start(VAR_0) < 0) {",
"VAR_0->first_field = 0;",
"return AVERROR_INVALIDDATA;",
"}",
"} else {",
"release_unused_pictures(VAR_0, 0);",
"}",
"}",
"assert(VAR_0->mb_num == VAR_0->mb_width * VAR_0->mb_height);",
"if (VAR_4 << FIELD_OR_MBAFF_PICTURE(VAR_0) >= VAR_0->mb_num ||\nVAR_4 >= VAR_0->mb_num) {",
"av_log(VAR_0->avctx, AV_LOG_ERROR, \"VAR_4 overflow\\n\");",
"return AVERROR_INVALIDDATA;",
"}",
"VAR_1->resync_mb_x = VAR_1->mb_x = VAR_4 % VAR_0->mb_width;",
"VAR_1->resync_mb_y = VAR_1->mb_y = (VAR_4 / VAR_0->mb_width) <<\nFIELD_OR_MBAFF_PICTURE(VAR_0);",
"if (VAR_0->VAR_18 == PICT_BOTTOM_FIELD)\nVAR_1->resync_mb_y = VAR_1->mb_y = VAR_1->mb_y + 1;",
"assert(VAR_1->mb_y < VAR_0->mb_height);",
"if (VAR_0->VAR_18 == PICT_FRAME) {",
"VAR_0->curr_pic_num = VAR_0->VAR_16;",
"VAR_0->max_pic_num = 1 << VAR_2->log2_max_frame_num;",
"} else {",
"VAR_0->curr_pic_num = 2 * VAR_0->VAR_16 + 1;",
"VAR_0->max_pic_num = 1 << (VAR_2->log2_max_frame_num + 1);",
"}",
"if (VAR_0->nal_unit_type == NAL_IDR_SLICE)\nget_ue_golomb(&VAR_1->gb);",
"if (VAR_2->poc_type == 0) {",
"int VAR_22 = get_bits(&VAR_1->gb, VAR_2->log2_max_poc_lsb);",
"if (!VAR_0->setup_finished)\nVAR_0->VAR_22 = VAR_22;",
"if (VAR_3->pic_order_present == 1 && VAR_0->VAR_18 == PICT_FRAME) {",
"int VAR_23 = get_se_golomb(&VAR_1->gb);",
"if (!VAR_0->setup_finished)\nVAR_0->VAR_23 = VAR_23;",
"}",
"}",
"if (VAR_2->poc_type == 1 && !VAR_2->delta_pic_order_always_zero_flag) {",
"int VAR_24 = get_se_golomb(&VAR_1->gb);",
"if (!VAR_0->setup_finished)\nVAR_0->VAR_24[0] = VAR_24;",
"if (VAR_3->pic_order_present == 1 && VAR_0->VAR_18 == PICT_FRAME) {",
"VAR_24 = get_se_golomb(&VAR_1->gb);",
"if (!VAR_0->setup_finished)\nVAR_0->VAR_24[1] = VAR_24;",
"}",
"}",
"if (!VAR_0->setup_finished)\nff_init_poc(VAR_0, VAR_0->cur_pic_ptr->field_poc, &VAR_0->cur_pic_ptr->poc);",
"if (VAR_3->redundant_pic_cnt_present)\nVAR_1->redundant_pic_count = get_ue_golomb(&VAR_1->gb);",
"if (VAR_1->slice_type_nos == AV_PICTURE_TYPE_B)\nVAR_1->direct_spatial_mv_pred = get_bits1(&VAR_1->gb);",
"VAR_6 = ff_h264_parse_ref_count(&VAR_1->list_count, VAR_1->ref_count,\n&VAR_1->gb, VAR_3, VAR_1->slice_type_nos,\nVAR_0->VAR_18);",
"if (VAR_6 < 0)\nreturn VAR_6;",
"if (VAR_1->slice_type_nos != AV_PICTURE_TYPE_I) {",
"VAR_6 = ff_h264_decode_ref_pic_list_reordering(VAR_0, VAR_1);",
"if (VAR_6 < 0) {",
"VAR_1->ref_count[1] = VAR_1->ref_count[0] = 0;",
"return VAR_6;",
"}",
"}",
"if ((VAR_3->weighted_pred && VAR_1->slice_type_nos == AV_PICTURE_TYPE_P) ||\n(VAR_3->weighted_bipred_idc == 1 &&\nVAR_1->slice_type_nos == AV_PICTURE_TYPE_B))\nff_h264_pred_weight_table(&VAR_1->gb, VAR_2, VAR_1->ref_count,\nVAR_1->slice_type_nos, &VAR_1->pwt);",
"else if (VAR_3->weighted_bipred_idc == 2 &&\nVAR_1->slice_type_nos == AV_PICTURE_TYPE_B) {",
"implicit_weight_table(VAR_0, VAR_1, -1);",
"} else {",
"VAR_1->pwt.use_weight = 0;",
"for (VAR_9 = 0; VAR_9 < 2; VAR_9++) {",
"VAR_1->pwt.luma_weight_flag[VAR_9] = 0;",
"VAR_1->pwt.chroma_weight_flag[VAR_9] = 0;",
"}",
"}",
"if (VAR_0->nal_ref_idc) {",
"VAR_6 = ff_h264_decode_ref_pic_marking(VAR_0, &VAR_1->gb,\n!(VAR_0->avctx->active_thread_type & FF_THREAD_FRAME) ||\nVAR_0->current_slice == 0);",
"if (VAR_6 < 0 && (VAR_0->avctx->err_recognition & AV_EF_EXPLODE))\nreturn AVERROR_INVALIDDATA;",
"}",
"if (FRAME_MBAFF(VAR_0)) {",
"ff_h264_fill_mbaff_ref_list(VAR_0, VAR_1);",
"if (VAR_3->weighted_bipred_idc == 2 && VAR_1->slice_type_nos == AV_PICTURE_TYPE_B) {",
"implicit_weight_table(VAR_0, VAR_1, 0);",
"implicit_weight_table(VAR_0, VAR_1, 1);",
"}",
"}",
"if (VAR_1->slice_type_nos == AV_PICTURE_TYPE_B && !VAR_1->direct_spatial_mv_pred)\nff_h264_direct_dist_scale_factor(VAR_0, VAR_1);",
"ff_h264_direct_ref_list_init(VAR_0, VAR_1);",
"if (VAR_1->slice_type_nos != AV_PICTURE_TYPE_I && VAR_3->cabac) {",
"VAR_8 = get_ue_golomb_31(&VAR_1->gb);",
"if (VAR_8 > 2) {",
"av_log(VAR_0->avctx, AV_LOG_ERROR, \"cabac_init_idc %u overflow\\n\", VAR_8);",
"return AVERROR_INVALIDDATA;",
"}",
"VAR_1->cabac_init_idc = VAR_8;",
"}",
"VAR_1->last_qscale_diff = 0;",
"VAR_8 = VAR_3->init_qp + get_se_golomb(&VAR_1->gb);",
"if (VAR_8 > 51 + 6 * (VAR_2->bit_depth_luma - 8)) {",
"av_log(VAR_0->avctx, AV_LOG_ERROR, \"QP %u out of range\\n\", VAR_8);",
"return AVERROR_INVALIDDATA;",
"}",
"VAR_1->qscale = VAR_8;",
"VAR_1->chroma_qp[0] = get_chroma_qp(VAR_0, 0, VAR_1->qscale);",
"VAR_1->chroma_qp[1] = get_chroma_qp(VAR_0, 1, VAR_1->qscale);",
"if (VAR_1->VAR_7 == AV_PICTURE_TYPE_SP)\nget_bits1(&VAR_1->gb);",
"if (VAR_1->VAR_7 == AV_PICTURE_TYPE_SP ||\nVAR_1->VAR_7 == AV_PICTURE_TYPE_SI)\nget_se_golomb(&VAR_1->gb);",
"VAR_1->deblocking_filter = 1;",
"VAR_1->slice_alpha_c0_offset = 0;",
"VAR_1->slice_beta_offset = 0;",
"if (VAR_3->deblocking_filter_parameters_present) {",
"VAR_8 = get_ue_golomb_31(&VAR_1->gb);",
"if (VAR_8 > 2) {",
"av_log(VAR_0->avctx, AV_LOG_ERROR,\n\"deblocking_filter_idc %u out of range\\n\", VAR_8);",
"return AVERROR_INVALIDDATA;",
"}",
"VAR_1->deblocking_filter = VAR_8;",
"if (VAR_1->deblocking_filter < 2)\nVAR_1->deblocking_filter ^= 1;",
"if (VAR_1->deblocking_filter) {",
"VAR_1->slice_alpha_c0_offset = get_se_golomb(&VAR_1->gb) * 2;",
"VAR_1->slice_beta_offset = get_se_golomb(&VAR_1->gb) * 2;",
"if (VAR_1->slice_alpha_c0_offset > 12 ||\nVAR_1->slice_alpha_c0_offset < -12 ||\nVAR_1->slice_beta_offset > 12 ||\nVAR_1->slice_beta_offset < -12) {",
"av_log(VAR_0->avctx, AV_LOG_ERROR,\n\"deblocking filter parameters %d %d out of range\\n\",\nVAR_1->slice_alpha_c0_offset, VAR_1->slice_beta_offset);",
"return AVERROR_INVALIDDATA;",
"}",
"}",
"}",
"if (VAR_0->avctx->skip_loop_filter >= AVDISCARD_ALL ||\n(VAR_0->avctx->skip_loop_filter >= AVDISCARD_NONKEY &&\nVAR_1->slice_type_nos != AV_PICTURE_TYPE_I) ||\n(VAR_0->avctx->skip_loop_filter >= AVDISCARD_BIDIR &&\nVAR_1->slice_type_nos == AV_PICTURE_TYPE_B) ||\n(VAR_0->avctx->skip_loop_filter >= AVDISCARD_NONREF &&\nVAR_0->nal_ref_idc == 0))\nVAR_1->deblocking_filter = 0;",
"if (VAR_1->deblocking_filter == 1 && VAR_0->max_contexts > 1) {",
"if (VAR_0->avctx->flags2 & AV_CODEC_FLAG2_FAST) {",
"VAR_1->deblocking_filter = 2;",
"} else {",
"VAR_0->max_contexts = 1;",
"if (!VAR_0->single_decode_warning) {",
"av_log(VAR_0->avctx, AV_LOG_INFO,\n\"Cannot parallelize deblocking type 1, decoding such frames in sequential order\\n\");",
"VAR_0->single_decode_warning = 1;",
"}",
"if (VAR_1 != VAR_0->slice_ctx) {",
"av_log(VAR_0->avctx, AV_LOG_ERROR,\n\"Deblocking switched inside frame.\\n\");",
"return 1;",
"}",
"}",
"}",
"VAR_1->qp_thresh = 15 -\nFFMIN(VAR_1->slice_alpha_c0_offset, VAR_1->slice_beta_offset) -\nFFMAX3(0,\nVAR_3->chroma_qp_index_offset[0],\nVAR_3->chroma_qp_index_offset[1]) +\n6 * (VAR_2->bit_depth_luma - 8);",
"VAR_1->slice_num = ++VAR_0->current_slice;",
"if (VAR_1->slice_num >= MAX_SLICES) {",
"av_log(VAR_0->avctx, AV_LOG_ERROR,\n\"Too many slices, increase MAX_SLICES and recompile\\n\");",
"}",
"for (VAR_10 = 0; VAR_10 < 2; VAR_10++) {",
"int VAR_25[16];",
"int *VAR_26 = VAR_1->VAR_26[VAR_1->slice_num & (MAX_SLICES - 1)][VAR_10];",
"for (VAR_9 = 0; VAR_9 < 16; VAR_9++) {",
"VAR_25[VAR_9] = 60;",
"if (VAR_10 < VAR_1->list_count && VAR_9 < VAR_1->ref_count[VAR_10] &&\nVAR_1->ref_list[VAR_10][VAR_9].parent->f->buf[0]) {",
"int VAR_27;",
"AVBuffer *buf = VAR_1->ref_list[VAR_10][VAR_9].parent->f->buf[0]->buffer;",
"for (VAR_27 = 0; VAR_27 < VAR_0->short_ref_count; VAR_27++)",
"if (VAR_0->short_ref[VAR_27]->f->buf[0]->buffer == buf) {",
"VAR_25[VAR_9] = VAR_27;",
"break;",
"}",
"for (VAR_27 = 0; VAR_27 < VAR_0->long_ref_count; VAR_27++)",
"if (VAR_0->long_ref[VAR_27] && VAR_0->long_ref[VAR_27]->f->buf[0]->buffer == buf) {",
"VAR_25[VAR_9] = VAR_0->short_ref_count + VAR_27;",
"break;",
"}",
"}",
"}",
"VAR_26[0] =\nVAR_26[1] = -1;",
"for (VAR_9 = 0; VAR_9 < 16; VAR_9++)",
"VAR_26[VAR_9 + 2] = 4 * VAR_25[VAR_9] + (VAR_1->ref_list[VAR_10][VAR_9].reference & 3);",
"VAR_26[18 + 0] =\nVAR_26[18 + 1] = -1;",
"for (VAR_9 = 16; VAR_9 < 48; VAR_9++)",
"VAR_26[VAR_9 + 4] = 4 * VAR_25[(VAR_9 - 16) >> 1] +\n(VAR_1->ref_list[VAR_10][VAR_9].reference & 3);",
"}",
"if (VAR_0->avctx->debug & FF_DEBUG_PICT_INFO) {",
"av_log(VAR_0->avctx, AV_LOG_DEBUG,\n\"slice:%d %s mb:%d %c%s%s VAR_3:%u frame:%d poc:%d/%d ref:%d/%d qp:%d loop:%d:%d:%d weight:%d%s %s\\n\",\nVAR_1->slice_num,\n(VAR_0->VAR_18 == PICT_FRAME ? \"F\" : VAR_0->VAR_18 == PICT_TOP_FIELD ? \"T\" : \"B\"),\nVAR_4,\nav_get_picture_type_char(VAR_1->VAR_7),\nVAR_1->slice_type_fixed ? \" fix\" : \"\",\nVAR_0->nal_unit_type == NAL_IDR_SLICE ? \" IDR\" : \"\",\nVAR_5, VAR_0->VAR_16,\nVAR_0->cur_pic_ptr->field_poc[0],\nVAR_0->cur_pic_ptr->field_poc[1],\nVAR_1->ref_count[0], VAR_1->ref_count[1],\nVAR_1->qscale,\nVAR_1->deblocking_filter,\nVAR_1->slice_alpha_c0_offset, VAR_1->slice_beta_offset,\nVAR_1->pwt.use_weight,\nVAR_1->pwt.use_weight == 1 && VAR_1->pwt.use_weight_chroma ? \"c\" : \"\",\nVAR_1->VAR_7 == AV_PICTURE_TYPE_B ? (VAR_1->direct_spatial_mv_pred ? \"SPAT\" : \"TEMP\") : \"\");",
"}",
"return 0;",
"}"
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | [
[
1,
3
],
[
5
],
[
7
],
[
9
],
[
11
],
[
13
],
[
15
],
[
17
],
[
19
],
[
21
],
[
23
],
[
25
],
[
29
],
[
31
],
[
35
],
[
39
],
[
41
],
[
43
],
[
45
],
[
49
],
[
51
],
[
53
],
[
55,
57
],
[
59
],
[
61
],
[
63
],
[
65
],
[
69
],
[
71
],
[
73,
75,
77
],
[
79
],
[
81
],
[
83
],
[
85
],
[
87
],
[
89
],
[
91
],
[
95
],
[
97
],
[
99
],
[
103,
105
],
[
107
],
[
109
],
[
111
],
[
117,
119
],
[
123
],
[
125
],
[
127
],
[
129
],
[
131
],
[
133
],
[
135,
137,
139
],
[
141
],
[
143
],
[
145
],
[
147
],
[
149
],
[
151
],
[
153
],
[
155
],
[
159
],
[
161,
163,
165
],
[
167
],
[
169
],
[
173
],
[
175
],
[
179,
181,
183
],
[
187,
189,
191
],
[
193,
195,
197
],
[
199,
201
],
[
203
],
[
207,
209
],
[
213
],
[
217
],
[
219
],
[
223
],
[
225
],
[
227
],
[
229
],
[
233,
235,
237
],
[
241
],
[
243
],
[
245
],
[
247
],
[
251
],
[
255
],
[
259
],
[
261
],
[
265
],
[
267,
269
],
[
273
],
[
275,
277
],
[
279
],
[
281,
283
],
[
285
],
[
287
],
[
289
],
[
291
],
[
293
],
[
295
],
[
299
],
[
301
],
[
303
],
[
305,
307,
309,
311,
313,
315
],
[
317
],
[
319
],
[
323
],
[
327,
329
],
[
331
],
[
335,
337
],
[
341
],
[
343,
345
],
[
347
],
[
349
],
[
351
],
[
353
],
[
355
],
[
357,
359
],
[
361
],
[
363
],
[
367,
369
],
[
371
],
[
375
],
[
377,
379
],
[
381
],
[
383
],
[
385
],
[
389
],
[
391,
393
],
[
397
],
[
401
],
[
403
],
[
407
],
[
409
],
[
411
],
[
413
],
[
415
],
[
417
],
[
419
],
[
421
],
[
423
],
[
425
],
[
427
],
[
429
],
[
431
],
[
433
],
[
435
],
[
437
],
[
439
],
[
441
],
[
443
],
[
447
],
[
449,
451
],
[
453,
455,
457
],
[
459
],
[
461
],
[
463,
465,
467
],
[
469
],
[
471
],
[
473
],
[
479
],
[
481
],
[
483
],
[
487,
489
],
[
493
],
[
495
],
[
497,
499
],
[
503
],
[
505
],
[
507
],
[
521
],
[
523
],
[
525
],
[
527
],
[
533
],
[
539
],
[
541,
543
],
[
545
],
[
547
],
[
549
],
[
559
],
[
561,
563
],
[
565
],
[
567
],
[
571,
573,
575,
577
],
[
579,
581,
583
],
[
585
],
[
587
],
[
589
],
[
591
],
[
593,
595
],
[
597
],
[
599
],
[
601
],
[
603
],
[
605
],
[
607
],
[
609
],
[
613,
615
],
[
617
],
[
619,
621
],
[
623
],
[
625
],
[
627
],
[
629
],
[
631
],
[
635
],
[
637
],
[
639
],
[
641
],
[
643
],
[
645
],
[
647,
649
],
[
651
],
[
653,
655
],
[
671
],
[
673,
675,
677,
679
],
[
681,
683,
685,
687,
689,
691,
693
],
[
695
],
[
697
],
[
699
],
[
701
],
[
703
],
[
713
],
[
715
],
[
717
],
[
719
],
[
725
],
[
731
],
[
733
],
[
735
],
[
737
],
[
745
],
[
747
],
[
749
],
[
753
],
[
755
],
[
757
],
[
759
],
[
763
],
[
765
],
[
769
],
[
771
],
[
773
],
[
775
],
[
777
],
[
779
],
[
781
],
[
783
],
[
785
],
[
789
],
[
791,
793
],
[
795
],
[
797
],
[
799
],
[
801
],
[
803,
805
],
[
807,
809
],
[
811
],
[
815
],
[
817
],
[
819
],
[
821
],
[
823
],
[
825
],
[
827
],
[
831,
833
],
[
837
],
[
839
],
[
843,
845
],
[
849
],
[
851
],
[
853,
855
],
[
857
],
[
859
],
[
863
],
[
865
],
[
869,
871
],
[
875
],
[
877
],
[
881,
883
],
[
885
],
[
887
],
[
891,
893
],
[
897,
899
],
[
903,
905
],
[
909,
911,
913
],
[
915,
917
],
[
921
],
[
923
],
[
925
],
[
927
],
[
929
],
[
931
],
[
933
],
[
937,
939,
941,
943,
945
],
[
947,
949
],
[
951
],
[
953
],
[
955
],
[
957
],
[
959
],
[
961
],
[
963
],
[
965
],
[
979
],
[
981,
983,
985
],
[
987,
989
],
[
991
],
[
995
],
[
997
],
[
1001
],
[
1003
],
[
1005
],
[
1007
],
[
1009
],
[
1013,
1015
],
[
1017
],
[
1021
],
[
1023
],
[
1025
],
[
1027
],
[
1029
],
[
1031
],
[
1033
],
[
1035
],
[
1039
],
[
1041
],
[
1043
],
[
1045
],
[
1047
],
[
1049
],
[
1051
],
[
1053
],
[
1055
],
[
1059,
1061
],
[
1063,
1065,
1067
],
[
1071
],
[
1073
],
[
1075
],
[
1077
],
[
1079
],
[
1081
],
[
1083,
1085
],
[
1087
],
[
1089
],
[
1091
],
[
1093,
1095
],
[
1099
],
[
1101
],
[
1103
],
[
1105,
1107,
1109,
1111
],
[
1113,
1115,
1117
],
[
1119
],
[
1121
],
[
1123
],
[
1125
],
[
1129,
1131,
1133,
1135,
1137,
1139,
1141,
1143
],
[
1147
],
[
1149
],
[
1155
],
[
1157
],
[
1159
],
[
1161
],
[
1163,
1165
],
[
1167
],
[
1169
],
[
1171
],
[
1173,
1175
],
[
1177
],
[
1179
],
[
1181
],
[
1183
],
[
1185,
1187,
1189,
1191,
1193,
1195
],
[
1199
],
[
1201
],
[
1203,
1205
],
[
1207
],
[
1211
],
[
1213
],
[
1215
],
[
1217
],
[
1219
],
[
1221,
1223
],
[
1225
],
[
1227
],
[
1229
],
[
1231
],
[
1233
],
[
1235
],
[
1237
],
[
1239
],
[
1241
],
[
1243
],
[
1245
],
[
1247
],
[
1249
],
[
1251
],
[
1255,
1257
],
[
1259
],
[
1261
],
[
1263,
1265
],
[
1267
],
[
1269,
1271
],
[
1273
],
[
1277
],
[
1279,
1281,
1283,
1285,
1287,
1289,
1291,
1293,
1295,
1297,
1299,
1301,
1303,
1305,
1307,
1309,
1311,
1313
],
[
1315
],
[
1319
],
[
1321
]
] |
21,432 | void virtio_blk_handle_request(VirtIOBlockReq *req, MultiReqBuffer *mrb)
{
uint32_t type;
struct iovec *in_iov = req->elem.in_sg;
struct iovec *iov = req->elem.out_sg;
unsigned in_num = req->elem.in_num;
unsigned out_num = req->elem.out_num;
if (req->elem.out_num < 1 || req->elem.in_num < 1) {
error_report("virtio-blk missing headers");
exit(1);
}
if (unlikely(iov_to_buf(iov, out_num, 0, &req->out,
sizeof(req->out)) != sizeof(req->out))) {
error_report("virtio-blk request outhdr too short");
exit(1);
}
iov_discard_front(&iov, &out_num, sizeof(req->out));
if (in_num < 1 ||
in_iov[in_num - 1].iov_len < sizeof(struct virtio_blk_inhdr)) {
error_report("virtio-blk request inhdr too short");
exit(1);
}
/* We always touch the last byte, so just see how big in_iov is. */
req->in_len = iov_size(in_iov, in_num);
req->in = (void *)in_iov[in_num - 1].iov_base
+ in_iov[in_num - 1].iov_len
- sizeof(struct virtio_blk_inhdr);
iov_discard_back(in_iov, &in_num, sizeof(struct virtio_blk_inhdr));
type = virtio_ldl_p(VIRTIO_DEVICE(req->dev), &req->out.type);
/* VIRTIO_BLK_T_OUT defines the command direction. VIRTIO_BLK_T_BARRIER
* is an optional flag. Although a guest should not send this flag if
* not negotiated we ignored it in the past. So keep ignoring it. */
switch (type & ~(VIRTIO_BLK_T_OUT | VIRTIO_BLK_T_BARRIER)) {
case VIRTIO_BLK_T_IN:
{
bool is_write = type & VIRTIO_BLK_T_OUT;
req->sector_num = virtio_ldq_p(VIRTIO_DEVICE(req->dev),
&req->out.sector);
if (is_write) {
qemu_iovec_init_external(&req->qiov, iov, out_num);
trace_virtio_blk_handle_write(req, req->sector_num,
req->qiov.size / BDRV_SECTOR_SIZE);
} else {
qemu_iovec_init_external(&req->qiov, in_iov, in_num);
trace_virtio_blk_handle_read(req, req->sector_num,
req->qiov.size / BDRV_SECTOR_SIZE);
}
if (!virtio_blk_sect_range_ok(req->dev, req->sector_num,
req->qiov.size)) {
virtio_blk_req_complete(req, VIRTIO_BLK_S_IOERR);
virtio_blk_free_request(req);
return;
}
block_acct_start(blk_get_stats(req->dev->blk),
&req->acct, req->qiov.size,
is_write ? BLOCK_ACCT_WRITE : BLOCK_ACCT_READ);
/* merge would exceed maximum number of requests or IO direction
* changes */
if (mrb->num_reqs > 0 && (mrb->num_reqs == VIRTIO_BLK_MAX_MERGE_REQS ||
is_write != mrb->is_write ||
!req->dev->conf.request_merging)) {
virtio_blk_submit_multireq(req->dev->blk, mrb);
}
assert(mrb->num_reqs < VIRTIO_BLK_MAX_MERGE_REQS);
mrb->reqs[mrb->num_reqs++] = req;
mrb->is_write = is_write;
break;
}
case VIRTIO_BLK_T_FLUSH:
virtio_blk_handle_flush(req, mrb);
break;
case VIRTIO_BLK_T_SCSI_CMD:
virtio_blk_handle_scsi(req);
break;
case VIRTIO_BLK_T_GET_ID:
{
VirtIOBlock *s = req->dev;
/*
* NB: per existing s/n string convention the string is
* terminated by '\0' only when shorter than buffer.
*/
const char *serial = s->conf.serial ? s->conf.serial : "";
size_t size = MIN(strlen(serial) + 1,
MIN(iov_size(in_iov, in_num),
VIRTIO_BLK_ID_BYTES));
iov_from_buf(in_iov, in_num, 0, serial, size);
virtio_blk_req_complete(req, VIRTIO_BLK_S_OK);
virtio_blk_free_request(req);
break;
}
default:
virtio_blk_req_complete(req, VIRTIO_BLK_S_UNSUPP);
virtio_blk_free_request(req);
}
}
| false | qemu | 12048545019cd1d64c8147ea9277648e685fa489 | void virtio_blk_handle_request(VirtIOBlockReq *req, MultiReqBuffer *mrb)
{
uint32_t type;
struct iovec *in_iov = req->elem.in_sg;
struct iovec *iov = req->elem.out_sg;
unsigned in_num = req->elem.in_num;
unsigned out_num = req->elem.out_num;
if (req->elem.out_num < 1 || req->elem.in_num < 1) {
error_report("virtio-blk missing headers");
exit(1);
}
if (unlikely(iov_to_buf(iov, out_num, 0, &req->out,
sizeof(req->out)) != sizeof(req->out))) {
error_report("virtio-blk request outhdr too short");
exit(1);
}
iov_discard_front(&iov, &out_num, sizeof(req->out));
if (in_num < 1 ||
in_iov[in_num - 1].iov_len < sizeof(struct virtio_blk_inhdr)) {
error_report("virtio-blk request inhdr too short");
exit(1);
}
req->in_len = iov_size(in_iov, in_num);
req->in = (void *)in_iov[in_num - 1].iov_base
+ in_iov[in_num - 1].iov_len
- sizeof(struct virtio_blk_inhdr);
iov_discard_back(in_iov, &in_num, sizeof(struct virtio_blk_inhdr));
type = virtio_ldl_p(VIRTIO_DEVICE(req->dev), &req->out.type);
switch (type & ~(VIRTIO_BLK_T_OUT | VIRTIO_BLK_T_BARRIER)) {
case VIRTIO_BLK_T_IN:
{
bool is_write = type & VIRTIO_BLK_T_OUT;
req->sector_num = virtio_ldq_p(VIRTIO_DEVICE(req->dev),
&req->out.sector);
if (is_write) {
qemu_iovec_init_external(&req->qiov, iov, out_num);
trace_virtio_blk_handle_write(req, req->sector_num,
req->qiov.size / BDRV_SECTOR_SIZE);
} else {
qemu_iovec_init_external(&req->qiov, in_iov, in_num);
trace_virtio_blk_handle_read(req, req->sector_num,
req->qiov.size / BDRV_SECTOR_SIZE);
}
if (!virtio_blk_sect_range_ok(req->dev, req->sector_num,
req->qiov.size)) {
virtio_blk_req_complete(req, VIRTIO_BLK_S_IOERR);
virtio_blk_free_request(req);
return;
}
block_acct_start(blk_get_stats(req->dev->blk),
&req->acct, req->qiov.size,
is_write ? BLOCK_ACCT_WRITE : BLOCK_ACCT_READ);
if (mrb->num_reqs > 0 && (mrb->num_reqs == VIRTIO_BLK_MAX_MERGE_REQS ||
is_write != mrb->is_write ||
!req->dev->conf.request_merging)) {
virtio_blk_submit_multireq(req->dev->blk, mrb);
}
assert(mrb->num_reqs < VIRTIO_BLK_MAX_MERGE_REQS);
mrb->reqs[mrb->num_reqs++] = req;
mrb->is_write = is_write;
break;
}
case VIRTIO_BLK_T_FLUSH:
virtio_blk_handle_flush(req, mrb);
break;
case VIRTIO_BLK_T_SCSI_CMD:
virtio_blk_handle_scsi(req);
break;
case VIRTIO_BLK_T_GET_ID:
{
VirtIOBlock *s = req->dev;
const char *serial = s->conf.serial ? s->conf.serial : "";
size_t size = MIN(strlen(serial) + 1,
MIN(iov_size(in_iov, in_num),
VIRTIO_BLK_ID_BYTES));
iov_from_buf(in_iov, in_num, 0, serial, size);
virtio_blk_req_complete(req, VIRTIO_BLK_S_OK);
virtio_blk_free_request(req);
break;
}
default:
virtio_blk_req_complete(req, VIRTIO_BLK_S_UNSUPP);
virtio_blk_free_request(req);
}
}
| {
"code": [],
"line_no": []
} | void FUNC_0(VirtIOBlockReq *VAR_0, MultiReqBuffer *VAR_1)
{
uint32_t type;
struct iovec *VAR_2 = VAR_0->elem.in_sg;
struct iovec *VAR_3 = VAR_0->elem.out_sg;
unsigned VAR_4 = VAR_0->elem.VAR_4;
unsigned VAR_5 = VAR_0->elem.VAR_5;
if (VAR_0->elem.VAR_5 < 1 || VAR_0->elem.VAR_4 < 1) {
error_report("virtio-blk missing headers");
exit(1);
}
if (unlikely(iov_to_buf(VAR_3, VAR_5, 0, &VAR_0->out,
sizeof(VAR_0->out)) != sizeof(VAR_0->out))) {
error_report("virtio-blk request outhdr too short");
exit(1);
}
iov_discard_front(&VAR_3, &VAR_5, sizeof(VAR_0->out));
if (VAR_4 < 1 ||
VAR_2[VAR_4 - 1].iov_len < sizeof(struct virtio_blk_inhdr)) {
error_report("virtio-blk request inhdr too short");
exit(1);
}
VAR_0->in_len = iov_size(VAR_2, VAR_4);
VAR_0->in = (void *)VAR_2[VAR_4 - 1].iov_base
+ VAR_2[VAR_4 - 1].iov_len
- sizeof(struct virtio_blk_inhdr);
iov_discard_back(VAR_2, &VAR_4, sizeof(struct virtio_blk_inhdr));
type = virtio_ldl_p(VIRTIO_DEVICE(VAR_0->dev), &VAR_0->out.type);
switch (type & ~(VIRTIO_BLK_T_OUT | VIRTIO_BLK_T_BARRIER)) {
case VIRTIO_BLK_T_IN:
{
bool is_write = type & VIRTIO_BLK_T_OUT;
VAR_0->sector_num = virtio_ldq_p(VIRTIO_DEVICE(VAR_0->dev),
&VAR_0->out.sector);
if (is_write) {
qemu_iovec_init_external(&VAR_0->qiov, VAR_3, VAR_5);
trace_virtio_blk_handle_write(VAR_0, VAR_0->sector_num,
VAR_0->qiov.size / BDRV_SECTOR_SIZE);
} else {
qemu_iovec_init_external(&VAR_0->qiov, VAR_2, VAR_4);
trace_virtio_blk_handle_read(VAR_0, VAR_0->sector_num,
VAR_0->qiov.size / BDRV_SECTOR_SIZE);
}
if (!virtio_blk_sect_range_ok(VAR_0->dev, VAR_0->sector_num,
VAR_0->qiov.size)) {
virtio_blk_req_complete(VAR_0, VIRTIO_BLK_S_IOERR);
virtio_blk_free_request(VAR_0);
return;
}
block_acct_start(blk_get_stats(VAR_0->dev->blk),
&VAR_0->acct, VAR_0->qiov.size,
is_write ? BLOCK_ACCT_WRITE : BLOCK_ACCT_READ);
if (VAR_1->num_reqs > 0 && (VAR_1->num_reqs == VIRTIO_BLK_MAX_MERGE_REQS ||
is_write != VAR_1->is_write ||
!VAR_0->dev->conf.request_merging)) {
virtio_blk_submit_multireq(VAR_0->dev->blk, VAR_1);
}
assert(VAR_1->num_reqs < VIRTIO_BLK_MAX_MERGE_REQS);
VAR_1->reqs[VAR_1->num_reqs++] = VAR_0;
VAR_1->is_write = is_write;
break;
}
case VIRTIO_BLK_T_FLUSH:
virtio_blk_handle_flush(VAR_0, VAR_1);
break;
case VIRTIO_BLK_T_SCSI_CMD:
virtio_blk_handle_scsi(VAR_0);
break;
case VIRTIO_BLK_T_GET_ID:
{
VirtIOBlock *s = VAR_0->dev;
const char *VAR_6 = s->conf.VAR_6 ? s->conf.VAR_6 : "";
size_t size = MIN(strlen(VAR_6) + 1,
MIN(iov_size(VAR_2, VAR_4),
VIRTIO_BLK_ID_BYTES));
iov_from_buf(VAR_2, VAR_4, 0, VAR_6, size);
virtio_blk_req_complete(VAR_0, VIRTIO_BLK_S_OK);
virtio_blk_free_request(VAR_0);
break;
}
default:
virtio_blk_req_complete(VAR_0, VIRTIO_BLK_S_UNSUPP);
virtio_blk_free_request(VAR_0);
}
}
| [
"void FUNC_0(VirtIOBlockReq *VAR_0, MultiReqBuffer *VAR_1)\n{",
"uint32_t type;",
"struct iovec *VAR_2 = VAR_0->elem.in_sg;",
"struct iovec *VAR_3 = VAR_0->elem.out_sg;",
"unsigned VAR_4 = VAR_0->elem.VAR_4;",
"unsigned VAR_5 = VAR_0->elem.VAR_5;",
"if (VAR_0->elem.VAR_5 < 1 || VAR_0->elem.VAR_4 < 1) {",
"error_report(\"virtio-blk missing headers\");",
"exit(1);",
"}",
"if (unlikely(iov_to_buf(VAR_3, VAR_5, 0, &VAR_0->out,\nsizeof(VAR_0->out)) != sizeof(VAR_0->out))) {",
"error_report(\"virtio-blk request outhdr too short\");",
"exit(1);",
"}",
"iov_discard_front(&VAR_3, &VAR_5, sizeof(VAR_0->out));",
"if (VAR_4 < 1 ||\nVAR_2[VAR_4 - 1].iov_len < sizeof(struct virtio_blk_inhdr)) {",
"error_report(\"virtio-blk request inhdr too short\");",
"exit(1);",
"}",
"VAR_0->in_len = iov_size(VAR_2, VAR_4);",
"VAR_0->in = (void *)VAR_2[VAR_4 - 1].iov_base\n+ VAR_2[VAR_4 - 1].iov_len\n- sizeof(struct virtio_blk_inhdr);",
"iov_discard_back(VAR_2, &VAR_4, sizeof(struct virtio_blk_inhdr));",
"type = virtio_ldl_p(VIRTIO_DEVICE(VAR_0->dev), &VAR_0->out.type);",
"switch (type & ~(VIRTIO_BLK_T_OUT | VIRTIO_BLK_T_BARRIER)) {",
"case VIRTIO_BLK_T_IN:\n{",
"bool is_write = type & VIRTIO_BLK_T_OUT;",
"VAR_0->sector_num = virtio_ldq_p(VIRTIO_DEVICE(VAR_0->dev),\n&VAR_0->out.sector);",
"if (is_write) {",
"qemu_iovec_init_external(&VAR_0->qiov, VAR_3, VAR_5);",
"trace_virtio_blk_handle_write(VAR_0, VAR_0->sector_num,\nVAR_0->qiov.size / BDRV_SECTOR_SIZE);",
"} else {",
"qemu_iovec_init_external(&VAR_0->qiov, VAR_2, VAR_4);",
"trace_virtio_blk_handle_read(VAR_0, VAR_0->sector_num,\nVAR_0->qiov.size / BDRV_SECTOR_SIZE);",
"}",
"if (!virtio_blk_sect_range_ok(VAR_0->dev, VAR_0->sector_num,\nVAR_0->qiov.size)) {",
"virtio_blk_req_complete(VAR_0, VIRTIO_BLK_S_IOERR);",
"virtio_blk_free_request(VAR_0);",
"return;",
"}",
"block_acct_start(blk_get_stats(VAR_0->dev->blk),\n&VAR_0->acct, VAR_0->qiov.size,\nis_write ? BLOCK_ACCT_WRITE : BLOCK_ACCT_READ);",
"if (VAR_1->num_reqs > 0 && (VAR_1->num_reqs == VIRTIO_BLK_MAX_MERGE_REQS ||\nis_write != VAR_1->is_write ||\n!VAR_0->dev->conf.request_merging)) {",
"virtio_blk_submit_multireq(VAR_0->dev->blk, VAR_1);",
"}",
"assert(VAR_1->num_reqs < VIRTIO_BLK_MAX_MERGE_REQS);",
"VAR_1->reqs[VAR_1->num_reqs++] = VAR_0;",
"VAR_1->is_write = is_write;",
"break;",
"}",
"case VIRTIO_BLK_T_FLUSH:\nvirtio_blk_handle_flush(VAR_0, VAR_1);",
"break;",
"case VIRTIO_BLK_T_SCSI_CMD:\nvirtio_blk_handle_scsi(VAR_0);",
"break;",
"case VIRTIO_BLK_T_GET_ID:\n{",
"VirtIOBlock *s = VAR_0->dev;",
"const char *VAR_6 = s->conf.VAR_6 ? s->conf.VAR_6 : \"\";",
"size_t size = MIN(strlen(VAR_6) + 1,\nMIN(iov_size(VAR_2, VAR_4),\nVIRTIO_BLK_ID_BYTES));",
"iov_from_buf(VAR_2, VAR_4, 0, VAR_6, size);",
"virtio_blk_req_complete(VAR_0, VIRTIO_BLK_S_OK);",
"virtio_blk_free_request(VAR_0);",
"break;",
"}",
"default:\nvirtio_blk_req_complete(VAR_0, VIRTIO_BLK_S_UNSUPP);",
"virtio_blk_free_request(VAR_0);",
"}",
"}"
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | [
[
1,
3
],
[
5
],
[
7
],
[
9
],
[
11
],
[
13
],
[
17
],
[
19
],
[
21
],
[
23
],
[
27,
29
],
[
31
],
[
33
],
[
35
],
[
39
],
[
43,
45
],
[
47
],
[
49
],
[
51
],
[
57
],
[
59,
61,
63
],
[
65
],
[
69
],
[
79
],
[
81,
83
],
[
85
],
[
87,
89
],
[
93
],
[
95
],
[
97,
99
],
[
101
],
[
103
],
[
105,
107
],
[
109
],
[
113,
115
],
[
117
],
[
119
],
[
121
],
[
123
],
[
127,
129,
131
],
[
139,
141,
143
],
[
145
],
[
147
],
[
151
],
[
153
],
[
155
],
[
157
],
[
159
],
[
161,
163
],
[
165
],
[
167,
169
],
[
171
],
[
173,
175
],
[
177
],
[
189
],
[
191,
193,
195
],
[
197
],
[
199
],
[
201
],
[
203
],
[
205
],
[
207,
209
],
[
211
],
[
213
],
[
215
]
] |
21,433 | static void net_vhost_user_event(void *opaque, int event)
{
VhostUserState *s = opaque;
switch (event) {
case CHR_EVENT_OPENED:
vhost_user_start(s);
net_vhost_link_down(s, false);
error_report("chardev \"%s\" went up", s->chr->label);
break;
case CHR_EVENT_CLOSED:
net_vhost_link_down(s, true);
vhost_user_stop(s);
error_report("chardev \"%s\" went down", s->chr->label);
break;
}
}
| false | qemu | b931bfbf042983f311b3b09894d8030b2755a638 | static void net_vhost_user_event(void *opaque, int event)
{
VhostUserState *s = opaque;
switch (event) {
case CHR_EVENT_OPENED:
vhost_user_start(s);
net_vhost_link_down(s, false);
error_report("chardev \"%s\" went up", s->chr->label);
break;
case CHR_EVENT_CLOSED:
net_vhost_link_down(s, true);
vhost_user_stop(s);
error_report("chardev \"%s\" went down", s->chr->label);
break;
}
}
| {
"code": [],
"line_no": []
} | static void FUNC_0(void *VAR_0, int VAR_1)
{
VhostUserState *s = VAR_0;
switch (VAR_1) {
case CHR_EVENT_OPENED:
vhost_user_start(s);
net_vhost_link_down(s, false);
error_report("chardev \"%s\" went up", s->chr->label);
break;
case CHR_EVENT_CLOSED:
net_vhost_link_down(s, true);
vhost_user_stop(s);
error_report("chardev \"%s\" went down", s->chr->label);
break;
}
}
| [
"static void FUNC_0(void *VAR_0, int VAR_1)\n{",
"VhostUserState *s = VAR_0;",
"switch (VAR_1) {",
"case CHR_EVENT_OPENED:\nvhost_user_start(s);",
"net_vhost_link_down(s, false);",
"error_report(\"chardev \\\"%s\\\" went up\", s->chr->label);",
"break;",
"case CHR_EVENT_CLOSED:\nnet_vhost_link_down(s, true);",
"vhost_user_stop(s);",
"error_report(\"chardev \\\"%s\\\" went down\", s->chr->label);",
"break;",
"}",
"}"
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | [
[
1,
3
],
[
5
],
[
9
],
[
11,
13
],
[
15
],
[
17
],
[
19
],
[
21,
23
],
[
25
],
[
27
],
[
29
],
[
31
],
[
33
]
] |
21,437 | static uint32_t virtio_blk_get_features(VirtIODevice *vdev)
{
VirtIOBlock *s = to_virtio_blk(vdev);
uint32_t features = 0;
features |= (1 << VIRTIO_BLK_F_SEG_MAX);
features |= (1 << VIRTIO_BLK_F_GEOMETRY);
if (bdrv_enable_write_cache(s->bs))
features |= (1 << VIRTIO_BLK_F_WCACHE);
#ifdef __linux__
features |= (1 << VIRTIO_BLK_F_SCSI);
#endif
if (strcmp(s->serial_str, "0"))
features |= 1 << VIRTIO_BLK_F_IDENTIFY;
if (bdrv_is_read_only(s->bs))
features |= 1 << VIRTIO_BLK_F_RO;
return features;
}
| false | qemu | 8172539d21a03e982aa7f139ddc1607dc1422045 | static uint32_t virtio_blk_get_features(VirtIODevice *vdev)
{
VirtIOBlock *s = to_virtio_blk(vdev);
uint32_t features = 0;
features |= (1 << VIRTIO_BLK_F_SEG_MAX);
features |= (1 << VIRTIO_BLK_F_GEOMETRY);
if (bdrv_enable_write_cache(s->bs))
features |= (1 << VIRTIO_BLK_F_WCACHE);
#ifdef __linux__
features |= (1 << VIRTIO_BLK_F_SCSI);
#endif
if (strcmp(s->serial_str, "0"))
features |= 1 << VIRTIO_BLK_F_IDENTIFY;
if (bdrv_is_read_only(s->bs))
features |= 1 << VIRTIO_BLK_F_RO;
return features;
}
| {
"code": [],
"line_no": []
} | static uint32_t FUNC_0(VirtIODevice *vdev)
{
VirtIOBlock *s = to_virtio_blk(vdev);
uint32_t features = 0;
features |= (1 << VIRTIO_BLK_F_SEG_MAX);
features |= (1 << VIRTIO_BLK_F_GEOMETRY);
if (bdrv_enable_write_cache(s->bs))
features |= (1 << VIRTIO_BLK_F_WCACHE);
#ifdef __linux__
features |= (1 << VIRTIO_BLK_F_SCSI);
#endif
if (strcmp(s->serial_str, "0"))
features |= 1 << VIRTIO_BLK_F_IDENTIFY;
if (bdrv_is_read_only(s->bs))
features |= 1 << VIRTIO_BLK_F_RO;
return features;
}
| [
"static uint32_t FUNC_0(VirtIODevice *vdev)\n{",
"VirtIOBlock *s = to_virtio_blk(vdev);",
"uint32_t features = 0;",
"features |= (1 << VIRTIO_BLK_F_SEG_MAX);",
"features |= (1 << VIRTIO_BLK_F_GEOMETRY);",
"if (bdrv_enable_write_cache(s->bs))\nfeatures |= (1 << VIRTIO_BLK_F_WCACHE);",
"#ifdef __linux__\nfeatures |= (1 << VIRTIO_BLK_F_SCSI);",
"#endif\nif (strcmp(s->serial_str, \"0\"))\nfeatures |= 1 << VIRTIO_BLK_F_IDENTIFY;",
"if (bdrv_is_read_only(s->bs))\nfeatures |= 1 << VIRTIO_BLK_F_RO;",
"return features;",
"}"
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | [
[
1,
3
],
[
5
],
[
7
],
[
11
],
[
13
],
[
17,
19
],
[
21,
23
],
[
25,
27,
29
],
[
33,
35
],
[
39
],
[
41
]
] |
21,438 | static void vmsvga_bios_write(void *opaque, uint32_t address, uint32_t data)
{
printf("%s: what are we supposed to do with (%08x)?\n",
__FUNCTION__, data);
}
| false | qemu | 0d7937974cd0504f30ad483c3368b21da426ddf9 | static void vmsvga_bios_write(void *opaque, uint32_t address, uint32_t data)
{
printf("%s: what are we supposed to do with (%08x)?\n",
__FUNCTION__, data);
}
| {
"code": [],
"line_no": []
} | static void FUNC_0(void *VAR_0, uint32_t VAR_1, uint32_t VAR_2)
{
printf("%s: what are we supposed to do with (%08x)?\n",
__FUNCTION__, VAR_2);
}
| [
"static void FUNC_0(void *VAR_0, uint32_t VAR_1, uint32_t VAR_2)\n{",
"printf(\"%s: what are we supposed to do with (%08x)?\\n\",\n__FUNCTION__, VAR_2);",
"}"
] | [
0,
0,
0
] | [
[
1,
3
],
[
5,
7
],
[
9
]
] |
21,439 | static void platform_ioport_map(PCIDevice *pci_dev, int region_num, pcibus_t addr, pcibus_t size, int type)
{
PCIXenPlatformState *d = DO_UPCAST(PCIXenPlatformState, pci_dev, pci_dev);
register_ioport_write(addr, size, 1, xen_platform_ioport_writeb, d);
register_ioport_read(addr, size, 1, xen_platform_ioport_readb, d);
}
| false | qemu | de00982e9e14e2d6ba3d148f02c5a1e94deaa985 | static void platform_ioport_map(PCIDevice *pci_dev, int region_num, pcibus_t addr, pcibus_t size, int type)
{
PCIXenPlatformState *d = DO_UPCAST(PCIXenPlatformState, pci_dev, pci_dev);
register_ioport_write(addr, size, 1, xen_platform_ioport_writeb, d);
register_ioport_read(addr, size, 1, xen_platform_ioport_readb, d);
}
| {
"code": [],
"line_no": []
} | static void FUNC_0(PCIDevice *VAR_0, int VAR_1, pcibus_t VAR_2, pcibus_t VAR_3, int VAR_4)
{
PCIXenPlatformState *d = DO_UPCAST(PCIXenPlatformState, VAR_0, VAR_0);
register_ioport_write(VAR_2, VAR_3, 1, xen_platform_ioport_writeb, d);
register_ioport_read(VAR_2, VAR_3, 1, xen_platform_ioport_readb, d);
}
| [
"static void FUNC_0(PCIDevice *VAR_0, int VAR_1, pcibus_t VAR_2, pcibus_t VAR_3, int VAR_4)\n{",
"PCIXenPlatformState *d = DO_UPCAST(PCIXenPlatformState, VAR_0, VAR_0);",
"register_ioport_write(VAR_2, VAR_3, 1, xen_platform_ioport_writeb, d);",
"register_ioport_read(VAR_2, VAR_3, 1, xen_platform_ioport_readb, d);",
"}"
] | [
0,
0,
0,
0,
0
] | [
[
1,
3
],
[
5
],
[
9
],
[
11
],
[
13
]
] |
21,441 | static void qemu_chr_fire_open_event(void *opaque)
{
CharDriverState *s = opaque;
qemu_chr_be_event(s, CHR_EVENT_OPENED);
qemu_free_timer(s->open_timer);
s->open_timer = NULL;
}
| false | qemu | 9f939df955a4152aad69a19a77e0898631bb2c18 | static void qemu_chr_fire_open_event(void *opaque)
{
CharDriverState *s = opaque;
qemu_chr_be_event(s, CHR_EVENT_OPENED);
qemu_free_timer(s->open_timer);
s->open_timer = NULL;
}
| {
"code": [],
"line_no": []
} | static void FUNC_0(void *VAR_0)
{
CharDriverState *s = VAR_0;
qemu_chr_be_event(s, CHR_EVENT_OPENED);
qemu_free_timer(s->open_timer);
s->open_timer = NULL;
}
| [
"static void FUNC_0(void *VAR_0)\n{",
"CharDriverState *s = VAR_0;",
"qemu_chr_be_event(s, CHR_EVENT_OPENED);",
"qemu_free_timer(s->open_timer);",
"s->open_timer = NULL;",
"}"
] | [
0,
0,
0,
0,
0,
0
] | [
[
1,
3
],
[
5
],
[
7
],
[
9
],
[
11
],
[
13
]
] |
21,442 | static int sd_snapshot_goto(BlockDriverState *bs, const char *snapshot_id)
{
BDRVSheepdogState *s = bs->opaque;
BDRVSheepdogState *old_s;
char vdi[SD_MAX_VDI_LEN], tag[SD_MAX_VDI_TAG_LEN];
char *buf = NULL;
uint32_t vid;
uint32_t snapid = 0;
int ret = 0, fd;
old_s = g_malloc(sizeof(BDRVSheepdogState));
memcpy(old_s, s, sizeof(BDRVSheepdogState));
pstrcpy(vdi, sizeof(vdi), s->name);
snapid = strtoul(snapshot_id, NULL, 10);
if (snapid) {
tag[0] = 0;
} else {
pstrcpy(tag, sizeof(tag), s->name);
}
ret = find_vdi_name(s, vdi, snapid, tag, &vid, 1);
if (ret) {
error_report("Failed to find_vdi_name");
goto out;
}
fd = connect_to_sdog(s->addr, s->port);
if (fd < 0) {
error_report("failed to connect");
ret = fd;
goto out;
}
buf = g_malloc(SD_INODE_SIZE);
ret = read_object(fd, buf, vid_to_vdi_oid(vid), s->inode.nr_copies,
SD_INODE_SIZE, 0, s->cache_enabled);
closesocket(fd);
if (ret) {
goto out;
}
memcpy(&s->inode, buf, sizeof(s->inode));
if (!s->inode.vm_state_size) {
error_report("Invalid snapshot");
ret = -ENOENT;
goto out;
}
s->is_snapshot = true;
g_free(buf);
g_free(old_s);
return 0;
out:
/* recover bdrv_sd_state */
memcpy(s, old_s, sizeof(BDRVSheepdogState));
g_free(buf);
g_free(old_s);
error_report("failed to open. recover old bdrv_sd_state.");
return ret;
}
| false | qemu | 0e7106d8b5f7ef4f9df10baf1dfb3db482bcd046 | static int sd_snapshot_goto(BlockDriverState *bs, const char *snapshot_id)
{
BDRVSheepdogState *s = bs->opaque;
BDRVSheepdogState *old_s;
char vdi[SD_MAX_VDI_LEN], tag[SD_MAX_VDI_TAG_LEN];
char *buf = NULL;
uint32_t vid;
uint32_t snapid = 0;
int ret = 0, fd;
old_s = g_malloc(sizeof(BDRVSheepdogState));
memcpy(old_s, s, sizeof(BDRVSheepdogState));
pstrcpy(vdi, sizeof(vdi), s->name);
snapid = strtoul(snapshot_id, NULL, 10);
if (snapid) {
tag[0] = 0;
} else {
pstrcpy(tag, sizeof(tag), s->name);
}
ret = find_vdi_name(s, vdi, snapid, tag, &vid, 1);
if (ret) {
error_report("Failed to find_vdi_name");
goto out;
}
fd = connect_to_sdog(s->addr, s->port);
if (fd < 0) {
error_report("failed to connect");
ret = fd;
goto out;
}
buf = g_malloc(SD_INODE_SIZE);
ret = read_object(fd, buf, vid_to_vdi_oid(vid), s->inode.nr_copies,
SD_INODE_SIZE, 0, s->cache_enabled);
closesocket(fd);
if (ret) {
goto out;
}
memcpy(&s->inode, buf, sizeof(s->inode));
if (!s->inode.vm_state_size) {
error_report("Invalid snapshot");
ret = -ENOENT;
goto out;
}
s->is_snapshot = true;
g_free(buf);
g_free(old_s);
return 0;
out:
memcpy(s, old_s, sizeof(BDRVSheepdogState));
g_free(buf);
g_free(old_s);
error_report("failed to open. recover old bdrv_sd_state.");
return ret;
}
| {
"code": [],
"line_no": []
} | static int FUNC_0(BlockDriverState *VAR_0, const char *VAR_1)
{
BDRVSheepdogState *s = VAR_0->opaque;
BDRVSheepdogState *old_s;
char VAR_2[SD_MAX_VDI_LEN], tag[SD_MAX_VDI_TAG_LEN];
char *VAR_3 = NULL;
uint32_t vid;
uint32_t snapid = 0;
int VAR_4 = 0, VAR_5;
old_s = g_malloc(sizeof(BDRVSheepdogState));
memcpy(old_s, s, sizeof(BDRVSheepdogState));
pstrcpy(VAR_2, sizeof(VAR_2), s->name);
snapid = strtoul(VAR_1, NULL, 10);
if (snapid) {
tag[0] = 0;
} else {
pstrcpy(tag, sizeof(tag), s->name);
}
VAR_4 = find_vdi_name(s, VAR_2, snapid, tag, &vid, 1);
if (VAR_4) {
error_report("Failed to find_vdi_name");
goto out;
}
VAR_5 = connect_to_sdog(s->addr, s->port);
if (VAR_5 < 0) {
error_report("failed to connect");
VAR_4 = VAR_5;
goto out;
}
VAR_3 = g_malloc(SD_INODE_SIZE);
VAR_4 = read_object(VAR_5, VAR_3, vid_to_vdi_oid(vid), s->inode.nr_copies,
SD_INODE_SIZE, 0, s->cache_enabled);
closesocket(VAR_5);
if (VAR_4) {
goto out;
}
memcpy(&s->inode, VAR_3, sizeof(s->inode));
if (!s->inode.vm_state_size) {
error_report("Invalid snapshot");
VAR_4 = -ENOENT;
goto out;
}
s->is_snapshot = true;
g_free(VAR_3);
g_free(old_s);
return 0;
out:
memcpy(s, old_s, sizeof(BDRVSheepdogState));
g_free(VAR_3);
g_free(old_s);
error_report("failed to open. recover old bdrv_sd_state.");
return VAR_4;
}
| [
"static int FUNC_0(BlockDriverState *VAR_0, const char *VAR_1)\n{",
"BDRVSheepdogState *s = VAR_0->opaque;",
"BDRVSheepdogState *old_s;",
"char VAR_2[SD_MAX_VDI_LEN], tag[SD_MAX_VDI_TAG_LEN];",
"char *VAR_3 = NULL;",
"uint32_t vid;",
"uint32_t snapid = 0;",
"int VAR_4 = 0, VAR_5;",
"old_s = g_malloc(sizeof(BDRVSheepdogState));",
"memcpy(old_s, s, sizeof(BDRVSheepdogState));",
"pstrcpy(VAR_2, sizeof(VAR_2), s->name);",
"snapid = strtoul(VAR_1, NULL, 10);",
"if (snapid) {",
"tag[0] = 0;",
"} else {",
"pstrcpy(tag, sizeof(tag), s->name);",
"}",
"VAR_4 = find_vdi_name(s, VAR_2, snapid, tag, &vid, 1);",
"if (VAR_4) {",
"error_report(\"Failed to find_vdi_name\");",
"goto out;",
"}",
"VAR_5 = connect_to_sdog(s->addr, s->port);",
"if (VAR_5 < 0) {",
"error_report(\"failed to connect\");",
"VAR_4 = VAR_5;",
"goto out;",
"}",
"VAR_3 = g_malloc(SD_INODE_SIZE);",
"VAR_4 = read_object(VAR_5, VAR_3, vid_to_vdi_oid(vid), s->inode.nr_copies,\nSD_INODE_SIZE, 0, s->cache_enabled);",
"closesocket(VAR_5);",
"if (VAR_4) {",
"goto out;",
"}",
"memcpy(&s->inode, VAR_3, sizeof(s->inode));",
"if (!s->inode.vm_state_size) {",
"error_report(\"Invalid snapshot\");",
"VAR_4 = -ENOENT;",
"goto out;",
"}",
"s->is_snapshot = true;",
"g_free(VAR_3);",
"g_free(old_s);",
"return 0;",
"out:\nmemcpy(s, old_s, sizeof(BDRVSheepdogState));",
"g_free(VAR_3);",
"g_free(old_s);",
"error_report(\"failed to open. recover old bdrv_sd_state.\");",
"return VAR_4;",
"}"
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | [
[
1,
3
],
[
5
],
[
7
],
[
9
],
[
11
],
[
13
],
[
15
],
[
17
],
[
21
],
[
25
],
[
29
],
[
33
],
[
35
],
[
37
],
[
39
],
[
41
],
[
43
],
[
47
],
[
49
],
[
51
],
[
53
],
[
55
],
[
59
],
[
61
],
[
63
],
[
65
],
[
67
],
[
69
],
[
73
],
[
75,
77
],
[
81
],
[
85
],
[
87
],
[
89
],
[
93
],
[
97
],
[
99
],
[
101
],
[
103
],
[
105
],
[
109
],
[
113
],
[
115
],
[
119
],
[
121,
125
],
[
127
],
[
129
],
[
133
],
[
137
],
[
139
]
] |
21,443 | static void ehci_advance_state(EHCIState *ehci,
int async)
{
EHCIQueue *q = NULL;
int again;
int iter = 0;
do {
if (ehci_get_state(ehci, async) == EST_FETCHQH) {
iter++;
/* if we are roaming a lot of QH without executing a qTD
* something is wrong with the linked list. TO-DO: why is
* this hack needed?
*/
assert(iter < MAX_ITERATIONS);
#if 0
if (iter > MAX_ITERATIONS) {
DPRINTF("\n*** advance_state: bailing on MAX ITERATIONS***\n");
ehci_set_state(ehci, async, EST_ACTIVE);
break;
}
#endif
}
switch(ehci_get_state(ehci, async)) {
case EST_WAITLISTHEAD:
again = ehci_state_waitlisthead(ehci, async);
break;
case EST_FETCHENTRY:
again = ehci_state_fetchentry(ehci, async);
break;
case EST_FETCHQH:
q = ehci_state_fetchqh(ehci, async);
again = q ? 1 : 0;
break;
case EST_FETCHITD:
again = ehci_state_fetchitd(ehci, async);
break;
case EST_FETCHSITD:
again = ehci_state_fetchsitd(ehci, async);
break;
case EST_ADVANCEQUEUE:
again = ehci_state_advqueue(q, async);
break;
case EST_FETCHQTD:
again = ehci_state_fetchqtd(q, async);
break;
case EST_HORIZONTALQH:
again = ehci_state_horizqh(q, async);
break;
case EST_EXECUTE:
iter = 0;
again = ehci_state_execute(q, async);
break;
case EST_EXECUTING:
assert(q != NULL);
again = ehci_state_executing(q, async);
break;
case EST_WRITEBACK:
assert(q != NULL);
again = ehci_state_writeback(q, async);
break;
default:
fprintf(stderr, "Bad state!\n");
again = -1;
assert(0);
break;
}
if (again < 0) {
fprintf(stderr, "processing error - resetting ehci HC\n");
ehci_reset(ehci);
again = 0;
}
}
while (again);
ehci_commit_interrupt(ehci);
}
| false | qemu | e59a8cf1eb2196cdaded214ccd1b819c8faad238 | static void ehci_advance_state(EHCIState *ehci,
int async)
{
EHCIQueue *q = NULL;
int again;
int iter = 0;
do {
if (ehci_get_state(ehci, async) == EST_FETCHQH) {
iter++;
assert(iter < MAX_ITERATIONS);
#if 0
if (iter > MAX_ITERATIONS) {
DPRINTF("\n*** advance_state: bailing on MAX ITERATIONS***\n");
ehci_set_state(ehci, async, EST_ACTIVE);
break;
}
#endif
}
switch(ehci_get_state(ehci, async)) {
case EST_WAITLISTHEAD:
again = ehci_state_waitlisthead(ehci, async);
break;
case EST_FETCHENTRY:
again = ehci_state_fetchentry(ehci, async);
break;
case EST_FETCHQH:
q = ehci_state_fetchqh(ehci, async);
again = q ? 1 : 0;
break;
case EST_FETCHITD:
again = ehci_state_fetchitd(ehci, async);
break;
case EST_FETCHSITD:
again = ehci_state_fetchsitd(ehci, async);
break;
case EST_ADVANCEQUEUE:
again = ehci_state_advqueue(q, async);
break;
case EST_FETCHQTD:
again = ehci_state_fetchqtd(q, async);
break;
case EST_HORIZONTALQH:
again = ehci_state_horizqh(q, async);
break;
case EST_EXECUTE:
iter = 0;
again = ehci_state_execute(q, async);
break;
case EST_EXECUTING:
assert(q != NULL);
again = ehci_state_executing(q, async);
break;
case EST_WRITEBACK:
assert(q != NULL);
again = ehci_state_writeback(q, async);
break;
default:
fprintf(stderr, "Bad state!\n");
again = -1;
assert(0);
break;
}
if (again < 0) {
fprintf(stderr, "processing error - resetting ehci HC\n");
ehci_reset(ehci);
again = 0;
}
}
while (again);
ehci_commit_interrupt(ehci);
}
| {
"code": [],
"line_no": []
} | static void FUNC_0(EHCIState *VAR_0,
int VAR_1)
{
EHCIQueue *q = NULL;
int VAR_2;
int VAR_3 = 0;
do {
if (ehci_get_state(VAR_0, VAR_1) == EST_FETCHQH) {
VAR_3++;
assert(VAR_3 < MAX_ITERATIONS);
#if 0
if (VAR_3 > MAX_ITERATIONS) {
DPRINTF("\n*** advance_state: bailing on MAX ITERATIONS***\n");
ehci_set_state(VAR_0, VAR_1, EST_ACTIVE);
break;
}
#endif
}
switch(ehci_get_state(VAR_0, VAR_1)) {
case EST_WAITLISTHEAD:
VAR_2 = ehci_state_waitlisthead(VAR_0, VAR_1);
break;
case EST_FETCHENTRY:
VAR_2 = ehci_state_fetchentry(VAR_0, VAR_1);
break;
case EST_FETCHQH:
q = ehci_state_fetchqh(VAR_0, VAR_1);
VAR_2 = q ? 1 : 0;
break;
case EST_FETCHITD:
VAR_2 = ehci_state_fetchitd(VAR_0, VAR_1);
break;
case EST_FETCHSITD:
VAR_2 = ehci_state_fetchsitd(VAR_0, VAR_1);
break;
case EST_ADVANCEQUEUE:
VAR_2 = ehci_state_advqueue(q, VAR_1);
break;
case EST_FETCHQTD:
VAR_2 = ehci_state_fetchqtd(q, VAR_1);
break;
case EST_HORIZONTALQH:
VAR_2 = ehci_state_horizqh(q, VAR_1);
break;
case EST_EXECUTE:
VAR_3 = 0;
VAR_2 = ehci_state_execute(q, VAR_1);
break;
case EST_EXECUTING:
assert(q != NULL);
VAR_2 = ehci_state_executing(q, VAR_1);
break;
case EST_WRITEBACK:
assert(q != NULL);
VAR_2 = ehci_state_writeback(q, VAR_1);
break;
default:
fprintf(stderr, "Bad state!\n");
VAR_2 = -1;
assert(0);
break;
}
if (VAR_2 < 0) {
fprintf(stderr, "processing error - resetting VAR_0 HC\n");
ehci_reset(VAR_0);
VAR_2 = 0;
}
}
while (VAR_2);
ehci_commit_interrupt(VAR_0);
}
| [
"static void FUNC_0(EHCIState *VAR_0,\nint VAR_1)\n{",
"EHCIQueue *q = NULL;",
"int VAR_2;",
"int VAR_3 = 0;",
"do {",
"if (ehci_get_state(VAR_0, VAR_1) == EST_FETCHQH) {",
"VAR_3++;",
"assert(VAR_3 < MAX_ITERATIONS);",
"#if 0\nif (VAR_3 > MAX_ITERATIONS) {",
"DPRINTF(\"\\n*** advance_state: bailing on MAX ITERATIONS***\\n\");",
"ehci_set_state(VAR_0, VAR_1, EST_ACTIVE);",
"break;",
"}",
"#endif\n}",
"switch(ehci_get_state(VAR_0, VAR_1)) {",
"case EST_WAITLISTHEAD:\nVAR_2 = ehci_state_waitlisthead(VAR_0, VAR_1);",
"break;",
"case EST_FETCHENTRY:\nVAR_2 = ehci_state_fetchentry(VAR_0, VAR_1);",
"break;",
"case EST_FETCHQH:\nq = ehci_state_fetchqh(VAR_0, VAR_1);",
"VAR_2 = q ? 1 : 0;",
"break;",
"case EST_FETCHITD:\nVAR_2 = ehci_state_fetchitd(VAR_0, VAR_1);",
"break;",
"case EST_FETCHSITD:\nVAR_2 = ehci_state_fetchsitd(VAR_0, VAR_1);",
"break;",
"case EST_ADVANCEQUEUE:\nVAR_2 = ehci_state_advqueue(q, VAR_1);",
"break;",
"case EST_FETCHQTD:\nVAR_2 = ehci_state_fetchqtd(q, VAR_1);",
"break;",
"case EST_HORIZONTALQH:\nVAR_2 = ehci_state_horizqh(q, VAR_1);",
"break;",
"case EST_EXECUTE:\nVAR_3 = 0;",
"VAR_2 = ehci_state_execute(q, VAR_1);",
"break;",
"case EST_EXECUTING:\nassert(q != NULL);",
"VAR_2 = ehci_state_executing(q, VAR_1);",
"break;",
"case EST_WRITEBACK:\nassert(q != NULL);",
"VAR_2 = ehci_state_writeback(q, VAR_1);",
"break;",
"default:\nfprintf(stderr, \"Bad state!\\n\");",
"VAR_2 = -1;",
"assert(0);",
"break;",
"}",
"if (VAR_2 < 0) {",
"fprintf(stderr, \"processing error - resetting VAR_0 HC\\n\");",
"ehci_reset(VAR_0);",
"VAR_2 = 0;",
"}",
"}",
"while (VAR_2);",
"ehci_commit_interrupt(VAR_0);",
"}"
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | [
[
1,
3,
5
],
[
7
],
[
9
],
[
11
],
[
15
],
[
17
],
[
19
],
[
29
],
[
31,
33
],
[
35
],
[
37
],
[
39
],
[
41
],
[
43,
45
],
[
47
],
[
49,
51
],
[
53
],
[
57,
59
],
[
61
],
[
65,
67
],
[
69
],
[
71
],
[
75,
77
],
[
79
],
[
83,
85
],
[
87
],
[
91,
93
],
[
95
],
[
99,
101
],
[
103
],
[
107,
109
],
[
111
],
[
115,
117
],
[
119
],
[
121
],
[
125,
127
],
[
129
],
[
131
],
[
135,
137
],
[
139
],
[
141
],
[
145,
147
],
[
149
],
[
151
],
[
153
],
[
155
],
[
159
],
[
161
],
[
163
],
[
165
],
[
167
],
[
169
],
[
171
],
[
175
],
[
177
]
] |
21,444 | static av_always_inline void mpeg_motion_lowres(MpegEncContext *s,
uint8_t *dest_y,
uint8_t *dest_cb,
uint8_t *dest_cr,
int field_based,
int bottom_field,
int field_select,
uint8_t **ref_picture,
h264_chroma_mc_func *pix_op,
int motion_x, int motion_y,
int h, int mb_y)
{
uint8_t *ptr_y, *ptr_cb, *ptr_cr;
int mx, my, src_x, src_y, uvsrc_x, uvsrc_y, uvlinesize, linesize, sx, sy,
uvsx, uvsy;
const int lowres = s->avctx->lowres;
const int op_index = FFMIN(lowres-1+s->chroma_x_shift, 2);
const int block_s = 8>>lowres;
const int s_mask = (2 << lowres) - 1;
const int h_edge_pos = s->h_edge_pos >> lowres;
const int v_edge_pos = s->v_edge_pos >> lowres;
linesize = s->current_picture.f.linesize[0] << field_based;
uvlinesize = s->current_picture.f.linesize[1] << field_based;
// FIXME obviously not perfect but qpel will not work in lowres anyway
if (s->quarter_sample) {
motion_x /= 2;
motion_y /= 2;
}
if(field_based){
motion_y += (bottom_field - field_select)*((1 << lowres)-1);
}
sx = motion_x & s_mask;
sy = motion_y & s_mask;
src_x = s->mb_x * 2 * block_s + (motion_x >> lowres + 1);
src_y = (mb_y * 2 * block_s >> field_based) + (motion_y >> lowres + 1);
if (s->out_format == FMT_H263) {
uvsx = ((motion_x >> 1) & s_mask) | (sx & 1);
uvsy = ((motion_y >> 1) & s_mask) | (sy & 1);
uvsrc_x = src_x >> 1;
uvsrc_y = src_y >> 1;
} else if (s->out_format == FMT_H261) {
// even chroma mv's are full pel in H261
mx = motion_x / 4;
my = motion_y / 4;
uvsx = (2 * mx) & s_mask;
uvsy = (2 * my) & s_mask;
uvsrc_x = s->mb_x * block_s + (mx >> lowres);
uvsrc_y = mb_y * block_s + (my >> lowres);
} else {
if(s->chroma_y_shift){
mx = motion_x / 2;
my = motion_y / 2;
uvsx = mx & s_mask;
uvsy = my & s_mask;
uvsrc_x = s->mb_x * block_s + (mx >> lowres + 1);
uvsrc_y = (mb_y * block_s >> field_based) + (my >> lowres + 1);
} else {
if(s->chroma_x_shift){
//Chroma422
mx = motion_x / 2;
uvsx = mx & s_mask;
uvsy = motion_y & s_mask;
uvsrc_y = src_y;
uvsrc_x = s->mb_x*block_s + (mx >> (lowres+1));
} else {
//Chroma444
uvsx = motion_x & s_mask;
uvsy = motion_y & s_mask;
uvsrc_x = src_x;
uvsrc_y = src_y;
}
}
}
ptr_y = ref_picture[0] + src_y * linesize + src_x;
ptr_cb = ref_picture[1] + uvsrc_y * uvlinesize + uvsrc_x;
ptr_cr = ref_picture[2] + uvsrc_y * uvlinesize + uvsrc_x;
if ((unsigned) src_x > FFMAX( h_edge_pos - (!!sx) - 2 * block_s, 0) || uvsrc_y<0 ||
(unsigned) src_y > FFMAX((v_edge_pos >> field_based) - (!!sy) - h, 0)) {
s->vdsp.emulated_edge_mc(s->edge_emu_buffer, ptr_y,
linesize >> field_based, 17, 17 + field_based,
src_x, src_y << field_based, h_edge_pos,
v_edge_pos);
ptr_y = s->edge_emu_buffer;
if (!CONFIG_GRAY || !(s->flags & CODEC_FLAG_GRAY)) {
uint8_t *uvbuf = s->edge_emu_buffer + 18 * s->linesize;
s->vdsp.emulated_edge_mc(uvbuf , ptr_cb, uvlinesize >> field_based, 9,
9 + field_based,
uvsrc_x, uvsrc_y << field_based,
h_edge_pos >> 1, v_edge_pos >> 1);
s->vdsp.emulated_edge_mc(uvbuf + 16, ptr_cr, uvlinesize >> field_based, 9,
9 + field_based,
uvsrc_x, uvsrc_y << field_based,
h_edge_pos >> 1, v_edge_pos >> 1);
ptr_cb = uvbuf;
ptr_cr = uvbuf + 16;
}
}
// FIXME use this for field pix too instead of the obnoxious hack which changes picture.f.data
if (bottom_field) {
dest_y += s->linesize;
dest_cb += s->uvlinesize;
dest_cr += s->uvlinesize;
}
if (field_select) {
ptr_y += s->linesize;
ptr_cb += s->uvlinesize;
ptr_cr += s->uvlinesize;
}
sx = (sx << 2) >> lowres;
sy = (sy << 2) >> lowres;
pix_op[lowres - 1](dest_y, ptr_y, linesize, h, sx, sy);
if (!CONFIG_GRAY || !(s->flags & CODEC_FLAG_GRAY)) {
int hc = s->chroma_y_shift ? (h+1-bottom_field)>>1 : h;
uvsx = (uvsx << 2) >> lowres;
uvsy = (uvsy << 2) >> lowres;
if (hc) {
pix_op[op_index](dest_cb, ptr_cb, uvlinesize, hc, uvsx, uvsy);
pix_op[op_index](dest_cr, ptr_cr, uvlinesize, hc, uvsx, uvsy);
}
}
// FIXME h261 lowres loop filter
}
| false | FFmpeg | 0abe923d20db6280dfdfa8a4ed07710ad8376e97 | static av_always_inline void mpeg_motion_lowres(MpegEncContext *s,
uint8_t *dest_y,
uint8_t *dest_cb,
uint8_t *dest_cr,
int field_based,
int bottom_field,
int field_select,
uint8_t **ref_picture,
h264_chroma_mc_func *pix_op,
int motion_x, int motion_y,
int h, int mb_y)
{
uint8_t *ptr_y, *ptr_cb, *ptr_cr;
int mx, my, src_x, src_y, uvsrc_x, uvsrc_y, uvlinesize, linesize, sx, sy,
uvsx, uvsy;
const int lowres = s->avctx->lowres;
const int op_index = FFMIN(lowres-1+s->chroma_x_shift, 2);
const int block_s = 8>>lowres;
const int s_mask = (2 << lowres) - 1;
const int h_edge_pos = s->h_edge_pos >> lowres;
const int v_edge_pos = s->v_edge_pos >> lowres;
linesize = s->current_picture.f.linesize[0] << field_based;
uvlinesize = s->current_picture.f.linesize[1] << field_based;
if (s->quarter_sample) {
motion_x /= 2;
motion_y /= 2;
}
if(field_based){
motion_y += (bottom_field - field_select)*((1 << lowres)-1);
}
sx = motion_x & s_mask;
sy = motion_y & s_mask;
src_x = s->mb_x * 2 * block_s + (motion_x >> lowres + 1);
src_y = (mb_y * 2 * block_s >> field_based) + (motion_y >> lowres + 1);
if (s->out_format == FMT_H263) {
uvsx = ((motion_x >> 1) & s_mask) | (sx & 1);
uvsy = ((motion_y >> 1) & s_mask) | (sy & 1);
uvsrc_x = src_x >> 1;
uvsrc_y = src_y >> 1;
} else if (s->out_format == FMT_H261) {
mx = motion_x / 4;
my = motion_y / 4;
uvsx = (2 * mx) & s_mask;
uvsy = (2 * my) & s_mask;
uvsrc_x = s->mb_x * block_s + (mx >> lowres);
uvsrc_y = mb_y * block_s + (my >> lowres);
} else {
if(s->chroma_y_shift){
mx = motion_x / 2;
my = motion_y / 2;
uvsx = mx & s_mask;
uvsy = my & s_mask;
uvsrc_x = s->mb_x * block_s + (mx >> lowres + 1);
uvsrc_y = (mb_y * block_s >> field_based) + (my >> lowres + 1);
} else {
if(s->chroma_x_shift){
mx = motion_x / 2;
uvsx = mx & s_mask;
uvsy = motion_y & s_mask;
uvsrc_y = src_y;
uvsrc_x = s->mb_x*block_s + (mx >> (lowres+1));
} else {
uvsx = motion_x & s_mask;
uvsy = motion_y & s_mask;
uvsrc_x = src_x;
uvsrc_y = src_y;
}
}
}
ptr_y = ref_picture[0] + src_y * linesize + src_x;
ptr_cb = ref_picture[1] + uvsrc_y * uvlinesize + uvsrc_x;
ptr_cr = ref_picture[2] + uvsrc_y * uvlinesize + uvsrc_x;
if ((unsigned) src_x > FFMAX( h_edge_pos - (!!sx) - 2 * block_s, 0) || uvsrc_y<0 ||
(unsigned) src_y > FFMAX((v_edge_pos >> field_based) - (!!sy) - h, 0)) {
s->vdsp.emulated_edge_mc(s->edge_emu_buffer, ptr_y,
linesize >> field_based, 17, 17 + field_based,
src_x, src_y << field_based, h_edge_pos,
v_edge_pos);
ptr_y = s->edge_emu_buffer;
if (!CONFIG_GRAY || !(s->flags & CODEC_FLAG_GRAY)) {
uint8_t *uvbuf = s->edge_emu_buffer + 18 * s->linesize;
s->vdsp.emulated_edge_mc(uvbuf , ptr_cb, uvlinesize >> field_based, 9,
9 + field_based,
uvsrc_x, uvsrc_y << field_based,
h_edge_pos >> 1, v_edge_pos >> 1);
s->vdsp.emulated_edge_mc(uvbuf + 16, ptr_cr, uvlinesize >> field_based, 9,
9 + field_based,
uvsrc_x, uvsrc_y << field_based,
h_edge_pos >> 1, v_edge_pos >> 1);
ptr_cb = uvbuf;
ptr_cr = uvbuf + 16;
}
}
if (bottom_field) {
dest_y += s->linesize;
dest_cb += s->uvlinesize;
dest_cr += s->uvlinesize;
}
if (field_select) {
ptr_y += s->linesize;
ptr_cb += s->uvlinesize;
ptr_cr += s->uvlinesize;
}
sx = (sx << 2) >> lowres;
sy = (sy << 2) >> lowres;
pix_op[lowres - 1](dest_y, ptr_y, linesize, h, sx, sy);
if (!CONFIG_GRAY || !(s->flags & CODEC_FLAG_GRAY)) {
int hc = s->chroma_y_shift ? (h+1-bottom_field)>>1 : h;
uvsx = (uvsx << 2) >> lowres;
uvsy = (uvsy << 2) >> lowres;
if (hc) {
pix_op[op_index](dest_cb, ptr_cb, uvlinesize, hc, uvsx, uvsy);
pix_op[op_index](dest_cr, ptr_cr, uvlinesize, hc, uvsx, uvsy);
}
}
}
| {
"code": [],
"line_no": []
} | static av_always_inline void FUNC_0(MpegEncContext *s,
uint8_t *dest_y,
uint8_t *dest_cb,
uint8_t *dest_cr,
int field_based,
int bottom_field,
int field_select,
uint8_t **ref_picture,
h264_chroma_mc_func *pix_op,
int motion_x, int motion_y,
int h, int mb_y)
{
uint8_t *ptr_y, *ptr_cb, *ptr_cr;
int VAR_0, VAR_1, VAR_2, VAR_3, VAR_4, VAR_5, VAR_6, VAR_7, VAR_8, VAR_9,
VAR_10, VAR_11;
const int VAR_12 = s->avctx->VAR_12;
const int VAR_13 = FFMIN(VAR_12-1+s->chroma_x_shift, 2);
const int VAR_14 = 8>>VAR_12;
const int VAR_15 = (2 << VAR_12) - 1;
const int VAR_16 = s->VAR_16 >> VAR_12;
const int VAR_17 = s->VAR_17 >> VAR_12;
VAR_7 = s->current_picture.f.VAR_7[0] << field_based;
VAR_6 = s->current_picture.f.VAR_7[1] << field_based;
if (s->quarter_sample) {
motion_x /= 2;
motion_y /= 2;
}
if(field_based){
motion_y += (bottom_field - field_select)*((1 << VAR_12)-1);
}
VAR_8 = motion_x & VAR_15;
VAR_9 = motion_y & VAR_15;
VAR_2 = s->mb_x * 2 * VAR_14 + (motion_x >> VAR_12 + 1);
VAR_3 = (mb_y * 2 * VAR_14 >> field_based) + (motion_y >> VAR_12 + 1);
if (s->out_format == FMT_H263) {
VAR_10 = ((motion_x >> 1) & VAR_15) | (VAR_8 & 1);
VAR_11 = ((motion_y >> 1) & VAR_15) | (VAR_9 & 1);
VAR_4 = VAR_2 >> 1;
VAR_5 = VAR_3 >> 1;
} else if (s->out_format == FMT_H261) {
VAR_0 = motion_x / 4;
VAR_1 = motion_y / 4;
VAR_10 = (2 * VAR_0) & VAR_15;
VAR_11 = (2 * VAR_1) & VAR_15;
VAR_4 = s->mb_x * VAR_14 + (VAR_0 >> VAR_12);
VAR_5 = mb_y * VAR_14 + (VAR_1 >> VAR_12);
} else {
if(s->chroma_y_shift){
VAR_0 = motion_x / 2;
VAR_1 = motion_y / 2;
VAR_10 = VAR_0 & VAR_15;
VAR_11 = VAR_1 & VAR_15;
VAR_4 = s->mb_x * VAR_14 + (VAR_0 >> VAR_12 + 1);
VAR_5 = (mb_y * VAR_14 >> field_based) + (VAR_1 >> VAR_12 + 1);
} else {
if(s->chroma_x_shift){
VAR_0 = motion_x / 2;
VAR_10 = VAR_0 & VAR_15;
VAR_11 = motion_y & VAR_15;
VAR_5 = VAR_3;
VAR_4 = s->mb_x*VAR_14 + (VAR_0 >> (VAR_12+1));
} else {
VAR_10 = motion_x & VAR_15;
VAR_11 = motion_y & VAR_15;
VAR_4 = VAR_2;
VAR_5 = VAR_3;
}
}
}
ptr_y = ref_picture[0] + VAR_3 * VAR_7 + VAR_2;
ptr_cb = ref_picture[1] + VAR_5 * VAR_6 + VAR_4;
ptr_cr = ref_picture[2] + VAR_5 * VAR_6 + VAR_4;
if ((unsigned) VAR_2 > FFMAX( VAR_16 - (!!VAR_8) - 2 * VAR_14, 0) || VAR_5<0 ||
(unsigned) VAR_3 > FFMAX((VAR_17 >> field_based) - (!!VAR_9) - h, 0)) {
s->vdsp.emulated_edge_mc(s->edge_emu_buffer, ptr_y,
VAR_7 >> field_based, 17, 17 + field_based,
VAR_2, VAR_3 << field_based, VAR_16,
VAR_17);
ptr_y = s->edge_emu_buffer;
if (!CONFIG_GRAY || !(s->flags & CODEC_FLAG_GRAY)) {
uint8_t *uvbuf = s->edge_emu_buffer + 18 * s->VAR_7;
s->vdsp.emulated_edge_mc(uvbuf , ptr_cb, VAR_6 >> field_based, 9,
9 + field_based,
VAR_4, VAR_5 << field_based,
VAR_16 >> 1, VAR_17 >> 1);
s->vdsp.emulated_edge_mc(uvbuf + 16, ptr_cr, VAR_6 >> field_based, 9,
9 + field_based,
VAR_4, VAR_5 << field_based,
VAR_16 >> 1, VAR_17 >> 1);
ptr_cb = uvbuf;
ptr_cr = uvbuf + 16;
}
}
if (bottom_field) {
dest_y += s->VAR_7;
dest_cb += s->VAR_6;
dest_cr += s->VAR_6;
}
if (field_select) {
ptr_y += s->VAR_7;
ptr_cb += s->VAR_6;
ptr_cr += s->VAR_6;
}
VAR_8 = (VAR_8 << 2) >> VAR_12;
VAR_9 = (VAR_9 << 2) >> VAR_12;
pix_op[VAR_12 - 1](dest_y, ptr_y, VAR_7, h, VAR_8, VAR_9);
if (!CONFIG_GRAY || !(s->flags & CODEC_FLAG_GRAY)) {
int VAR_18 = s->chroma_y_shift ? (h+1-bottom_field)>>1 : h;
VAR_10 = (VAR_10 << 2) >> VAR_12;
VAR_11 = (VAR_11 << 2) >> VAR_12;
if (VAR_18) {
pix_op[VAR_13](dest_cb, ptr_cb, VAR_6, VAR_18, VAR_10, VAR_11);
pix_op[VAR_13](dest_cr, ptr_cr, VAR_6, VAR_18, VAR_10, VAR_11);
}
}
}
| [
"static av_always_inline void FUNC_0(MpegEncContext *s,\nuint8_t *dest_y,\nuint8_t *dest_cb,\nuint8_t *dest_cr,\nint field_based,\nint bottom_field,\nint field_select,\nuint8_t **ref_picture,\nh264_chroma_mc_func *pix_op,\nint motion_x, int motion_y,\nint h, int mb_y)\n{",
"uint8_t *ptr_y, *ptr_cb, *ptr_cr;",
"int VAR_0, VAR_1, VAR_2, VAR_3, VAR_4, VAR_5, VAR_6, VAR_7, VAR_8, VAR_9,\nVAR_10, VAR_11;",
"const int VAR_12 = s->avctx->VAR_12;",
"const int VAR_13 = FFMIN(VAR_12-1+s->chroma_x_shift, 2);",
"const int VAR_14 = 8>>VAR_12;",
"const int VAR_15 = (2 << VAR_12) - 1;",
"const int VAR_16 = s->VAR_16 >> VAR_12;",
"const int VAR_17 = s->VAR_17 >> VAR_12;",
"VAR_7 = s->current_picture.f.VAR_7[0] << field_based;",
"VAR_6 = s->current_picture.f.VAR_7[1] << field_based;",
"if (s->quarter_sample) {",
"motion_x /= 2;",
"motion_y /= 2;",
"}",
"if(field_based){",
"motion_y += (bottom_field - field_select)*((1 << VAR_12)-1);",
"}",
"VAR_8 = motion_x & VAR_15;",
"VAR_9 = motion_y & VAR_15;",
"VAR_2 = s->mb_x * 2 * VAR_14 + (motion_x >> VAR_12 + 1);",
"VAR_3 = (mb_y * 2 * VAR_14 >> field_based) + (motion_y >> VAR_12 + 1);",
"if (s->out_format == FMT_H263) {",
"VAR_10 = ((motion_x >> 1) & VAR_15) | (VAR_8 & 1);",
"VAR_11 = ((motion_y >> 1) & VAR_15) | (VAR_9 & 1);",
"VAR_4 = VAR_2 >> 1;",
"VAR_5 = VAR_3 >> 1;",
"} else if (s->out_format == FMT_H261) {",
"VAR_0 = motion_x / 4;",
"VAR_1 = motion_y / 4;",
"VAR_10 = (2 * VAR_0) & VAR_15;",
"VAR_11 = (2 * VAR_1) & VAR_15;",
"VAR_4 = s->mb_x * VAR_14 + (VAR_0 >> VAR_12);",
"VAR_5 = mb_y * VAR_14 + (VAR_1 >> VAR_12);",
"} else {",
"if(s->chroma_y_shift){",
"VAR_0 = motion_x / 2;",
"VAR_1 = motion_y / 2;",
"VAR_10 = VAR_0 & VAR_15;",
"VAR_11 = VAR_1 & VAR_15;",
"VAR_4 = s->mb_x * VAR_14 + (VAR_0 >> VAR_12 + 1);",
"VAR_5 = (mb_y * VAR_14 >> field_based) + (VAR_1 >> VAR_12 + 1);",
"} else {",
"if(s->chroma_x_shift){",
"VAR_0 = motion_x / 2;",
"VAR_10 = VAR_0 & VAR_15;",
"VAR_11 = motion_y & VAR_15;",
"VAR_5 = VAR_3;",
"VAR_4 = s->mb_x*VAR_14 + (VAR_0 >> (VAR_12+1));",
"} else {",
"VAR_10 = motion_x & VAR_15;",
"VAR_11 = motion_y & VAR_15;",
"VAR_4 = VAR_2;",
"VAR_5 = VAR_3;",
"}",
"}",
"}",
"ptr_y = ref_picture[0] + VAR_3 * VAR_7 + VAR_2;",
"ptr_cb = ref_picture[1] + VAR_5 * VAR_6 + VAR_4;",
"ptr_cr = ref_picture[2] + VAR_5 * VAR_6 + VAR_4;",
"if ((unsigned) VAR_2 > FFMAX( VAR_16 - (!!VAR_8) - 2 * VAR_14, 0) || VAR_5<0 ||\n(unsigned) VAR_3 > FFMAX((VAR_17 >> field_based) - (!!VAR_9) - h, 0)) {",
"s->vdsp.emulated_edge_mc(s->edge_emu_buffer, ptr_y,\nVAR_7 >> field_based, 17, 17 + field_based,\nVAR_2, VAR_3 << field_based, VAR_16,\nVAR_17);",
"ptr_y = s->edge_emu_buffer;",
"if (!CONFIG_GRAY || !(s->flags & CODEC_FLAG_GRAY)) {",
"uint8_t *uvbuf = s->edge_emu_buffer + 18 * s->VAR_7;",
"s->vdsp.emulated_edge_mc(uvbuf , ptr_cb, VAR_6 >> field_based, 9,\n9 + field_based,\nVAR_4, VAR_5 << field_based,\nVAR_16 >> 1, VAR_17 >> 1);",
"s->vdsp.emulated_edge_mc(uvbuf + 16, ptr_cr, VAR_6 >> field_based, 9,\n9 + field_based,\nVAR_4, VAR_5 << field_based,\nVAR_16 >> 1, VAR_17 >> 1);",
"ptr_cb = uvbuf;",
"ptr_cr = uvbuf + 16;",
"}",
"}",
"if (bottom_field) {",
"dest_y += s->VAR_7;",
"dest_cb += s->VAR_6;",
"dest_cr += s->VAR_6;",
"}",
"if (field_select) {",
"ptr_y += s->VAR_7;",
"ptr_cb += s->VAR_6;",
"ptr_cr += s->VAR_6;",
"}",
"VAR_8 = (VAR_8 << 2) >> VAR_12;",
"VAR_9 = (VAR_9 << 2) >> VAR_12;",
"pix_op[VAR_12 - 1](dest_y, ptr_y, VAR_7, h, VAR_8, VAR_9);",
"if (!CONFIG_GRAY || !(s->flags & CODEC_FLAG_GRAY)) {",
"int VAR_18 = s->chroma_y_shift ? (h+1-bottom_field)>>1 : h;",
"VAR_10 = (VAR_10 << 2) >> VAR_12;",
"VAR_11 = (VAR_11 << 2) >> VAR_12;",
"if (VAR_18) {",
"pix_op[VAR_13](dest_cb, ptr_cb, VAR_6, VAR_18, VAR_10, VAR_11);",
"pix_op[VAR_13](dest_cr, ptr_cr, VAR_6, VAR_18, VAR_10, VAR_11);",
"}",
"}",
"}"
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | [
[
1,
3,
5,
7,
9,
11,
13,
15,
17,
19,
21,
23
],
[
25
],
[
27,
29
],
[
31
],
[
33
],
[
35
],
[
37
],
[
39
],
[
41
],
[
43
],
[
45
],
[
51
],
[
53
],
[
55
],
[
57
],
[
61
],
[
63
],
[
65
],
[
69
],
[
71
],
[
73
],
[
75
],
[
79
],
[
81
],
[
83
],
[
85
],
[
87
],
[
89
],
[
93
],
[
95
],
[
97
],
[
99
],
[
101
],
[
103
],
[
105
],
[
107
],
[
109
],
[
111
],
[
113
],
[
115
],
[
117
],
[
119
],
[
121
],
[
123
],
[
127
],
[
129
],
[
131
],
[
133
],
[
135
],
[
137
],
[
141
],
[
143
],
[
145
],
[
147
],
[
149
],
[
151
],
[
153
],
[
157
],
[
159
],
[
161
],
[
165,
167
],
[
169,
171,
173,
175
],
[
177
],
[
179
],
[
181
],
[
183,
185,
187,
189
],
[
191,
193,
195,
197
],
[
199
],
[
201
],
[
203
],
[
205
],
[
211
],
[
213
],
[
215
],
[
217
],
[
219
],
[
223
],
[
225
],
[
227
],
[
229
],
[
231
],
[
235
],
[
237
],
[
239
],
[
243
],
[
245
],
[
247
],
[
249
],
[
251
],
[
253
],
[
255
],
[
257
],
[
259
],
[
263
]
] |
21,445 | static bool run_poll_handlers_once(AioContext *ctx)
{
bool progress = false;
AioHandler *node;
QLIST_FOREACH_RCU(node, &ctx->aio_handlers, node) {
if (!node->deleted && node->io_poll &&
aio_node_check(ctx, node->is_external) &&
node->io_poll(node->opaque)) {
progress = true;
}
/* Caller handles freeing deleted nodes. Don't do it here. */
}
return progress;
}
| false | qemu | c2b38b277a7882a592f4f2ec955084b2b756daaa | static bool run_poll_handlers_once(AioContext *ctx)
{
bool progress = false;
AioHandler *node;
QLIST_FOREACH_RCU(node, &ctx->aio_handlers, node) {
if (!node->deleted && node->io_poll &&
aio_node_check(ctx, node->is_external) &&
node->io_poll(node->opaque)) {
progress = true;
}
}
return progress;
}
| {
"code": [],
"line_no": []
} | static bool FUNC_0(AioContext *ctx)
{
bool progress = false;
AioHandler *node;
QLIST_FOREACH_RCU(node, &ctx->aio_handlers, node) {
if (!node->deleted && node->io_poll &&
aio_node_check(ctx, node->is_external) &&
node->io_poll(node->opaque)) {
progress = true;
}
}
return progress;
}
| [
"static bool FUNC_0(AioContext *ctx)\n{",
"bool progress = false;",
"AioHandler *node;",
"QLIST_FOREACH_RCU(node, &ctx->aio_handlers, node) {",
"if (!node->deleted && node->io_poll &&\naio_node_check(ctx, node->is_external) &&\nnode->io_poll(node->opaque)) {",
"progress = true;",
"}",
"}",
"return progress;",
"}"
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | [
[
1,
3
],
[
5
],
[
7
],
[
11
],
[
13,
15,
17
],
[
19
],
[
21
],
[
27
],
[
31
],
[
33
]
] |
21,446 | print_insn_ppi (int field_b, struct disassemble_info *info)
{
static const char *sx_tab[] = { "x0", "x1", "a0", "a1" };
static const char *sy_tab[] = { "y0", "y1", "m0", "m1" };
fprintf_ftype fprintf_fn = info->fprintf_func;
void *stream = info->stream;
unsigned int nib1, nib2, nib3;
unsigned int altnib1, nib4;
const char *dc = NULL;
const sh_opcode_info *op;
if ((field_b & 0xe800) == 0)
{
fprintf_fn (stream, "psh%c\t#%d,",
field_b & 0x1000 ? 'a' : 'l',
(field_b >> 4) & 127);
print_dsp_reg (field_b & 0xf, fprintf_fn, stream);
return;
}
if ((field_b & 0xc000) == 0x4000 && (field_b & 0x3000) != 0x1000)
{
static const char *du_tab[] = { "x0", "y0", "a0", "a1" };
static const char *se_tab[] = { "x0", "x1", "y0", "a1" };
static const char *sf_tab[] = { "y0", "y1", "x0", "a1" };
static const char *sg_tab[] = { "m0", "m1", "a0", "a1" };
if (field_b & 0x2000)
{
fprintf_fn (stream, "p%s %s,%s,%s\t",
(field_b & 0x1000) ? "add" : "sub",
sx_tab[(field_b >> 6) & 3],
sy_tab[(field_b >> 4) & 3],
du_tab[(field_b >> 0) & 3]);
}
else if ((field_b & 0xf0) == 0x10
&& info->mach != bfd_mach_sh_dsp
&& info->mach != bfd_mach_sh3_dsp)
{
fprintf_fn (stream, "pclr %s \t", du_tab[(field_b >> 0) & 3]);
}
else if ((field_b & 0xf3) != 0)
{
fprintf_fn (stream, ".word 0x%x\t", field_b);
}
fprintf_fn (stream, "pmuls%c%s,%s,%s",
field_b & 0x2000 ? ' ' : '\t',
se_tab[(field_b >> 10) & 3],
sf_tab[(field_b >> 8) & 3],
sg_tab[(field_b >> 2) & 3]);
return;
}
nib1 = PPIC;
nib2 = field_b >> 12 & 0xf;
nib3 = field_b >> 8 & 0xf;
nib4 = field_b >> 4 & 0xf;
switch (nib3 & 0x3)
{
case 0:
dc = "";
nib1 = PPI3;
break;
case 1:
dc = "";
break;
case 2:
dc = "dct ";
nib3 -= 1;
break;
case 3:
dc = "dcf ";
nib3 -= 2;
break;
}
if (nib1 == PPI3)
altnib1 = PPI3NC;
else
altnib1 = nib1;
for (op = sh_table; op->name; op++)
{
if ((op->nibbles[1] == nib1 || op->nibbles[1] == altnib1)
&& op->nibbles[2] == nib2
&& op->nibbles[3] == nib3)
{
int n;
switch (op->nibbles[4])
{
case HEX_0:
break;
case HEX_XX00:
if ((nib4 & 3) != 0)
continue;
break;
case HEX_1:
if ((nib4 & 3) != 1)
continue;
break;
case HEX_00YY:
if ((nib4 & 0xc) != 0)
continue;
break;
case HEX_4:
if ((nib4 & 0xc) != 4)
continue;
break;
default:
abort ();
}
fprintf_fn (stream, "%s%s\t", dc, op->name);
for (n = 0; n < 3 && op->arg[n] != A_END; n++)
{
if (n && op->arg[1] != A_END)
fprintf_fn (stream, ",");
switch (op->arg[n])
{
case DSP_REG_N:
print_dsp_reg (field_b & 0xf, fprintf_fn, stream);
break;
case DSP_REG_X:
fprintf_fn (stream, sx_tab[(field_b >> 6) & 3]);
break;
case DSP_REG_Y:
fprintf_fn (stream, sy_tab[(field_b >> 4) & 3]);
break;
case A_MACH:
fprintf_fn (stream, "mach");
break;
case A_MACL:
fprintf_fn (stream, "macl");
break;
default:
abort ();
}
}
return;
}
}
/* Not found. */
fprintf_fn (stream, ".word 0x%x", field_b);
}
| false | qemu | c8160fab31e7a27979196c338a305e7095dd8aea | print_insn_ppi (int field_b, struct disassemble_info *info)
{
static const char *sx_tab[] = { "x0", "x1", "a0", "a1" };
static const char *sy_tab[] = { "y0", "y1", "m0", "m1" };
fprintf_ftype fprintf_fn = info->fprintf_func;
void *stream = info->stream;
unsigned int nib1, nib2, nib3;
unsigned int altnib1, nib4;
const char *dc = NULL;
const sh_opcode_info *op;
if ((field_b & 0xe800) == 0)
{
fprintf_fn (stream, "psh%c\t#%d,",
field_b & 0x1000 ? 'a' : 'l',
(field_b >> 4) & 127);
print_dsp_reg (field_b & 0xf, fprintf_fn, stream);
return;
}
if ((field_b & 0xc000) == 0x4000 && (field_b & 0x3000) != 0x1000)
{
static const char *du_tab[] = { "x0", "y0", "a0", "a1" };
static const char *se_tab[] = { "x0", "x1", "y0", "a1" };
static const char *sf_tab[] = { "y0", "y1", "x0", "a1" };
static const char *sg_tab[] = { "m0", "m1", "a0", "a1" };
if (field_b & 0x2000)
{
fprintf_fn (stream, "p%s %s,%s,%s\t",
(field_b & 0x1000) ? "add" : "sub",
sx_tab[(field_b >> 6) & 3],
sy_tab[(field_b >> 4) & 3],
du_tab[(field_b >> 0) & 3]);
}
else if ((field_b & 0xf0) == 0x10
&& info->mach != bfd_mach_sh_dsp
&& info->mach != bfd_mach_sh3_dsp)
{
fprintf_fn (stream, "pclr %s \t", du_tab[(field_b >> 0) & 3]);
}
else if ((field_b & 0xf3) != 0)
{
fprintf_fn (stream, ".word 0x%x\t", field_b);
}
fprintf_fn (stream, "pmuls%c%s,%s,%s",
field_b & 0x2000 ? ' ' : '\t',
se_tab[(field_b >> 10) & 3],
sf_tab[(field_b >> 8) & 3],
sg_tab[(field_b >> 2) & 3]);
return;
}
nib1 = PPIC;
nib2 = field_b >> 12 & 0xf;
nib3 = field_b >> 8 & 0xf;
nib4 = field_b >> 4 & 0xf;
switch (nib3 & 0x3)
{
case 0:
dc = "";
nib1 = PPI3;
break;
case 1:
dc = "";
break;
case 2:
dc = "dct ";
nib3 -= 1;
break;
case 3:
dc = "dcf ";
nib3 -= 2;
break;
}
if (nib1 == PPI3)
altnib1 = PPI3NC;
else
altnib1 = nib1;
for (op = sh_table; op->name; op++)
{
if ((op->nibbles[1] == nib1 || op->nibbles[1] == altnib1)
&& op->nibbles[2] == nib2
&& op->nibbles[3] == nib3)
{
int n;
switch (op->nibbles[4])
{
case HEX_0:
break;
case HEX_XX00:
if ((nib4 & 3) != 0)
continue;
break;
case HEX_1:
if ((nib4 & 3) != 1)
continue;
break;
case HEX_00YY:
if ((nib4 & 0xc) != 0)
continue;
break;
case HEX_4:
if ((nib4 & 0xc) != 4)
continue;
break;
default:
abort ();
}
fprintf_fn (stream, "%s%s\t", dc, op->name);
for (n = 0; n < 3 && op->arg[n] != A_END; n++)
{
if (n && op->arg[1] != A_END)
fprintf_fn (stream, ",");
switch (op->arg[n])
{
case DSP_REG_N:
print_dsp_reg (field_b & 0xf, fprintf_fn, stream);
break;
case DSP_REG_X:
fprintf_fn (stream, sx_tab[(field_b >> 6) & 3]);
break;
case DSP_REG_Y:
fprintf_fn (stream, sy_tab[(field_b >> 4) & 3]);
break;
case A_MACH:
fprintf_fn (stream, "mach");
break;
case A_MACL:
fprintf_fn (stream, "macl");
break;
default:
abort ();
}
}
return;
}
}
fprintf_fn (stream, ".word 0x%x", field_b);
}
| {
"code": [],
"line_no": []
} | FUNC_0 (int VAR_0, struct disassemble_info *VAR_1)
{
static const char *VAR_2[] = { "x0", "x1", "a0", "a1" };
static const char *VAR_3[] = { "y0", "y1", "m0", "m1" };
fprintf_ftype fprintf_fn = VAR_1->fprintf_func;
void *VAR_4 = VAR_1->VAR_4;
unsigned int VAR_5, VAR_6, VAR_7;
unsigned int VAR_8, VAR_9;
const char *VAR_10 = NULL;
const sh_opcode_info *VAR_11;
if ((VAR_0 & 0xe800) == 0)
{
fprintf_fn (VAR_4, "psh%c\t#%d,",
VAR_0 & 0x1000 ? 'a' : 'l',
(VAR_0 >> 4) & 127);
print_dsp_reg (VAR_0 & 0xf, fprintf_fn, VAR_4);
return;
}
if ((VAR_0 & 0xc000) == 0x4000 && (VAR_0 & 0x3000) != 0x1000)
{
static const char *VAR_12[] = { "x0", "y0", "a0", "a1" };
static const char *VAR_13[] = { "x0", "x1", "y0", "a1" };
static const char *VAR_14[] = { "y0", "y1", "x0", "a1" };
static const char *VAR_15[] = { "m0", "m1", "a0", "a1" };
if (VAR_0 & 0x2000)
{
fprintf_fn (VAR_4, "p%s %s,%s,%s\t",
(VAR_0 & 0x1000) ? "add" : "sub",
VAR_2[(VAR_0 >> 6) & 3],
VAR_3[(VAR_0 >> 4) & 3],
VAR_12[(VAR_0 >> 0) & 3]);
}
else if ((VAR_0 & 0xf0) == 0x10
&& VAR_1->mach != bfd_mach_sh_dsp
&& VAR_1->mach != bfd_mach_sh3_dsp)
{
fprintf_fn (VAR_4, "pclr %s \t", VAR_12[(VAR_0 >> 0) & 3]);
}
else if ((VAR_0 & 0xf3) != 0)
{
fprintf_fn (VAR_4, ".word 0x%x\t", VAR_0);
}
fprintf_fn (VAR_4, "pmuls%c%s,%s,%s",
VAR_0 & 0x2000 ? ' ' : '\t',
VAR_13[(VAR_0 >> 10) & 3],
VAR_14[(VAR_0 >> 8) & 3],
VAR_15[(VAR_0 >> 2) & 3]);
return;
}
VAR_5 = PPIC;
VAR_6 = VAR_0 >> 12 & 0xf;
VAR_7 = VAR_0 >> 8 & 0xf;
VAR_9 = VAR_0 >> 4 & 0xf;
switch (VAR_7 & 0x3)
{
case 0:
VAR_10 = "";
VAR_5 = PPI3;
break;
case 1:
VAR_10 = "";
break;
case 2:
VAR_10 = "dct ";
VAR_7 -= 1;
break;
case 3:
VAR_10 = "dcf ";
VAR_7 -= 2;
break;
}
if (VAR_5 == PPI3)
VAR_8 = PPI3NC;
else
VAR_8 = VAR_5;
for (VAR_11 = sh_table; VAR_11->name; VAR_11++)
{
if ((VAR_11->nibbles[1] == VAR_5 || VAR_11->nibbles[1] == VAR_8)
&& VAR_11->nibbles[2] == VAR_6
&& VAR_11->nibbles[3] == VAR_7)
{
int n;
switch (VAR_11->nibbles[4])
{
case HEX_0:
break;
case HEX_XX00:
if ((VAR_9 & 3) != 0)
continue;
break;
case HEX_1:
if ((VAR_9 & 3) != 1)
continue;
break;
case HEX_00YY:
if ((VAR_9 & 0xc) != 0)
continue;
break;
case HEX_4:
if ((VAR_9 & 0xc) != 4)
continue;
break;
default:
abort ();
}
fprintf_fn (VAR_4, "%s%s\t", VAR_10, VAR_11->name);
for (n = 0; n < 3 && VAR_11->arg[n] != A_END; n++)
{
if (n && VAR_11->arg[1] != A_END)
fprintf_fn (VAR_4, ",");
switch (VAR_11->arg[n])
{
case DSP_REG_N:
print_dsp_reg (VAR_0 & 0xf, fprintf_fn, VAR_4);
break;
case DSP_REG_X:
fprintf_fn (VAR_4, VAR_2[(VAR_0 >> 6) & 3]);
break;
case DSP_REG_Y:
fprintf_fn (VAR_4, VAR_3[(VAR_0 >> 4) & 3]);
break;
case A_MACH:
fprintf_fn (VAR_4, "mach");
break;
case A_MACL:
fprintf_fn (VAR_4, "macl");
break;
default:
abort ();
}
}
return;
}
}
fprintf_fn (VAR_4, ".word 0x%x", VAR_0);
}
| [
"FUNC_0 (int VAR_0, struct disassemble_info *VAR_1)\n{",
"static const char *VAR_2[] = { \"x0\", \"x1\", \"a0\", \"a1\" };",
"static const char *VAR_3[] = { \"y0\", \"y1\", \"m0\", \"m1\" };",
"fprintf_ftype fprintf_fn = VAR_1->fprintf_func;",
"void *VAR_4 = VAR_1->VAR_4;",
"unsigned int VAR_5, VAR_6, VAR_7;",
"unsigned int VAR_8, VAR_9;",
"const char *VAR_10 = NULL;",
"const sh_opcode_info *VAR_11;",
"if ((VAR_0 & 0xe800) == 0)\n{",
"fprintf_fn (VAR_4, \"psh%c\\t#%d,\",\nVAR_0 & 0x1000 ? 'a' : 'l',\n(VAR_0 >> 4) & 127);",
"print_dsp_reg (VAR_0 & 0xf, fprintf_fn, VAR_4);",
"return;",
"}",
"if ((VAR_0 & 0xc000) == 0x4000 && (VAR_0 & 0x3000) != 0x1000)\n{",
"static const char *VAR_12[] = { \"x0\", \"y0\", \"a0\", \"a1\" };",
"static const char *VAR_13[] = { \"x0\", \"x1\", \"y0\", \"a1\" };",
"static const char *VAR_14[] = { \"y0\", \"y1\", \"x0\", \"a1\" };",
"static const char *VAR_15[] = { \"m0\", \"m1\", \"a0\", \"a1\" };",
"if (VAR_0 & 0x2000)\n{",
"fprintf_fn (VAR_4, \"p%s %s,%s,%s\\t\",\n(VAR_0 & 0x1000) ? \"add\" : \"sub\",\nVAR_2[(VAR_0 >> 6) & 3],\nVAR_3[(VAR_0 >> 4) & 3],\nVAR_12[(VAR_0 >> 0) & 3]);",
"}",
"else if ((VAR_0 & 0xf0) == 0x10\n&& VAR_1->mach != bfd_mach_sh_dsp\n&& VAR_1->mach != bfd_mach_sh3_dsp)\n{",
"fprintf_fn (VAR_4, \"pclr %s \\t\", VAR_12[(VAR_0 >> 0) & 3]);",
"}",
"else if ((VAR_0 & 0xf3) != 0)\n{",
"fprintf_fn (VAR_4, \".word 0x%x\\t\", VAR_0);",
"}",
"fprintf_fn (VAR_4, \"pmuls%c%s,%s,%s\",\nVAR_0 & 0x2000 ? ' ' : '\\t',\nVAR_13[(VAR_0 >> 10) & 3],\nVAR_14[(VAR_0 >> 8) & 3],\nVAR_15[(VAR_0 >> 2) & 3]);",
"return;",
"}",
"VAR_5 = PPIC;",
"VAR_6 = VAR_0 >> 12 & 0xf;",
"VAR_7 = VAR_0 >> 8 & 0xf;",
"VAR_9 = VAR_0 >> 4 & 0xf;",
"switch (VAR_7 & 0x3)\n{",
"case 0:\nVAR_10 = \"\";",
"VAR_5 = PPI3;",
"break;",
"case 1:\nVAR_10 = \"\";",
"break;",
"case 2:\nVAR_10 = \"dct \";",
"VAR_7 -= 1;",
"break;",
"case 3:\nVAR_10 = \"dcf \";",
"VAR_7 -= 2;",
"break;",
"}",
"if (VAR_5 == PPI3)\nVAR_8 = PPI3NC;",
"else\nVAR_8 = VAR_5;",
"for (VAR_11 = sh_table; VAR_11->name; VAR_11++)",
"{",
"if ((VAR_11->nibbles[1] == VAR_5 || VAR_11->nibbles[1] == VAR_8)\n&& VAR_11->nibbles[2] == VAR_6\n&& VAR_11->nibbles[3] == VAR_7)\n{",
"int n;",
"switch (VAR_11->nibbles[4])\n{",
"case HEX_0:\nbreak;",
"case HEX_XX00:\nif ((VAR_9 & 3) != 0)\ncontinue;",
"break;",
"case HEX_1:\nif ((VAR_9 & 3) != 1)\ncontinue;",
"break;",
"case HEX_00YY:\nif ((VAR_9 & 0xc) != 0)\ncontinue;",
"break;",
"case HEX_4:\nif ((VAR_9 & 0xc) != 4)\ncontinue;",
"break;",
"default:\nabort ();",
"}",
"fprintf_fn (VAR_4, \"%s%s\\t\", VAR_10, VAR_11->name);",
"for (n = 0; n < 3 && VAR_11->arg[n] != A_END; n++)",
"{",
"if (n && VAR_11->arg[1] != A_END)\nfprintf_fn (VAR_4, \",\");",
"switch (VAR_11->arg[n])\n{",
"case DSP_REG_N:\nprint_dsp_reg (VAR_0 & 0xf, fprintf_fn, VAR_4);",
"break;",
"case DSP_REG_X:\nfprintf_fn (VAR_4, VAR_2[(VAR_0 >> 6) & 3]);",
"break;",
"case DSP_REG_Y:\nfprintf_fn (VAR_4, VAR_3[(VAR_0 >> 4) & 3]);",
"break;",
"case A_MACH:\nfprintf_fn (VAR_4, \"mach\");",
"break;",
"case A_MACL:\nfprintf_fn (VAR_4, \"macl\");",
"break;",
"default:\nabort ();",
"}",
"}",
"return;",
"}",
"}",
"fprintf_fn (VAR_4, \".word 0x%x\", VAR_0);",
"}"
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | [
[
1,
3
],
[
5
],
[
7
],
[
9
],
[
11
],
[
13
],
[
15
],
[
17
],
[
19
],
[
23,
25
],
[
27,
29,
31
],
[
33
],
[
35
],
[
37
],
[
39,
41
],
[
43
],
[
45
],
[
47
],
[
49
],
[
53,
55
],
[
57,
59,
61,
63,
65
],
[
67
],
[
69,
71,
73,
75
],
[
77
],
[
79
],
[
81,
83
],
[
85
],
[
87
],
[
89,
91,
93,
95,
97
],
[
99
],
[
101
],
[
105
],
[
107
],
[
109
],
[
111
],
[
113,
115
],
[
117,
119
],
[
121
],
[
123
],
[
125,
127
],
[
129
],
[
131,
133
],
[
135
],
[
137
],
[
139,
141
],
[
143
],
[
145
],
[
147
],
[
149,
151
],
[
153,
155
],
[
157
],
[
159
],
[
161,
163,
165,
167
],
[
169
],
[
173,
175
],
[
177,
179
],
[
181,
183,
185
],
[
187
],
[
189,
191,
193
],
[
195
],
[
197,
199,
201
],
[
203
],
[
205,
207,
209
],
[
211
],
[
213,
215
],
[
217
],
[
219
],
[
221
],
[
223
],
[
225,
227
],
[
229,
231
],
[
233,
235
],
[
237
],
[
239,
241
],
[
243
],
[
245,
247
],
[
249
],
[
251,
253
],
[
255
],
[
257,
259
],
[
261
],
[
263,
265
],
[
267
],
[
269
],
[
271
],
[
273
],
[
275
],
[
279
],
[
281
]
] |
21,447 | static int monitor_parse(const char *devname)
{
static int index = 0;
char label[32];
if (strcmp(devname, "none") == 0)
return 0;
if (index == MAX_MONITOR_DEVICES) {
fprintf(stderr, "qemu: too many monitor devices\n");
exit(1);
}
if (index == 0) {
snprintf(label, sizeof(label), "monitor");
} else {
snprintf(label, sizeof(label), "monitor%d", index);
}
monitor_hds[index] = qemu_chr_open(label, devname, NULL);
if (!monitor_hds[index]) {
fprintf(stderr, "qemu: could not open monitor device '%s'\n",
devname);
return -1;
}
index++;
return 0;
}
| false | qemu | 88589343708f10f1ded0af100b2e11eec623bae2 | static int monitor_parse(const char *devname)
{
static int index = 0;
char label[32];
if (strcmp(devname, "none") == 0)
return 0;
if (index == MAX_MONITOR_DEVICES) {
fprintf(stderr, "qemu: too many monitor devices\n");
exit(1);
}
if (index == 0) {
snprintf(label, sizeof(label), "monitor");
} else {
snprintf(label, sizeof(label), "monitor%d", index);
}
monitor_hds[index] = qemu_chr_open(label, devname, NULL);
if (!monitor_hds[index]) {
fprintf(stderr, "qemu: could not open monitor device '%s'\n",
devname);
return -1;
}
index++;
return 0;
}
| {
"code": [],
"line_no": []
} | static int FUNC_0(const char *VAR_0)
{
static int VAR_1 = 0;
char VAR_2[32];
if (strcmp(VAR_0, "none") == 0)
return 0;
if (VAR_1 == MAX_MONITOR_DEVICES) {
fprintf(stderr, "qemu: too many monitor devices\n");
exit(1);
}
if (VAR_1 == 0) {
snprintf(VAR_2, sizeof(VAR_2), "monitor");
} else {
snprintf(VAR_2, sizeof(VAR_2), "monitor%d", VAR_1);
}
monitor_hds[VAR_1] = qemu_chr_open(VAR_2, VAR_0, NULL);
if (!monitor_hds[VAR_1]) {
fprintf(stderr, "qemu: could not open monitor device '%s'\n",
VAR_0);
return -1;
}
VAR_1++;
return 0;
}
| [
"static int FUNC_0(const char *VAR_0)\n{",
"static int VAR_1 = 0;",
"char VAR_2[32];",
"if (strcmp(VAR_0, \"none\") == 0)\nreturn 0;",
"if (VAR_1 == MAX_MONITOR_DEVICES) {",
"fprintf(stderr, \"qemu: too many monitor devices\\n\");",
"exit(1);",
"}",
"if (VAR_1 == 0) {",
"snprintf(VAR_2, sizeof(VAR_2), \"monitor\");",
"} else {",
"snprintf(VAR_2, sizeof(VAR_2), \"monitor%d\", VAR_1);",
"}",
"monitor_hds[VAR_1] = qemu_chr_open(VAR_2, VAR_0, NULL);",
"if (!monitor_hds[VAR_1]) {",
"fprintf(stderr, \"qemu: could not open monitor device '%s'\\n\",\nVAR_0);",
"return -1;",
"}",
"VAR_1++;",
"return 0;",
"}"
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | [
[
1,
3
],
[
5
],
[
7
],
[
11,
13
],
[
15
],
[
17
],
[
19
],
[
21
],
[
23
],
[
25
],
[
27
],
[
29
],
[
31
],
[
33
],
[
35
],
[
37,
39
],
[
41
],
[
43
],
[
45
],
[
47
],
[
49
]
] |
21,448 | void ppc_store_sdr1(CPUPPCState *env, target_ulong value)
{
qemu_log_mask(CPU_LOG_MMU, "%s: " TARGET_FMT_lx "\n", __func__, value);
assert(!env->external_htab);
env->spr[SPR_SDR1] = value;
#if defined(TARGET_PPC64)
if (env->mmu_model & POWERPC_MMU_64) {
PowerPCCPU *cpu = ppc_env_get_cpu(env);
Error *local_err = NULL;
ppc_hash64_set_sdr1(cpu, value, &local_err);
if (local_err) {
error_report_err(local_err);
error_free(local_err);
}
} else
#endif /* defined(TARGET_PPC64) */
{
/* FIXME: Should check for valid HTABMASK values */
env->htab_mask = ((value & SDR_32_HTABMASK) << 16) | 0xFFFF;
env->htab_base = value & SDR_32_HTABORG;
}
}
| false | qemu | 36778660d7fd0748a6129916e47ecedd67bdb758 | void ppc_store_sdr1(CPUPPCState *env, target_ulong value)
{
qemu_log_mask(CPU_LOG_MMU, "%s: " TARGET_FMT_lx "\n", __func__, value);
assert(!env->external_htab);
env->spr[SPR_SDR1] = value;
#if defined(TARGET_PPC64)
if (env->mmu_model & POWERPC_MMU_64) {
PowerPCCPU *cpu = ppc_env_get_cpu(env);
Error *local_err = NULL;
ppc_hash64_set_sdr1(cpu, value, &local_err);
if (local_err) {
error_report_err(local_err);
error_free(local_err);
}
} else
#endif
{
env->htab_mask = ((value & SDR_32_HTABMASK) << 16) | 0xFFFF;
env->htab_base = value & SDR_32_HTABORG;
}
}
| {
"code": [],
"line_no": []
} | void FUNC_0(CPUPPCState *VAR_0, target_ulong VAR_1)
{
qemu_log_mask(CPU_LOG_MMU, "%s: " TARGET_FMT_lx "\n", __func__, VAR_1);
assert(!VAR_0->external_htab);
VAR_0->spr[SPR_SDR1] = VAR_1;
#if defined(TARGET_PPC64)
if (VAR_0->mmu_model & POWERPC_MMU_64) {
PowerPCCPU *cpu = ppc_env_get_cpu(VAR_0);
Error *local_err = NULL;
ppc_hash64_set_sdr1(cpu, VAR_1, &local_err);
if (local_err) {
error_report_err(local_err);
error_free(local_err);
}
} else
#endif
{
VAR_0->htab_mask = ((VAR_1 & SDR_32_HTABMASK) << 16) | 0xFFFF;
VAR_0->htab_base = VAR_1 & SDR_32_HTABORG;
}
}
| [
"void FUNC_0(CPUPPCState *VAR_0, target_ulong VAR_1)\n{",
"qemu_log_mask(CPU_LOG_MMU, \"%s: \" TARGET_FMT_lx \"\\n\", __func__, VAR_1);",
"assert(!VAR_0->external_htab);",
"VAR_0->spr[SPR_SDR1] = VAR_1;",
"#if defined(TARGET_PPC64)\nif (VAR_0->mmu_model & POWERPC_MMU_64) {",
"PowerPCCPU *cpu = ppc_env_get_cpu(VAR_0);",
"Error *local_err = NULL;",
"ppc_hash64_set_sdr1(cpu, VAR_1, &local_err);",
"if (local_err) {",
"error_report_err(local_err);",
"error_free(local_err);",
"}",
"} else",
"#endif\n{",
"VAR_0->htab_mask = ((VAR_1 & SDR_32_HTABMASK) << 16) | 0xFFFF;",
"VAR_0->htab_base = VAR_1 & SDR_32_HTABORG;",
"}",
"}"
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | [
[
1,
3
],
[
5
],
[
7
],
[
9
],
[
11,
13
],
[
15
],
[
17
],
[
21
],
[
23
],
[
25
],
[
27
],
[
29
],
[
31
],
[
33,
35
],
[
39
],
[
41
],
[
43
],
[
45
]
] |
21,449 | static av_always_inline void idct_internal(uint8_t *dst, DCTELEM *block, int stride, int block_stride, int shift, int add){
int i;
uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
block[0] += 1<<(shift-1);
for(i=0; i<4; i++){
const int z0= block[0 + block_stride*i] + block[2 + block_stride*i];
const int z1= block[0 + block_stride*i] - block[2 + block_stride*i];
const int z2= (block[1 + block_stride*i]>>1) - block[3 + block_stride*i];
const int z3= block[1 + block_stride*i] + (block[3 + block_stride*i]>>1);
block[0 + block_stride*i]= z0 + z3;
block[1 + block_stride*i]= z1 + z2;
block[2 + block_stride*i]= z1 - z2;
block[3 + block_stride*i]= z0 - z3;
}
for(i=0; i<4; i++){
const int z0= block[i + block_stride*0] + block[i + block_stride*2];
const int z1= block[i + block_stride*0] - block[i + block_stride*2];
const int z2= (block[i + block_stride*1]>>1) - block[i + block_stride*3];
const int z3= block[i + block_stride*1] + (block[i + block_stride*3]>>1);
dst[i + 0*stride]= cm[ add*dst[i + 0*stride] + ((z0 + z3) >> shift) ];
dst[i + 1*stride]= cm[ add*dst[i + 1*stride] + ((z1 + z2) >> shift) ];
dst[i + 2*stride]= cm[ add*dst[i + 2*stride] + ((z1 - z2) >> shift) ];
dst[i + 3*stride]= cm[ add*dst[i + 3*stride] + ((z0 - z3) >> shift) ];
}
}
| false | FFmpeg | ca32f7f2083f9ededd1d9964ed065e0ad07a01e0 | static av_always_inline void idct_internal(uint8_t *dst, DCTELEM *block, int stride, int block_stride, int shift, int add){
int i;
uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
block[0] += 1<<(shift-1);
for(i=0; i<4; i++){
const int z0= block[0 + block_stride*i] + block[2 + block_stride*i];
const int z1= block[0 + block_stride*i] - block[2 + block_stride*i];
const int z2= (block[1 + block_stride*i]>>1) - block[3 + block_stride*i];
const int z3= block[1 + block_stride*i] + (block[3 + block_stride*i]>>1);
block[0 + block_stride*i]= z0 + z3;
block[1 + block_stride*i]= z1 + z2;
block[2 + block_stride*i]= z1 - z2;
block[3 + block_stride*i]= z0 - z3;
}
for(i=0; i<4; i++){
const int z0= block[i + block_stride*0] + block[i + block_stride*2];
const int z1= block[i + block_stride*0] - block[i + block_stride*2];
const int z2= (block[i + block_stride*1]>>1) - block[i + block_stride*3];
const int z3= block[i + block_stride*1] + (block[i + block_stride*3]>>1);
dst[i + 0*stride]= cm[ add*dst[i + 0*stride] + ((z0 + z3) >> shift) ];
dst[i + 1*stride]= cm[ add*dst[i + 1*stride] + ((z1 + z2) >> shift) ];
dst[i + 2*stride]= cm[ add*dst[i + 2*stride] + ((z1 - z2) >> shift) ];
dst[i + 3*stride]= cm[ add*dst[i + 3*stride] + ((z0 - z3) >> shift) ];
}
}
| {
"code": [],
"line_no": []
} | static av_always_inline void FUNC_0(uint8_t *dst, DCTELEM *block, int stride, int block_stride, int shift, int add){
int VAR_0;
uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
block[0] += 1<<(shift-1);
for(VAR_0=0; VAR_0<4; VAR_0++){
const int VAR_5= block[0 + block_stride*VAR_0] + block[2 + block_stride*VAR_0];
const int VAR_5= block[0 + block_stride*VAR_0] - block[2 + block_stride*VAR_0];
const int VAR_5= (block[1 + block_stride*VAR_0]>>1) - block[3 + block_stride*VAR_0];
const int VAR_5= block[1 + block_stride*VAR_0] + (block[3 + block_stride*VAR_0]>>1);
block[0 + block_stride*VAR_0]= VAR_5 + VAR_5;
block[1 + block_stride*VAR_0]= VAR_5 + VAR_5;
block[2 + block_stride*VAR_0]= VAR_5 - VAR_5;
block[3 + block_stride*VAR_0]= VAR_5 - VAR_5;
}
for(VAR_0=0; VAR_0<4; VAR_0++){
const int VAR_5= block[VAR_0 + block_stride*0] + block[VAR_0 + block_stride*2];
const int VAR_5= block[VAR_0 + block_stride*0] - block[VAR_0 + block_stride*2];
const int VAR_5= (block[VAR_0 + block_stride*1]>>1) - block[VAR_0 + block_stride*3];
const int VAR_5= block[VAR_0 + block_stride*1] + (block[VAR_0 + block_stride*3]>>1);
dst[VAR_0 + 0*stride]= cm[ add*dst[VAR_0 + 0*stride] + ((VAR_5 + VAR_5) >> shift) ];
dst[VAR_0 + 1*stride]= cm[ add*dst[VAR_0 + 1*stride] + ((VAR_5 + VAR_5) >> shift) ];
dst[VAR_0 + 2*stride]= cm[ add*dst[VAR_0 + 2*stride] + ((VAR_5 - VAR_5) >> shift) ];
dst[VAR_0 + 3*stride]= cm[ add*dst[VAR_0 + 3*stride] + ((VAR_5 - VAR_5) >> shift) ];
}
}
| [
"static av_always_inline void FUNC_0(uint8_t *dst, DCTELEM *block, int stride, int block_stride, int shift, int add){",
"int VAR_0;",
"uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;",
"block[0] += 1<<(shift-1);",
"for(VAR_0=0; VAR_0<4; VAR_0++){",
"const int VAR_5= block[0 + block_stride*VAR_0] + block[2 + block_stride*VAR_0];",
"const int VAR_5= block[0 + block_stride*VAR_0] - block[2 + block_stride*VAR_0];",
"const int VAR_5= (block[1 + block_stride*VAR_0]>>1) - block[3 + block_stride*VAR_0];",
"const int VAR_5= block[1 + block_stride*VAR_0] + (block[3 + block_stride*VAR_0]>>1);",
"block[0 + block_stride*VAR_0]= VAR_5 + VAR_5;",
"block[1 + block_stride*VAR_0]= VAR_5 + VAR_5;",
"block[2 + block_stride*VAR_0]= VAR_5 - VAR_5;",
"block[3 + block_stride*VAR_0]= VAR_5 - VAR_5;",
"}",
"for(VAR_0=0; VAR_0<4; VAR_0++){",
"const int VAR_5= block[VAR_0 + block_stride*0] + block[VAR_0 + block_stride*2];",
"const int VAR_5= block[VAR_0 + block_stride*0] - block[VAR_0 + block_stride*2];",
"const int VAR_5= (block[VAR_0 + block_stride*1]>>1) - block[VAR_0 + block_stride*3];",
"const int VAR_5= block[VAR_0 + block_stride*1] + (block[VAR_0 + block_stride*3]>>1);",
"dst[VAR_0 + 0*stride]= cm[ add*dst[VAR_0 + 0*stride] + ((VAR_5 + VAR_5) >> shift) ];",
"dst[VAR_0 + 1*stride]= cm[ add*dst[VAR_0 + 1*stride] + ((VAR_5 + VAR_5) >> shift) ];",
"dst[VAR_0 + 2*stride]= cm[ add*dst[VAR_0 + 2*stride] + ((VAR_5 - VAR_5) >> shift) ];",
"dst[VAR_0 + 3*stride]= cm[ add*dst[VAR_0 + 3*stride] + ((VAR_5 - VAR_5) >> shift) ];",
"}",
"}"
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | [
[
1
],
[
3
],
[
5
],
[
9
],
[
13
],
[
15
],
[
17
],
[
19
],
[
21
],
[
25
],
[
27
],
[
29
],
[
31
],
[
33
],
[
37
],
[
39
],
[
41
],
[
43
],
[
45
],
[
49
],
[
51
],
[
53
],
[
55
],
[
57
],
[
59
]
] |
21,451 | static int mp_dacl_removexattr(FsContext *ctx,
const char *path, const char *name)
{
int ret;
char buffer[PATH_MAX];
ret = lremovexattr(rpath(ctx, path, buffer), MAP_ACL_DEFAULT);
if (ret == -1 && errno == ENODATA) {
/*
* We don't get ENODATA error when trying to remove a
* posix acl that is not present. So don't throw the error
* even in case of mapped security model
*/
errno = 0;
ret = 0;
}
return ret;
}
| false | qemu | 4fa4ce7107c6ec432f185307158c5df91ce54308 | static int mp_dacl_removexattr(FsContext *ctx,
const char *path, const char *name)
{
int ret;
char buffer[PATH_MAX];
ret = lremovexattr(rpath(ctx, path, buffer), MAP_ACL_DEFAULT);
if (ret == -1 && errno == ENODATA) {
errno = 0;
ret = 0;
}
return ret;
}
| {
"code": [],
"line_no": []
} | static int FUNC_0(FsContext *VAR_0,
const char *VAR_1, const char *VAR_2)
{
int VAR_3;
char VAR_4[PATH_MAX];
VAR_3 = lremovexattr(rpath(VAR_0, VAR_1, VAR_4), MAP_ACL_DEFAULT);
if (VAR_3 == -1 && errno == ENODATA) {
errno = 0;
VAR_3 = 0;
}
return VAR_3;
}
| [
"static int FUNC_0(FsContext *VAR_0,\nconst char *VAR_1, const char *VAR_2)\n{",
"int VAR_3;",
"char VAR_4[PATH_MAX];",
"VAR_3 = lremovexattr(rpath(VAR_0, VAR_1, VAR_4), MAP_ACL_DEFAULT);",
"if (VAR_3 == -1 && errno == ENODATA) {",
"errno = 0;",
"VAR_3 = 0;",
"}",
"return VAR_3;",
"}"
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | [
[
1,
3,
5
],
[
7
],
[
9
],
[
11
],
[
13
],
[
25
],
[
27
],
[
29
],
[
31
],
[
33
]
] |
21,452 | void *qemu_thread_join(QemuThread *thread)
{
QemuThreadData *data;
void *ret;
HANDLE handle;
data = thread->data;
if (!data) {
return NULL;
}
/*
* Because multiple copies of the QemuThread can exist via
* qemu_thread_get_self, we need to store a value that cannot
* leak there. The simplest, non racy way is to store the TID,
* discard the handle that _beginthreadex gives back, and
* get another copy of the handle here.
*/
EnterCriticalSection(&data->cs);
if (!data->exited) {
handle = OpenThread(SYNCHRONIZE, FALSE, thread->tid);
LeaveCriticalSection(&data->cs);
WaitForSingleObject(handle, INFINITE);
CloseHandle(handle);
} else {
LeaveCriticalSection(&data->cs);
}
ret = data->ret;
DeleteCriticalSection(&data->cs);
g_free(data);
return ret;
}
| false | qemu | 1ecf47bf0a091700e45f1b7d1f5ad85abc0acd22 | void *qemu_thread_join(QemuThread *thread)
{
QemuThreadData *data;
void *ret;
HANDLE handle;
data = thread->data;
if (!data) {
return NULL;
}
EnterCriticalSection(&data->cs);
if (!data->exited) {
handle = OpenThread(SYNCHRONIZE, FALSE, thread->tid);
LeaveCriticalSection(&data->cs);
WaitForSingleObject(handle, INFINITE);
CloseHandle(handle);
} else {
LeaveCriticalSection(&data->cs);
}
ret = data->ret;
DeleteCriticalSection(&data->cs);
g_free(data);
return ret;
}
| {
"code": [],
"line_no": []
} | void *FUNC_0(QemuThread *VAR_0)
{
QemuThreadData *data;
void *VAR_1;
HANDLE handle;
data = VAR_0->data;
if (!data) {
return NULL;
}
EnterCriticalSection(&data->cs);
if (!data->exited) {
handle = OpenThread(SYNCHRONIZE, FALSE, VAR_0->tid);
LeaveCriticalSection(&data->cs);
WaitForSingleObject(handle, INFINITE);
CloseHandle(handle);
} else {
LeaveCriticalSection(&data->cs);
}
VAR_1 = data->VAR_1;
DeleteCriticalSection(&data->cs);
g_free(data);
return VAR_1;
}
| [
"void *FUNC_0(QemuThread *VAR_0)\n{",
"QemuThreadData *data;",
"void *VAR_1;",
"HANDLE handle;",
"data = VAR_0->data;",
"if (!data) {",
"return NULL;",
"}",
"EnterCriticalSection(&data->cs);",
"if (!data->exited) {",
"handle = OpenThread(SYNCHRONIZE, FALSE, VAR_0->tid);",
"LeaveCriticalSection(&data->cs);",
"WaitForSingleObject(handle, INFINITE);",
"CloseHandle(handle);",
"} else {",
"LeaveCriticalSection(&data->cs);",
"}",
"VAR_1 = data->VAR_1;",
"DeleteCriticalSection(&data->cs);",
"g_free(data);",
"return VAR_1;",
"}"
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | [
[
1,
3
],
[
5
],
[
7
],
[
9
],
[
13
],
[
15
],
[
17
],
[
19
],
[
35
],
[
37
],
[
39
],
[
41
],
[
43
],
[
45
],
[
47
],
[
49
],
[
51
],
[
53
],
[
55
],
[
57
],
[
59
],
[
61
]
] |
21,454 | void OPPROTO op_sti(void)
{
raise_exception(EXCP0D_GPF);
}
| false | qemu | 504e56ebdca53bf8e8d379aa994e90a2e3b0d564 | void OPPROTO op_sti(void)
{
raise_exception(EXCP0D_GPF);
}
| {
"code": [],
"line_no": []
} | void VAR_0 op_sti(void)
{
raise_exception(EXCP0D_GPF);
}
| [
"void VAR_0 op_sti(void)\n{",
"raise_exception(EXCP0D_GPF);",
"}"
] | [
0,
0,
0
] | [
[
1,
3
],
[
5
],
[
7
]
] |
21,455 | static void test_pci_spec(void)
{
AHCIQState *ahci;
ahci = ahci_boot();
ahci_test_pci_spec(ahci);
ahci_shutdown(ahci);
}
| false | qemu | debaaa114a8877a939533ba846e64168fb287b7b | static void test_pci_spec(void)
{
AHCIQState *ahci;
ahci = ahci_boot();
ahci_test_pci_spec(ahci);
ahci_shutdown(ahci);
}
| {
"code": [],
"line_no": []
} | static void FUNC_0(void)
{
AHCIQState *ahci;
ahci = ahci_boot();
ahci_test_pci_spec(ahci);
ahci_shutdown(ahci);
}
| [
"static void FUNC_0(void)\n{",
"AHCIQState *ahci;",
"ahci = ahci_boot();",
"ahci_test_pci_spec(ahci);",
"ahci_shutdown(ahci);",
"}"
] | [
0,
0,
0,
0,
0,
0
] | [
[
1,
3
],
[
5
],
[
7
],
[
9
],
[
11
],
[
13
]
] |
21,456 | static uint32_t nvdimm_rw_label_data_check(NVDIMMDevice *nvdimm,
uint32_t offset, uint32_t length)
{
uint32_t ret = 3 /* Invalid Input Parameters */;
if (offset + length < offset) {
nvdimm_debug("offset %#x + length %#x is overflow.\n", offset,
length);
return ret;
}
if (nvdimm->label_size < offset + length) {
nvdimm_debug("position %#x is beyond label data (len = %" PRIx64 ").\n",
offset + length, nvdimm->label_size);
return ret;
}
if (length > nvdimm_get_max_xfer_label_size()) {
nvdimm_debug("length (%#x) is larger than max_xfer (%#x).\n",
length, nvdimm_get_max_xfer_label_size());
return ret;
}
return 0 /* Success */;
}
| false | qemu | c2fa30757a2ba1bb5b053883773a9a61fbdd7082 | static uint32_t nvdimm_rw_label_data_check(NVDIMMDevice *nvdimm,
uint32_t offset, uint32_t length)
{
uint32_t ret = 3 ;
if (offset + length < offset) {
nvdimm_debug("offset %#x + length %#x is overflow.\n", offset,
length);
return ret;
}
if (nvdimm->label_size < offset + length) {
nvdimm_debug("position %#x is beyond label data (len = %" PRIx64 ").\n",
offset + length, nvdimm->label_size);
return ret;
}
if (length > nvdimm_get_max_xfer_label_size()) {
nvdimm_debug("length (%#x) is larger than max_xfer (%#x).\n",
length, nvdimm_get_max_xfer_label_size());
return ret;
}
return 0 ;
}
| {
"code": [],
"line_no": []
} | static uint32_t FUNC_0(NVDIMMDevice *nvdimm,
uint32_t offset, uint32_t length)
{
uint32_t ret = 3 ;
if (offset + length < offset) {
nvdimm_debug("offset %#x + length %#x is overflow.\n", offset,
length);
return ret;
}
if (nvdimm->label_size < offset + length) {
nvdimm_debug("position %#x is beyond label data (len = %" PRIx64 ").\n",
offset + length, nvdimm->label_size);
return ret;
}
if (length > nvdimm_get_max_xfer_label_size()) {
nvdimm_debug("length (%#x) is larger than max_xfer (%#x).\n",
length, nvdimm_get_max_xfer_label_size());
return ret;
}
return 0 ;
}
| [
"static uint32_t FUNC_0(NVDIMMDevice *nvdimm,\nuint32_t offset, uint32_t length)\n{",
"uint32_t ret = 3 ;",
"if (offset + length < offset) {",
"nvdimm_debug(\"offset %#x + length %#x is overflow.\\n\", offset,\nlength);",
"return ret;",
"}",
"if (nvdimm->label_size < offset + length) {",
"nvdimm_debug(\"position %#x is beyond label data (len = %\" PRIx64 \").\\n\",\noffset + length, nvdimm->label_size);",
"return ret;",
"}",
"if (length > nvdimm_get_max_xfer_label_size()) {",
"nvdimm_debug(\"length (%#x) is larger than max_xfer (%#x).\\n\",\nlength, nvdimm_get_max_xfer_label_size());",
"return ret;",
"}",
"return 0 ;",
"}"
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | [
[
1,
3,
5
],
[
7
],
[
11
],
[
13,
15
],
[
17
],
[
19
],
[
23
],
[
25,
27
],
[
29
],
[
31
],
[
35
],
[
37,
39
],
[
41
],
[
43
],
[
47
],
[
49
]
] |
21,457 | static inline void gen_evmwumia(DisasContext *ctx)
{
TCGv_i64 tmp;
if (unlikely(!ctx->spe_enabled)) {
gen_exception(ctx, POWERPC_EXCP_APU);
return;
}
gen_evmwumi(ctx); /* rD := rA * rB */
tmp = tcg_temp_new_i64();
/* acc := rD */
gen_load_gpr64(tmp, rD(ctx->opcode));
tcg_gen_st_i64(tmp, cpu_env, offsetof(CPUState, spe_acc));
tcg_temp_free_i64(tmp);
}
| false | qemu | 27a69bb088bee6d4efea254659422fb9c751b3c7 | static inline void gen_evmwumia(DisasContext *ctx)
{
TCGv_i64 tmp;
if (unlikely(!ctx->spe_enabled)) {
gen_exception(ctx, POWERPC_EXCP_APU);
return;
}
gen_evmwumi(ctx);
tmp = tcg_temp_new_i64();
gen_load_gpr64(tmp, rD(ctx->opcode));
tcg_gen_st_i64(tmp, cpu_env, offsetof(CPUState, spe_acc));
tcg_temp_free_i64(tmp);
}
| {
"code": [],
"line_no": []
} | static inline void FUNC_0(DisasContext *VAR_0)
{
TCGv_i64 tmp;
if (unlikely(!VAR_0->spe_enabled)) {
gen_exception(VAR_0, POWERPC_EXCP_APU);
return;
}
gen_evmwumi(VAR_0);
tmp = tcg_temp_new_i64();
gen_load_gpr64(tmp, rD(VAR_0->opcode));
tcg_gen_st_i64(tmp, cpu_env, offsetof(CPUState, spe_acc));
tcg_temp_free_i64(tmp);
}
| [
"static inline void FUNC_0(DisasContext *VAR_0)\n{",
"TCGv_i64 tmp;",
"if (unlikely(!VAR_0->spe_enabled)) {",
"gen_exception(VAR_0, POWERPC_EXCP_APU);",
"return;",
"}",
"gen_evmwumi(VAR_0);",
"tmp = tcg_temp_new_i64();",
"gen_load_gpr64(tmp, rD(VAR_0->opcode));",
"tcg_gen_st_i64(tmp, cpu_env, offsetof(CPUState, spe_acc));",
"tcg_temp_free_i64(tmp);",
"}"
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | [
[
1,
3
],
[
5
],
[
9
],
[
11
],
[
13
],
[
15
],
[
19
],
[
23
],
[
29
],
[
31
],
[
33
],
[
35
]
] |
21,458 | QmpInputVisitor *qmp_input_visitor_new(QObject *obj, bool strict)
{
QmpInputVisitor *v;
v = g_malloc0(sizeof(*v));
v->visitor.type = VISITOR_INPUT;
v->visitor.start_struct = qmp_input_start_struct;
v->visitor.end_struct = qmp_input_end_struct;
v->visitor.start_list = qmp_input_start_list;
v->visitor.next_list = qmp_input_next_list;
v->visitor.end_list = qmp_input_end_list;
v->visitor.start_alternate = qmp_input_start_alternate;
v->visitor.type_int64 = qmp_input_type_int64;
v->visitor.type_uint64 = qmp_input_type_uint64;
v->visitor.type_bool = qmp_input_type_bool;
v->visitor.type_str = qmp_input_type_str;
v->visitor.type_number = qmp_input_type_number;
v->visitor.type_any = qmp_input_type_any;
v->visitor.optional = qmp_input_optional;
v->strict = strict;
qmp_input_push(v, obj, NULL);
qobject_incref(obj);
return v;
}
| false | qemu | ce140b176920b5b65184020735a3c65ed3e9aeda | QmpInputVisitor *qmp_input_visitor_new(QObject *obj, bool strict)
{
QmpInputVisitor *v;
v = g_malloc0(sizeof(*v));
v->visitor.type = VISITOR_INPUT;
v->visitor.start_struct = qmp_input_start_struct;
v->visitor.end_struct = qmp_input_end_struct;
v->visitor.start_list = qmp_input_start_list;
v->visitor.next_list = qmp_input_next_list;
v->visitor.end_list = qmp_input_end_list;
v->visitor.start_alternate = qmp_input_start_alternate;
v->visitor.type_int64 = qmp_input_type_int64;
v->visitor.type_uint64 = qmp_input_type_uint64;
v->visitor.type_bool = qmp_input_type_bool;
v->visitor.type_str = qmp_input_type_str;
v->visitor.type_number = qmp_input_type_number;
v->visitor.type_any = qmp_input_type_any;
v->visitor.optional = qmp_input_optional;
v->strict = strict;
qmp_input_push(v, obj, NULL);
qobject_incref(obj);
return v;
}
| {
"code": [],
"line_no": []
} | QmpInputVisitor *FUNC_0(QObject *obj, bool strict)
{
QmpInputVisitor *v;
v = g_malloc0(sizeof(*v));
v->visitor.type = VISITOR_INPUT;
v->visitor.start_struct = qmp_input_start_struct;
v->visitor.end_struct = qmp_input_end_struct;
v->visitor.start_list = qmp_input_start_list;
v->visitor.next_list = qmp_input_next_list;
v->visitor.end_list = qmp_input_end_list;
v->visitor.start_alternate = qmp_input_start_alternate;
v->visitor.type_int64 = qmp_input_type_int64;
v->visitor.type_uint64 = qmp_input_type_uint64;
v->visitor.type_bool = qmp_input_type_bool;
v->visitor.type_str = qmp_input_type_str;
v->visitor.type_number = qmp_input_type_number;
v->visitor.type_any = qmp_input_type_any;
v->visitor.optional = qmp_input_optional;
v->strict = strict;
qmp_input_push(v, obj, NULL);
qobject_incref(obj);
return v;
}
| [
"QmpInputVisitor *FUNC_0(QObject *obj, bool strict)\n{",
"QmpInputVisitor *v;",
"v = g_malloc0(sizeof(*v));",
"v->visitor.type = VISITOR_INPUT;",
"v->visitor.start_struct = qmp_input_start_struct;",
"v->visitor.end_struct = qmp_input_end_struct;",
"v->visitor.start_list = qmp_input_start_list;",
"v->visitor.next_list = qmp_input_next_list;",
"v->visitor.end_list = qmp_input_end_list;",
"v->visitor.start_alternate = qmp_input_start_alternate;",
"v->visitor.type_int64 = qmp_input_type_int64;",
"v->visitor.type_uint64 = qmp_input_type_uint64;",
"v->visitor.type_bool = qmp_input_type_bool;",
"v->visitor.type_str = qmp_input_type_str;",
"v->visitor.type_number = qmp_input_type_number;",
"v->visitor.type_any = qmp_input_type_any;",
"v->visitor.optional = qmp_input_optional;",
"v->strict = strict;",
"qmp_input_push(v, obj, NULL);",
"qobject_incref(obj);",
"return v;",
"}"
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | [
[
1,
3
],
[
5
],
[
9
],
[
13
],
[
15
],
[
17
],
[
19
],
[
21
],
[
23
],
[
25
],
[
27
],
[
29
],
[
31
],
[
33
],
[
35
],
[
37
],
[
39
],
[
41
],
[
45
],
[
47
],
[
51
],
[
53
]
] |
21,460 | static int mxf_parse_index(MXFContext *mxf, int track_id, AVStream *st)
{
int64_t accumulated_offset = 0;
int j, k, ret, nb_sorted_segments;
MXFIndexTableSegment **sorted_segments;
int n_delta = track_id - 1; /* TrackID = 1-based stream index */
if (track_id < 1) {
av_log(mxf->fc, AV_LOG_ERROR, "TrackID not positive: %i\n", track_id);
return AVERROR_INVALIDDATA;
}
if ((ret = mxf_get_sorted_table_segments(mxf, &nb_sorted_segments, &sorted_segments)))
return ret;
for (j = 0; j < nb_sorted_segments; j++) {
int duration, sample_duration = 1, last_sample_size = 0;
int64_t segment_size;
MXFIndexTableSegment *tableseg = sorted_segments[j];
/* reset accumulated_offset on BodySID change */
if (j > 0 && tableseg->body_sid != sorted_segments[j-1]->body_sid)
accumulated_offset = 0;
if (n_delta >= tableseg->nb_delta_entries && st->index != 0)
continue;
duration = tableseg->index_duration > 0 ? tableseg->index_duration :
st->duration - st->nb_index_entries;
segment_size = tableseg->edit_unit_byte_count * duration;
/* check small EditUnitByteCount for audio */
if (tableseg->edit_unit_byte_count && tableseg->edit_unit_byte_count < 32
&& !tableseg->index_duration) {
/* duration might be prime relative to the new sample_duration,
* which means we need to handle the last frame differently */
sample_duration = 8192;
last_sample_size = (duration % sample_duration) * tableseg->edit_unit_byte_count;
tableseg->edit_unit_byte_count *= sample_duration;
duration /= sample_duration;
if (last_sample_size) duration++;
}
for (k = 0; k < duration; k++) {
int64_t pos;
int size, flags = 0;
if (k < tableseg->nb_index_entries) {
pos = tableseg->stream_offset_entries[k];
if (n_delta < tableseg->nb_delta_entries) {
if (n_delta < tableseg->nb_delta_entries - 1) {
size =
tableseg->slice_offset_entries[k][tableseg->slice[n_delta+1]-1] +
tableseg->element_delta[n_delta+1] -
tableseg->element_delta[n_delta];
if (tableseg->slice[n_delta] > 0)
size -= tableseg->slice_offset_entries[k][tableseg->slice[n_delta]-1];
} else if (k < duration - 1) {
size = tableseg->stream_offset_entries[k+1] -
tableseg->stream_offset_entries[k] -
tableseg->slice_offset_entries[k][tableseg->slice[tableseg->nb_delta_entries-1]-1] -
tableseg->element_delta[tableseg->nb_delta_entries-1];
} else
size = 0;
if (tableseg->slice[n_delta] > 0)
pos += tableseg->slice_offset_entries[k][tableseg->slice[n_delta]-1];
pos += tableseg->element_delta[n_delta];
} else
size = 0;
flags = !(tableseg->flag_entries[k] & 0x30) ? AVINDEX_KEYFRAME : 0;
} else {
pos = (int64_t)k * tableseg->edit_unit_byte_count + accumulated_offset;
if (n_delta < tableseg->nb_delta_entries - 1)
size = tableseg->element_delta[n_delta+1] - tableseg->element_delta[n_delta];
else {
/* use smaller size for last sample if we should */
if (last_sample_size && k == duration - 1)
size = last_sample_size;
else
size = tableseg->edit_unit_byte_count;
if (tableseg->nb_delta_entries)
size -= tableseg->element_delta[tableseg->nb_delta_entries-1];
}
if (n_delta < tableseg->nb_delta_entries)
pos += tableseg->element_delta[n_delta];
flags = AVINDEX_KEYFRAME;
}
if (mxf_absolute_bodysid_offset(mxf, tableseg->body_sid, pos, &pos) < 0) {
/* probably partial file - no point going further for this stream */
break;
}
av_dlog(mxf->fc, "Stream %d IndexEntry %d TrackID %d Offset %"PRIx64" Timestamp %"PRId64"\n",
st->index, st->nb_index_entries, track_id, pos, sample_duration * st->nb_index_entries);
if ((ret = av_add_index_entry(st, pos, sample_duration * st->nb_index_entries, size, 0, flags)) < 0)
return ret;
}
accumulated_offset += segment_size;
}
av_free(sorted_segments);
return 0;
}
| true | FFmpeg | f028d4d1c393a13c66e828d45ba8412c0b4df6da | static int mxf_parse_index(MXFContext *mxf, int track_id, AVStream *st)
{
int64_t accumulated_offset = 0;
int j, k, ret, nb_sorted_segments;
MXFIndexTableSegment **sorted_segments;
int n_delta = track_id - 1;
if (track_id < 1) {
av_log(mxf->fc, AV_LOG_ERROR, "TrackID not positive: %i\n", track_id);
return AVERROR_INVALIDDATA;
}
if ((ret = mxf_get_sorted_table_segments(mxf, &nb_sorted_segments, &sorted_segments)))
return ret;
for (j = 0; j < nb_sorted_segments; j++) {
int duration, sample_duration = 1, last_sample_size = 0;
int64_t segment_size;
MXFIndexTableSegment *tableseg = sorted_segments[j];
if (j > 0 && tableseg->body_sid != sorted_segments[j-1]->body_sid)
accumulated_offset = 0;
if (n_delta >= tableseg->nb_delta_entries && st->index != 0)
continue;
duration = tableseg->index_duration > 0 ? tableseg->index_duration :
st->duration - st->nb_index_entries;
segment_size = tableseg->edit_unit_byte_count * duration;
if (tableseg->edit_unit_byte_count && tableseg->edit_unit_byte_count < 32
&& !tableseg->index_duration) {
sample_duration = 8192;
last_sample_size = (duration % sample_duration) * tableseg->edit_unit_byte_count;
tableseg->edit_unit_byte_count *= sample_duration;
duration /= sample_duration;
if (last_sample_size) duration++;
}
for (k = 0; k < duration; k++) {
int64_t pos;
int size, flags = 0;
if (k < tableseg->nb_index_entries) {
pos = tableseg->stream_offset_entries[k];
if (n_delta < tableseg->nb_delta_entries) {
if (n_delta < tableseg->nb_delta_entries - 1) {
size =
tableseg->slice_offset_entries[k][tableseg->slice[n_delta+1]-1] +
tableseg->element_delta[n_delta+1] -
tableseg->element_delta[n_delta];
if (tableseg->slice[n_delta] > 0)
size -= tableseg->slice_offset_entries[k][tableseg->slice[n_delta]-1];
} else if (k < duration - 1) {
size = tableseg->stream_offset_entries[k+1] -
tableseg->stream_offset_entries[k] -
tableseg->slice_offset_entries[k][tableseg->slice[tableseg->nb_delta_entries-1]-1] -
tableseg->element_delta[tableseg->nb_delta_entries-1];
} else
size = 0;
if (tableseg->slice[n_delta] > 0)
pos += tableseg->slice_offset_entries[k][tableseg->slice[n_delta]-1];
pos += tableseg->element_delta[n_delta];
} else
size = 0;
flags = !(tableseg->flag_entries[k] & 0x30) ? AVINDEX_KEYFRAME : 0;
} else {
pos = (int64_t)k * tableseg->edit_unit_byte_count + accumulated_offset;
if (n_delta < tableseg->nb_delta_entries - 1)
size = tableseg->element_delta[n_delta+1] - tableseg->element_delta[n_delta];
else {
if (last_sample_size && k == duration - 1)
size = last_sample_size;
else
size = tableseg->edit_unit_byte_count;
if (tableseg->nb_delta_entries)
size -= tableseg->element_delta[tableseg->nb_delta_entries-1];
}
if (n_delta < tableseg->nb_delta_entries)
pos += tableseg->element_delta[n_delta];
flags = AVINDEX_KEYFRAME;
}
if (mxf_absolute_bodysid_offset(mxf, tableseg->body_sid, pos, &pos) < 0) {
break;
}
av_dlog(mxf->fc, "Stream %d IndexEntry %d TrackID %d Offset %"PRIx64" Timestamp %"PRId64"\n",
st->index, st->nb_index_entries, track_id, pos, sample_duration * st->nb_index_entries);
if ((ret = av_add_index_entry(st, pos, sample_duration * st->nb_index_entries, size, 0, flags)) < 0)
return ret;
}
accumulated_offset += segment_size;
}
av_free(sorted_segments);
return 0;
}
| {
"code": [
" } else {",
"static int mxf_parse_index(MXFContext *mxf, int track_id, AVStream *st)",
" int64_t accumulated_offset = 0;",
" int j, k, ret, nb_sorted_segments;",
" MXFIndexTableSegment **sorted_segments;",
" if (track_id < 1) {",
" av_log(mxf->fc, AV_LOG_ERROR, \"TrackID not positive: %i\\n\", track_id);",
" return AVERROR_INVALIDDATA;",
" if ((ret = mxf_get_sorted_table_segments(mxf, &nb_sorted_segments, &sorted_segments)))",
" return ret;",
" for (j = 0; j < nb_sorted_segments; j++) {",
" int duration, sample_duration = 1, last_sample_size = 0;",
" int64_t segment_size;",
" MXFIndexTableSegment *tableseg = sorted_segments[j];",
" if (j > 0 && tableseg->body_sid != sorted_segments[j-1]->body_sid)",
" accumulated_offset = 0;",
" if (n_delta >= tableseg->nb_delta_entries && st->index != 0)",
" continue;",
" duration = tableseg->index_duration > 0 ? tableseg->index_duration :",
" st->duration - st->nb_index_entries;",
" segment_size = tableseg->edit_unit_byte_count * duration;",
" if (tableseg->edit_unit_byte_count && tableseg->edit_unit_byte_count < 32",
" && !tableseg->index_duration) {",
" sample_duration = 8192;",
" last_sample_size = (duration % sample_duration) * tableseg->edit_unit_byte_count;",
" tableseg->edit_unit_byte_count *= sample_duration;",
" duration /= sample_duration;",
" if (last_sample_size) duration++;",
" for (k = 0; k < duration; k++) {",
" int64_t pos;",
" int size, flags = 0;",
" if (k < tableseg->nb_index_entries) {",
" pos = tableseg->stream_offset_entries[k];",
" if (n_delta < tableseg->nb_delta_entries) {",
" if (n_delta < tableseg->nb_delta_entries - 1) {",
" size =",
" tableseg->slice_offset_entries[k][tableseg->slice[n_delta+1]-1] +",
" tableseg->element_delta[n_delta+1] -",
" tableseg->element_delta[n_delta];",
" if (tableseg->slice[n_delta] > 0)",
" size -= tableseg->slice_offset_entries[k][tableseg->slice[n_delta]-1];",
" } else if (k < duration - 1) {",
" size = tableseg->stream_offset_entries[k+1] -",
" tableseg->stream_offset_entries[k] -",
" tableseg->slice_offset_entries[k][tableseg->slice[tableseg->nb_delta_entries-1]-1] -",
" tableseg->element_delta[tableseg->nb_delta_entries-1];",
" } else",
" size = 0;",
" if (tableseg->slice[n_delta] > 0)",
" pos += tableseg->slice_offset_entries[k][tableseg->slice[n_delta]-1];",
" pos += tableseg->element_delta[n_delta];",
" } else",
" size = 0;",
" flags = !(tableseg->flag_entries[k] & 0x30) ? AVINDEX_KEYFRAME : 0;",
" } else {",
" pos = (int64_t)k * tableseg->edit_unit_byte_count + accumulated_offset;",
" if (n_delta < tableseg->nb_delta_entries - 1)",
" size = tableseg->element_delta[n_delta+1] - tableseg->element_delta[n_delta];",
" else {",
" if (last_sample_size && k == duration - 1)",
" size = last_sample_size;",
" size = tableseg->edit_unit_byte_count;",
" if (tableseg->nb_delta_entries)",
" size -= tableseg->element_delta[tableseg->nb_delta_entries-1];",
" if (n_delta < tableseg->nb_delta_entries)",
" pos += tableseg->element_delta[n_delta];",
" flags = AVINDEX_KEYFRAME;",
" if (mxf_absolute_bodysid_offset(mxf, tableseg->body_sid, pos, &pos) < 0) {",
" break;",
" av_dlog(mxf->fc, \"Stream %d IndexEntry %d TrackID %d Offset %\"PRIx64\" Timestamp %\"PRId64\"\\n\",",
" st->index, st->nb_index_entries, track_id, pos, sample_duration * st->nb_index_entries);",
" if ((ret = av_add_index_entry(st, pos, sample_duration * st->nb_index_entries, size, 0, flags)) < 0)",
" return ret;",
" accumulated_offset += segment_size;",
" av_free(sorted_segments);",
" return 0;"
],
"line_no": [
137,
1,
5,
7,
9,
15,
17,
19,
25,
27,
31,
33,
35,
37,
43,
45,
49,
51,
53,
55,
57,
61,
63,
69,
71,
73,
75,
77,
83,
85,
87,
91,
93,
95,
97,
99,
101,
103,
105,
107,
109,
111,
113,
115,
117,
119,
121,
123,
125,
127,
129,
131,
133,
135,
137,
139,
141,
143,
145,
149,
151,
155,
157,
159,
163,
129,
167,
173,
177,
183,
185,
189,
191,
195,
201,
205
]
} | static int FUNC_0(MXFContext *VAR_0, int VAR_1, AVStream *VAR_2)
{
int64_t accumulated_offset = 0;
int VAR_3, VAR_4, VAR_5, VAR_6;
MXFIndexTableSegment **sorted_segments;
int VAR_7 = VAR_1 - 1;
if (VAR_1 < 1) {
av_log(VAR_0->fc, AV_LOG_ERROR, "TrackID not positive: %i\n", VAR_1);
return AVERROR_INVALIDDATA;
}
if ((VAR_5 = mxf_get_sorted_table_segments(VAR_0, &VAR_6, &sorted_segments)))
return VAR_5;
for (VAR_3 = 0; VAR_3 < VAR_6; VAR_3++) {
int VAR_8, VAR_9 = 1, VAR_10 = 0;
int64_t segment_size;
MXFIndexTableSegment *tableseg = sorted_segments[VAR_3];
if (VAR_3 > 0 && tableseg->body_sid != sorted_segments[VAR_3-1]->body_sid)
accumulated_offset = 0;
if (VAR_7 >= tableseg->nb_delta_entries && VAR_2->index != 0)
continue;
VAR_8 = tableseg->index_duration > 0 ? tableseg->index_duration :
VAR_2->VAR_8 - VAR_2->nb_index_entries;
segment_size = tableseg->edit_unit_byte_count * VAR_8;
if (tableseg->edit_unit_byte_count && tableseg->edit_unit_byte_count < 32
&& !tableseg->index_duration) {
VAR_9 = 8192;
VAR_10 = (VAR_8 % VAR_9) * tableseg->edit_unit_byte_count;
tableseg->edit_unit_byte_count *= VAR_9;
VAR_8 /= VAR_9;
if (VAR_10) VAR_8++;
}
for (VAR_4 = 0; VAR_4 < VAR_8; VAR_4++) {
int64_t pos;
int VAR_11, VAR_12 = 0;
if (VAR_4 < tableseg->nb_index_entries) {
pos = tableseg->stream_offset_entries[VAR_4];
if (VAR_7 < tableseg->nb_delta_entries) {
if (VAR_7 < tableseg->nb_delta_entries - 1) {
VAR_11 =
tableseg->slice_offset_entries[VAR_4][tableseg->slice[VAR_7+1]-1] +
tableseg->element_delta[VAR_7+1] -
tableseg->element_delta[VAR_7];
if (tableseg->slice[VAR_7] > 0)
VAR_11 -= tableseg->slice_offset_entries[VAR_4][tableseg->slice[VAR_7]-1];
} else if (VAR_4 < VAR_8 - 1) {
VAR_11 = tableseg->stream_offset_entries[VAR_4+1] -
tableseg->stream_offset_entries[VAR_4] -
tableseg->slice_offset_entries[VAR_4][tableseg->slice[tableseg->nb_delta_entries-1]-1] -
tableseg->element_delta[tableseg->nb_delta_entries-1];
} else
VAR_11 = 0;
if (tableseg->slice[VAR_7] > 0)
pos += tableseg->slice_offset_entries[VAR_4][tableseg->slice[VAR_7]-1];
pos += tableseg->element_delta[VAR_7];
} else
VAR_11 = 0;
VAR_12 = !(tableseg->flag_entries[VAR_4] & 0x30) ? AVINDEX_KEYFRAME : 0;
} else {
pos = (int64_t)VAR_4 * tableseg->edit_unit_byte_count + accumulated_offset;
if (VAR_7 < tableseg->nb_delta_entries - 1)
VAR_11 = tableseg->element_delta[VAR_7+1] - tableseg->element_delta[VAR_7];
else {
if (VAR_10 && VAR_4 == VAR_8 - 1)
VAR_11 = VAR_10;
else
VAR_11 = tableseg->edit_unit_byte_count;
if (tableseg->nb_delta_entries)
VAR_11 -= tableseg->element_delta[tableseg->nb_delta_entries-1];
}
if (VAR_7 < tableseg->nb_delta_entries)
pos += tableseg->element_delta[VAR_7];
VAR_12 = AVINDEX_KEYFRAME;
}
if (mxf_absolute_bodysid_offset(VAR_0, tableseg->body_sid, pos, &pos) < 0) {
break;
}
av_dlog(VAR_0->fc, "Stream %d IndexEntry %d TrackID %d Offset %"PRIx64" Timestamp %"PRId64"\n",
VAR_2->index, VAR_2->nb_index_entries, VAR_1, pos, VAR_9 * VAR_2->nb_index_entries);
if ((VAR_5 = av_add_index_entry(VAR_2, pos, VAR_9 * VAR_2->nb_index_entries, VAR_11, 0, VAR_12)) < 0)
return VAR_5;
}
accumulated_offset += segment_size;
}
av_free(sorted_segments);
return 0;
}
| [
"static int FUNC_0(MXFContext *VAR_0, int VAR_1, AVStream *VAR_2)\n{",
"int64_t accumulated_offset = 0;",
"int VAR_3, VAR_4, VAR_5, VAR_6;",
"MXFIndexTableSegment **sorted_segments;",
"int VAR_7 = VAR_1 - 1;",
"if (VAR_1 < 1) {",
"av_log(VAR_0->fc, AV_LOG_ERROR, \"TrackID not positive: %i\\n\", VAR_1);",
"return AVERROR_INVALIDDATA;",
"}",
"if ((VAR_5 = mxf_get_sorted_table_segments(VAR_0, &VAR_6, &sorted_segments)))\nreturn VAR_5;",
"for (VAR_3 = 0; VAR_3 < VAR_6; VAR_3++) {",
"int VAR_8, VAR_9 = 1, VAR_10 = 0;",
"int64_t segment_size;",
"MXFIndexTableSegment *tableseg = sorted_segments[VAR_3];",
"if (VAR_3 > 0 && tableseg->body_sid != sorted_segments[VAR_3-1]->body_sid)\naccumulated_offset = 0;",
"if (VAR_7 >= tableseg->nb_delta_entries && VAR_2->index != 0)\ncontinue;",
"VAR_8 = tableseg->index_duration > 0 ? tableseg->index_duration :\nVAR_2->VAR_8 - VAR_2->nb_index_entries;",
"segment_size = tableseg->edit_unit_byte_count * VAR_8;",
"if (tableseg->edit_unit_byte_count && tableseg->edit_unit_byte_count < 32\n&& !tableseg->index_duration) {",
"VAR_9 = 8192;",
"VAR_10 = (VAR_8 % VAR_9) * tableseg->edit_unit_byte_count;",
"tableseg->edit_unit_byte_count *= VAR_9;",
"VAR_8 /= VAR_9;",
"if (VAR_10) VAR_8++;",
"}",
"for (VAR_4 = 0; VAR_4 < VAR_8; VAR_4++) {",
"int64_t pos;",
"int VAR_11, VAR_12 = 0;",
"if (VAR_4 < tableseg->nb_index_entries) {",
"pos = tableseg->stream_offset_entries[VAR_4];",
"if (VAR_7 < tableseg->nb_delta_entries) {",
"if (VAR_7 < tableseg->nb_delta_entries - 1) {",
"VAR_11 =\ntableseg->slice_offset_entries[VAR_4][tableseg->slice[VAR_7+1]-1] +\ntableseg->element_delta[VAR_7+1] -\ntableseg->element_delta[VAR_7];",
"if (tableseg->slice[VAR_7] > 0)\nVAR_11 -= tableseg->slice_offset_entries[VAR_4][tableseg->slice[VAR_7]-1];",
"} else if (VAR_4 < VAR_8 - 1) {",
"VAR_11 = tableseg->stream_offset_entries[VAR_4+1] -\ntableseg->stream_offset_entries[VAR_4] -\ntableseg->slice_offset_entries[VAR_4][tableseg->slice[tableseg->nb_delta_entries-1]-1] -\ntableseg->element_delta[tableseg->nb_delta_entries-1];",
"} else",
"VAR_11 = 0;",
"if (tableseg->slice[VAR_7] > 0)\npos += tableseg->slice_offset_entries[VAR_4][tableseg->slice[VAR_7]-1];",
"pos += tableseg->element_delta[VAR_7];",
"} else",
"VAR_11 = 0;",
"VAR_12 = !(tableseg->flag_entries[VAR_4] & 0x30) ? AVINDEX_KEYFRAME : 0;",
"} else {",
"pos = (int64_t)VAR_4 * tableseg->edit_unit_byte_count + accumulated_offset;",
"if (VAR_7 < tableseg->nb_delta_entries - 1)\nVAR_11 = tableseg->element_delta[VAR_7+1] - tableseg->element_delta[VAR_7];",
"else {",
"if (VAR_10 && VAR_4 == VAR_8 - 1)\nVAR_11 = VAR_10;",
"else\nVAR_11 = tableseg->edit_unit_byte_count;",
"if (tableseg->nb_delta_entries)\nVAR_11 -= tableseg->element_delta[tableseg->nb_delta_entries-1];",
"}",
"if (VAR_7 < tableseg->nb_delta_entries)\npos += tableseg->element_delta[VAR_7];",
"VAR_12 = AVINDEX_KEYFRAME;",
"}",
"if (mxf_absolute_bodysid_offset(VAR_0, tableseg->body_sid, pos, &pos) < 0) {",
"break;",
"}",
"av_dlog(VAR_0->fc, \"Stream %d IndexEntry %d TrackID %d Offset %\"PRIx64\" Timestamp %\"PRId64\"\\n\",\nVAR_2->index, VAR_2->nb_index_entries, VAR_1, pos, VAR_9 * VAR_2->nb_index_entries);",
"if ((VAR_5 = av_add_index_entry(VAR_2, pos, VAR_9 * VAR_2->nb_index_entries, VAR_11, 0, VAR_12)) < 0)\nreturn VAR_5;",
"}",
"accumulated_offset += segment_size;",
"}",
"av_free(sorted_segments);",
"return 0;",
"}"
] | [
1,
1,
1,
1,
0,
1,
1,
1,
0,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
0,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
0,
1,
1,
1,
0,
1,
1,
0,
1,
1,
0,
1,
1,
1,
0,
1,
1,
0,
1,
1,
0,
1,
1,
0,
1,
0,
1,
1,
0
] | [
[
1,
3
],
[
5
],
[
7
],
[
9
],
[
11
],
[
15
],
[
17
],
[
19
],
[
21
],
[
25,
27
],
[
31
],
[
33
],
[
35
],
[
37
],
[
43,
45
],
[
49,
51
],
[
53,
55
],
[
57
],
[
61,
63
],
[
69
],
[
71
],
[
73
],
[
75
],
[
77
],
[
79
],
[
83
],
[
85
],
[
87
],
[
91
],
[
93
],
[
95
],
[
97
],
[
99,
101,
103,
105
],
[
107,
109
],
[
111
],
[
113,
115,
117,
119
],
[
121
],
[
123
],
[
125,
127
],
[
129
],
[
131
],
[
133
],
[
135
],
[
137
],
[
139
],
[
141,
143
],
[
145
],
[
149,
151
],
[
153,
155
],
[
157,
159
],
[
161
],
[
163,
165
],
[
167
],
[
169
],
[
173
],
[
177
],
[
179
],
[
183,
185
],
[
189,
191
],
[
193
],
[
195
],
[
197
],
[
201
],
[
205
],
[
207
]
] |
21,461 | static void fill_picture_parameters(const AVCodecContext *avctx, AVDXVAContext *ctx, const HEVCContext *h,
DXVA_PicParams_HEVC *pp)
{
const HEVCFrame *current_picture = h->ref;
int i, j, k;
memset(pp, 0, sizeof(*pp));
pp->PicWidthInMinCbsY = h->sps->min_cb_width;
pp->PicHeightInMinCbsY = h->sps->min_cb_height;
pp->wFormatAndSequenceInfoFlags = (h->sps->chroma_format_idc << 0) |
(h->sps->separate_colour_plane_flag << 2) |
((h->sps->bit_depth - 8) << 3) |
((h->sps->bit_depth - 8) << 6) |
((h->sps->log2_max_poc_lsb - 4) << 9) |
(0 << 13) |
(0 << 14) |
(0 << 15);
fill_picture_entry(&pp->CurrPic, ff_dxva2_get_surface_index(avctx, ctx, current_picture->frame), 0);
pp->sps_max_dec_pic_buffering_minus1 = h->sps->temporal_layer[h->sps->max_sub_layers - 1].max_dec_pic_buffering - 1;
pp->log2_min_luma_coding_block_size_minus3 = h->sps->log2_min_cb_size - 3;
pp->log2_diff_max_min_luma_coding_block_size = h->sps->log2_diff_max_min_coding_block_size;
pp->log2_min_transform_block_size_minus2 = h->sps->log2_min_tb_size - 2;
pp->log2_diff_max_min_transform_block_size = h->sps->log2_max_trafo_size - h->sps->log2_min_tb_size;
pp->max_transform_hierarchy_depth_inter = h->sps->max_transform_hierarchy_depth_inter;
pp->max_transform_hierarchy_depth_intra = h->sps->max_transform_hierarchy_depth_intra;
pp->num_short_term_ref_pic_sets = h->sps->nb_st_rps;
pp->num_long_term_ref_pics_sps = h->sps->num_long_term_ref_pics_sps;
pp->num_ref_idx_l0_default_active_minus1 = h->pps->num_ref_idx_l0_default_active - 1;
pp->num_ref_idx_l1_default_active_minus1 = h->pps->num_ref_idx_l1_default_active - 1;
pp->init_qp_minus26 = h->pps->pic_init_qp_minus26;
if (h->sh.short_term_ref_pic_set_sps_flag == 0 && h->sh.short_term_rps) {
pp->ucNumDeltaPocsOfRefRpsIdx = h->sh.short_term_rps->num_delta_pocs;
pp->wNumBitsForShortTermRPSInSlice = h->sh.short_term_ref_pic_set_size;
}
pp->dwCodingParamToolFlags = (h->sps->scaling_list_enable_flag << 0) |
(h->sps->amp_enabled_flag << 1) |
(h->sps->sao_enabled << 2) |
(h->sps->pcm_enabled_flag << 3) |
((h->sps->pcm_enabled_flag ? (h->sps->pcm.bit_depth - 1) : 0) << 4) |
((h->sps->pcm_enabled_flag ? (h->sps->pcm.bit_depth_chroma - 1) : 0) << 8) |
((h->sps->pcm_enabled_flag ? (h->sps->pcm.log2_min_pcm_cb_size - 3) : 0) << 12) |
((h->sps->pcm_enabled_flag ? (h->sps->pcm.log2_max_pcm_cb_size - h->sps->pcm.log2_min_pcm_cb_size) : 0) << 14) |
(h->sps->pcm.loop_filter_disable_flag << 16) |
(h->sps->long_term_ref_pics_present_flag << 17) |
(h->sps->sps_temporal_mvp_enabled_flag << 18) |
(h->sps->sps_strong_intra_smoothing_enable_flag << 19) |
(h->pps->dependent_slice_segments_enabled_flag << 20) |
(h->pps->output_flag_present_flag << 21) |
(h->pps->num_extra_slice_header_bits << 22) |
(h->pps->sign_data_hiding_flag << 25) |
(h->pps->cabac_init_present_flag << 26) |
(0 << 27);
pp->dwCodingSettingPicturePropertyFlags = (h->pps->constrained_intra_pred_flag << 0) |
(h->pps->transform_skip_enabled_flag << 1) |
(h->pps->cu_qp_delta_enabled_flag << 2) |
(h->pps->pic_slice_level_chroma_qp_offsets_present_flag << 3) |
(h->pps->weighted_pred_flag << 4) |
(h->pps->weighted_bipred_flag << 5) |
(h->pps->transquant_bypass_enable_flag << 6) |
(h->pps->tiles_enabled_flag << 7) |
(h->pps->entropy_coding_sync_enabled_flag << 8) |
(h->pps->uniform_spacing_flag << 9) |
((h->pps->tiles_enabled_flag ? h->pps->loop_filter_across_tiles_enabled_flag : 0) << 10) |
(h->pps->seq_loop_filter_across_slices_enabled_flag << 11) |
(h->pps->deblocking_filter_override_enabled_flag << 12) |
(h->pps->disable_dbf << 13) |
(h->pps->lists_modification_present_flag << 14) |
(h->pps->slice_header_extension_present_flag << 15) |
(IS_IRAP(h) << 16) |
(IS_IDR(h) << 17) |
/* IntraPicFlag */
(IS_IRAP(h) << 18) |
(0 << 19);
pp->pps_cb_qp_offset = h->pps->cb_qp_offset;
pp->pps_cr_qp_offset = h->pps->cr_qp_offset;
if (h->pps->tiles_enabled_flag) {
pp->num_tile_columns_minus1 = h->pps->num_tile_columns - 1;
pp->num_tile_rows_minus1 = h->pps->num_tile_rows - 1;
if (!h->pps->uniform_spacing_flag) {
for (i = 0; i < h->pps->num_tile_columns; i++)
pp->column_width_minus1[i] = h->pps->column_width[i] - 1;
for (i = 0; i < h->pps->num_tile_rows; i++)
pp->row_height_minus1[i] = h->pps->row_height[i] - 1;
}
}
pp->diff_cu_qp_delta_depth = h->pps->diff_cu_qp_delta_depth;
pp->pps_beta_offset_div2 = h->pps->beta_offset / 2;
pp->pps_tc_offset_div2 = h->pps->tc_offset / 2;
pp->log2_parallel_merge_level_minus2 = h->pps->log2_parallel_merge_level - 2;
pp->CurrPicOrderCntVal = h->poc;
// empty the lists
memset(&pp->RefPicList, 0xff, sizeof(pp->RefPicList));
memset(&pp->RefPicSetStCurrBefore, 0xff, sizeof(pp->RefPicSetStCurrBefore));
memset(&pp->RefPicSetStCurrAfter, 0xff, sizeof(pp->RefPicSetStCurrAfter));
memset(&pp->RefPicSetLtCurr, 0xff, sizeof(pp->RefPicSetLtCurr));
// fill RefPicList from the DPB
for (i = 0, j = 0; i < FF_ARRAY_ELEMS(h->DPB); i++) {
const HEVCFrame *frame = &h->DPB[i];
if (frame != current_picture && (frame->flags & (HEVC_FRAME_FLAG_LONG_REF | HEVC_FRAME_FLAG_SHORT_REF))) {
fill_picture_entry(&pp->RefPicList[j], ff_dxva2_get_surface_index(avctx, ctx, frame->frame), !!(frame->flags & HEVC_FRAME_FLAG_LONG_REF));
pp->PicOrderCntValList[j] = frame->poc;
j++;
}
}
#define DO_REF_LIST(ref_idx, ref_list) { \
const RefPicList *rpl = &h->rps[ref_idx]; \
av_assert0(rpl->nb_refs <= FF_ARRAY_ELEMS(pp->ref_list)); \
for (j = 0, k = 0; j < rpl->nb_refs; j++) { \
if (rpl->ref[j]) { \
pp->ref_list[k] = get_refpic_index(pp, ff_dxva2_get_surface_index(avctx, ctx, rpl->ref[j]->frame)); \
k++; \
} \
} \
}
// Fill short term and long term lists
DO_REF_LIST(ST_CURR_BEF, RefPicSetStCurrBefore);
DO_REF_LIST(ST_CURR_AFT, RefPicSetStCurrAfter);
DO_REF_LIST(LT_CURR, RefPicSetLtCurr);
pp->StatusReportFeedbackNumber = 1 + DXVA_CONTEXT_REPORT_ID(avctx, ctx)++;
}
| true | FFmpeg | c7bd6a54af1b5bf290deff928aab7897ce6b99a8 | static void fill_picture_parameters(const AVCodecContext *avctx, AVDXVAContext *ctx, const HEVCContext *h,
DXVA_PicParams_HEVC *pp)
{
const HEVCFrame *current_picture = h->ref;
int i, j, k;
memset(pp, 0, sizeof(*pp));
pp->PicWidthInMinCbsY = h->sps->min_cb_width;
pp->PicHeightInMinCbsY = h->sps->min_cb_height;
pp->wFormatAndSequenceInfoFlags = (h->sps->chroma_format_idc << 0) |
(h->sps->separate_colour_plane_flag << 2) |
((h->sps->bit_depth - 8) << 3) |
((h->sps->bit_depth - 8) << 6) |
((h->sps->log2_max_poc_lsb - 4) << 9) |
(0 << 13) |
(0 << 14) |
(0 << 15);
fill_picture_entry(&pp->CurrPic, ff_dxva2_get_surface_index(avctx, ctx, current_picture->frame), 0);
pp->sps_max_dec_pic_buffering_minus1 = h->sps->temporal_layer[h->sps->max_sub_layers - 1].max_dec_pic_buffering - 1;
pp->log2_min_luma_coding_block_size_minus3 = h->sps->log2_min_cb_size - 3;
pp->log2_diff_max_min_luma_coding_block_size = h->sps->log2_diff_max_min_coding_block_size;
pp->log2_min_transform_block_size_minus2 = h->sps->log2_min_tb_size - 2;
pp->log2_diff_max_min_transform_block_size = h->sps->log2_max_trafo_size - h->sps->log2_min_tb_size;
pp->max_transform_hierarchy_depth_inter = h->sps->max_transform_hierarchy_depth_inter;
pp->max_transform_hierarchy_depth_intra = h->sps->max_transform_hierarchy_depth_intra;
pp->num_short_term_ref_pic_sets = h->sps->nb_st_rps;
pp->num_long_term_ref_pics_sps = h->sps->num_long_term_ref_pics_sps;
pp->num_ref_idx_l0_default_active_minus1 = h->pps->num_ref_idx_l0_default_active - 1;
pp->num_ref_idx_l1_default_active_minus1 = h->pps->num_ref_idx_l1_default_active - 1;
pp->init_qp_minus26 = h->pps->pic_init_qp_minus26;
if (h->sh.short_term_ref_pic_set_sps_flag == 0 && h->sh.short_term_rps) {
pp->ucNumDeltaPocsOfRefRpsIdx = h->sh.short_term_rps->num_delta_pocs;
pp->wNumBitsForShortTermRPSInSlice = h->sh.short_term_ref_pic_set_size;
}
pp->dwCodingParamToolFlags = (h->sps->scaling_list_enable_flag << 0) |
(h->sps->amp_enabled_flag << 1) |
(h->sps->sao_enabled << 2) |
(h->sps->pcm_enabled_flag << 3) |
((h->sps->pcm_enabled_flag ? (h->sps->pcm.bit_depth - 1) : 0) << 4) |
((h->sps->pcm_enabled_flag ? (h->sps->pcm.bit_depth_chroma - 1) : 0) << 8) |
((h->sps->pcm_enabled_flag ? (h->sps->pcm.log2_min_pcm_cb_size - 3) : 0) << 12) |
((h->sps->pcm_enabled_flag ? (h->sps->pcm.log2_max_pcm_cb_size - h->sps->pcm.log2_min_pcm_cb_size) : 0) << 14) |
(h->sps->pcm.loop_filter_disable_flag << 16) |
(h->sps->long_term_ref_pics_present_flag << 17) |
(h->sps->sps_temporal_mvp_enabled_flag << 18) |
(h->sps->sps_strong_intra_smoothing_enable_flag << 19) |
(h->pps->dependent_slice_segments_enabled_flag << 20) |
(h->pps->output_flag_present_flag << 21) |
(h->pps->num_extra_slice_header_bits << 22) |
(h->pps->sign_data_hiding_flag << 25) |
(h->pps->cabac_init_present_flag << 26) |
(0 << 27);
pp->dwCodingSettingPicturePropertyFlags = (h->pps->constrained_intra_pred_flag << 0) |
(h->pps->transform_skip_enabled_flag << 1) |
(h->pps->cu_qp_delta_enabled_flag << 2) |
(h->pps->pic_slice_level_chroma_qp_offsets_present_flag << 3) |
(h->pps->weighted_pred_flag << 4) |
(h->pps->weighted_bipred_flag << 5) |
(h->pps->transquant_bypass_enable_flag << 6) |
(h->pps->tiles_enabled_flag << 7) |
(h->pps->entropy_coding_sync_enabled_flag << 8) |
(h->pps->uniform_spacing_flag << 9) |
((h->pps->tiles_enabled_flag ? h->pps->loop_filter_across_tiles_enabled_flag : 0) << 10) |
(h->pps->seq_loop_filter_across_slices_enabled_flag << 11) |
(h->pps->deblocking_filter_override_enabled_flag << 12) |
(h->pps->disable_dbf << 13) |
(h->pps->lists_modification_present_flag << 14) |
(h->pps->slice_header_extension_present_flag << 15) |
(IS_IRAP(h) << 16) |
(IS_IDR(h) << 17) |
(IS_IRAP(h) << 18) |
(0 << 19);
pp->pps_cb_qp_offset = h->pps->cb_qp_offset;
pp->pps_cr_qp_offset = h->pps->cr_qp_offset;
if (h->pps->tiles_enabled_flag) {
pp->num_tile_columns_minus1 = h->pps->num_tile_columns - 1;
pp->num_tile_rows_minus1 = h->pps->num_tile_rows - 1;
if (!h->pps->uniform_spacing_flag) {
for (i = 0; i < h->pps->num_tile_columns; i++)
pp->column_width_minus1[i] = h->pps->column_width[i] - 1;
for (i = 0; i < h->pps->num_tile_rows; i++)
pp->row_height_minus1[i] = h->pps->row_height[i] - 1;
}
}
pp->diff_cu_qp_delta_depth = h->pps->diff_cu_qp_delta_depth;
pp->pps_beta_offset_div2 = h->pps->beta_offset / 2;
pp->pps_tc_offset_div2 = h->pps->tc_offset / 2;
pp->log2_parallel_merge_level_minus2 = h->pps->log2_parallel_merge_level - 2;
pp->CurrPicOrderCntVal = h->poc;
memset(&pp->RefPicList, 0xff, sizeof(pp->RefPicList));
memset(&pp->RefPicSetStCurrBefore, 0xff, sizeof(pp->RefPicSetStCurrBefore));
memset(&pp->RefPicSetStCurrAfter, 0xff, sizeof(pp->RefPicSetStCurrAfter));
memset(&pp->RefPicSetLtCurr, 0xff, sizeof(pp->RefPicSetLtCurr));
for (i = 0, j = 0; i < FF_ARRAY_ELEMS(h->DPB); i++) {
const HEVCFrame *frame = &h->DPB[i];
if (frame != current_picture && (frame->flags & (HEVC_FRAME_FLAG_LONG_REF | HEVC_FRAME_FLAG_SHORT_REF))) {
fill_picture_entry(&pp->RefPicList[j], ff_dxva2_get_surface_index(avctx, ctx, frame->frame), !!(frame->flags & HEVC_FRAME_FLAG_LONG_REF));
pp->PicOrderCntValList[j] = frame->poc;
j++;
}
}
#define DO_REF_LIST(ref_idx, ref_list) { \
const RefPicList *rpl = &h->rps[ref_idx]; \
av_assert0(rpl->nb_refs <= FF_ARRAY_ELEMS(pp->ref_list)); \
for (j = 0, k = 0; j < rpl->nb_refs; j++) { \
if (rpl->ref[j]) { \
pp->ref_list[k] = get_refpic_index(pp, ff_dxva2_get_surface_index(avctx, ctx, rpl->ref[j]->frame)); \
k++; \
} \
} \
}
DO_REF_LIST(ST_CURR_BEF, RefPicSetStCurrBefore);
DO_REF_LIST(ST_CURR_AFT, RefPicSetStCurrAfter);
DO_REF_LIST(LT_CURR, RefPicSetLtCurr);
pp->StatusReportFeedbackNumber = 1 + DXVA_CONTEXT_REPORT_ID(avctx, ctx)++;
}
| {
"code": [
" int i, j, k;",
" memset(&pp->RefPicList, 0xff, sizeof(pp->RefPicList));",
" memset(&pp->RefPicSetStCurrBefore, 0xff, sizeof(pp->RefPicSetStCurrBefore));",
" memset(&pp->RefPicSetStCurrAfter, 0xff, sizeof(pp->RefPicSetStCurrAfter));",
" memset(&pp->RefPicSetLtCurr, 0xff, sizeof(pp->RefPicSetLtCurr));",
" for (i = 0, j = 0; i < FF_ARRAY_ELEMS(h->DPB); i++) {",
" const HEVCFrame *frame = &h->DPB[i];",
" if (frame != current_picture && (frame->flags & (HEVC_FRAME_FLAG_LONG_REF | HEVC_FRAME_FLAG_SHORT_REF))) {",
" fill_picture_entry(&pp->RefPicList[j], ff_dxva2_get_surface_index(avctx, ctx, frame->frame), !!(frame->flags & HEVC_FRAME_FLAG_LONG_REF));",
" pp->PicOrderCntValList[j] = frame->poc;",
" av_assert0(rpl->nb_refs <= FF_ARRAY_ELEMS(pp->ref_list)); \\",
" for (j = 0, k = 0; j < rpl->nb_refs; j++) { \\",
" if (rpl->ref[j]) { \\",
" pp->ref_list[k] = get_refpic_index(pp, ff_dxva2_get_surface_index(avctx, ctx, rpl->ref[j]->frame)); \\",
" k++; \\",
" } \\"
],
"line_no": [
9,
207,
209,
211,
213,
219,
221,
223,
225,
227,
241,
243,
245,
247,
249,
251
]
} | static void FUNC_0(const AVCodecContext *VAR_0, AVDXVAContext *VAR_1, const HEVCContext *VAR_2,
DXVA_PicParams_HEVC *VAR_3)
{
const HEVCFrame *VAR_4 = VAR_2->ref;
int VAR_5, VAR_6, VAR_7;
memset(VAR_3, 0, sizeof(*VAR_3));
VAR_3->PicWidthInMinCbsY = VAR_2->sps->min_cb_width;
VAR_3->PicHeightInMinCbsY = VAR_2->sps->min_cb_height;
VAR_3->wFormatAndSequenceInfoFlags = (VAR_2->sps->chroma_format_idc << 0) |
(VAR_2->sps->separate_colour_plane_flag << 2) |
((VAR_2->sps->bit_depth - 8) << 3) |
((VAR_2->sps->bit_depth - 8) << 6) |
((VAR_2->sps->log2_max_poc_lsb - 4) << 9) |
(0 << 13) |
(0 << 14) |
(0 << 15);
fill_picture_entry(&VAR_3->CurrPic, ff_dxva2_get_surface_index(VAR_0, VAR_1, VAR_4->frame), 0);
VAR_3->sps_max_dec_pic_buffering_minus1 = VAR_2->sps->temporal_layer[VAR_2->sps->max_sub_layers - 1].max_dec_pic_buffering - 1;
VAR_3->log2_min_luma_coding_block_size_minus3 = VAR_2->sps->log2_min_cb_size - 3;
VAR_3->log2_diff_max_min_luma_coding_block_size = VAR_2->sps->log2_diff_max_min_coding_block_size;
VAR_3->log2_min_transform_block_size_minus2 = VAR_2->sps->log2_min_tb_size - 2;
VAR_3->log2_diff_max_min_transform_block_size = VAR_2->sps->log2_max_trafo_size - VAR_2->sps->log2_min_tb_size;
VAR_3->max_transform_hierarchy_depth_inter = VAR_2->sps->max_transform_hierarchy_depth_inter;
VAR_3->max_transform_hierarchy_depth_intra = VAR_2->sps->max_transform_hierarchy_depth_intra;
VAR_3->num_short_term_ref_pic_sets = VAR_2->sps->nb_st_rps;
VAR_3->num_long_term_ref_pics_sps = VAR_2->sps->num_long_term_ref_pics_sps;
VAR_3->num_ref_idx_l0_default_active_minus1 = VAR_2->pps->num_ref_idx_l0_default_active - 1;
VAR_3->num_ref_idx_l1_default_active_minus1 = VAR_2->pps->num_ref_idx_l1_default_active - 1;
VAR_3->init_qp_minus26 = VAR_2->pps->pic_init_qp_minus26;
if (VAR_2->sh.short_term_ref_pic_set_sps_flag == 0 && VAR_2->sh.short_term_rps) {
VAR_3->ucNumDeltaPocsOfRefRpsIdx = VAR_2->sh.short_term_rps->num_delta_pocs;
VAR_3->wNumBitsForShortTermRPSInSlice = VAR_2->sh.short_term_ref_pic_set_size;
}
VAR_3->dwCodingParamToolFlags = (VAR_2->sps->scaling_list_enable_flag << 0) |
(VAR_2->sps->amp_enabled_flag << 1) |
(VAR_2->sps->sao_enabled << 2) |
(VAR_2->sps->pcm_enabled_flag << 3) |
((VAR_2->sps->pcm_enabled_flag ? (VAR_2->sps->pcm.bit_depth - 1) : 0) << 4) |
((VAR_2->sps->pcm_enabled_flag ? (VAR_2->sps->pcm.bit_depth_chroma - 1) : 0) << 8) |
((VAR_2->sps->pcm_enabled_flag ? (VAR_2->sps->pcm.log2_min_pcm_cb_size - 3) : 0) << 12) |
((VAR_2->sps->pcm_enabled_flag ? (VAR_2->sps->pcm.log2_max_pcm_cb_size - VAR_2->sps->pcm.log2_min_pcm_cb_size) : 0) << 14) |
(VAR_2->sps->pcm.loop_filter_disable_flag << 16) |
(VAR_2->sps->long_term_ref_pics_present_flag << 17) |
(VAR_2->sps->sps_temporal_mvp_enabled_flag << 18) |
(VAR_2->sps->sps_strong_intra_smoothing_enable_flag << 19) |
(VAR_2->pps->dependent_slice_segments_enabled_flag << 20) |
(VAR_2->pps->output_flag_present_flag << 21) |
(VAR_2->pps->num_extra_slice_header_bits << 22) |
(VAR_2->pps->sign_data_hiding_flag << 25) |
(VAR_2->pps->cabac_init_present_flag << 26) |
(0 << 27);
VAR_3->dwCodingSettingPicturePropertyFlags = (VAR_2->pps->constrained_intra_pred_flag << 0) |
(VAR_2->pps->transform_skip_enabled_flag << 1) |
(VAR_2->pps->cu_qp_delta_enabled_flag << 2) |
(VAR_2->pps->pic_slice_level_chroma_qp_offsets_present_flag << 3) |
(VAR_2->pps->weighted_pred_flag << 4) |
(VAR_2->pps->weighted_bipred_flag << 5) |
(VAR_2->pps->transquant_bypass_enable_flag << 6) |
(VAR_2->pps->tiles_enabled_flag << 7) |
(VAR_2->pps->entropy_coding_sync_enabled_flag << 8) |
(VAR_2->pps->uniform_spacing_flag << 9) |
((VAR_2->pps->tiles_enabled_flag ? VAR_2->pps->loop_filter_across_tiles_enabled_flag : 0) << 10) |
(VAR_2->pps->seq_loop_filter_across_slices_enabled_flag << 11) |
(VAR_2->pps->deblocking_filter_override_enabled_flag << 12) |
(VAR_2->pps->disable_dbf << 13) |
(VAR_2->pps->lists_modification_present_flag << 14) |
(VAR_2->pps->slice_header_extension_present_flag << 15) |
(IS_IRAP(VAR_2) << 16) |
(IS_IDR(VAR_2) << 17) |
(IS_IRAP(VAR_2) << 18) |
(0 << 19);
VAR_3->pps_cb_qp_offset = VAR_2->pps->cb_qp_offset;
VAR_3->pps_cr_qp_offset = VAR_2->pps->cr_qp_offset;
if (VAR_2->pps->tiles_enabled_flag) {
VAR_3->num_tile_columns_minus1 = VAR_2->pps->num_tile_columns - 1;
VAR_3->num_tile_rows_minus1 = VAR_2->pps->num_tile_rows - 1;
if (!VAR_2->pps->uniform_spacing_flag) {
for (VAR_5 = 0; VAR_5 < VAR_2->pps->num_tile_columns; VAR_5++)
VAR_3->column_width_minus1[VAR_5] = VAR_2->pps->column_width[VAR_5] - 1;
for (VAR_5 = 0; VAR_5 < VAR_2->pps->num_tile_rows; VAR_5++)
VAR_3->row_height_minus1[VAR_5] = VAR_2->pps->row_height[VAR_5] - 1;
}
}
VAR_3->diff_cu_qp_delta_depth = VAR_2->pps->diff_cu_qp_delta_depth;
VAR_3->pps_beta_offset_div2 = VAR_2->pps->beta_offset / 2;
VAR_3->pps_tc_offset_div2 = VAR_2->pps->tc_offset / 2;
VAR_3->log2_parallel_merge_level_minus2 = VAR_2->pps->log2_parallel_merge_level - 2;
VAR_3->CurrPicOrderCntVal = VAR_2->poc;
memset(&VAR_3->RefPicList, 0xff, sizeof(VAR_3->RefPicList));
memset(&VAR_3->RefPicSetStCurrBefore, 0xff, sizeof(VAR_3->RefPicSetStCurrBefore));
memset(&VAR_3->RefPicSetStCurrAfter, 0xff, sizeof(VAR_3->RefPicSetStCurrAfter));
memset(&VAR_3->RefPicSetLtCurr, 0xff, sizeof(VAR_3->RefPicSetLtCurr));
for (VAR_5 = 0, VAR_6 = 0; VAR_5 < FF_ARRAY_ELEMS(VAR_2->DPB); VAR_5++) {
const HEVCFrame *frame = &VAR_2->DPB[VAR_5];
if (frame != VAR_4 && (frame->flags & (HEVC_FRAME_FLAG_LONG_REF | HEVC_FRAME_FLAG_SHORT_REF))) {
fill_picture_entry(&VAR_3->RefPicList[VAR_6], ff_dxva2_get_surface_index(VAR_0, VAR_1, frame->frame), !!(frame->flags & HEVC_FRAME_FLAG_LONG_REF));
VAR_3->PicOrderCntValList[VAR_6] = frame->poc;
VAR_6++;
}
}
#define DO_REF_LIST(ref_idx, ref_list) { \
const RefPicList *VAR_8 = &VAR_2->rps[ref_idx]; \
av_assert0(VAR_8->nb_refs <= FF_ARRAY_ELEMS(VAR_3->ref_list)); \
for (VAR_6 = 0, VAR_7 = 0; VAR_6 < VAR_8->nb_refs; VAR_6++) { \
if (VAR_8->ref[VAR_6]) { \
VAR_3->ref_list[VAR_7] = get_refpic_index(VAR_3, ff_dxva2_get_surface_index(VAR_0, VAR_1, VAR_8->ref[VAR_6]->frame)); \
VAR_7++; \
} \
} \
}
DO_REF_LIST(ST_CURR_BEF, RefPicSetStCurrBefore);
DO_REF_LIST(ST_CURR_AFT, RefPicSetStCurrAfter);
DO_REF_LIST(LT_CURR, RefPicSetLtCurr);
VAR_3->StatusReportFeedbackNumber = 1 + DXVA_CONTEXT_REPORT_ID(VAR_0, VAR_1)++;
}
| [
"static void FUNC_0(const AVCodecContext *VAR_0, AVDXVAContext *VAR_1, const HEVCContext *VAR_2,\nDXVA_PicParams_HEVC *VAR_3)\n{",
"const HEVCFrame *VAR_4 = VAR_2->ref;",
"int VAR_5, VAR_6, VAR_7;",
"memset(VAR_3, 0, sizeof(*VAR_3));",
"VAR_3->PicWidthInMinCbsY = VAR_2->sps->min_cb_width;",
"VAR_3->PicHeightInMinCbsY = VAR_2->sps->min_cb_height;",
"VAR_3->wFormatAndSequenceInfoFlags = (VAR_2->sps->chroma_format_idc << 0) |\n(VAR_2->sps->separate_colour_plane_flag << 2) |\n((VAR_2->sps->bit_depth - 8) << 3) |\n((VAR_2->sps->bit_depth - 8) << 6) |\n((VAR_2->sps->log2_max_poc_lsb - 4) << 9) |\n(0 << 13) |\n(0 << 14) |\n(0 << 15);",
"fill_picture_entry(&VAR_3->CurrPic, ff_dxva2_get_surface_index(VAR_0, VAR_1, VAR_4->frame), 0);",
"VAR_3->sps_max_dec_pic_buffering_minus1 = VAR_2->sps->temporal_layer[VAR_2->sps->max_sub_layers - 1].max_dec_pic_buffering - 1;",
"VAR_3->log2_min_luma_coding_block_size_minus3 = VAR_2->sps->log2_min_cb_size - 3;",
"VAR_3->log2_diff_max_min_luma_coding_block_size = VAR_2->sps->log2_diff_max_min_coding_block_size;",
"VAR_3->log2_min_transform_block_size_minus2 = VAR_2->sps->log2_min_tb_size - 2;",
"VAR_3->log2_diff_max_min_transform_block_size = VAR_2->sps->log2_max_trafo_size - VAR_2->sps->log2_min_tb_size;",
"VAR_3->max_transform_hierarchy_depth_inter = VAR_2->sps->max_transform_hierarchy_depth_inter;",
"VAR_3->max_transform_hierarchy_depth_intra = VAR_2->sps->max_transform_hierarchy_depth_intra;",
"VAR_3->num_short_term_ref_pic_sets = VAR_2->sps->nb_st_rps;",
"VAR_3->num_long_term_ref_pics_sps = VAR_2->sps->num_long_term_ref_pics_sps;",
"VAR_3->num_ref_idx_l0_default_active_minus1 = VAR_2->pps->num_ref_idx_l0_default_active - 1;",
"VAR_3->num_ref_idx_l1_default_active_minus1 = VAR_2->pps->num_ref_idx_l1_default_active - 1;",
"VAR_3->init_qp_minus26 = VAR_2->pps->pic_init_qp_minus26;",
"if (VAR_2->sh.short_term_ref_pic_set_sps_flag == 0 && VAR_2->sh.short_term_rps) {",
"VAR_3->ucNumDeltaPocsOfRefRpsIdx = VAR_2->sh.short_term_rps->num_delta_pocs;",
"VAR_3->wNumBitsForShortTermRPSInSlice = VAR_2->sh.short_term_ref_pic_set_size;",
"}",
"VAR_3->dwCodingParamToolFlags = (VAR_2->sps->scaling_list_enable_flag << 0) |\n(VAR_2->sps->amp_enabled_flag << 1) |\n(VAR_2->sps->sao_enabled << 2) |\n(VAR_2->sps->pcm_enabled_flag << 3) |\n((VAR_2->sps->pcm_enabled_flag ? (VAR_2->sps->pcm.bit_depth - 1) : 0) << 4) |\n((VAR_2->sps->pcm_enabled_flag ? (VAR_2->sps->pcm.bit_depth_chroma - 1) : 0) << 8) |\n((VAR_2->sps->pcm_enabled_flag ? (VAR_2->sps->pcm.log2_min_pcm_cb_size - 3) : 0) << 12) |\n((VAR_2->sps->pcm_enabled_flag ? (VAR_2->sps->pcm.log2_max_pcm_cb_size - VAR_2->sps->pcm.log2_min_pcm_cb_size) : 0) << 14) |\n(VAR_2->sps->pcm.loop_filter_disable_flag << 16) |\n(VAR_2->sps->long_term_ref_pics_present_flag << 17) |\n(VAR_2->sps->sps_temporal_mvp_enabled_flag << 18) |\n(VAR_2->sps->sps_strong_intra_smoothing_enable_flag << 19) |\n(VAR_2->pps->dependent_slice_segments_enabled_flag << 20) |\n(VAR_2->pps->output_flag_present_flag << 21) |\n(VAR_2->pps->num_extra_slice_header_bits << 22) |\n(VAR_2->pps->sign_data_hiding_flag << 25) |\n(VAR_2->pps->cabac_init_present_flag << 26) |\n(0 << 27);",
"VAR_3->dwCodingSettingPicturePropertyFlags = (VAR_2->pps->constrained_intra_pred_flag << 0) |\n(VAR_2->pps->transform_skip_enabled_flag << 1) |\n(VAR_2->pps->cu_qp_delta_enabled_flag << 2) |\n(VAR_2->pps->pic_slice_level_chroma_qp_offsets_present_flag << 3) |\n(VAR_2->pps->weighted_pred_flag << 4) |\n(VAR_2->pps->weighted_bipred_flag << 5) |\n(VAR_2->pps->transquant_bypass_enable_flag << 6) |\n(VAR_2->pps->tiles_enabled_flag << 7) |\n(VAR_2->pps->entropy_coding_sync_enabled_flag << 8) |\n(VAR_2->pps->uniform_spacing_flag << 9) |\n((VAR_2->pps->tiles_enabled_flag ? VAR_2->pps->loop_filter_across_tiles_enabled_flag : 0) << 10) |\n(VAR_2->pps->seq_loop_filter_across_slices_enabled_flag << 11) |\n(VAR_2->pps->deblocking_filter_override_enabled_flag << 12) |\n(VAR_2->pps->disable_dbf << 13) |\n(VAR_2->pps->lists_modification_present_flag << 14) |\n(VAR_2->pps->slice_header_extension_present_flag << 15) |\n(IS_IRAP(VAR_2) << 16) |\n(IS_IDR(VAR_2) << 17) |\n(IS_IRAP(VAR_2) << 18) |\n(0 << 19);",
"VAR_3->pps_cb_qp_offset = VAR_2->pps->cb_qp_offset;",
"VAR_3->pps_cr_qp_offset = VAR_2->pps->cr_qp_offset;",
"if (VAR_2->pps->tiles_enabled_flag) {",
"VAR_3->num_tile_columns_minus1 = VAR_2->pps->num_tile_columns - 1;",
"VAR_3->num_tile_rows_minus1 = VAR_2->pps->num_tile_rows - 1;",
"if (!VAR_2->pps->uniform_spacing_flag) {",
"for (VAR_5 = 0; VAR_5 < VAR_2->pps->num_tile_columns; VAR_5++)",
"VAR_3->column_width_minus1[VAR_5] = VAR_2->pps->column_width[VAR_5] - 1;",
"for (VAR_5 = 0; VAR_5 < VAR_2->pps->num_tile_rows; VAR_5++)",
"VAR_3->row_height_minus1[VAR_5] = VAR_2->pps->row_height[VAR_5] - 1;",
"}",
"}",
"VAR_3->diff_cu_qp_delta_depth = VAR_2->pps->diff_cu_qp_delta_depth;",
"VAR_3->pps_beta_offset_div2 = VAR_2->pps->beta_offset / 2;",
"VAR_3->pps_tc_offset_div2 = VAR_2->pps->tc_offset / 2;",
"VAR_3->log2_parallel_merge_level_minus2 = VAR_2->pps->log2_parallel_merge_level - 2;",
"VAR_3->CurrPicOrderCntVal = VAR_2->poc;",
"memset(&VAR_3->RefPicList, 0xff, sizeof(VAR_3->RefPicList));",
"memset(&VAR_3->RefPicSetStCurrBefore, 0xff, sizeof(VAR_3->RefPicSetStCurrBefore));",
"memset(&VAR_3->RefPicSetStCurrAfter, 0xff, sizeof(VAR_3->RefPicSetStCurrAfter));",
"memset(&VAR_3->RefPicSetLtCurr, 0xff, sizeof(VAR_3->RefPicSetLtCurr));",
"for (VAR_5 = 0, VAR_6 = 0; VAR_5 < FF_ARRAY_ELEMS(VAR_2->DPB); VAR_5++) {",
"const HEVCFrame *frame = &VAR_2->DPB[VAR_5];",
"if (frame != VAR_4 && (frame->flags & (HEVC_FRAME_FLAG_LONG_REF | HEVC_FRAME_FLAG_SHORT_REF))) {",
"fill_picture_entry(&VAR_3->RefPicList[VAR_6], ff_dxva2_get_surface_index(VAR_0, VAR_1, frame->frame), !!(frame->flags & HEVC_FRAME_FLAG_LONG_REF));",
"VAR_3->PicOrderCntValList[VAR_6] = frame->poc;",
"VAR_6++;",
"}",
"}",
"#define DO_REF_LIST(ref_idx, ref_list) { \\",
"const RefPicList *VAR_8 = &VAR_2->rps[ref_idx]; \\",
"av_assert0(VAR_8->nb_refs <= FF_ARRAY_ELEMS(VAR_3->ref_list)); \\",
"for (VAR_6 = 0, VAR_7 = 0; VAR_6 < VAR_8->nb_refs; VAR_6++) { \\",
"if (VAR_8->ref[VAR_6]) { \\",
"VAR_3->ref_list[VAR_7] = get_refpic_index(VAR_3, ff_dxva2_get_surface_index(VAR_0, VAR_1, VAR_8->ref[VAR_6]->frame)); \\",
"VAR_7++; \\",
"} \\",
"} \\",
"}",
"DO_REF_LIST(ST_CURR_BEF, RefPicSetStCurrBefore);",
"DO_REF_LIST(ST_CURR_AFT, RefPicSetStCurrAfter);",
"DO_REF_LIST(LT_CURR, RefPicSetLtCurr);",
"VAR_3->StatusReportFeedbackNumber = 1 + DXVA_CONTEXT_REPORT_ID(VAR_0, VAR_1)++;",
"}"
] | [
0,
0,
1,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
1,
1,
1,
1,
1,
1,
1,
1,
1,
0,
0,
0,
0,
0,
1,
1,
1,
1,
1,
1,
0,
0,
0,
0,
0,
0,
0
] | [
[
1,
3,
5
],
[
7
],
[
9
],
[
13
],
[
17
],
[
19
],
[
23,
25,
27,
29,
31,
33,
35,
37
],
[
41
],
[
45
],
[
47
],
[
49
],
[
51
],
[
53
],
[
55
],
[
57
],
[
59
],
[
61
],
[
65
],
[
67
],
[
69
],
[
73
],
[
75
],
[
77
],
[
79
],
[
83,
85,
87,
89,
91,
93,
95,
97,
99,
101,
103,
105,
107,
109,
111,
113,
115,
117
],
[
121,
123,
125,
127,
129,
131,
133,
135,
137,
139,
141,
143,
145,
147,
149,
151,
153,
155,
159,
161
],
[
163
],
[
165
],
[
167
],
[
169
],
[
171
],
[
175
],
[
177
],
[
179
],
[
183
],
[
185
],
[
187
],
[
189
],
[
193
],
[
195
],
[
197
],
[
199
],
[
201
],
[
207
],
[
209
],
[
211
],
[
213
],
[
219
],
[
221
],
[
223
],
[
225
],
[
227
],
[
229
],
[
231
],
[
233
],
[
237
],
[
239
],
[
241
],
[
243
],
[
245
],
[
247
],
[
249
],
[
251
],
[
253
],
[
255
],
[
261
],
[
263
],
[
265
],
[
269
],
[
271
]
] |
21,462 | static void isa_ipmi_bmc_check(Object *obj, const char *name,
Object *val, Error **errp)
{
IPMIBmc *bmc = IPMI_BMC(val);
if (bmc->intf)
error_setg(errp, "BMC object is already in use");
}
| true | qemu | 8f5d58ef2c92d7b82d9a6eeefd7c8854a183ba4a | static void isa_ipmi_bmc_check(Object *obj, const char *name,
Object *val, Error **errp)
{
IPMIBmc *bmc = IPMI_BMC(val);
if (bmc->intf)
error_setg(errp, "BMC object is already in use");
}
| {
"code": [
"static void isa_ipmi_bmc_check(Object *obj, const char *name,"
],
"line_no": [
1
]
} | static void FUNC_0(Object *VAR_0, const char *VAR_1,
Object *VAR_2, Error **VAR_3)
{
IPMIBmc *bmc = IPMI_BMC(VAR_2);
if (bmc->intf)
error_setg(VAR_3, "BMC object is already in use");
}
| [
"static void FUNC_0(Object *VAR_0, const char *VAR_1,\nObject *VAR_2, Error **VAR_3)\n{",
"IPMIBmc *bmc = IPMI_BMC(VAR_2);",
"if (bmc->intf)\nerror_setg(VAR_3, \"BMC object is already in use\");",
"}"
] | [
1,
0,
0,
0
] | [
[
1,
3,
5
],
[
7
],
[
11,
13
],
[
15
]
] |
21,463 | av_cold int ff_yuv2rgb_c_init_tables(SwsContext *c, const int inv_table[4],
int fullRange, int brightness,
int contrast, int saturation)
{
const int isRgb = c->dstFormat == AV_PIX_FMT_RGB32 ||
c->dstFormat == AV_PIX_FMT_RGB32_1 ||
c->dstFormat == AV_PIX_FMT_BGR24 ||
c->dstFormat == AV_PIX_FMT_RGB565BE ||
c->dstFormat == AV_PIX_FMT_RGB565LE ||
c->dstFormat == AV_PIX_FMT_RGB555BE ||
c->dstFormat == AV_PIX_FMT_RGB555LE ||
c->dstFormat == AV_PIX_FMT_RGB444BE ||
c->dstFormat == AV_PIX_FMT_RGB444LE ||
c->dstFormat == AV_PIX_FMT_RGB8 ||
c->dstFormat == AV_PIX_FMT_RGB4 ||
c->dstFormat == AV_PIX_FMT_RGB4_BYTE ||
c->dstFormat == AV_PIX_FMT_MONOBLACK;
const int isNotNe = c->dstFormat == AV_PIX_FMT_NE(RGB565LE, RGB565BE) ||
c->dstFormat == AV_PIX_FMT_NE(RGB555LE, RGB555BE) ||
c->dstFormat == AV_PIX_FMT_NE(RGB444LE, RGB444BE) ||
c->dstFormat == AV_PIX_FMT_NE(BGR565LE, BGR565BE) ||
c->dstFormat == AV_PIX_FMT_NE(BGR555LE, BGR555BE) ||
c->dstFormat == AV_PIX_FMT_NE(BGR444LE, BGR444BE);
const int bpp = c->dstFormatBpp;
uint8_t *y_table;
uint16_t *y_table16;
uint32_t *y_table32;
int i, base, rbase, gbase, bbase, av_uninit(abase), needAlpha;
const int yoffs = fullRange ? 384 : 326;
int64_t crv = inv_table[0];
int64_t cbu = inv_table[1];
int64_t cgu = -inv_table[2];
int64_t cgv = -inv_table[3];
int64_t cy = 1 << 16;
int64_t oy = 0;
int64_t yb = 0;
if (!fullRange) {
cy = (cy * 255) / 219;
oy = 16 << 16;
} else {
crv = (crv * 224) / 255;
cbu = (cbu * 224) / 255;
cgu = (cgu * 224) / 255;
cgv = (cgv * 224) / 255;
}
cy = (cy * contrast) >> 16;
crv = (crv * contrast * saturation) >> 32;
cbu = (cbu * contrast * saturation) >> 32;
cgu = (cgu * contrast * saturation) >> 32;
cgv = (cgv * contrast * saturation) >> 32;
oy -= 256 * brightness;
c->uOffset = 0x0400040004000400LL;
c->vOffset = 0x0400040004000400LL;
c->yCoeff = roundToInt16(cy * 8192) * 0x0001000100010001ULL;
c->vrCoeff = roundToInt16(crv * 8192) * 0x0001000100010001ULL;
c->ubCoeff = roundToInt16(cbu * 8192) * 0x0001000100010001ULL;
c->vgCoeff = roundToInt16(cgv * 8192) * 0x0001000100010001ULL;
c->ugCoeff = roundToInt16(cgu * 8192) * 0x0001000100010001ULL;
c->yOffset = roundToInt16(oy * 8) * 0x0001000100010001ULL;
c->yuv2rgb_y_coeff = (int16_t)roundToInt16(cy << 13);
c->yuv2rgb_y_offset = (int16_t)roundToInt16(oy << 9);
c->yuv2rgb_v2r_coeff = (int16_t)roundToInt16(crv << 13);
c->yuv2rgb_v2g_coeff = (int16_t)roundToInt16(cgv << 13);
c->yuv2rgb_u2g_coeff = (int16_t)roundToInt16(cgu << 13);
c->yuv2rgb_u2b_coeff = (int16_t)roundToInt16(cbu << 13);
//scale coefficients by cy
crv = ((crv << 16) + 0x8000) / cy;
cbu = ((cbu << 16) + 0x8000) / cy;
cgu = ((cgu << 16) + 0x8000) / cy;
cgv = ((cgv << 16) + 0x8000) / cy;
av_freep(&c->yuvTable);
switch (bpp) {
case 1:
c->yuvTable = av_malloc(1024);
y_table = c->yuvTable;
yb = -(384 << 16) - oy;
for (i = 0; i < 1024 - 110; i++) {
y_table[i + 110] = av_clip_uint8((yb + 0x8000) >> 16) >> 7;
yb += cy;
}
fill_table(c->table_gU, 1, cgu, y_table + yoffs);
fill_gv_table(c->table_gV, 1, cgv);
break;
case 4:
case 4 | 128:
rbase = isRgb ? 3 : 0;
gbase = 1;
bbase = isRgb ? 0 : 3;
c->yuvTable = av_malloc(1024 * 3);
y_table = c->yuvTable;
yb = -(384 << 16) - oy;
for (i = 0; i < 1024 - 110; i++) {
int yval = av_clip_uint8((yb + 0x8000) >> 16);
y_table[i + 110] = (yval >> 7) << rbase;
y_table[i + 37 + 1024] = ((yval + 43) / 85) << gbase;
y_table[i + 110 + 2048] = (yval >> 7) << bbase;
yb += cy;
}
fill_table(c->table_rV, 1, crv, y_table + yoffs);
fill_table(c->table_gU, 1, cgu, y_table + yoffs + 1024);
fill_table(c->table_bU, 1, cbu, y_table + yoffs + 2048);
fill_gv_table(c->table_gV, 1, cgv);
break;
case 8:
rbase = isRgb ? 5 : 0;
gbase = isRgb ? 2 : 3;
bbase = isRgb ? 0 : 6;
c->yuvTable = av_malloc(1024 * 3);
y_table = c->yuvTable;
yb = -(384 << 16) - oy;
for (i = 0; i < 1024 - 38; i++) {
int yval = av_clip_uint8((yb + 0x8000) >> 16);
y_table[i + 16] = ((yval + 18) / 36) << rbase;
y_table[i + 16 + 1024] = ((yval + 18) / 36) << gbase;
y_table[i + 37 + 2048] = ((yval + 43) / 85) << bbase;
yb += cy;
}
fill_table(c->table_rV, 1, crv, y_table + yoffs);
fill_table(c->table_gU, 1, cgu, y_table + yoffs + 1024);
fill_table(c->table_bU, 1, cbu, y_table + yoffs + 2048);
fill_gv_table(c->table_gV, 1, cgv);
break;
case 12:
rbase = isRgb ? 8 : 0;
gbase = 4;
bbase = isRgb ? 0 : 8;
c->yuvTable = av_malloc(1024 * 3 * 2);
y_table16 = c->yuvTable;
yb = -(384 << 16) - oy;
for (i = 0; i < 1024; i++) {
uint8_t yval = av_clip_uint8((yb + 0x8000) >> 16);
y_table16[i] = (yval >> 4) << rbase;
y_table16[i + 1024] = (yval >> 4) << gbase;
y_table16[i + 2048] = (yval >> 4) << bbase;
yb += cy;
}
if (isNotNe)
for (i = 0; i < 1024 * 3; i++)
y_table16[i] = av_bswap16(y_table16[i]);
fill_table(c->table_rV, 2, crv, y_table16 + yoffs);
fill_table(c->table_gU, 2, cgu, y_table16 + yoffs + 1024);
fill_table(c->table_bU, 2, cbu, y_table16 + yoffs + 2048);
fill_gv_table(c->table_gV, 2, cgv);
break;
case 15:
case 16:
rbase = isRgb ? bpp - 5 : 0;
gbase = 5;
bbase = isRgb ? 0 : (bpp - 5);
c->yuvTable = av_malloc(1024 * 3 * 2);
y_table16 = c->yuvTable;
yb = -(384 << 16) - oy;
for (i = 0; i < 1024; i++) {
uint8_t yval = av_clip_uint8((yb + 0x8000) >> 16);
y_table16[i] = (yval >> 3) << rbase;
y_table16[i + 1024] = (yval >> (18 - bpp)) << gbase;
y_table16[i + 2048] = (yval >> 3) << bbase;
yb += cy;
}
if (isNotNe)
for (i = 0; i < 1024 * 3; i++)
y_table16[i] = av_bswap16(y_table16[i]);
fill_table(c->table_rV, 2, crv, y_table16 + yoffs);
fill_table(c->table_gU, 2, cgu, y_table16 + yoffs + 1024);
fill_table(c->table_bU, 2, cbu, y_table16 + yoffs + 2048);
fill_gv_table(c->table_gV, 2, cgv);
break;
case 24:
case 48:
c->yuvTable = av_malloc(1024);
y_table = c->yuvTable;
yb = -(384 << 16) - oy;
for (i = 0; i < 1024; i++) {
y_table[i] = av_clip_uint8((yb + 0x8000) >> 16);
yb += cy;
}
fill_table(c->table_rV, 1, crv, y_table + yoffs);
fill_table(c->table_gU, 1, cgu, y_table + yoffs);
fill_table(c->table_bU, 1, cbu, y_table + yoffs);
fill_gv_table(c->table_gV, 1, cgv);
break;
case 32:
case 64:
base = (c->dstFormat == AV_PIX_FMT_RGB32_1 ||
c->dstFormat == AV_PIX_FMT_BGR32_1) ? 8 : 0;
rbase = base + (isRgb ? 16 : 0);
gbase = base + 8;
bbase = base + (isRgb ? 0 : 16);
needAlpha = CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat);
if (!needAlpha)
abase = (base + 24) & 31;
c->yuvTable = av_malloc(1024 * 3 * 4);
y_table32 = c->yuvTable;
yb = -(384 << 16) - oy;
for (i = 0; i < 1024; i++) {
unsigned yval = av_clip_uint8((yb + 0x8000) >> 16);
y_table32[i] = (yval << rbase) +
(needAlpha ? 0 : (255u << abase));
y_table32[i + 1024] = yval << gbase;
y_table32[i + 2048] = yval << bbase;
yb += cy;
}
fill_table(c->table_rV, 4, crv, y_table32 + yoffs);
fill_table(c->table_gU, 4, cgu, y_table32 + yoffs + 1024);
fill_table(c->table_bU, 4, cbu, y_table32 + yoffs + 2048);
fill_gv_table(c->table_gV, 4, cgv);
break;
default:
if(!isPlanar(c->dstFormat) || bpp <= 24)
av_log(c, AV_LOG_ERROR, "%ibpp not supported by yuv2rgb\n", bpp);
return -1;
}
return 0;
}
| true | FFmpeg | d0a3bc13025baab8d48cbcf4c698daf2f0c44adc | av_cold int ff_yuv2rgb_c_init_tables(SwsContext *c, const int inv_table[4],
int fullRange, int brightness,
int contrast, int saturation)
{
const int isRgb = c->dstFormat == AV_PIX_FMT_RGB32 ||
c->dstFormat == AV_PIX_FMT_RGB32_1 ||
c->dstFormat == AV_PIX_FMT_BGR24 ||
c->dstFormat == AV_PIX_FMT_RGB565BE ||
c->dstFormat == AV_PIX_FMT_RGB565LE ||
c->dstFormat == AV_PIX_FMT_RGB555BE ||
c->dstFormat == AV_PIX_FMT_RGB555LE ||
c->dstFormat == AV_PIX_FMT_RGB444BE ||
c->dstFormat == AV_PIX_FMT_RGB444LE ||
c->dstFormat == AV_PIX_FMT_RGB8 ||
c->dstFormat == AV_PIX_FMT_RGB4 ||
c->dstFormat == AV_PIX_FMT_RGB4_BYTE ||
c->dstFormat == AV_PIX_FMT_MONOBLACK;
const int isNotNe = c->dstFormat == AV_PIX_FMT_NE(RGB565LE, RGB565BE) ||
c->dstFormat == AV_PIX_FMT_NE(RGB555LE, RGB555BE) ||
c->dstFormat == AV_PIX_FMT_NE(RGB444LE, RGB444BE) ||
c->dstFormat == AV_PIX_FMT_NE(BGR565LE, BGR565BE) ||
c->dstFormat == AV_PIX_FMT_NE(BGR555LE, BGR555BE) ||
c->dstFormat == AV_PIX_FMT_NE(BGR444LE, BGR444BE);
const int bpp = c->dstFormatBpp;
uint8_t *y_table;
uint16_t *y_table16;
uint32_t *y_table32;
int i, base, rbase, gbase, bbase, av_uninit(abase), needAlpha;
const int yoffs = fullRange ? 384 : 326;
int64_t crv = inv_table[0];
int64_t cbu = inv_table[1];
int64_t cgu = -inv_table[2];
int64_t cgv = -inv_table[3];
int64_t cy = 1 << 16;
int64_t oy = 0;
int64_t yb = 0;
if (!fullRange) {
cy = (cy * 255) / 219;
oy = 16 << 16;
} else {
crv = (crv * 224) / 255;
cbu = (cbu * 224) / 255;
cgu = (cgu * 224) / 255;
cgv = (cgv * 224) / 255;
}
cy = (cy * contrast) >> 16;
crv = (crv * contrast * saturation) >> 32;
cbu = (cbu * contrast * saturation) >> 32;
cgu = (cgu * contrast * saturation) >> 32;
cgv = (cgv * contrast * saturation) >> 32;
oy -= 256 * brightness;
c->uOffset = 0x0400040004000400LL;
c->vOffset = 0x0400040004000400LL;
c->yCoeff = roundToInt16(cy * 8192) * 0x0001000100010001ULL;
c->vrCoeff = roundToInt16(crv * 8192) * 0x0001000100010001ULL;
c->ubCoeff = roundToInt16(cbu * 8192) * 0x0001000100010001ULL;
c->vgCoeff = roundToInt16(cgv * 8192) * 0x0001000100010001ULL;
c->ugCoeff = roundToInt16(cgu * 8192) * 0x0001000100010001ULL;
c->yOffset = roundToInt16(oy * 8) * 0x0001000100010001ULL;
c->yuv2rgb_y_coeff = (int16_t)roundToInt16(cy << 13);
c->yuv2rgb_y_offset = (int16_t)roundToInt16(oy << 9);
c->yuv2rgb_v2r_coeff = (int16_t)roundToInt16(crv << 13);
c->yuv2rgb_v2g_coeff = (int16_t)roundToInt16(cgv << 13);
c->yuv2rgb_u2g_coeff = (int16_t)roundToInt16(cgu << 13);
c->yuv2rgb_u2b_coeff = (int16_t)roundToInt16(cbu << 13);
crv = ((crv << 16) + 0x8000) / cy;
cbu = ((cbu << 16) + 0x8000) / cy;
cgu = ((cgu << 16) + 0x8000) / cy;
cgv = ((cgv << 16) + 0x8000) / cy;
av_freep(&c->yuvTable);
switch (bpp) {
case 1:
c->yuvTable = av_malloc(1024);
y_table = c->yuvTable;
yb = -(384 << 16) - oy;
for (i = 0; i < 1024 - 110; i++) {
y_table[i + 110] = av_clip_uint8((yb + 0x8000) >> 16) >> 7;
yb += cy;
}
fill_table(c->table_gU, 1, cgu, y_table + yoffs);
fill_gv_table(c->table_gV, 1, cgv);
break;
case 4:
case 4 | 128:
rbase = isRgb ? 3 : 0;
gbase = 1;
bbase = isRgb ? 0 : 3;
c->yuvTable = av_malloc(1024 * 3);
y_table = c->yuvTable;
yb = -(384 << 16) - oy;
for (i = 0; i < 1024 - 110; i++) {
int yval = av_clip_uint8((yb + 0x8000) >> 16);
y_table[i + 110] = (yval >> 7) << rbase;
y_table[i + 37 + 1024] = ((yval + 43) / 85) << gbase;
y_table[i + 110 + 2048] = (yval >> 7) << bbase;
yb += cy;
}
fill_table(c->table_rV, 1, crv, y_table + yoffs);
fill_table(c->table_gU, 1, cgu, y_table + yoffs + 1024);
fill_table(c->table_bU, 1, cbu, y_table + yoffs + 2048);
fill_gv_table(c->table_gV, 1, cgv);
break;
case 8:
rbase = isRgb ? 5 : 0;
gbase = isRgb ? 2 : 3;
bbase = isRgb ? 0 : 6;
c->yuvTable = av_malloc(1024 * 3);
y_table = c->yuvTable;
yb = -(384 << 16) - oy;
for (i = 0; i < 1024 - 38; i++) {
int yval = av_clip_uint8((yb + 0x8000) >> 16);
y_table[i + 16] = ((yval + 18) / 36) << rbase;
y_table[i + 16 + 1024] = ((yval + 18) / 36) << gbase;
y_table[i + 37 + 2048] = ((yval + 43) / 85) << bbase;
yb += cy;
}
fill_table(c->table_rV, 1, crv, y_table + yoffs);
fill_table(c->table_gU, 1, cgu, y_table + yoffs + 1024);
fill_table(c->table_bU, 1, cbu, y_table + yoffs + 2048);
fill_gv_table(c->table_gV, 1, cgv);
break;
case 12:
rbase = isRgb ? 8 : 0;
gbase = 4;
bbase = isRgb ? 0 : 8;
c->yuvTable = av_malloc(1024 * 3 * 2);
y_table16 = c->yuvTable;
yb = -(384 << 16) - oy;
for (i = 0; i < 1024; i++) {
uint8_t yval = av_clip_uint8((yb + 0x8000) >> 16);
y_table16[i] = (yval >> 4) << rbase;
y_table16[i + 1024] = (yval >> 4) << gbase;
y_table16[i + 2048] = (yval >> 4) << bbase;
yb += cy;
}
if (isNotNe)
for (i = 0; i < 1024 * 3; i++)
y_table16[i] = av_bswap16(y_table16[i]);
fill_table(c->table_rV, 2, crv, y_table16 + yoffs);
fill_table(c->table_gU, 2, cgu, y_table16 + yoffs + 1024);
fill_table(c->table_bU, 2, cbu, y_table16 + yoffs + 2048);
fill_gv_table(c->table_gV, 2, cgv);
break;
case 15:
case 16:
rbase = isRgb ? bpp - 5 : 0;
gbase = 5;
bbase = isRgb ? 0 : (bpp - 5);
c->yuvTable = av_malloc(1024 * 3 * 2);
y_table16 = c->yuvTable;
yb = -(384 << 16) - oy;
for (i = 0; i < 1024; i++) {
uint8_t yval = av_clip_uint8((yb + 0x8000) >> 16);
y_table16[i] = (yval >> 3) << rbase;
y_table16[i + 1024] = (yval >> (18 - bpp)) << gbase;
y_table16[i + 2048] = (yval >> 3) << bbase;
yb += cy;
}
if (isNotNe)
for (i = 0; i < 1024 * 3; i++)
y_table16[i] = av_bswap16(y_table16[i]);
fill_table(c->table_rV, 2, crv, y_table16 + yoffs);
fill_table(c->table_gU, 2, cgu, y_table16 + yoffs + 1024);
fill_table(c->table_bU, 2, cbu, y_table16 + yoffs + 2048);
fill_gv_table(c->table_gV, 2, cgv);
break;
case 24:
case 48:
c->yuvTable = av_malloc(1024);
y_table = c->yuvTable;
yb = -(384 << 16) - oy;
for (i = 0; i < 1024; i++) {
y_table[i] = av_clip_uint8((yb + 0x8000) >> 16);
yb += cy;
}
fill_table(c->table_rV, 1, crv, y_table + yoffs);
fill_table(c->table_gU, 1, cgu, y_table + yoffs);
fill_table(c->table_bU, 1, cbu, y_table + yoffs);
fill_gv_table(c->table_gV, 1, cgv);
break;
case 32:
case 64:
base = (c->dstFormat == AV_PIX_FMT_RGB32_1 ||
c->dstFormat == AV_PIX_FMT_BGR32_1) ? 8 : 0;
rbase = base + (isRgb ? 16 : 0);
gbase = base + 8;
bbase = base + (isRgb ? 0 : 16);
needAlpha = CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat);
if (!needAlpha)
abase = (base + 24) & 31;
c->yuvTable = av_malloc(1024 * 3 * 4);
y_table32 = c->yuvTable;
yb = -(384 << 16) - oy;
for (i = 0; i < 1024; i++) {
unsigned yval = av_clip_uint8((yb + 0x8000) >> 16);
y_table32[i] = (yval << rbase) +
(needAlpha ? 0 : (255u << abase));
y_table32[i + 1024] = yval << gbase;
y_table32[i + 2048] = yval << bbase;
yb += cy;
}
fill_table(c->table_rV, 4, crv, y_table32 + yoffs);
fill_table(c->table_gU, 4, cgu, y_table32 + yoffs + 1024);
fill_table(c->table_bU, 4, cbu, y_table32 + yoffs + 2048);
fill_gv_table(c->table_gV, 4, cgv);
break;
default:
if(!isPlanar(c->dstFormat) || bpp <= 24)
av_log(c, AV_LOG_ERROR, "%ibpp not supported by yuv2rgb\n", bpp);
return -1;
}
return 0;
}
| {
"code": [
" crv = ((crv << 16) + 0x8000) / cy;",
" cbu = ((cbu << 16) + 0x8000) / cy;",
" cgu = ((cgu << 16) + 0x8000) / cy;",
" cgv = ((cgv << 16) + 0x8000) / cy;"
],
"line_no": [
145,
147,
149,
151
]
} | av_cold int FUNC_0(SwsContext *c, const int inv_table[4],
int fullRange, int brightness,
int contrast, int saturation)
{
const int VAR_0 = c->dstFormat == AV_PIX_FMT_RGB32 ||
c->dstFormat == AV_PIX_FMT_RGB32_1 ||
c->dstFormat == AV_PIX_FMT_BGR24 ||
c->dstFormat == AV_PIX_FMT_RGB565BE ||
c->dstFormat == AV_PIX_FMT_RGB565LE ||
c->dstFormat == AV_PIX_FMT_RGB555BE ||
c->dstFormat == AV_PIX_FMT_RGB555LE ||
c->dstFormat == AV_PIX_FMT_RGB444BE ||
c->dstFormat == AV_PIX_FMT_RGB444LE ||
c->dstFormat == AV_PIX_FMT_RGB8 ||
c->dstFormat == AV_PIX_FMT_RGB4 ||
c->dstFormat == AV_PIX_FMT_RGB4_BYTE ||
c->dstFormat == AV_PIX_FMT_MONOBLACK;
const int VAR_1 = c->dstFormat == AV_PIX_FMT_NE(RGB565LE, RGB565BE) ||
c->dstFormat == AV_PIX_FMT_NE(RGB555LE, RGB555BE) ||
c->dstFormat == AV_PIX_FMT_NE(RGB444LE, RGB444BE) ||
c->dstFormat == AV_PIX_FMT_NE(BGR565LE, BGR565BE) ||
c->dstFormat == AV_PIX_FMT_NE(BGR555LE, BGR555BE) ||
c->dstFormat == AV_PIX_FMT_NE(BGR444LE, BGR444BE);
const int VAR_2 = c->dstFormatBpp;
uint8_t *y_table;
uint16_t *y_table16;
uint32_t *y_table32;
int VAR_3, VAR_4, VAR_5, VAR_6, VAR_7, FUNC_1(abase), needAlpha;
const int VAR_8 = fullRange ? 384 : 326;
int64_t crv = inv_table[0];
int64_t cbu = inv_table[1];
int64_t cgu = -inv_table[2];
int64_t cgv = -inv_table[3];
int64_t cy = 1 << 16;
int64_t oy = 0;
int64_t yb = 0;
if (!fullRange) {
cy = (cy * 255) / 219;
oy = 16 << 16;
} else {
crv = (crv * 224) / 255;
cbu = (cbu * 224) / 255;
cgu = (cgu * 224) / 255;
cgv = (cgv * 224) / 255;
}
cy = (cy * contrast) >> 16;
crv = (crv * contrast * saturation) >> 32;
cbu = (cbu * contrast * saturation) >> 32;
cgu = (cgu * contrast * saturation) >> 32;
cgv = (cgv * contrast * saturation) >> 32;
oy -= 256 * brightness;
c->uOffset = 0x0400040004000400LL;
c->vOffset = 0x0400040004000400LL;
c->yCoeff = roundToInt16(cy * 8192) * 0x0001000100010001ULL;
c->vrCoeff = roundToInt16(crv * 8192) * 0x0001000100010001ULL;
c->ubCoeff = roundToInt16(cbu * 8192) * 0x0001000100010001ULL;
c->vgCoeff = roundToInt16(cgv * 8192) * 0x0001000100010001ULL;
c->ugCoeff = roundToInt16(cgu * 8192) * 0x0001000100010001ULL;
c->yOffset = roundToInt16(oy * 8) * 0x0001000100010001ULL;
c->yuv2rgb_y_coeff = (int16_t)roundToInt16(cy << 13);
c->yuv2rgb_y_offset = (int16_t)roundToInt16(oy << 9);
c->yuv2rgb_v2r_coeff = (int16_t)roundToInt16(crv << 13);
c->yuv2rgb_v2g_coeff = (int16_t)roundToInt16(cgv << 13);
c->yuv2rgb_u2g_coeff = (int16_t)roundToInt16(cgu << 13);
c->yuv2rgb_u2b_coeff = (int16_t)roundToInt16(cbu << 13);
crv = ((crv << 16) + 0x8000) / cy;
cbu = ((cbu << 16) + 0x8000) / cy;
cgu = ((cgu << 16) + 0x8000) / cy;
cgv = ((cgv << 16) + 0x8000) / cy;
av_freep(&c->yuvTable);
switch (VAR_2) {
case 1:
c->yuvTable = av_malloc(1024);
y_table = c->yuvTable;
yb = -(384 << 16) - oy;
for (VAR_3 = 0; VAR_3 < 1024 - 110; VAR_3++) {
y_table[VAR_3 + 110] = av_clip_uint8((yb + 0x8000) >> 16) >> 7;
yb += cy;
}
fill_table(c->table_gU, 1, cgu, y_table + VAR_8);
fill_gv_table(c->table_gV, 1, cgv);
break;
case 4:
case 4 | 128:
VAR_5 = VAR_0 ? 3 : 0;
VAR_6 = 1;
VAR_7 = VAR_0 ? 0 : 3;
c->yuvTable = av_malloc(1024 * 3);
y_table = c->yuvTable;
yb = -(384 << 16) - oy;
for (VAR_3 = 0; VAR_3 < 1024 - 110; VAR_3++) {
int VAR_10 = av_clip_uint8((yb + 0x8000) >> 16);
y_table[VAR_3 + 110] = (VAR_10 >> 7) << VAR_5;
y_table[VAR_3 + 37 + 1024] = ((VAR_10 + 43) / 85) << VAR_6;
y_table[VAR_3 + 110 + 2048] = (VAR_10 >> 7) << VAR_7;
yb += cy;
}
fill_table(c->table_rV, 1, crv, y_table + VAR_8);
fill_table(c->table_gU, 1, cgu, y_table + VAR_8 + 1024);
fill_table(c->table_bU, 1, cbu, y_table + VAR_8 + 2048);
fill_gv_table(c->table_gV, 1, cgv);
break;
case 8:
VAR_5 = VAR_0 ? 5 : 0;
VAR_6 = VAR_0 ? 2 : 3;
VAR_7 = VAR_0 ? 0 : 6;
c->yuvTable = av_malloc(1024 * 3);
y_table = c->yuvTable;
yb = -(384 << 16) - oy;
for (VAR_3 = 0; VAR_3 < 1024 - 38; VAR_3++) {
int VAR_10 = av_clip_uint8((yb + 0x8000) >> 16);
y_table[VAR_3 + 16] = ((VAR_10 + 18) / 36) << VAR_5;
y_table[VAR_3 + 16 + 1024] = ((VAR_10 + 18) / 36) << VAR_6;
y_table[VAR_3 + 37 + 2048] = ((VAR_10 + 43) / 85) << VAR_7;
yb += cy;
}
fill_table(c->table_rV, 1, crv, y_table + VAR_8);
fill_table(c->table_gU, 1, cgu, y_table + VAR_8 + 1024);
fill_table(c->table_bU, 1, cbu, y_table + VAR_8 + 2048);
fill_gv_table(c->table_gV, 1, cgv);
break;
case 12:
VAR_5 = VAR_0 ? 8 : 0;
VAR_6 = 4;
VAR_7 = VAR_0 ? 0 : 8;
c->yuvTable = av_malloc(1024 * 3 * 2);
y_table16 = c->yuvTable;
yb = -(384 << 16) - oy;
for (VAR_3 = 0; VAR_3 < 1024; VAR_3++) {
uint8_t VAR_10 = av_clip_uint8((yb + 0x8000) >> 16);
y_table16[VAR_3] = (VAR_10 >> 4) << VAR_5;
y_table16[VAR_3 + 1024] = (VAR_10 >> 4) << VAR_6;
y_table16[VAR_3 + 2048] = (VAR_10 >> 4) << VAR_7;
yb += cy;
}
if (VAR_1)
for (VAR_3 = 0; VAR_3 < 1024 * 3; VAR_3++)
y_table16[VAR_3] = av_bswap16(y_table16[VAR_3]);
fill_table(c->table_rV, 2, crv, y_table16 + VAR_8);
fill_table(c->table_gU, 2, cgu, y_table16 + VAR_8 + 1024);
fill_table(c->table_bU, 2, cbu, y_table16 + VAR_8 + 2048);
fill_gv_table(c->table_gV, 2, cgv);
break;
case 15:
case 16:
VAR_5 = VAR_0 ? VAR_2 - 5 : 0;
VAR_6 = 5;
VAR_7 = VAR_0 ? 0 : (VAR_2 - 5);
c->yuvTable = av_malloc(1024 * 3 * 2);
y_table16 = c->yuvTable;
yb = -(384 << 16) - oy;
for (VAR_3 = 0; VAR_3 < 1024; VAR_3++) {
uint8_t VAR_10 = av_clip_uint8((yb + 0x8000) >> 16);
y_table16[VAR_3] = (VAR_10 >> 3) << VAR_5;
y_table16[VAR_3 + 1024] = (VAR_10 >> (18 - VAR_2)) << VAR_6;
y_table16[VAR_3 + 2048] = (VAR_10 >> 3) << VAR_7;
yb += cy;
}
if (VAR_1)
for (VAR_3 = 0; VAR_3 < 1024 * 3; VAR_3++)
y_table16[VAR_3] = av_bswap16(y_table16[VAR_3]);
fill_table(c->table_rV, 2, crv, y_table16 + VAR_8);
fill_table(c->table_gU, 2, cgu, y_table16 + VAR_8 + 1024);
fill_table(c->table_bU, 2, cbu, y_table16 + VAR_8 + 2048);
fill_gv_table(c->table_gV, 2, cgv);
break;
case 24:
case 48:
c->yuvTable = av_malloc(1024);
y_table = c->yuvTable;
yb = -(384 << 16) - oy;
for (VAR_3 = 0; VAR_3 < 1024; VAR_3++) {
y_table[VAR_3] = av_clip_uint8((yb + 0x8000) >> 16);
yb += cy;
}
fill_table(c->table_rV, 1, crv, y_table + VAR_8);
fill_table(c->table_gU, 1, cgu, y_table + VAR_8);
fill_table(c->table_bU, 1, cbu, y_table + VAR_8);
fill_gv_table(c->table_gV, 1, cgv);
break;
case 32:
case 64:
VAR_4 = (c->dstFormat == AV_PIX_FMT_RGB32_1 ||
c->dstFormat == AV_PIX_FMT_BGR32_1) ? 8 : 0;
VAR_5 = VAR_4 + (VAR_0 ? 16 : 0);
VAR_6 = VAR_4 + 8;
VAR_7 = VAR_4 + (VAR_0 ? 0 : 16);
needAlpha = CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat);
if (!needAlpha)
abase = (VAR_4 + 24) & 31;
c->yuvTable = av_malloc(1024 * 3 * 4);
y_table32 = c->yuvTable;
yb = -(384 << 16) - oy;
for (VAR_3 = 0; VAR_3 < 1024; VAR_3++) {
unsigned VAR_10 = av_clip_uint8((yb + 0x8000) >> 16);
y_table32[VAR_3] = (VAR_10 << VAR_5) +
(needAlpha ? 0 : (255u << abase));
y_table32[VAR_3 + 1024] = VAR_10 << VAR_6;
y_table32[VAR_3 + 2048] = VAR_10 << VAR_7;
yb += cy;
}
fill_table(c->table_rV, 4, crv, y_table32 + VAR_8);
fill_table(c->table_gU, 4, cgu, y_table32 + VAR_8 + 1024);
fill_table(c->table_bU, 4, cbu, y_table32 + VAR_8 + 2048);
fill_gv_table(c->table_gV, 4, cgv);
break;
default:
if(!isPlanar(c->dstFormat) || VAR_2 <= 24)
av_log(c, AV_LOG_ERROR, "%ibpp not supported by yuv2rgb\n", VAR_2);
return -1;
}
return 0;
}
| [
"av_cold int FUNC_0(SwsContext *c, const int inv_table[4],\nint fullRange, int brightness,\nint contrast, int saturation)\n{",
"const int VAR_0 = c->dstFormat == AV_PIX_FMT_RGB32 ||\nc->dstFormat == AV_PIX_FMT_RGB32_1 ||\nc->dstFormat == AV_PIX_FMT_BGR24 ||\nc->dstFormat == AV_PIX_FMT_RGB565BE ||\nc->dstFormat == AV_PIX_FMT_RGB565LE ||\nc->dstFormat == AV_PIX_FMT_RGB555BE ||\nc->dstFormat == AV_PIX_FMT_RGB555LE ||\nc->dstFormat == AV_PIX_FMT_RGB444BE ||\nc->dstFormat == AV_PIX_FMT_RGB444LE ||\nc->dstFormat == AV_PIX_FMT_RGB8 ||\nc->dstFormat == AV_PIX_FMT_RGB4 ||\nc->dstFormat == AV_PIX_FMT_RGB4_BYTE ||\nc->dstFormat == AV_PIX_FMT_MONOBLACK;",
"const int VAR_1 = c->dstFormat == AV_PIX_FMT_NE(RGB565LE, RGB565BE) ||\nc->dstFormat == AV_PIX_FMT_NE(RGB555LE, RGB555BE) ||\nc->dstFormat == AV_PIX_FMT_NE(RGB444LE, RGB444BE) ||\nc->dstFormat == AV_PIX_FMT_NE(BGR565LE, BGR565BE) ||\nc->dstFormat == AV_PIX_FMT_NE(BGR555LE, BGR555BE) ||\nc->dstFormat == AV_PIX_FMT_NE(BGR444LE, BGR444BE);",
"const int VAR_2 = c->dstFormatBpp;",
"uint8_t *y_table;",
"uint16_t *y_table16;",
"uint32_t *y_table32;",
"int VAR_3, VAR_4, VAR_5, VAR_6, VAR_7, FUNC_1(abase), needAlpha;",
"const int VAR_8 = fullRange ? 384 : 326;",
"int64_t crv = inv_table[0];",
"int64_t cbu = inv_table[1];",
"int64_t cgu = -inv_table[2];",
"int64_t cgv = -inv_table[3];",
"int64_t cy = 1 << 16;",
"int64_t oy = 0;",
"int64_t yb = 0;",
"if (!fullRange) {",
"cy = (cy * 255) / 219;",
"oy = 16 << 16;",
"} else {",
"crv = (crv * 224) / 255;",
"cbu = (cbu * 224) / 255;",
"cgu = (cgu * 224) / 255;",
"cgv = (cgv * 224) / 255;",
"}",
"cy = (cy * contrast) >> 16;",
"crv = (crv * contrast * saturation) >> 32;",
"cbu = (cbu * contrast * saturation) >> 32;",
"cgu = (cgu * contrast * saturation) >> 32;",
"cgv = (cgv * contrast * saturation) >> 32;",
"oy -= 256 * brightness;",
"c->uOffset = 0x0400040004000400LL;",
"c->vOffset = 0x0400040004000400LL;",
"c->yCoeff = roundToInt16(cy * 8192) * 0x0001000100010001ULL;",
"c->vrCoeff = roundToInt16(crv * 8192) * 0x0001000100010001ULL;",
"c->ubCoeff = roundToInt16(cbu * 8192) * 0x0001000100010001ULL;",
"c->vgCoeff = roundToInt16(cgv * 8192) * 0x0001000100010001ULL;",
"c->ugCoeff = roundToInt16(cgu * 8192) * 0x0001000100010001ULL;",
"c->yOffset = roundToInt16(oy * 8) * 0x0001000100010001ULL;",
"c->yuv2rgb_y_coeff = (int16_t)roundToInt16(cy << 13);",
"c->yuv2rgb_y_offset = (int16_t)roundToInt16(oy << 9);",
"c->yuv2rgb_v2r_coeff = (int16_t)roundToInt16(crv << 13);",
"c->yuv2rgb_v2g_coeff = (int16_t)roundToInt16(cgv << 13);",
"c->yuv2rgb_u2g_coeff = (int16_t)roundToInt16(cgu << 13);",
"c->yuv2rgb_u2b_coeff = (int16_t)roundToInt16(cbu << 13);",
"crv = ((crv << 16) + 0x8000) / cy;",
"cbu = ((cbu << 16) + 0x8000) / cy;",
"cgu = ((cgu << 16) + 0x8000) / cy;",
"cgv = ((cgv << 16) + 0x8000) / cy;",
"av_freep(&c->yuvTable);",
"switch (VAR_2) {",
"case 1:\nc->yuvTable = av_malloc(1024);",
"y_table = c->yuvTable;",
"yb = -(384 << 16) - oy;",
"for (VAR_3 = 0; VAR_3 < 1024 - 110; VAR_3++) {",
"y_table[VAR_3 + 110] = av_clip_uint8((yb + 0x8000) >> 16) >> 7;",
"yb += cy;",
"}",
"fill_table(c->table_gU, 1, cgu, y_table + VAR_8);",
"fill_gv_table(c->table_gV, 1, cgv);",
"break;",
"case 4:\ncase 4 | 128:\nVAR_5 = VAR_0 ? 3 : 0;",
"VAR_6 = 1;",
"VAR_7 = VAR_0 ? 0 : 3;",
"c->yuvTable = av_malloc(1024 * 3);",
"y_table = c->yuvTable;",
"yb = -(384 << 16) - oy;",
"for (VAR_3 = 0; VAR_3 < 1024 - 110; VAR_3++) {",
"int VAR_10 = av_clip_uint8((yb + 0x8000) >> 16);",
"y_table[VAR_3 + 110] = (VAR_10 >> 7) << VAR_5;",
"y_table[VAR_3 + 37 + 1024] = ((VAR_10 + 43) / 85) << VAR_6;",
"y_table[VAR_3 + 110 + 2048] = (VAR_10 >> 7) << VAR_7;",
"yb += cy;",
"}",
"fill_table(c->table_rV, 1, crv, y_table + VAR_8);",
"fill_table(c->table_gU, 1, cgu, y_table + VAR_8 + 1024);",
"fill_table(c->table_bU, 1, cbu, y_table + VAR_8 + 2048);",
"fill_gv_table(c->table_gV, 1, cgv);",
"break;",
"case 8:\nVAR_5 = VAR_0 ? 5 : 0;",
"VAR_6 = VAR_0 ? 2 : 3;",
"VAR_7 = VAR_0 ? 0 : 6;",
"c->yuvTable = av_malloc(1024 * 3);",
"y_table = c->yuvTable;",
"yb = -(384 << 16) - oy;",
"for (VAR_3 = 0; VAR_3 < 1024 - 38; VAR_3++) {",
"int VAR_10 = av_clip_uint8((yb + 0x8000) >> 16);",
"y_table[VAR_3 + 16] = ((VAR_10 + 18) / 36) << VAR_5;",
"y_table[VAR_3 + 16 + 1024] = ((VAR_10 + 18) / 36) << VAR_6;",
"y_table[VAR_3 + 37 + 2048] = ((VAR_10 + 43) / 85) << VAR_7;",
"yb += cy;",
"}",
"fill_table(c->table_rV, 1, crv, y_table + VAR_8);",
"fill_table(c->table_gU, 1, cgu, y_table + VAR_8 + 1024);",
"fill_table(c->table_bU, 1, cbu, y_table + VAR_8 + 2048);",
"fill_gv_table(c->table_gV, 1, cgv);",
"break;",
"case 12:\nVAR_5 = VAR_0 ? 8 : 0;",
"VAR_6 = 4;",
"VAR_7 = VAR_0 ? 0 : 8;",
"c->yuvTable = av_malloc(1024 * 3 * 2);",
"y_table16 = c->yuvTable;",
"yb = -(384 << 16) - oy;",
"for (VAR_3 = 0; VAR_3 < 1024; VAR_3++) {",
"uint8_t VAR_10 = av_clip_uint8((yb + 0x8000) >> 16);",
"y_table16[VAR_3] = (VAR_10 >> 4) << VAR_5;",
"y_table16[VAR_3 + 1024] = (VAR_10 >> 4) << VAR_6;",
"y_table16[VAR_3 + 2048] = (VAR_10 >> 4) << VAR_7;",
"yb += cy;",
"}",
"if (VAR_1)\nfor (VAR_3 = 0; VAR_3 < 1024 * 3; VAR_3++)",
"y_table16[VAR_3] = av_bswap16(y_table16[VAR_3]);",
"fill_table(c->table_rV, 2, crv, y_table16 + VAR_8);",
"fill_table(c->table_gU, 2, cgu, y_table16 + VAR_8 + 1024);",
"fill_table(c->table_bU, 2, cbu, y_table16 + VAR_8 + 2048);",
"fill_gv_table(c->table_gV, 2, cgv);",
"break;",
"case 15:\ncase 16:\nVAR_5 = VAR_0 ? VAR_2 - 5 : 0;",
"VAR_6 = 5;",
"VAR_7 = VAR_0 ? 0 : (VAR_2 - 5);",
"c->yuvTable = av_malloc(1024 * 3 * 2);",
"y_table16 = c->yuvTable;",
"yb = -(384 << 16) - oy;",
"for (VAR_3 = 0; VAR_3 < 1024; VAR_3++) {",
"uint8_t VAR_10 = av_clip_uint8((yb + 0x8000) >> 16);",
"y_table16[VAR_3] = (VAR_10 >> 3) << VAR_5;",
"y_table16[VAR_3 + 1024] = (VAR_10 >> (18 - VAR_2)) << VAR_6;",
"y_table16[VAR_3 + 2048] = (VAR_10 >> 3) << VAR_7;",
"yb += cy;",
"}",
"if (VAR_1)\nfor (VAR_3 = 0; VAR_3 < 1024 * 3; VAR_3++)",
"y_table16[VAR_3] = av_bswap16(y_table16[VAR_3]);",
"fill_table(c->table_rV, 2, crv, y_table16 + VAR_8);",
"fill_table(c->table_gU, 2, cgu, y_table16 + VAR_8 + 1024);",
"fill_table(c->table_bU, 2, cbu, y_table16 + VAR_8 + 2048);",
"fill_gv_table(c->table_gV, 2, cgv);",
"break;",
"case 24:\ncase 48:\nc->yuvTable = av_malloc(1024);",
"y_table = c->yuvTable;",
"yb = -(384 << 16) - oy;",
"for (VAR_3 = 0; VAR_3 < 1024; VAR_3++) {",
"y_table[VAR_3] = av_clip_uint8((yb + 0x8000) >> 16);",
"yb += cy;",
"}",
"fill_table(c->table_rV, 1, crv, y_table + VAR_8);",
"fill_table(c->table_gU, 1, cgu, y_table + VAR_8);",
"fill_table(c->table_bU, 1, cbu, y_table + VAR_8);",
"fill_gv_table(c->table_gV, 1, cgv);",
"break;",
"case 32:\ncase 64:\nVAR_4 = (c->dstFormat == AV_PIX_FMT_RGB32_1 ||\nc->dstFormat == AV_PIX_FMT_BGR32_1) ? 8 : 0;",
"VAR_5 = VAR_4 + (VAR_0 ? 16 : 0);",
"VAR_6 = VAR_4 + 8;",
"VAR_7 = VAR_4 + (VAR_0 ? 0 : 16);",
"needAlpha = CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat);",
"if (!needAlpha)\nabase = (VAR_4 + 24) & 31;",
"c->yuvTable = av_malloc(1024 * 3 * 4);",
"y_table32 = c->yuvTable;",
"yb = -(384 << 16) - oy;",
"for (VAR_3 = 0; VAR_3 < 1024; VAR_3++) {",
"unsigned VAR_10 = av_clip_uint8((yb + 0x8000) >> 16);",
"y_table32[VAR_3] = (VAR_10 << VAR_5) +\n(needAlpha ? 0 : (255u << abase));",
"y_table32[VAR_3 + 1024] = VAR_10 << VAR_6;",
"y_table32[VAR_3 + 2048] = VAR_10 << VAR_7;",
"yb += cy;",
"}",
"fill_table(c->table_rV, 4, crv, y_table32 + VAR_8);",
"fill_table(c->table_gU, 4, cgu, y_table32 + VAR_8 + 1024);",
"fill_table(c->table_bU, 4, cbu, y_table32 + VAR_8 + 2048);",
"fill_gv_table(c->table_gV, 4, cgv);",
"break;",
"default:\nif(!isPlanar(c->dstFormat) || VAR_2 <= 24)\nav_log(c, AV_LOG_ERROR, \"%ibpp not supported by yuv2rgb\\n\", VAR_2);",
"return -1;",
"}",
"return 0;",
"}"
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
1,
1,
1,
1,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | [
[
1,
3,
5,
7
],
[
9,
11,
13,
15,
17,
19,
21,
23,
25,
27,
29,
31,
33
],
[
35,
37,
39,
41,
43,
45
],
[
47
],
[
49
],
[
51
],
[
53
],
[
55
],
[
57
],
[
61
],
[
63
],
[
65
],
[
67
],
[
69
],
[
71
],
[
73
],
[
77
],
[
79
],
[
81
],
[
83
],
[
85
],
[
87
],
[
89
],
[
91
],
[
93
],
[
97
],
[
99
],
[
101
],
[
103
],
[
105
],
[
107
],
[
111
],
[
113
],
[
115
],
[
117
],
[
119
],
[
121
],
[
123
],
[
125
],
[
129
],
[
131
],
[
133
],
[
135
],
[
137
],
[
139
],
[
145
],
[
147
],
[
149
],
[
151
],
[
155
],
[
159
],
[
161,
163
],
[
165
],
[
167
],
[
169
],
[
171
],
[
173
],
[
175
],
[
177
],
[
179
],
[
181
],
[
183,
185,
187
],
[
189
],
[
191
],
[
193
],
[
195
],
[
197
],
[
199
],
[
201
],
[
203
],
[
205
],
[
207
],
[
209
],
[
211
],
[
213
],
[
215
],
[
217
],
[
219
],
[
221
],
[
223,
225
],
[
227
],
[
229
],
[
231
],
[
233
],
[
235
],
[
237
],
[
239
],
[
241
],
[
243
],
[
245
],
[
247
],
[
249
],
[
251
],
[
253
],
[
255
],
[
257
],
[
259
],
[
261,
263
],
[
265
],
[
267
],
[
269
],
[
271
],
[
273
],
[
275
],
[
277
],
[
279
],
[
281
],
[
283
],
[
285
],
[
287
],
[
289,
291
],
[
293
],
[
295
],
[
297
],
[
299
],
[
301
],
[
303
],
[
305,
307,
309
],
[
311
],
[
313
],
[
315
],
[
317
],
[
319
],
[
321
],
[
323
],
[
325
],
[
327
],
[
329
],
[
331
],
[
333
],
[
335,
337
],
[
339
],
[
341
],
[
343
],
[
345
],
[
347
],
[
349
],
[
351,
353,
355
],
[
357
],
[
359
],
[
361
],
[
363
],
[
365
],
[
367
],
[
369
],
[
371
],
[
373
],
[
375
],
[
377
],
[
379,
381,
383,
385
],
[
387
],
[
389
],
[
391
],
[
393
],
[
395,
397
],
[
399
],
[
401
],
[
403
],
[
405
],
[
407
],
[
409,
411
],
[
413
],
[
415
],
[
417
],
[
419
],
[
421
],
[
423
],
[
425
],
[
427
],
[
429
],
[
431,
433,
435
],
[
437
],
[
439
],
[
441
],
[
443
]
] |
21,464 | abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
abi_long arg2, abi_long arg3, abi_long arg4,
abi_long arg5, abi_long arg6, abi_long arg7,
abi_long arg8)
{
CPUState *cpu = ENV_GET_CPU(cpu_env);
abi_long ret;
struct stat st;
struct statfs stfs;
void *p;
#if defined(DEBUG_ERESTARTSYS)
/* Debug-only code for exercising the syscall-restart code paths
* in the per-architecture cpu main loops: restart every syscall
* the guest makes once before letting it through.
*/
{
static int flag;
flag = !flag;
if (flag) {
return -TARGET_ERESTARTSYS;
#endif
#ifdef DEBUG
gemu_log("syscall %d", num);
#endif
trace_guest_user_syscall(cpu, num, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);
if(do_strace)
print_syscall(num, arg1, arg2, arg3, arg4, arg5, arg6);
switch(num) {
case TARGET_NR_exit:
/* In old applications this may be used to implement _exit(2).
However in threaded applictions it is used for thread termination,
and _exit_group is used for application termination.
Do thread termination if we have more then one thread. */
if (block_signals()) {
ret = -TARGET_ERESTARTSYS;
if (CPU_NEXT(first_cpu)) {
TaskState *ts;
cpu_list_lock();
/* Remove the CPU from the list. */
QTAILQ_REMOVE(&cpus, cpu, node);
cpu_list_unlock();
ts = cpu->opaque;
if (ts->child_tidptr) {
put_user_u32(0, ts->child_tidptr);
sys_futex(g2h(ts->child_tidptr), FUTEX_WAKE, INT_MAX,
NULL, NULL, 0);
thread_cpu = NULL;
object_unref(OBJECT(cpu));
g_free(ts);
rcu_unregister_thread();
pthread_exit(NULL);
#ifdef TARGET_GPROF
_mcleanup();
#endif
gdb_exit(cpu_env, arg1);
_exit(arg1);
ret = 0; /* avoid warning */
case TARGET_NR_read:
if (arg3 == 0)
ret = 0;
else {
if (!(p = lock_user(VERIFY_WRITE, arg2, arg3, 0)))
goto efault;
ret = get_errno(safe_read(arg1, p, arg3));
if (ret >= 0 &&
fd_trans_host_to_target_data(arg1)) {
ret = fd_trans_host_to_target_data(arg1)(p, ret);
unlock_user(p, arg2, ret);
case TARGET_NR_write:
if (!(p = lock_user(VERIFY_READ, arg2, arg3, 1)))
goto efault;
ret = get_errno(safe_write(arg1, p, arg3));
unlock_user(p, arg2, 0);
#ifdef TARGET_NR_open
case TARGET_NR_open:
if (!(p = lock_user_string(arg1)))
goto efault;
ret = get_errno(do_openat(cpu_env, AT_FDCWD, p,
target_to_host_bitmask(arg2, fcntl_flags_tbl),
arg3));
fd_trans_unregister(ret);
unlock_user(p, arg1, 0);
#endif
case TARGET_NR_openat:
if (!(p = lock_user_string(arg2)))
goto efault;
ret = get_errno(do_openat(cpu_env, arg1, p,
target_to_host_bitmask(arg3, fcntl_flags_tbl),
arg4));
fd_trans_unregister(ret);
unlock_user(p, arg2, 0);
#if defined(TARGET_NR_name_to_handle_at) && defined(CONFIG_OPEN_BY_HANDLE)
case TARGET_NR_name_to_handle_at:
ret = do_name_to_handle_at(arg1, arg2, arg3, arg4, arg5);
#endif
#if defined(TARGET_NR_open_by_handle_at) && defined(CONFIG_OPEN_BY_HANDLE)
case TARGET_NR_open_by_handle_at:
ret = do_open_by_handle_at(arg1, arg2, arg3);
fd_trans_unregister(ret);
#endif
case TARGET_NR_close:
fd_trans_unregister(arg1);
ret = get_errno(close(arg1));
case TARGET_NR_brk:
ret = do_brk(arg1);
#ifdef TARGET_NR_fork
case TARGET_NR_fork:
ret = get_errno(do_fork(cpu_env, SIGCHLD, 0, 0, 0, 0));
#endif
#ifdef TARGET_NR_waitpid
case TARGET_NR_waitpid:
{
int status;
ret = get_errno(safe_wait4(arg1, &status, arg3, 0));
if (!is_error(ret) && arg2 && ret
&& put_user_s32(host_to_target_waitstatus(status), arg2))
goto efault;
#endif
#ifdef TARGET_NR_waitid
case TARGET_NR_waitid:
{
siginfo_t info;
info.si_pid = 0;
ret = get_errno(safe_waitid(arg1, arg2, &info, arg4, NULL));
if (!is_error(ret) && arg3 && info.si_pid != 0) {
if (!(p = lock_user(VERIFY_WRITE, arg3, sizeof(target_siginfo_t), 0)))
goto efault;
host_to_target_siginfo(p, &info);
unlock_user(p, arg3, sizeof(target_siginfo_t));
#endif
#ifdef TARGET_NR_creat /* not on alpha */
case TARGET_NR_creat:
if (!(p = lock_user_string(arg1)))
goto efault;
ret = get_errno(creat(p, arg2));
fd_trans_unregister(ret);
unlock_user(p, arg1, 0);
#endif
#ifdef TARGET_NR_link
case TARGET_NR_link:
{
void * p2;
p = lock_user_string(arg1);
p2 = lock_user_string(arg2);
if (!p || !p2)
ret = -TARGET_EFAULT;
else
ret = get_errno(link(p, p2));
unlock_user(p2, arg2, 0);
unlock_user(p, arg1, 0);
#endif
#if defined(TARGET_NR_linkat)
case TARGET_NR_linkat:
{
void * p2 = NULL;
if (!arg2 || !arg4)
goto efault;
p = lock_user_string(arg2);
p2 = lock_user_string(arg4);
if (!p || !p2)
ret = -TARGET_EFAULT;
else
ret = get_errno(linkat(arg1, p, arg3, p2, arg5));
unlock_user(p, arg2, 0);
unlock_user(p2, arg4, 0);
#endif
#ifdef TARGET_NR_unlink
case TARGET_NR_unlink:
if (!(p = lock_user_string(arg1)))
goto efault;
ret = get_errno(unlink(p));
unlock_user(p, arg1, 0);
#endif
#if defined(TARGET_NR_unlinkat)
case TARGET_NR_unlinkat:
if (!(p = lock_user_string(arg2)))
goto efault;
ret = get_errno(unlinkat(arg1, p, arg3));
unlock_user(p, arg2, 0);
#endif
case TARGET_NR_execve:
{
char **argp, **envp;
int argc, envc;
abi_ulong gp;
abi_ulong guest_argp;
abi_ulong guest_envp;
abi_ulong addr;
char **q;
int total_size = 0;
argc = 0;
guest_argp = arg2;
for (gp = guest_argp; gp; gp += sizeof(abi_ulong)) {
if (get_user_ual(addr, gp))
goto efault;
if (!addr)
argc++;
envc = 0;
guest_envp = arg3;
for (gp = guest_envp; gp; gp += sizeof(abi_ulong)) {
if (get_user_ual(addr, gp))
goto efault;
if (!addr)
envc++;
argp = alloca((argc + 1) * sizeof(void *));
envp = alloca((envc + 1) * sizeof(void *));
for (gp = guest_argp, q = argp; gp;
gp += sizeof(abi_ulong), q++) {
if (get_user_ual(addr, gp))
goto execve_efault;
if (!addr)
if (!(*q = lock_user_string(addr)))
goto execve_efault;
total_size += strlen(*q) + 1;
*q = NULL;
for (gp = guest_envp, q = envp; gp;
gp += sizeof(abi_ulong), q++) {
if (get_user_ual(addr, gp))
goto execve_efault;
if (!addr)
if (!(*q = lock_user_string(addr)))
goto execve_efault;
total_size += strlen(*q) + 1;
*q = NULL;
if (!(p = lock_user_string(arg1)))
goto execve_efault;
/* Although execve() is not an interruptible syscall it is
* a special case where we must use the safe_syscall wrapper:
* if we allow a signal to happen before we make the host
* syscall then we will 'lose' it, because at the point of
* execve the process leaves QEMU's control. So we use the
* safe syscall wrapper to ensure that we either take the
* signal as a guest signal, or else it does not happen
* before the execve completes and makes it the other
* program's problem.
*/
ret = get_errno(safe_execve(p, argp, envp));
unlock_user(p, arg1, 0);
goto execve_end;
execve_efault:
ret = -TARGET_EFAULT;
execve_end:
for (gp = guest_argp, q = argp; *q;
gp += sizeof(abi_ulong), q++) {
if (get_user_ual(addr, gp)
|| !addr)
unlock_user(*q, addr, 0);
for (gp = guest_envp, q = envp; *q;
gp += sizeof(abi_ulong), q++) {
if (get_user_ual(addr, gp)
|| !addr)
unlock_user(*q, addr, 0);
case TARGET_NR_chdir:
if (!(p = lock_user_string(arg1)))
goto efault;
ret = get_errno(chdir(p));
unlock_user(p, arg1, 0);
#ifdef TARGET_NR_time
case TARGET_NR_time:
{
time_t host_time;
ret = get_errno(time(&host_time));
if (!is_error(ret)
&& arg1
&& put_user_sal(host_time, arg1))
goto efault;
#endif
#ifdef TARGET_NR_mknod
case TARGET_NR_mknod:
if (!(p = lock_user_string(arg1)))
goto efault;
ret = get_errno(mknod(p, arg2, arg3));
unlock_user(p, arg1, 0);
#endif
#if defined(TARGET_NR_mknodat)
case TARGET_NR_mknodat:
if (!(p = lock_user_string(arg2)))
goto efault;
ret = get_errno(mknodat(arg1, p, arg3, arg4));
unlock_user(p, arg2, 0);
#endif
#ifdef TARGET_NR_chmod
case TARGET_NR_chmod:
if (!(p = lock_user_string(arg1)))
goto efault;
ret = get_errno(chmod(p, arg2));
unlock_user(p, arg1, 0);
#endif
#ifdef TARGET_NR_break
case TARGET_NR_break:
goto unimplemented;
#endif
#ifdef TARGET_NR_oldstat
case TARGET_NR_oldstat:
goto unimplemented;
#endif
case TARGET_NR_lseek:
ret = get_errno(lseek(arg1, arg2, arg3));
#if defined(TARGET_NR_getxpid) && defined(TARGET_ALPHA)
/* Alpha specific */
case TARGET_NR_getxpid:
((CPUAlphaState *)cpu_env)->ir[IR_A4] = getppid();
ret = get_errno(getpid());
#endif
#ifdef TARGET_NR_getpid
case TARGET_NR_getpid:
ret = get_errno(getpid());
#endif
case TARGET_NR_mount:
{
/* need to look at the data field */
void *p2, *p3;
if (arg1) {
p = lock_user_string(arg1);
if (!p) {
goto efault;
} else {
p = NULL;
p2 = lock_user_string(arg2);
if (!p2) {
if (arg1) {
unlock_user(p, arg1, 0);
goto efault;
if (arg3) {
p3 = lock_user_string(arg3);
if (!p3) {
if (arg1) {
unlock_user(p, arg1, 0);
unlock_user(p2, arg2, 0);
goto efault;
} else {
p3 = NULL;
/* FIXME - arg5 should be locked, but it isn't clear how to
* do that since it's not guaranteed to be a NULL-terminated
* string.
*/
if (!arg5) {
ret = mount(p, p2, p3, (unsigned long)arg4, NULL);
} else {
ret = mount(p, p2, p3, (unsigned long)arg4, g2h(arg5));
ret = get_errno(ret);
if (arg1) {
unlock_user(p, arg1, 0);
unlock_user(p2, arg2, 0);
if (arg3) {
unlock_user(p3, arg3, 0);
#ifdef TARGET_NR_umount
case TARGET_NR_umount:
if (!(p = lock_user_string(arg1)))
goto efault;
ret = get_errno(umount(p));
unlock_user(p, arg1, 0);
#endif
#ifdef TARGET_NR_stime /* not on alpha */
case TARGET_NR_stime:
{
time_t host_time;
if (get_user_sal(host_time, arg1))
goto efault;
ret = get_errno(stime(&host_time));
#endif
case TARGET_NR_ptrace:
goto unimplemented;
#ifdef TARGET_NR_alarm /* not on alpha */
case TARGET_NR_alarm:
ret = alarm(arg1);
#endif
#ifdef TARGET_NR_oldfstat
case TARGET_NR_oldfstat:
goto unimplemented;
#endif
#ifdef TARGET_NR_pause /* not on alpha */
case TARGET_NR_pause:
if (!block_signals()) {
sigsuspend(&((TaskState *)cpu->opaque)->signal_mask);
ret = -TARGET_EINTR;
#endif
#ifdef TARGET_NR_utime
case TARGET_NR_utime:
{
struct utimbuf tbuf, *host_tbuf;
struct target_utimbuf *target_tbuf;
if (arg2) {
if (!lock_user_struct(VERIFY_READ, target_tbuf, arg2, 1))
goto efault;
tbuf.actime = tswapal(target_tbuf->actime);
tbuf.modtime = tswapal(target_tbuf->modtime);
unlock_user_struct(target_tbuf, arg2, 0);
host_tbuf = &tbuf;
} else {
host_tbuf = NULL;
if (!(p = lock_user_string(arg1)))
goto efault;
ret = get_errno(utime(p, host_tbuf));
unlock_user(p, arg1, 0);
#endif
#ifdef TARGET_NR_utimes
case TARGET_NR_utimes:
{
struct timeval *tvp, tv[2];
if (arg2) {
if (copy_from_user_timeval(&tv[0], arg2)
|| copy_from_user_timeval(&tv[1],
arg2 + sizeof(struct target_timeval)))
goto efault;
tvp = tv;
} else {
tvp = NULL;
if (!(p = lock_user_string(arg1)))
goto efault;
ret = get_errno(utimes(p, tvp));
unlock_user(p, arg1, 0);
#endif
#if defined(TARGET_NR_futimesat)
case TARGET_NR_futimesat:
{
struct timeval *tvp, tv[2];
if (arg3) {
if (copy_from_user_timeval(&tv[0], arg3)
|| copy_from_user_timeval(&tv[1],
arg3 + sizeof(struct target_timeval)))
goto efault;
tvp = tv;
} else {
tvp = NULL;
if (!(p = lock_user_string(arg2)))
goto efault;
ret = get_errno(futimesat(arg1, path(p), tvp));
unlock_user(p, arg2, 0);
#endif
#ifdef TARGET_NR_stty
case TARGET_NR_stty:
goto unimplemented;
#endif
#ifdef TARGET_NR_gtty
case TARGET_NR_gtty:
goto unimplemented;
#endif
#ifdef TARGET_NR_access
case TARGET_NR_access:
if (!(p = lock_user_string(arg1)))
goto efault;
ret = get_errno(access(path(p), arg2));
unlock_user(p, arg1, 0);
#endif
#if defined(TARGET_NR_faccessat) && defined(__NR_faccessat)
case TARGET_NR_faccessat:
if (!(p = lock_user_string(arg2)))
goto efault;
ret = get_errno(faccessat(arg1, p, arg3, 0));
unlock_user(p, arg2, 0);
#endif
#ifdef TARGET_NR_nice /* not on alpha */
case TARGET_NR_nice:
ret = get_errno(nice(arg1));
#endif
#ifdef TARGET_NR_ftime
case TARGET_NR_ftime:
goto unimplemented;
#endif
case TARGET_NR_sync:
sync();
ret = 0;
case TARGET_NR_kill:
ret = get_errno(safe_kill(arg1, target_to_host_signal(arg2)));
#ifdef TARGET_NR_rename
case TARGET_NR_rename:
{
void *p2;
p = lock_user_string(arg1);
p2 = lock_user_string(arg2);
if (!p || !p2)
ret = -TARGET_EFAULT;
else
ret = get_errno(rename(p, p2));
unlock_user(p2, arg2, 0);
unlock_user(p, arg1, 0);
#endif
#if defined(TARGET_NR_renameat)
case TARGET_NR_renameat:
{
void *p2;
p = lock_user_string(arg2);
p2 = lock_user_string(arg4);
if (!p || !p2)
ret = -TARGET_EFAULT;
else
ret = get_errno(renameat(arg1, p, arg3, p2));
unlock_user(p2, arg4, 0);
unlock_user(p, arg2, 0);
#endif
#ifdef TARGET_NR_mkdir
case TARGET_NR_mkdir:
if (!(p = lock_user_string(arg1)))
goto efault;
ret = get_errno(mkdir(p, arg2));
unlock_user(p, arg1, 0);
#endif
#if defined(TARGET_NR_mkdirat)
case TARGET_NR_mkdirat:
if (!(p = lock_user_string(arg2)))
goto efault;
ret = get_errno(mkdirat(arg1, p, arg3));
unlock_user(p, arg2, 0);
#endif
#ifdef TARGET_NR_rmdir
case TARGET_NR_rmdir:
if (!(p = lock_user_string(arg1)))
goto efault;
ret = get_errno(rmdir(p));
unlock_user(p, arg1, 0);
#endif
case TARGET_NR_dup:
ret = get_errno(dup(arg1));
if (ret >= 0) {
fd_trans_dup(arg1, ret);
#ifdef TARGET_NR_pipe
case TARGET_NR_pipe:
ret = do_pipe(cpu_env, arg1, 0, 0);
#endif
#ifdef TARGET_NR_pipe2
case TARGET_NR_pipe2:
ret = do_pipe(cpu_env, arg1,
target_to_host_bitmask(arg2, fcntl_flags_tbl), 1);
#endif
case TARGET_NR_times:
{
struct target_tms *tmsp;
struct tms tms;
ret = get_errno(times(&tms));
if (arg1) {
tmsp = lock_user(VERIFY_WRITE, arg1, sizeof(struct target_tms), 0);
if (!tmsp)
goto efault;
tmsp->tms_utime = tswapal(host_to_target_clock_t(tms.tms_utime));
tmsp->tms_stime = tswapal(host_to_target_clock_t(tms.tms_stime));
tmsp->tms_cutime = tswapal(host_to_target_clock_t(tms.tms_cutime));
tmsp->tms_cstime = tswapal(host_to_target_clock_t(tms.tms_cstime));
if (!is_error(ret))
ret = host_to_target_clock_t(ret);
#ifdef TARGET_NR_prof
case TARGET_NR_prof:
goto unimplemented;
#endif
#ifdef TARGET_NR_signal
case TARGET_NR_signal:
goto unimplemented;
#endif
case TARGET_NR_acct:
if (arg1 == 0) {
ret = get_errno(acct(NULL));
} else {
if (!(p = lock_user_string(arg1)))
goto efault;
ret = get_errno(acct(path(p)));
unlock_user(p, arg1, 0);
#ifdef TARGET_NR_umount2
case TARGET_NR_umount2:
if (!(p = lock_user_string(arg1)))
goto efault;
ret = get_errno(umount2(p, arg2));
unlock_user(p, arg1, 0);
#endif
#ifdef TARGET_NR_lock
case TARGET_NR_lock:
goto unimplemented;
#endif
case TARGET_NR_ioctl:
ret = do_ioctl(arg1, arg2, arg3);
case TARGET_NR_fcntl:
ret = do_fcntl(arg1, arg2, arg3);
#ifdef TARGET_NR_mpx
case TARGET_NR_mpx:
goto unimplemented;
#endif
case TARGET_NR_setpgid:
ret = get_errno(setpgid(arg1, arg2));
#ifdef TARGET_NR_ulimit
case TARGET_NR_ulimit:
goto unimplemented;
#endif
#ifdef TARGET_NR_oldolduname
case TARGET_NR_oldolduname:
goto unimplemented;
#endif
case TARGET_NR_umask:
ret = get_errno(umask(arg1));
case TARGET_NR_chroot:
if (!(p = lock_user_string(arg1)))
goto efault;
ret = get_errno(chroot(p));
unlock_user(p, arg1, 0);
#ifdef TARGET_NR_ustat
case TARGET_NR_ustat:
goto unimplemented;
#endif
#ifdef TARGET_NR_dup2
case TARGET_NR_dup2:
ret = get_errno(dup2(arg1, arg2));
if (ret >= 0) {
fd_trans_dup(arg1, arg2);
#endif
#if defined(CONFIG_DUP3) && defined(TARGET_NR_dup3)
case TARGET_NR_dup3:
ret = get_errno(dup3(arg1, arg2, arg3));
if (ret >= 0) {
fd_trans_dup(arg1, arg2);
#endif
#ifdef TARGET_NR_getppid /* not on alpha */
case TARGET_NR_getppid:
ret = get_errno(getppid());
#endif
#ifdef TARGET_NR_getpgrp
case TARGET_NR_getpgrp:
ret = get_errno(getpgrp());
#endif
case TARGET_NR_setsid:
ret = get_errno(setsid());
#ifdef TARGET_NR_sigaction
case TARGET_NR_sigaction:
{
#if defined(TARGET_ALPHA)
struct target_sigaction act, oact, *pact = 0;
struct target_old_sigaction *old_act;
if (arg2) {
if (!lock_user_struct(VERIFY_READ, old_act, arg2, 1))
goto efault;
act._sa_handler = old_act->_sa_handler;
target_siginitset(&act.sa_mask, old_act->sa_mask);
act.sa_flags = old_act->sa_flags;
act.sa_restorer = 0;
unlock_user_struct(old_act, arg2, 0);
pact = &act;
ret = get_errno(do_sigaction(arg1, pact, &oact));
if (!is_error(ret) && arg3) {
if (!lock_user_struct(VERIFY_WRITE, old_act, arg3, 0))
goto efault;
old_act->_sa_handler = oact._sa_handler;
old_act->sa_mask = oact.sa_mask.sig[0];
old_act->sa_flags = oact.sa_flags;
unlock_user_struct(old_act, arg3, 1);
#elif defined(TARGET_MIPS)
struct target_sigaction act, oact, *pact, *old_act;
if (arg2) {
if (!lock_user_struct(VERIFY_READ, old_act, arg2, 1))
goto efault;
act._sa_handler = old_act->_sa_handler;
target_siginitset(&act.sa_mask, old_act->sa_mask.sig[0]);
act.sa_flags = old_act->sa_flags;
unlock_user_struct(old_act, arg2, 0);
pact = &act;
} else {
pact = NULL;
ret = get_errno(do_sigaction(arg1, pact, &oact));
if (!is_error(ret) && arg3) {
if (!lock_user_struct(VERIFY_WRITE, old_act, arg3, 0))
goto efault;
old_act->_sa_handler = oact._sa_handler;
old_act->sa_flags = oact.sa_flags;
old_act->sa_mask.sig[0] = oact.sa_mask.sig[0];
old_act->sa_mask.sig[1] = 0;
old_act->sa_mask.sig[2] = 0;
old_act->sa_mask.sig[3] = 0;
unlock_user_struct(old_act, arg3, 1);
#else
struct target_old_sigaction *old_act;
struct target_sigaction act, oact, *pact;
if (arg2) {
if (!lock_user_struct(VERIFY_READ, old_act, arg2, 1))
goto efault;
act._sa_handler = old_act->_sa_handler;
target_siginitset(&act.sa_mask, old_act->sa_mask);
act.sa_flags = old_act->sa_flags;
act.sa_restorer = old_act->sa_restorer;
unlock_user_struct(old_act, arg2, 0);
pact = &act;
} else {
pact = NULL;
ret = get_errno(do_sigaction(arg1, pact, &oact));
if (!is_error(ret) && arg3) {
if (!lock_user_struct(VERIFY_WRITE, old_act, arg3, 0))
goto efault;
old_act->_sa_handler = oact._sa_handler;
old_act->sa_mask = oact.sa_mask.sig[0];
old_act->sa_flags = oact.sa_flags;
old_act->sa_restorer = oact.sa_restorer;
unlock_user_struct(old_act, arg3, 1);
#endif
#endif
case TARGET_NR_rt_sigaction:
{
#if defined(TARGET_ALPHA)
struct target_sigaction act, oact, *pact = 0;
struct target_rt_sigaction *rt_act;
if (arg4 != sizeof(target_sigset_t)) {
if (arg2) {
if (!lock_user_struct(VERIFY_READ, rt_act, arg2, 1))
goto efault;
act._sa_handler = rt_act->_sa_handler;
act.sa_mask = rt_act->sa_mask;
act.sa_flags = rt_act->sa_flags;
act.sa_restorer = arg5;
unlock_user_struct(rt_act, arg2, 0);
pact = &act;
ret = get_errno(do_sigaction(arg1, pact, &oact));
if (!is_error(ret) && arg3) {
if (!lock_user_struct(VERIFY_WRITE, rt_act, arg3, 0))
goto efault;
rt_act->_sa_handler = oact._sa_handler;
rt_act->sa_mask = oact.sa_mask;
rt_act->sa_flags = oact.sa_flags;
unlock_user_struct(rt_act, arg3, 1);
#else
struct target_sigaction *act;
struct target_sigaction *oact;
if (arg4 != sizeof(target_sigset_t)) {
if (arg2) {
if (!lock_user_struct(VERIFY_READ, act, arg2, 1))
goto efault;
} else
act = NULL;
if (arg3) {
if (!lock_user_struct(VERIFY_WRITE, oact, arg3, 0)) {
ret = -TARGET_EFAULT;
goto rt_sigaction_fail;
} else
oact = NULL;
ret = get_errno(do_sigaction(arg1, act, oact));
rt_sigaction_fail:
if (act)
unlock_user_struct(act, arg2, 0);
if (oact)
unlock_user_struct(oact, arg3, 1);
#endif
#ifdef TARGET_NR_sgetmask /* not on alpha */
case TARGET_NR_sgetmask:
{
sigset_t cur_set;
abi_ulong target_set;
ret = do_sigprocmask(0, NULL, &cur_set);
if (!ret) {
host_to_target_old_sigset(&target_set, &cur_set);
ret = target_set;
#endif
#ifdef TARGET_NR_ssetmask /* not on alpha */
case TARGET_NR_ssetmask:
{
sigset_t set, oset, cur_set;
abi_ulong target_set = arg1;
/* We only have one word of the new mask so we must read
* the rest of it with do_sigprocmask() and OR in this word.
* We are guaranteed that a do_sigprocmask() that only queries
* the signal mask will not fail.
*/
ret = do_sigprocmask(0, NULL, &cur_set);
assert(!ret);
target_to_host_old_sigset(&set, &target_set);
sigorset(&set, &set, &cur_set);
ret = do_sigprocmask(SIG_SETMASK, &set, &oset);
if (!ret) {
host_to_target_old_sigset(&target_set, &oset);
ret = target_set;
#endif
#ifdef TARGET_NR_sigprocmask
case TARGET_NR_sigprocmask:
{
#if defined(TARGET_ALPHA)
sigset_t set, oldset;
abi_ulong mask;
int how;
switch (arg1) {
case TARGET_SIG_BLOCK:
how = SIG_BLOCK;
case TARGET_SIG_UNBLOCK:
how = SIG_UNBLOCK;
case TARGET_SIG_SETMASK:
how = SIG_SETMASK;
default:
goto fail;
mask = arg2;
target_to_host_old_sigset(&set, &mask);
ret = do_sigprocmask(how, &set, &oldset);
if (!is_error(ret)) {
host_to_target_old_sigset(&mask, &oldset);
ret = mask;
((CPUAlphaState *)cpu_env)->ir[IR_V0] = 0; /* force no error */
#else
sigset_t set, oldset, *set_ptr;
int how;
if (arg2) {
switch (arg1) {
case TARGET_SIG_BLOCK:
how = SIG_BLOCK;
case TARGET_SIG_UNBLOCK:
how = SIG_UNBLOCK;
case TARGET_SIG_SETMASK:
how = SIG_SETMASK;
default:
goto fail;
if (!(p = lock_user(VERIFY_READ, arg2, sizeof(target_sigset_t), 1)))
goto efault;
target_to_host_old_sigset(&set, p);
unlock_user(p, arg2, 0);
set_ptr = &set;
} else {
how = 0;
set_ptr = NULL;
ret = do_sigprocmask(how, set_ptr, &oldset);
if (!is_error(ret) && arg3) {
if (!(p = lock_user(VERIFY_WRITE, arg3, sizeof(target_sigset_t), 0)))
goto efault;
host_to_target_old_sigset(p, &oldset);
unlock_user(p, arg3, sizeof(target_sigset_t));
#endif
#endif
case TARGET_NR_rt_sigprocmask:
{
int how = arg1;
sigset_t set, oldset, *set_ptr;
if (arg4 != sizeof(target_sigset_t)) {
if (arg2) {
switch(how) {
case TARGET_SIG_BLOCK:
how = SIG_BLOCK;
case TARGET_SIG_UNBLOCK:
how = SIG_UNBLOCK;
case TARGET_SIG_SETMASK:
how = SIG_SETMASK;
default:
goto fail;
if (!(p = lock_user(VERIFY_READ, arg2, sizeof(target_sigset_t), 1)))
goto efault;
target_to_host_sigset(&set, p);
unlock_user(p, arg2, 0);
set_ptr = &set;
} else {
how = 0;
set_ptr = NULL;
ret = do_sigprocmask(how, set_ptr, &oldset);
if (!is_error(ret) && arg3) {
if (!(p = lock_user(VERIFY_WRITE, arg3, sizeof(target_sigset_t), 0)))
goto efault;
host_to_target_sigset(p, &oldset);
unlock_user(p, arg3, sizeof(target_sigset_t));
#ifdef TARGET_NR_sigpending
case TARGET_NR_sigpending:
{
sigset_t set;
ret = get_errno(sigpending(&set));
if (!is_error(ret)) {
if (!(p = lock_user(VERIFY_WRITE, arg1, sizeof(target_sigset_t), 0)))
goto efault;
host_to_target_old_sigset(p, &set);
unlock_user(p, arg1, sizeof(target_sigset_t));
#endif
case TARGET_NR_rt_sigpending:
{
sigset_t set;
/* Yes, this check is >, not != like most. We follow the kernel's
* logic and it does it like this because it implements
* NR_sigpending through the same code path, and in that case
* the old_sigset_t is smaller in size.
*/
if (arg2 > sizeof(target_sigset_t)) {
ret = get_errno(sigpending(&set));
if (!is_error(ret)) {
if (!(p = lock_user(VERIFY_WRITE, arg1, sizeof(target_sigset_t), 0)))
goto efault;
host_to_target_sigset(p, &set);
unlock_user(p, arg1, sizeof(target_sigset_t));
#ifdef TARGET_NR_sigsuspend
case TARGET_NR_sigsuspend:
{
TaskState *ts = cpu->opaque;
#if defined(TARGET_ALPHA)
abi_ulong mask = arg1;
target_to_host_old_sigset(&ts->sigsuspend_mask, &mask);
#else
if (!(p = lock_user(VERIFY_READ, arg1, sizeof(target_sigset_t), 1)))
goto efault;
target_to_host_old_sigset(&ts->sigsuspend_mask, p);
unlock_user(p, arg1, 0);
#endif
ret = get_errno(safe_rt_sigsuspend(&ts->sigsuspend_mask,
SIGSET_T_SIZE));
if (ret != -TARGET_ERESTARTSYS) {
ts->in_sigsuspend = 1;
#endif
case TARGET_NR_rt_sigsuspend:
{
TaskState *ts = cpu->opaque;
if (arg2 != sizeof(target_sigset_t)) {
if (!(p = lock_user(VERIFY_READ, arg1, sizeof(target_sigset_t), 1)))
goto efault;
target_to_host_sigset(&ts->sigsuspend_mask, p);
unlock_user(p, arg1, 0);
ret = get_errno(safe_rt_sigsuspend(&ts->sigsuspend_mask,
SIGSET_T_SIZE));
if (ret != -TARGET_ERESTARTSYS) {
ts->in_sigsuspend = 1;
case TARGET_NR_rt_sigtimedwait:
{
sigset_t set;
struct timespec uts, *puts;
siginfo_t uinfo;
if (arg4 != sizeof(target_sigset_t)) {
if (!(p = lock_user(VERIFY_READ, arg1, sizeof(target_sigset_t), 1)))
goto efault;
target_to_host_sigset(&set, p);
unlock_user(p, arg1, 0);
if (arg3) {
puts = &uts;
target_to_host_timespec(puts, arg3);
} else {
puts = NULL;
ret = get_errno(safe_rt_sigtimedwait(&set, &uinfo, puts,
SIGSET_T_SIZE));
if (!is_error(ret)) {
if (arg2) {
p = lock_user(VERIFY_WRITE, arg2, sizeof(target_siginfo_t),
0);
if (!p) {
goto efault;
host_to_target_siginfo(p, &uinfo);
unlock_user(p, arg2, sizeof(target_siginfo_t));
ret = host_to_target_signal(ret);
case TARGET_NR_rt_sigqueueinfo:
{
siginfo_t uinfo;
p = lock_user(VERIFY_READ, arg3, sizeof(target_siginfo_t), 1);
if (!p) {
goto efault;
target_to_host_siginfo(&uinfo, p);
unlock_user(p, arg1, 0);
ret = get_errno(sys_rt_sigqueueinfo(arg1, arg2, &uinfo));
#ifdef TARGET_NR_sigreturn
case TARGET_NR_sigreturn:
if (block_signals()) {
ret = -TARGET_ERESTARTSYS;
} else {
ret = do_sigreturn(cpu_env);
#endif
case TARGET_NR_rt_sigreturn:
if (block_signals()) {
ret = -TARGET_ERESTARTSYS;
} else {
ret = do_rt_sigreturn(cpu_env);
case TARGET_NR_sethostname:
if (!(p = lock_user_string(arg1)))
goto efault;
ret = get_errno(sethostname(p, arg2));
unlock_user(p, arg1, 0);
case TARGET_NR_setrlimit:
{
int resource = target_to_host_resource(arg1);
struct target_rlimit *target_rlim;
struct rlimit rlim;
if (!lock_user_struct(VERIFY_READ, target_rlim, arg2, 1))
goto efault;
rlim.rlim_cur = target_to_host_rlim(target_rlim->rlim_cur);
rlim.rlim_max = target_to_host_rlim(target_rlim->rlim_max);
unlock_user_struct(target_rlim, arg2, 0);
ret = get_errno(setrlimit(resource, &rlim));
case TARGET_NR_getrlimit:
{
int resource = target_to_host_resource(arg1);
struct target_rlimit *target_rlim;
struct rlimit rlim;
ret = get_errno(getrlimit(resource, &rlim));
if (!is_error(ret)) {
if (!lock_user_struct(VERIFY_WRITE, target_rlim, arg2, 0))
goto efault;
target_rlim->rlim_cur = host_to_target_rlim(rlim.rlim_cur);
target_rlim->rlim_max = host_to_target_rlim(rlim.rlim_max);
unlock_user_struct(target_rlim, arg2, 1);
case TARGET_NR_getrusage:
{
struct rusage rusage;
ret = get_errno(getrusage(arg1, &rusage));
if (!is_error(ret)) {
ret = host_to_target_rusage(arg2, &rusage);
case TARGET_NR_gettimeofday:
{
struct timeval tv;
ret = get_errno(gettimeofday(&tv, NULL));
if (!is_error(ret)) {
if (copy_to_user_timeval(arg1, &tv))
goto efault;
case TARGET_NR_settimeofday:
{
struct timeval tv, *ptv = NULL;
struct timezone tz, *ptz = NULL;
if (arg1) {
if (copy_from_user_timeval(&tv, arg1)) {
goto efault;
ptv = &tv;
if (arg2) {
if (copy_from_user_timezone(&tz, arg2)) {
goto efault;
ptz = &tz;
ret = get_errno(settimeofday(ptv, ptz));
#if defined(TARGET_NR_select)
case TARGET_NR_select:
#if defined(TARGET_S390X) || defined(TARGET_ALPHA)
ret = do_select(arg1, arg2, arg3, arg4, arg5);
#else
{
struct target_sel_arg_struct *sel;
abi_ulong inp, outp, exp, tvp;
long nsel;
if (!lock_user_struct(VERIFY_READ, sel, arg1, 1))
goto efault;
nsel = tswapal(sel->n);
inp = tswapal(sel->inp);
outp = tswapal(sel->outp);
exp = tswapal(sel->exp);
tvp = tswapal(sel->tvp);
unlock_user_struct(sel, arg1, 0);
ret = do_select(nsel, inp, outp, exp, tvp);
#endif
#endif
#ifdef TARGET_NR_pselect6
case TARGET_NR_pselect6:
{
abi_long rfd_addr, wfd_addr, efd_addr, n, ts_addr;
fd_set rfds, wfds, efds;
fd_set *rfds_ptr, *wfds_ptr, *efds_ptr;
struct timespec ts, *ts_ptr;
/*
* The 6th arg is actually two args smashed together,
* so we cannot use the C library.
*/
sigset_t set;
struct {
sigset_t *set;
size_t size;
} sig, *sig_ptr;
abi_ulong arg_sigset, arg_sigsize, *arg7;
target_sigset_t *target_sigset;
n = arg1;
rfd_addr = arg2;
wfd_addr = arg3;
efd_addr = arg4;
ts_addr = arg5;
ret = copy_from_user_fdset_ptr(&rfds, &rfds_ptr, rfd_addr, n);
if (ret) {
goto fail;
ret = copy_from_user_fdset_ptr(&wfds, &wfds_ptr, wfd_addr, n);
if (ret) {
goto fail;
ret = copy_from_user_fdset_ptr(&efds, &efds_ptr, efd_addr, n);
if (ret) {
goto fail;
/*
* This takes a timespec, and not a timeval, so we cannot
* use the do_select() helper ...
*/
if (ts_addr) {
if (target_to_host_timespec(&ts, ts_addr)) {
goto efault;
ts_ptr = &ts;
} else {
ts_ptr = NULL;
/* Extract the two packed args for the sigset */
if (arg6) {
sig_ptr = &sig;
sig.size = SIGSET_T_SIZE;
arg7 = lock_user(VERIFY_READ, arg6, sizeof(*arg7) * 2, 1);
if (!arg7) {
goto efault;
arg_sigset = tswapal(arg7[0]);
arg_sigsize = tswapal(arg7[1]);
unlock_user(arg7, arg6, 0);
if (arg_sigset) {
sig.set = &set;
if (arg_sigsize != sizeof(*target_sigset)) {
/* Like the kernel, we enforce correct size sigsets */
goto fail;
target_sigset = lock_user(VERIFY_READ, arg_sigset,
sizeof(*target_sigset), 1);
if (!target_sigset) {
goto efault;
target_to_host_sigset(&set, target_sigset);
unlock_user(target_sigset, arg_sigset, 0);
} else {
sig.set = NULL;
} else {
sig_ptr = NULL;
ret = get_errno(safe_pselect6(n, rfds_ptr, wfds_ptr, efds_ptr,
ts_ptr, sig_ptr));
if (!is_error(ret)) {
if (rfd_addr && copy_to_user_fdset(rfd_addr, &rfds, n))
goto efault;
if (wfd_addr && copy_to_user_fdset(wfd_addr, &wfds, n))
goto efault;
if (efd_addr && copy_to_user_fdset(efd_addr, &efds, n))
goto efault;
if (ts_addr && host_to_target_timespec(ts_addr, &ts))
goto efault;
#endif
#ifdef TARGET_NR_symlink
case TARGET_NR_symlink:
{
void *p2;
p = lock_user_string(arg1);
p2 = lock_user_string(arg2);
if (!p || !p2)
ret = -TARGET_EFAULT;
else
ret = get_errno(symlink(p, p2));
unlock_user(p2, arg2, 0);
unlock_user(p, arg1, 0);
#endif
#if defined(TARGET_NR_symlinkat)
case TARGET_NR_symlinkat:
{
void *p2;
p = lock_user_string(arg1);
p2 = lock_user_string(arg3);
if (!p || !p2)
ret = -TARGET_EFAULT;
else
ret = get_errno(symlinkat(p, arg2, p2));
unlock_user(p2, arg3, 0);
unlock_user(p, arg1, 0);
#endif
#ifdef TARGET_NR_oldlstat
case TARGET_NR_oldlstat:
goto unimplemented;
#endif
#ifdef TARGET_NR_readlink
case TARGET_NR_readlink:
{
void *p2;
p = lock_user_string(arg1);
p2 = lock_user(VERIFY_WRITE, arg2, arg3, 0);
if (!p || !p2) {
ret = -TARGET_EFAULT;
} else if (!arg3) {
/* Short circuit this for the magic exe check. */
} else if (is_proc_myself((const char *)p, "exe")) {
char real[PATH_MAX], *temp;
temp = realpath(exec_path, real);
/* Return value is # of bytes that we wrote to the buffer. */
if (temp == NULL) {
ret = get_errno(-1);
} else {
/* Don't worry about sign mismatch as earlier mapping
* logic would have thrown a bad address error. */
ret = MIN(strlen(real), arg3);
/* We cannot NUL terminate the string. */
memcpy(p2, real, ret);
} else {
ret = get_errno(readlink(path(p), p2, arg3));
unlock_user(p2, arg2, ret);
unlock_user(p, arg1, 0);
#endif
#if defined(TARGET_NR_readlinkat)
case TARGET_NR_readlinkat:
{
void *p2;
p = lock_user_string(arg2);
p2 = lock_user(VERIFY_WRITE, arg3, arg4, 0);
if (!p || !p2) {
ret = -TARGET_EFAULT;
} else if (is_proc_myself((const char *)p, "exe")) {
char real[PATH_MAX], *temp;
temp = realpath(exec_path, real);
ret = temp == NULL ? get_errno(-1) : strlen(real) ;
snprintf((char *)p2, arg4, "%s", real);
} else {
ret = get_errno(readlinkat(arg1, path(p), p2, arg4));
unlock_user(p2, arg3, ret);
unlock_user(p, arg2, 0);
#endif
#ifdef TARGET_NR_uselib
case TARGET_NR_uselib:
goto unimplemented;
#endif
#ifdef TARGET_NR_swapon
case TARGET_NR_swapon:
if (!(p = lock_user_string(arg1)))
goto efault;
ret = get_errno(swapon(p, arg2));
unlock_user(p, arg1, 0);
#endif
case TARGET_NR_reboot:
if (arg3 == LINUX_REBOOT_CMD_RESTART2) {
/* arg4 must be ignored in all other cases */
p = lock_user_string(arg4);
if (!p) {
goto efault;
ret = get_errno(reboot(arg1, arg2, arg3, p));
unlock_user(p, arg4, 0);
} else {
ret = get_errno(reboot(arg1, arg2, arg3, NULL));
#ifdef TARGET_NR_readdir
case TARGET_NR_readdir:
goto unimplemented;
#endif
#ifdef TARGET_NR_mmap
case TARGET_NR_mmap:
#if (defined(TARGET_I386) && defined(TARGET_ABI32)) || \
(defined(TARGET_ARM) && defined(TARGET_ABI32)) || \
defined(TARGET_M68K) || defined(TARGET_CRIS) || defined(TARGET_MICROBLAZE) \
|| defined(TARGET_S390X)
{
abi_ulong *v;
abi_ulong v1, v2, v3, v4, v5, v6;
if (!(v = lock_user(VERIFY_READ, arg1, 6 * sizeof(abi_ulong), 1)))
goto efault;
v1 = tswapal(v[0]);
v2 = tswapal(v[1]);
v3 = tswapal(v[2]);
v4 = tswapal(v[3]);
v5 = tswapal(v[4]);
v6 = tswapal(v[5]);
unlock_user(v, arg1, 0);
ret = get_errno(target_mmap(v1, v2, v3,
target_to_host_bitmask(v4, mmap_flags_tbl),
v5, v6));
#else
ret = get_errno(target_mmap(arg1, arg2, arg3,
target_to_host_bitmask(arg4, mmap_flags_tbl),
arg5,
arg6));
#endif
#endif
#ifdef TARGET_NR_mmap2
case TARGET_NR_mmap2:
#ifndef MMAP_SHIFT
#define MMAP_SHIFT 12
#endif
ret = get_errno(target_mmap(arg1, arg2, arg3,
target_to_host_bitmask(arg4, mmap_flags_tbl),
arg5,
arg6 << MMAP_SHIFT));
#endif
case TARGET_NR_munmap:
ret = get_errno(target_munmap(arg1, arg2));
case TARGET_NR_mprotect:
{
TaskState *ts = cpu->opaque;
/* Special hack to detect libc making the stack executable. */
if ((arg3 & PROT_GROWSDOWN)
&& arg1 >= ts->info->stack_limit
&& arg1 <= ts->info->start_stack) {
arg3 &= ~PROT_GROWSDOWN;
arg2 = arg2 + arg1 - ts->info->stack_limit;
arg1 = ts->info->stack_limit;
ret = get_errno(target_mprotect(arg1, arg2, arg3));
#ifdef TARGET_NR_mremap
case TARGET_NR_mremap:
ret = get_errno(target_mremap(arg1, arg2, arg3, arg4, arg5));
#endif
/* ??? msync/mlock/munlock are broken for softmmu. */
#ifdef TARGET_NR_msync
case TARGET_NR_msync:
ret = get_errno(msync(g2h(arg1), arg2, arg3));
#endif
#ifdef TARGET_NR_mlock
case TARGET_NR_mlock:
ret = get_errno(mlock(g2h(arg1), arg2));
#endif
#ifdef TARGET_NR_munlock
case TARGET_NR_munlock:
ret = get_errno(munlock(g2h(arg1), arg2));
#endif
#ifdef TARGET_NR_mlockall
case TARGET_NR_mlockall:
ret = get_errno(mlockall(target_to_host_mlockall_arg(arg1)));
#endif
#ifdef TARGET_NR_munlockall
case TARGET_NR_munlockall:
ret = get_errno(munlockall());
#endif
case TARGET_NR_truncate:
if (!(p = lock_user_string(arg1)))
goto efault;
ret = get_errno(truncate(p, arg2));
unlock_user(p, arg1, 0);
case TARGET_NR_ftruncate:
ret = get_errno(ftruncate(arg1, arg2));
case TARGET_NR_fchmod:
ret = get_errno(fchmod(arg1, arg2));
#if defined(TARGET_NR_fchmodat)
case TARGET_NR_fchmodat:
if (!(p = lock_user_string(arg2)))
goto efault;
ret = get_errno(fchmodat(arg1, p, arg3, 0));
unlock_user(p, arg2, 0);
#endif
case TARGET_NR_getpriority:
/* Note that negative values are valid for getpriority, so we must
differentiate based on errno settings. */
errno = 0;
ret = getpriority(arg1, arg2);
if (ret == -1 && errno != 0) {
ret = -host_to_target_errno(errno);
#ifdef TARGET_ALPHA
/* Return value is the unbiased priority. Signal no error. */
((CPUAlphaState *)cpu_env)->ir[IR_V0] = 0;
#else
/* Return value is a biased priority to avoid negative numbers. */
ret = 20 - ret;
#endif
case TARGET_NR_setpriority:
ret = get_errno(setpriority(arg1, arg2, arg3));
#ifdef TARGET_NR_profil
case TARGET_NR_profil:
goto unimplemented;
#endif
case TARGET_NR_statfs:
if (!(p = lock_user_string(arg1)))
goto efault;
ret = get_errno(statfs(path(p), &stfs));
unlock_user(p, arg1, 0);
convert_statfs:
if (!is_error(ret)) {
struct target_statfs *target_stfs;
if (!lock_user_struct(VERIFY_WRITE, target_stfs, arg2, 0))
goto efault;
__put_user(stfs.f_type, &target_stfs->f_type);
__put_user(stfs.f_bsize, &target_stfs->f_bsize);
__put_user(stfs.f_blocks, &target_stfs->f_blocks);
__put_user(stfs.f_bfree, &target_stfs->f_bfree);
__put_user(stfs.f_bavail, &target_stfs->f_bavail);
__put_user(stfs.f_files, &target_stfs->f_files);
__put_user(stfs.f_ffree, &target_stfs->f_ffree);
__put_user(stfs.f_fsid.__val[0], &target_stfs->f_fsid.val[0]);
__put_user(stfs.f_fsid.__val[1], &target_stfs->f_fsid.val[1]);
__put_user(stfs.f_namelen, &target_stfs->f_namelen);
__put_user(stfs.f_frsize, &target_stfs->f_frsize);
memset(target_stfs->f_spare, 0, sizeof(target_stfs->f_spare));
unlock_user_struct(target_stfs, arg2, 1);
case TARGET_NR_fstatfs:
ret = get_errno(fstatfs(arg1, &stfs));
goto convert_statfs;
#ifdef TARGET_NR_statfs64
case TARGET_NR_statfs64:
if (!(p = lock_user_string(arg1)))
goto efault;
ret = get_errno(statfs(path(p), &stfs));
unlock_user(p, arg1, 0);
convert_statfs64:
if (!is_error(ret)) {
struct target_statfs64 *target_stfs;
if (!lock_user_struct(VERIFY_WRITE, target_stfs, arg3, 0))
goto efault;
__put_user(stfs.f_type, &target_stfs->f_type);
__put_user(stfs.f_bsize, &target_stfs->f_bsize);
__put_user(stfs.f_blocks, &target_stfs->f_blocks);
__put_user(stfs.f_bfree, &target_stfs->f_bfree);
__put_user(stfs.f_bavail, &target_stfs->f_bavail);
__put_user(stfs.f_files, &target_stfs->f_files);
__put_user(stfs.f_ffree, &target_stfs->f_ffree);
__put_user(stfs.f_fsid.__val[0], &target_stfs->f_fsid.val[0]);
__put_user(stfs.f_fsid.__val[1], &target_stfs->f_fsid.val[1]);
__put_user(stfs.f_namelen, &target_stfs->f_namelen);
__put_user(stfs.f_frsize, &target_stfs->f_frsize);
memset(target_stfs->f_spare, 0, sizeof(target_stfs->f_spare));
unlock_user_struct(target_stfs, arg3, 1);
case TARGET_NR_fstatfs64:
ret = get_errno(fstatfs(arg1, &stfs));
goto convert_statfs64;
#endif
#ifdef TARGET_NR_ioperm
case TARGET_NR_ioperm:
goto unimplemented;
#endif
#ifdef TARGET_NR_socketcall
case TARGET_NR_socketcall:
ret = do_socketcall(arg1, arg2);
#endif
#ifdef TARGET_NR_accept
case TARGET_NR_accept:
ret = do_accept4(arg1, arg2, arg3, 0);
#endif
#ifdef TARGET_NR_accept4
case TARGET_NR_accept4:
ret = do_accept4(arg1, arg2, arg3, arg4);
#endif
#ifdef TARGET_NR_bind
case TARGET_NR_bind:
ret = do_bind(arg1, arg2, arg3);
#endif
#ifdef TARGET_NR_connect
case TARGET_NR_connect:
ret = do_connect(arg1, arg2, arg3);
#endif
#ifdef TARGET_NR_getpeername
case TARGET_NR_getpeername:
ret = do_getpeername(arg1, arg2, arg3);
#endif
#ifdef TARGET_NR_getsockname
case TARGET_NR_getsockname:
ret = do_getsockname(arg1, arg2, arg3);
#endif
#ifdef TARGET_NR_getsockopt
case TARGET_NR_getsockopt:
ret = do_getsockopt(arg1, arg2, arg3, arg4, arg5);
#endif
#ifdef TARGET_NR_listen
case TARGET_NR_listen:
ret = get_errno(listen(arg1, arg2));
#endif
#ifdef TARGET_NR_recv
case TARGET_NR_recv:
ret = do_recvfrom(arg1, arg2, arg3, arg4, 0, 0);
#endif
#ifdef TARGET_NR_recvfrom
case TARGET_NR_recvfrom:
ret = do_recvfrom(arg1, arg2, arg3, arg4, arg5, arg6);
#endif
#ifdef TARGET_NR_recvmsg
case TARGET_NR_recvmsg:
ret = do_sendrecvmsg(arg1, arg2, arg3, 0);
#endif
#ifdef TARGET_NR_send
case TARGET_NR_send:
ret = do_sendto(arg1, arg2, arg3, arg4, 0, 0);
#endif
#ifdef TARGET_NR_sendmsg
case TARGET_NR_sendmsg:
ret = do_sendrecvmsg(arg1, arg2, arg3, 1);
#endif
#ifdef TARGET_NR_sendmmsg
case TARGET_NR_sendmmsg:
ret = do_sendrecvmmsg(arg1, arg2, arg3, arg4, 1);
case TARGET_NR_recvmmsg:
ret = do_sendrecvmmsg(arg1, arg2, arg3, arg4, 0);
#endif
#ifdef TARGET_NR_sendto
case TARGET_NR_sendto:
ret = do_sendto(arg1, arg2, arg3, arg4, arg5, arg6);
#endif
#ifdef TARGET_NR_shutdown
case TARGET_NR_shutdown:
ret = get_errno(shutdown(arg1, arg2));
#endif
#if defined(TARGET_NR_getrandom) && defined(__NR_getrandom)
case TARGET_NR_getrandom:
p = lock_user(VERIFY_WRITE, arg1, arg2, 0);
if (!p) {
goto efault;
ret = get_errno(getrandom(p, arg2, arg3));
unlock_user(p, arg1, ret);
#endif
#ifdef TARGET_NR_socket
case TARGET_NR_socket:
ret = do_socket(arg1, arg2, arg3);
fd_trans_unregister(ret);
#endif
#ifdef TARGET_NR_socketpair
case TARGET_NR_socketpair:
ret = do_socketpair(arg1, arg2, arg3, arg4);
#endif
#ifdef TARGET_NR_setsockopt
case TARGET_NR_setsockopt:
ret = do_setsockopt(arg1, arg2, arg3, arg4, (socklen_t) arg5);
#endif
case TARGET_NR_syslog:
if (!(p = lock_user_string(arg2)))
goto efault;
ret = get_errno(sys_syslog((int)arg1, p, (int)arg3));
unlock_user(p, arg2, 0);
case TARGET_NR_setitimer:
{
struct itimerval value, ovalue, *pvalue;
if (arg2) {
pvalue = &value;
if (copy_from_user_timeval(&pvalue->it_interval, arg2)
|| copy_from_user_timeval(&pvalue->it_value,
arg2 + sizeof(struct target_timeval)))
goto efault;
} else {
pvalue = NULL;
ret = get_errno(setitimer(arg1, pvalue, &ovalue));
if (!is_error(ret) && arg3) {
if (copy_to_user_timeval(arg3,
&ovalue.it_interval)
|| copy_to_user_timeval(arg3 + sizeof(struct target_timeval),
&ovalue.it_value))
goto efault;
case TARGET_NR_getitimer:
{
struct itimerval value;
ret = get_errno(getitimer(arg1, &value));
if (!is_error(ret) && arg2) {
if (copy_to_user_timeval(arg2,
&value.it_interval)
|| copy_to_user_timeval(arg2 + sizeof(struct target_timeval),
&value.it_value))
goto efault;
#ifdef TARGET_NR_stat
case TARGET_NR_stat:
if (!(p = lock_user_string(arg1)))
goto efault;
ret = get_errno(stat(path(p), &st));
unlock_user(p, arg1, 0);
goto do_stat;
#endif
#ifdef TARGET_NR_lstat
case TARGET_NR_lstat:
if (!(p = lock_user_string(arg1)))
goto efault;
ret = get_errno(lstat(path(p), &st));
unlock_user(p, arg1, 0);
goto do_stat;
#endif
case TARGET_NR_fstat:
{
ret = get_errno(fstat(arg1, &st));
#if defined(TARGET_NR_stat) || defined(TARGET_NR_lstat)
do_stat:
#endif
if (!is_error(ret)) {
struct target_stat *target_st;
if (!lock_user_struct(VERIFY_WRITE, target_st, arg2, 0))
goto efault;
memset(target_st, 0, sizeof(*target_st));
__put_user(st.st_dev, &target_st->st_dev);
__put_user(st.st_ino, &target_st->st_ino);
__put_user(st.st_mode, &target_st->st_mode);
__put_user(st.st_uid, &target_st->st_uid);
__put_user(st.st_gid, &target_st->st_gid);
__put_user(st.st_nlink, &target_st->st_nlink);
__put_user(st.st_rdev, &target_st->st_rdev);
__put_user(st.st_size, &target_st->st_size);
__put_user(st.st_blksize, &target_st->st_blksize);
__put_user(st.st_blocks, &target_st->st_blocks);
__put_user(st.st_atime, &target_st->target_st_atime);
__put_user(st.st_mtime, &target_st->target_st_mtime);
__put_user(st.st_ctime, &target_st->target_st_ctime);
unlock_user_struct(target_st, arg2, 1);
#ifdef TARGET_NR_olduname
case TARGET_NR_olduname:
goto unimplemented;
#endif
#ifdef TARGET_NR_iopl
case TARGET_NR_iopl:
goto unimplemented;
#endif
case TARGET_NR_vhangup:
ret = get_errno(vhangup());
#ifdef TARGET_NR_idle
case TARGET_NR_idle:
goto unimplemented;
#endif
#ifdef TARGET_NR_syscall
case TARGET_NR_syscall:
ret = do_syscall(cpu_env, arg1 & 0xffff, arg2, arg3, arg4, arg5,
arg6, arg7, arg8, 0);
#endif
case TARGET_NR_wait4:
{
int status;
abi_long status_ptr = arg2;
struct rusage rusage, *rusage_ptr;
abi_ulong target_rusage = arg4;
abi_long rusage_err;
if (target_rusage)
rusage_ptr = &rusage;
else
rusage_ptr = NULL;
ret = get_errno(safe_wait4(arg1, &status, arg3, rusage_ptr));
if (!is_error(ret)) {
if (status_ptr && ret) {
status = host_to_target_waitstatus(status);
if (put_user_s32(status, status_ptr))
goto efault;
if (target_rusage) {
rusage_err = host_to_target_rusage(target_rusage, &rusage);
if (rusage_err) {
ret = rusage_err;
#ifdef TARGET_NR_swapoff
case TARGET_NR_swapoff:
if (!(p = lock_user_string(arg1)))
goto efault;
ret = get_errno(swapoff(p));
unlock_user(p, arg1, 0);
#endif
case TARGET_NR_sysinfo:
{
struct target_sysinfo *target_value;
struct sysinfo value;
ret = get_errno(sysinfo(&value));
if (!is_error(ret) && arg1)
{
if (!lock_user_struct(VERIFY_WRITE, target_value, arg1, 0))
goto efault;
__put_user(value.uptime, &target_value->uptime);
__put_user(value.loads[0], &target_value->loads[0]);
__put_user(value.loads[1], &target_value->loads[1]);
__put_user(value.loads[2], &target_value->loads[2]);
__put_user(value.totalram, &target_value->totalram);
__put_user(value.freeram, &target_value->freeram);
__put_user(value.sharedram, &target_value->sharedram);
__put_user(value.bufferram, &target_value->bufferram);
__put_user(value.totalswap, &target_value->totalswap);
__put_user(value.freeswap, &target_value->freeswap);
__put_user(value.procs, &target_value->procs);
__put_user(value.totalhigh, &target_value->totalhigh);
__put_user(value.freehigh, &target_value->freehigh);
__put_user(value.mem_unit, &target_value->mem_unit);
unlock_user_struct(target_value, arg1, 1);
#ifdef TARGET_NR_ipc
case TARGET_NR_ipc:
ret = do_ipc(arg1, arg2, arg3, arg4, arg5, arg6);
#endif
#ifdef TARGET_NR_semget
case TARGET_NR_semget:
ret = get_errno(semget(arg1, arg2, arg3));
#endif
#ifdef TARGET_NR_semop
case TARGET_NR_semop:
ret = do_semop(arg1, arg2, arg3);
#endif
#ifdef TARGET_NR_semctl
case TARGET_NR_semctl:
ret = do_semctl(arg1, arg2, arg3, arg4);
#endif
#ifdef TARGET_NR_msgctl
case TARGET_NR_msgctl:
ret = do_msgctl(arg1, arg2, arg3);
#endif
#ifdef TARGET_NR_msgget
case TARGET_NR_msgget:
ret = get_errno(msgget(arg1, arg2));
#endif
#ifdef TARGET_NR_msgrcv
case TARGET_NR_msgrcv:
ret = do_msgrcv(arg1, arg2, arg3, arg4, arg5);
#endif
#ifdef TARGET_NR_msgsnd
case TARGET_NR_msgsnd:
ret = do_msgsnd(arg1, arg2, arg3, arg4);
#endif
#ifdef TARGET_NR_shmget
case TARGET_NR_shmget:
ret = get_errno(shmget(arg1, arg2, arg3));
#endif
#ifdef TARGET_NR_shmctl
case TARGET_NR_shmctl:
ret = do_shmctl(arg1, arg2, arg3);
#endif
#ifdef TARGET_NR_shmat
case TARGET_NR_shmat:
ret = do_shmat(arg1, arg2, arg3);
#endif
#ifdef TARGET_NR_shmdt
case TARGET_NR_shmdt:
ret = do_shmdt(arg1);
#endif
case TARGET_NR_fsync:
ret = get_errno(fsync(arg1));
case TARGET_NR_clone:
/* Linux manages to have three different orderings for its
* arguments to clone(); the BACKWARDS and BACKWARDS2 defines
* match the kernel's CONFIG_CLONE_* settings.
* Microblaze is further special in that it uses a sixth
* implicit argument to clone for the TLS pointer.
*/
#if defined(TARGET_MICROBLAZE)
ret = get_errno(do_fork(cpu_env, arg1, arg2, arg4, arg6, arg5));
#elif defined(TARGET_CLONE_BACKWARDS)
ret = get_errno(do_fork(cpu_env, arg1, arg2, arg3, arg4, arg5));
#elif defined(TARGET_CLONE_BACKWARDS2)
ret = get_errno(do_fork(cpu_env, arg2, arg1, arg3, arg5, arg4));
#else
ret = get_errno(do_fork(cpu_env, arg1, arg2, arg3, arg5, arg4));
#endif
#ifdef __NR_exit_group
/* new thread calls */
case TARGET_NR_exit_group:
#ifdef TARGET_GPROF
_mcleanup();
#endif
gdb_exit(cpu_env, arg1);
ret = get_errno(exit_group(arg1));
#endif
case TARGET_NR_setdomainname:
if (!(p = lock_user_string(arg1)))
goto efault;
ret = get_errno(setdomainname(p, arg2));
unlock_user(p, arg1, 0);
case TARGET_NR_uname:
/* no need to transcode because we use the linux syscall */
{
struct new_utsname * buf;
if (!lock_user_struct(VERIFY_WRITE, buf, arg1, 0))
goto efault;
ret = get_errno(sys_uname(buf));
if (!is_error(ret)) {
/* Overwrite the native machine name with whatever is being
emulated. */
strcpy (buf->machine, cpu_to_uname_machine(cpu_env));
/* Allow the user to override the reported release. */
if (qemu_uname_release && *qemu_uname_release) {
g_strlcpy(buf->release, qemu_uname_release,
sizeof(buf->release));
unlock_user_struct(buf, arg1, 1);
#ifdef TARGET_I386
case TARGET_NR_modify_ldt:
ret = do_modify_ldt(cpu_env, arg1, arg2, arg3);
#if !defined(TARGET_X86_64)
case TARGET_NR_vm86old:
goto unimplemented;
case TARGET_NR_vm86:
ret = do_vm86(cpu_env, arg1, arg2);
#endif
#endif
case TARGET_NR_adjtimex:
goto unimplemented;
#ifdef TARGET_NR_create_module
case TARGET_NR_create_module:
#endif
case TARGET_NR_init_module:
case TARGET_NR_delete_module:
#ifdef TARGET_NR_get_kernel_syms
case TARGET_NR_get_kernel_syms:
#endif
goto unimplemented;
case TARGET_NR_quotactl:
goto unimplemented;
case TARGET_NR_getpgid:
ret = get_errno(getpgid(arg1));
case TARGET_NR_fchdir:
ret = get_errno(fchdir(arg1));
#ifdef TARGET_NR_bdflush /* not on x86_64 */
case TARGET_NR_bdflush:
goto unimplemented;
#endif
#ifdef TARGET_NR_sysfs
case TARGET_NR_sysfs:
goto unimplemented;
#endif
case TARGET_NR_personality:
ret = get_errno(personality(arg1));
#ifdef TARGET_NR_afs_syscall
case TARGET_NR_afs_syscall:
goto unimplemented;
#endif
#ifdef TARGET_NR__llseek /* Not on alpha */
case TARGET_NR__llseek:
{
int64_t res;
#if !defined(__NR_llseek)
res = lseek(arg1, ((uint64_t)arg2 << 32) | (abi_ulong)arg3, arg5);
if (res == -1) {
ret = get_errno(res);
} else {
ret = 0;
#else
ret = get_errno(_llseek(arg1, arg2, arg3, &res, arg5));
#endif
if ((ret == 0) && put_user_s64(res, arg4)) {
goto efault;
#endif
#ifdef TARGET_NR_getdents
case TARGET_NR_getdents:
#ifdef __NR_getdents
#if TARGET_ABI_BITS == 32 && HOST_LONG_BITS == 64
{
struct target_dirent *target_dirp;
struct linux_dirent *dirp;
abi_long count = arg3;
dirp = g_try_malloc(count);
if (!dirp) {
ret = -TARGET_ENOMEM;
goto fail;
ret = get_errno(sys_getdents(arg1, dirp, count));
if (!is_error(ret)) {
struct linux_dirent *de;
struct target_dirent *tde;
int len = ret;
int reclen, treclen;
int count1, tnamelen;
count1 = 0;
de = dirp;
if (!(target_dirp = lock_user(VERIFY_WRITE, arg2, count, 0)))
goto efault;
tde = target_dirp;
while (len > 0) {
reclen = de->d_reclen;
tnamelen = reclen - offsetof(struct linux_dirent, d_name);
assert(tnamelen >= 0);
treclen = tnamelen + offsetof(struct target_dirent, d_name);
assert(count1 + treclen <= count);
tde->d_reclen = tswap16(treclen);
tde->d_ino = tswapal(de->d_ino);
tde->d_off = tswapal(de->d_off);
memcpy(tde->d_name, de->d_name, tnamelen);
de = (struct linux_dirent *)((char *)de + reclen);
len -= reclen;
tde = (struct target_dirent *)((char *)tde + treclen);
count1 += treclen;
ret = count1;
unlock_user(target_dirp, arg2, ret);
g_free(dirp);
#else
{
struct linux_dirent *dirp;
abi_long count = arg3;
if (!(dirp = lock_user(VERIFY_WRITE, arg2, count, 0)))
goto efault;
ret = get_errno(sys_getdents(arg1, dirp, count));
if (!is_error(ret)) {
struct linux_dirent *de;
int len = ret;
int reclen;
de = dirp;
while (len > 0) {
reclen = de->d_reclen;
if (reclen > len)
de->d_reclen = tswap16(reclen);
tswapls(&de->d_ino);
tswapls(&de->d_off);
de = (struct linux_dirent *)((char *)de + reclen);
len -= reclen;
unlock_user(dirp, arg2, ret);
#endif
#else
/* Implement getdents in terms of getdents64 */
{
struct linux_dirent64 *dirp;
abi_long count = arg3;
dirp = lock_user(VERIFY_WRITE, arg2, count, 0);
if (!dirp) {
goto efault;
ret = get_errno(sys_getdents64(arg1, dirp, count));
if (!is_error(ret)) {
/* Convert the dirent64 structs to target dirent. We do this
* in-place, since we can guarantee that a target_dirent is no
* larger than a dirent64; however this means we have to be
* careful to read everything before writing in the new format.
*/
struct linux_dirent64 *de;
struct target_dirent *tde;
int len = ret;
int tlen = 0;
de = dirp;
tde = (struct target_dirent *)dirp;
while (len > 0) {
int namelen, treclen;
int reclen = de->d_reclen;
uint64_t ino = de->d_ino;
int64_t off = de->d_off;
uint8_t type = de->d_type;
namelen = strlen(de->d_name);
treclen = offsetof(struct target_dirent, d_name)
+ namelen + 2;
treclen = QEMU_ALIGN_UP(treclen, sizeof(abi_long));
memmove(tde->d_name, de->d_name, namelen + 1);
tde->d_ino = tswapal(ino);
tde->d_off = tswapal(off);
tde->d_reclen = tswap16(treclen);
/* The target_dirent type is in what was formerly a padding
* byte at the end of the structure:
*/
*(((char *)tde) + treclen - 1) = type;
de = (struct linux_dirent64 *)((char *)de + reclen);
tde = (struct target_dirent *)((char *)tde + treclen);
len -= reclen;
tlen += treclen;
ret = tlen;
unlock_user(dirp, arg2, ret);
#endif
#endif /* TARGET_NR_getdents */
#if defined(TARGET_NR_getdents64) && defined(__NR_getdents64)
case TARGET_NR_getdents64:
{
struct linux_dirent64 *dirp;
abi_long count = arg3;
if (!(dirp = lock_user(VERIFY_WRITE, arg2, count, 0)))
goto efault;
ret = get_errno(sys_getdents64(arg1, dirp, count));
if (!is_error(ret)) {
struct linux_dirent64 *de;
int len = ret;
int reclen;
de = dirp;
while (len > 0) {
reclen = de->d_reclen;
if (reclen > len)
de->d_reclen = tswap16(reclen);
tswap64s((uint64_t *)&de->d_ino);
tswap64s((uint64_t *)&de->d_off);
de = (struct linux_dirent64 *)((char *)de + reclen);
len -= reclen;
unlock_user(dirp, arg2, ret);
#endif /* TARGET_NR_getdents64 */
#if defined(TARGET_NR__newselect)
case TARGET_NR__newselect:
ret = do_select(arg1, arg2, arg3, arg4, arg5);
#endif
#if defined(TARGET_NR_poll) || defined(TARGET_NR_ppoll)
# ifdef TARGET_NR_poll
case TARGET_NR_poll:
# endif
# ifdef TARGET_NR_ppoll
case TARGET_NR_ppoll:
# endif
{
struct target_pollfd *target_pfd;
unsigned int nfds = arg2;
struct pollfd *pfd;
unsigned int i;
pfd = NULL;
target_pfd = NULL;
if (nfds) {
target_pfd = lock_user(VERIFY_WRITE, arg1,
sizeof(struct target_pollfd) * nfds, 1);
if (!target_pfd) {
goto efault;
pfd = alloca(sizeof(struct pollfd) * nfds);
for (i = 0; i < nfds; i++) {
pfd[i].fd = tswap32(target_pfd[i].fd);
pfd[i].events = tswap16(target_pfd[i].events);
switch (num) {
# ifdef TARGET_NR_ppoll
case TARGET_NR_ppoll:
{
struct timespec _timeout_ts, *timeout_ts = &_timeout_ts;
target_sigset_t *target_set;
sigset_t _set, *set = &_set;
if (arg3) {
if (target_to_host_timespec(timeout_ts, arg3)) {
unlock_user(target_pfd, arg1, 0);
goto efault;
} else {
timeout_ts = NULL;
if (arg4) {
if (arg5 != sizeof(target_sigset_t)) {
unlock_user(target_pfd, arg1, 0);
target_set = lock_user(VERIFY_READ, arg4, sizeof(target_sigset_t), 1);
if (!target_set) {
unlock_user(target_pfd, arg1, 0);
goto efault;
target_to_host_sigset(set, target_set);
} else {
set = NULL;
ret = get_errno(safe_ppoll(pfd, nfds, timeout_ts,
set, SIGSET_T_SIZE));
if (!is_error(ret) && arg3) {
host_to_target_timespec(arg3, timeout_ts);
if (arg4) {
unlock_user(target_set, arg4, 0);
# endif
# ifdef TARGET_NR_poll
case TARGET_NR_poll:
{
struct timespec ts, *pts;
if (arg3 >= 0) {
/* Convert ms to secs, ns */
ts.tv_sec = arg3 / 1000;
ts.tv_nsec = (arg3 % 1000) * 1000000LL;
pts = &ts;
} else {
/* -ve poll() timeout means "infinite" */
pts = NULL;
ret = get_errno(safe_ppoll(pfd, nfds, pts, NULL, 0));
# endif
default:
g_assert_not_reached();
if (!is_error(ret)) {
for(i = 0; i < nfds; i++) {
target_pfd[i].revents = tswap16(pfd[i].revents);
unlock_user(target_pfd, arg1, sizeof(struct target_pollfd) * nfds);
#endif
case TARGET_NR_flock:
/* NOTE: the flock constant seems to be the same for every
Linux platform */
ret = get_errno(safe_flock(arg1, arg2));
case TARGET_NR_readv:
{
struct iovec *vec = lock_iovec(VERIFY_WRITE, arg2, arg3, 0);
if (vec != NULL) {
ret = get_errno(safe_readv(arg1, vec, arg3));
unlock_iovec(vec, arg2, arg3, 1);
} else {
ret = -host_to_target_errno(errno);
case TARGET_NR_writev:
{
struct iovec *vec = lock_iovec(VERIFY_READ, arg2, arg3, 1);
if (vec != NULL) {
ret = get_errno(safe_writev(arg1, vec, arg3));
unlock_iovec(vec, arg2, arg3, 0);
} else {
ret = -host_to_target_errno(errno);
case TARGET_NR_getsid:
ret = get_errno(getsid(arg1));
#if defined(TARGET_NR_fdatasync) /* Not on alpha (osf_datasync ?) */
case TARGET_NR_fdatasync:
ret = get_errno(fdatasync(arg1));
#endif
#ifdef TARGET_NR__sysctl
case TARGET_NR__sysctl:
/* We don't implement this, but ENOTDIR is always a safe
return value. */
ret = -TARGET_ENOTDIR;
#endif
case TARGET_NR_sched_getaffinity:
{
unsigned int mask_size;
unsigned long *mask;
/*
* sched_getaffinity needs multiples of ulong, so need to take
* care of mismatches between target ulong and host ulong sizes.
*/
if (arg2 & (sizeof(abi_ulong) - 1)) {
mask_size = (arg2 + (sizeof(*mask) - 1)) & ~(sizeof(*mask) - 1);
mask = alloca(mask_size);
ret = get_errno(sys_sched_getaffinity(arg1, mask_size, mask));
if (!is_error(ret)) {
if (ret > arg2) {
/* More data returned than the caller's buffer will fit.
* This only happens if sizeof(abi_long) < sizeof(long)
* and the caller passed us a buffer holding an odd number
* of abi_longs. If the host kernel is actually using the
* extra 4 bytes then fail EINVAL; otherwise we can just
* ignore them and only copy the interesting part.
*/
int numcpus = sysconf(_SC_NPROCESSORS_CONF);
if (numcpus > arg2 * 8) {
ret = arg2;
if (copy_to_user(arg3, mask, ret)) {
goto efault;
case TARGET_NR_sched_setaffinity:
{
unsigned int mask_size;
unsigned long *mask;
/*
* sched_setaffinity needs multiples of ulong, so need to take
* care of mismatches between target ulong and host ulong sizes.
*/
if (arg2 & (sizeof(abi_ulong) - 1)) {
mask_size = (arg2 + (sizeof(*mask) - 1)) & ~(sizeof(*mask) - 1);
mask = alloca(mask_size);
if (!lock_user_struct(VERIFY_READ, p, arg3, 1)) {
goto efault;
memcpy(mask, p, arg2);
unlock_user_struct(p, arg2, 0);
ret = get_errno(sys_sched_setaffinity(arg1, mask_size, mask));
case TARGET_NR_sched_setparam:
{
struct sched_param *target_schp;
struct sched_param schp;
if (arg2 == 0) {
return -TARGET_EINVAL;
if (!lock_user_struct(VERIFY_READ, target_schp, arg2, 1))
goto efault;
schp.sched_priority = tswap32(target_schp->sched_priority);
unlock_user_struct(target_schp, arg2, 0);
ret = get_errno(sched_setparam(arg1, &schp));
case TARGET_NR_sched_getparam:
{
struct sched_param *target_schp;
struct sched_param schp;
if (arg2 == 0) {
return -TARGET_EINVAL;
ret = get_errno(sched_getparam(arg1, &schp));
if (!is_error(ret)) {
if (!lock_user_struct(VERIFY_WRITE, target_schp, arg2, 0))
goto efault;
target_schp->sched_priority = tswap32(schp.sched_priority);
unlock_user_struct(target_schp, arg2, 1);
case TARGET_NR_sched_setscheduler:
{
struct sched_param *target_schp;
struct sched_param schp;
if (arg3 == 0) {
return -TARGET_EINVAL;
if (!lock_user_struct(VERIFY_READ, target_schp, arg3, 1))
goto efault;
schp.sched_priority = tswap32(target_schp->sched_priority);
unlock_user_struct(target_schp, arg3, 0);
ret = get_errno(sched_setscheduler(arg1, arg2, &schp));
case TARGET_NR_sched_getscheduler:
ret = get_errno(sched_getscheduler(arg1));
case TARGET_NR_sched_yield:
ret = get_errno(sched_yield());
case TARGET_NR_sched_get_priority_max:
ret = get_errno(sched_get_priority_max(arg1));
case TARGET_NR_sched_get_priority_min:
ret = get_errno(sched_get_priority_min(arg1));
case TARGET_NR_sched_rr_get_interval:
{
struct timespec ts;
ret = get_errno(sched_rr_get_interval(arg1, &ts));
if (!is_error(ret)) {
ret = host_to_target_timespec(arg2, &ts);
case TARGET_NR_nanosleep:
{
struct timespec req, rem;
target_to_host_timespec(&req, arg1);
ret = get_errno(safe_nanosleep(&req, &rem));
if (is_error(ret) && arg2) {
host_to_target_timespec(arg2, &rem);
#ifdef TARGET_NR_query_module
case TARGET_NR_query_module:
goto unimplemented;
#endif
#ifdef TARGET_NR_nfsservctl
case TARGET_NR_nfsservctl:
goto unimplemented;
#endif
case TARGET_NR_prctl:
switch (arg1) {
case PR_GET_PDEATHSIG:
{
int deathsig;
ret = get_errno(prctl(arg1, &deathsig, arg3, arg4, arg5));
if (!is_error(ret) && arg2
&& put_user_ual(deathsig, arg2)) {
goto efault;
#ifdef PR_GET_NAME
case PR_GET_NAME:
{
void *name = lock_user(VERIFY_WRITE, arg2, 16, 1);
if (!name) {
goto efault;
ret = get_errno(prctl(arg1, (unsigned long)name,
arg3, arg4, arg5));
unlock_user(name, arg2, 16);
case PR_SET_NAME:
{
void *name = lock_user(VERIFY_READ, arg2, 16, 1);
if (!name) {
goto efault;
ret = get_errno(prctl(arg1, (unsigned long)name,
arg3, arg4, arg5));
unlock_user(name, arg2, 0);
#endif
default:
/* Most prctl options have no pointer arguments */
ret = get_errno(prctl(arg1, arg2, arg3, arg4, arg5));
#ifdef TARGET_NR_arch_prctl
case TARGET_NR_arch_prctl:
#if defined(TARGET_I386) && !defined(TARGET_ABI32)
ret = do_arch_prctl(cpu_env, arg1, arg2);
#else
goto unimplemented;
#endif
#endif
#ifdef TARGET_NR_pread64
case TARGET_NR_pread64:
if (regpairs_aligned(cpu_env)) {
arg4 = arg5;
arg5 = arg6;
if (!(p = lock_user(VERIFY_WRITE, arg2, arg3, 0)))
goto efault;
ret = get_errno(pread64(arg1, p, arg3, target_offset64(arg4, arg5)));
unlock_user(p, arg2, ret);
case TARGET_NR_pwrite64:
if (regpairs_aligned(cpu_env)) {
arg4 = arg5;
arg5 = arg6;
if (!(p = lock_user(VERIFY_READ, arg2, arg3, 1)))
goto efault;
ret = get_errno(pwrite64(arg1, p, arg3, target_offset64(arg4, arg5)));
unlock_user(p, arg2, 0);
#endif
case TARGET_NR_getcwd:
if (!(p = lock_user(VERIFY_WRITE, arg1, arg2, 0)))
goto efault;
ret = get_errno(sys_getcwd1(p, arg2));
unlock_user(p, arg1, ret);
case TARGET_NR_capget:
case TARGET_NR_capset:
{
struct target_user_cap_header *target_header;
struct target_user_cap_data *target_data = NULL;
struct __user_cap_header_struct header;
struct __user_cap_data_struct data[2];
struct __user_cap_data_struct *dataptr = NULL;
int i, target_datalen;
int data_items = 1;
if (!lock_user_struct(VERIFY_WRITE, target_header, arg1, 1)) {
goto efault;
header.version = tswap32(target_header->version);
header.pid = tswap32(target_header->pid);
if (header.version != _LINUX_CAPABILITY_VERSION) {
/* Version 2 and up takes pointer to two user_data structs */
data_items = 2;
target_datalen = sizeof(*target_data) * data_items;
if (arg2) {
if (num == TARGET_NR_capget) {
target_data = lock_user(VERIFY_WRITE, arg2, target_datalen, 0);
} else {
target_data = lock_user(VERIFY_READ, arg2, target_datalen, 1);
if (!target_data) {
unlock_user_struct(target_header, arg1, 0);
goto efault;
if (num == TARGET_NR_capset) {
for (i = 0; i < data_items; i++) {
data[i].effective = tswap32(target_data[i].effective);
data[i].permitted = tswap32(target_data[i].permitted);
data[i].inheritable = tswap32(target_data[i].inheritable);
dataptr = data;
if (num == TARGET_NR_capget) {
ret = get_errno(capget(&header, dataptr));
} else {
ret = get_errno(capset(&header, dataptr));
/* The kernel always updates version for both capget and capset */
target_header->version = tswap32(header.version);
unlock_user_struct(target_header, arg1, 1);
if (arg2) {
if (num == TARGET_NR_capget) {
for (i = 0; i < data_items; i++) {
target_data[i].effective = tswap32(data[i].effective);
target_data[i].permitted = tswap32(data[i].permitted);
target_data[i].inheritable = tswap32(data[i].inheritable);
unlock_user(target_data, arg2, target_datalen);
} else {
unlock_user(target_data, arg2, 0);
case TARGET_NR_sigaltstack:
ret = do_sigaltstack(arg1, arg2, get_sp_from_cpustate((CPUArchState *)cpu_env));
#ifdef CONFIG_SENDFILE
case TARGET_NR_sendfile:
{
off_t *offp = NULL;
off_t off;
if (arg3) {
ret = get_user_sal(off, arg3);
if (is_error(ret)) {
offp = &off;
ret = get_errno(sendfile(arg1, arg2, offp, arg4));
if (!is_error(ret) && arg3) {
abi_long ret2 = put_user_sal(off, arg3);
if (is_error(ret2)) {
ret = ret2;
#ifdef TARGET_NR_sendfile64
case TARGET_NR_sendfile64:
{
off_t *offp = NULL;
off_t off;
if (arg3) {
ret = get_user_s64(off, arg3);
if (is_error(ret)) {
offp = &off;
ret = get_errno(sendfile(arg1, arg2, offp, arg4));
if (!is_error(ret) && arg3) {
abi_long ret2 = put_user_s64(off, arg3);
if (is_error(ret2)) {
ret = ret2;
#endif
#else
case TARGET_NR_sendfile:
#ifdef TARGET_NR_sendfile64
case TARGET_NR_sendfile64:
#endif
goto unimplemented;
#endif
#ifdef TARGET_NR_getpmsg
case TARGET_NR_getpmsg:
goto unimplemented;
#endif
#ifdef TARGET_NR_putpmsg
case TARGET_NR_putpmsg:
goto unimplemented;
#endif
#ifdef TARGET_NR_vfork
case TARGET_NR_vfork:
ret = get_errno(do_fork(cpu_env, CLONE_VFORK | CLONE_VM | SIGCHLD,
0, 0, 0, 0));
#endif
#ifdef TARGET_NR_ugetrlimit
case TARGET_NR_ugetrlimit:
{
struct rlimit rlim;
int resource = target_to_host_resource(arg1);
ret = get_errno(getrlimit(resource, &rlim));
if (!is_error(ret)) {
struct target_rlimit *target_rlim;
if (!lock_user_struct(VERIFY_WRITE, target_rlim, arg2, 0))
goto efault;
target_rlim->rlim_cur = host_to_target_rlim(rlim.rlim_cur);
target_rlim->rlim_max = host_to_target_rlim(rlim.rlim_max);
unlock_user_struct(target_rlim, arg2, 1);
#endif
#ifdef TARGET_NR_truncate64
case TARGET_NR_truncate64:
if (!(p = lock_user_string(arg1)))
goto efault;
ret = target_truncate64(cpu_env, p, arg2, arg3, arg4);
unlock_user(p, arg1, 0);
#endif
#ifdef TARGET_NR_ftruncate64
case TARGET_NR_ftruncate64:
ret = target_ftruncate64(cpu_env, arg1, arg2, arg3, arg4);
#endif
#ifdef TARGET_NR_stat64
case TARGET_NR_stat64:
if (!(p = lock_user_string(arg1)))
goto efault;
ret = get_errno(stat(path(p), &st));
unlock_user(p, arg1, 0);
if (!is_error(ret))
ret = host_to_target_stat64(cpu_env, arg2, &st);
#endif
#ifdef TARGET_NR_lstat64
case TARGET_NR_lstat64:
if (!(p = lock_user_string(arg1)))
goto efault;
ret = get_errno(lstat(path(p), &st));
unlock_user(p, arg1, 0);
if (!is_error(ret))
ret = host_to_target_stat64(cpu_env, arg2, &st);
#endif
#ifdef TARGET_NR_fstat64
case TARGET_NR_fstat64:
ret = get_errno(fstat(arg1, &st));
if (!is_error(ret))
ret = host_to_target_stat64(cpu_env, arg2, &st);
#endif
#if (defined(TARGET_NR_fstatat64) || defined(TARGET_NR_newfstatat))
#ifdef TARGET_NR_fstatat64
case TARGET_NR_fstatat64:
#endif
#ifdef TARGET_NR_newfstatat
case TARGET_NR_newfstatat:
#endif
if (!(p = lock_user_string(arg2)))
goto efault;
ret = get_errno(fstatat(arg1, path(p), &st, arg4));
if (!is_error(ret))
ret = host_to_target_stat64(cpu_env, arg3, &st);
#endif
#ifdef TARGET_NR_lchown
case TARGET_NR_lchown:
if (!(p = lock_user_string(arg1)))
goto efault;
ret = get_errno(lchown(p, low2highuid(arg2), low2highgid(arg3)));
unlock_user(p, arg1, 0);
#endif
#ifdef TARGET_NR_getuid
case TARGET_NR_getuid:
ret = get_errno(high2lowuid(getuid()));
#endif
#ifdef TARGET_NR_getgid
case TARGET_NR_getgid:
ret = get_errno(high2lowgid(getgid()));
#endif
#ifdef TARGET_NR_geteuid
case TARGET_NR_geteuid:
ret = get_errno(high2lowuid(geteuid()));
#endif
#ifdef TARGET_NR_getegid
case TARGET_NR_getegid:
ret = get_errno(high2lowgid(getegid()));
#endif
case TARGET_NR_setreuid:
ret = get_errno(setreuid(low2highuid(arg1), low2highuid(arg2)));
case TARGET_NR_setregid:
ret = get_errno(setregid(low2highgid(arg1), low2highgid(arg2)));
case TARGET_NR_getgroups:
{
int gidsetsize = arg1;
target_id *target_grouplist;
gid_t *grouplist;
int i;
grouplist = alloca(gidsetsize * sizeof(gid_t));
ret = get_errno(getgroups(gidsetsize, grouplist));
if (gidsetsize == 0)
if (!is_error(ret)) {
target_grouplist = lock_user(VERIFY_WRITE, arg2, gidsetsize * sizeof(target_id), 0);
if (!target_grouplist)
goto efault;
for(i = 0;i < ret; i++)
target_grouplist[i] = tswapid(high2lowgid(grouplist[i]));
unlock_user(target_grouplist, arg2, gidsetsize * sizeof(target_id));
case TARGET_NR_setgroups:
{
int gidsetsize = arg1;
target_id *target_grouplist;
gid_t *grouplist = NULL;
int i;
if (gidsetsize) {
grouplist = alloca(gidsetsize * sizeof(gid_t));
target_grouplist = lock_user(VERIFY_READ, arg2, gidsetsize * sizeof(target_id), 1);
if (!target_grouplist) {
ret = -TARGET_EFAULT;
goto fail;
for (i = 0; i < gidsetsize; i++) {
grouplist[i] = low2highgid(tswapid(target_grouplist[i]));
unlock_user(target_grouplist, arg2, 0);
ret = get_errno(setgroups(gidsetsize, grouplist));
case TARGET_NR_fchown:
ret = get_errno(fchown(arg1, low2highuid(arg2), low2highgid(arg3)));
#if defined(TARGET_NR_fchownat)
case TARGET_NR_fchownat:
if (!(p = lock_user_string(arg2)))
goto efault;
ret = get_errno(fchownat(arg1, p, low2highuid(arg3),
low2highgid(arg4), arg5));
unlock_user(p, arg2, 0);
#endif
#ifdef TARGET_NR_setresuid
case TARGET_NR_setresuid:
ret = get_errno(sys_setresuid(low2highuid(arg1),
low2highuid(arg2),
low2highuid(arg3)));
#endif
#ifdef TARGET_NR_getresuid
case TARGET_NR_getresuid:
{
uid_t ruid, euid, suid;
ret = get_errno(getresuid(&ruid, &euid, &suid));
if (!is_error(ret)) {
if (put_user_id(high2lowuid(ruid), arg1)
|| put_user_id(high2lowuid(euid), arg2)
|| put_user_id(high2lowuid(suid), arg3))
goto efault;
#endif
#ifdef TARGET_NR_getresgid
case TARGET_NR_setresgid:
ret = get_errno(sys_setresgid(low2highgid(arg1),
low2highgid(arg2),
low2highgid(arg3)));
#endif
#ifdef TARGET_NR_getresgid
case TARGET_NR_getresgid:
{
gid_t rgid, egid, sgid;
ret = get_errno(getresgid(&rgid, &egid, &sgid));
if (!is_error(ret)) {
if (put_user_id(high2lowgid(rgid), arg1)
|| put_user_id(high2lowgid(egid), arg2)
|| put_user_id(high2lowgid(sgid), arg3))
goto efault;
#endif
#ifdef TARGET_NR_chown
case TARGET_NR_chown:
if (!(p = lock_user_string(arg1)))
goto efault;
ret = get_errno(chown(p, low2highuid(arg2), low2highgid(arg3)));
unlock_user(p, arg1, 0);
#endif
case TARGET_NR_setuid:
ret = get_errno(sys_setuid(low2highuid(arg1)));
case TARGET_NR_setgid:
ret = get_errno(sys_setgid(low2highgid(arg1)));
case TARGET_NR_setfsuid:
ret = get_errno(setfsuid(arg1));
case TARGET_NR_setfsgid:
ret = get_errno(setfsgid(arg1));
#ifdef TARGET_NR_lchown32
case TARGET_NR_lchown32:
if (!(p = lock_user_string(arg1)))
goto efault;
ret = get_errno(lchown(p, arg2, arg3));
unlock_user(p, arg1, 0);
#endif
#ifdef TARGET_NR_getuid32
case TARGET_NR_getuid32:
ret = get_errno(getuid());
#endif
#if defined(TARGET_NR_getxuid) && defined(TARGET_ALPHA)
/* Alpha specific */
case TARGET_NR_getxuid:
{
uid_t euid;
euid=geteuid();
((CPUAlphaState *)cpu_env)->ir[IR_A4]=euid;
ret = get_errno(getuid());
#endif
#if defined(TARGET_NR_getxgid) && defined(TARGET_ALPHA)
/* Alpha specific */
case TARGET_NR_getxgid:
{
uid_t egid;
egid=getegid();
((CPUAlphaState *)cpu_env)->ir[IR_A4]=egid;
ret = get_errno(getgid());
#endif
#if defined(TARGET_NR_osf_getsysinfo) && defined(TARGET_ALPHA)
/* Alpha specific */
case TARGET_NR_osf_getsysinfo:
ret = -TARGET_EOPNOTSUPP;
switch (arg1) {
case TARGET_GSI_IEEE_FP_CONTROL:
{
uint64_t swcr, fpcr = cpu_alpha_load_fpcr (cpu_env);
/* Copied from linux ieee_fpcr_to_swcr. */
swcr = (fpcr >> 35) & SWCR_STATUS_MASK;
swcr |= (fpcr >> 36) & SWCR_MAP_DMZ;
swcr |= (~fpcr >> 48) & (SWCR_TRAP_ENABLE_INV
| SWCR_TRAP_ENABLE_DZE
| SWCR_TRAP_ENABLE_OVF);
swcr |= (~fpcr >> 57) & (SWCR_TRAP_ENABLE_UNF
| SWCR_TRAP_ENABLE_INE);
swcr |= (fpcr >> 47) & SWCR_MAP_UMZ;
swcr |= (~fpcr >> 41) & SWCR_TRAP_ENABLE_DNO;
if (put_user_u64 (swcr, arg2))
goto efault;
ret = 0;
/* case GSI_IEEE_STATE_AT_SIGNAL:
-- Not implemented in linux kernel.
case GSI_UACPROC:
-- Retrieves current unaligned access state; not much used.
case GSI_PROC_TYPE:
-- Retrieves implver information; surely not used.
case GSI_GET_HWRPB:
-- Grabs a copy of the HWRPB; surely not used.
*/
#endif
#if defined(TARGET_NR_osf_setsysinfo) && defined(TARGET_ALPHA)
/* Alpha specific */
case TARGET_NR_osf_setsysinfo:
ret = -TARGET_EOPNOTSUPP;
switch (arg1) {
case TARGET_SSI_IEEE_FP_CONTROL:
{
uint64_t swcr, fpcr, orig_fpcr;
if (get_user_u64 (swcr, arg2)) {
goto efault;
orig_fpcr = cpu_alpha_load_fpcr(cpu_env);
fpcr = orig_fpcr & FPCR_DYN_MASK;
/* Copied from linux ieee_swcr_to_fpcr. */
fpcr |= (swcr & SWCR_STATUS_MASK) << 35;
fpcr |= (swcr & SWCR_MAP_DMZ) << 36;
fpcr |= (~swcr & (SWCR_TRAP_ENABLE_INV
| SWCR_TRAP_ENABLE_DZE
| SWCR_TRAP_ENABLE_OVF)) << 48;
fpcr |= (~swcr & (SWCR_TRAP_ENABLE_UNF
| SWCR_TRAP_ENABLE_INE)) << 57;
fpcr |= (swcr & SWCR_MAP_UMZ ? FPCR_UNDZ | FPCR_UNFD : 0);
fpcr |= (~swcr & SWCR_TRAP_ENABLE_DNO) << 41;
cpu_alpha_store_fpcr(cpu_env, fpcr);
ret = 0;
case TARGET_SSI_IEEE_RAISE_EXCEPTION:
{
uint64_t exc, fpcr, orig_fpcr;
int si_code;
if (get_user_u64(exc, arg2)) {
goto efault;
orig_fpcr = cpu_alpha_load_fpcr(cpu_env);
/* We only add to the exception status here. */
fpcr = orig_fpcr | ((exc & SWCR_STATUS_MASK) << 35);
cpu_alpha_store_fpcr(cpu_env, fpcr);
ret = 0;
/* Old exceptions are not signaled. */
fpcr &= ~(orig_fpcr & FPCR_STATUS_MASK);
/* If any exceptions set by this call,
and are unmasked, send a signal. */
si_code = 0;
if ((fpcr & (FPCR_INE | FPCR_INED)) == FPCR_INE) {
si_code = TARGET_FPE_FLTRES;
if ((fpcr & (FPCR_UNF | FPCR_UNFD)) == FPCR_UNF) {
si_code = TARGET_FPE_FLTUND;
if ((fpcr & (FPCR_OVF | FPCR_OVFD)) == FPCR_OVF) {
si_code = TARGET_FPE_FLTOVF;
if ((fpcr & (FPCR_DZE | FPCR_DZED)) == FPCR_DZE) {
si_code = TARGET_FPE_FLTDIV;
if ((fpcr & (FPCR_INV | FPCR_INVD)) == FPCR_INV) {
si_code = TARGET_FPE_FLTINV;
if (si_code != 0) {
target_siginfo_t info;
info.si_signo = SIGFPE;
info.si_errno = 0;
info.si_code = si_code;
info._sifields._sigfault._addr
= ((CPUArchState *)cpu_env)->pc;
queue_signal((CPUArchState *)cpu_env, info.si_signo, &info);
/* case SSI_NVPAIRS:
-- Used with SSIN_UACPROC to enable unaligned accesses.
case SSI_IEEE_STATE_AT_SIGNAL:
case SSI_IEEE_IGNORE_STATE_AT_SIGNAL:
-- Not implemented in linux kernel
*/
#endif
#ifdef TARGET_NR_osf_sigprocmask
/* Alpha specific. */
case TARGET_NR_osf_sigprocmask:
{
abi_ulong mask;
int how;
sigset_t set, oldset;
switch(arg1) {
case TARGET_SIG_BLOCK:
how = SIG_BLOCK;
case TARGET_SIG_UNBLOCK:
how = SIG_UNBLOCK;
case TARGET_SIG_SETMASK:
how = SIG_SETMASK;
default:
goto fail;
mask = arg2;
target_to_host_old_sigset(&set, &mask);
ret = do_sigprocmask(how, &set, &oldset);
if (!ret) {
host_to_target_old_sigset(&mask, &oldset);
ret = mask;
#endif
#ifdef TARGET_NR_getgid32
case TARGET_NR_getgid32:
ret = get_errno(getgid());
#endif
#ifdef TARGET_NR_geteuid32
case TARGET_NR_geteuid32:
ret = get_errno(geteuid());
#endif
#ifdef TARGET_NR_getegid32
case TARGET_NR_getegid32:
ret = get_errno(getegid());
#endif
#ifdef TARGET_NR_setreuid32
case TARGET_NR_setreuid32:
ret = get_errno(setreuid(arg1, arg2));
#endif
#ifdef TARGET_NR_setregid32
case TARGET_NR_setregid32:
ret = get_errno(setregid(arg1, arg2));
#endif
#ifdef TARGET_NR_getgroups32
case TARGET_NR_getgroups32:
{
int gidsetsize = arg1;
uint32_t *target_grouplist;
gid_t *grouplist;
int i;
grouplist = alloca(gidsetsize * sizeof(gid_t));
ret = get_errno(getgroups(gidsetsize, grouplist));
if (gidsetsize == 0)
if (!is_error(ret)) {
target_grouplist = lock_user(VERIFY_WRITE, arg2, gidsetsize * 4, 0);
if (!target_grouplist) {
ret = -TARGET_EFAULT;
goto fail;
for(i = 0;i < ret; i++)
target_grouplist[i] = tswap32(grouplist[i]);
unlock_user(target_grouplist, arg2, gidsetsize * 4);
#endif
#ifdef TARGET_NR_setgroups32
case TARGET_NR_setgroups32:
{
int gidsetsize = arg1;
uint32_t *target_grouplist;
gid_t *grouplist;
int i;
grouplist = alloca(gidsetsize * sizeof(gid_t));
target_grouplist = lock_user(VERIFY_READ, arg2, gidsetsize * 4, 1);
if (!target_grouplist) {
ret = -TARGET_EFAULT;
goto fail;
for(i = 0;i < gidsetsize; i++)
grouplist[i] = tswap32(target_grouplist[i]);
unlock_user(target_grouplist, arg2, 0);
ret = get_errno(setgroups(gidsetsize, grouplist));
#endif
#ifdef TARGET_NR_fchown32
case TARGET_NR_fchown32:
ret = get_errno(fchown(arg1, arg2, arg3));
#endif
#ifdef TARGET_NR_setresuid32
case TARGET_NR_setresuid32:
ret = get_errno(sys_setresuid(arg1, arg2, arg3));
#endif
#ifdef TARGET_NR_getresuid32
case TARGET_NR_getresuid32:
{
uid_t ruid, euid, suid;
ret = get_errno(getresuid(&ruid, &euid, &suid));
if (!is_error(ret)) {
if (put_user_u32(ruid, arg1)
|| put_user_u32(euid, arg2)
|| put_user_u32(suid, arg3))
goto efault;
#endif
#ifdef TARGET_NR_setresgid32
case TARGET_NR_setresgid32:
ret = get_errno(sys_setresgid(arg1, arg2, arg3));
#endif
#ifdef TARGET_NR_getresgid32
case TARGET_NR_getresgid32:
{
gid_t rgid, egid, sgid;
ret = get_errno(getresgid(&rgid, &egid, &sgid));
if (!is_error(ret)) {
if (put_user_u32(rgid, arg1)
|| put_user_u32(egid, arg2)
|| put_user_u32(sgid, arg3))
goto efault;
#endif
#ifdef TARGET_NR_chown32
case TARGET_NR_chown32:
if (!(p = lock_user_string(arg1)))
goto efault;
ret = get_errno(chown(p, arg2, arg3));
unlock_user(p, arg1, 0);
#endif
#ifdef TARGET_NR_setuid32
case TARGET_NR_setuid32:
ret = get_errno(sys_setuid(arg1));
#endif
#ifdef TARGET_NR_setgid32
case TARGET_NR_setgid32:
ret = get_errno(sys_setgid(arg1));
#endif
#ifdef TARGET_NR_setfsuid32
case TARGET_NR_setfsuid32:
ret = get_errno(setfsuid(arg1));
#endif
#ifdef TARGET_NR_setfsgid32
case TARGET_NR_setfsgid32:
ret = get_errno(setfsgid(arg1));
#endif
case TARGET_NR_pivot_root:
goto unimplemented;
#ifdef TARGET_NR_mincore
case TARGET_NR_mincore:
{
void *a;
ret = -TARGET_EFAULT;
if (!(a = lock_user(VERIFY_READ, arg1,arg2, 0)))
goto efault;
if (!(p = lock_user_string(arg3)))
goto mincore_fail;
ret = get_errno(mincore(a, arg2, p));
unlock_user(p, arg3, ret);
mincore_fail:
unlock_user(a, arg1, 0);
#endif
#ifdef TARGET_NR_arm_fadvise64_64
case TARGET_NR_arm_fadvise64_64:
/* arm_fadvise64_64 looks like fadvise64_64 but
* with different argument order: fd, advice, offset, len
* rather than the usual fd, offset, len, advice.
* Note that offset and len are both 64-bit so appear as
* pairs of 32-bit registers.
*/
ret = posix_fadvise(arg1, target_offset64(arg3, arg4),
target_offset64(arg5, arg6), arg2);
ret = -host_to_target_errno(ret);
#endif
#if TARGET_ABI_BITS == 32
#ifdef TARGET_NR_fadvise64_64
case TARGET_NR_fadvise64_64:
/* 6 args: fd, offset (high, low), len (high, low), advice */
if (regpairs_aligned(cpu_env)) {
/* offset is in (3,4), len in (5,6) and advice in 7 */
arg2 = arg3;
arg3 = arg4;
arg4 = arg5;
arg5 = arg6;
arg6 = arg7;
ret = -host_to_target_errno(posix_fadvise(arg1,
target_offset64(arg2, arg3),
target_offset64(arg4, arg5),
arg6));
#endif
#ifdef TARGET_NR_fadvise64
case TARGET_NR_fadvise64:
/* 5 args: fd, offset (high, low), len, advice */
if (regpairs_aligned(cpu_env)) {
/* offset is in (3,4), len in 5 and advice in 6 */
arg2 = arg3;
arg3 = arg4;
arg4 = arg5;
arg5 = arg6;
ret = -host_to_target_errno(posix_fadvise(arg1,
target_offset64(arg2, arg3),
arg4, arg5));
#endif
#else /* not a 32-bit ABI */
#if defined(TARGET_NR_fadvise64_64) || defined(TARGET_NR_fadvise64)
#ifdef TARGET_NR_fadvise64_64
case TARGET_NR_fadvise64_64:
#endif
#ifdef TARGET_NR_fadvise64
case TARGET_NR_fadvise64:
#endif
#ifdef TARGET_S390X
switch (arg4) {
case 4: arg4 = POSIX_FADV_NOREUSE + 1; break; /* make sure it's an invalid value */
case 5: arg4 = POSIX_FADV_NOREUSE + 2; break; /* ditto */
case 6: arg4 = POSIX_FADV_DONTNEED; break;
case 7: arg4 = POSIX_FADV_NOREUSE; break;
default: break;
#endif
ret = -host_to_target_errno(posix_fadvise(arg1, arg2, arg3, arg4));
#endif
#endif /* end of 64-bit ABI fadvise handling */
#ifdef TARGET_NR_madvise
case TARGET_NR_madvise:
/* A straight passthrough may not be safe because qemu sometimes
turns private file-backed mappings into anonymous mappings.
This will break MADV_DONTNEED.
This is a hint, so ignoring and returning success is ok. */
ret = get_errno(0);
#endif
#if TARGET_ABI_BITS == 32
case TARGET_NR_fcntl64:
{
int cmd;
struct flock64 fl;
from_flock64_fn *copyfrom = copy_from_user_flock64;
to_flock64_fn *copyto = copy_to_user_flock64;
#ifdef TARGET_ARM
if (((CPUARMState *)cpu_env)->eabi) {
copyfrom = copy_from_user_eabi_flock64;
copyto = copy_to_user_eabi_flock64;
#endif
cmd = target_to_host_fcntl_cmd(arg2);
if (cmd == -TARGET_EINVAL) {
ret = cmd;
switch(arg2) {
case TARGET_F_GETLK64:
ret = copyfrom(&fl, arg3);
if (ret) {
ret = get_errno(fcntl(arg1, cmd, &fl));
if (ret == 0) {
ret = copyto(arg3, &fl);
case TARGET_F_SETLK64:
case TARGET_F_SETLKW64:
ret = copyfrom(&fl, arg3);
if (ret) {
ret = get_errno(safe_fcntl(arg1, cmd, &fl));
default:
ret = do_fcntl(arg1, arg2, arg3);
#endif
#ifdef TARGET_NR_cacheflush
case TARGET_NR_cacheflush:
/* self-modifying code is handled automatically, so nothing needed */
ret = 0;
#endif
#ifdef TARGET_NR_security
case TARGET_NR_security:
goto unimplemented;
#endif
#ifdef TARGET_NR_getpagesize
case TARGET_NR_getpagesize:
ret = TARGET_PAGE_SIZE;
#endif
case TARGET_NR_gettid:
ret = get_errno(gettid());
#ifdef TARGET_NR_readahead
case TARGET_NR_readahead:
#if TARGET_ABI_BITS == 32
if (regpairs_aligned(cpu_env)) {
arg2 = arg3;
arg3 = arg4;
arg4 = arg5;
ret = get_errno(readahead(arg1, ((off64_t)arg3 << 32) | arg2, arg4));
#else
ret = get_errno(readahead(arg1, arg2, arg3));
#endif
#endif
#ifdef CONFIG_ATTR
#ifdef TARGET_NR_setxattr
case TARGET_NR_listxattr:
case TARGET_NR_llistxattr:
{
void *p, *b = 0;
if (arg2) {
b = lock_user(VERIFY_WRITE, arg2, arg3, 0);
if (!b) {
ret = -TARGET_EFAULT;
p = lock_user_string(arg1);
if (p) {
if (num == TARGET_NR_listxattr) {
ret = get_errno(listxattr(p, b, arg3));
} else {
ret = get_errno(llistxattr(p, b, arg3));
} else {
ret = -TARGET_EFAULT;
unlock_user(p, arg1, 0);
unlock_user(b, arg2, arg3);
case TARGET_NR_flistxattr:
{
void *b = 0;
if (arg2) {
b = lock_user(VERIFY_WRITE, arg2, arg3, 0);
if (!b) {
ret = -TARGET_EFAULT;
ret = get_errno(flistxattr(arg1, b, arg3));
unlock_user(b, arg2, arg3);
case TARGET_NR_setxattr:
case TARGET_NR_lsetxattr:
{
void *p, *n, *v = 0;
if (arg3) {
v = lock_user(VERIFY_READ, arg3, arg4, 1);
if (!v) {
ret = -TARGET_EFAULT;
p = lock_user_string(arg1);
n = lock_user_string(arg2);
if (p && n) {
if (num == TARGET_NR_setxattr) {
ret = get_errno(setxattr(p, n, v, arg4, arg5));
} else {
ret = get_errno(lsetxattr(p, n, v, arg4, arg5));
} else {
ret = -TARGET_EFAULT;
unlock_user(p, arg1, 0);
unlock_user(n, arg2, 0);
unlock_user(v, arg3, 0);
case TARGET_NR_fsetxattr:
{
void *n, *v = 0;
if (arg3) {
v = lock_user(VERIFY_READ, arg3, arg4, 1);
if (!v) {
ret = -TARGET_EFAULT;
n = lock_user_string(arg2);
if (n) {
ret = get_errno(fsetxattr(arg1, n, v, arg4, arg5));
} else {
ret = -TARGET_EFAULT;
unlock_user(n, arg2, 0);
unlock_user(v, arg3, 0);
case TARGET_NR_getxattr:
case TARGET_NR_lgetxattr:
{
void *p, *n, *v = 0;
if (arg3) {
v = lock_user(VERIFY_WRITE, arg3, arg4, 0);
if (!v) {
ret = -TARGET_EFAULT;
p = lock_user_string(arg1);
n = lock_user_string(arg2);
if (p && n) {
if (num == TARGET_NR_getxattr) {
ret = get_errno(getxattr(p, n, v, arg4));
} else {
ret = get_errno(lgetxattr(p, n, v, arg4));
} else {
ret = -TARGET_EFAULT;
unlock_user(p, arg1, 0);
unlock_user(n, arg2, 0);
unlock_user(v, arg3, arg4);
case TARGET_NR_fgetxattr:
{
void *n, *v = 0;
if (arg3) {
v = lock_user(VERIFY_WRITE, arg3, arg4, 0);
if (!v) {
ret = -TARGET_EFAULT;
n = lock_user_string(arg2);
if (n) {
ret = get_errno(fgetxattr(arg1, n, v, arg4));
} else {
ret = -TARGET_EFAULT;
unlock_user(n, arg2, 0);
unlock_user(v, arg3, arg4);
case TARGET_NR_removexattr:
case TARGET_NR_lremovexattr:
{
void *p, *n;
p = lock_user_string(arg1);
n = lock_user_string(arg2);
if (p && n) {
if (num == TARGET_NR_removexattr) {
ret = get_errno(removexattr(p, n));
} else {
ret = get_errno(lremovexattr(p, n));
} else {
ret = -TARGET_EFAULT;
unlock_user(p, arg1, 0);
unlock_user(n, arg2, 0);
case TARGET_NR_fremovexattr:
{
void *n;
n = lock_user_string(arg2);
if (n) {
ret = get_errno(fremovexattr(arg1, n));
} else {
ret = -TARGET_EFAULT;
unlock_user(n, arg2, 0);
#endif
#endif /* CONFIG_ATTR */
#ifdef TARGET_NR_set_thread_area
case TARGET_NR_set_thread_area:
#if defined(TARGET_MIPS)
((CPUMIPSState *) cpu_env)->active_tc.CP0_UserLocal = arg1;
ret = 0;
#elif defined(TARGET_CRIS)
if (arg1 & 0xff)
else {
((CPUCRISState *) cpu_env)->pregs[PR_PID] = arg1;
ret = 0;
#elif defined(TARGET_I386) && defined(TARGET_ABI32)
ret = do_set_thread_area(cpu_env, arg1);
#elif defined(TARGET_M68K)
{
TaskState *ts = cpu->opaque;
ts->tp_value = arg1;
ret = 0;
#else
goto unimplemented_nowarn;
#endif
#endif
#ifdef TARGET_NR_get_thread_area
case TARGET_NR_get_thread_area:
#if defined(TARGET_I386) && defined(TARGET_ABI32)
ret = do_get_thread_area(cpu_env, arg1);
#elif defined(TARGET_M68K)
{
TaskState *ts = cpu->opaque;
ret = ts->tp_value;
#else
goto unimplemented_nowarn;
#endif
#endif
#ifdef TARGET_NR_getdomainname
case TARGET_NR_getdomainname:
goto unimplemented_nowarn;
#endif
#ifdef TARGET_NR_clock_gettime
case TARGET_NR_clock_gettime:
{
struct timespec ts;
ret = get_errno(clock_gettime(arg1, &ts));
if (!is_error(ret)) {
host_to_target_timespec(arg2, &ts);
#endif
#ifdef TARGET_NR_clock_getres
case TARGET_NR_clock_getres:
{
struct timespec ts;
ret = get_errno(clock_getres(arg1, &ts));
if (!is_error(ret)) {
host_to_target_timespec(arg2, &ts);
#endif
#ifdef TARGET_NR_clock_nanosleep
case TARGET_NR_clock_nanosleep:
{
struct timespec ts;
target_to_host_timespec(&ts, arg3);
ret = get_errno(safe_clock_nanosleep(arg1, arg2,
&ts, arg4 ? &ts : NULL));
if (arg4)
host_to_target_timespec(arg4, &ts);
#if defined(TARGET_PPC)
/* clock_nanosleep is odd in that it returns positive errno values.
* On PPC, CR0 bit 3 should be set in such a situation. */
if (ret && ret != -TARGET_ERESTARTSYS) {
((CPUPPCState *)cpu_env)->crf[0] |= 1;
#endif
#endif
#if defined(TARGET_NR_set_tid_address) && defined(__NR_set_tid_address)
case TARGET_NR_set_tid_address:
ret = get_errno(set_tid_address((int *)g2h(arg1)));
#endif
case TARGET_NR_tkill:
ret = get_errno(safe_tkill((int)arg1, target_to_host_signal(arg2)));
case TARGET_NR_tgkill:
ret = get_errno(safe_tgkill((int)arg1, (int)arg2,
target_to_host_signal(arg3)));
#ifdef TARGET_NR_set_robust_list
case TARGET_NR_set_robust_list:
case TARGET_NR_get_robust_list:
/* The ABI for supporting robust futexes has userspace pass
* the kernel a pointer to a linked list which is updated by
* userspace after the syscall; the list is walked by the kernel
* when the thread exits. Since the linked list in QEMU guest
* memory isn't a valid linked list for the host and we have
* no way to reliably intercept the thread-death event, we can't
* support these. Silently return ENOSYS so that guest userspace
* falls back to a non-robust futex implementation (which should
* be OK except in the corner case of the guest crashing while
* holding a mutex that is shared with another process via
* shared memory).
*/
goto unimplemented_nowarn;
#endif
#if defined(TARGET_NR_utimensat)
case TARGET_NR_utimensat:
{
struct timespec *tsp, ts[2];
if (!arg3) {
tsp = NULL;
} else {
target_to_host_timespec(ts, arg3);
target_to_host_timespec(ts+1, arg3+sizeof(struct target_timespec));
tsp = ts;
if (!arg2)
ret = get_errno(sys_utimensat(arg1, NULL, tsp, arg4));
else {
if (!(p = lock_user_string(arg2))) {
ret = -TARGET_EFAULT;
goto fail;
ret = get_errno(sys_utimensat(arg1, path(p), tsp, arg4));
unlock_user(p, arg2, 0);
#endif
case TARGET_NR_futex:
ret = do_futex(arg1, arg2, arg3, arg4, arg5, arg6);
#if defined(TARGET_NR_inotify_init) && defined(__NR_inotify_init)
case TARGET_NR_inotify_init:
ret = get_errno(sys_inotify_init());
#endif
#ifdef CONFIG_INOTIFY1
#if defined(TARGET_NR_inotify_init1) && defined(__NR_inotify_init1)
case TARGET_NR_inotify_init1:
ret = get_errno(sys_inotify_init1(arg1));
#endif
#endif
#if defined(TARGET_NR_inotify_add_watch) && defined(__NR_inotify_add_watch)
case TARGET_NR_inotify_add_watch:
p = lock_user_string(arg2);
ret = get_errno(sys_inotify_add_watch(arg1, path(p), arg3));
unlock_user(p, arg2, 0);
#endif
#if defined(TARGET_NR_inotify_rm_watch) && defined(__NR_inotify_rm_watch)
case TARGET_NR_inotify_rm_watch:
ret = get_errno(sys_inotify_rm_watch(arg1, arg2));
#endif
#if defined(TARGET_NR_mq_open) && defined(__NR_mq_open)
case TARGET_NR_mq_open:
{
struct mq_attr posix_mq_attr, *attrp;
p = lock_user_string(arg1 - 1);
if (arg4 != 0) {
copy_from_user_mq_attr (&posix_mq_attr, arg4);
attrp = &posix_mq_attr;
} else {
attrp = 0;
ret = get_errno(mq_open(p, arg2, arg3, attrp));
unlock_user (p, arg1, 0);
case TARGET_NR_mq_unlink:
p = lock_user_string(arg1 - 1);
ret = get_errno(mq_unlink(p));
unlock_user (p, arg1, 0);
case TARGET_NR_mq_timedsend:
{
struct timespec ts;
p = lock_user (VERIFY_READ, arg2, arg3, 1);
if (arg5 != 0) {
target_to_host_timespec(&ts, arg5);
ret = get_errno(safe_mq_timedsend(arg1, p, arg3, arg4, &ts));
host_to_target_timespec(arg5, &ts);
} else {
ret = get_errno(safe_mq_timedsend(arg1, p, arg3, arg4, NULL));
unlock_user (p, arg2, arg3);
case TARGET_NR_mq_timedreceive:
{
struct timespec ts;
unsigned int prio;
p = lock_user (VERIFY_READ, arg2, arg3, 1);
if (arg5 != 0) {
target_to_host_timespec(&ts, arg5);
ret = get_errno(safe_mq_timedreceive(arg1, p, arg3,
&prio, &ts));
host_to_target_timespec(arg5, &ts);
} else {
ret = get_errno(safe_mq_timedreceive(arg1, p, arg3,
&prio, NULL));
unlock_user (p, arg2, arg3);
if (arg4 != 0)
put_user_u32(prio, arg4);
/* Not implemented for now... */
/* case TARGET_NR_mq_notify: */
/* break; */
case TARGET_NR_mq_getsetattr:
{
struct mq_attr posix_mq_attr_in, posix_mq_attr_out;
ret = 0;
if (arg3 != 0) {
ret = mq_getattr(arg1, &posix_mq_attr_out);
copy_to_user_mq_attr(arg3, &posix_mq_attr_out);
if (arg2 != 0) {
copy_from_user_mq_attr(&posix_mq_attr_in, arg2);
ret |= mq_setattr(arg1, &posix_mq_attr_in, &posix_mq_attr_out);
#endif
#ifdef CONFIG_SPLICE
#ifdef TARGET_NR_tee
case TARGET_NR_tee:
{
ret = get_errno(tee(arg1,arg2,arg3,arg4));
#endif
#ifdef TARGET_NR_splice
case TARGET_NR_splice:
{
loff_t loff_in, loff_out;
loff_t *ploff_in = NULL, *ploff_out = NULL;
if (arg2) {
if (get_user_u64(loff_in, arg2)) {
goto efault;
ploff_in = &loff_in;
if (arg4) {
if (get_user_u64(loff_out, arg4)) {
goto efault;
ploff_out = &loff_out;
ret = get_errno(splice(arg1, ploff_in, arg3, ploff_out, arg5, arg6));
if (arg2) {
if (put_user_u64(loff_in, arg2)) {
goto efault;
if (arg4) {
if (put_user_u64(loff_out, arg4)) {
goto efault;
#endif
#ifdef TARGET_NR_vmsplice
case TARGET_NR_vmsplice:
{
struct iovec *vec = lock_iovec(VERIFY_READ, arg2, arg3, 1);
if (vec != NULL) {
ret = get_errno(vmsplice(arg1, vec, arg3, arg4));
unlock_iovec(vec, arg2, arg3, 0);
} else {
ret = -host_to_target_errno(errno);
#endif
#endif /* CONFIG_SPLICE */
#ifdef CONFIG_EVENTFD
#if defined(TARGET_NR_eventfd)
case TARGET_NR_eventfd:
ret = get_errno(eventfd(arg1, 0));
fd_trans_unregister(ret);
#endif
#if defined(TARGET_NR_eventfd2)
case TARGET_NR_eventfd2:
{
int host_flags = arg2 & (~(TARGET_O_NONBLOCK | TARGET_O_CLOEXEC));
if (arg2 & TARGET_O_NONBLOCK) {
host_flags |= O_NONBLOCK;
if (arg2 & TARGET_O_CLOEXEC) {
host_flags |= O_CLOEXEC;
ret = get_errno(eventfd(arg1, host_flags));
fd_trans_unregister(ret);
#endif
#endif /* CONFIG_EVENTFD */
#if defined(CONFIG_FALLOCATE) && defined(TARGET_NR_fallocate)
case TARGET_NR_fallocate:
#if TARGET_ABI_BITS == 32
ret = get_errno(fallocate(arg1, arg2, target_offset64(arg3, arg4),
target_offset64(arg5, arg6)));
#else
ret = get_errno(fallocate(arg1, arg2, arg3, arg4));
#endif
#endif
#if defined(CONFIG_SYNC_FILE_RANGE)
#if defined(TARGET_NR_sync_file_range)
case TARGET_NR_sync_file_range:
#if TARGET_ABI_BITS == 32
#if defined(TARGET_MIPS)
ret = get_errno(sync_file_range(arg1, target_offset64(arg3, arg4),
target_offset64(arg5, arg6), arg7));
#else
ret = get_errno(sync_file_range(arg1, target_offset64(arg2, arg3),
target_offset64(arg4, arg5), arg6));
#endif /* !TARGET_MIPS */
#else
ret = get_errno(sync_file_range(arg1, arg2, arg3, arg4));
#endif
#endif
#if defined(TARGET_NR_sync_file_range2)
case TARGET_NR_sync_file_range2:
/* This is like sync_file_range but the arguments are reordered */
#if TARGET_ABI_BITS == 32
ret = get_errno(sync_file_range(arg1, target_offset64(arg3, arg4),
target_offset64(arg5, arg6), arg2));
#else
ret = get_errno(sync_file_range(arg1, arg3, arg4, arg2));
#endif
#endif
#endif
#if defined(TARGET_NR_signalfd4)
case TARGET_NR_signalfd4:
ret = do_signalfd4(arg1, arg2, arg4);
#endif
#if defined(TARGET_NR_signalfd)
case TARGET_NR_signalfd:
ret = do_signalfd4(arg1, arg2, 0);
#endif
#if defined(CONFIG_EPOLL)
#if defined(TARGET_NR_epoll_create)
case TARGET_NR_epoll_create:
ret = get_errno(epoll_create(arg1));
#endif
#if defined(TARGET_NR_epoll_create1) && defined(CONFIG_EPOLL_CREATE1)
case TARGET_NR_epoll_create1:
ret = get_errno(epoll_create1(arg1));
#endif
#if defined(TARGET_NR_epoll_ctl)
case TARGET_NR_epoll_ctl:
{
struct epoll_event ep;
struct epoll_event *epp = 0;
if (arg4) {
struct target_epoll_event *target_ep;
if (!lock_user_struct(VERIFY_READ, target_ep, arg4, 1)) {
goto efault;
ep.events = tswap32(target_ep->events);
/* The epoll_data_t union is just opaque data to the kernel,
* so we transfer all 64 bits across and need not worry what
* actual data type it is.
*/
ep.data.u64 = tswap64(target_ep->data.u64);
unlock_user_struct(target_ep, arg4, 0);
epp = &ep;
ret = get_errno(epoll_ctl(arg1, arg2, arg3, epp));
#endif
#if defined(TARGET_NR_epoll_wait) || defined(TARGET_NR_epoll_pwait)
#if defined(TARGET_NR_epoll_wait)
case TARGET_NR_epoll_wait:
#endif
#if defined(TARGET_NR_epoll_pwait)
case TARGET_NR_epoll_pwait:
#endif
{
struct target_epoll_event *target_ep;
struct epoll_event *ep;
int epfd = arg1;
int maxevents = arg3;
int timeout = arg4;
if (maxevents <= 0 || maxevents > TARGET_EP_MAX_EVENTS) {
target_ep = lock_user(VERIFY_WRITE, arg2,
maxevents * sizeof(struct target_epoll_event), 1);
if (!target_ep) {
goto efault;
ep = alloca(maxevents * sizeof(struct epoll_event));
switch (num) {
#if defined(TARGET_NR_epoll_pwait)
case TARGET_NR_epoll_pwait:
{
target_sigset_t *target_set;
sigset_t _set, *set = &_set;
if (arg5) {
if (arg6 != sizeof(target_sigset_t)) {
target_set = lock_user(VERIFY_READ, arg5,
sizeof(target_sigset_t), 1);
if (!target_set) {
unlock_user(target_ep, arg2, 0);
goto efault;
target_to_host_sigset(set, target_set);
unlock_user(target_set, arg5, 0);
} else {
set = NULL;
ret = get_errno(safe_epoll_pwait(epfd, ep, maxevents, timeout,
set, SIGSET_T_SIZE));
#endif
#if defined(TARGET_NR_epoll_wait)
case TARGET_NR_epoll_wait:
ret = get_errno(safe_epoll_pwait(epfd, ep, maxevents, timeout,
NULL, 0));
#endif
default:
ret = -TARGET_ENOSYS;
if (!is_error(ret)) {
int i;
for (i = 0; i < ret; i++) {
target_ep[i].events = tswap32(ep[i].events);
target_ep[i].data.u64 = tswap64(ep[i].data.u64);
unlock_user(target_ep, arg2, ret * sizeof(struct target_epoll_event));
#endif
#endif
#ifdef TARGET_NR_prlimit64
case TARGET_NR_prlimit64:
{
/* args: pid, resource number, ptr to new rlimit, ptr to old rlimit */
struct target_rlimit64 *target_rnew, *target_rold;
struct host_rlimit64 rnew, rold, *rnewp = 0;
int resource = target_to_host_resource(arg2);
if (arg3) {
if (!lock_user_struct(VERIFY_READ, target_rnew, arg3, 1)) {
goto efault;
rnew.rlim_cur = tswap64(target_rnew->rlim_cur);
rnew.rlim_max = tswap64(target_rnew->rlim_max);
unlock_user_struct(target_rnew, arg3, 0);
rnewp = &rnew;
ret = get_errno(sys_prlimit64(arg1, resource, rnewp, arg4 ? &rold : 0));
if (!is_error(ret) && arg4) {
if (!lock_user_struct(VERIFY_WRITE, target_rold, arg4, 1)) {
goto efault;
target_rold->rlim_cur = tswap64(rold.rlim_cur);
target_rold->rlim_max = tswap64(rold.rlim_max);
unlock_user_struct(target_rold, arg4, 1);
#endif
#ifdef TARGET_NR_gethostname
case TARGET_NR_gethostname:
{
char *name = lock_user(VERIFY_WRITE, arg1, arg2, 0);
if (name) {
ret = get_errno(gethostname(name, arg2));
unlock_user(name, arg1, arg2);
} else {
ret = -TARGET_EFAULT;
#endif
#ifdef TARGET_NR_atomic_cmpxchg_32
case TARGET_NR_atomic_cmpxchg_32:
{
/* should use start_exclusive from main.c */
abi_ulong mem_value;
if (get_user_u32(mem_value, arg6)) {
target_siginfo_t info;
info.si_signo = SIGSEGV;
info.si_errno = 0;
info.si_code = TARGET_SEGV_MAPERR;
info._sifields._sigfault._addr = arg6;
queue_signal((CPUArchState *)cpu_env, info.si_signo, &info);
ret = 0xdeadbeef;
if (mem_value == arg2)
put_user_u32(arg1, arg6);
ret = mem_value;
#endif
#ifdef TARGET_NR_atomic_barrier
case TARGET_NR_atomic_barrier:
{
/* Like the kernel implementation and the qemu arm barrier, no-op this? */
ret = 0;
#endif
#ifdef TARGET_NR_timer_create
case TARGET_NR_timer_create:
{
/* args: clockid_t clockid, struct sigevent *sevp, timer_t *timerid */
struct sigevent host_sevp = { {0}, }, *phost_sevp = NULL;
int clkid = arg1;
int timer_index = next_free_host_timer();
if (timer_index < 0) {
ret = -TARGET_EAGAIN;
} else {
timer_t *phtimer = g_posix_timers + timer_index;
if (arg2) {
phost_sevp = &host_sevp;
ret = target_to_host_sigevent(phost_sevp, arg2);
if (ret != 0) {
ret = get_errno(timer_create(clkid, phost_sevp, phtimer));
if (ret) {
phtimer = NULL;
} else {
if (put_user(TIMER_MAGIC | timer_index, arg3, target_timer_t)) {
goto efault;
#endif
#ifdef TARGET_NR_timer_settime
case TARGET_NR_timer_settime:
{
/* args: timer_t timerid, int flags, const struct itimerspec *new_value,
* struct itimerspec * old_value */
target_timer_t timerid = get_timer_id(arg1);
if (timerid < 0) {
ret = timerid;
} else if (arg3 == 0) {
} else {
timer_t htimer = g_posix_timers[timerid];
struct itimerspec hspec_new = {{0},}, hspec_old = {{0},};
target_to_host_itimerspec(&hspec_new, arg3);
ret = get_errno(
timer_settime(htimer, arg2, &hspec_new, &hspec_old));
host_to_target_itimerspec(arg2, &hspec_old);
#endif
#ifdef TARGET_NR_timer_gettime
case TARGET_NR_timer_gettime:
{
/* args: timer_t timerid, struct itimerspec *curr_value */
target_timer_t timerid = get_timer_id(arg1);
if (timerid < 0) {
ret = timerid;
} else if (!arg2) {
ret = -TARGET_EFAULT;
} else {
timer_t htimer = g_posix_timers[timerid];
struct itimerspec hspec;
ret = get_errno(timer_gettime(htimer, &hspec));
if (host_to_target_itimerspec(arg2, &hspec)) {
ret = -TARGET_EFAULT;
#endif
#ifdef TARGET_NR_timer_getoverrun
case TARGET_NR_timer_getoverrun:
{
/* args: timer_t timerid */
target_timer_t timerid = get_timer_id(arg1);
if (timerid < 0) {
ret = timerid;
} else {
timer_t htimer = g_posix_timers[timerid];
ret = get_errno(timer_getoverrun(htimer));
fd_trans_unregister(ret);
#endif
#ifdef TARGET_NR_timer_delete
case TARGET_NR_timer_delete:
{
/* args: timer_t timerid */
target_timer_t timerid = get_timer_id(arg1);
if (timerid < 0) {
ret = timerid;
} else {
timer_t htimer = g_posix_timers[timerid];
ret = get_errno(timer_delete(htimer));
g_posix_timers[timerid] = 0;
#endif
#if defined(TARGET_NR_timerfd_create) && defined(CONFIG_TIMERFD)
case TARGET_NR_timerfd_create:
ret = get_errno(timerfd_create(arg1,
target_to_host_bitmask(arg2, fcntl_flags_tbl)));
#endif
#if defined(TARGET_NR_timerfd_gettime) && defined(CONFIG_TIMERFD)
case TARGET_NR_timerfd_gettime:
{
struct itimerspec its_curr;
ret = get_errno(timerfd_gettime(arg1, &its_curr));
if (arg2 && host_to_target_itimerspec(arg2, &its_curr)) {
goto efault;
#endif
#if defined(TARGET_NR_timerfd_settime) && defined(CONFIG_TIMERFD)
case TARGET_NR_timerfd_settime:
{
struct itimerspec its_new, its_old, *p_new;
if (arg3) {
if (target_to_host_itimerspec(&its_new, arg3)) {
goto efault;
p_new = &its_new;
} else {
p_new = NULL;
ret = get_errno(timerfd_settime(arg1, arg2, p_new, &its_old));
if (arg4 && host_to_target_itimerspec(arg4, &its_old)) {
goto efault;
#endif
#if defined(TARGET_NR_ioprio_get) && defined(__NR_ioprio_get)
case TARGET_NR_ioprio_get:
ret = get_errno(ioprio_get(arg1, arg2));
#endif
#if defined(TARGET_NR_ioprio_set) && defined(__NR_ioprio_set)
case TARGET_NR_ioprio_set:
ret = get_errno(ioprio_set(arg1, arg2, arg3));
#endif
#if defined(TARGET_NR_setns) && defined(CONFIG_SETNS)
case TARGET_NR_setns:
ret = get_errno(setns(arg1, arg2));
#endif
#if defined(TARGET_NR_unshare) && defined(CONFIG_SETNS)
case TARGET_NR_unshare:
ret = get_errno(unshare(arg1));
#endif
default:
unimplemented:
gemu_log("qemu: Unsupported syscall: %d\n", num);
#if defined(TARGET_NR_setxattr) || defined(TARGET_NR_get_thread_area) || defined(TARGET_NR_getdomainname) || defined(TARGET_NR_set_robust_list)
unimplemented_nowarn:
#endif
ret = -TARGET_ENOSYS;
fail:
#ifdef DEBUG
gemu_log(" = " TARGET_ABI_FMT_ld "\n", ret);
#endif
if(do_strace)
print_syscall_ret(num, ret);
trace_guest_user_syscall_ret(cpu, num, ret);
return ret;
efault:
ret = -TARGET_EFAULT;
goto fail; | true | qemu | ce9c139d93db03e464341385976606b7568b768f | abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
abi_long arg2, abi_long arg3, abi_long arg4,
abi_long arg5, abi_long arg6, abi_long arg7,
abi_long arg8)
{
CPUState *cpu = ENV_GET_CPU(cpu_env);
abi_long ret;
struct stat st;
struct statfs stfs;
void *p;
#if defined(DEBUG_ERESTARTSYS)
{
static int flag;
flag = !flag;
if (flag) {
return -TARGET_ERESTARTSYS;
#endif
#ifdef DEBUG
gemu_log("syscall %d", num);
#endif
trace_guest_user_syscall(cpu, num, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);
if(do_strace)
print_syscall(num, arg1, arg2, arg3, arg4, arg5, arg6);
switch(num) {
case TARGET_NR_exit:
if (block_signals()) {
ret = -TARGET_ERESTARTSYS;
if (CPU_NEXT(first_cpu)) {
TaskState *ts;
cpu_list_lock();
QTAILQ_REMOVE(&cpus, cpu, node);
cpu_list_unlock();
ts = cpu->opaque;
if (ts->child_tidptr) {
put_user_u32(0, ts->child_tidptr);
sys_futex(g2h(ts->child_tidptr), FUTEX_WAKE, INT_MAX,
NULL, NULL, 0);
thread_cpu = NULL;
object_unref(OBJECT(cpu));
g_free(ts);
rcu_unregister_thread();
pthread_exit(NULL);
#ifdef TARGET_GPROF
_mcleanup();
#endif
gdb_exit(cpu_env, arg1);
_exit(arg1);
ret = 0;
case TARGET_NR_read:
if (arg3 == 0)
ret = 0;
else {
if (!(p = lock_user(VERIFY_WRITE, arg2, arg3, 0)))
goto efault;
ret = get_errno(safe_read(arg1, p, arg3));
if (ret >= 0 &&
fd_trans_host_to_target_data(arg1)) {
ret = fd_trans_host_to_target_data(arg1)(p, ret);
unlock_user(p, arg2, ret);
case TARGET_NR_write:
if (!(p = lock_user(VERIFY_READ, arg2, arg3, 1)))
goto efault;
ret = get_errno(safe_write(arg1, p, arg3));
unlock_user(p, arg2, 0);
#ifdef TARGET_NR_open
case TARGET_NR_open:
if (!(p = lock_user_string(arg1)))
goto efault;
ret = get_errno(do_openat(cpu_env, AT_FDCWD, p,
target_to_host_bitmask(arg2, fcntl_flags_tbl),
arg3));
fd_trans_unregister(ret);
unlock_user(p, arg1, 0);
#endif
case TARGET_NR_openat:
if (!(p = lock_user_string(arg2)))
goto efault;
ret = get_errno(do_openat(cpu_env, arg1, p,
target_to_host_bitmask(arg3, fcntl_flags_tbl),
arg4));
fd_trans_unregister(ret);
unlock_user(p, arg2, 0);
#if defined(TARGET_NR_name_to_handle_at) && defined(CONFIG_OPEN_BY_HANDLE)
case TARGET_NR_name_to_handle_at:
ret = do_name_to_handle_at(arg1, arg2, arg3, arg4, arg5);
#endif
#if defined(TARGET_NR_open_by_handle_at) && defined(CONFIG_OPEN_BY_HANDLE)
case TARGET_NR_open_by_handle_at:
ret = do_open_by_handle_at(arg1, arg2, arg3);
fd_trans_unregister(ret);
#endif
case TARGET_NR_close:
fd_trans_unregister(arg1);
ret = get_errno(close(arg1));
case TARGET_NR_brk:
ret = do_brk(arg1);
#ifdef TARGET_NR_fork
case TARGET_NR_fork:
ret = get_errno(do_fork(cpu_env, SIGCHLD, 0, 0, 0, 0));
#endif
#ifdef TARGET_NR_waitpid
case TARGET_NR_waitpid:
{
int status;
ret = get_errno(safe_wait4(arg1, &status, arg3, 0));
if (!is_error(ret) && arg2 && ret
&& put_user_s32(host_to_target_waitstatus(status), arg2))
goto efault;
#endif
#ifdef TARGET_NR_waitid
case TARGET_NR_waitid:
{
siginfo_t info;
info.si_pid = 0;
ret = get_errno(safe_waitid(arg1, arg2, &info, arg4, NULL));
if (!is_error(ret) && arg3 && info.si_pid != 0) {
if (!(p = lock_user(VERIFY_WRITE, arg3, sizeof(target_siginfo_t), 0)))
goto efault;
host_to_target_siginfo(p, &info);
unlock_user(p, arg3, sizeof(target_siginfo_t));
#endif
#ifdef TARGET_NR_creat
case TARGET_NR_creat:
if (!(p = lock_user_string(arg1)))
goto efault;
ret = get_errno(creat(p, arg2));
fd_trans_unregister(ret);
unlock_user(p, arg1, 0);
#endif
#ifdef TARGET_NR_link
case TARGET_NR_link:
{
void * p2;
p = lock_user_string(arg1);
p2 = lock_user_string(arg2);
if (!p || !p2)
ret = -TARGET_EFAULT;
else
ret = get_errno(link(p, p2));
unlock_user(p2, arg2, 0);
unlock_user(p, arg1, 0);
#endif
#if defined(TARGET_NR_linkat)
case TARGET_NR_linkat:
{
void * p2 = NULL;
if (!arg2 || !arg4)
goto efault;
p = lock_user_string(arg2);
p2 = lock_user_string(arg4);
if (!p || !p2)
ret = -TARGET_EFAULT;
else
ret = get_errno(linkat(arg1, p, arg3, p2, arg5));
unlock_user(p, arg2, 0);
unlock_user(p2, arg4, 0);
#endif
#ifdef TARGET_NR_unlink
case TARGET_NR_unlink:
if (!(p = lock_user_string(arg1)))
goto efault;
ret = get_errno(unlink(p));
unlock_user(p, arg1, 0);
#endif
#if defined(TARGET_NR_unlinkat)
case TARGET_NR_unlinkat:
if (!(p = lock_user_string(arg2)))
goto efault;
ret = get_errno(unlinkat(arg1, p, arg3));
unlock_user(p, arg2, 0);
#endif
case TARGET_NR_execve:
{
char **argp, **envp;
int argc, envc;
abi_ulong gp;
abi_ulong guest_argp;
abi_ulong guest_envp;
abi_ulong addr;
char **q;
int total_size = 0;
argc = 0;
guest_argp = arg2;
for (gp = guest_argp; gp; gp += sizeof(abi_ulong)) {
if (get_user_ual(addr, gp))
goto efault;
if (!addr)
argc++;
envc = 0;
guest_envp = arg3;
for (gp = guest_envp; gp; gp += sizeof(abi_ulong)) {
if (get_user_ual(addr, gp))
goto efault;
if (!addr)
envc++;
argp = alloca((argc + 1) * sizeof(void *));
envp = alloca((envc + 1) * sizeof(void *));
for (gp = guest_argp, q = argp; gp;
gp += sizeof(abi_ulong), q++) {
if (get_user_ual(addr, gp))
goto execve_efault;
if (!addr)
if (!(*q = lock_user_string(addr)))
goto execve_efault;
total_size += strlen(*q) + 1;
*q = NULL;
for (gp = guest_envp, q = envp; gp;
gp += sizeof(abi_ulong), q++) {
if (get_user_ual(addr, gp))
goto execve_efault;
if (!addr)
if (!(*q = lock_user_string(addr)))
goto execve_efault;
total_size += strlen(*q) + 1;
*q = NULL;
if (!(p = lock_user_string(arg1)))
goto execve_efault;
ret = get_errno(safe_execve(p, argp, envp));
unlock_user(p, arg1, 0);
goto execve_end;
execve_efault:
ret = -TARGET_EFAULT;
execve_end:
for (gp = guest_argp, q = argp; *q;
gp += sizeof(abi_ulong), q++) {
if (get_user_ual(addr, gp)
|| !addr)
unlock_user(*q, addr, 0);
for (gp = guest_envp, q = envp; *q;
gp += sizeof(abi_ulong), q++) {
if (get_user_ual(addr, gp)
|| !addr)
unlock_user(*q, addr, 0);
case TARGET_NR_chdir:
if (!(p = lock_user_string(arg1)))
goto efault;
ret = get_errno(chdir(p));
unlock_user(p, arg1, 0);
#ifdef TARGET_NR_time
case TARGET_NR_time:
{
time_t host_time;
ret = get_errno(time(&host_time));
if (!is_error(ret)
&& arg1
&& put_user_sal(host_time, arg1))
goto efault;
#endif
#ifdef TARGET_NR_mknod
case TARGET_NR_mknod:
if (!(p = lock_user_string(arg1)))
goto efault;
ret = get_errno(mknod(p, arg2, arg3));
unlock_user(p, arg1, 0);
#endif
#if defined(TARGET_NR_mknodat)
case TARGET_NR_mknodat:
if (!(p = lock_user_string(arg2)))
goto efault;
ret = get_errno(mknodat(arg1, p, arg3, arg4));
unlock_user(p, arg2, 0);
#endif
#ifdef TARGET_NR_chmod
case TARGET_NR_chmod:
if (!(p = lock_user_string(arg1)))
goto efault;
ret = get_errno(chmod(p, arg2));
unlock_user(p, arg1, 0);
#endif
#ifdef TARGET_NR_break
case TARGET_NR_break:
goto unimplemented;
#endif
#ifdef TARGET_NR_oldstat
case TARGET_NR_oldstat:
goto unimplemented;
#endif
case TARGET_NR_lseek:
ret = get_errno(lseek(arg1, arg2, arg3));
#if defined(TARGET_NR_getxpid) && defined(TARGET_ALPHA)
case TARGET_NR_getxpid:
((CPUAlphaState *)cpu_env)->ir[IR_A4] = getppid();
ret = get_errno(getpid());
#endif
#ifdef TARGET_NR_getpid
case TARGET_NR_getpid:
ret = get_errno(getpid());
#endif
case TARGET_NR_mount:
{
void *p2, *p3;
if (arg1) {
p = lock_user_string(arg1);
if (!p) {
goto efault;
} else {
p = NULL;
p2 = lock_user_string(arg2);
if (!p2) {
if (arg1) {
unlock_user(p, arg1, 0);
goto efault;
if (arg3) {
p3 = lock_user_string(arg3);
if (!p3) {
if (arg1) {
unlock_user(p, arg1, 0);
unlock_user(p2, arg2, 0);
goto efault;
} else {
p3 = NULL;
if (!arg5) {
ret = mount(p, p2, p3, (unsigned long)arg4, NULL);
} else {
ret = mount(p, p2, p3, (unsigned long)arg4, g2h(arg5));
ret = get_errno(ret);
if (arg1) {
unlock_user(p, arg1, 0);
unlock_user(p2, arg2, 0);
if (arg3) {
unlock_user(p3, arg3, 0);
#ifdef TARGET_NR_umount
case TARGET_NR_umount:
if (!(p = lock_user_string(arg1)))
goto efault;
ret = get_errno(umount(p));
unlock_user(p, arg1, 0);
#endif
#ifdef TARGET_NR_stime
case TARGET_NR_stime:
{
time_t host_time;
if (get_user_sal(host_time, arg1))
goto efault;
ret = get_errno(stime(&host_time));
#endif
case TARGET_NR_ptrace:
goto unimplemented;
#ifdef TARGET_NR_alarm
case TARGET_NR_alarm:
ret = alarm(arg1);
#endif
#ifdef TARGET_NR_oldfstat
case TARGET_NR_oldfstat:
goto unimplemented;
#endif
#ifdef TARGET_NR_pause
case TARGET_NR_pause:
if (!block_signals()) {
sigsuspend(&((TaskState *)cpu->opaque)->signal_mask);
ret = -TARGET_EINTR;
#endif
#ifdef TARGET_NR_utime
case TARGET_NR_utime:
{
struct utimbuf tbuf, *host_tbuf;
struct target_utimbuf *target_tbuf;
if (arg2) {
if (!lock_user_struct(VERIFY_READ, target_tbuf, arg2, 1))
goto efault;
tbuf.actime = tswapal(target_tbuf->actime);
tbuf.modtime = tswapal(target_tbuf->modtime);
unlock_user_struct(target_tbuf, arg2, 0);
host_tbuf = &tbuf;
} else {
host_tbuf = NULL;
if (!(p = lock_user_string(arg1)))
goto efault;
ret = get_errno(utime(p, host_tbuf));
unlock_user(p, arg1, 0);
#endif
#ifdef TARGET_NR_utimes
case TARGET_NR_utimes:
{
struct timeval *tvp, tv[2];
if (arg2) {
if (copy_from_user_timeval(&tv[0], arg2)
|| copy_from_user_timeval(&tv[1],
arg2 + sizeof(struct target_timeval)))
goto efault;
tvp = tv;
} else {
tvp = NULL;
if (!(p = lock_user_string(arg1)))
goto efault;
ret = get_errno(utimes(p, tvp));
unlock_user(p, arg1, 0);
#endif
#if defined(TARGET_NR_futimesat)
case TARGET_NR_futimesat:
{
struct timeval *tvp, tv[2];
if (arg3) {
if (copy_from_user_timeval(&tv[0], arg3)
|| copy_from_user_timeval(&tv[1],
arg3 + sizeof(struct target_timeval)))
goto efault;
tvp = tv;
} else {
tvp = NULL;
if (!(p = lock_user_string(arg2)))
goto efault;
ret = get_errno(futimesat(arg1, path(p), tvp));
unlock_user(p, arg2, 0);
#endif
#ifdef TARGET_NR_stty
case TARGET_NR_stty:
goto unimplemented;
#endif
#ifdef TARGET_NR_gtty
case TARGET_NR_gtty:
goto unimplemented;
#endif
#ifdef TARGET_NR_access
case TARGET_NR_access:
if (!(p = lock_user_string(arg1)))
goto efault;
ret = get_errno(access(path(p), arg2));
unlock_user(p, arg1, 0);
#endif
#if defined(TARGET_NR_faccessat) && defined(__NR_faccessat)
case TARGET_NR_faccessat:
if (!(p = lock_user_string(arg2)))
goto efault;
ret = get_errno(faccessat(arg1, p, arg3, 0));
unlock_user(p, arg2, 0);
#endif
#ifdef TARGET_NR_nice
case TARGET_NR_nice:
ret = get_errno(nice(arg1));
#endif
#ifdef TARGET_NR_ftime
case TARGET_NR_ftime:
goto unimplemented;
#endif
case TARGET_NR_sync:
sync();
ret = 0;
case TARGET_NR_kill:
ret = get_errno(safe_kill(arg1, target_to_host_signal(arg2)));
#ifdef TARGET_NR_rename
case TARGET_NR_rename:
{
void *p2;
p = lock_user_string(arg1);
p2 = lock_user_string(arg2);
if (!p || !p2)
ret = -TARGET_EFAULT;
else
ret = get_errno(rename(p, p2));
unlock_user(p2, arg2, 0);
unlock_user(p, arg1, 0);
#endif
#if defined(TARGET_NR_renameat)
case TARGET_NR_renameat:
{
void *p2;
p = lock_user_string(arg2);
p2 = lock_user_string(arg4);
if (!p || !p2)
ret = -TARGET_EFAULT;
else
ret = get_errno(renameat(arg1, p, arg3, p2));
unlock_user(p2, arg4, 0);
unlock_user(p, arg2, 0);
#endif
#ifdef TARGET_NR_mkdir
case TARGET_NR_mkdir:
if (!(p = lock_user_string(arg1)))
goto efault;
ret = get_errno(mkdir(p, arg2));
unlock_user(p, arg1, 0);
#endif
#if defined(TARGET_NR_mkdirat)
case TARGET_NR_mkdirat:
if (!(p = lock_user_string(arg2)))
goto efault;
ret = get_errno(mkdirat(arg1, p, arg3));
unlock_user(p, arg2, 0);
#endif
#ifdef TARGET_NR_rmdir
case TARGET_NR_rmdir:
if (!(p = lock_user_string(arg1)))
goto efault;
ret = get_errno(rmdir(p));
unlock_user(p, arg1, 0);
#endif
case TARGET_NR_dup:
ret = get_errno(dup(arg1));
if (ret >= 0) {
fd_trans_dup(arg1, ret);
#ifdef TARGET_NR_pipe
case TARGET_NR_pipe:
ret = do_pipe(cpu_env, arg1, 0, 0);
#endif
#ifdef TARGET_NR_pipe2
case TARGET_NR_pipe2:
ret = do_pipe(cpu_env, arg1,
target_to_host_bitmask(arg2, fcntl_flags_tbl), 1);
#endif
case TARGET_NR_times:
{
struct target_tms *tmsp;
struct tms tms;
ret = get_errno(times(&tms));
if (arg1) {
tmsp = lock_user(VERIFY_WRITE, arg1, sizeof(struct target_tms), 0);
if (!tmsp)
goto efault;
tmsp->tms_utime = tswapal(host_to_target_clock_t(tms.tms_utime));
tmsp->tms_stime = tswapal(host_to_target_clock_t(tms.tms_stime));
tmsp->tms_cutime = tswapal(host_to_target_clock_t(tms.tms_cutime));
tmsp->tms_cstime = tswapal(host_to_target_clock_t(tms.tms_cstime));
if (!is_error(ret))
ret = host_to_target_clock_t(ret);
#ifdef TARGET_NR_prof
case TARGET_NR_prof:
goto unimplemented;
#endif
#ifdef TARGET_NR_signal
case TARGET_NR_signal:
goto unimplemented;
#endif
case TARGET_NR_acct:
if (arg1 == 0) {
ret = get_errno(acct(NULL));
} else {
if (!(p = lock_user_string(arg1)))
goto efault;
ret = get_errno(acct(path(p)));
unlock_user(p, arg1, 0);
#ifdef TARGET_NR_umount2
case TARGET_NR_umount2:
if (!(p = lock_user_string(arg1)))
goto efault;
ret = get_errno(umount2(p, arg2));
unlock_user(p, arg1, 0);
#endif
#ifdef TARGET_NR_lock
case TARGET_NR_lock:
goto unimplemented;
#endif
case TARGET_NR_ioctl:
ret = do_ioctl(arg1, arg2, arg3);
case TARGET_NR_fcntl:
ret = do_fcntl(arg1, arg2, arg3);
#ifdef TARGET_NR_mpx
case TARGET_NR_mpx:
goto unimplemented;
#endif
case TARGET_NR_setpgid:
ret = get_errno(setpgid(arg1, arg2));
#ifdef TARGET_NR_ulimit
case TARGET_NR_ulimit:
goto unimplemented;
#endif
#ifdef TARGET_NR_oldolduname
case TARGET_NR_oldolduname:
goto unimplemented;
#endif
case TARGET_NR_umask:
ret = get_errno(umask(arg1));
case TARGET_NR_chroot:
if (!(p = lock_user_string(arg1)))
goto efault;
ret = get_errno(chroot(p));
unlock_user(p, arg1, 0);
#ifdef TARGET_NR_ustat
case TARGET_NR_ustat:
goto unimplemented;
#endif
#ifdef TARGET_NR_dup2
case TARGET_NR_dup2:
ret = get_errno(dup2(arg1, arg2));
if (ret >= 0) {
fd_trans_dup(arg1, arg2);
#endif
#if defined(CONFIG_DUP3) && defined(TARGET_NR_dup3)
case TARGET_NR_dup3:
ret = get_errno(dup3(arg1, arg2, arg3));
if (ret >= 0) {
fd_trans_dup(arg1, arg2);
#endif
#ifdef TARGET_NR_getppid
case TARGET_NR_getppid:
ret = get_errno(getppid());
#endif
#ifdef TARGET_NR_getpgrp
case TARGET_NR_getpgrp:
ret = get_errno(getpgrp());
#endif
case TARGET_NR_setsid:
ret = get_errno(setsid());
#ifdef TARGET_NR_sigaction
case TARGET_NR_sigaction:
{
#if defined(TARGET_ALPHA)
struct target_sigaction act, oact, *pact = 0;
struct target_old_sigaction *old_act;
if (arg2) {
if (!lock_user_struct(VERIFY_READ, old_act, arg2, 1))
goto efault;
act._sa_handler = old_act->_sa_handler;
target_siginitset(&act.sa_mask, old_act->sa_mask);
act.sa_flags = old_act->sa_flags;
act.sa_restorer = 0;
unlock_user_struct(old_act, arg2, 0);
pact = &act;
ret = get_errno(do_sigaction(arg1, pact, &oact));
if (!is_error(ret) && arg3) {
if (!lock_user_struct(VERIFY_WRITE, old_act, arg3, 0))
goto efault;
old_act->_sa_handler = oact._sa_handler;
old_act->sa_mask = oact.sa_mask.sig[0];
old_act->sa_flags = oact.sa_flags;
unlock_user_struct(old_act, arg3, 1);
#elif defined(TARGET_MIPS)
struct target_sigaction act, oact, *pact, *old_act;
if (arg2) {
if (!lock_user_struct(VERIFY_READ, old_act, arg2, 1))
goto efault;
act._sa_handler = old_act->_sa_handler;
target_siginitset(&act.sa_mask, old_act->sa_mask.sig[0]);
act.sa_flags = old_act->sa_flags;
unlock_user_struct(old_act, arg2, 0);
pact = &act;
} else {
pact = NULL;
ret = get_errno(do_sigaction(arg1, pact, &oact));
if (!is_error(ret) && arg3) {
if (!lock_user_struct(VERIFY_WRITE, old_act, arg3, 0))
goto efault;
old_act->_sa_handler = oact._sa_handler;
old_act->sa_flags = oact.sa_flags;
old_act->sa_mask.sig[0] = oact.sa_mask.sig[0];
old_act->sa_mask.sig[1] = 0;
old_act->sa_mask.sig[2] = 0;
old_act->sa_mask.sig[3] = 0;
unlock_user_struct(old_act, arg3, 1);
#else
struct target_old_sigaction *old_act;
struct target_sigaction act, oact, *pact;
if (arg2) {
if (!lock_user_struct(VERIFY_READ, old_act, arg2, 1))
goto efault;
act._sa_handler = old_act->_sa_handler;
target_siginitset(&act.sa_mask, old_act->sa_mask);
act.sa_flags = old_act->sa_flags;
act.sa_restorer = old_act->sa_restorer;
unlock_user_struct(old_act, arg2, 0);
pact = &act;
} else {
pact = NULL;
ret = get_errno(do_sigaction(arg1, pact, &oact));
if (!is_error(ret) && arg3) {
if (!lock_user_struct(VERIFY_WRITE, old_act, arg3, 0))
goto efault;
old_act->_sa_handler = oact._sa_handler;
old_act->sa_mask = oact.sa_mask.sig[0];
old_act->sa_flags = oact.sa_flags;
old_act->sa_restorer = oact.sa_restorer;
unlock_user_struct(old_act, arg3, 1);
#endif
#endif
case TARGET_NR_rt_sigaction:
{
#if defined(TARGET_ALPHA)
struct target_sigaction act, oact, *pact = 0;
struct target_rt_sigaction *rt_act;
if (arg4 != sizeof(target_sigset_t)) {
if (arg2) {
if (!lock_user_struct(VERIFY_READ, rt_act, arg2, 1))
goto efault;
act._sa_handler = rt_act->_sa_handler;
act.sa_mask = rt_act->sa_mask;
act.sa_flags = rt_act->sa_flags;
act.sa_restorer = arg5;
unlock_user_struct(rt_act, arg2, 0);
pact = &act;
ret = get_errno(do_sigaction(arg1, pact, &oact));
if (!is_error(ret) && arg3) {
if (!lock_user_struct(VERIFY_WRITE, rt_act, arg3, 0))
goto efault;
rt_act->_sa_handler = oact._sa_handler;
rt_act->sa_mask = oact.sa_mask;
rt_act->sa_flags = oact.sa_flags;
unlock_user_struct(rt_act, arg3, 1);
#else
struct target_sigaction *act;
struct target_sigaction *oact;
if (arg4 != sizeof(target_sigset_t)) {
if (arg2) {
if (!lock_user_struct(VERIFY_READ, act, arg2, 1))
goto efault;
} else
act = NULL;
if (arg3) {
if (!lock_user_struct(VERIFY_WRITE, oact, arg3, 0)) {
ret = -TARGET_EFAULT;
goto rt_sigaction_fail;
} else
oact = NULL;
ret = get_errno(do_sigaction(arg1, act, oact));
rt_sigaction_fail:
if (act)
unlock_user_struct(act, arg2, 0);
if (oact)
unlock_user_struct(oact, arg3, 1);
#endif
#ifdef TARGET_NR_sgetmask
case TARGET_NR_sgetmask:
{
sigset_t cur_set;
abi_ulong target_set;
ret = do_sigprocmask(0, NULL, &cur_set);
if (!ret) {
host_to_target_old_sigset(&target_set, &cur_set);
ret = target_set;
#endif
#ifdef TARGET_NR_ssetmask
case TARGET_NR_ssetmask:
{
sigset_t set, oset, cur_set;
abi_ulong target_set = arg1;
ret = do_sigprocmask(0, NULL, &cur_set);
assert(!ret);
target_to_host_old_sigset(&set, &target_set);
sigorset(&set, &set, &cur_set);
ret = do_sigprocmask(SIG_SETMASK, &set, &oset);
if (!ret) {
host_to_target_old_sigset(&target_set, &oset);
ret = target_set;
#endif
#ifdef TARGET_NR_sigprocmask
case TARGET_NR_sigprocmask:
{
#if defined(TARGET_ALPHA)
sigset_t set, oldset;
abi_ulong mask;
int how;
switch (arg1) {
case TARGET_SIG_BLOCK:
how = SIG_BLOCK;
case TARGET_SIG_UNBLOCK:
how = SIG_UNBLOCK;
case TARGET_SIG_SETMASK:
how = SIG_SETMASK;
default:
goto fail;
mask = arg2;
target_to_host_old_sigset(&set, &mask);
ret = do_sigprocmask(how, &set, &oldset);
if (!is_error(ret)) {
host_to_target_old_sigset(&mask, &oldset);
ret = mask;
((CPUAlphaState *)cpu_env)->ir[IR_V0] = 0;
#else
sigset_t set, oldset, *set_ptr;
int how;
if (arg2) {
switch (arg1) {
case TARGET_SIG_BLOCK:
how = SIG_BLOCK;
case TARGET_SIG_UNBLOCK:
how = SIG_UNBLOCK;
case TARGET_SIG_SETMASK:
how = SIG_SETMASK;
default:
goto fail;
if (!(p = lock_user(VERIFY_READ, arg2, sizeof(target_sigset_t), 1)))
goto efault;
target_to_host_old_sigset(&set, p);
unlock_user(p, arg2, 0);
set_ptr = &set;
} else {
how = 0;
set_ptr = NULL;
ret = do_sigprocmask(how, set_ptr, &oldset);
if (!is_error(ret) && arg3) {
if (!(p = lock_user(VERIFY_WRITE, arg3, sizeof(target_sigset_t), 0)))
goto efault;
host_to_target_old_sigset(p, &oldset);
unlock_user(p, arg3, sizeof(target_sigset_t));
#endif
#endif
case TARGET_NR_rt_sigprocmask:
{
int how = arg1;
sigset_t set, oldset, *set_ptr;
if (arg4 != sizeof(target_sigset_t)) {
if (arg2) {
switch(how) {
case TARGET_SIG_BLOCK:
how = SIG_BLOCK;
case TARGET_SIG_UNBLOCK:
how = SIG_UNBLOCK;
case TARGET_SIG_SETMASK:
how = SIG_SETMASK;
default:
goto fail;
if (!(p = lock_user(VERIFY_READ, arg2, sizeof(target_sigset_t), 1)))
goto efault;
target_to_host_sigset(&set, p);
unlock_user(p, arg2, 0);
set_ptr = &set;
} else {
how = 0;
set_ptr = NULL;
ret = do_sigprocmask(how, set_ptr, &oldset);
if (!is_error(ret) && arg3) {
if (!(p = lock_user(VERIFY_WRITE, arg3, sizeof(target_sigset_t), 0)))
goto efault;
host_to_target_sigset(p, &oldset);
unlock_user(p, arg3, sizeof(target_sigset_t));
#ifdef TARGET_NR_sigpending
case TARGET_NR_sigpending:
{
sigset_t set;
ret = get_errno(sigpending(&set));
if (!is_error(ret)) {
if (!(p = lock_user(VERIFY_WRITE, arg1, sizeof(target_sigset_t), 0)))
goto efault;
host_to_target_old_sigset(p, &set);
unlock_user(p, arg1, sizeof(target_sigset_t));
#endif
case TARGET_NR_rt_sigpending:
{
sigset_t set;
if (arg2 > sizeof(target_sigset_t)) {
ret = get_errno(sigpending(&set));
if (!is_error(ret)) {
if (!(p = lock_user(VERIFY_WRITE, arg1, sizeof(target_sigset_t), 0)))
goto efault;
host_to_target_sigset(p, &set);
unlock_user(p, arg1, sizeof(target_sigset_t));
#ifdef TARGET_NR_sigsuspend
case TARGET_NR_sigsuspend:
{
TaskState *ts = cpu->opaque;
#if defined(TARGET_ALPHA)
abi_ulong mask = arg1;
target_to_host_old_sigset(&ts->sigsuspend_mask, &mask);
#else
if (!(p = lock_user(VERIFY_READ, arg1, sizeof(target_sigset_t), 1)))
goto efault;
target_to_host_old_sigset(&ts->sigsuspend_mask, p);
unlock_user(p, arg1, 0);
#endif
ret = get_errno(safe_rt_sigsuspend(&ts->sigsuspend_mask,
SIGSET_T_SIZE));
if (ret != -TARGET_ERESTARTSYS) {
ts->in_sigsuspend = 1;
#endif
case TARGET_NR_rt_sigsuspend:
{
TaskState *ts = cpu->opaque;
if (arg2 != sizeof(target_sigset_t)) {
if (!(p = lock_user(VERIFY_READ, arg1, sizeof(target_sigset_t), 1)))
goto efault;
target_to_host_sigset(&ts->sigsuspend_mask, p);
unlock_user(p, arg1, 0);
ret = get_errno(safe_rt_sigsuspend(&ts->sigsuspend_mask,
SIGSET_T_SIZE));
if (ret != -TARGET_ERESTARTSYS) {
ts->in_sigsuspend = 1;
case TARGET_NR_rt_sigtimedwait:
{
sigset_t set;
struct timespec uts, *puts;
siginfo_t uinfo;
if (arg4 != sizeof(target_sigset_t)) {
if (!(p = lock_user(VERIFY_READ, arg1, sizeof(target_sigset_t), 1)))
goto efault;
target_to_host_sigset(&set, p);
unlock_user(p, arg1, 0);
if (arg3) {
puts = &uts;
target_to_host_timespec(puts, arg3);
} else {
puts = NULL;
ret = get_errno(safe_rt_sigtimedwait(&set, &uinfo, puts,
SIGSET_T_SIZE));
if (!is_error(ret)) {
if (arg2) {
p = lock_user(VERIFY_WRITE, arg2, sizeof(target_siginfo_t),
0);
if (!p) {
goto efault;
host_to_target_siginfo(p, &uinfo);
unlock_user(p, arg2, sizeof(target_siginfo_t));
ret = host_to_target_signal(ret);
case TARGET_NR_rt_sigqueueinfo:
{
siginfo_t uinfo;
p = lock_user(VERIFY_READ, arg3, sizeof(target_siginfo_t), 1);
if (!p) {
goto efault;
target_to_host_siginfo(&uinfo, p);
unlock_user(p, arg1, 0);
ret = get_errno(sys_rt_sigqueueinfo(arg1, arg2, &uinfo));
#ifdef TARGET_NR_sigreturn
case TARGET_NR_sigreturn:
if (block_signals()) {
ret = -TARGET_ERESTARTSYS;
} else {
ret = do_sigreturn(cpu_env);
#endif
case TARGET_NR_rt_sigreturn:
if (block_signals()) {
ret = -TARGET_ERESTARTSYS;
} else {
ret = do_rt_sigreturn(cpu_env);
case TARGET_NR_sethostname:
if (!(p = lock_user_string(arg1)))
goto efault;
ret = get_errno(sethostname(p, arg2));
unlock_user(p, arg1, 0);
case TARGET_NR_setrlimit:
{
int resource = target_to_host_resource(arg1);
struct target_rlimit *target_rlim;
struct rlimit rlim;
if (!lock_user_struct(VERIFY_READ, target_rlim, arg2, 1))
goto efault;
rlim.rlim_cur = target_to_host_rlim(target_rlim->rlim_cur);
rlim.rlim_max = target_to_host_rlim(target_rlim->rlim_max);
unlock_user_struct(target_rlim, arg2, 0);
ret = get_errno(setrlimit(resource, &rlim));
case TARGET_NR_getrlimit:
{
int resource = target_to_host_resource(arg1);
struct target_rlimit *target_rlim;
struct rlimit rlim;
ret = get_errno(getrlimit(resource, &rlim));
if (!is_error(ret)) {
if (!lock_user_struct(VERIFY_WRITE, target_rlim, arg2, 0))
goto efault;
target_rlim->rlim_cur = host_to_target_rlim(rlim.rlim_cur);
target_rlim->rlim_max = host_to_target_rlim(rlim.rlim_max);
unlock_user_struct(target_rlim, arg2, 1);
case TARGET_NR_getrusage:
{
struct rusage rusage;
ret = get_errno(getrusage(arg1, &rusage));
if (!is_error(ret)) {
ret = host_to_target_rusage(arg2, &rusage);
case TARGET_NR_gettimeofday:
{
struct timeval tv;
ret = get_errno(gettimeofday(&tv, NULL));
if (!is_error(ret)) {
if (copy_to_user_timeval(arg1, &tv))
goto efault;
case TARGET_NR_settimeofday:
{
struct timeval tv, *ptv = NULL;
struct timezone tz, *ptz = NULL;
if (arg1) {
if (copy_from_user_timeval(&tv, arg1)) {
goto efault;
ptv = &tv;
if (arg2) {
if (copy_from_user_timezone(&tz, arg2)) {
goto efault;
ptz = &tz;
ret = get_errno(settimeofday(ptv, ptz));
#if defined(TARGET_NR_select)
case TARGET_NR_select:
#if defined(TARGET_S390X) || defined(TARGET_ALPHA)
ret = do_select(arg1, arg2, arg3, arg4, arg5);
#else
{
struct target_sel_arg_struct *sel;
abi_ulong inp, outp, exp, tvp;
long nsel;
if (!lock_user_struct(VERIFY_READ, sel, arg1, 1))
goto efault;
nsel = tswapal(sel->n);
inp = tswapal(sel->inp);
outp = tswapal(sel->outp);
exp = tswapal(sel->exp);
tvp = tswapal(sel->tvp);
unlock_user_struct(sel, arg1, 0);
ret = do_select(nsel, inp, outp, exp, tvp);
#endif
#endif
#ifdef TARGET_NR_pselect6
case TARGET_NR_pselect6:
{
abi_long rfd_addr, wfd_addr, efd_addr, n, ts_addr;
fd_set rfds, wfds, efds;
fd_set *rfds_ptr, *wfds_ptr, *efds_ptr;
struct timespec ts, *ts_ptr;
sigset_t set;
struct {
sigset_t *set;
size_t size;
} sig, *sig_ptr;
abi_ulong arg_sigset, arg_sigsize, *arg7;
target_sigset_t *target_sigset;
n = arg1;
rfd_addr = arg2;
wfd_addr = arg3;
efd_addr = arg4;
ts_addr = arg5;
ret = copy_from_user_fdset_ptr(&rfds, &rfds_ptr, rfd_addr, n);
if (ret) {
goto fail;
ret = copy_from_user_fdset_ptr(&wfds, &wfds_ptr, wfd_addr, n);
if (ret) {
goto fail;
ret = copy_from_user_fdset_ptr(&efds, &efds_ptr, efd_addr, n);
if (ret) {
goto fail;
if (ts_addr) {
if (target_to_host_timespec(&ts, ts_addr)) {
goto efault;
ts_ptr = &ts;
} else {
ts_ptr = NULL;
if (arg6) {
sig_ptr = &sig;
sig.size = SIGSET_T_SIZE;
arg7 = lock_user(VERIFY_READ, arg6, sizeof(*arg7) * 2, 1);
if (!arg7) {
goto efault;
arg_sigset = tswapal(arg7[0]);
arg_sigsize = tswapal(arg7[1]);
unlock_user(arg7, arg6, 0);
if (arg_sigset) {
sig.set = &set;
if (arg_sigsize != sizeof(*target_sigset)) {
goto fail;
target_sigset = lock_user(VERIFY_READ, arg_sigset,
sizeof(*target_sigset), 1);
if (!target_sigset) {
goto efault;
target_to_host_sigset(&set, target_sigset);
unlock_user(target_sigset, arg_sigset, 0);
} else {
sig.set = NULL;
} else {
sig_ptr = NULL;
ret = get_errno(safe_pselect6(n, rfds_ptr, wfds_ptr, efds_ptr,
ts_ptr, sig_ptr));
if (!is_error(ret)) {
if (rfd_addr && copy_to_user_fdset(rfd_addr, &rfds, n))
goto efault;
if (wfd_addr && copy_to_user_fdset(wfd_addr, &wfds, n))
goto efault;
if (efd_addr && copy_to_user_fdset(efd_addr, &efds, n))
goto efault;
if (ts_addr && host_to_target_timespec(ts_addr, &ts))
goto efault;
#endif
#ifdef TARGET_NR_symlink
case TARGET_NR_symlink:
{
void *p2;
p = lock_user_string(arg1);
p2 = lock_user_string(arg2);
if (!p || !p2)
ret = -TARGET_EFAULT;
else
ret = get_errno(symlink(p, p2));
unlock_user(p2, arg2, 0);
unlock_user(p, arg1, 0);
#endif
#if defined(TARGET_NR_symlinkat)
case TARGET_NR_symlinkat:
{
void *p2;
p = lock_user_string(arg1);
p2 = lock_user_string(arg3);
if (!p || !p2)
ret = -TARGET_EFAULT;
else
ret = get_errno(symlinkat(p, arg2, p2));
unlock_user(p2, arg3, 0);
unlock_user(p, arg1, 0);
#endif
#ifdef TARGET_NR_oldlstat
case TARGET_NR_oldlstat:
goto unimplemented;
#endif
#ifdef TARGET_NR_readlink
case TARGET_NR_readlink:
{
void *p2;
p = lock_user_string(arg1);
p2 = lock_user(VERIFY_WRITE, arg2, arg3, 0);
if (!p || !p2) {
ret = -TARGET_EFAULT;
} else if (!arg3) {
} else if (is_proc_myself((const char *)p, "exe")) {
char real[PATH_MAX], *temp;
temp = realpath(exec_path, real);
if (temp == NULL) {
ret = get_errno(-1);
} else {
ret = MIN(strlen(real), arg3);
memcpy(p2, real, ret);
} else {
ret = get_errno(readlink(path(p), p2, arg3));
unlock_user(p2, arg2, ret);
unlock_user(p, arg1, 0);
#endif
#if defined(TARGET_NR_readlinkat)
case TARGET_NR_readlinkat:
{
void *p2;
p = lock_user_string(arg2);
p2 = lock_user(VERIFY_WRITE, arg3, arg4, 0);
if (!p || !p2) {
ret = -TARGET_EFAULT;
} else if (is_proc_myself((const char *)p, "exe")) {
char real[PATH_MAX], *temp;
temp = realpath(exec_path, real);
ret = temp == NULL ? get_errno(-1) : strlen(real) ;
snprintf((char *)p2, arg4, "%s", real);
} else {
ret = get_errno(readlinkat(arg1, path(p), p2, arg4));
unlock_user(p2, arg3, ret);
unlock_user(p, arg2, 0);
#endif
#ifdef TARGET_NR_uselib
case TARGET_NR_uselib:
goto unimplemented;
#endif
#ifdef TARGET_NR_swapon
case TARGET_NR_swapon:
if (!(p = lock_user_string(arg1)))
goto efault;
ret = get_errno(swapon(p, arg2));
unlock_user(p, arg1, 0);
#endif
case TARGET_NR_reboot:
if (arg3 == LINUX_REBOOT_CMD_RESTART2) {
p = lock_user_string(arg4);
if (!p) {
goto efault;
ret = get_errno(reboot(arg1, arg2, arg3, p));
unlock_user(p, arg4, 0);
} else {
ret = get_errno(reboot(arg1, arg2, arg3, NULL));
#ifdef TARGET_NR_readdir
case TARGET_NR_readdir:
goto unimplemented;
#endif
#ifdef TARGET_NR_mmap
case TARGET_NR_mmap:
#if (defined(TARGET_I386) && defined(TARGET_ABI32)) || \
(defined(TARGET_ARM) && defined(TARGET_ABI32)) || \
defined(TARGET_M68K) || defined(TARGET_CRIS) || defined(TARGET_MICROBLAZE) \
|| defined(TARGET_S390X)
{
abi_ulong *v;
abi_ulong v1, v2, v3, v4, v5, v6;
if (!(v = lock_user(VERIFY_READ, arg1, 6 * sizeof(abi_ulong), 1)))
goto efault;
v1 = tswapal(v[0]);
v2 = tswapal(v[1]);
v3 = tswapal(v[2]);
v4 = tswapal(v[3]);
v5 = tswapal(v[4]);
v6 = tswapal(v[5]);
unlock_user(v, arg1, 0);
ret = get_errno(target_mmap(v1, v2, v3,
target_to_host_bitmask(v4, mmap_flags_tbl),
v5, v6));
#else
ret = get_errno(target_mmap(arg1, arg2, arg3,
target_to_host_bitmask(arg4, mmap_flags_tbl),
arg5,
arg6));
#endif
#endif
#ifdef TARGET_NR_mmap2
case TARGET_NR_mmap2:
#ifndef MMAP_SHIFT
#define MMAP_SHIFT 12
#endif
ret = get_errno(target_mmap(arg1, arg2, arg3,
target_to_host_bitmask(arg4, mmap_flags_tbl),
arg5,
arg6 << MMAP_SHIFT));
#endif
case TARGET_NR_munmap:
ret = get_errno(target_munmap(arg1, arg2));
case TARGET_NR_mprotect:
{
TaskState *ts = cpu->opaque;
if ((arg3 & PROT_GROWSDOWN)
&& arg1 >= ts->info->stack_limit
&& arg1 <= ts->info->start_stack) {
arg3 &= ~PROT_GROWSDOWN;
arg2 = arg2 + arg1 - ts->info->stack_limit;
arg1 = ts->info->stack_limit;
ret = get_errno(target_mprotect(arg1, arg2, arg3));
#ifdef TARGET_NR_mremap
case TARGET_NR_mremap:
ret = get_errno(target_mremap(arg1, arg2, arg3, arg4, arg5));
#endif
#ifdef TARGET_NR_msync
case TARGET_NR_msync:
ret = get_errno(msync(g2h(arg1), arg2, arg3));
#endif
#ifdef TARGET_NR_mlock
case TARGET_NR_mlock:
ret = get_errno(mlock(g2h(arg1), arg2));
#endif
#ifdef TARGET_NR_munlock
case TARGET_NR_munlock:
ret = get_errno(munlock(g2h(arg1), arg2));
#endif
#ifdef TARGET_NR_mlockall
case TARGET_NR_mlockall:
ret = get_errno(mlockall(target_to_host_mlockall_arg(arg1)));
#endif
#ifdef TARGET_NR_munlockall
case TARGET_NR_munlockall:
ret = get_errno(munlockall());
#endif
case TARGET_NR_truncate:
if (!(p = lock_user_string(arg1)))
goto efault;
ret = get_errno(truncate(p, arg2));
unlock_user(p, arg1, 0);
case TARGET_NR_ftruncate:
ret = get_errno(ftruncate(arg1, arg2));
case TARGET_NR_fchmod:
ret = get_errno(fchmod(arg1, arg2));
#if defined(TARGET_NR_fchmodat)
case TARGET_NR_fchmodat:
if (!(p = lock_user_string(arg2)))
goto efault;
ret = get_errno(fchmodat(arg1, p, arg3, 0));
unlock_user(p, arg2, 0);
#endif
case TARGET_NR_getpriority:
errno = 0;
ret = getpriority(arg1, arg2);
if (ret == -1 && errno != 0) {
ret = -host_to_target_errno(errno);
#ifdef TARGET_ALPHA
((CPUAlphaState *)cpu_env)->ir[IR_V0] = 0;
#else
ret = 20 - ret;
#endif
case TARGET_NR_setpriority:
ret = get_errno(setpriority(arg1, arg2, arg3));
#ifdef TARGET_NR_profil
case TARGET_NR_profil:
goto unimplemented;
#endif
case TARGET_NR_statfs:
if (!(p = lock_user_string(arg1)))
goto efault;
ret = get_errno(statfs(path(p), &stfs));
unlock_user(p, arg1, 0);
convert_statfs:
if (!is_error(ret)) {
struct target_statfs *target_stfs;
if (!lock_user_struct(VERIFY_WRITE, target_stfs, arg2, 0))
goto efault;
__put_user(stfs.f_type, &target_stfs->f_type);
__put_user(stfs.f_bsize, &target_stfs->f_bsize);
__put_user(stfs.f_blocks, &target_stfs->f_blocks);
__put_user(stfs.f_bfree, &target_stfs->f_bfree);
__put_user(stfs.f_bavail, &target_stfs->f_bavail);
__put_user(stfs.f_files, &target_stfs->f_files);
__put_user(stfs.f_ffree, &target_stfs->f_ffree);
__put_user(stfs.f_fsid.__val[0], &target_stfs->f_fsid.val[0]);
__put_user(stfs.f_fsid.__val[1], &target_stfs->f_fsid.val[1]);
__put_user(stfs.f_namelen, &target_stfs->f_namelen);
__put_user(stfs.f_frsize, &target_stfs->f_frsize);
memset(target_stfs->f_spare, 0, sizeof(target_stfs->f_spare));
unlock_user_struct(target_stfs, arg2, 1);
case TARGET_NR_fstatfs:
ret = get_errno(fstatfs(arg1, &stfs));
goto convert_statfs;
#ifdef TARGET_NR_statfs64
case TARGET_NR_statfs64:
if (!(p = lock_user_string(arg1)))
goto efault;
ret = get_errno(statfs(path(p), &stfs));
unlock_user(p, arg1, 0);
convert_statfs64:
if (!is_error(ret)) {
struct target_statfs64 *target_stfs;
if (!lock_user_struct(VERIFY_WRITE, target_stfs, arg3, 0))
goto efault;
__put_user(stfs.f_type, &target_stfs->f_type);
__put_user(stfs.f_bsize, &target_stfs->f_bsize);
__put_user(stfs.f_blocks, &target_stfs->f_blocks);
__put_user(stfs.f_bfree, &target_stfs->f_bfree);
__put_user(stfs.f_bavail, &target_stfs->f_bavail);
__put_user(stfs.f_files, &target_stfs->f_files);
__put_user(stfs.f_ffree, &target_stfs->f_ffree);
__put_user(stfs.f_fsid.__val[0], &target_stfs->f_fsid.val[0]);
__put_user(stfs.f_fsid.__val[1], &target_stfs->f_fsid.val[1]);
__put_user(stfs.f_namelen, &target_stfs->f_namelen);
__put_user(stfs.f_frsize, &target_stfs->f_frsize);
memset(target_stfs->f_spare, 0, sizeof(target_stfs->f_spare));
unlock_user_struct(target_stfs, arg3, 1);
case TARGET_NR_fstatfs64:
ret = get_errno(fstatfs(arg1, &stfs));
goto convert_statfs64;
#endif
#ifdef TARGET_NR_ioperm
case TARGET_NR_ioperm:
goto unimplemented;
#endif
#ifdef TARGET_NR_socketcall
case TARGET_NR_socketcall:
ret = do_socketcall(arg1, arg2);
#endif
#ifdef TARGET_NR_accept
case TARGET_NR_accept:
ret = do_accept4(arg1, arg2, arg3, 0);
#endif
#ifdef TARGET_NR_accept4
case TARGET_NR_accept4:
ret = do_accept4(arg1, arg2, arg3, arg4);
#endif
#ifdef TARGET_NR_bind
case TARGET_NR_bind:
ret = do_bind(arg1, arg2, arg3);
#endif
#ifdef TARGET_NR_connect
case TARGET_NR_connect:
ret = do_connect(arg1, arg2, arg3);
#endif
#ifdef TARGET_NR_getpeername
case TARGET_NR_getpeername:
ret = do_getpeername(arg1, arg2, arg3);
#endif
#ifdef TARGET_NR_getsockname
case TARGET_NR_getsockname:
ret = do_getsockname(arg1, arg2, arg3);
#endif
#ifdef TARGET_NR_getsockopt
case TARGET_NR_getsockopt:
ret = do_getsockopt(arg1, arg2, arg3, arg4, arg5);
#endif
#ifdef TARGET_NR_listen
case TARGET_NR_listen:
ret = get_errno(listen(arg1, arg2));
#endif
#ifdef TARGET_NR_recv
case TARGET_NR_recv:
ret = do_recvfrom(arg1, arg2, arg3, arg4, 0, 0);
#endif
#ifdef TARGET_NR_recvfrom
case TARGET_NR_recvfrom:
ret = do_recvfrom(arg1, arg2, arg3, arg4, arg5, arg6);
#endif
#ifdef TARGET_NR_recvmsg
case TARGET_NR_recvmsg:
ret = do_sendrecvmsg(arg1, arg2, arg3, 0);
#endif
#ifdef TARGET_NR_send
case TARGET_NR_send:
ret = do_sendto(arg1, arg2, arg3, arg4, 0, 0);
#endif
#ifdef TARGET_NR_sendmsg
case TARGET_NR_sendmsg:
ret = do_sendrecvmsg(arg1, arg2, arg3, 1);
#endif
#ifdef TARGET_NR_sendmmsg
case TARGET_NR_sendmmsg:
ret = do_sendrecvmmsg(arg1, arg2, arg3, arg4, 1);
case TARGET_NR_recvmmsg:
ret = do_sendrecvmmsg(arg1, arg2, arg3, arg4, 0);
#endif
#ifdef TARGET_NR_sendto
case TARGET_NR_sendto:
ret = do_sendto(arg1, arg2, arg3, arg4, arg5, arg6);
#endif
#ifdef TARGET_NR_shutdown
case TARGET_NR_shutdown:
ret = get_errno(shutdown(arg1, arg2));
#endif
#if defined(TARGET_NR_getrandom) && defined(__NR_getrandom)
case TARGET_NR_getrandom:
p = lock_user(VERIFY_WRITE, arg1, arg2, 0);
if (!p) {
goto efault;
ret = get_errno(getrandom(p, arg2, arg3));
unlock_user(p, arg1, ret);
#endif
#ifdef TARGET_NR_socket
case TARGET_NR_socket:
ret = do_socket(arg1, arg2, arg3);
fd_trans_unregister(ret);
#endif
#ifdef TARGET_NR_socketpair
case TARGET_NR_socketpair:
ret = do_socketpair(arg1, arg2, arg3, arg4);
#endif
#ifdef TARGET_NR_setsockopt
case TARGET_NR_setsockopt:
ret = do_setsockopt(arg1, arg2, arg3, arg4, (socklen_t) arg5);
#endif
case TARGET_NR_syslog:
if (!(p = lock_user_string(arg2)))
goto efault;
ret = get_errno(sys_syslog((int)arg1, p, (int)arg3));
unlock_user(p, arg2, 0);
case TARGET_NR_setitimer:
{
struct itimerval value, ovalue, *pvalue;
if (arg2) {
pvalue = &value;
if (copy_from_user_timeval(&pvalue->it_interval, arg2)
|| copy_from_user_timeval(&pvalue->it_value,
arg2 + sizeof(struct target_timeval)))
goto efault;
} else {
pvalue = NULL;
ret = get_errno(setitimer(arg1, pvalue, &ovalue));
if (!is_error(ret) && arg3) {
if (copy_to_user_timeval(arg3,
&ovalue.it_interval)
|| copy_to_user_timeval(arg3 + sizeof(struct target_timeval),
&ovalue.it_value))
goto efault;
case TARGET_NR_getitimer:
{
struct itimerval value;
ret = get_errno(getitimer(arg1, &value));
if (!is_error(ret) && arg2) {
if (copy_to_user_timeval(arg2,
&value.it_interval)
|| copy_to_user_timeval(arg2 + sizeof(struct target_timeval),
&value.it_value))
goto efault;
#ifdef TARGET_NR_stat
case TARGET_NR_stat:
if (!(p = lock_user_string(arg1)))
goto efault;
ret = get_errno(stat(path(p), &st));
unlock_user(p, arg1, 0);
goto do_stat;
#endif
#ifdef TARGET_NR_lstat
case TARGET_NR_lstat:
if (!(p = lock_user_string(arg1)))
goto efault;
ret = get_errno(lstat(path(p), &st));
unlock_user(p, arg1, 0);
goto do_stat;
#endif
case TARGET_NR_fstat:
{
ret = get_errno(fstat(arg1, &st));
#if defined(TARGET_NR_stat) || defined(TARGET_NR_lstat)
do_stat:
#endif
if (!is_error(ret)) {
struct target_stat *target_st;
if (!lock_user_struct(VERIFY_WRITE, target_st, arg2, 0))
goto efault;
memset(target_st, 0, sizeof(*target_st));
__put_user(st.st_dev, &target_st->st_dev);
__put_user(st.st_ino, &target_st->st_ino);
__put_user(st.st_mode, &target_st->st_mode);
__put_user(st.st_uid, &target_st->st_uid);
__put_user(st.st_gid, &target_st->st_gid);
__put_user(st.st_nlink, &target_st->st_nlink);
__put_user(st.st_rdev, &target_st->st_rdev);
__put_user(st.st_size, &target_st->st_size);
__put_user(st.st_blksize, &target_st->st_blksize);
__put_user(st.st_blocks, &target_st->st_blocks);
__put_user(st.st_atime, &target_st->target_st_atime);
__put_user(st.st_mtime, &target_st->target_st_mtime);
__put_user(st.st_ctime, &target_st->target_st_ctime);
unlock_user_struct(target_st, arg2, 1);
#ifdef TARGET_NR_olduname
case TARGET_NR_olduname:
goto unimplemented;
#endif
#ifdef TARGET_NR_iopl
case TARGET_NR_iopl:
goto unimplemented;
#endif
case TARGET_NR_vhangup:
ret = get_errno(vhangup());
#ifdef TARGET_NR_idle
case TARGET_NR_idle:
goto unimplemented;
#endif
#ifdef TARGET_NR_syscall
case TARGET_NR_syscall:
ret = do_syscall(cpu_env, arg1 & 0xffff, arg2, arg3, arg4, arg5,
arg6, arg7, arg8, 0);
#endif
case TARGET_NR_wait4:
{
int status;
abi_long status_ptr = arg2;
struct rusage rusage, *rusage_ptr;
abi_ulong target_rusage = arg4;
abi_long rusage_err;
if (target_rusage)
rusage_ptr = &rusage;
else
rusage_ptr = NULL;
ret = get_errno(safe_wait4(arg1, &status, arg3, rusage_ptr));
if (!is_error(ret)) {
if (status_ptr && ret) {
status = host_to_target_waitstatus(status);
if (put_user_s32(status, status_ptr))
goto efault;
if (target_rusage) {
rusage_err = host_to_target_rusage(target_rusage, &rusage);
if (rusage_err) {
ret = rusage_err;
#ifdef TARGET_NR_swapoff
case TARGET_NR_swapoff:
if (!(p = lock_user_string(arg1)))
goto efault;
ret = get_errno(swapoff(p));
unlock_user(p, arg1, 0);
#endif
case TARGET_NR_sysinfo:
{
struct target_sysinfo *target_value;
struct sysinfo value;
ret = get_errno(sysinfo(&value));
if (!is_error(ret) && arg1)
{
if (!lock_user_struct(VERIFY_WRITE, target_value, arg1, 0))
goto efault;
__put_user(value.uptime, &target_value->uptime);
__put_user(value.loads[0], &target_value->loads[0]);
__put_user(value.loads[1], &target_value->loads[1]);
__put_user(value.loads[2], &target_value->loads[2]);
__put_user(value.totalram, &target_value->totalram);
__put_user(value.freeram, &target_value->freeram);
__put_user(value.sharedram, &target_value->sharedram);
__put_user(value.bufferram, &target_value->bufferram);
__put_user(value.totalswap, &target_value->totalswap);
__put_user(value.freeswap, &target_value->freeswap);
__put_user(value.procs, &target_value->procs);
__put_user(value.totalhigh, &target_value->totalhigh);
__put_user(value.freehigh, &target_value->freehigh);
__put_user(value.mem_unit, &target_value->mem_unit);
unlock_user_struct(target_value, arg1, 1);
#ifdef TARGET_NR_ipc
case TARGET_NR_ipc:
ret = do_ipc(arg1, arg2, arg3, arg4, arg5, arg6);
#endif
#ifdef TARGET_NR_semget
case TARGET_NR_semget:
ret = get_errno(semget(arg1, arg2, arg3));
#endif
#ifdef TARGET_NR_semop
case TARGET_NR_semop:
ret = do_semop(arg1, arg2, arg3);
#endif
#ifdef TARGET_NR_semctl
case TARGET_NR_semctl:
ret = do_semctl(arg1, arg2, arg3, arg4);
#endif
#ifdef TARGET_NR_msgctl
case TARGET_NR_msgctl:
ret = do_msgctl(arg1, arg2, arg3);
#endif
#ifdef TARGET_NR_msgget
case TARGET_NR_msgget:
ret = get_errno(msgget(arg1, arg2));
#endif
#ifdef TARGET_NR_msgrcv
case TARGET_NR_msgrcv:
ret = do_msgrcv(arg1, arg2, arg3, arg4, arg5);
#endif
#ifdef TARGET_NR_msgsnd
case TARGET_NR_msgsnd:
ret = do_msgsnd(arg1, arg2, arg3, arg4);
#endif
#ifdef TARGET_NR_shmget
case TARGET_NR_shmget:
ret = get_errno(shmget(arg1, arg2, arg3));
#endif
#ifdef TARGET_NR_shmctl
case TARGET_NR_shmctl:
ret = do_shmctl(arg1, arg2, arg3);
#endif
#ifdef TARGET_NR_shmat
case TARGET_NR_shmat:
ret = do_shmat(arg1, arg2, arg3);
#endif
#ifdef TARGET_NR_shmdt
case TARGET_NR_shmdt:
ret = do_shmdt(arg1);
#endif
case TARGET_NR_fsync:
ret = get_errno(fsync(arg1));
case TARGET_NR_clone:
#if defined(TARGET_MICROBLAZE)
ret = get_errno(do_fork(cpu_env, arg1, arg2, arg4, arg6, arg5));
#elif defined(TARGET_CLONE_BACKWARDS)
ret = get_errno(do_fork(cpu_env, arg1, arg2, arg3, arg4, arg5));
#elif defined(TARGET_CLONE_BACKWARDS2)
ret = get_errno(do_fork(cpu_env, arg2, arg1, arg3, arg5, arg4));
#else
ret = get_errno(do_fork(cpu_env, arg1, arg2, arg3, arg5, arg4));
#endif
#ifdef __NR_exit_group
case TARGET_NR_exit_group:
#ifdef TARGET_GPROF
_mcleanup();
#endif
gdb_exit(cpu_env, arg1);
ret = get_errno(exit_group(arg1));
#endif
case TARGET_NR_setdomainname:
if (!(p = lock_user_string(arg1)))
goto efault;
ret = get_errno(setdomainname(p, arg2));
unlock_user(p, arg1, 0);
case TARGET_NR_uname:
{
struct new_utsname * buf;
if (!lock_user_struct(VERIFY_WRITE, buf, arg1, 0))
goto efault;
ret = get_errno(sys_uname(buf));
if (!is_error(ret)) {
strcpy (buf->machine, cpu_to_uname_machine(cpu_env));
if (qemu_uname_release && *qemu_uname_release) {
g_strlcpy(buf->release, qemu_uname_release,
sizeof(buf->release));
unlock_user_struct(buf, arg1, 1);
#ifdef TARGET_I386
case TARGET_NR_modify_ldt:
ret = do_modify_ldt(cpu_env, arg1, arg2, arg3);
#if !defined(TARGET_X86_64)
case TARGET_NR_vm86old:
goto unimplemented;
case TARGET_NR_vm86:
ret = do_vm86(cpu_env, arg1, arg2);
#endif
#endif
case TARGET_NR_adjtimex:
goto unimplemented;
#ifdef TARGET_NR_create_module
case TARGET_NR_create_module:
#endif
case TARGET_NR_init_module:
case TARGET_NR_delete_module:
#ifdef TARGET_NR_get_kernel_syms
case TARGET_NR_get_kernel_syms:
#endif
goto unimplemented;
case TARGET_NR_quotactl:
goto unimplemented;
case TARGET_NR_getpgid:
ret = get_errno(getpgid(arg1));
case TARGET_NR_fchdir:
ret = get_errno(fchdir(arg1));
#ifdef TARGET_NR_bdflush
case TARGET_NR_bdflush:
goto unimplemented;
#endif
#ifdef TARGET_NR_sysfs
case TARGET_NR_sysfs:
goto unimplemented;
#endif
case TARGET_NR_personality:
ret = get_errno(personality(arg1));
#ifdef TARGET_NR_afs_syscall
case TARGET_NR_afs_syscall:
goto unimplemented;
#endif
#ifdef TARGET_NR__llseek
case TARGET_NR__llseek:
{
int64_t res;
#if !defined(__NR_llseek)
res = lseek(arg1, ((uint64_t)arg2 << 32) | (abi_ulong)arg3, arg5);
if (res == -1) {
ret = get_errno(res);
} else {
ret = 0;
#else
ret = get_errno(_llseek(arg1, arg2, arg3, &res, arg5));
#endif
if ((ret == 0) && put_user_s64(res, arg4)) {
goto efault;
#endif
#ifdef TARGET_NR_getdents
case TARGET_NR_getdents:
#ifdef __NR_getdents
#if TARGET_ABI_BITS == 32 && HOST_LONG_BITS == 64
{
struct target_dirent *target_dirp;
struct linux_dirent *dirp;
abi_long count = arg3;
dirp = g_try_malloc(count);
if (!dirp) {
ret = -TARGET_ENOMEM;
goto fail;
ret = get_errno(sys_getdents(arg1, dirp, count));
if (!is_error(ret)) {
struct linux_dirent *de;
struct target_dirent *tde;
int len = ret;
int reclen, treclen;
int count1, tnamelen;
count1 = 0;
de = dirp;
if (!(target_dirp = lock_user(VERIFY_WRITE, arg2, count, 0)))
goto efault;
tde = target_dirp;
while (len > 0) {
reclen = de->d_reclen;
tnamelen = reclen - offsetof(struct linux_dirent, d_name);
assert(tnamelen >= 0);
treclen = tnamelen + offsetof(struct target_dirent, d_name);
assert(count1 + treclen <= count);
tde->d_reclen = tswap16(treclen);
tde->d_ino = tswapal(de->d_ino);
tde->d_off = tswapal(de->d_off);
memcpy(tde->d_name, de->d_name, tnamelen);
de = (struct linux_dirent *)((char *)de + reclen);
len -= reclen;
tde = (struct target_dirent *)((char *)tde + treclen);
count1 += treclen;
ret = count1;
unlock_user(target_dirp, arg2, ret);
g_free(dirp);
#else
{
struct linux_dirent *dirp;
abi_long count = arg3;
if (!(dirp = lock_user(VERIFY_WRITE, arg2, count, 0)))
goto efault;
ret = get_errno(sys_getdents(arg1, dirp, count));
if (!is_error(ret)) {
struct linux_dirent *de;
int len = ret;
int reclen;
de = dirp;
while (len > 0) {
reclen = de->d_reclen;
if (reclen > len)
de->d_reclen = tswap16(reclen);
tswapls(&de->d_ino);
tswapls(&de->d_off);
de = (struct linux_dirent *)((char *)de + reclen);
len -= reclen;
unlock_user(dirp, arg2, ret);
#endif
#else
{
struct linux_dirent64 *dirp;
abi_long count = arg3;
dirp = lock_user(VERIFY_WRITE, arg2, count, 0);
if (!dirp) {
goto efault;
ret = get_errno(sys_getdents64(arg1, dirp, count));
if (!is_error(ret)) {
struct linux_dirent64 *de;
struct target_dirent *tde;
int len = ret;
int tlen = 0;
de = dirp;
tde = (struct target_dirent *)dirp;
while (len > 0) {
int namelen, treclen;
int reclen = de->d_reclen;
uint64_t ino = de->d_ino;
int64_t off = de->d_off;
uint8_t type = de->d_type;
namelen = strlen(de->d_name);
treclen = offsetof(struct target_dirent, d_name)
+ namelen + 2;
treclen = QEMU_ALIGN_UP(treclen, sizeof(abi_long));
memmove(tde->d_name, de->d_name, namelen + 1);
tde->d_ino = tswapal(ino);
tde->d_off = tswapal(off);
tde->d_reclen = tswap16(treclen);
*(((char *)tde) + treclen - 1) = type;
de = (struct linux_dirent64 *)((char *)de + reclen);
tde = (struct target_dirent *)((char *)tde + treclen);
len -= reclen;
tlen += treclen;
ret = tlen;
unlock_user(dirp, arg2, ret);
#endif
#endif
#if defined(TARGET_NR_getdents64) && defined(__NR_getdents64)
case TARGET_NR_getdents64:
{
struct linux_dirent64 *dirp;
abi_long count = arg3;
if (!(dirp = lock_user(VERIFY_WRITE, arg2, count, 0)))
goto efault;
ret = get_errno(sys_getdents64(arg1, dirp, count));
if (!is_error(ret)) {
struct linux_dirent64 *de;
int len = ret;
int reclen;
de = dirp;
while (len > 0) {
reclen = de->d_reclen;
if (reclen > len)
de->d_reclen = tswap16(reclen);
tswap64s((uint64_t *)&de->d_ino);
tswap64s((uint64_t *)&de->d_off);
de = (struct linux_dirent64 *)((char *)de + reclen);
len -= reclen;
unlock_user(dirp, arg2, ret);
#endif
#if defined(TARGET_NR__newselect)
case TARGET_NR__newselect:
ret = do_select(arg1, arg2, arg3, arg4, arg5);
#endif
#if defined(TARGET_NR_poll) || defined(TARGET_NR_ppoll)
# ifdef TARGET_NR_poll
case TARGET_NR_poll:
# endif
# ifdef TARGET_NR_ppoll
case TARGET_NR_ppoll:
# endif
{
struct target_pollfd *target_pfd;
unsigned int nfds = arg2;
struct pollfd *pfd;
unsigned int i;
pfd = NULL;
target_pfd = NULL;
if (nfds) {
target_pfd = lock_user(VERIFY_WRITE, arg1,
sizeof(struct target_pollfd) * nfds, 1);
if (!target_pfd) {
goto efault;
pfd = alloca(sizeof(struct pollfd) * nfds);
for (i = 0; i < nfds; i++) {
pfd[i].fd = tswap32(target_pfd[i].fd);
pfd[i].events = tswap16(target_pfd[i].events);
switch (num) {
# ifdef TARGET_NR_ppoll
case TARGET_NR_ppoll:
{
struct timespec _timeout_ts, *timeout_ts = &_timeout_ts;
target_sigset_t *target_set;
sigset_t _set, *set = &_set;
if (arg3) {
if (target_to_host_timespec(timeout_ts, arg3)) {
unlock_user(target_pfd, arg1, 0);
goto efault;
} else {
timeout_ts = NULL;
if (arg4) {
if (arg5 != sizeof(target_sigset_t)) {
unlock_user(target_pfd, arg1, 0);
target_set = lock_user(VERIFY_READ, arg4, sizeof(target_sigset_t), 1);
if (!target_set) {
unlock_user(target_pfd, arg1, 0);
goto efault;
target_to_host_sigset(set, target_set);
} else {
set = NULL;
ret = get_errno(safe_ppoll(pfd, nfds, timeout_ts,
set, SIGSET_T_SIZE));
if (!is_error(ret) && arg3) {
host_to_target_timespec(arg3, timeout_ts);
if (arg4) {
unlock_user(target_set, arg4, 0);
# endif
# ifdef TARGET_NR_poll
case TARGET_NR_poll:
{
struct timespec ts, *pts;
if (arg3 >= 0) {
ts.tv_sec = arg3 / 1000;
ts.tv_nsec = (arg3 % 1000) * 1000000LL;
pts = &ts;
} else {
pts = NULL;
ret = get_errno(safe_ppoll(pfd, nfds, pts, NULL, 0));
# endif
default:
g_assert_not_reached();
if (!is_error(ret)) {
for(i = 0; i < nfds; i++) {
target_pfd[i].revents = tswap16(pfd[i].revents);
unlock_user(target_pfd, arg1, sizeof(struct target_pollfd) * nfds);
#endif
case TARGET_NR_flock:
ret = get_errno(safe_flock(arg1, arg2));
case TARGET_NR_readv:
{
struct iovec *vec = lock_iovec(VERIFY_WRITE, arg2, arg3, 0);
if (vec != NULL) {
ret = get_errno(safe_readv(arg1, vec, arg3));
unlock_iovec(vec, arg2, arg3, 1);
} else {
ret = -host_to_target_errno(errno);
case TARGET_NR_writev:
{
struct iovec *vec = lock_iovec(VERIFY_READ, arg2, arg3, 1);
if (vec != NULL) {
ret = get_errno(safe_writev(arg1, vec, arg3));
unlock_iovec(vec, arg2, arg3, 0);
} else {
ret = -host_to_target_errno(errno);
case TARGET_NR_getsid:
ret = get_errno(getsid(arg1));
#if defined(TARGET_NR_fdatasync)
case TARGET_NR_fdatasync:
ret = get_errno(fdatasync(arg1));
#endif
#ifdef TARGET_NR__sysctl
case TARGET_NR__sysctl:
ret = -TARGET_ENOTDIR;
#endif
case TARGET_NR_sched_getaffinity:
{
unsigned int mask_size;
unsigned long *mask;
if (arg2 & (sizeof(abi_ulong) - 1)) {
mask_size = (arg2 + (sizeof(*mask) - 1)) & ~(sizeof(*mask) - 1);
mask = alloca(mask_size);
ret = get_errno(sys_sched_getaffinity(arg1, mask_size, mask));
if (!is_error(ret)) {
if (ret > arg2) {
int numcpus = sysconf(_SC_NPROCESSORS_CONF);
if (numcpus > arg2 * 8) {
ret = arg2;
if (copy_to_user(arg3, mask, ret)) {
goto efault;
case TARGET_NR_sched_setaffinity:
{
unsigned int mask_size;
unsigned long *mask;
if (arg2 & (sizeof(abi_ulong) - 1)) {
mask_size = (arg2 + (sizeof(*mask) - 1)) & ~(sizeof(*mask) - 1);
mask = alloca(mask_size);
if (!lock_user_struct(VERIFY_READ, p, arg3, 1)) {
goto efault;
memcpy(mask, p, arg2);
unlock_user_struct(p, arg2, 0);
ret = get_errno(sys_sched_setaffinity(arg1, mask_size, mask));
case TARGET_NR_sched_setparam:
{
struct sched_param *target_schp;
struct sched_param schp;
if (arg2 == 0) {
return -TARGET_EINVAL;
if (!lock_user_struct(VERIFY_READ, target_schp, arg2, 1))
goto efault;
schp.sched_priority = tswap32(target_schp->sched_priority);
unlock_user_struct(target_schp, arg2, 0);
ret = get_errno(sched_setparam(arg1, &schp));
case TARGET_NR_sched_getparam:
{
struct sched_param *target_schp;
struct sched_param schp;
if (arg2 == 0) {
return -TARGET_EINVAL;
ret = get_errno(sched_getparam(arg1, &schp));
if (!is_error(ret)) {
if (!lock_user_struct(VERIFY_WRITE, target_schp, arg2, 0))
goto efault;
target_schp->sched_priority = tswap32(schp.sched_priority);
unlock_user_struct(target_schp, arg2, 1);
case TARGET_NR_sched_setscheduler:
{
struct sched_param *target_schp;
struct sched_param schp;
if (arg3 == 0) {
return -TARGET_EINVAL;
if (!lock_user_struct(VERIFY_READ, target_schp, arg3, 1))
goto efault;
schp.sched_priority = tswap32(target_schp->sched_priority);
unlock_user_struct(target_schp, arg3, 0);
ret = get_errno(sched_setscheduler(arg1, arg2, &schp));
case TARGET_NR_sched_getscheduler:
ret = get_errno(sched_getscheduler(arg1));
case TARGET_NR_sched_yield:
ret = get_errno(sched_yield());
case TARGET_NR_sched_get_priority_max:
ret = get_errno(sched_get_priority_max(arg1));
case TARGET_NR_sched_get_priority_min:
ret = get_errno(sched_get_priority_min(arg1));
case TARGET_NR_sched_rr_get_interval:
{
struct timespec ts;
ret = get_errno(sched_rr_get_interval(arg1, &ts));
if (!is_error(ret)) {
ret = host_to_target_timespec(arg2, &ts);
case TARGET_NR_nanosleep:
{
struct timespec req, rem;
target_to_host_timespec(&req, arg1);
ret = get_errno(safe_nanosleep(&req, &rem));
if (is_error(ret) && arg2) {
host_to_target_timespec(arg2, &rem);
#ifdef TARGET_NR_query_module
case TARGET_NR_query_module:
goto unimplemented;
#endif
#ifdef TARGET_NR_nfsservctl
case TARGET_NR_nfsservctl:
goto unimplemented;
#endif
case TARGET_NR_prctl:
switch (arg1) {
case PR_GET_PDEATHSIG:
{
int deathsig;
ret = get_errno(prctl(arg1, &deathsig, arg3, arg4, arg5));
if (!is_error(ret) && arg2
&& put_user_ual(deathsig, arg2)) {
goto efault;
#ifdef PR_GET_NAME
case PR_GET_NAME:
{
void *name = lock_user(VERIFY_WRITE, arg2, 16, 1);
if (!name) {
goto efault;
ret = get_errno(prctl(arg1, (unsigned long)name,
arg3, arg4, arg5));
unlock_user(name, arg2, 16);
case PR_SET_NAME:
{
void *name = lock_user(VERIFY_READ, arg2, 16, 1);
if (!name) {
goto efault;
ret = get_errno(prctl(arg1, (unsigned long)name,
arg3, arg4, arg5));
unlock_user(name, arg2, 0);
#endif
default:
ret = get_errno(prctl(arg1, arg2, arg3, arg4, arg5));
#ifdef TARGET_NR_arch_prctl
case TARGET_NR_arch_prctl:
#if defined(TARGET_I386) && !defined(TARGET_ABI32)
ret = do_arch_prctl(cpu_env, arg1, arg2);
#else
goto unimplemented;
#endif
#endif
#ifdef TARGET_NR_pread64
case TARGET_NR_pread64:
if (regpairs_aligned(cpu_env)) {
arg4 = arg5;
arg5 = arg6;
if (!(p = lock_user(VERIFY_WRITE, arg2, arg3, 0)))
goto efault;
ret = get_errno(pread64(arg1, p, arg3, target_offset64(arg4, arg5)));
unlock_user(p, arg2, ret);
case TARGET_NR_pwrite64:
if (regpairs_aligned(cpu_env)) {
arg4 = arg5;
arg5 = arg6;
if (!(p = lock_user(VERIFY_READ, arg2, arg3, 1)))
goto efault;
ret = get_errno(pwrite64(arg1, p, arg3, target_offset64(arg4, arg5)));
unlock_user(p, arg2, 0);
#endif
case TARGET_NR_getcwd:
if (!(p = lock_user(VERIFY_WRITE, arg1, arg2, 0)))
goto efault;
ret = get_errno(sys_getcwd1(p, arg2));
unlock_user(p, arg1, ret);
case TARGET_NR_capget:
case TARGET_NR_capset:
{
struct target_user_cap_header *target_header;
struct target_user_cap_data *target_data = NULL;
struct __user_cap_header_struct header;
struct __user_cap_data_struct data[2];
struct __user_cap_data_struct *dataptr = NULL;
int i, target_datalen;
int data_items = 1;
if (!lock_user_struct(VERIFY_WRITE, target_header, arg1, 1)) {
goto efault;
header.version = tswap32(target_header->version);
header.pid = tswap32(target_header->pid);
if (header.version != _LINUX_CAPABILITY_VERSION) {
data_items = 2;
target_datalen = sizeof(*target_data) * data_items;
if (arg2) {
if (num == TARGET_NR_capget) {
target_data = lock_user(VERIFY_WRITE, arg2, target_datalen, 0);
} else {
target_data = lock_user(VERIFY_READ, arg2, target_datalen, 1);
if (!target_data) {
unlock_user_struct(target_header, arg1, 0);
goto efault;
if (num == TARGET_NR_capset) {
for (i = 0; i < data_items; i++) {
data[i].effective = tswap32(target_data[i].effective);
data[i].permitted = tswap32(target_data[i].permitted);
data[i].inheritable = tswap32(target_data[i].inheritable);
dataptr = data;
if (num == TARGET_NR_capget) {
ret = get_errno(capget(&header, dataptr));
} else {
ret = get_errno(capset(&header, dataptr));
target_header->version = tswap32(header.version);
unlock_user_struct(target_header, arg1, 1);
if (arg2) {
if (num == TARGET_NR_capget) {
for (i = 0; i < data_items; i++) {
target_data[i].effective = tswap32(data[i].effective);
target_data[i].permitted = tswap32(data[i].permitted);
target_data[i].inheritable = tswap32(data[i].inheritable);
unlock_user(target_data, arg2, target_datalen);
} else {
unlock_user(target_data, arg2, 0);
case TARGET_NR_sigaltstack:
ret = do_sigaltstack(arg1, arg2, get_sp_from_cpustate((CPUArchState *)cpu_env));
#ifdef CONFIG_SENDFILE
case TARGET_NR_sendfile:
{
off_t *offp = NULL;
off_t off;
if (arg3) {
ret = get_user_sal(off, arg3);
if (is_error(ret)) {
offp = &off;
ret = get_errno(sendfile(arg1, arg2, offp, arg4));
if (!is_error(ret) && arg3) {
abi_long ret2 = put_user_sal(off, arg3);
if (is_error(ret2)) {
ret = ret2;
#ifdef TARGET_NR_sendfile64
case TARGET_NR_sendfile64:
{
off_t *offp = NULL;
off_t off;
if (arg3) {
ret = get_user_s64(off, arg3);
if (is_error(ret)) {
offp = &off;
ret = get_errno(sendfile(arg1, arg2, offp, arg4));
if (!is_error(ret) && arg3) {
abi_long ret2 = put_user_s64(off, arg3);
if (is_error(ret2)) {
ret = ret2;
#endif
#else
case TARGET_NR_sendfile:
#ifdef TARGET_NR_sendfile64
case TARGET_NR_sendfile64:
#endif
goto unimplemented;
#endif
#ifdef TARGET_NR_getpmsg
case TARGET_NR_getpmsg:
goto unimplemented;
#endif
#ifdef TARGET_NR_putpmsg
case TARGET_NR_putpmsg:
goto unimplemented;
#endif
#ifdef TARGET_NR_vfork
case TARGET_NR_vfork:
ret = get_errno(do_fork(cpu_env, CLONE_VFORK | CLONE_VM | SIGCHLD,
0, 0, 0, 0));
#endif
#ifdef TARGET_NR_ugetrlimit
case TARGET_NR_ugetrlimit:
{
struct rlimit rlim;
int resource = target_to_host_resource(arg1);
ret = get_errno(getrlimit(resource, &rlim));
if (!is_error(ret)) {
struct target_rlimit *target_rlim;
if (!lock_user_struct(VERIFY_WRITE, target_rlim, arg2, 0))
goto efault;
target_rlim->rlim_cur = host_to_target_rlim(rlim.rlim_cur);
target_rlim->rlim_max = host_to_target_rlim(rlim.rlim_max);
unlock_user_struct(target_rlim, arg2, 1);
#endif
#ifdef TARGET_NR_truncate64
case TARGET_NR_truncate64:
if (!(p = lock_user_string(arg1)))
goto efault;
ret = target_truncate64(cpu_env, p, arg2, arg3, arg4);
unlock_user(p, arg1, 0);
#endif
#ifdef TARGET_NR_ftruncate64
case TARGET_NR_ftruncate64:
ret = target_ftruncate64(cpu_env, arg1, arg2, arg3, arg4);
#endif
#ifdef TARGET_NR_stat64
case TARGET_NR_stat64:
if (!(p = lock_user_string(arg1)))
goto efault;
ret = get_errno(stat(path(p), &st));
unlock_user(p, arg1, 0);
if (!is_error(ret))
ret = host_to_target_stat64(cpu_env, arg2, &st);
#endif
#ifdef TARGET_NR_lstat64
case TARGET_NR_lstat64:
if (!(p = lock_user_string(arg1)))
goto efault;
ret = get_errno(lstat(path(p), &st));
unlock_user(p, arg1, 0);
if (!is_error(ret))
ret = host_to_target_stat64(cpu_env, arg2, &st);
#endif
#ifdef TARGET_NR_fstat64
case TARGET_NR_fstat64:
ret = get_errno(fstat(arg1, &st));
if (!is_error(ret))
ret = host_to_target_stat64(cpu_env, arg2, &st);
#endif
#if (defined(TARGET_NR_fstatat64) || defined(TARGET_NR_newfstatat))
#ifdef TARGET_NR_fstatat64
case TARGET_NR_fstatat64:
#endif
#ifdef TARGET_NR_newfstatat
case TARGET_NR_newfstatat:
#endif
if (!(p = lock_user_string(arg2)))
goto efault;
ret = get_errno(fstatat(arg1, path(p), &st, arg4));
if (!is_error(ret))
ret = host_to_target_stat64(cpu_env, arg3, &st);
#endif
#ifdef TARGET_NR_lchown
case TARGET_NR_lchown:
if (!(p = lock_user_string(arg1)))
goto efault;
ret = get_errno(lchown(p, low2highuid(arg2), low2highgid(arg3)));
unlock_user(p, arg1, 0);
#endif
#ifdef TARGET_NR_getuid
case TARGET_NR_getuid:
ret = get_errno(high2lowuid(getuid()));
#endif
#ifdef TARGET_NR_getgid
case TARGET_NR_getgid:
ret = get_errno(high2lowgid(getgid()));
#endif
#ifdef TARGET_NR_geteuid
case TARGET_NR_geteuid:
ret = get_errno(high2lowuid(geteuid()));
#endif
#ifdef TARGET_NR_getegid
case TARGET_NR_getegid:
ret = get_errno(high2lowgid(getegid()));
#endif
case TARGET_NR_setreuid:
ret = get_errno(setreuid(low2highuid(arg1), low2highuid(arg2)));
case TARGET_NR_setregid:
ret = get_errno(setregid(low2highgid(arg1), low2highgid(arg2)));
case TARGET_NR_getgroups:
{
int gidsetsize = arg1;
target_id *target_grouplist;
gid_t *grouplist;
int i;
grouplist = alloca(gidsetsize * sizeof(gid_t));
ret = get_errno(getgroups(gidsetsize, grouplist));
if (gidsetsize == 0)
if (!is_error(ret)) {
target_grouplist = lock_user(VERIFY_WRITE, arg2, gidsetsize * sizeof(target_id), 0);
if (!target_grouplist)
goto efault;
for(i = 0;i < ret; i++)
target_grouplist[i] = tswapid(high2lowgid(grouplist[i]));
unlock_user(target_grouplist, arg2, gidsetsize * sizeof(target_id));
case TARGET_NR_setgroups:
{
int gidsetsize = arg1;
target_id *target_grouplist;
gid_t *grouplist = NULL;
int i;
if (gidsetsize) {
grouplist = alloca(gidsetsize * sizeof(gid_t));
target_grouplist = lock_user(VERIFY_READ, arg2, gidsetsize * sizeof(target_id), 1);
if (!target_grouplist) {
ret = -TARGET_EFAULT;
goto fail;
for (i = 0; i < gidsetsize; i++) {
grouplist[i] = low2highgid(tswapid(target_grouplist[i]));
unlock_user(target_grouplist, arg2, 0);
ret = get_errno(setgroups(gidsetsize, grouplist));
case TARGET_NR_fchown:
ret = get_errno(fchown(arg1, low2highuid(arg2), low2highgid(arg3)));
#if defined(TARGET_NR_fchownat)
case TARGET_NR_fchownat:
if (!(p = lock_user_string(arg2)))
goto efault;
ret = get_errno(fchownat(arg1, p, low2highuid(arg3),
low2highgid(arg4), arg5));
unlock_user(p, arg2, 0);
#endif
#ifdef TARGET_NR_setresuid
case TARGET_NR_setresuid:
ret = get_errno(sys_setresuid(low2highuid(arg1),
low2highuid(arg2),
low2highuid(arg3)));
#endif
#ifdef TARGET_NR_getresuid
case TARGET_NR_getresuid:
{
uid_t ruid, euid, suid;
ret = get_errno(getresuid(&ruid, &euid, &suid));
if (!is_error(ret)) {
if (put_user_id(high2lowuid(ruid), arg1)
|| put_user_id(high2lowuid(euid), arg2)
|| put_user_id(high2lowuid(suid), arg3))
goto efault;
#endif
#ifdef TARGET_NR_getresgid
case TARGET_NR_setresgid:
ret = get_errno(sys_setresgid(low2highgid(arg1),
low2highgid(arg2),
low2highgid(arg3)));
#endif
#ifdef TARGET_NR_getresgid
case TARGET_NR_getresgid:
{
gid_t rgid, egid, sgid;
ret = get_errno(getresgid(&rgid, &egid, &sgid));
if (!is_error(ret)) {
if (put_user_id(high2lowgid(rgid), arg1)
|| put_user_id(high2lowgid(egid), arg2)
|| put_user_id(high2lowgid(sgid), arg3))
goto efault;
#endif
#ifdef TARGET_NR_chown
case TARGET_NR_chown:
if (!(p = lock_user_string(arg1)))
goto efault;
ret = get_errno(chown(p, low2highuid(arg2), low2highgid(arg3)));
unlock_user(p, arg1, 0);
#endif
case TARGET_NR_setuid:
ret = get_errno(sys_setuid(low2highuid(arg1)));
case TARGET_NR_setgid:
ret = get_errno(sys_setgid(low2highgid(arg1)));
case TARGET_NR_setfsuid:
ret = get_errno(setfsuid(arg1));
case TARGET_NR_setfsgid:
ret = get_errno(setfsgid(arg1));
#ifdef TARGET_NR_lchown32
case TARGET_NR_lchown32:
if (!(p = lock_user_string(arg1)))
goto efault;
ret = get_errno(lchown(p, arg2, arg3));
unlock_user(p, arg1, 0);
#endif
#ifdef TARGET_NR_getuid32
case TARGET_NR_getuid32:
ret = get_errno(getuid());
#endif
#if defined(TARGET_NR_getxuid) && defined(TARGET_ALPHA)
case TARGET_NR_getxuid:
{
uid_t euid;
euid=geteuid();
((CPUAlphaState *)cpu_env)->ir[IR_A4]=euid;
ret = get_errno(getuid());
#endif
#if defined(TARGET_NR_getxgid) && defined(TARGET_ALPHA)
case TARGET_NR_getxgid:
{
uid_t egid;
egid=getegid();
((CPUAlphaState *)cpu_env)->ir[IR_A4]=egid;
ret = get_errno(getgid());
#endif
#if defined(TARGET_NR_osf_getsysinfo) && defined(TARGET_ALPHA)
case TARGET_NR_osf_getsysinfo:
ret = -TARGET_EOPNOTSUPP;
switch (arg1) {
case TARGET_GSI_IEEE_FP_CONTROL:
{
uint64_t swcr, fpcr = cpu_alpha_load_fpcr (cpu_env);
swcr = (fpcr >> 35) & SWCR_STATUS_MASK;
swcr |= (fpcr >> 36) & SWCR_MAP_DMZ;
swcr |= (~fpcr >> 48) & (SWCR_TRAP_ENABLE_INV
| SWCR_TRAP_ENABLE_DZE
| SWCR_TRAP_ENABLE_OVF);
swcr |= (~fpcr >> 57) & (SWCR_TRAP_ENABLE_UNF
| SWCR_TRAP_ENABLE_INE);
swcr |= (fpcr >> 47) & SWCR_MAP_UMZ;
swcr |= (~fpcr >> 41) & SWCR_TRAP_ENABLE_DNO;
if (put_user_u64 (swcr, arg2))
goto efault;
ret = 0;
#endif
#if defined(TARGET_NR_osf_setsysinfo) && defined(TARGET_ALPHA)
case TARGET_NR_osf_setsysinfo:
ret = -TARGET_EOPNOTSUPP;
switch (arg1) {
case TARGET_SSI_IEEE_FP_CONTROL:
{
uint64_t swcr, fpcr, orig_fpcr;
if (get_user_u64 (swcr, arg2)) {
goto efault;
orig_fpcr = cpu_alpha_load_fpcr(cpu_env);
fpcr = orig_fpcr & FPCR_DYN_MASK;
fpcr |= (swcr & SWCR_STATUS_MASK) << 35;
fpcr |= (swcr & SWCR_MAP_DMZ) << 36;
fpcr |= (~swcr & (SWCR_TRAP_ENABLE_INV
| SWCR_TRAP_ENABLE_DZE
| SWCR_TRAP_ENABLE_OVF)) << 48;
fpcr |= (~swcr & (SWCR_TRAP_ENABLE_UNF
| SWCR_TRAP_ENABLE_INE)) << 57;
fpcr |= (swcr & SWCR_MAP_UMZ ? FPCR_UNDZ | FPCR_UNFD : 0);
fpcr |= (~swcr & SWCR_TRAP_ENABLE_DNO) << 41;
cpu_alpha_store_fpcr(cpu_env, fpcr);
ret = 0;
case TARGET_SSI_IEEE_RAISE_EXCEPTION:
{
uint64_t exc, fpcr, orig_fpcr;
int si_code;
if (get_user_u64(exc, arg2)) {
goto efault;
orig_fpcr = cpu_alpha_load_fpcr(cpu_env);
fpcr = orig_fpcr | ((exc & SWCR_STATUS_MASK) << 35);
cpu_alpha_store_fpcr(cpu_env, fpcr);
ret = 0;
fpcr &= ~(orig_fpcr & FPCR_STATUS_MASK);
si_code = 0;
if ((fpcr & (FPCR_INE | FPCR_INED)) == FPCR_INE) {
si_code = TARGET_FPE_FLTRES;
if ((fpcr & (FPCR_UNF | FPCR_UNFD)) == FPCR_UNF) {
si_code = TARGET_FPE_FLTUND;
if ((fpcr & (FPCR_OVF | FPCR_OVFD)) == FPCR_OVF) {
si_code = TARGET_FPE_FLTOVF;
if ((fpcr & (FPCR_DZE | FPCR_DZED)) == FPCR_DZE) {
si_code = TARGET_FPE_FLTDIV;
if ((fpcr & (FPCR_INV | FPCR_INVD)) == FPCR_INV) {
si_code = TARGET_FPE_FLTINV;
if (si_code != 0) {
target_siginfo_t info;
info.si_signo = SIGFPE;
info.si_errno = 0;
info.si_code = si_code;
info._sifields._sigfault._addr
= ((CPUArchState *)cpu_env)->pc;
queue_signal((CPUArchState *)cpu_env, info.si_signo, &info);
#endif
#ifdef TARGET_NR_osf_sigprocmask
case TARGET_NR_osf_sigprocmask:
{
abi_ulong mask;
int how;
sigset_t set, oldset;
switch(arg1) {
case TARGET_SIG_BLOCK:
how = SIG_BLOCK;
case TARGET_SIG_UNBLOCK:
how = SIG_UNBLOCK;
case TARGET_SIG_SETMASK:
how = SIG_SETMASK;
default:
goto fail;
mask = arg2;
target_to_host_old_sigset(&set, &mask);
ret = do_sigprocmask(how, &set, &oldset);
if (!ret) {
host_to_target_old_sigset(&mask, &oldset);
ret = mask;
#endif
#ifdef TARGET_NR_getgid32
case TARGET_NR_getgid32:
ret = get_errno(getgid());
#endif
#ifdef TARGET_NR_geteuid32
case TARGET_NR_geteuid32:
ret = get_errno(geteuid());
#endif
#ifdef TARGET_NR_getegid32
case TARGET_NR_getegid32:
ret = get_errno(getegid());
#endif
#ifdef TARGET_NR_setreuid32
case TARGET_NR_setreuid32:
ret = get_errno(setreuid(arg1, arg2));
#endif
#ifdef TARGET_NR_setregid32
case TARGET_NR_setregid32:
ret = get_errno(setregid(arg1, arg2));
#endif
#ifdef TARGET_NR_getgroups32
case TARGET_NR_getgroups32:
{
int gidsetsize = arg1;
uint32_t *target_grouplist;
gid_t *grouplist;
int i;
grouplist = alloca(gidsetsize * sizeof(gid_t));
ret = get_errno(getgroups(gidsetsize, grouplist));
if (gidsetsize == 0)
if (!is_error(ret)) {
target_grouplist = lock_user(VERIFY_WRITE, arg2, gidsetsize * 4, 0);
if (!target_grouplist) {
ret = -TARGET_EFAULT;
goto fail;
for(i = 0;i < ret; i++)
target_grouplist[i] = tswap32(grouplist[i]);
unlock_user(target_grouplist, arg2, gidsetsize * 4);
#endif
#ifdef TARGET_NR_setgroups32
case TARGET_NR_setgroups32:
{
int gidsetsize = arg1;
uint32_t *target_grouplist;
gid_t *grouplist;
int i;
grouplist = alloca(gidsetsize * sizeof(gid_t));
target_grouplist = lock_user(VERIFY_READ, arg2, gidsetsize * 4, 1);
if (!target_grouplist) {
ret = -TARGET_EFAULT;
goto fail;
for(i = 0;i < gidsetsize; i++)
grouplist[i] = tswap32(target_grouplist[i]);
unlock_user(target_grouplist, arg2, 0);
ret = get_errno(setgroups(gidsetsize, grouplist));
#endif
#ifdef TARGET_NR_fchown32
case TARGET_NR_fchown32:
ret = get_errno(fchown(arg1, arg2, arg3));
#endif
#ifdef TARGET_NR_setresuid32
case TARGET_NR_setresuid32:
ret = get_errno(sys_setresuid(arg1, arg2, arg3));
#endif
#ifdef TARGET_NR_getresuid32
case TARGET_NR_getresuid32:
{
uid_t ruid, euid, suid;
ret = get_errno(getresuid(&ruid, &euid, &suid));
if (!is_error(ret)) {
if (put_user_u32(ruid, arg1)
|| put_user_u32(euid, arg2)
|| put_user_u32(suid, arg3))
goto efault;
#endif
#ifdef TARGET_NR_setresgid32
case TARGET_NR_setresgid32:
ret = get_errno(sys_setresgid(arg1, arg2, arg3));
#endif
#ifdef TARGET_NR_getresgid32
case TARGET_NR_getresgid32:
{
gid_t rgid, egid, sgid;
ret = get_errno(getresgid(&rgid, &egid, &sgid));
if (!is_error(ret)) {
if (put_user_u32(rgid, arg1)
|| put_user_u32(egid, arg2)
|| put_user_u32(sgid, arg3))
goto efault;
#endif
#ifdef TARGET_NR_chown32
case TARGET_NR_chown32:
if (!(p = lock_user_string(arg1)))
goto efault;
ret = get_errno(chown(p, arg2, arg3));
unlock_user(p, arg1, 0);
#endif
#ifdef TARGET_NR_setuid32
case TARGET_NR_setuid32:
ret = get_errno(sys_setuid(arg1));
#endif
#ifdef TARGET_NR_setgid32
case TARGET_NR_setgid32:
ret = get_errno(sys_setgid(arg1));
#endif
#ifdef TARGET_NR_setfsuid32
case TARGET_NR_setfsuid32:
ret = get_errno(setfsuid(arg1));
#endif
#ifdef TARGET_NR_setfsgid32
case TARGET_NR_setfsgid32:
ret = get_errno(setfsgid(arg1));
#endif
case TARGET_NR_pivot_root:
goto unimplemented;
#ifdef TARGET_NR_mincore
case TARGET_NR_mincore:
{
void *a;
ret = -TARGET_EFAULT;
if (!(a = lock_user(VERIFY_READ, arg1,arg2, 0)))
goto efault;
if (!(p = lock_user_string(arg3)))
goto mincore_fail;
ret = get_errno(mincore(a, arg2, p));
unlock_user(p, arg3, ret);
mincore_fail:
unlock_user(a, arg1, 0);
#endif
#ifdef TARGET_NR_arm_fadvise64_64
case TARGET_NR_arm_fadvise64_64:
ret = posix_fadvise(arg1, target_offset64(arg3, arg4),
target_offset64(arg5, arg6), arg2);
ret = -host_to_target_errno(ret);
#endif
#if TARGET_ABI_BITS == 32
#ifdef TARGET_NR_fadvise64_64
case TARGET_NR_fadvise64_64:
if (regpairs_aligned(cpu_env)) {
arg2 = arg3;
arg3 = arg4;
arg4 = arg5;
arg5 = arg6;
arg6 = arg7;
ret = -host_to_target_errno(posix_fadvise(arg1,
target_offset64(arg2, arg3),
target_offset64(arg4, arg5),
arg6));
#endif
#ifdef TARGET_NR_fadvise64
case TARGET_NR_fadvise64:
if (regpairs_aligned(cpu_env)) {
arg2 = arg3;
arg3 = arg4;
arg4 = arg5;
arg5 = arg6;
ret = -host_to_target_errno(posix_fadvise(arg1,
target_offset64(arg2, arg3),
arg4, arg5));
#endif
#else
#if defined(TARGET_NR_fadvise64_64) || defined(TARGET_NR_fadvise64)
#ifdef TARGET_NR_fadvise64_64
case TARGET_NR_fadvise64_64:
#endif
#ifdef TARGET_NR_fadvise64
case TARGET_NR_fadvise64:
#endif
#ifdef TARGET_S390X
switch (arg4) {
case 4: arg4 = POSIX_FADV_NOREUSE + 1; break;
case 5: arg4 = POSIX_FADV_NOREUSE + 2; break;
case 6: arg4 = POSIX_FADV_DONTNEED; break;
case 7: arg4 = POSIX_FADV_NOREUSE; break;
default: break;
#endif
ret = -host_to_target_errno(posix_fadvise(arg1, arg2, arg3, arg4));
#endif
#endif
#ifdef TARGET_NR_madvise
case TARGET_NR_madvise:
ret = get_errno(0);
#endif
#if TARGET_ABI_BITS == 32
case TARGET_NR_fcntl64:
{
int cmd;
struct flock64 fl;
from_flock64_fn *copyfrom = copy_from_user_flock64;
to_flock64_fn *copyto = copy_to_user_flock64;
#ifdef TARGET_ARM
if (((CPUARMState *)cpu_env)->eabi) {
copyfrom = copy_from_user_eabi_flock64;
copyto = copy_to_user_eabi_flock64;
#endif
cmd = target_to_host_fcntl_cmd(arg2);
if (cmd == -TARGET_EINVAL) {
ret = cmd;
switch(arg2) {
case TARGET_F_GETLK64:
ret = copyfrom(&fl, arg3);
if (ret) {
ret = get_errno(fcntl(arg1, cmd, &fl));
if (ret == 0) {
ret = copyto(arg3, &fl);
case TARGET_F_SETLK64:
case TARGET_F_SETLKW64:
ret = copyfrom(&fl, arg3);
if (ret) {
ret = get_errno(safe_fcntl(arg1, cmd, &fl));
default:
ret = do_fcntl(arg1, arg2, arg3);
#endif
#ifdef TARGET_NR_cacheflush
case TARGET_NR_cacheflush:
ret = 0;
#endif
#ifdef TARGET_NR_security
case TARGET_NR_security:
goto unimplemented;
#endif
#ifdef TARGET_NR_getpagesize
case TARGET_NR_getpagesize:
ret = TARGET_PAGE_SIZE;
#endif
case TARGET_NR_gettid:
ret = get_errno(gettid());
#ifdef TARGET_NR_readahead
case TARGET_NR_readahead:
#if TARGET_ABI_BITS == 32
if (regpairs_aligned(cpu_env)) {
arg2 = arg3;
arg3 = arg4;
arg4 = arg5;
ret = get_errno(readahead(arg1, ((off64_t)arg3 << 32) | arg2, arg4));
#else
ret = get_errno(readahead(arg1, arg2, arg3));
#endif
#endif
#ifdef CONFIG_ATTR
#ifdef TARGET_NR_setxattr
case TARGET_NR_listxattr:
case TARGET_NR_llistxattr:
{
void *p, *b = 0;
if (arg2) {
b = lock_user(VERIFY_WRITE, arg2, arg3, 0);
if (!b) {
ret = -TARGET_EFAULT;
p = lock_user_string(arg1);
if (p) {
if (num == TARGET_NR_listxattr) {
ret = get_errno(listxattr(p, b, arg3));
} else {
ret = get_errno(llistxattr(p, b, arg3));
} else {
ret = -TARGET_EFAULT;
unlock_user(p, arg1, 0);
unlock_user(b, arg2, arg3);
case TARGET_NR_flistxattr:
{
void *b = 0;
if (arg2) {
b = lock_user(VERIFY_WRITE, arg2, arg3, 0);
if (!b) {
ret = -TARGET_EFAULT;
ret = get_errno(flistxattr(arg1, b, arg3));
unlock_user(b, arg2, arg3);
case TARGET_NR_setxattr:
case TARGET_NR_lsetxattr:
{
void *p, *n, *v = 0;
if (arg3) {
v = lock_user(VERIFY_READ, arg3, arg4, 1);
if (!v) {
ret = -TARGET_EFAULT;
p = lock_user_string(arg1);
n = lock_user_string(arg2);
if (p && n) {
if (num == TARGET_NR_setxattr) {
ret = get_errno(setxattr(p, n, v, arg4, arg5));
} else {
ret = get_errno(lsetxattr(p, n, v, arg4, arg5));
} else {
ret = -TARGET_EFAULT;
unlock_user(p, arg1, 0);
unlock_user(n, arg2, 0);
unlock_user(v, arg3, 0);
case TARGET_NR_fsetxattr:
{
void *n, *v = 0;
if (arg3) {
v = lock_user(VERIFY_READ, arg3, arg4, 1);
if (!v) {
ret = -TARGET_EFAULT;
n = lock_user_string(arg2);
if (n) {
ret = get_errno(fsetxattr(arg1, n, v, arg4, arg5));
} else {
ret = -TARGET_EFAULT;
unlock_user(n, arg2, 0);
unlock_user(v, arg3, 0);
case TARGET_NR_getxattr:
case TARGET_NR_lgetxattr:
{
void *p, *n, *v = 0;
if (arg3) {
v = lock_user(VERIFY_WRITE, arg3, arg4, 0);
if (!v) {
ret = -TARGET_EFAULT;
p = lock_user_string(arg1);
n = lock_user_string(arg2);
if (p && n) {
if (num == TARGET_NR_getxattr) {
ret = get_errno(getxattr(p, n, v, arg4));
} else {
ret = get_errno(lgetxattr(p, n, v, arg4));
} else {
ret = -TARGET_EFAULT;
unlock_user(p, arg1, 0);
unlock_user(n, arg2, 0);
unlock_user(v, arg3, arg4);
case TARGET_NR_fgetxattr:
{
void *n, *v = 0;
if (arg3) {
v = lock_user(VERIFY_WRITE, arg3, arg4, 0);
if (!v) {
ret = -TARGET_EFAULT;
n = lock_user_string(arg2);
if (n) {
ret = get_errno(fgetxattr(arg1, n, v, arg4));
} else {
ret = -TARGET_EFAULT;
unlock_user(n, arg2, 0);
unlock_user(v, arg3, arg4);
case TARGET_NR_removexattr:
case TARGET_NR_lremovexattr:
{
void *p, *n;
p = lock_user_string(arg1);
n = lock_user_string(arg2);
if (p && n) {
if (num == TARGET_NR_removexattr) {
ret = get_errno(removexattr(p, n));
} else {
ret = get_errno(lremovexattr(p, n));
} else {
ret = -TARGET_EFAULT;
unlock_user(p, arg1, 0);
unlock_user(n, arg2, 0);
case TARGET_NR_fremovexattr:
{
void *n;
n = lock_user_string(arg2);
if (n) {
ret = get_errno(fremovexattr(arg1, n));
} else {
ret = -TARGET_EFAULT;
unlock_user(n, arg2, 0);
#endif
#endif
#ifdef TARGET_NR_set_thread_area
case TARGET_NR_set_thread_area:
#if defined(TARGET_MIPS)
((CPUMIPSState *) cpu_env)->active_tc.CP0_UserLocal = arg1;
ret = 0;
#elif defined(TARGET_CRIS)
if (arg1 & 0xff)
else {
((CPUCRISState *) cpu_env)->pregs[PR_PID] = arg1;
ret = 0;
#elif defined(TARGET_I386) && defined(TARGET_ABI32)
ret = do_set_thread_area(cpu_env, arg1);
#elif defined(TARGET_M68K)
{
TaskState *ts = cpu->opaque;
ts->tp_value = arg1;
ret = 0;
#else
goto unimplemented_nowarn;
#endif
#endif
#ifdef TARGET_NR_get_thread_area
case TARGET_NR_get_thread_area:
#if defined(TARGET_I386) && defined(TARGET_ABI32)
ret = do_get_thread_area(cpu_env, arg1);
#elif defined(TARGET_M68K)
{
TaskState *ts = cpu->opaque;
ret = ts->tp_value;
#else
goto unimplemented_nowarn;
#endif
#endif
#ifdef TARGET_NR_getdomainname
case TARGET_NR_getdomainname:
goto unimplemented_nowarn;
#endif
#ifdef TARGET_NR_clock_gettime
case TARGET_NR_clock_gettime:
{
struct timespec ts;
ret = get_errno(clock_gettime(arg1, &ts));
if (!is_error(ret)) {
host_to_target_timespec(arg2, &ts);
#endif
#ifdef TARGET_NR_clock_getres
case TARGET_NR_clock_getres:
{
struct timespec ts;
ret = get_errno(clock_getres(arg1, &ts));
if (!is_error(ret)) {
host_to_target_timespec(arg2, &ts);
#endif
#ifdef TARGET_NR_clock_nanosleep
case TARGET_NR_clock_nanosleep:
{
struct timespec ts;
target_to_host_timespec(&ts, arg3);
ret = get_errno(safe_clock_nanosleep(arg1, arg2,
&ts, arg4 ? &ts : NULL));
if (arg4)
host_to_target_timespec(arg4, &ts);
#if defined(TARGET_PPC)
if (ret && ret != -TARGET_ERESTARTSYS) {
((CPUPPCState *)cpu_env)->crf[0] |= 1;
#endif
#endif
#if defined(TARGET_NR_set_tid_address) && defined(__NR_set_tid_address)
case TARGET_NR_set_tid_address:
ret = get_errno(set_tid_address((int *)g2h(arg1)));
#endif
case TARGET_NR_tkill:
ret = get_errno(safe_tkill((int)arg1, target_to_host_signal(arg2)));
case TARGET_NR_tgkill:
ret = get_errno(safe_tgkill((int)arg1, (int)arg2,
target_to_host_signal(arg3)));
#ifdef TARGET_NR_set_robust_list
case TARGET_NR_set_robust_list:
case TARGET_NR_get_robust_list:
goto unimplemented_nowarn;
#endif
#if defined(TARGET_NR_utimensat)
case TARGET_NR_utimensat:
{
struct timespec *tsp, ts[2];
if (!arg3) {
tsp = NULL;
} else {
target_to_host_timespec(ts, arg3);
target_to_host_timespec(ts+1, arg3+sizeof(struct target_timespec));
tsp = ts;
if (!arg2)
ret = get_errno(sys_utimensat(arg1, NULL, tsp, arg4));
else {
if (!(p = lock_user_string(arg2))) {
ret = -TARGET_EFAULT;
goto fail;
ret = get_errno(sys_utimensat(arg1, path(p), tsp, arg4));
unlock_user(p, arg2, 0);
#endif
case TARGET_NR_futex:
ret = do_futex(arg1, arg2, arg3, arg4, arg5, arg6);
#if defined(TARGET_NR_inotify_init) && defined(__NR_inotify_init)
case TARGET_NR_inotify_init:
ret = get_errno(sys_inotify_init());
#endif
#ifdef CONFIG_INOTIFY1
#if defined(TARGET_NR_inotify_init1) && defined(__NR_inotify_init1)
case TARGET_NR_inotify_init1:
ret = get_errno(sys_inotify_init1(arg1));
#endif
#endif
#if defined(TARGET_NR_inotify_add_watch) && defined(__NR_inotify_add_watch)
case TARGET_NR_inotify_add_watch:
p = lock_user_string(arg2);
ret = get_errno(sys_inotify_add_watch(arg1, path(p), arg3));
unlock_user(p, arg2, 0);
#endif
#if defined(TARGET_NR_inotify_rm_watch) && defined(__NR_inotify_rm_watch)
case TARGET_NR_inotify_rm_watch:
ret = get_errno(sys_inotify_rm_watch(arg1, arg2));
#endif
#if defined(TARGET_NR_mq_open) && defined(__NR_mq_open)
case TARGET_NR_mq_open:
{
struct mq_attr posix_mq_attr, *attrp;
p = lock_user_string(arg1 - 1);
if (arg4 != 0) {
copy_from_user_mq_attr (&posix_mq_attr, arg4);
attrp = &posix_mq_attr;
} else {
attrp = 0;
ret = get_errno(mq_open(p, arg2, arg3, attrp));
unlock_user (p, arg1, 0);
case TARGET_NR_mq_unlink:
p = lock_user_string(arg1 - 1);
ret = get_errno(mq_unlink(p));
unlock_user (p, arg1, 0);
case TARGET_NR_mq_timedsend:
{
struct timespec ts;
p = lock_user (VERIFY_READ, arg2, arg3, 1);
if (arg5 != 0) {
target_to_host_timespec(&ts, arg5);
ret = get_errno(safe_mq_timedsend(arg1, p, arg3, arg4, &ts));
host_to_target_timespec(arg5, &ts);
} else {
ret = get_errno(safe_mq_timedsend(arg1, p, arg3, arg4, NULL));
unlock_user (p, arg2, arg3);
case TARGET_NR_mq_timedreceive:
{
struct timespec ts;
unsigned int prio;
p = lock_user (VERIFY_READ, arg2, arg3, 1);
if (arg5 != 0) {
target_to_host_timespec(&ts, arg5);
ret = get_errno(safe_mq_timedreceive(arg1, p, arg3,
&prio, &ts));
host_to_target_timespec(arg5, &ts);
} else {
ret = get_errno(safe_mq_timedreceive(arg1, p, arg3,
&prio, NULL));
unlock_user (p, arg2, arg3);
if (arg4 != 0)
put_user_u32(prio, arg4);
case TARGET_NR_mq_getsetattr:
{
struct mq_attr posix_mq_attr_in, posix_mq_attr_out;
ret = 0;
if (arg3 != 0) {
ret = mq_getattr(arg1, &posix_mq_attr_out);
copy_to_user_mq_attr(arg3, &posix_mq_attr_out);
if (arg2 != 0) {
copy_from_user_mq_attr(&posix_mq_attr_in, arg2);
ret |= mq_setattr(arg1, &posix_mq_attr_in, &posix_mq_attr_out);
#endif
#ifdef CONFIG_SPLICE
#ifdef TARGET_NR_tee
case TARGET_NR_tee:
{
ret = get_errno(tee(arg1,arg2,arg3,arg4));
#endif
#ifdef TARGET_NR_splice
case TARGET_NR_splice:
{
loff_t loff_in, loff_out;
loff_t *ploff_in = NULL, *ploff_out = NULL;
if (arg2) {
if (get_user_u64(loff_in, arg2)) {
goto efault;
ploff_in = &loff_in;
if (arg4) {
if (get_user_u64(loff_out, arg4)) {
goto efault;
ploff_out = &loff_out;
ret = get_errno(splice(arg1, ploff_in, arg3, ploff_out, arg5, arg6));
if (arg2) {
if (put_user_u64(loff_in, arg2)) {
goto efault;
if (arg4) {
if (put_user_u64(loff_out, arg4)) {
goto efault;
#endif
#ifdef TARGET_NR_vmsplice
case TARGET_NR_vmsplice:
{
struct iovec *vec = lock_iovec(VERIFY_READ, arg2, arg3, 1);
if (vec != NULL) {
ret = get_errno(vmsplice(arg1, vec, arg3, arg4));
unlock_iovec(vec, arg2, arg3, 0);
} else {
ret = -host_to_target_errno(errno);
#endif
#endif
#ifdef CONFIG_EVENTFD
#if defined(TARGET_NR_eventfd)
case TARGET_NR_eventfd:
ret = get_errno(eventfd(arg1, 0));
fd_trans_unregister(ret);
#endif
#if defined(TARGET_NR_eventfd2)
case TARGET_NR_eventfd2:
{
int host_flags = arg2 & (~(TARGET_O_NONBLOCK | TARGET_O_CLOEXEC));
if (arg2 & TARGET_O_NONBLOCK) {
host_flags |= O_NONBLOCK;
if (arg2 & TARGET_O_CLOEXEC) {
host_flags |= O_CLOEXEC;
ret = get_errno(eventfd(arg1, host_flags));
fd_trans_unregister(ret);
#endif
#endif
#if defined(CONFIG_FALLOCATE) && defined(TARGET_NR_fallocate)
case TARGET_NR_fallocate:
#if TARGET_ABI_BITS == 32
ret = get_errno(fallocate(arg1, arg2, target_offset64(arg3, arg4),
target_offset64(arg5, arg6)));
#else
ret = get_errno(fallocate(arg1, arg2, arg3, arg4));
#endif
#endif
#if defined(CONFIG_SYNC_FILE_RANGE)
#if defined(TARGET_NR_sync_file_range)
case TARGET_NR_sync_file_range:
#if TARGET_ABI_BITS == 32
#if defined(TARGET_MIPS)
ret = get_errno(sync_file_range(arg1, target_offset64(arg3, arg4),
target_offset64(arg5, arg6), arg7));
#else
ret = get_errno(sync_file_range(arg1, target_offset64(arg2, arg3),
target_offset64(arg4, arg5), arg6));
#endif
#else
ret = get_errno(sync_file_range(arg1, arg2, arg3, arg4));
#endif
#endif
#if defined(TARGET_NR_sync_file_range2)
case TARGET_NR_sync_file_range2:
#if TARGET_ABI_BITS == 32
ret = get_errno(sync_file_range(arg1, target_offset64(arg3, arg4),
target_offset64(arg5, arg6), arg2));
#else
ret = get_errno(sync_file_range(arg1, arg3, arg4, arg2));
#endif
#endif
#endif
#if defined(TARGET_NR_signalfd4)
case TARGET_NR_signalfd4:
ret = do_signalfd4(arg1, arg2, arg4);
#endif
#if defined(TARGET_NR_signalfd)
case TARGET_NR_signalfd:
ret = do_signalfd4(arg1, arg2, 0);
#endif
#if defined(CONFIG_EPOLL)
#if defined(TARGET_NR_epoll_create)
case TARGET_NR_epoll_create:
ret = get_errno(epoll_create(arg1));
#endif
#if defined(TARGET_NR_epoll_create1) && defined(CONFIG_EPOLL_CREATE1)
case TARGET_NR_epoll_create1:
ret = get_errno(epoll_create1(arg1));
#endif
#if defined(TARGET_NR_epoll_ctl)
case TARGET_NR_epoll_ctl:
{
struct epoll_event ep;
struct epoll_event *epp = 0;
if (arg4) {
struct target_epoll_event *target_ep;
if (!lock_user_struct(VERIFY_READ, target_ep, arg4, 1)) {
goto efault;
ep.events = tswap32(target_ep->events);
ep.data.u64 = tswap64(target_ep->data.u64);
unlock_user_struct(target_ep, arg4, 0);
epp = &ep;
ret = get_errno(epoll_ctl(arg1, arg2, arg3, epp));
#endif
#if defined(TARGET_NR_epoll_wait) || defined(TARGET_NR_epoll_pwait)
#if defined(TARGET_NR_epoll_wait)
case TARGET_NR_epoll_wait:
#endif
#if defined(TARGET_NR_epoll_pwait)
case TARGET_NR_epoll_pwait:
#endif
{
struct target_epoll_event *target_ep;
struct epoll_event *ep;
int epfd = arg1;
int maxevents = arg3;
int timeout = arg4;
if (maxevents <= 0 || maxevents > TARGET_EP_MAX_EVENTS) {
target_ep = lock_user(VERIFY_WRITE, arg2,
maxevents * sizeof(struct target_epoll_event), 1);
if (!target_ep) {
goto efault;
ep = alloca(maxevents * sizeof(struct epoll_event));
switch (num) {
#if defined(TARGET_NR_epoll_pwait)
case TARGET_NR_epoll_pwait:
{
target_sigset_t *target_set;
sigset_t _set, *set = &_set;
if (arg5) {
if (arg6 != sizeof(target_sigset_t)) {
target_set = lock_user(VERIFY_READ, arg5,
sizeof(target_sigset_t), 1);
if (!target_set) {
unlock_user(target_ep, arg2, 0);
goto efault;
target_to_host_sigset(set, target_set);
unlock_user(target_set, arg5, 0);
} else {
set = NULL;
ret = get_errno(safe_epoll_pwait(epfd, ep, maxevents, timeout,
set, SIGSET_T_SIZE));
#endif
#if defined(TARGET_NR_epoll_wait)
case TARGET_NR_epoll_wait:
ret = get_errno(safe_epoll_pwait(epfd, ep, maxevents, timeout,
NULL, 0));
#endif
default:
ret = -TARGET_ENOSYS;
if (!is_error(ret)) {
int i;
for (i = 0; i < ret; i++) {
target_ep[i].events = tswap32(ep[i].events);
target_ep[i].data.u64 = tswap64(ep[i].data.u64);
unlock_user(target_ep, arg2, ret * sizeof(struct target_epoll_event));
#endif
#endif
#ifdef TARGET_NR_prlimit64
case TARGET_NR_prlimit64:
{
struct target_rlimit64 *target_rnew, *target_rold;
struct host_rlimit64 rnew, rold, *rnewp = 0;
int resource = target_to_host_resource(arg2);
if (arg3) {
if (!lock_user_struct(VERIFY_READ, target_rnew, arg3, 1)) {
goto efault;
rnew.rlim_cur = tswap64(target_rnew->rlim_cur);
rnew.rlim_max = tswap64(target_rnew->rlim_max);
unlock_user_struct(target_rnew, arg3, 0);
rnewp = &rnew;
ret = get_errno(sys_prlimit64(arg1, resource, rnewp, arg4 ? &rold : 0));
if (!is_error(ret) && arg4) {
if (!lock_user_struct(VERIFY_WRITE, target_rold, arg4, 1)) {
goto efault;
target_rold->rlim_cur = tswap64(rold.rlim_cur);
target_rold->rlim_max = tswap64(rold.rlim_max);
unlock_user_struct(target_rold, arg4, 1);
#endif
#ifdef TARGET_NR_gethostname
case TARGET_NR_gethostname:
{
char *name = lock_user(VERIFY_WRITE, arg1, arg2, 0);
if (name) {
ret = get_errno(gethostname(name, arg2));
unlock_user(name, arg1, arg2);
} else {
ret = -TARGET_EFAULT;
#endif
#ifdef TARGET_NR_atomic_cmpxchg_32
case TARGET_NR_atomic_cmpxchg_32:
{
abi_ulong mem_value;
if (get_user_u32(mem_value, arg6)) {
target_siginfo_t info;
info.si_signo = SIGSEGV;
info.si_errno = 0;
info.si_code = TARGET_SEGV_MAPERR;
info._sifields._sigfault._addr = arg6;
queue_signal((CPUArchState *)cpu_env, info.si_signo, &info);
ret = 0xdeadbeef;
if (mem_value == arg2)
put_user_u32(arg1, arg6);
ret = mem_value;
#endif
#ifdef TARGET_NR_atomic_barrier
case TARGET_NR_atomic_barrier:
{
ret = 0;
#endif
#ifdef TARGET_NR_timer_create
case TARGET_NR_timer_create:
{
struct sigevent host_sevp = { {0}, }, *phost_sevp = NULL;
int clkid = arg1;
int timer_index = next_free_host_timer();
if (timer_index < 0) {
ret = -TARGET_EAGAIN;
} else {
timer_t *phtimer = g_posix_timers + timer_index;
if (arg2) {
phost_sevp = &host_sevp;
ret = target_to_host_sigevent(phost_sevp, arg2);
if (ret != 0) {
ret = get_errno(timer_create(clkid, phost_sevp, phtimer));
if (ret) {
phtimer = NULL;
} else {
if (put_user(TIMER_MAGIC | timer_index, arg3, target_timer_t)) {
goto efault;
#endif
#ifdef TARGET_NR_timer_settime
case TARGET_NR_timer_settime:
{
target_timer_t timerid = get_timer_id(arg1);
if (timerid < 0) {
ret = timerid;
} else if (arg3 == 0) {
} else {
timer_t htimer = g_posix_timers[timerid];
struct itimerspec hspec_new = {{0},}, hspec_old = {{0},};
target_to_host_itimerspec(&hspec_new, arg3);
ret = get_errno(
timer_settime(htimer, arg2, &hspec_new, &hspec_old));
host_to_target_itimerspec(arg2, &hspec_old);
#endif
#ifdef TARGET_NR_timer_gettime
case TARGET_NR_timer_gettime:
{
target_timer_t timerid = get_timer_id(arg1);
if (timerid < 0) {
ret = timerid;
} else if (!arg2) {
ret = -TARGET_EFAULT;
} else {
timer_t htimer = g_posix_timers[timerid];
struct itimerspec hspec;
ret = get_errno(timer_gettime(htimer, &hspec));
if (host_to_target_itimerspec(arg2, &hspec)) {
ret = -TARGET_EFAULT;
#endif
#ifdef TARGET_NR_timer_getoverrun
case TARGET_NR_timer_getoverrun:
{
target_timer_t timerid = get_timer_id(arg1);
if (timerid < 0) {
ret = timerid;
} else {
timer_t htimer = g_posix_timers[timerid];
ret = get_errno(timer_getoverrun(htimer));
fd_trans_unregister(ret);
#endif
#ifdef TARGET_NR_timer_delete
case TARGET_NR_timer_delete:
{
target_timer_t timerid = get_timer_id(arg1);
if (timerid < 0) {
ret = timerid;
} else {
timer_t htimer = g_posix_timers[timerid];
ret = get_errno(timer_delete(htimer));
g_posix_timers[timerid] = 0;
#endif
#if defined(TARGET_NR_timerfd_create) && defined(CONFIG_TIMERFD)
case TARGET_NR_timerfd_create:
ret = get_errno(timerfd_create(arg1,
target_to_host_bitmask(arg2, fcntl_flags_tbl)));
#endif
#if defined(TARGET_NR_timerfd_gettime) && defined(CONFIG_TIMERFD)
case TARGET_NR_timerfd_gettime:
{
struct itimerspec its_curr;
ret = get_errno(timerfd_gettime(arg1, &its_curr));
if (arg2 && host_to_target_itimerspec(arg2, &its_curr)) {
goto efault;
#endif
#if defined(TARGET_NR_timerfd_settime) && defined(CONFIG_TIMERFD)
case TARGET_NR_timerfd_settime:
{
struct itimerspec its_new, its_old, *p_new;
if (arg3) {
if (target_to_host_itimerspec(&its_new, arg3)) {
goto efault;
p_new = &its_new;
} else {
p_new = NULL;
ret = get_errno(timerfd_settime(arg1, arg2, p_new, &its_old));
if (arg4 && host_to_target_itimerspec(arg4, &its_old)) {
goto efault;
#endif
#if defined(TARGET_NR_ioprio_get) && defined(__NR_ioprio_get)
case TARGET_NR_ioprio_get:
ret = get_errno(ioprio_get(arg1, arg2));
#endif
#if defined(TARGET_NR_ioprio_set) && defined(__NR_ioprio_set)
case TARGET_NR_ioprio_set:
ret = get_errno(ioprio_set(arg1, arg2, arg3));
#endif
#if defined(TARGET_NR_setns) && defined(CONFIG_SETNS)
case TARGET_NR_setns:
ret = get_errno(setns(arg1, arg2));
#endif
#if defined(TARGET_NR_unshare) && defined(CONFIG_SETNS)
case TARGET_NR_unshare:
ret = get_errno(unshare(arg1));
#endif
default:
unimplemented:
gemu_log("qemu: Unsupported syscall: %d\n", num);
#if defined(TARGET_NR_setxattr) || defined(TARGET_NR_get_thread_area) || defined(TARGET_NR_getdomainname) || defined(TARGET_NR_set_robust_list)
unimplemented_nowarn:
#endif
ret = -TARGET_ENOSYS;
fail:
#ifdef DEBUG
gemu_log(" = " TARGET_ABI_FMT_ld "\n", ret);
#endif
if(do_strace)
print_syscall_ret(num, ret);
trace_guest_user_syscall_ret(cpu, num, ret);
return ret;
efault:
ret = -TARGET_EFAULT;
goto fail; | {
"code": [],
"line_no": []
} | abi_long FUNC_0(void *cpu_env, int num, abi_long arg1,
abi_long arg2, abi_long arg3, abi_long arg4,
abi_long arg5, abi_long arg6, abi_long arg7,
abi_long arg8)
{
CPUState *cpu = ENV_GET_CPU(cpu_env);
abi_long ret;
struct stat VAR_0;
struct statfs VAR_1;
void *VAR_2;
#if defined(DEBUG_ERESTARTSYS)
{
static int flag;
flag = !flag;
if (flag) {
return -TARGET_ERESTARTSYS;
#endif
#ifdef DEBUG
gemu_log("syscall %d", num);
#endif
trace_guest_user_syscall(cpu, num, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);
if(do_strace)
print_syscall(num, arg1, arg2, arg3, arg4, arg5, arg6);
switch(num) {
case TARGET_NR_exit:
if (block_signals()) {
ret = -TARGET_ERESTARTSYS;
if (CPU_NEXT(first_cpu)) {
TaskState *ts;
cpu_list_lock();
QTAILQ_REMOVE(&cpus, cpu, node);
cpu_list_unlock();
ts = cpu->opaque;
if (ts->child_tidptr) {
put_user_u32(0, ts->child_tidptr);
sys_futex(g2h(ts->child_tidptr), FUTEX_WAKE, INT_MAX,
NULL, NULL, 0);
thread_cpu = NULL;
object_unref(OBJECT(cpu));
g_free(ts);
rcu_unregister_thread();
pthread_exit(NULL);
#ifdef TARGET_GPROF
_mcleanup();
#endif
gdb_exit(cpu_env, arg1);
_exit(arg1);
ret = 0;
case TARGET_NR_read:
if (arg3 == 0)
ret = 0;
else {
if (!(VAR_2 = lock_user(VERIFY_WRITE, arg2, arg3, 0)))
goto efault;
ret = get_errno(safe_read(arg1, VAR_2, arg3));
if (ret >= 0 &&
fd_trans_host_to_target_data(arg1)) {
ret = fd_trans_host_to_target_data(arg1)(VAR_2, ret);
unlock_user(VAR_2, arg2, ret);
case TARGET_NR_write:
if (!(VAR_2 = lock_user(VERIFY_READ, arg2, arg3, 1)))
goto efault;
ret = get_errno(safe_write(arg1, VAR_2, arg3));
unlock_user(VAR_2, arg2, 0);
#ifdef TARGET_NR_open
case TARGET_NR_open:
if (!(VAR_2 = lock_user_string(arg1)))
goto efault;
ret = get_errno(do_openat(cpu_env, AT_FDCWD, VAR_2,
target_to_host_bitmask(arg2, fcntl_flags_tbl),
arg3));
fd_trans_unregister(ret);
unlock_user(VAR_2, arg1, 0);
#endif
case TARGET_NR_openat:
if (!(VAR_2 = lock_user_string(arg2)))
goto efault;
ret = get_errno(do_openat(cpu_env, arg1, VAR_2,
target_to_host_bitmask(arg3, fcntl_flags_tbl),
arg4));
fd_trans_unregister(ret);
unlock_user(VAR_2, arg2, 0);
#if defined(TARGET_NR_name_to_handle_at) && defined(CONFIG_OPEN_BY_HANDLE)
case TARGET_NR_name_to_handle_at:
ret = do_name_to_handle_at(arg1, arg2, arg3, arg4, arg5);
#endif
#if defined(TARGET_NR_open_by_handle_at) && defined(CONFIG_OPEN_BY_HANDLE)
case TARGET_NR_open_by_handle_at:
ret = do_open_by_handle_at(arg1, arg2, arg3);
fd_trans_unregister(ret);
#endif
case TARGET_NR_close:
fd_trans_unregister(arg1);
ret = get_errno(close(arg1));
case TARGET_NR_brk:
ret = do_brk(arg1);
#ifdef TARGET_NR_fork
case TARGET_NR_fork:
ret = get_errno(do_fork(cpu_env, SIGCHLD, 0, 0, 0, 0));
#endif
#ifdef TARGET_NR_waitpid
case TARGET_NR_waitpid:
{
int status;
ret = get_errno(safe_wait4(arg1, &status, arg3, 0));
if (!is_error(ret) && arg2 && ret
&& put_user_s32(host_to_target_waitstatus(status), arg2))
goto efault;
#endif
#ifdef TARGET_NR_waitid
case TARGET_NR_waitid:
{
siginfo_t info;
info.si_pid = 0;
ret = get_errno(safe_waitid(arg1, arg2, &info, arg4, NULL));
if (!is_error(ret) && arg3 && info.si_pid != 0) {
if (!(VAR_2 = lock_user(VERIFY_WRITE, arg3, sizeof(target_siginfo_t), 0)))
goto efault;
host_to_target_siginfo(VAR_2, &info);
unlock_user(VAR_2, arg3, sizeof(target_siginfo_t));
#endif
#ifdef TARGET_NR_creat
case TARGET_NR_creat:
if (!(VAR_2 = lock_user_string(arg1)))
goto efault;
ret = get_errno(creat(VAR_2, arg2));
fd_trans_unregister(ret);
unlock_user(VAR_2, arg1, 0);
#endif
#ifdef TARGET_NR_link
case TARGET_NR_link:
{
void * p2;
VAR_2 = lock_user_string(arg1);
p2 = lock_user_string(arg2);
if (!VAR_2 || !p2)
ret = -TARGET_EFAULT;
else
ret = get_errno(link(VAR_2, p2));
unlock_user(p2, arg2, 0);
unlock_user(VAR_2, arg1, 0);
#endif
#if defined(TARGET_NR_linkat)
case TARGET_NR_linkat:
{
void * p2 = NULL;
if (!arg2 || !arg4)
goto efault;
VAR_2 = lock_user_string(arg2);
p2 = lock_user_string(arg4);
if (!VAR_2 || !p2)
ret = -TARGET_EFAULT;
else
ret = get_errno(linkat(arg1, VAR_2, arg3, p2, arg5));
unlock_user(VAR_2, arg2, 0);
unlock_user(p2, arg4, 0);
#endif
#ifdef TARGET_NR_unlink
case TARGET_NR_unlink:
if (!(VAR_2 = lock_user_string(arg1)))
goto efault;
ret = get_errno(unlink(VAR_2));
unlock_user(VAR_2, arg1, 0);
#endif
#if defined(TARGET_NR_unlinkat)
case TARGET_NR_unlinkat:
if (!(VAR_2 = lock_user_string(arg2)))
goto efault;
ret = get_errno(unlinkat(arg1, VAR_2, arg3));
unlock_user(VAR_2, arg2, 0);
#endif
case TARGET_NR_execve:
{
char **VAR_3, **VAR_4;
int VAR_5, VAR_6;
abi_ulong gp;
abi_ulong guest_argp;
abi_ulong guest_envp;
abi_ulong addr;
char **VAR_7;
int VAR_8 = 0;
VAR_5 = 0;
guest_argp = arg2;
for (gp = guest_argp; gp; gp += sizeof(abi_ulong)) {
if (get_user_ual(addr, gp))
goto efault;
if (!addr)
VAR_5++;
VAR_6 = 0;
guest_envp = arg3;
for (gp = guest_envp; gp; gp += sizeof(abi_ulong)) {
if (get_user_ual(addr, gp))
goto efault;
if (!addr)
VAR_6++;
VAR_3 = alloca((VAR_5 + 1) * sizeof(void *));
VAR_4 = alloca((VAR_6 + 1) * sizeof(void *));
for (gp = guest_argp, VAR_7 = VAR_3; gp;
gp += sizeof(abi_ulong), VAR_7++) {
if (get_user_ual(addr, gp))
goto execve_efault;
if (!addr)
if (!(*VAR_7 = lock_user_string(addr)))
goto execve_efault;
VAR_8 += strlen(*VAR_7) + 1;
*VAR_7 = NULL;
for (gp = guest_envp, VAR_7 = VAR_4; gp;
gp += sizeof(abi_ulong), VAR_7++) {
if (get_user_ual(addr, gp))
goto execve_efault;
if (!addr)
if (!(*VAR_7 = lock_user_string(addr)))
goto execve_efault;
VAR_8 += strlen(*VAR_7) + 1;
*VAR_7 = NULL;
if (!(VAR_2 = lock_user_string(arg1)))
goto execve_efault;
ret = get_errno(safe_execve(VAR_2, VAR_3, VAR_4));
unlock_user(VAR_2, arg1, 0);
goto execve_end;
execve_efault:
ret = -TARGET_EFAULT;
execve_end:
for (gp = guest_argp, VAR_7 = VAR_3; *VAR_7;
gp += sizeof(abi_ulong), VAR_7++) {
if (get_user_ual(addr, gp)
|| !addr)
unlock_user(*VAR_7, addr, 0);
for (gp = guest_envp, VAR_7 = VAR_4; *VAR_7;
gp += sizeof(abi_ulong), VAR_7++) {
if (get_user_ual(addr, gp)
|| !addr)
unlock_user(*VAR_7, addr, 0);
case TARGET_NR_chdir:
if (!(VAR_2 = lock_user_string(arg1)))
goto efault;
ret = get_errno(chdir(VAR_2));
unlock_user(VAR_2, arg1, 0);
#ifdef TARGET_NR_time
case TARGET_NR_time:
{
time_t host_time;
ret = get_errno(time(&host_time));
if (!is_error(ret)
&& arg1
&& put_user_sal(host_time, arg1))
goto efault;
#endif
#ifdef TARGET_NR_mknod
case TARGET_NR_mknod:
if (!(VAR_2 = lock_user_string(arg1)))
goto efault;
ret = get_errno(mknod(VAR_2, arg2, arg3));
unlock_user(VAR_2, arg1, 0);
#endif
#if defined(TARGET_NR_mknodat)
case TARGET_NR_mknodat:
if (!(VAR_2 = lock_user_string(arg2)))
goto efault;
ret = get_errno(mknodat(arg1, VAR_2, arg3, arg4));
unlock_user(VAR_2, arg2, 0);
#endif
#ifdef TARGET_NR_chmod
case TARGET_NR_chmod:
if (!(VAR_2 = lock_user_string(arg1)))
goto efault;
ret = get_errno(chmod(VAR_2, arg2));
unlock_user(VAR_2, arg1, 0);
#endif
#ifdef TARGET_NR_break
case TARGET_NR_break:
goto unimplemented;
#endif
#ifdef TARGET_NR_oldstat
case TARGET_NR_oldstat:
goto unimplemented;
#endif
case TARGET_NR_lseek:
ret = get_errno(lseek(arg1, arg2, arg3));
#if defined(TARGET_NR_getxpid) && defined(TARGET_ALPHA)
case TARGET_NR_getxpid:
((CPUAlphaState *)cpu_env)->ir[IR_A4] = getppid();
ret = get_errno(getpid());
#endif
#ifdef TARGET_NR_getpid
case TARGET_NR_getpid:
ret = get_errno(getpid());
#endif
case TARGET_NR_mount:
{
void *p2, *p3;
if (arg1) {
VAR_2 = lock_user_string(arg1);
if (!VAR_2) {
goto efault;
} else {
VAR_2 = NULL;
p2 = lock_user_string(arg2);
if (!p2) {
if (arg1) {
unlock_user(VAR_2, arg1, 0);
goto efault;
if (arg3) {
p3 = lock_user_string(arg3);
if (!p3) {
if (arg1) {
unlock_user(VAR_2, arg1, 0);
unlock_user(p2, arg2, 0);
goto efault;
} else {
p3 = NULL;
if (!arg5) {
ret = mount(VAR_2, p2, p3, (unsigned long)arg4, NULL);
} else {
ret = mount(VAR_2, p2, p3, (unsigned long)arg4, g2h(arg5));
ret = get_errno(ret);
if (arg1) {
unlock_user(VAR_2, arg1, 0);
unlock_user(p2, arg2, 0);
if (arg3) {
unlock_user(p3, arg3, 0);
#ifdef TARGET_NR_umount
case TARGET_NR_umount:
if (!(VAR_2 = lock_user_string(arg1)))
goto efault;
ret = get_errno(umount(VAR_2));
unlock_user(VAR_2, arg1, 0);
#endif
#ifdef TARGET_NR_stime
case TARGET_NR_stime:
{
time_t host_time;
if (get_user_sal(host_time, arg1))
goto efault;
ret = get_errno(stime(&host_time));
#endif
case TARGET_NR_ptrace:
goto unimplemented;
#ifdef TARGET_NR_alarm
case TARGET_NR_alarm:
ret = alarm(arg1);
#endif
#ifdef TARGET_NR_oldfstat
case TARGET_NR_oldfstat:
goto unimplemented;
#endif
#ifdef TARGET_NR_pause
case TARGET_NR_pause:
if (!block_signals()) {
sigsuspend(&((TaskState *)cpu->opaque)->signal_mask);
ret = -TARGET_EINTR;
#endif
#ifdef TARGET_NR_utime
case TARGET_NR_utime:
{
struct utimbuf tbuf, *host_tbuf;
struct target_utimbuf *target_tbuf;
if (arg2) {
if (!lock_user_struct(VERIFY_READ, target_tbuf, arg2, 1))
goto efault;
tbuf.actime = tswapal(target_tbuf->actime);
tbuf.modtime = tswapal(target_tbuf->modtime);
unlock_user_struct(target_tbuf, arg2, 0);
host_tbuf = &tbuf;
} else {
host_tbuf = NULL;
if (!(VAR_2 = lock_user_string(arg1)))
goto efault;
ret = get_errno(utime(VAR_2, host_tbuf));
unlock_user(VAR_2, arg1, 0);
#endif
#ifdef TARGET_NR_utimes
case TARGET_NR_utimes:
{
struct timeval *tvp, tv[2];
if (arg2) {
if (copy_from_user_timeval(&tv[0], arg2)
|| copy_from_user_timeval(&tv[1],
arg2 + sizeof(struct target_timeval)))
goto efault;
tvp = tv;
} else {
tvp = NULL;
if (!(VAR_2 = lock_user_string(arg1)))
goto efault;
ret = get_errno(utimes(VAR_2, tvp));
unlock_user(VAR_2, arg1, 0);
#endif
#if defined(TARGET_NR_futimesat)
case TARGET_NR_futimesat:
{
struct timeval *tvp, tv[2];
if (arg3) {
if (copy_from_user_timeval(&tv[0], arg3)
|| copy_from_user_timeval(&tv[1],
arg3 + sizeof(struct target_timeval)))
goto efault;
tvp = tv;
} else {
tvp = NULL;
if (!(VAR_2 = lock_user_string(arg2)))
goto efault;
ret = get_errno(futimesat(arg1, path(VAR_2), tvp));
unlock_user(VAR_2, arg2, 0);
#endif
#ifdef TARGET_NR_stty
case TARGET_NR_stty:
goto unimplemented;
#endif
#ifdef TARGET_NR_gtty
case TARGET_NR_gtty:
goto unimplemented;
#endif
#ifdef TARGET_NR_access
case TARGET_NR_access:
if (!(VAR_2 = lock_user_string(arg1)))
goto efault;
ret = get_errno(access(path(VAR_2), arg2));
unlock_user(VAR_2, arg1, 0);
#endif
#if defined(TARGET_NR_faccessat) && defined(__NR_faccessat)
case TARGET_NR_faccessat:
if (!(VAR_2 = lock_user_string(arg2)))
goto efault;
ret = get_errno(faccessat(arg1, VAR_2, arg3, 0));
unlock_user(VAR_2, arg2, 0);
#endif
#ifdef TARGET_NR_nice
case TARGET_NR_nice:
ret = get_errno(nice(arg1));
#endif
#ifdef TARGET_NR_ftime
case TARGET_NR_ftime:
goto unimplemented;
#endif
case TARGET_NR_sync:
sync();
ret = 0;
case TARGET_NR_kill:
ret = get_errno(safe_kill(arg1, target_to_host_signal(arg2)));
#ifdef TARGET_NR_rename
case TARGET_NR_rename:
{
void *p2;
VAR_2 = lock_user_string(arg1);
p2 = lock_user_string(arg2);
if (!VAR_2 || !p2)
ret = -TARGET_EFAULT;
else
ret = get_errno(rename(VAR_2, p2));
unlock_user(p2, arg2, 0);
unlock_user(VAR_2, arg1, 0);
#endif
#if defined(TARGET_NR_renameat)
case TARGET_NR_renameat:
{
void *p2;
VAR_2 = lock_user_string(arg2);
p2 = lock_user_string(arg4);
if (!VAR_2 || !p2)
ret = -TARGET_EFAULT;
else
ret = get_errno(renameat(arg1, VAR_2, arg3, p2));
unlock_user(p2, arg4, 0);
unlock_user(VAR_2, arg2, 0);
#endif
#ifdef TARGET_NR_mkdir
case TARGET_NR_mkdir:
if (!(VAR_2 = lock_user_string(arg1)))
goto efault;
ret = get_errno(mkdir(VAR_2, arg2));
unlock_user(VAR_2, arg1, 0);
#endif
#if defined(TARGET_NR_mkdirat)
case TARGET_NR_mkdirat:
if (!(VAR_2 = lock_user_string(arg2)))
goto efault;
ret = get_errno(mkdirat(arg1, VAR_2, arg3));
unlock_user(VAR_2, arg2, 0);
#endif
#ifdef TARGET_NR_rmdir
case TARGET_NR_rmdir:
if (!(VAR_2 = lock_user_string(arg1)))
goto efault;
ret = get_errno(rmdir(VAR_2));
unlock_user(VAR_2, arg1, 0);
#endif
case TARGET_NR_dup:
ret = get_errno(dup(arg1));
if (ret >= 0) {
fd_trans_dup(arg1, ret);
#ifdef TARGET_NR_pipe
case TARGET_NR_pipe:
ret = do_pipe(cpu_env, arg1, 0, 0);
#endif
#ifdef TARGET_NR_pipe2
case TARGET_NR_pipe2:
ret = do_pipe(cpu_env, arg1,
target_to_host_bitmask(arg2, fcntl_flags_tbl), 1);
#endif
case TARGET_NR_times:
{
struct target_tms *tmsp;
struct tms tms;
ret = get_errno(times(&tms));
if (arg1) {
tmsp = lock_user(VERIFY_WRITE, arg1, sizeof(struct target_tms), 0);
if (!tmsp)
goto efault;
tmsp->tms_utime = tswapal(host_to_target_clock_t(tms.tms_utime));
tmsp->tms_stime = tswapal(host_to_target_clock_t(tms.tms_stime));
tmsp->tms_cutime = tswapal(host_to_target_clock_t(tms.tms_cutime));
tmsp->tms_cstime = tswapal(host_to_target_clock_t(tms.tms_cstime));
if (!is_error(ret))
ret = host_to_target_clock_t(ret);
#ifdef TARGET_NR_prof
case TARGET_NR_prof:
goto unimplemented;
#endif
#ifdef TARGET_NR_signal
case TARGET_NR_signal:
goto unimplemented;
#endif
case TARGET_NR_acct:
if (arg1 == 0) {
ret = get_errno(acct(NULL));
} else {
if (!(VAR_2 = lock_user_string(arg1)))
goto efault;
ret = get_errno(acct(path(VAR_2)));
unlock_user(VAR_2, arg1, 0);
#ifdef TARGET_NR_umount2
case TARGET_NR_umount2:
if (!(VAR_2 = lock_user_string(arg1)))
goto efault;
ret = get_errno(umount2(VAR_2, arg2));
unlock_user(VAR_2, arg1, 0);
#endif
#ifdef TARGET_NR_lock
case TARGET_NR_lock:
goto unimplemented;
#endif
case TARGET_NR_ioctl:
ret = do_ioctl(arg1, arg2, arg3);
case TARGET_NR_fcntl:
ret = do_fcntl(arg1, arg2, arg3);
#ifdef TARGET_NR_mpx
case TARGET_NR_mpx:
goto unimplemented;
#endif
case TARGET_NR_setpgid:
ret = get_errno(setpgid(arg1, arg2));
#ifdef TARGET_NR_ulimit
case TARGET_NR_ulimit:
goto unimplemented;
#endif
#ifdef TARGET_NR_oldolduname
case TARGET_NR_oldolduname:
goto unimplemented;
#endif
case TARGET_NR_umask:
ret = get_errno(umask(arg1));
case TARGET_NR_chroot:
if (!(VAR_2 = lock_user_string(arg1)))
goto efault;
ret = get_errno(chroot(VAR_2));
unlock_user(VAR_2, arg1, 0);
#ifdef TARGET_NR_ustat
case TARGET_NR_ustat:
goto unimplemented;
#endif
#ifdef TARGET_NR_dup2
case TARGET_NR_dup2:
ret = get_errno(dup2(arg1, arg2));
if (ret >= 0) {
fd_trans_dup(arg1, arg2);
#endif
#if defined(CONFIG_DUP3) && defined(TARGET_NR_dup3)
case TARGET_NR_dup3:
ret = get_errno(dup3(arg1, arg2, arg3));
if (ret >= 0) {
fd_trans_dup(arg1, arg2);
#endif
#ifdef TARGET_NR_getppid
case TARGET_NR_getppid:
ret = get_errno(getppid());
#endif
#ifdef TARGET_NR_getpgrp
case TARGET_NR_getpgrp:
ret = get_errno(getpgrp());
#endif
case TARGET_NR_setsid:
ret = get_errno(setsid());
#ifdef TARGET_NR_sigaction
case TARGET_NR_sigaction:
{
#if defined(TARGET_ALPHA)
struct target_sigaction act, oact, *pact = 0;
struct target_old_sigaction *old_act;
if (arg2) {
if (!lock_user_struct(VERIFY_READ, old_act, arg2, 1))
goto efault;
act._sa_handler = old_act->_sa_handler;
target_siginitset(&act.sa_mask, old_act->sa_mask);
act.sa_flags = old_act->sa_flags;
act.sa_restorer = 0;
unlock_user_struct(old_act, arg2, 0);
pact = &act;
ret = get_errno(do_sigaction(arg1, pact, &oact));
if (!is_error(ret) && arg3) {
if (!lock_user_struct(VERIFY_WRITE, old_act, arg3, 0))
goto efault;
old_act->_sa_handler = oact._sa_handler;
old_act->sa_mask = oact.sa_mask.sig[0];
old_act->sa_flags = oact.sa_flags;
unlock_user_struct(old_act, arg3, 1);
#elif defined(TARGET_MIPS)
struct target_sigaction act, oact, *pact, *old_act;
if (arg2) {
if (!lock_user_struct(VERIFY_READ, old_act, arg2, 1))
goto efault;
act._sa_handler = old_act->_sa_handler;
target_siginitset(&act.sa_mask, old_act->sa_mask.sig[0]);
act.sa_flags = old_act->sa_flags;
unlock_user_struct(old_act, arg2, 0);
pact = &act;
} else {
pact = NULL;
ret = get_errno(do_sigaction(arg1, pact, &oact));
if (!is_error(ret) && arg3) {
if (!lock_user_struct(VERIFY_WRITE, old_act, arg3, 0))
goto efault;
old_act->_sa_handler = oact._sa_handler;
old_act->sa_flags = oact.sa_flags;
old_act->sa_mask.sig[0] = oact.sa_mask.sig[0];
old_act->sa_mask.sig[1] = 0;
old_act->sa_mask.sig[2] = 0;
old_act->sa_mask.sig[3] = 0;
unlock_user_struct(old_act, arg3, 1);
#else
struct target_old_sigaction *old_act;
struct target_sigaction act, oact, *pact;
if (arg2) {
if (!lock_user_struct(VERIFY_READ, old_act, arg2, 1))
goto efault;
act._sa_handler = old_act->_sa_handler;
target_siginitset(&act.sa_mask, old_act->sa_mask);
act.sa_flags = old_act->sa_flags;
act.sa_restorer = old_act->sa_restorer;
unlock_user_struct(old_act, arg2, 0);
pact = &act;
} else {
pact = NULL;
ret = get_errno(do_sigaction(arg1, pact, &oact));
if (!is_error(ret) && arg3) {
if (!lock_user_struct(VERIFY_WRITE, old_act, arg3, 0))
goto efault;
old_act->_sa_handler = oact._sa_handler;
old_act->sa_mask = oact.sa_mask.sig[0];
old_act->sa_flags = oact.sa_flags;
old_act->sa_restorer = oact.sa_restorer;
unlock_user_struct(old_act, arg3, 1);
#endif
#endif
case TARGET_NR_rt_sigaction:
{
#if defined(TARGET_ALPHA)
struct target_sigaction act, oact, *pact = 0;
struct target_rt_sigaction *rt_act;
if (arg4 != sizeof(target_sigset_t)) {
if (arg2) {
if (!lock_user_struct(VERIFY_READ, rt_act, arg2, 1))
goto efault;
act._sa_handler = rt_act->_sa_handler;
act.sa_mask = rt_act->sa_mask;
act.sa_flags = rt_act->sa_flags;
act.sa_restorer = arg5;
unlock_user_struct(rt_act, arg2, 0);
pact = &act;
ret = get_errno(do_sigaction(arg1, pact, &oact));
if (!is_error(ret) && arg3) {
if (!lock_user_struct(VERIFY_WRITE, rt_act, arg3, 0))
goto efault;
rt_act->_sa_handler = oact._sa_handler;
rt_act->sa_mask = oact.sa_mask;
rt_act->sa_flags = oact.sa_flags;
unlock_user_struct(rt_act, arg3, 1);
#else
struct target_sigaction *act;
struct target_sigaction *oact;
if (arg4 != sizeof(target_sigset_t)) {
if (arg2) {
if (!lock_user_struct(VERIFY_READ, act, arg2, 1))
goto efault;
} else
act = NULL;
if (arg3) {
if (!lock_user_struct(VERIFY_WRITE, oact, arg3, 0)) {
ret = -TARGET_EFAULT;
goto rt_sigaction_fail;
} else
oact = NULL;
ret = get_errno(do_sigaction(arg1, act, oact));
rt_sigaction_fail:
if (act)
unlock_user_struct(act, arg2, 0);
if (oact)
unlock_user_struct(oact, arg3, 1);
#endif
#ifdef TARGET_NR_sgetmask
case TARGET_NR_sgetmask:
{
sigset_t cur_set;
abi_ulong target_set;
ret = do_sigprocmask(0, NULL, &cur_set);
if (!ret) {
host_to_target_old_sigset(&target_set, &cur_set);
ret = target_set;
#endif
#ifdef TARGET_NR_ssetmask
case TARGET_NR_ssetmask:
{
sigset_t set, oset, cur_set;
abi_ulong target_set = arg1;
ret = do_sigprocmask(0, NULL, &cur_set);
assert(!ret);
target_to_host_old_sigset(&set, &target_set);
sigorset(&set, &set, &cur_set);
ret = do_sigprocmask(SIG_SETMASK, &set, &oset);
if (!ret) {
host_to_target_old_sigset(&target_set, &oset);
ret = target_set;
#endif
#ifdef TARGET_NR_sigprocmask
case TARGET_NR_sigprocmask:
{
#if defined(TARGET_ALPHA)
sigset_t set, oldset;
abi_ulong mask;
int how;
switch (arg1) {
case TARGET_SIG_BLOCK:
how = SIG_BLOCK;
case TARGET_SIG_UNBLOCK:
how = SIG_UNBLOCK;
case TARGET_SIG_SETMASK:
how = SIG_SETMASK;
default:
goto fail;
mask = arg2;
target_to_host_old_sigset(&set, &mask);
ret = do_sigprocmask(how, &set, &oldset);
if (!is_error(ret)) {
host_to_target_old_sigset(&mask, &oldset);
ret = mask;
((CPUAlphaState *)cpu_env)->ir[IR_V0] = 0;
#else
sigset_t set, oldset, *set_ptr;
int how;
if (arg2) {
switch (arg1) {
case TARGET_SIG_BLOCK:
how = SIG_BLOCK;
case TARGET_SIG_UNBLOCK:
how = SIG_UNBLOCK;
case TARGET_SIG_SETMASK:
how = SIG_SETMASK;
default:
goto fail;
if (!(VAR_2 = lock_user(VERIFY_READ, arg2, sizeof(target_sigset_t), 1)))
goto efault;
target_to_host_old_sigset(&set, VAR_2);
unlock_user(VAR_2, arg2, 0);
set_ptr = &set;
} else {
how = 0;
set_ptr = NULL;
ret = do_sigprocmask(how, set_ptr, &oldset);
if (!is_error(ret) && arg3) {
if (!(VAR_2 = lock_user(VERIFY_WRITE, arg3, sizeof(target_sigset_t), 0)))
goto efault;
host_to_target_old_sigset(VAR_2, &oldset);
unlock_user(VAR_2, arg3, sizeof(target_sigset_t));
#endif
#endif
case TARGET_NR_rt_sigprocmask:
{
int how = arg1;
sigset_t set, oldset, *set_ptr;
if (arg4 != sizeof(target_sigset_t)) {
if (arg2) {
switch(how) {
case TARGET_SIG_BLOCK:
how = SIG_BLOCK;
case TARGET_SIG_UNBLOCK:
how = SIG_UNBLOCK;
case TARGET_SIG_SETMASK:
how = SIG_SETMASK;
default:
goto fail;
if (!(VAR_2 = lock_user(VERIFY_READ, arg2, sizeof(target_sigset_t), 1)))
goto efault;
target_to_host_sigset(&set, VAR_2);
unlock_user(VAR_2, arg2, 0);
set_ptr = &set;
} else {
how = 0;
set_ptr = NULL;
ret = do_sigprocmask(how, set_ptr, &oldset);
if (!is_error(ret) && arg3) {
if (!(VAR_2 = lock_user(VERIFY_WRITE, arg3, sizeof(target_sigset_t), 0)))
goto efault;
host_to_target_sigset(VAR_2, &oldset);
unlock_user(VAR_2, arg3, sizeof(target_sigset_t));
#ifdef TARGET_NR_sigpending
case TARGET_NR_sigpending:
{
sigset_t set;
ret = get_errno(sigpending(&set));
if (!is_error(ret)) {
if (!(VAR_2 = lock_user(VERIFY_WRITE, arg1, sizeof(target_sigset_t), 0)))
goto efault;
host_to_target_old_sigset(VAR_2, &set);
unlock_user(VAR_2, arg1, sizeof(target_sigset_t));
#endif
case TARGET_NR_rt_sigpending:
{
sigset_t set;
if (arg2 > sizeof(target_sigset_t)) {
ret = get_errno(sigpending(&set));
if (!is_error(ret)) {
if (!(VAR_2 = lock_user(VERIFY_WRITE, arg1, sizeof(target_sigset_t), 0)))
goto efault;
host_to_target_sigset(VAR_2, &set);
unlock_user(VAR_2, arg1, sizeof(target_sigset_t));
#ifdef TARGET_NR_sigsuspend
case TARGET_NR_sigsuspend:
{
TaskState *ts = cpu->opaque;
#if defined(TARGET_ALPHA)
abi_ulong mask = arg1;
target_to_host_old_sigset(&ts->sigsuspend_mask, &mask);
#else
if (!(VAR_2 = lock_user(VERIFY_READ, arg1, sizeof(target_sigset_t), 1)))
goto efault;
target_to_host_old_sigset(&ts->sigsuspend_mask, VAR_2);
unlock_user(VAR_2, arg1, 0);
#endif
ret = get_errno(safe_rt_sigsuspend(&ts->sigsuspend_mask,
SIGSET_T_SIZE));
if (ret != -TARGET_ERESTARTSYS) {
ts->in_sigsuspend = 1;
#endif
case TARGET_NR_rt_sigsuspend:
{
TaskState *ts = cpu->opaque;
if (arg2 != sizeof(target_sigset_t)) {
if (!(VAR_2 = lock_user(VERIFY_READ, arg1, sizeof(target_sigset_t), 1)))
goto efault;
target_to_host_sigset(&ts->sigsuspend_mask, VAR_2);
unlock_user(VAR_2, arg1, 0);
ret = get_errno(safe_rt_sigsuspend(&ts->sigsuspend_mask,
SIGSET_T_SIZE));
if (ret != -TARGET_ERESTARTSYS) {
ts->in_sigsuspend = 1;
case TARGET_NR_rt_sigtimedwait:
{
sigset_t set;
struct timespec uts, *puts;
siginfo_t uinfo;
if (arg4 != sizeof(target_sigset_t)) {
if (!(VAR_2 = lock_user(VERIFY_READ, arg1, sizeof(target_sigset_t), 1)))
goto efault;
target_to_host_sigset(&set, VAR_2);
unlock_user(VAR_2, arg1, 0);
if (arg3) {
puts = &uts;
target_to_host_timespec(puts, arg3);
} else {
puts = NULL;
ret = get_errno(safe_rt_sigtimedwait(&set, &uinfo, puts,
SIGSET_T_SIZE));
if (!is_error(ret)) {
if (arg2) {
VAR_2 = lock_user(VERIFY_WRITE, arg2, sizeof(target_siginfo_t),
0);
if (!VAR_2) {
goto efault;
host_to_target_siginfo(VAR_2, &uinfo);
unlock_user(VAR_2, arg2, sizeof(target_siginfo_t));
ret = host_to_target_signal(ret);
case TARGET_NR_rt_sigqueueinfo:
{
siginfo_t uinfo;
VAR_2 = lock_user(VERIFY_READ, arg3, sizeof(target_siginfo_t), 1);
if (!VAR_2) {
goto efault;
target_to_host_siginfo(&uinfo, VAR_2);
unlock_user(VAR_2, arg1, 0);
ret = get_errno(sys_rt_sigqueueinfo(arg1, arg2, &uinfo));
#ifdef TARGET_NR_sigreturn
case TARGET_NR_sigreturn:
if (block_signals()) {
ret = -TARGET_ERESTARTSYS;
} else {
ret = do_sigreturn(cpu_env);
#endif
case TARGET_NR_rt_sigreturn:
if (block_signals()) {
ret = -TARGET_ERESTARTSYS;
} else {
ret = do_rt_sigreturn(cpu_env);
case TARGET_NR_sethostname:
if (!(VAR_2 = lock_user_string(arg1)))
goto efault;
ret = get_errno(sethostname(VAR_2, arg2));
unlock_user(VAR_2, arg1, 0);
case TARGET_NR_setrlimit:
{
int resource = target_to_host_resource(arg1);
struct target_rlimit *target_rlim;
struct rlimit rlim;
if (!lock_user_struct(VERIFY_READ, target_rlim, arg2, 1))
goto efault;
rlim.rlim_cur = target_to_host_rlim(target_rlim->rlim_cur);
rlim.rlim_max = target_to_host_rlim(target_rlim->rlim_max);
unlock_user_struct(target_rlim, arg2, 0);
ret = get_errno(setrlimit(resource, &rlim));
case TARGET_NR_getrlimit:
{
int resource = target_to_host_resource(arg1);
struct target_rlimit *target_rlim;
struct rlimit rlim;
ret = get_errno(getrlimit(resource, &rlim));
if (!is_error(ret)) {
if (!lock_user_struct(VERIFY_WRITE, target_rlim, arg2, 0))
goto efault;
target_rlim->rlim_cur = host_to_target_rlim(rlim.rlim_cur);
target_rlim->rlim_max = host_to_target_rlim(rlim.rlim_max);
unlock_user_struct(target_rlim, arg2, 1);
case TARGET_NR_getrusage:
{
struct rusage rusage;
ret = get_errno(getrusage(arg1, &rusage));
if (!is_error(ret)) {
ret = host_to_target_rusage(arg2, &rusage);
case TARGET_NR_gettimeofday:
{
struct timeval tv;
ret = get_errno(gettimeofday(&tv, NULL));
if (!is_error(ret)) {
if (copy_to_user_timeval(arg1, &tv))
goto efault;
case TARGET_NR_settimeofday:
{
struct timeval tv, *ptv = NULL;
struct timezone tz, *ptz = NULL;
if (arg1) {
if (copy_from_user_timeval(&tv, arg1)) {
goto efault;
ptv = &tv;
if (arg2) {
if (copy_from_user_timezone(&tz, arg2)) {
goto efault;
ptz = &tz;
ret = get_errno(settimeofday(ptv, ptz));
#if defined(TARGET_NR_select)
case TARGET_NR_select:
#if defined(TARGET_S390X) || defined(TARGET_ALPHA)
ret = do_select(arg1, arg2, arg3, arg4, arg5);
#else
{
struct target_sel_arg_struct *sel;
abi_ulong inp, outp, exp, tvp;
long nsel;
if (!lock_user_struct(VERIFY_READ, sel, arg1, 1))
goto efault;
nsel = tswapal(sel->n);
inp = tswapal(sel->inp);
outp = tswapal(sel->outp);
exp = tswapal(sel->exp);
tvp = tswapal(sel->tvp);
unlock_user_struct(sel, arg1, 0);
ret = do_select(nsel, inp, outp, exp, tvp);
#endif
#endif
#ifdef TARGET_NR_pselect6
case TARGET_NR_pselect6:
{
abi_long rfd_addr, wfd_addr, efd_addr, n, ts_addr;
fd_set rfds, wfds, efds;
fd_set *rfds_ptr, *wfds_ptr, *efds_ptr;
struct timespec ts, *ts_ptr;
sigset_t set;
struct {
sigset_t *set;
size_t size;
} sig, *sig_ptr;
abi_ulong arg_sigset, arg_sigsize, *arg7;
target_sigset_t *target_sigset;
n = arg1;
rfd_addr = arg2;
wfd_addr = arg3;
efd_addr = arg4;
ts_addr = arg5;
ret = copy_from_user_fdset_ptr(&rfds, &rfds_ptr, rfd_addr, n);
if (ret) {
goto fail;
ret = copy_from_user_fdset_ptr(&wfds, &wfds_ptr, wfd_addr, n);
if (ret) {
goto fail;
ret = copy_from_user_fdset_ptr(&efds, &efds_ptr, efd_addr, n);
if (ret) {
goto fail;
if (ts_addr) {
if (target_to_host_timespec(&ts, ts_addr)) {
goto efault;
ts_ptr = &ts;
} else {
ts_ptr = NULL;
if (arg6) {
sig_ptr = &sig;
sig.size = SIGSET_T_SIZE;
arg7 = lock_user(VERIFY_READ, arg6, sizeof(*arg7) * 2, 1);
if (!arg7) {
goto efault;
arg_sigset = tswapal(arg7[0]);
arg_sigsize = tswapal(arg7[1]);
unlock_user(arg7, arg6, 0);
if (arg_sigset) {
sig.set = &set;
if (arg_sigsize != sizeof(*target_sigset)) {
goto fail;
target_sigset = lock_user(VERIFY_READ, arg_sigset,
sizeof(*target_sigset), 1);
if (!target_sigset) {
goto efault;
target_to_host_sigset(&set, target_sigset);
unlock_user(target_sigset, arg_sigset, 0);
} else {
sig.set = NULL;
} else {
sig_ptr = NULL;
ret = get_errno(safe_pselect6(n, rfds_ptr, wfds_ptr, efds_ptr,
ts_ptr, sig_ptr));
if (!is_error(ret)) {
if (rfd_addr && copy_to_user_fdset(rfd_addr, &rfds, n))
goto efault;
if (wfd_addr && copy_to_user_fdset(wfd_addr, &wfds, n))
goto efault;
if (efd_addr && copy_to_user_fdset(efd_addr, &efds, n))
goto efault;
if (ts_addr && host_to_target_timespec(ts_addr, &ts))
goto efault;
#endif
#ifdef TARGET_NR_symlink
case TARGET_NR_symlink:
{
void *p2;
VAR_2 = lock_user_string(arg1);
p2 = lock_user_string(arg2);
if (!VAR_2 || !p2)
ret = -TARGET_EFAULT;
else
ret = get_errno(symlink(VAR_2, p2));
unlock_user(p2, arg2, 0);
unlock_user(VAR_2, arg1, 0);
#endif
#if defined(TARGET_NR_symlinkat)
case TARGET_NR_symlinkat:
{
void *p2;
VAR_2 = lock_user_string(arg1);
p2 = lock_user_string(arg3);
if (!VAR_2 || !p2)
ret = -TARGET_EFAULT;
else
ret = get_errno(symlinkat(VAR_2, arg2, p2));
unlock_user(p2, arg3, 0);
unlock_user(VAR_2, arg1, 0);
#endif
#ifdef TARGET_NR_oldlstat
case TARGET_NR_oldlstat:
goto unimplemented;
#endif
#ifdef TARGET_NR_readlink
case TARGET_NR_readlink:
{
void *p2;
VAR_2 = lock_user_string(arg1);
p2 = lock_user(VERIFY_WRITE, arg2, arg3, 0);
if (!VAR_2 || !p2) {
ret = -TARGET_EFAULT;
} else if (!arg3) {
} else if (is_proc_myself((const char *)VAR_2, "exe")) {
char real[PATH_MAX], *temp;
temp = realpath(exec_path, real);
if (temp == NULL) {
ret = get_errno(-1);
} else {
ret = MIN(strlen(real), arg3);
memcpy(p2, real, ret);
} else {
ret = get_errno(readlink(path(VAR_2), p2, arg3));
unlock_user(p2, arg2, ret);
unlock_user(VAR_2, arg1, 0);
#endif
#if defined(TARGET_NR_readlinkat)
case TARGET_NR_readlinkat:
{
void *p2;
VAR_2 = lock_user_string(arg2);
p2 = lock_user(VERIFY_WRITE, arg3, arg4, 0);
if (!VAR_2 || !p2) {
ret = -TARGET_EFAULT;
} else if (is_proc_myself((const char *)VAR_2, "exe")) {
char real[PATH_MAX], *temp;
temp = realpath(exec_path, real);
ret = temp == NULL ? get_errno(-1) : strlen(real) ;
snprintf((char *)p2, arg4, "%s", real);
} else {
ret = get_errno(readlinkat(arg1, path(VAR_2), p2, arg4));
unlock_user(p2, arg3, ret);
unlock_user(VAR_2, arg2, 0);
#endif
#ifdef TARGET_NR_uselib
case TARGET_NR_uselib:
goto unimplemented;
#endif
#ifdef TARGET_NR_swapon
case TARGET_NR_swapon:
if (!(VAR_2 = lock_user_string(arg1)))
goto efault;
ret = get_errno(swapon(VAR_2, arg2));
unlock_user(VAR_2, arg1, 0);
#endif
case TARGET_NR_reboot:
if (arg3 == LINUX_REBOOT_CMD_RESTART2) {
VAR_2 = lock_user_string(arg4);
if (!VAR_2) {
goto efault;
ret = get_errno(reboot(arg1, arg2, arg3, VAR_2));
unlock_user(VAR_2, arg4, 0);
} else {
ret = get_errno(reboot(arg1, arg2, arg3, NULL));
#ifdef TARGET_NR_readdir
case TARGET_NR_readdir:
goto unimplemented;
#endif
#ifdef TARGET_NR_mmap
case TARGET_NR_mmap:
#if (defined(TARGET_I386) && defined(TARGET_ABI32)) || \
(defined(TARGET_ARM) && defined(TARGET_ABI32)) || \
defined(TARGET_M68K) || defined(TARGET_CRIS) || defined(TARGET_MICROBLAZE) \
|| defined(TARGET_S390X)
{
abi_ulong *v;
abi_ulong v1, v2, v3, v4, v5, v6;
if (!(v = lock_user(VERIFY_READ, arg1, 6 * sizeof(abi_ulong), 1)))
goto efault;
v1 = tswapal(v[0]);
v2 = tswapal(v[1]);
v3 = tswapal(v[2]);
v4 = tswapal(v[3]);
v5 = tswapal(v[4]);
v6 = tswapal(v[5]);
unlock_user(v, arg1, 0);
ret = get_errno(target_mmap(v1, v2, v3,
target_to_host_bitmask(v4, mmap_flags_tbl),
v5, v6));
#else
ret = get_errno(target_mmap(arg1, arg2, arg3,
target_to_host_bitmask(arg4, mmap_flags_tbl),
arg5,
arg6));
#endif
#endif
#ifdef TARGET_NR_mmap2
case TARGET_NR_mmap2:
#ifndef MMAP_SHIFT
#define MMAP_SHIFT 12
#endif
ret = get_errno(target_mmap(arg1, arg2, arg3,
target_to_host_bitmask(arg4, mmap_flags_tbl),
arg5,
arg6 << MMAP_SHIFT));
#endif
case TARGET_NR_munmap:
ret = get_errno(target_munmap(arg1, arg2));
case TARGET_NR_mprotect:
{
TaskState *ts = cpu->opaque;
if ((arg3 & PROT_GROWSDOWN)
&& arg1 >= ts->info->stack_limit
&& arg1 <= ts->info->start_stack) {
arg3 &= ~PROT_GROWSDOWN;
arg2 = arg2 + arg1 - ts->info->stack_limit;
arg1 = ts->info->stack_limit;
ret = get_errno(target_mprotect(arg1, arg2, arg3));
#ifdef TARGET_NR_mremap
case TARGET_NR_mremap:
ret = get_errno(target_mremap(arg1, arg2, arg3, arg4, arg5));
#endif
#ifdef TARGET_NR_msync
case TARGET_NR_msync:
ret = get_errno(msync(g2h(arg1), arg2, arg3));
#endif
#ifdef TARGET_NR_mlock
case TARGET_NR_mlock:
ret = get_errno(mlock(g2h(arg1), arg2));
#endif
#ifdef TARGET_NR_munlock
case TARGET_NR_munlock:
ret = get_errno(munlock(g2h(arg1), arg2));
#endif
#ifdef TARGET_NR_mlockall
case TARGET_NR_mlockall:
ret = get_errno(mlockall(target_to_host_mlockall_arg(arg1)));
#endif
#ifdef TARGET_NR_munlockall
case TARGET_NR_munlockall:
ret = get_errno(munlockall());
#endif
case TARGET_NR_truncate:
if (!(VAR_2 = lock_user_string(arg1)))
goto efault;
ret = get_errno(truncate(VAR_2, arg2));
unlock_user(VAR_2, arg1, 0);
case TARGET_NR_ftruncate:
ret = get_errno(ftruncate(arg1, arg2));
case TARGET_NR_fchmod:
ret = get_errno(fchmod(arg1, arg2));
#if defined(TARGET_NR_fchmodat)
case TARGET_NR_fchmodat:
if (!(VAR_2 = lock_user_string(arg2)))
goto efault;
ret = get_errno(fchmodat(arg1, VAR_2, arg3, 0));
unlock_user(VAR_2, arg2, 0);
#endif
case TARGET_NR_getpriority:
errno = 0;
ret = getpriority(arg1, arg2);
if (ret == -1 && errno != 0) {
ret = -host_to_target_errno(errno);
#ifdef TARGET_ALPHA
((CPUAlphaState *)cpu_env)->ir[IR_V0] = 0;
#else
ret = 20 - ret;
#endif
case TARGET_NR_setpriority:
ret = get_errno(setpriority(arg1, arg2, arg3));
#ifdef TARGET_NR_profil
case TARGET_NR_profil:
goto unimplemented;
#endif
case TARGET_NR_statfs:
if (!(VAR_2 = lock_user_string(arg1)))
goto efault;
ret = get_errno(statfs(path(VAR_2), &VAR_1));
unlock_user(VAR_2, arg1, 0);
convert_statfs:
if (!is_error(ret)) {
struct target_statfs *target_stfs;
if (!lock_user_struct(VERIFY_WRITE, target_stfs, arg2, 0))
goto efault;
__put_user(VAR_1.f_type, &target_stfs->f_type);
__put_user(VAR_1.f_bsize, &target_stfs->f_bsize);
__put_user(VAR_1.f_blocks, &target_stfs->f_blocks);
__put_user(VAR_1.f_bfree, &target_stfs->f_bfree);
__put_user(VAR_1.f_bavail, &target_stfs->f_bavail);
__put_user(VAR_1.f_files, &target_stfs->f_files);
__put_user(VAR_1.f_ffree, &target_stfs->f_ffree);
__put_user(VAR_1.f_fsid.__val[0], &target_stfs->f_fsid.val[0]);
__put_user(VAR_1.f_fsid.__val[1], &target_stfs->f_fsid.val[1]);
__put_user(VAR_1.f_namelen, &target_stfs->f_namelen);
__put_user(VAR_1.f_frsize, &target_stfs->f_frsize);
memset(target_stfs->f_spare, 0, sizeof(target_stfs->f_spare));
unlock_user_struct(target_stfs, arg2, 1);
case TARGET_NR_fstatfs:
ret = get_errno(fstatfs(arg1, &VAR_1));
goto convert_statfs;
#ifdef TARGET_NR_statfs64
case TARGET_NR_statfs64:
if (!(VAR_2 = lock_user_string(arg1)))
goto efault;
ret = get_errno(statfs(path(VAR_2), &VAR_1));
unlock_user(VAR_2, arg1, 0);
convert_statfs64:
if (!is_error(ret)) {
struct target_statfs64 *target_stfs;
if (!lock_user_struct(VERIFY_WRITE, target_stfs, arg3, 0))
goto efault;
__put_user(VAR_1.f_type, &target_stfs->f_type);
__put_user(VAR_1.f_bsize, &target_stfs->f_bsize);
__put_user(VAR_1.f_blocks, &target_stfs->f_blocks);
__put_user(VAR_1.f_bfree, &target_stfs->f_bfree);
__put_user(VAR_1.f_bavail, &target_stfs->f_bavail);
__put_user(VAR_1.f_files, &target_stfs->f_files);
__put_user(VAR_1.f_ffree, &target_stfs->f_ffree);
__put_user(VAR_1.f_fsid.__val[0], &target_stfs->f_fsid.val[0]);
__put_user(VAR_1.f_fsid.__val[1], &target_stfs->f_fsid.val[1]);
__put_user(VAR_1.f_namelen, &target_stfs->f_namelen);
__put_user(VAR_1.f_frsize, &target_stfs->f_frsize);
memset(target_stfs->f_spare, 0, sizeof(target_stfs->f_spare));
unlock_user_struct(target_stfs, arg3, 1);
case TARGET_NR_fstatfs64:
ret = get_errno(fstatfs(arg1, &VAR_1));
goto convert_statfs64;
#endif
#ifdef TARGET_NR_ioperm
case TARGET_NR_ioperm:
goto unimplemented;
#endif
#ifdef TARGET_NR_socketcall
case TARGET_NR_socketcall:
ret = do_socketcall(arg1, arg2);
#endif
#ifdef TARGET_NR_accept
case TARGET_NR_accept:
ret = do_accept4(arg1, arg2, arg3, 0);
#endif
#ifdef TARGET_NR_accept4
case TARGET_NR_accept4:
ret = do_accept4(arg1, arg2, arg3, arg4);
#endif
#ifdef TARGET_NR_bind
case TARGET_NR_bind:
ret = do_bind(arg1, arg2, arg3);
#endif
#ifdef TARGET_NR_connect
case TARGET_NR_connect:
ret = do_connect(arg1, arg2, arg3);
#endif
#ifdef TARGET_NR_getpeername
case TARGET_NR_getpeername:
ret = do_getpeername(arg1, arg2, arg3);
#endif
#ifdef TARGET_NR_getsockname
case TARGET_NR_getsockname:
ret = do_getsockname(arg1, arg2, arg3);
#endif
#ifdef TARGET_NR_getsockopt
case TARGET_NR_getsockopt:
ret = do_getsockopt(arg1, arg2, arg3, arg4, arg5);
#endif
#ifdef TARGET_NR_listen
case TARGET_NR_listen:
ret = get_errno(listen(arg1, arg2));
#endif
#ifdef TARGET_NR_recv
case TARGET_NR_recv:
ret = do_recvfrom(arg1, arg2, arg3, arg4, 0, 0);
#endif
#ifdef TARGET_NR_recvfrom
case TARGET_NR_recvfrom:
ret = do_recvfrom(arg1, arg2, arg3, arg4, arg5, arg6);
#endif
#ifdef TARGET_NR_recvmsg
case TARGET_NR_recvmsg:
ret = do_sendrecvmsg(arg1, arg2, arg3, 0);
#endif
#ifdef TARGET_NR_send
case TARGET_NR_send:
ret = do_sendto(arg1, arg2, arg3, arg4, 0, 0);
#endif
#ifdef TARGET_NR_sendmsg
case TARGET_NR_sendmsg:
ret = do_sendrecvmsg(arg1, arg2, arg3, 1);
#endif
#ifdef TARGET_NR_sendmmsg
case TARGET_NR_sendmmsg:
ret = do_sendrecvmmsg(arg1, arg2, arg3, arg4, 1);
case TARGET_NR_recvmmsg:
ret = do_sendrecvmmsg(arg1, arg2, arg3, arg4, 0);
#endif
#ifdef TARGET_NR_sendto
case TARGET_NR_sendto:
ret = do_sendto(arg1, arg2, arg3, arg4, arg5, arg6);
#endif
#ifdef TARGET_NR_shutdown
case TARGET_NR_shutdown:
ret = get_errno(shutdown(arg1, arg2));
#endif
#if defined(TARGET_NR_getrandom) && defined(__NR_getrandom)
case TARGET_NR_getrandom:
VAR_2 = lock_user(VERIFY_WRITE, arg1, arg2, 0);
if (!VAR_2) {
goto efault;
ret = get_errno(getrandom(VAR_2, arg2, arg3));
unlock_user(VAR_2, arg1, ret);
#endif
#ifdef TARGET_NR_socket
case TARGET_NR_socket:
ret = do_socket(arg1, arg2, arg3);
fd_trans_unregister(ret);
#endif
#ifdef TARGET_NR_socketpair
case TARGET_NR_socketpair:
ret = do_socketpair(arg1, arg2, arg3, arg4);
#endif
#ifdef TARGET_NR_setsockopt
case TARGET_NR_setsockopt:
ret = do_setsockopt(arg1, arg2, arg3, arg4, (socklen_t) arg5);
#endif
case TARGET_NR_syslog:
if (!(VAR_2 = lock_user_string(arg2)))
goto efault;
ret = get_errno(sys_syslog((int)arg1, VAR_2, (int)arg3));
unlock_user(VAR_2, arg2, 0);
case TARGET_NR_setitimer:
{
struct itimerval value, ovalue, *pvalue;
if (arg2) {
pvalue = &value;
if (copy_from_user_timeval(&pvalue->it_interval, arg2)
|| copy_from_user_timeval(&pvalue->it_value,
arg2 + sizeof(struct target_timeval)))
goto efault;
} else {
pvalue = NULL;
ret = get_errno(setitimer(arg1, pvalue, &ovalue));
if (!is_error(ret) && arg3) {
if (copy_to_user_timeval(arg3,
&ovalue.it_interval)
|| copy_to_user_timeval(arg3 + sizeof(struct target_timeval),
&ovalue.it_value))
goto efault;
case TARGET_NR_getitimer:
{
struct itimerval value;
ret = get_errno(getitimer(arg1, &value));
if (!is_error(ret) && arg2) {
if (copy_to_user_timeval(arg2,
&value.it_interval)
|| copy_to_user_timeval(arg2 + sizeof(struct target_timeval),
&value.it_value))
goto efault;
#ifdef TARGET_NR_stat
case TARGET_NR_stat:
if (!(VAR_2 = lock_user_string(arg1)))
goto efault;
ret = get_errno(stat(path(VAR_2), &VAR_0));
unlock_user(VAR_2, arg1, 0);
goto do_stat;
#endif
#ifdef TARGET_NR_lstat
case TARGET_NR_lstat:
if (!(VAR_2 = lock_user_string(arg1)))
goto efault;
ret = get_errno(lstat(path(VAR_2), &VAR_0));
unlock_user(VAR_2, arg1, 0);
goto do_stat;
#endif
case TARGET_NR_fstat:
{
ret = get_errno(fstat(arg1, &VAR_0));
#if defined(TARGET_NR_stat) || defined(TARGET_NR_lstat)
do_stat:
#endif
if (!is_error(ret)) {
struct target_stat *target_st;
if (!lock_user_struct(VERIFY_WRITE, target_st, arg2, 0))
goto efault;
memset(target_st, 0, sizeof(*target_st));
__put_user(VAR_0.st_dev, &target_st->st_dev);
__put_user(VAR_0.st_ino, &target_st->st_ino);
__put_user(VAR_0.st_mode, &target_st->st_mode);
__put_user(VAR_0.st_uid, &target_st->st_uid);
__put_user(VAR_0.st_gid, &target_st->st_gid);
__put_user(VAR_0.st_nlink, &target_st->st_nlink);
__put_user(VAR_0.st_rdev, &target_st->st_rdev);
__put_user(VAR_0.st_size, &target_st->st_size);
__put_user(VAR_0.st_blksize, &target_st->st_blksize);
__put_user(VAR_0.st_blocks, &target_st->st_blocks);
__put_user(VAR_0.st_atime, &target_st->target_st_atime);
__put_user(VAR_0.st_mtime, &target_st->target_st_mtime);
__put_user(VAR_0.st_ctime, &target_st->target_st_ctime);
unlock_user_struct(target_st, arg2, 1);
#ifdef TARGET_NR_olduname
case TARGET_NR_olduname:
goto unimplemented;
#endif
#ifdef TARGET_NR_iopl
case TARGET_NR_iopl:
goto unimplemented;
#endif
case TARGET_NR_vhangup:
ret = get_errno(vhangup());
#ifdef TARGET_NR_idle
case TARGET_NR_idle:
goto unimplemented;
#endif
#ifdef TARGET_NR_syscall
case TARGET_NR_syscall:
ret = FUNC_0(cpu_env, arg1 & 0xffff, arg2, arg3, arg4, arg5,
arg6, arg7, arg8, 0);
#endif
case TARGET_NR_wait4:
{
int status;
abi_long status_ptr = arg2;
struct rusage rusage, *rusage_ptr;
abi_ulong target_rusage = arg4;
abi_long rusage_err;
if (target_rusage)
rusage_ptr = &rusage;
else
rusage_ptr = NULL;
ret = get_errno(safe_wait4(arg1, &status, arg3, rusage_ptr));
if (!is_error(ret)) {
if (status_ptr && ret) {
status = host_to_target_waitstatus(status);
if (put_user_s32(status, status_ptr))
goto efault;
if (target_rusage) {
rusage_err = host_to_target_rusage(target_rusage, &rusage);
if (rusage_err) {
ret = rusage_err;
#ifdef TARGET_NR_swapoff
case TARGET_NR_swapoff:
if (!(VAR_2 = lock_user_string(arg1)))
goto efault;
ret = get_errno(swapoff(VAR_2));
unlock_user(VAR_2, arg1, 0);
#endif
case TARGET_NR_sysinfo:
{
struct target_sysinfo *target_value;
struct sysinfo value;
ret = get_errno(sysinfo(&value));
if (!is_error(ret) && arg1)
{
if (!lock_user_struct(VERIFY_WRITE, target_value, arg1, 0))
goto efault;
__put_user(value.uptime, &target_value->uptime);
__put_user(value.loads[0], &target_value->loads[0]);
__put_user(value.loads[1], &target_value->loads[1]);
__put_user(value.loads[2], &target_value->loads[2]);
__put_user(value.totalram, &target_value->totalram);
__put_user(value.freeram, &target_value->freeram);
__put_user(value.sharedram, &target_value->sharedram);
__put_user(value.bufferram, &target_value->bufferram);
__put_user(value.totalswap, &target_value->totalswap);
__put_user(value.freeswap, &target_value->freeswap);
__put_user(value.procs, &target_value->procs);
__put_user(value.totalhigh, &target_value->totalhigh);
__put_user(value.freehigh, &target_value->freehigh);
__put_user(value.mem_unit, &target_value->mem_unit);
unlock_user_struct(target_value, arg1, 1);
#ifdef TARGET_NR_ipc
case TARGET_NR_ipc:
ret = do_ipc(arg1, arg2, arg3, arg4, arg5, arg6);
#endif
#ifdef TARGET_NR_semget
case TARGET_NR_semget:
ret = get_errno(semget(arg1, arg2, arg3));
#endif
#ifdef TARGET_NR_semop
case TARGET_NR_semop:
ret = do_semop(arg1, arg2, arg3);
#endif
#ifdef TARGET_NR_semctl
case TARGET_NR_semctl:
ret = do_semctl(arg1, arg2, arg3, arg4);
#endif
#ifdef TARGET_NR_msgctl
case TARGET_NR_msgctl:
ret = do_msgctl(arg1, arg2, arg3);
#endif
#ifdef TARGET_NR_msgget
case TARGET_NR_msgget:
ret = get_errno(msgget(arg1, arg2));
#endif
#ifdef TARGET_NR_msgrcv
case TARGET_NR_msgrcv:
ret = do_msgrcv(arg1, arg2, arg3, arg4, arg5);
#endif
#ifdef TARGET_NR_msgsnd
case TARGET_NR_msgsnd:
ret = do_msgsnd(arg1, arg2, arg3, arg4);
#endif
#ifdef TARGET_NR_shmget
case TARGET_NR_shmget:
ret = get_errno(shmget(arg1, arg2, arg3));
#endif
#ifdef TARGET_NR_shmctl
case TARGET_NR_shmctl:
ret = do_shmctl(arg1, arg2, arg3);
#endif
#ifdef TARGET_NR_shmat
case TARGET_NR_shmat:
ret = do_shmat(arg1, arg2, arg3);
#endif
#ifdef TARGET_NR_shmdt
case TARGET_NR_shmdt:
ret = do_shmdt(arg1);
#endif
case TARGET_NR_fsync:
ret = get_errno(fsync(arg1));
case TARGET_NR_clone:
#if defined(TARGET_MICROBLAZE)
ret = get_errno(do_fork(cpu_env, arg1, arg2, arg4, arg6, arg5));
#elif defined(TARGET_CLONE_BACKWARDS)
ret = get_errno(do_fork(cpu_env, arg1, arg2, arg3, arg4, arg5));
#elif defined(TARGET_CLONE_BACKWARDS2)
ret = get_errno(do_fork(cpu_env, arg2, arg1, arg3, arg5, arg4));
#else
ret = get_errno(do_fork(cpu_env, arg1, arg2, arg3, arg5, arg4));
#endif
#ifdef __NR_exit_group
case TARGET_NR_exit_group:
#ifdef TARGET_GPROF
_mcleanup();
#endif
gdb_exit(cpu_env, arg1);
ret = get_errno(exit_group(arg1));
#endif
case TARGET_NR_setdomainname:
if (!(VAR_2 = lock_user_string(arg1)))
goto efault;
ret = get_errno(setdomainname(VAR_2, arg2));
unlock_user(VAR_2, arg1, 0);
case TARGET_NR_uname:
{
struct new_utsname * buf;
if (!lock_user_struct(VERIFY_WRITE, buf, arg1, 0))
goto efault;
ret = get_errno(sys_uname(buf));
if (!is_error(ret)) {
strcpy (buf->machine, cpu_to_uname_machine(cpu_env));
if (qemu_uname_release && *qemu_uname_release) {
g_strlcpy(buf->release, qemu_uname_release,
sizeof(buf->release));
unlock_user_struct(buf, arg1, 1);
#ifdef TARGET_I386
case TARGET_NR_modify_ldt:
ret = do_modify_ldt(cpu_env, arg1, arg2, arg3);
#if !defined(TARGET_X86_64)
case TARGET_NR_vm86old:
goto unimplemented;
case TARGET_NR_vm86:
ret = do_vm86(cpu_env, arg1, arg2);
#endif
#endif
case TARGET_NR_adjtimex:
goto unimplemented;
#ifdef TARGET_NR_create_module
case TARGET_NR_create_module:
#endif
case TARGET_NR_init_module:
case TARGET_NR_delete_module:
#ifdef TARGET_NR_get_kernel_syms
case TARGET_NR_get_kernel_syms:
#endif
goto unimplemented;
case TARGET_NR_quotactl:
goto unimplemented;
case TARGET_NR_getpgid:
ret = get_errno(getpgid(arg1));
case TARGET_NR_fchdir:
ret = get_errno(fchdir(arg1));
#ifdef TARGET_NR_bdflush
case TARGET_NR_bdflush:
goto unimplemented;
#endif
#ifdef TARGET_NR_sysfs
case TARGET_NR_sysfs:
goto unimplemented;
#endif
case TARGET_NR_personality:
ret = get_errno(personality(arg1));
#ifdef TARGET_NR_afs_syscall
case TARGET_NR_afs_syscall:
goto unimplemented;
#endif
#ifdef TARGET_NR__llseek
case TARGET_NR__llseek:
{
int64_t res;
#if !defined(__NR_llseek)
res = lseek(arg1, ((uint64_t)arg2 << 32) | (abi_ulong)arg3, arg5);
if (res == -1) {
ret = get_errno(res);
} else {
ret = 0;
#else
ret = get_errno(_llseek(arg1, arg2, arg3, &res, arg5));
#endif
if ((ret == 0) && put_user_s64(res, arg4)) {
goto efault;
#endif
#ifdef TARGET_NR_getdents
case TARGET_NR_getdents:
#ifdef __NR_getdents
#if TARGET_ABI_BITS == 32 && HOST_LONG_BITS == 64
{
struct target_dirent *target_dirp;
struct linux_dirent *dirp;
abi_long count = arg3;
dirp = g_try_malloc(count);
if (!dirp) {
ret = -TARGET_ENOMEM;
goto fail;
ret = get_errno(sys_getdents(arg1, dirp, count));
if (!is_error(ret)) {
struct linux_dirent *de;
struct target_dirent *tde;
int len = ret;
int reclen, treclen;
int count1, tnamelen;
count1 = 0;
de = dirp;
if (!(target_dirp = lock_user(VERIFY_WRITE, arg2, count, 0)))
goto efault;
tde = target_dirp;
while (len > 0) {
reclen = de->d_reclen;
tnamelen = reclen - offsetof(struct linux_dirent, d_name);
assert(tnamelen >= 0);
treclen = tnamelen + offsetof(struct target_dirent, d_name);
assert(count1 + treclen <= count);
tde->d_reclen = tswap16(treclen);
tde->d_ino = tswapal(de->d_ino);
tde->d_off = tswapal(de->d_off);
memcpy(tde->d_name, de->d_name, tnamelen);
de = (struct linux_dirent *)((char *)de + reclen);
len -= reclen;
tde = (struct target_dirent *)((char *)tde + treclen);
count1 += treclen;
ret = count1;
unlock_user(target_dirp, arg2, ret);
g_free(dirp);
#else
{
struct linux_dirent *dirp;
abi_long count = arg3;
if (!(dirp = lock_user(VERIFY_WRITE, arg2, count, 0)))
goto efault;
ret = get_errno(sys_getdents(arg1, dirp, count));
if (!is_error(ret)) {
struct linux_dirent *de;
int len = ret;
int reclen;
de = dirp;
while (len > 0) {
reclen = de->d_reclen;
if (reclen > len)
de->d_reclen = tswap16(reclen);
tswapls(&de->d_ino);
tswapls(&de->d_off);
de = (struct linux_dirent *)((char *)de + reclen);
len -= reclen;
unlock_user(dirp, arg2, ret);
#endif
#else
{
struct linux_dirent64 *dirp;
abi_long count = arg3;
dirp = lock_user(VERIFY_WRITE, arg2, count, 0);
if (!dirp) {
goto efault;
ret = get_errno(sys_getdents64(arg1, dirp, count));
if (!is_error(ret)) {
struct linux_dirent64 *de;
struct target_dirent *tde;
int len = ret;
int tlen = 0;
de = dirp;
tde = (struct target_dirent *)dirp;
while (len > 0) {
int namelen, treclen;
int reclen = de->d_reclen;
uint64_t ino = de->d_ino;
int64_t off = de->d_off;
uint8_t type = de->d_type;
namelen = strlen(de->d_name);
treclen = offsetof(struct target_dirent, d_name)
+ namelen + 2;
treclen = QEMU_ALIGN_UP(treclen, sizeof(abi_long));
memmove(tde->d_name, de->d_name, namelen + 1);
tde->d_ino = tswapal(ino);
tde->d_off = tswapal(off);
tde->d_reclen = tswap16(treclen);
*(((char *)tde) + treclen - 1) = type;
de = (struct linux_dirent64 *)((char *)de + reclen);
tde = (struct target_dirent *)((char *)tde + treclen);
len -= reclen;
tlen += treclen;
ret = tlen;
unlock_user(dirp, arg2, ret);
#endif
#endif
#if defined(TARGET_NR_getdents64) && defined(__NR_getdents64)
case TARGET_NR_getdents64:
{
struct linux_dirent64 *dirp;
abi_long count = arg3;
if (!(dirp = lock_user(VERIFY_WRITE, arg2, count, 0)))
goto efault;
ret = get_errno(sys_getdents64(arg1, dirp, count));
if (!is_error(ret)) {
struct linux_dirent64 *de;
int len = ret;
int reclen;
de = dirp;
while (len > 0) {
reclen = de->d_reclen;
if (reclen > len)
de->d_reclen = tswap16(reclen);
tswap64s((uint64_t *)&de->d_ino);
tswap64s((uint64_t *)&de->d_off);
de = (struct linux_dirent64 *)((char *)de + reclen);
len -= reclen;
unlock_user(dirp, arg2, ret);
#endif
#if defined(TARGET_NR__newselect)
case TARGET_NR__newselect:
ret = do_select(arg1, arg2, arg3, arg4, arg5);
#endif
#if defined(TARGET_NR_poll) || defined(TARGET_NR_ppoll)
# ifdef TARGET_NR_poll
case TARGET_NR_poll:
# endif
# ifdef TARGET_NR_ppoll
case TARGET_NR_ppoll:
# endif
{
struct target_pollfd *target_pfd;
unsigned int nfds = arg2;
struct pollfd *pfd;
unsigned int i;
pfd = NULL;
target_pfd = NULL;
if (nfds) {
target_pfd = lock_user(VERIFY_WRITE, arg1,
sizeof(struct target_pollfd) * nfds, 1);
if (!target_pfd) {
goto efault;
pfd = alloca(sizeof(struct pollfd) * nfds);
for (i = 0; i < nfds; i++) {
pfd[i].fd = tswap32(target_pfd[i].fd);
pfd[i].events = tswap16(target_pfd[i].events);
switch (num) {
# ifdef TARGET_NR_ppoll
case TARGET_NR_ppoll:
{
struct timespec _timeout_ts, *timeout_ts = &_timeout_ts;
target_sigset_t *target_set;
sigset_t _set, *set = &_set;
if (arg3) {
if (target_to_host_timespec(timeout_ts, arg3)) {
unlock_user(target_pfd, arg1, 0);
goto efault;
} else {
timeout_ts = NULL;
if (arg4) {
if (arg5 != sizeof(target_sigset_t)) {
unlock_user(target_pfd, arg1, 0);
target_set = lock_user(VERIFY_READ, arg4, sizeof(target_sigset_t), 1);
if (!target_set) {
unlock_user(target_pfd, arg1, 0);
goto efault;
target_to_host_sigset(set, target_set);
} else {
set = NULL;
ret = get_errno(safe_ppoll(pfd, nfds, timeout_ts,
set, SIGSET_T_SIZE));
if (!is_error(ret) && arg3) {
host_to_target_timespec(arg3, timeout_ts);
if (arg4) {
unlock_user(target_set, arg4, 0);
# endif
# ifdef TARGET_NR_poll
case TARGET_NR_poll:
{
struct timespec ts, *pts;
if (arg3 >= 0) {
ts.tv_sec = arg3 / 1000;
ts.tv_nsec = (arg3 % 1000) * 1000000LL;
pts = &ts;
} else {
pts = NULL;
ret = get_errno(safe_ppoll(pfd, nfds, pts, NULL, 0));
# endif
default:
g_assert_not_reached();
if (!is_error(ret)) {
for(i = 0; i < nfds; i++) {
target_pfd[i].revents = tswap16(pfd[i].revents);
unlock_user(target_pfd, arg1, sizeof(struct target_pollfd) * nfds);
#endif
case TARGET_NR_flock:
ret = get_errno(safe_flock(arg1, arg2));
case TARGET_NR_readv:
{
struct iovec *vec = lock_iovec(VERIFY_WRITE, arg2, arg3, 0);
if (vec != NULL) {
ret = get_errno(safe_readv(arg1, vec, arg3));
unlock_iovec(vec, arg2, arg3, 1);
} else {
ret = -host_to_target_errno(errno);
case TARGET_NR_writev:
{
struct iovec *vec = lock_iovec(VERIFY_READ, arg2, arg3, 1);
if (vec != NULL) {
ret = get_errno(safe_writev(arg1, vec, arg3));
unlock_iovec(vec, arg2, arg3, 0);
} else {
ret = -host_to_target_errno(errno);
case TARGET_NR_getsid:
ret = get_errno(getsid(arg1));
#if defined(TARGET_NR_fdatasync)
case TARGET_NR_fdatasync:
ret = get_errno(fdatasync(arg1));
#endif
#ifdef TARGET_NR__sysctl
case TARGET_NR__sysctl:
ret = -TARGET_ENOTDIR;
#endif
case TARGET_NR_sched_getaffinity:
{
unsigned int mask_size;
unsigned long *mask;
if (arg2 & (sizeof(abi_ulong) - 1)) {
mask_size = (arg2 + (sizeof(*mask) - 1)) & ~(sizeof(*mask) - 1);
mask = alloca(mask_size);
ret = get_errno(sys_sched_getaffinity(arg1, mask_size, mask));
if (!is_error(ret)) {
if (ret > arg2) {
int numcpus = sysconf(_SC_NPROCESSORS_CONF);
if (numcpus > arg2 * 8) {
ret = arg2;
if (copy_to_user(arg3, mask, ret)) {
goto efault;
case TARGET_NR_sched_setaffinity:
{
unsigned int mask_size;
unsigned long *mask;
if (arg2 & (sizeof(abi_ulong) - 1)) {
mask_size = (arg2 + (sizeof(*mask) - 1)) & ~(sizeof(*mask) - 1);
mask = alloca(mask_size);
if (!lock_user_struct(VERIFY_READ, VAR_2, arg3, 1)) {
goto efault;
memcpy(mask, VAR_2, arg2);
unlock_user_struct(VAR_2, arg2, 0);
ret = get_errno(sys_sched_setaffinity(arg1, mask_size, mask));
case TARGET_NR_sched_setparam:
{
struct sched_param *target_schp;
struct sched_param schp;
if (arg2 == 0) {
return -TARGET_EINVAL;
if (!lock_user_struct(VERIFY_READ, target_schp, arg2, 1))
goto efault;
schp.sched_priority = tswap32(target_schp->sched_priority);
unlock_user_struct(target_schp, arg2, 0);
ret = get_errno(sched_setparam(arg1, &schp));
case TARGET_NR_sched_getparam:
{
struct sched_param *target_schp;
struct sched_param schp;
if (arg2 == 0) {
return -TARGET_EINVAL;
ret = get_errno(sched_getparam(arg1, &schp));
if (!is_error(ret)) {
if (!lock_user_struct(VERIFY_WRITE, target_schp, arg2, 0))
goto efault;
target_schp->sched_priority = tswap32(schp.sched_priority);
unlock_user_struct(target_schp, arg2, 1);
case TARGET_NR_sched_setscheduler:
{
struct sched_param *target_schp;
struct sched_param schp;
if (arg3 == 0) {
return -TARGET_EINVAL;
if (!lock_user_struct(VERIFY_READ, target_schp, arg3, 1))
goto efault;
schp.sched_priority = tswap32(target_schp->sched_priority);
unlock_user_struct(target_schp, arg3, 0);
ret = get_errno(sched_setscheduler(arg1, arg2, &schp));
case TARGET_NR_sched_getscheduler:
ret = get_errno(sched_getscheduler(arg1));
case TARGET_NR_sched_yield:
ret = get_errno(sched_yield());
case TARGET_NR_sched_get_priority_max:
ret = get_errno(sched_get_priority_max(arg1));
case TARGET_NR_sched_get_priority_min:
ret = get_errno(sched_get_priority_min(arg1));
case TARGET_NR_sched_rr_get_interval:
{
struct timespec ts;
ret = get_errno(sched_rr_get_interval(arg1, &ts));
if (!is_error(ret)) {
ret = host_to_target_timespec(arg2, &ts);
case TARGET_NR_nanosleep:
{
struct timespec req, rem;
target_to_host_timespec(&req, arg1);
ret = get_errno(safe_nanosleep(&req, &rem));
if (is_error(ret) && arg2) {
host_to_target_timespec(arg2, &rem);
#ifdef TARGET_NR_query_module
case TARGET_NR_query_module:
goto unimplemented;
#endif
#ifdef TARGET_NR_nfsservctl
case TARGET_NR_nfsservctl:
goto unimplemented;
#endif
case TARGET_NR_prctl:
switch (arg1) {
case PR_GET_PDEATHSIG:
{
int deathsig;
ret = get_errno(prctl(arg1, &deathsig, arg3, arg4, arg5));
if (!is_error(ret) && arg2
&& put_user_ual(deathsig, arg2)) {
goto efault;
#ifdef PR_GET_NAME
case PR_GET_NAME:
{
void *name = lock_user(VERIFY_WRITE, arg2, 16, 1);
if (!name) {
goto efault;
ret = get_errno(prctl(arg1, (unsigned long)name,
arg3, arg4, arg5));
unlock_user(name, arg2, 16);
case PR_SET_NAME:
{
void *name = lock_user(VERIFY_READ, arg2, 16, 1);
if (!name) {
goto efault;
ret = get_errno(prctl(arg1, (unsigned long)name,
arg3, arg4, arg5));
unlock_user(name, arg2, 0);
#endif
default:
ret = get_errno(prctl(arg1, arg2, arg3, arg4, arg5));
#ifdef TARGET_NR_arch_prctl
case TARGET_NR_arch_prctl:
#if defined(TARGET_I386) && !defined(TARGET_ABI32)
ret = do_arch_prctl(cpu_env, arg1, arg2);
#else
goto unimplemented;
#endif
#endif
#ifdef TARGET_NR_pread64
case TARGET_NR_pread64:
if (regpairs_aligned(cpu_env)) {
arg4 = arg5;
arg5 = arg6;
if (!(VAR_2 = lock_user(VERIFY_WRITE, arg2, arg3, 0)))
goto efault;
ret = get_errno(pread64(arg1, VAR_2, arg3, target_offset64(arg4, arg5)));
unlock_user(VAR_2, arg2, ret);
case TARGET_NR_pwrite64:
if (regpairs_aligned(cpu_env)) {
arg4 = arg5;
arg5 = arg6;
if (!(VAR_2 = lock_user(VERIFY_READ, arg2, arg3, 1)))
goto efault;
ret = get_errno(pwrite64(arg1, VAR_2, arg3, target_offset64(arg4, arg5)));
unlock_user(VAR_2, arg2, 0);
#endif
case TARGET_NR_getcwd:
if (!(VAR_2 = lock_user(VERIFY_WRITE, arg1, arg2, 0)))
goto efault;
ret = get_errno(sys_getcwd1(VAR_2, arg2));
unlock_user(VAR_2, arg1, ret);
case TARGET_NR_capget:
case TARGET_NR_capset:
{
struct target_user_cap_header *target_header;
struct target_user_cap_data *target_data = NULL;
struct __user_cap_header_struct header;
struct __user_cap_data_struct data[2];
struct __user_cap_data_struct *dataptr = NULL;
int i, target_datalen;
int data_items = 1;
if (!lock_user_struct(VERIFY_WRITE, target_header, arg1, 1)) {
goto efault;
header.version = tswap32(target_header->version);
header.pid = tswap32(target_header->pid);
if (header.version != _LINUX_CAPABILITY_VERSION) {
data_items = 2;
target_datalen = sizeof(*target_data) * data_items;
if (arg2) {
if (num == TARGET_NR_capget) {
target_data = lock_user(VERIFY_WRITE, arg2, target_datalen, 0);
} else {
target_data = lock_user(VERIFY_READ, arg2, target_datalen, 1);
if (!target_data) {
unlock_user_struct(target_header, arg1, 0);
goto efault;
if (num == TARGET_NR_capset) {
for (i = 0; i < data_items; i++) {
data[i].effective = tswap32(target_data[i].effective);
data[i].permitted = tswap32(target_data[i].permitted);
data[i].inheritable = tswap32(target_data[i].inheritable);
dataptr = data;
if (num == TARGET_NR_capget) {
ret = get_errno(capget(&header, dataptr));
} else {
ret = get_errno(capset(&header, dataptr));
target_header->version = tswap32(header.version);
unlock_user_struct(target_header, arg1, 1);
if (arg2) {
if (num == TARGET_NR_capget) {
for (i = 0; i < data_items; i++) {
target_data[i].effective = tswap32(data[i].effective);
target_data[i].permitted = tswap32(data[i].permitted);
target_data[i].inheritable = tswap32(data[i].inheritable);
unlock_user(target_data, arg2, target_datalen);
} else {
unlock_user(target_data, arg2, 0);
case TARGET_NR_sigaltstack:
ret = do_sigaltstack(arg1, arg2, get_sp_from_cpustate((CPUArchState *)cpu_env));
#ifdef CONFIG_SENDFILE
case TARGET_NR_sendfile:
{
off_t *offp = NULL;
off_t off;
if (arg3) {
ret = get_user_sal(off, arg3);
if (is_error(ret)) {
offp = &off;
ret = get_errno(sendfile(arg1, arg2, offp, arg4));
if (!is_error(ret) && arg3) {
abi_long ret2 = put_user_sal(off, arg3);
if (is_error(ret2)) {
ret = ret2;
#ifdef TARGET_NR_sendfile64
case TARGET_NR_sendfile64:
{
off_t *offp = NULL;
off_t off;
if (arg3) {
ret = get_user_s64(off, arg3);
if (is_error(ret)) {
offp = &off;
ret = get_errno(sendfile(arg1, arg2, offp, arg4));
if (!is_error(ret) && arg3) {
abi_long ret2 = put_user_s64(off, arg3);
if (is_error(ret2)) {
ret = ret2;
#endif
#else
case TARGET_NR_sendfile:
#ifdef TARGET_NR_sendfile64
case TARGET_NR_sendfile64:
#endif
goto unimplemented;
#endif
#ifdef TARGET_NR_getpmsg
case TARGET_NR_getpmsg:
goto unimplemented;
#endif
#ifdef TARGET_NR_putpmsg
case TARGET_NR_putpmsg:
goto unimplemented;
#endif
#ifdef TARGET_NR_vfork
case TARGET_NR_vfork:
ret = get_errno(do_fork(cpu_env, CLONE_VFORK | CLONE_VM | SIGCHLD,
0, 0, 0, 0));
#endif
#ifdef TARGET_NR_ugetrlimit
case TARGET_NR_ugetrlimit:
{
struct rlimit rlim;
int resource = target_to_host_resource(arg1);
ret = get_errno(getrlimit(resource, &rlim));
if (!is_error(ret)) {
struct target_rlimit *target_rlim;
if (!lock_user_struct(VERIFY_WRITE, target_rlim, arg2, 0))
goto efault;
target_rlim->rlim_cur = host_to_target_rlim(rlim.rlim_cur);
target_rlim->rlim_max = host_to_target_rlim(rlim.rlim_max);
unlock_user_struct(target_rlim, arg2, 1);
#endif
#ifdef TARGET_NR_truncate64
case TARGET_NR_truncate64:
if (!(VAR_2 = lock_user_string(arg1)))
goto efault;
ret = target_truncate64(cpu_env, VAR_2, arg2, arg3, arg4);
unlock_user(VAR_2, arg1, 0);
#endif
#ifdef TARGET_NR_ftruncate64
case TARGET_NR_ftruncate64:
ret = target_ftruncate64(cpu_env, arg1, arg2, arg3, arg4);
#endif
#ifdef TARGET_NR_stat64
case TARGET_NR_stat64:
if (!(VAR_2 = lock_user_string(arg1)))
goto efault;
ret = get_errno(stat(path(VAR_2), &VAR_0));
unlock_user(VAR_2, arg1, 0);
if (!is_error(ret))
ret = host_to_target_stat64(cpu_env, arg2, &VAR_0);
#endif
#ifdef TARGET_NR_lstat64
case TARGET_NR_lstat64:
if (!(VAR_2 = lock_user_string(arg1)))
goto efault;
ret = get_errno(lstat(path(VAR_2), &VAR_0));
unlock_user(VAR_2, arg1, 0);
if (!is_error(ret))
ret = host_to_target_stat64(cpu_env, arg2, &VAR_0);
#endif
#ifdef TARGET_NR_fstat64
case TARGET_NR_fstat64:
ret = get_errno(fstat(arg1, &VAR_0));
if (!is_error(ret))
ret = host_to_target_stat64(cpu_env, arg2, &VAR_0);
#endif
#if (defined(TARGET_NR_fstatat64) || defined(TARGET_NR_newfstatat))
#ifdef TARGET_NR_fstatat64
case TARGET_NR_fstatat64:
#endif
#ifdef TARGET_NR_newfstatat
case TARGET_NR_newfstatat:
#endif
if (!(VAR_2 = lock_user_string(arg2)))
goto efault;
ret = get_errno(fstatat(arg1, path(VAR_2), &VAR_0, arg4));
if (!is_error(ret))
ret = host_to_target_stat64(cpu_env, arg3, &VAR_0);
#endif
#ifdef TARGET_NR_lchown
case TARGET_NR_lchown:
if (!(VAR_2 = lock_user_string(arg1)))
goto efault;
ret = get_errno(lchown(VAR_2, low2highuid(arg2), low2highgid(arg3)));
unlock_user(VAR_2, arg1, 0);
#endif
#ifdef TARGET_NR_getuid
case TARGET_NR_getuid:
ret = get_errno(high2lowuid(getuid()));
#endif
#ifdef TARGET_NR_getgid
case TARGET_NR_getgid:
ret = get_errno(high2lowgid(getgid()));
#endif
#ifdef TARGET_NR_geteuid
case TARGET_NR_geteuid:
ret = get_errno(high2lowuid(geteuid()));
#endif
#ifdef TARGET_NR_getegid
case TARGET_NR_getegid:
ret = get_errno(high2lowgid(getegid()));
#endif
case TARGET_NR_setreuid:
ret = get_errno(setreuid(low2highuid(arg1), low2highuid(arg2)));
case TARGET_NR_setregid:
ret = get_errno(setregid(low2highgid(arg1), low2highgid(arg2)));
case TARGET_NR_getgroups:
{
int gidsetsize = arg1;
target_id *target_grouplist;
gid_t *grouplist;
int i;
grouplist = alloca(gidsetsize * sizeof(gid_t));
ret = get_errno(getgroups(gidsetsize, grouplist));
if (gidsetsize == 0)
if (!is_error(ret)) {
target_grouplist = lock_user(VERIFY_WRITE, arg2, gidsetsize * sizeof(target_id), 0);
if (!target_grouplist)
goto efault;
for(i = 0;i < ret; i++)
target_grouplist[i] = tswapid(high2lowgid(grouplist[i]));
unlock_user(target_grouplist, arg2, gidsetsize * sizeof(target_id));
case TARGET_NR_setgroups:
{
int gidsetsize = arg1;
target_id *target_grouplist;
gid_t *grouplist = NULL;
int i;
if (gidsetsize) {
grouplist = alloca(gidsetsize * sizeof(gid_t));
target_grouplist = lock_user(VERIFY_READ, arg2, gidsetsize * sizeof(target_id), 1);
if (!target_grouplist) {
ret = -TARGET_EFAULT;
goto fail;
for (i = 0; i < gidsetsize; i++) {
grouplist[i] = low2highgid(tswapid(target_grouplist[i]));
unlock_user(target_grouplist, arg2, 0);
ret = get_errno(setgroups(gidsetsize, grouplist));
case TARGET_NR_fchown:
ret = get_errno(fchown(arg1, low2highuid(arg2), low2highgid(arg3)));
#if defined(TARGET_NR_fchownat)
case TARGET_NR_fchownat:
if (!(VAR_2 = lock_user_string(arg2)))
goto efault;
ret = get_errno(fchownat(arg1, VAR_2, low2highuid(arg3),
low2highgid(arg4), arg5));
unlock_user(VAR_2, arg2, 0);
#endif
#ifdef TARGET_NR_setresuid
case TARGET_NR_setresuid:
ret = get_errno(sys_setresuid(low2highuid(arg1),
low2highuid(arg2),
low2highuid(arg3)));
#endif
#ifdef TARGET_NR_getresuid
case TARGET_NR_getresuid:
{
uid_t ruid, euid, suid;
ret = get_errno(getresuid(&ruid, &euid, &suid));
if (!is_error(ret)) {
if (put_user_id(high2lowuid(ruid), arg1)
|| put_user_id(high2lowuid(euid), arg2)
|| put_user_id(high2lowuid(suid), arg3))
goto efault;
#endif
#ifdef TARGET_NR_getresgid
case TARGET_NR_setresgid:
ret = get_errno(sys_setresgid(low2highgid(arg1),
low2highgid(arg2),
low2highgid(arg3)));
#endif
#ifdef TARGET_NR_getresgid
case TARGET_NR_getresgid:
{
gid_t rgid, egid, sgid;
ret = get_errno(getresgid(&rgid, &egid, &sgid));
if (!is_error(ret)) {
if (put_user_id(high2lowgid(rgid), arg1)
|| put_user_id(high2lowgid(egid), arg2)
|| put_user_id(high2lowgid(sgid), arg3))
goto efault;
#endif
#ifdef TARGET_NR_chown
case TARGET_NR_chown:
if (!(VAR_2 = lock_user_string(arg1)))
goto efault;
ret = get_errno(chown(VAR_2, low2highuid(arg2), low2highgid(arg3)));
unlock_user(VAR_2, arg1, 0);
#endif
case TARGET_NR_setuid:
ret = get_errno(sys_setuid(low2highuid(arg1)));
case TARGET_NR_setgid:
ret = get_errno(sys_setgid(low2highgid(arg1)));
case TARGET_NR_setfsuid:
ret = get_errno(setfsuid(arg1));
case TARGET_NR_setfsgid:
ret = get_errno(setfsgid(arg1));
#ifdef TARGET_NR_lchown32
case TARGET_NR_lchown32:
if (!(VAR_2 = lock_user_string(arg1)))
goto efault;
ret = get_errno(lchown(VAR_2, arg2, arg3));
unlock_user(VAR_2, arg1, 0);
#endif
#ifdef TARGET_NR_getuid32
case TARGET_NR_getuid32:
ret = get_errno(getuid());
#endif
#if defined(TARGET_NR_getxuid) && defined(TARGET_ALPHA)
case TARGET_NR_getxuid:
{
uid_t euid;
euid=geteuid();
((CPUAlphaState *)cpu_env)->ir[IR_A4]=euid;
ret = get_errno(getuid());
#endif
#if defined(TARGET_NR_getxgid) && defined(TARGET_ALPHA)
case TARGET_NR_getxgid:
{
uid_t egid;
egid=getegid();
((CPUAlphaState *)cpu_env)->ir[IR_A4]=egid;
ret = get_errno(getgid());
#endif
#if defined(TARGET_NR_osf_getsysinfo) && defined(TARGET_ALPHA)
case TARGET_NR_osf_getsysinfo:
ret = -TARGET_EOPNOTSUPP;
switch (arg1) {
case TARGET_GSI_IEEE_FP_CONTROL:
{
uint64_t swcr, fpcr = cpu_alpha_load_fpcr (cpu_env);
swcr = (fpcr >> 35) & SWCR_STATUS_MASK;
swcr |= (fpcr >> 36) & SWCR_MAP_DMZ;
swcr |= (~fpcr >> 48) & (SWCR_TRAP_ENABLE_INV
| SWCR_TRAP_ENABLE_DZE
| SWCR_TRAP_ENABLE_OVF);
swcr |= (~fpcr >> 57) & (SWCR_TRAP_ENABLE_UNF
| SWCR_TRAP_ENABLE_INE);
swcr |= (fpcr >> 47) & SWCR_MAP_UMZ;
swcr |= (~fpcr >> 41) & SWCR_TRAP_ENABLE_DNO;
if (put_user_u64 (swcr, arg2))
goto efault;
ret = 0;
#endif
#if defined(TARGET_NR_osf_setsysinfo) && defined(TARGET_ALPHA)
case TARGET_NR_osf_setsysinfo:
ret = -TARGET_EOPNOTSUPP;
switch (arg1) {
case TARGET_SSI_IEEE_FP_CONTROL:
{
uint64_t swcr, fpcr, orig_fpcr;
if (get_user_u64 (swcr, arg2)) {
goto efault;
orig_fpcr = cpu_alpha_load_fpcr(cpu_env);
fpcr = orig_fpcr & FPCR_DYN_MASK;
fpcr |= (swcr & SWCR_STATUS_MASK) << 35;
fpcr |= (swcr & SWCR_MAP_DMZ) << 36;
fpcr |= (~swcr & (SWCR_TRAP_ENABLE_INV
| SWCR_TRAP_ENABLE_DZE
| SWCR_TRAP_ENABLE_OVF)) << 48;
fpcr |= (~swcr & (SWCR_TRAP_ENABLE_UNF
| SWCR_TRAP_ENABLE_INE)) << 57;
fpcr |= (swcr & SWCR_MAP_UMZ ? FPCR_UNDZ | FPCR_UNFD : 0);
fpcr |= (~swcr & SWCR_TRAP_ENABLE_DNO) << 41;
cpu_alpha_store_fpcr(cpu_env, fpcr);
ret = 0;
case TARGET_SSI_IEEE_RAISE_EXCEPTION:
{
uint64_t exc, fpcr, orig_fpcr;
int si_code;
if (get_user_u64(exc, arg2)) {
goto efault;
orig_fpcr = cpu_alpha_load_fpcr(cpu_env);
fpcr = orig_fpcr | ((exc & SWCR_STATUS_MASK) << 35);
cpu_alpha_store_fpcr(cpu_env, fpcr);
ret = 0;
fpcr &= ~(orig_fpcr & FPCR_STATUS_MASK);
si_code = 0;
if ((fpcr & (FPCR_INE | FPCR_INED)) == FPCR_INE) {
si_code = TARGET_FPE_FLTRES;
if ((fpcr & (FPCR_UNF | FPCR_UNFD)) == FPCR_UNF) {
si_code = TARGET_FPE_FLTUND;
if ((fpcr & (FPCR_OVF | FPCR_OVFD)) == FPCR_OVF) {
si_code = TARGET_FPE_FLTOVF;
if ((fpcr & (FPCR_DZE | FPCR_DZED)) == FPCR_DZE) {
si_code = TARGET_FPE_FLTDIV;
if ((fpcr & (FPCR_INV | FPCR_INVD)) == FPCR_INV) {
si_code = TARGET_FPE_FLTINV;
if (si_code != 0) {
target_siginfo_t info;
info.si_signo = SIGFPE;
info.si_errno = 0;
info.si_code = si_code;
info._sifields._sigfault._addr
= ((CPUArchState *)cpu_env)->pc;
queue_signal((CPUArchState *)cpu_env, info.si_signo, &info);
#endif
#ifdef TARGET_NR_osf_sigprocmask
case TARGET_NR_osf_sigprocmask:
{
abi_ulong mask;
int how;
sigset_t set, oldset;
switch(arg1) {
case TARGET_SIG_BLOCK:
how = SIG_BLOCK;
case TARGET_SIG_UNBLOCK:
how = SIG_UNBLOCK;
case TARGET_SIG_SETMASK:
how = SIG_SETMASK;
default:
goto fail;
mask = arg2;
target_to_host_old_sigset(&set, &mask);
ret = do_sigprocmask(how, &set, &oldset);
if (!ret) {
host_to_target_old_sigset(&mask, &oldset);
ret = mask;
#endif
#ifdef TARGET_NR_getgid32
case TARGET_NR_getgid32:
ret = get_errno(getgid());
#endif
#ifdef TARGET_NR_geteuid32
case TARGET_NR_geteuid32:
ret = get_errno(geteuid());
#endif
#ifdef TARGET_NR_getegid32
case TARGET_NR_getegid32:
ret = get_errno(getegid());
#endif
#ifdef TARGET_NR_setreuid32
case TARGET_NR_setreuid32:
ret = get_errno(setreuid(arg1, arg2));
#endif
#ifdef TARGET_NR_setregid32
case TARGET_NR_setregid32:
ret = get_errno(setregid(arg1, arg2));
#endif
#ifdef TARGET_NR_getgroups32
case TARGET_NR_getgroups32:
{
int gidsetsize = arg1;
uint32_t *target_grouplist;
gid_t *grouplist;
int i;
grouplist = alloca(gidsetsize * sizeof(gid_t));
ret = get_errno(getgroups(gidsetsize, grouplist));
if (gidsetsize == 0)
if (!is_error(ret)) {
target_grouplist = lock_user(VERIFY_WRITE, arg2, gidsetsize * 4, 0);
if (!target_grouplist) {
ret = -TARGET_EFAULT;
goto fail;
for(i = 0;i < ret; i++)
target_grouplist[i] = tswap32(grouplist[i]);
unlock_user(target_grouplist, arg2, gidsetsize * 4);
#endif
#ifdef TARGET_NR_setgroups32
case TARGET_NR_setgroups32:
{
int gidsetsize = arg1;
uint32_t *target_grouplist;
gid_t *grouplist;
int i;
grouplist = alloca(gidsetsize * sizeof(gid_t));
target_grouplist = lock_user(VERIFY_READ, arg2, gidsetsize * 4, 1);
if (!target_grouplist) {
ret = -TARGET_EFAULT;
goto fail;
for(i = 0;i < gidsetsize; i++)
grouplist[i] = tswap32(target_grouplist[i]);
unlock_user(target_grouplist, arg2, 0);
ret = get_errno(setgroups(gidsetsize, grouplist));
#endif
#ifdef TARGET_NR_fchown32
case TARGET_NR_fchown32:
ret = get_errno(fchown(arg1, arg2, arg3));
#endif
#ifdef TARGET_NR_setresuid32
case TARGET_NR_setresuid32:
ret = get_errno(sys_setresuid(arg1, arg2, arg3));
#endif
#ifdef TARGET_NR_getresuid32
case TARGET_NR_getresuid32:
{
uid_t ruid, euid, suid;
ret = get_errno(getresuid(&ruid, &euid, &suid));
if (!is_error(ret)) {
if (put_user_u32(ruid, arg1)
|| put_user_u32(euid, arg2)
|| put_user_u32(suid, arg3))
goto efault;
#endif
#ifdef TARGET_NR_setresgid32
case TARGET_NR_setresgid32:
ret = get_errno(sys_setresgid(arg1, arg2, arg3));
#endif
#ifdef TARGET_NR_getresgid32
case TARGET_NR_getresgid32:
{
gid_t rgid, egid, sgid;
ret = get_errno(getresgid(&rgid, &egid, &sgid));
if (!is_error(ret)) {
if (put_user_u32(rgid, arg1)
|| put_user_u32(egid, arg2)
|| put_user_u32(sgid, arg3))
goto efault;
#endif
#ifdef TARGET_NR_chown32
case TARGET_NR_chown32:
if (!(VAR_2 = lock_user_string(arg1)))
goto efault;
ret = get_errno(chown(VAR_2, arg2, arg3));
unlock_user(VAR_2, arg1, 0);
#endif
#ifdef TARGET_NR_setuid32
case TARGET_NR_setuid32:
ret = get_errno(sys_setuid(arg1));
#endif
#ifdef TARGET_NR_setgid32
case TARGET_NR_setgid32:
ret = get_errno(sys_setgid(arg1));
#endif
#ifdef TARGET_NR_setfsuid32
case TARGET_NR_setfsuid32:
ret = get_errno(setfsuid(arg1));
#endif
#ifdef TARGET_NR_setfsgid32
case TARGET_NR_setfsgid32:
ret = get_errno(setfsgid(arg1));
#endif
case TARGET_NR_pivot_root:
goto unimplemented;
#ifdef TARGET_NR_mincore
case TARGET_NR_mincore:
{
void *a;
ret = -TARGET_EFAULT;
if (!(a = lock_user(VERIFY_READ, arg1,arg2, 0)))
goto efault;
if (!(VAR_2 = lock_user_string(arg3)))
goto mincore_fail;
ret = get_errno(mincore(a, arg2, VAR_2));
unlock_user(VAR_2, arg3, ret);
mincore_fail:
unlock_user(a, arg1, 0);
#endif
#ifdef TARGET_NR_arm_fadvise64_64
case TARGET_NR_arm_fadvise64_64:
ret = posix_fadvise(arg1, target_offset64(arg3, arg4),
target_offset64(arg5, arg6), arg2);
ret = -host_to_target_errno(ret);
#endif
#if TARGET_ABI_BITS == 32
#ifdef TARGET_NR_fadvise64_64
case TARGET_NR_fadvise64_64:
if (regpairs_aligned(cpu_env)) {
arg2 = arg3;
arg3 = arg4;
arg4 = arg5;
arg5 = arg6;
arg6 = arg7;
ret = -host_to_target_errno(posix_fadvise(arg1,
target_offset64(arg2, arg3),
target_offset64(arg4, arg5),
arg6));
#endif
#ifdef TARGET_NR_fadvise64
case TARGET_NR_fadvise64:
if (regpairs_aligned(cpu_env)) {
arg2 = arg3;
arg3 = arg4;
arg4 = arg5;
arg5 = arg6;
ret = -host_to_target_errno(posix_fadvise(arg1,
target_offset64(arg2, arg3),
arg4, arg5));
#endif
#else
#if defined(TARGET_NR_fadvise64_64) || defined(TARGET_NR_fadvise64)
#ifdef TARGET_NR_fadvise64_64
case TARGET_NR_fadvise64_64:
#endif
#ifdef TARGET_NR_fadvise64
case TARGET_NR_fadvise64:
#endif
#ifdef TARGET_S390X
switch (arg4) {
case 4: arg4 = POSIX_FADV_NOREUSE + 1; break;
case 5: arg4 = POSIX_FADV_NOREUSE + 2; break;
case 6: arg4 = POSIX_FADV_DONTNEED; break;
case 7: arg4 = POSIX_FADV_NOREUSE; break;
default: break;
#endif
ret = -host_to_target_errno(posix_fadvise(arg1, arg2, arg3, arg4));
#endif
#endif
#ifdef TARGET_NR_madvise
case TARGET_NR_madvise:
ret = get_errno(0);
#endif
#if TARGET_ABI_BITS == 32
case TARGET_NR_fcntl64:
{
int cmd;
struct flock64 fl;
from_flock64_fn *copyfrom = copy_from_user_flock64;
to_flock64_fn *copyto = copy_to_user_flock64;
#ifdef TARGET_ARM
if (((CPUARMState *)cpu_env)->eabi) {
copyfrom = copy_from_user_eabi_flock64;
copyto = copy_to_user_eabi_flock64;
#endif
cmd = target_to_host_fcntl_cmd(arg2);
if (cmd == -TARGET_EINVAL) {
ret = cmd;
switch(arg2) {
case TARGET_F_GETLK64:
ret = copyfrom(&fl, arg3);
if (ret) {
ret = get_errno(fcntl(arg1, cmd, &fl));
if (ret == 0) {
ret = copyto(arg3, &fl);
case TARGET_F_SETLK64:
case TARGET_F_SETLKW64:
ret = copyfrom(&fl, arg3);
if (ret) {
ret = get_errno(safe_fcntl(arg1, cmd, &fl));
default:
ret = do_fcntl(arg1, arg2, arg3);
#endif
#ifdef TARGET_NR_cacheflush
case TARGET_NR_cacheflush:
ret = 0;
#endif
#ifdef TARGET_NR_security
case TARGET_NR_security:
goto unimplemented;
#endif
#ifdef TARGET_NR_getpagesize
case TARGET_NR_getpagesize:
ret = TARGET_PAGE_SIZE;
#endif
case TARGET_NR_gettid:
ret = get_errno(gettid());
#ifdef TARGET_NR_readahead
case TARGET_NR_readahead:
#if TARGET_ABI_BITS == 32
if (regpairs_aligned(cpu_env)) {
arg2 = arg3;
arg3 = arg4;
arg4 = arg5;
ret = get_errno(readahead(arg1, ((off64_t)arg3 << 32) | arg2, arg4));
#else
ret = get_errno(readahead(arg1, arg2, arg3));
#endif
#endif
#ifdef CONFIG_ATTR
#ifdef TARGET_NR_setxattr
case TARGET_NR_listxattr:
case TARGET_NR_llistxattr:
{
void *VAR_2, *b = 0;
if (arg2) {
b = lock_user(VERIFY_WRITE, arg2, arg3, 0);
if (!b) {
ret = -TARGET_EFAULT;
VAR_2 = lock_user_string(arg1);
if (VAR_2) {
if (num == TARGET_NR_listxattr) {
ret = get_errno(listxattr(VAR_2, b, arg3));
} else {
ret = get_errno(llistxattr(VAR_2, b, arg3));
} else {
ret = -TARGET_EFAULT;
unlock_user(VAR_2, arg1, 0);
unlock_user(b, arg2, arg3);
case TARGET_NR_flistxattr:
{
void *b = 0;
if (arg2) {
b = lock_user(VERIFY_WRITE, arg2, arg3, 0);
if (!b) {
ret = -TARGET_EFAULT;
ret = get_errno(flistxattr(arg1, b, arg3));
unlock_user(b, arg2, arg3);
case TARGET_NR_setxattr:
case TARGET_NR_lsetxattr:
{
void *VAR_2, *n, *v = 0;
if (arg3) {
v = lock_user(VERIFY_READ, arg3, arg4, 1);
if (!v) {
ret = -TARGET_EFAULT;
VAR_2 = lock_user_string(arg1);
n = lock_user_string(arg2);
if (VAR_2 && n) {
if (num == TARGET_NR_setxattr) {
ret = get_errno(setxattr(VAR_2, n, v, arg4, arg5));
} else {
ret = get_errno(lsetxattr(VAR_2, n, v, arg4, arg5));
} else {
ret = -TARGET_EFAULT;
unlock_user(VAR_2, arg1, 0);
unlock_user(n, arg2, 0);
unlock_user(v, arg3, 0);
case TARGET_NR_fsetxattr:
{
void *n, *v = 0;
if (arg3) {
v = lock_user(VERIFY_READ, arg3, arg4, 1);
if (!v) {
ret = -TARGET_EFAULT;
n = lock_user_string(arg2);
if (n) {
ret = get_errno(fsetxattr(arg1, n, v, arg4, arg5));
} else {
ret = -TARGET_EFAULT;
unlock_user(n, arg2, 0);
unlock_user(v, arg3, 0);
case TARGET_NR_getxattr:
case TARGET_NR_lgetxattr:
{
void *VAR_2, *n, *v = 0;
if (arg3) {
v = lock_user(VERIFY_WRITE, arg3, arg4, 0);
if (!v) {
ret = -TARGET_EFAULT;
VAR_2 = lock_user_string(arg1);
n = lock_user_string(arg2);
if (VAR_2 && n) {
if (num == TARGET_NR_getxattr) {
ret = get_errno(getxattr(VAR_2, n, v, arg4));
} else {
ret = get_errno(lgetxattr(VAR_2, n, v, arg4));
} else {
ret = -TARGET_EFAULT;
unlock_user(VAR_2, arg1, 0);
unlock_user(n, arg2, 0);
unlock_user(v, arg3, arg4);
case TARGET_NR_fgetxattr:
{
void *n, *v = 0;
if (arg3) {
v = lock_user(VERIFY_WRITE, arg3, arg4, 0);
if (!v) {
ret = -TARGET_EFAULT;
n = lock_user_string(arg2);
if (n) {
ret = get_errno(fgetxattr(arg1, n, v, arg4));
} else {
ret = -TARGET_EFAULT;
unlock_user(n, arg2, 0);
unlock_user(v, arg3, arg4);
case TARGET_NR_removexattr:
case TARGET_NR_lremovexattr:
{
void *VAR_2, *n;
VAR_2 = lock_user_string(arg1);
n = lock_user_string(arg2);
if (VAR_2 && n) {
if (num == TARGET_NR_removexattr) {
ret = get_errno(removexattr(VAR_2, n));
} else {
ret = get_errno(lremovexattr(VAR_2, n));
} else {
ret = -TARGET_EFAULT;
unlock_user(VAR_2, arg1, 0);
unlock_user(n, arg2, 0);
case TARGET_NR_fremovexattr:
{
void *n;
n = lock_user_string(arg2);
if (n) {
ret = get_errno(fremovexattr(arg1, n));
} else {
ret = -TARGET_EFAULT;
unlock_user(n, arg2, 0);
#endif
#endif
#ifdef TARGET_NR_set_thread_area
case TARGET_NR_set_thread_area:
#if defined(TARGET_MIPS)
((CPUMIPSState *) cpu_env)->active_tc.CP0_UserLocal = arg1;
ret = 0;
#elif defined(TARGET_CRIS)
if (arg1 & 0xff)
else {
((CPUCRISState *) cpu_env)->pregs[PR_PID] = arg1;
ret = 0;
#elif defined(TARGET_I386) && defined(TARGET_ABI32)
ret = do_set_thread_area(cpu_env, arg1);
#elif defined(TARGET_M68K)
{
TaskState *ts = cpu->opaque;
ts->tp_value = arg1;
ret = 0;
#else
goto unimplemented_nowarn;
#endif
#endif
#ifdef TARGET_NR_get_thread_area
case TARGET_NR_get_thread_area:
#if defined(TARGET_I386) && defined(TARGET_ABI32)
ret = do_get_thread_area(cpu_env, arg1);
#elif defined(TARGET_M68K)
{
TaskState *ts = cpu->opaque;
ret = ts->tp_value;
#else
goto unimplemented_nowarn;
#endif
#endif
#ifdef TARGET_NR_getdomainname
case TARGET_NR_getdomainname:
goto unimplemented_nowarn;
#endif
#ifdef TARGET_NR_clock_gettime
case TARGET_NR_clock_gettime:
{
struct timespec ts;
ret = get_errno(clock_gettime(arg1, &ts));
if (!is_error(ret)) {
host_to_target_timespec(arg2, &ts);
#endif
#ifdef TARGET_NR_clock_getres
case TARGET_NR_clock_getres:
{
struct timespec ts;
ret = get_errno(clock_getres(arg1, &ts));
if (!is_error(ret)) {
host_to_target_timespec(arg2, &ts);
#endif
#ifdef TARGET_NR_clock_nanosleep
case TARGET_NR_clock_nanosleep:
{
struct timespec ts;
target_to_host_timespec(&ts, arg3);
ret = get_errno(safe_clock_nanosleep(arg1, arg2,
&ts, arg4 ? &ts : NULL));
if (arg4)
host_to_target_timespec(arg4, &ts);
#if defined(TARGET_PPC)
if (ret && ret != -TARGET_ERESTARTSYS) {
((CPUPPCState *)cpu_env)->crf[0] |= 1;
#endif
#endif
#if defined(TARGET_NR_set_tid_address) && defined(__NR_set_tid_address)
case TARGET_NR_set_tid_address:
ret = get_errno(set_tid_address((int *)g2h(arg1)));
#endif
case TARGET_NR_tkill:
ret = get_errno(safe_tkill((int)arg1, target_to_host_signal(arg2)));
case TARGET_NR_tgkill:
ret = get_errno(safe_tgkill((int)arg1, (int)arg2,
target_to_host_signal(arg3)));
#ifdef TARGET_NR_set_robust_list
case TARGET_NR_set_robust_list:
case TARGET_NR_get_robust_list:
goto unimplemented_nowarn;
#endif
#if defined(TARGET_NR_utimensat)
case TARGET_NR_utimensat:
{
struct timespec *tsp, ts[2];
if (!arg3) {
tsp = NULL;
} else {
target_to_host_timespec(ts, arg3);
target_to_host_timespec(ts+1, arg3+sizeof(struct target_timespec));
tsp = ts;
if (!arg2)
ret = get_errno(sys_utimensat(arg1, NULL, tsp, arg4));
else {
if (!(VAR_2 = lock_user_string(arg2))) {
ret = -TARGET_EFAULT;
goto fail;
ret = get_errno(sys_utimensat(arg1, path(VAR_2), tsp, arg4));
unlock_user(VAR_2, arg2, 0);
#endif
case TARGET_NR_futex:
ret = do_futex(arg1, arg2, arg3, arg4, arg5, arg6);
#if defined(TARGET_NR_inotify_init) && defined(__NR_inotify_init)
case TARGET_NR_inotify_init:
ret = get_errno(sys_inotify_init());
#endif
#ifdef CONFIG_INOTIFY1
#if defined(TARGET_NR_inotify_init1) && defined(__NR_inotify_init1)
case TARGET_NR_inotify_init1:
ret = get_errno(sys_inotify_init1(arg1));
#endif
#endif
#if defined(TARGET_NR_inotify_add_watch) && defined(__NR_inotify_add_watch)
case TARGET_NR_inotify_add_watch:
VAR_2 = lock_user_string(arg2);
ret = get_errno(sys_inotify_add_watch(arg1, path(VAR_2), arg3));
unlock_user(VAR_2, arg2, 0);
#endif
#if defined(TARGET_NR_inotify_rm_watch) && defined(__NR_inotify_rm_watch)
case TARGET_NR_inotify_rm_watch:
ret = get_errno(sys_inotify_rm_watch(arg1, arg2));
#endif
#if defined(TARGET_NR_mq_open) && defined(__NR_mq_open)
case TARGET_NR_mq_open:
{
struct mq_attr posix_mq_attr, *attrp;
VAR_2 = lock_user_string(arg1 - 1);
if (arg4 != 0) {
copy_from_user_mq_attr (&posix_mq_attr, arg4);
attrp = &posix_mq_attr;
} else {
attrp = 0;
ret = get_errno(mq_open(VAR_2, arg2, arg3, attrp));
unlock_user (VAR_2, arg1, 0);
case TARGET_NR_mq_unlink:
VAR_2 = lock_user_string(arg1 - 1);
ret = get_errno(mq_unlink(VAR_2));
unlock_user (VAR_2, arg1, 0);
case TARGET_NR_mq_timedsend:
{
struct timespec ts;
VAR_2 = lock_user (VERIFY_READ, arg2, arg3, 1);
if (arg5 != 0) {
target_to_host_timespec(&ts, arg5);
ret = get_errno(safe_mq_timedsend(arg1, VAR_2, arg3, arg4, &ts));
host_to_target_timespec(arg5, &ts);
} else {
ret = get_errno(safe_mq_timedsend(arg1, VAR_2, arg3, arg4, NULL));
unlock_user (VAR_2, arg2, arg3);
case TARGET_NR_mq_timedreceive:
{
struct timespec ts;
unsigned int prio;
VAR_2 = lock_user (VERIFY_READ, arg2, arg3, 1);
if (arg5 != 0) {
target_to_host_timespec(&ts, arg5);
ret = get_errno(safe_mq_timedreceive(arg1, VAR_2, arg3,
&prio, &ts));
host_to_target_timespec(arg5, &ts);
} else {
ret = get_errno(safe_mq_timedreceive(arg1, VAR_2, arg3,
&prio, NULL));
unlock_user (VAR_2, arg2, arg3);
if (arg4 != 0)
put_user_u32(prio, arg4);
case TARGET_NR_mq_getsetattr:
{
struct mq_attr posix_mq_attr_in, posix_mq_attr_out;
ret = 0;
if (arg3 != 0) {
ret = mq_getattr(arg1, &posix_mq_attr_out);
copy_to_user_mq_attr(arg3, &posix_mq_attr_out);
if (arg2 != 0) {
copy_from_user_mq_attr(&posix_mq_attr_in, arg2);
ret |= mq_setattr(arg1, &posix_mq_attr_in, &posix_mq_attr_out);
#endif
#ifdef CONFIG_SPLICE
#ifdef TARGET_NR_tee
case TARGET_NR_tee:
{
ret = get_errno(tee(arg1,arg2,arg3,arg4));
#endif
#ifdef TARGET_NR_splice
case TARGET_NR_splice:
{
loff_t loff_in, loff_out;
loff_t *ploff_in = NULL, *ploff_out = NULL;
if (arg2) {
if (get_user_u64(loff_in, arg2)) {
goto efault;
ploff_in = &loff_in;
if (arg4) {
if (get_user_u64(loff_out, arg4)) {
goto efault;
ploff_out = &loff_out;
ret = get_errno(splice(arg1, ploff_in, arg3, ploff_out, arg5, arg6));
if (arg2) {
if (put_user_u64(loff_in, arg2)) {
goto efault;
if (arg4) {
if (put_user_u64(loff_out, arg4)) {
goto efault;
#endif
#ifdef TARGET_NR_vmsplice
case TARGET_NR_vmsplice:
{
struct iovec *vec = lock_iovec(VERIFY_READ, arg2, arg3, 1);
if (vec != NULL) {
ret = get_errno(vmsplice(arg1, vec, arg3, arg4));
unlock_iovec(vec, arg2, arg3, 0);
} else {
ret = -host_to_target_errno(errno);
#endif
#endif
#ifdef CONFIG_EVENTFD
#if defined(TARGET_NR_eventfd)
case TARGET_NR_eventfd:
ret = get_errno(eventfd(arg1, 0));
fd_trans_unregister(ret);
#endif
#if defined(TARGET_NR_eventfd2)
case TARGET_NR_eventfd2:
{
int host_flags = arg2 & (~(TARGET_O_NONBLOCK | TARGET_O_CLOEXEC));
if (arg2 & TARGET_O_NONBLOCK) {
host_flags |= O_NONBLOCK;
if (arg2 & TARGET_O_CLOEXEC) {
host_flags |= O_CLOEXEC;
ret = get_errno(eventfd(arg1, host_flags));
fd_trans_unregister(ret);
#endif
#endif
#if defined(CONFIG_FALLOCATE) && defined(TARGET_NR_fallocate)
case TARGET_NR_fallocate:
#if TARGET_ABI_BITS == 32
ret = get_errno(fallocate(arg1, arg2, target_offset64(arg3, arg4),
target_offset64(arg5, arg6)));
#else
ret = get_errno(fallocate(arg1, arg2, arg3, arg4));
#endif
#endif
#if defined(CONFIG_SYNC_FILE_RANGE)
#if defined(TARGET_NR_sync_file_range)
case TARGET_NR_sync_file_range:
#if TARGET_ABI_BITS == 32
#if defined(TARGET_MIPS)
ret = get_errno(sync_file_range(arg1, target_offset64(arg3, arg4),
target_offset64(arg5, arg6), arg7));
#else
ret = get_errno(sync_file_range(arg1, target_offset64(arg2, arg3),
target_offset64(arg4, arg5), arg6));
#endif
#else
ret = get_errno(sync_file_range(arg1, arg2, arg3, arg4));
#endif
#endif
#if defined(TARGET_NR_sync_file_range2)
case TARGET_NR_sync_file_range2:
#if TARGET_ABI_BITS == 32
ret = get_errno(sync_file_range(arg1, target_offset64(arg3, arg4),
target_offset64(arg5, arg6), arg2));
#else
ret = get_errno(sync_file_range(arg1, arg3, arg4, arg2));
#endif
#endif
#endif
#if defined(TARGET_NR_signalfd4)
case TARGET_NR_signalfd4:
ret = do_signalfd4(arg1, arg2, arg4);
#endif
#if defined(TARGET_NR_signalfd)
case TARGET_NR_signalfd:
ret = do_signalfd4(arg1, arg2, 0);
#endif
#if defined(CONFIG_EPOLL)
#if defined(TARGET_NR_epoll_create)
case TARGET_NR_epoll_create:
ret = get_errno(epoll_create(arg1));
#endif
#if defined(TARGET_NR_epoll_create1) && defined(CONFIG_EPOLL_CREATE1)
case TARGET_NR_epoll_create1:
ret = get_errno(epoll_create1(arg1));
#endif
#if defined(TARGET_NR_epoll_ctl)
case TARGET_NR_epoll_ctl:
{
struct epoll_event ep;
struct epoll_event *epp = 0;
if (arg4) {
struct target_epoll_event *target_ep;
if (!lock_user_struct(VERIFY_READ, target_ep, arg4, 1)) {
goto efault;
ep.events = tswap32(target_ep->events);
ep.data.u64 = tswap64(target_ep->data.u64);
unlock_user_struct(target_ep, arg4, 0);
epp = &ep;
ret = get_errno(epoll_ctl(arg1, arg2, arg3, epp));
#endif
#if defined(TARGET_NR_epoll_wait) || defined(TARGET_NR_epoll_pwait)
#if defined(TARGET_NR_epoll_wait)
case TARGET_NR_epoll_wait:
#endif
#if defined(TARGET_NR_epoll_pwait)
case TARGET_NR_epoll_pwait:
#endif
{
struct target_epoll_event *target_ep;
struct epoll_event *ep;
int epfd = arg1;
int maxevents = arg3;
int timeout = arg4;
if (maxevents <= 0 || maxevents > TARGET_EP_MAX_EVENTS) {
target_ep = lock_user(VERIFY_WRITE, arg2,
maxevents * sizeof(struct target_epoll_event), 1);
if (!target_ep) {
goto efault;
ep = alloca(maxevents * sizeof(struct epoll_event));
switch (num) {
#if defined(TARGET_NR_epoll_pwait)
case TARGET_NR_epoll_pwait:
{
target_sigset_t *target_set;
sigset_t _set, *set = &_set;
if (arg5) {
if (arg6 != sizeof(target_sigset_t)) {
target_set = lock_user(VERIFY_READ, arg5,
sizeof(target_sigset_t), 1);
if (!target_set) {
unlock_user(target_ep, arg2, 0);
goto efault;
target_to_host_sigset(set, target_set);
unlock_user(target_set, arg5, 0);
} else {
set = NULL;
ret = get_errno(safe_epoll_pwait(epfd, ep, maxevents, timeout,
set, SIGSET_T_SIZE));
#endif
#if defined(TARGET_NR_epoll_wait)
case TARGET_NR_epoll_wait:
ret = get_errno(safe_epoll_pwait(epfd, ep, maxevents, timeout,
NULL, 0));
#endif
default:
ret = -TARGET_ENOSYS;
if (!is_error(ret)) {
int i;
for (i = 0; i < ret; i++) {
target_ep[i].events = tswap32(ep[i].events);
target_ep[i].data.u64 = tswap64(ep[i].data.u64);
unlock_user(target_ep, arg2, ret * sizeof(struct target_epoll_event));
#endif
#endif
#ifdef TARGET_NR_prlimit64
case TARGET_NR_prlimit64:
{
struct target_rlimit64 *target_rnew, *target_rold;
struct host_rlimit64 rnew, rold, *rnewp = 0;
int resource = target_to_host_resource(arg2);
if (arg3) {
if (!lock_user_struct(VERIFY_READ, target_rnew, arg3, 1)) {
goto efault;
rnew.rlim_cur = tswap64(target_rnew->rlim_cur);
rnew.rlim_max = tswap64(target_rnew->rlim_max);
unlock_user_struct(target_rnew, arg3, 0);
rnewp = &rnew;
ret = get_errno(sys_prlimit64(arg1, resource, rnewp, arg4 ? &rold : 0));
if (!is_error(ret) && arg4) {
if (!lock_user_struct(VERIFY_WRITE, target_rold, arg4, 1)) {
goto efault;
target_rold->rlim_cur = tswap64(rold.rlim_cur);
target_rold->rlim_max = tswap64(rold.rlim_max);
unlock_user_struct(target_rold, arg4, 1);
#endif
#ifdef TARGET_NR_gethostname
case TARGET_NR_gethostname:
{
char *name = lock_user(VERIFY_WRITE, arg1, arg2, 0);
if (name) {
ret = get_errno(gethostname(name, arg2));
unlock_user(name, arg1, arg2);
} else {
ret = -TARGET_EFAULT;
#endif
#ifdef TARGET_NR_atomic_cmpxchg_32
case TARGET_NR_atomic_cmpxchg_32:
{
abi_ulong mem_value;
if (get_user_u32(mem_value, arg6)) {
target_siginfo_t info;
info.si_signo = SIGSEGV;
info.si_errno = 0;
info.si_code = TARGET_SEGV_MAPERR;
info._sifields._sigfault._addr = arg6;
queue_signal((CPUArchState *)cpu_env, info.si_signo, &info);
ret = 0xdeadbeef;
if (mem_value == arg2)
put_user_u32(arg1, arg6);
ret = mem_value;
#endif
#ifdef TARGET_NR_atomic_barrier
case TARGET_NR_atomic_barrier:
{
ret = 0;
#endif
#ifdef TARGET_NR_timer_create
case TARGET_NR_timer_create:
{
struct sigevent host_sevp = { {0}, }, *phost_sevp = NULL;
int clkid = arg1;
int timer_index = next_free_host_timer();
if (timer_index < 0) {
ret = -TARGET_EAGAIN;
} else {
timer_t *phtimer = g_posix_timers + timer_index;
if (arg2) {
phost_sevp = &host_sevp;
ret = target_to_host_sigevent(phost_sevp, arg2);
if (ret != 0) {
ret = get_errno(timer_create(clkid, phost_sevp, phtimer));
if (ret) {
phtimer = NULL;
} else {
if (put_user(TIMER_MAGIC | timer_index, arg3, target_timer_t)) {
goto efault;
#endif
#ifdef TARGET_NR_timer_settime
case TARGET_NR_timer_settime:
{
target_timer_t timerid = get_timer_id(arg1);
if (timerid < 0) {
ret = timerid;
} else if (arg3 == 0) {
} else {
timer_t htimer = g_posix_timers[timerid];
struct itimerspec hspec_new = {{0},}, hspec_old = {{0},};
target_to_host_itimerspec(&hspec_new, arg3);
ret = get_errno(
timer_settime(htimer, arg2, &hspec_new, &hspec_old));
host_to_target_itimerspec(arg2, &hspec_old);
#endif
#ifdef TARGET_NR_timer_gettime
case TARGET_NR_timer_gettime:
{
target_timer_t timerid = get_timer_id(arg1);
if (timerid < 0) {
ret = timerid;
} else if (!arg2) {
ret = -TARGET_EFAULT;
} else {
timer_t htimer = g_posix_timers[timerid];
struct itimerspec hspec;
ret = get_errno(timer_gettime(htimer, &hspec));
if (host_to_target_itimerspec(arg2, &hspec)) {
ret = -TARGET_EFAULT;
#endif
#ifdef TARGET_NR_timer_getoverrun
case TARGET_NR_timer_getoverrun:
{
target_timer_t timerid = get_timer_id(arg1);
if (timerid < 0) {
ret = timerid;
} else {
timer_t htimer = g_posix_timers[timerid];
ret = get_errno(timer_getoverrun(htimer));
fd_trans_unregister(ret);
#endif
#ifdef TARGET_NR_timer_delete
case TARGET_NR_timer_delete:
{
target_timer_t timerid = get_timer_id(arg1);
if (timerid < 0) {
ret = timerid;
} else {
timer_t htimer = g_posix_timers[timerid];
ret = get_errno(timer_delete(htimer));
g_posix_timers[timerid] = 0;
#endif
#if defined(TARGET_NR_timerfd_create) && defined(CONFIG_TIMERFD)
case TARGET_NR_timerfd_create:
ret = get_errno(timerfd_create(arg1,
target_to_host_bitmask(arg2, fcntl_flags_tbl)));
#endif
#if defined(TARGET_NR_timerfd_gettime) && defined(CONFIG_TIMERFD)
case TARGET_NR_timerfd_gettime:
{
struct itimerspec its_curr;
ret = get_errno(timerfd_gettime(arg1, &its_curr));
if (arg2 && host_to_target_itimerspec(arg2, &its_curr)) {
goto efault;
#endif
#if defined(TARGET_NR_timerfd_settime) && defined(CONFIG_TIMERFD)
case TARGET_NR_timerfd_settime:
{
struct itimerspec its_new, its_old, *p_new;
if (arg3) {
if (target_to_host_itimerspec(&its_new, arg3)) {
goto efault;
p_new = &its_new;
} else {
p_new = NULL;
ret = get_errno(timerfd_settime(arg1, arg2, p_new, &its_old));
if (arg4 && host_to_target_itimerspec(arg4, &its_old)) {
goto efault;
#endif
#if defined(TARGET_NR_ioprio_get) && defined(__NR_ioprio_get)
case TARGET_NR_ioprio_get:
ret = get_errno(ioprio_get(arg1, arg2));
#endif
#if defined(TARGET_NR_ioprio_set) && defined(__NR_ioprio_set)
case TARGET_NR_ioprio_set:
ret = get_errno(ioprio_set(arg1, arg2, arg3));
#endif
#if defined(TARGET_NR_setns) && defined(CONFIG_SETNS)
case TARGET_NR_setns:
ret = get_errno(setns(arg1, arg2));
#endif
#if defined(TARGET_NR_unshare) && defined(CONFIG_SETNS)
case TARGET_NR_unshare:
ret = get_errno(unshare(arg1));
#endif
default:
unimplemented:
gemu_log("qemu: Unsupported syscall: %d\n", num);
#if defined(TARGET_NR_setxattr) || defined(TARGET_NR_get_thread_area) || defined(TARGET_NR_getdomainname) || defined(TARGET_NR_set_robust_list)
unimplemented_nowarn:
#endif
ret = -TARGET_ENOSYS;
fail:
#ifdef DEBUG
gemu_log(" = " TARGET_ABI_FMT_ld "\n", ret);
#endif
if(do_strace)
print_syscall_ret(num, ret);
trace_guest_user_syscall_ret(cpu, num, ret);
return ret;
efault:
ret = -TARGET_EFAULT;
goto fail; | [
"abi_long FUNC_0(void *cpu_env, int num, abi_long arg1,\nabi_long arg2, abi_long arg3, abi_long arg4,\nabi_long arg5, abi_long arg6, abi_long arg7,\nabi_long arg8)\n{",
"CPUState *cpu = ENV_GET_CPU(cpu_env);",
"abi_long ret;",
"struct stat VAR_0;",
"struct statfs VAR_1;",
"void *VAR_2;",
"#if defined(DEBUG_ERESTARTSYS)\n{",
"static int flag;",
"flag = !flag;",
"if (flag) {",
"return -TARGET_ERESTARTSYS;",
"#endif\n#ifdef DEBUG\ngemu_log(\"syscall %d\", num);",
"#endif\ntrace_guest_user_syscall(cpu, num, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);",
"if(do_strace)\nprint_syscall(num, arg1, arg2, arg3, arg4, arg5, arg6);",
"switch(num) {",
"case TARGET_NR_exit:\nif (block_signals()) {",
"ret = -TARGET_ERESTARTSYS;",
"if (CPU_NEXT(first_cpu)) {",
"TaskState *ts;",
"cpu_list_lock();",
"QTAILQ_REMOVE(&cpus, cpu, node);",
"cpu_list_unlock();",
"ts = cpu->opaque;",
"if (ts->child_tidptr) {",
"put_user_u32(0, ts->child_tidptr);",
"sys_futex(g2h(ts->child_tidptr), FUTEX_WAKE, INT_MAX,\nNULL, NULL, 0);",
"thread_cpu = NULL;",
"object_unref(OBJECT(cpu));",
"g_free(ts);",
"rcu_unregister_thread();",
"pthread_exit(NULL);",
"#ifdef TARGET_GPROF\n_mcleanup();",
"#endif\ngdb_exit(cpu_env, arg1);",
"_exit(arg1);",
"ret = 0;",
"case TARGET_NR_read:\nif (arg3 == 0)\nret = 0;",
"else {",
"if (!(VAR_2 = lock_user(VERIFY_WRITE, arg2, arg3, 0)))\ngoto efault;",
"ret = get_errno(safe_read(arg1, VAR_2, arg3));",
"if (ret >= 0 &&\nfd_trans_host_to_target_data(arg1)) {",
"ret = fd_trans_host_to_target_data(arg1)(VAR_2, ret);",
"unlock_user(VAR_2, arg2, ret);",
"case TARGET_NR_write:\nif (!(VAR_2 = lock_user(VERIFY_READ, arg2, arg3, 1)))\ngoto efault;",
"ret = get_errno(safe_write(arg1, VAR_2, arg3));",
"unlock_user(VAR_2, arg2, 0);",
"#ifdef TARGET_NR_open\ncase TARGET_NR_open:\nif (!(VAR_2 = lock_user_string(arg1)))\ngoto efault;",
"ret = get_errno(do_openat(cpu_env, AT_FDCWD, VAR_2,\ntarget_to_host_bitmask(arg2, fcntl_flags_tbl),\narg3));",
"fd_trans_unregister(ret);",
"unlock_user(VAR_2, arg1, 0);",
"#endif\ncase TARGET_NR_openat:\nif (!(VAR_2 = lock_user_string(arg2)))\ngoto efault;",
"ret = get_errno(do_openat(cpu_env, arg1, VAR_2,\ntarget_to_host_bitmask(arg3, fcntl_flags_tbl),\narg4));",
"fd_trans_unregister(ret);",
"unlock_user(VAR_2, arg2, 0);",
"#if defined(TARGET_NR_name_to_handle_at) && defined(CONFIG_OPEN_BY_HANDLE)\ncase TARGET_NR_name_to_handle_at:\nret = do_name_to_handle_at(arg1, arg2, arg3, arg4, arg5);",
"#endif\n#if defined(TARGET_NR_open_by_handle_at) && defined(CONFIG_OPEN_BY_HANDLE)\ncase TARGET_NR_open_by_handle_at:\nret = do_open_by_handle_at(arg1, arg2, arg3);",
"fd_trans_unregister(ret);",
"#endif\ncase TARGET_NR_close:\nfd_trans_unregister(arg1);",
"ret = get_errno(close(arg1));",
"case TARGET_NR_brk:\nret = do_brk(arg1);",
"#ifdef TARGET_NR_fork\ncase TARGET_NR_fork:\nret = get_errno(do_fork(cpu_env, SIGCHLD, 0, 0, 0, 0));",
"#endif\n#ifdef TARGET_NR_waitpid\ncase TARGET_NR_waitpid:\n{",
"int status;",
"ret = get_errno(safe_wait4(arg1, &status, arg3, 0));",
"if (!is_error(ret) && arg2 && ret\n&& put_user_s32(host_to_target_waitstatus(status), arg2))\ngoto efault;",
"#endif\n#ifdef TARGET_NR_waitid\ncase TARGET_NR_waitid:\n{",
"siginfo_t info;",
"info.si_pid = 0;",
"ret = get_errno(safe_waitid(arg1, arg2, &info, arg4, NULL));",
"if (!is_error(ret) && arg3 && info.si_pid != 0) {",
"if (!(VAR_2 = lock_user(VERIFY_WRITE, arg3, sizeof(target_siginfo_t), 0)))\ngoto efault;",
"host_to_target_siginfo(VAR_2, &info);",
"unlock_user(VAR_2, arg3, sizeof(target_siginfo_t));",
"#endif\n#ifdef TARGET_NR_creat\ncase TARGET_NR_creat:\nif (!(VAR_2 = lock_user_string(arg1)))\ngoto efault;",
"ret = get_errno(creat(VAR_2, arg2));",
"fd_trans_unregister(ret);",
"unlock_user(VAR_2, arg1, 0);",
"#endif\n#ifdef TARGET_NR_link\ncase TARGET_NR_link:\n{",
"void * p2;",
"VAR_2 = lock_user_string(arg1);",
"p2 = lock_user_string(arg2);",
"if (!VAR_2 || !p2)\nret = -TARGET_EFAULT;",
"else\nret = get_errno(link(VAR_2, p2));",
"unlock_user(p2, arg2, 0);",
"unlock_user(VAR_2, arg1, 0);",
"#endif\n#if defined(TARGET_NR_linkat)\ncase TARGET_NR_linkat:\n{",
"void * p2 = NULL;",
"if (!arg2 || !arg4)\ngoto efault;",
"VAR_2 = lock_user_string(arg2);",
"p2 = lock_user_string(arg4);",
"if (!VAR_2 || !p2)\nret = -TARGET_EFAULT;",
"else\nret = get_errno(linkat(arg1, VAR_2, arg3, p2, arg5));",
"unlock_user(VAR_2, arg2, 0);",
"unlock_user(p2, arg4, 0);",
"#endif\n#ifdef TARGET_NR_unlink\ncase TARGET_NR_unlink:\nif (!(VAR_2 = lock_user_string(arg1)))\ngoto efault;",
"ret = get_errno(unlink(VAR_2));",
"unlock_user(VAR_2, arg1, 0);",
"#endif\n#if defined(TARGET_NR_unlinkat)\ncase TARGET_NR_unlinkat:\nif (!(VAR_2 = lock_user_string(arg2)))\ngoto efault;",
"ret = get_errno(unlinkat(arg1, VAR_2, arg3));",
"unlock_user(VAR_2, arg2, 0);",
"#endif\ncase TARGET_NR_execve:\n{",
"char **VAR_3, **VAR_4;",
"int VAR_5, VAR_6;",
"abi_ulong gp;",
"abi_ulong guest_argp;",
"abi_ulong guest_envp;",
"abi_ulong addr;",
"char **VAR_7;",
"int VAR_8 = 0;",
"VAR_5 = 0;",
"guest_argp = arg2;",
"for (gp = guest_argp; gp; gp += sizeof(abi_ulong)) {",
"if (get_user_ual(addr, gp))\ngoto efault;",
"if (!addr)\nVAR_5++;",
"VAR_6 = 0;",
"guest_envp = arg3;",
"for (gp = guest_envp; gp; gp += sizeof(abi_ulong)) {",
"if (get_user_ual(addr, gp))\ngoto efault;",
"if (!addr)\nVAR_6++;",
"VAR_3 = alloca((VAR_5 + 1) * sizeof(void *));",
"VAR_4 = alloca((VAR_6 + 1) * sizeof(void *));",
"for (gp = guest_argp, VAR_7 = VAR_3; gp;",
"gp += sizeof(abi_ulong), VAR_7++) {",
"if (get_user_ual(addr, gp))\ngoto execve_efault;",
"if (!addr)\nif (!(*VAR_7 = lock_user_string(addr)))\ngoto execve_efault;",
"VAR_8 += strlen(*VAR_7) + 1;",
"*VAR_7 = NULL;",
"for (gp = guest_envp, VAR_7 = VAR_4; gp;",
"gp += sizeof(abi_ulong), VAR_7++) {",
"if (get_user_ual(addr, gp))\ngoto execve_efault;",
"if (!addr)\nif (!(*VAR_7 = lock_user_string(addr)))\ngoto execve_efault;",
"VAR_8 += strlen(*VAR_7) + 1;",
"*VAR_7 = NULL;",
"if (!(VAR_2 = lock_user_string(arg1)))\ngoto execve_efault;",
"ret = get_errno(safe_execve(VAR_2, VAR_3, VAR_4));",
"unlock_user(VAR_2, arg1, 0);",
"goto execve_end;",
"execve_efault:\nret = -TARGET_EFAULT;",
"execve_end:\nfor (gp = guest_argp, VAR_7 = VAR_3; *VAR_7;",
"gp += sizeof(abi_ulong), VAR_7++) {",
"if (get_user_ual(addr, gp)\n|| !addr)\nunlock_user(*VAR_7, addr, 0);",
"for (gp = guest_envp, VAR_7 = VAR_4; *VAR_7;",
"gp += sizeof(abi_ulong), VAR_7++) {",
"if (get_user_ual(addr, gp)\n|| !addr)\nunlock_user(*VAR_7, addr, 0);",
"case TARGET_NR_chdir:\nif (!(VAR_2 = lock_user_string(arg1)))\ngoto efault;",
"ret = get_errno(chdir(VAR_2));",
"unlock_user(VAR_2, arg1, 0);",
"#ifdef TARGET_NR_time\ncase TARGET_NR_time:\n{",
"time_t host_time;",
"ret = get_errno(time(&host_time));",
"if (!is_error(ret)\n&& arg1\n&& put_user_sal(host_time, arg1))\ngoto efault;",
"#endif\n#ifdef TARGET_NR_mknod\ncase TARGET_NR_mknod:\nif (!(VAR_2 = lock_user_string(arg1)))\ngoto efault;",
"ret = get_errno(mknod(VAR_2, arg2, arg3));",
"unlock_user(VAR_2, arg1, 0);",
"#endif\n#if defined(TARGET_NR_mknodat)\ncase TARGET_NR_mknodat:\nif (!(VAR_2 = lock_user_string(arg2)))\ngoto efault;",
"ret = get_errno(mknodat(arg1, VAR_2, arg3, arg4));",
"unlock_user(VAR_2, arg2, 0);",
"#endif\n#ifdef TARGET_NR_chmod\ncase TARGET_NR_chmod:\nif (!(VAR_2 = lock_user_string(arg1)))\ngoto efault;",
"ret = get_errno(chmod(VAR_2, arg2));",
"unlock_user(VAR_2, arg1, 0);",
"#endif\n#ifdef TARGET_NR_break\ncase TARGET_NR_break:\ngoto unimplemented;",
"#endif\n#ifdef TARGET_NR_oldstat\ncase TARGET_NR_oldstat:\ngoto unimplemented;",
"#endif\ncase TARGET_NR_lseek:\nret = get_errno(lseek(arg1, arg2, arg3));",
"#if defined(TARGET_NR_getxpid) && defined(TARGET_ALPHA)\ncase TARGET_NR_getxpid:\n((CPUAlphaState *)cpu_env)->ir[IR_A4] = getppid();",
"ret = get_errno(getpid());",
"#endif\n#ifdef TARGET_NR_getpid\ncase TARGET_NR_getpid:\nret = get_errno(getpid());",
"#endif\ncase TARGET_NR_mount:\n{",
"void *p2, *p3;",
"if (arg1) {",
"VAR_2 = lock_user_string(arg1);",
"if (!VAR_2) {",
"goto efault;",
"} else {",
"VAR_2 = NULL;",
"p2 = lock_user_string(arg2);",
"if (!p2) {",
"if (arg1) {",
"unlock_user(VAR_2, arg1, 0);",
"goto efault;",
"if (arg3) {",
"p3 = lock_user_string(arg3);",
"if (!p3) {",
"if (arg1) {",
"unlock_user(VAR_2, arg1, 0);",
"unlock_user(p2, arg2, 0);",
"goto efault;",
"} else {",
"p3 = NULL;",
"if (!arg5) {",
"ret = mount(VAR_2, p2, p3, (unsigned long)arg4, NULL);",
"} else {",
"ret = mount(VAR_2, p2, p3, (unsigned long)arg4, g2h(arg5));",
"ret = get_errno(ret);",
"if (arg1) {",
"unlock_user(VAR_2, arg1, 0);",
"unlock_user(p2, arg2, 0);",
"if (arg3) {",
"unlock_user(p3, arg3, 0);",
"#ifdef TARGET_NR_umount\ncase TARGET_NR_umount:\nif (!(VAR_2 = lock_user_string(arg1)))\ngoto efault;",
"ret = get_errno(umount(VAR_2));",
"unlock_user(VAR_2, arg1, 0);",
"#endif\n#ifdef TARGET_NR_stime\ncase TARGET_NR_stime:\n{",
"time_t host_time;",
"if (get_user_sal(host_time, arg1))\ngoto efault;",
"ret = get_errno(stime(&host_time));",
"#endif\ncase TARGET_NR_ptrace:\ngoto unimplemented;",
"#ifdef TARGET_NR_alarm\ncase TARGET_NR_alarm:\nret = alarm(arg1);",
"#endif\n#ifdef TARGET_NR_oldfstat\ncase TARGET_NR_oldfstat:\ngoto unimplemented;",
"#endif\n#ifdef TARGET_NR_pause\ncase TARGET_NR_pause:\nif (!block_signals()) {",
"sigsuspend(&((TaskState *)cpu->opaque)->signal_mask);",
"ret = -TARGET_EINTR;",
"#endif\n#ifdef TARGET_NR_utime\ncase TARGET_NR_utime:\n{",
"struct utimbuf tbuf, *host_tbuf;",
"struct target_utimbuf *target_tbuf;",
"if (arg2) {",
"if (!lock_user_struct(VERIFY_READ, target_tbuf, arg2, 1))\ngoto efault;",
"tbuf.actime = tswapal(target_tbuf->actime);",
"tbuf.modtime = tswapal(target_tbuf->modtime);",
"unlock_user_struct(target_tbuf, arg2, 0);",
"host_tbuf = &tbuf;",
"} else {",
"host_tbuf = NULL;",
"if (!(VAR_2 = lock_user_string(arg1)))\ngoto efault;",
"ret = get_errno(utime(VAR_2, host_tbuf));",
"unlock_user(VAR_2, arg1, 0);",
"#endif\n#ifdef TARGET_NR_utimes\ncase TARGET_NR_utimes:\n{",
"struct timeval *tvp, tv[2];",
"if (arg2) {",
"if (copy_from_user_timeval(&tv[0], arg2)\n|| copy_from_user_timeval(&tv[1],\narg2 + sizeof(struct target_timeval)))\ngoto efault;",
"tvp = tv;",
"} else {",
"tvp = NULL;",
"if (!(VAR_2 = lock_user_string(arg1)))\ngoto efault;",
"ret = get_errno(utimes(VAR_2, tvp));",
"unlock_user(VAR_2, arg1, 0);",
"#endif\n#if defined(TARGET_NR_futimesat)\ncase TARGET_NR_futimesat:\n{",
"struct timeval *tvp, tv[2];",
"if (arg3) {",
"if (copy_from_user_timeval(&tv[0], arg3)\n|| copy_from_user_timeval(&tv[1],\narg3 + sizeof(struct target_timeval)))\ngoto efault;",
"tvp = tv;",
"} else {",
"tvp = NULL;",
"if (!(VAR_2 = lock_user_string(arg2)))\ngoto efault;",
"ret = get_errno(futimesat(arg1, path(VAR_2), tvp));",
"unlock_user(VAR_2, arg2, 0);",
"#endif\n#ifdef TARGET_NR_stty\ncase TARGET_NR_stty:\ngoto unimplemented;",
"#endif\n#ifdef TARGET_NR_gtty\ncase TARGET_NR_gtty:\ngoto unimplemented;",
"#endif\n#ifdef TARGET_NR_access\ncase TARGET_NR_access:\nif (!(VAR_2 = lock_user_string(arg1)))\ngoto efault;",
"ret = get_errno(access(path(VAR_2), arg2));",
"unlock_user(VAR_2, arg1, 0);",
"#endif\n#if defined(TARGET_NR_faccessat) && defined(__NR_faccessat)\ncase TARGET_NR_faccessat:\nif (!(VAR_2 = lock_user_string(arg2)))\ngoto efault;",
"ret = get_errno(faccessat(arg1, VAR_2, arg3, 0));",
"unlock_user(VAR_2, arg2, 0);",
"#endif\n#ifdef TARGET_NR_nice\ncase TARGET_NR_nice:\nret = get_errno(nice(arg1));",
"#endif\n#ifdef TARGET_NR_ftime\ncase TARGET_NR_ftime:\ngoto unimplemented;",
"#endif\ncase TARGET_NR_sync:\nsync();",
"ret = 0;",
"case TARGET_NR_kill:\nret = get_errno(safe_kill(arg1, target_to_host_signal(arg2)));",
"#ifdef TARGET_NR_rename\ncase TARGET_NR_rename:\n{",
"void *p2;",
"VAR_2 = lock_user_string(arg1);",
"p2 = lock_user_string(arg2);",
"if (!VAR_2 || !p2)\nret = -TARGET_EFAULT;",
"else\nret = get_errno(rename(VAR_2, p2));",
"unlock_user(p2, arg2, 0);",
"unlock_user(VAR_2, arg1, 0);",
"#endif\n#if defined(TARGET_NR_renameat)\ncase TARGET_NR_renameat:\n{",
"void *p2;",
"VAR_2 = lock_user_string(arg2);",
"p2 = lock_user_string(arg4);",
"if (!VAR_2 || !p2)\nret = -TARGET_EFAULT;",
"else\nret = get_errno(renameat(arg1, VAR_2, arg3, p2));",
"unlock_user(p2, arg4, 0);",
"unlock_user(VAR_2, arg2, 0);",
"#endif\n#ifdef TARGET_NR_mkdir\ncase TARGET_NR_mkdir:\nif (!(VAR_2 = lock_user_string(arg1)))\ngoto efault;",
"ret = get_errno(mkdir(VAR_2, arg2));",
"unlock_user(VAR_2, arg1, 0);",
"#endif\n#if defined(TARGET_NR_mkdirat)\ncase TARGET_NR_mkdirat:\nif (!(VAR_2 = lock_user_string(arg2)))\ngoto efault;",
"ret = get_errno(mkdirat(arg1, VAR_2, arg3));",
"unlock_user(VAR_2, arg2, 0);",
"#endif\n#ifdef TARGET_NR_rmdir\ncase TARGET_NR_rmdir:\nif (!(VAR_2 = lock_user_string(arg1)))\ngoto efault;",
"ret = get_errno(rmdir(VAR_2));",
"unlock_user(VAR_2, arg1, 0);",
"#endif\ncase TARGET_NR_dup:\nret = get_errno(dup(arg1));",
"if (ret >= 0) {",
"fd_trans_dup(arg1, ret);",
"#ifdef TARGET_NR_pipe\ncase TARGET_NR_pipe:\nret = do_pipe(cpu_env, arg1, 0, 0);",
"#endif\n#ifdef TARGET_NR_pipe2\ncase TARGET_NR_pipe2:\nret = do_pipe(cpu_env, arg1,\ntarget_to_host_bitmask(arg2, fcntl_flags_tbl), 1);",
"#endif\ncase TARGET_NR_times:\n{",
"struct target_tms *tmsp;",
"struct tms tms;",
"ret = get_errno(times(&tms));",
"if (arg1) {",
"tmsp = lock_user(VERIFY_WRITE, arg1, sizeof(struct target_tms), 0);",
"if (!tmsp)\ngoto efault;",
"tmsp->tms_utime = tswapal(host_to_target_clock_t(tms.tms_utime));",
"tmsp->tms_stime = tswapal(host_to_target_clock_t(tms.tms_stime));",
"tmsp->tms_cutime = tswapal(host_to_target_clock_t(tms.tms_cutime));",
"tmsp->tms_cstime = tswapal(host_to_target_clock_t(tms.tms_cstime));",
"if (!is_error(ret))\nret = host_to_target_clock_t(ret);",
"#ifdef TARGET_NR_prof\ncase TARGET_NR_prof:\ngoto unimplemented;",
"#endif\n#ifdef TARGET_NR_signal\ncase TARGET_NR_signal:\ngoto unimplemented;",
"#endif\ncase TARGET_NR_acct:\nif (arg1 == 0) {",
"ret = get_errno(acct(NULL));",
"} else {",
"if (!(VAR_2 = lock_user_string(arg1)))\ngoto efault;",
"ret = get_errno(acct(path(VAR_2)));",
"unlock_user(VAR_2, arg1, 0);",
"#ifdef TARGET_NR_umount2\ncase TARGET_NR_umount2:\nif (!(VAR_2 = lock_user_string(arg1)))\ngoto efault;",
"ret = get_errno(umount2(VAR_2, arg2));",
"unlock_user(VAR_2, arg1, 0);",
"#endif\n#ifdef TARGET_NR_lock\ncase TARGET_NR_lock:\ngoto unimplemented;",
"#endif\ncase TARGET_NR_ioctl:\nret = do_ioctl(arg1, arg2, arg3);",
"case TARGET_NR_fcntl:\nret = do_fcntl(arg1, arg2, arg3);",
"#ifdef TARGET_NR_mpx\ncase TARGET_NR_mpx:\ngoto unimplemented;",
"#endif\ncase TARGET_NR_setpgid:\nret = get_errno(setpgid(arg1, arg2));",
"#ifdef TARGET_NR_ulimit\ncase TARGET_NR_ulimit:\ngoto unimplemented;",
"#endif\n#ifdef TARGET_NR_oldolduname\ncase TARGET_NR_oldolduname:\ngoto unimplemented;",
"#endif\ncase TARGET_NR_umask:\nret = get_errno(umask(arg1));",
"case TARGET_NR_chroot:\nif (!(VAR_2 = lock_user_string(arg1)))\ngoto efault;",
"ret = get_errno(chroot(VAR_2));",
"unlock_user(VAR_2, arg1, 0);",
"#ifdef TARGET_NR_ustat\ncase TARGET_NR_ustat:\ngoto unimplemented;",
"#endif\n#ifdef TARGET_NR_dup2\ncase TARGET_NR_dup2:\nret = get_errno(dup2(arg1, arg2));",
"if (ret >= 0) {",
"fd_trans_dup(arg1, arg2);",
"#endif\n#if defined(CONFIG_DUP3) && defined(TARGET_NR_dup3)\ncase TARGET_NR_dup3:\nret = get_errno(dup3(arg1, arg2, arg3));",
"if (ret >= 0) {",
"fd_trans_dup(arg1, arg2);",
"#endif\n#ifdef TARGET_NR_getppid\ncase TARGET_NR_getppid:\nret = get_errno(getppid());",
"#endif\n#ifdef TARGET_NR_getpgrp\ncase TARGET_NR_getpgrp:\nret = get_errno(getpgrp());",
"#endif\ncase TARGET_NR_setsid:\nret = get_errno(setsid());",
"#ifdef TARGET_NR_sigaction\ncase TARGET_NR_sigaction:\n{",
"#if defined(TARGET_ALPHA)\nstruct target_sigaction act, oact, *pact = 0;",
"struct target_old_sigaction *old_act;",
"if (arg2) {",
"if (!lock_user_struct(VERIFY_READ, old_act, arg2, 1))\ngoto efault;",
"act._sa_handler = old_act->_sa_handler;",
"target_siginitset(&act.sa_mask, old_act->sa_mask);",
"act.sa_flags = old_act->sa_flags;",
"act.sa_restorer = 0;",
"unlock_user_struct(old_act, arg2, 0);",
"pact = &act;",
"ret = get_errno(do_sigaction(arg1, pact, &oact));",
"if (!is_error(ret) && arg3) {",
"if (!lock_user_struct(VERIFY_WRITE, old_act, arg3, 0))\ngoto efault;",
"old_act->_sa_handler = oact._sa_handler;",
"old_act->sa_mask = oact.sa_mask.sig[0];",
"old_act->sa_flags = oact.sa_flags;",
"unlock_user_struct(old_act, arg3, 1);",
"#elif defined(TARGET_MIPS)\nstruct target_sigaction act, oact, *pact, *old_act;",
"if (arg2) {",
"if (!lock_user_struct(VERIFY_READ, old_act, arg2, 1))\ngoto efault;",
"act._sa_handler = old_act->_sa_handler;",
"target_siginitset(&act.sa_mask, old_act->sa_mask.sig[0]);",
"act.sa_flags = old_act->sa_flags;",
"unlock_user_struct(old_act, arg2, 0);",
"pact = &act;",
"} else {",
"pact = NULL;",
"ret = get_errno(do_sigaction(arg1, pact, &oact));",
"if (!is_error(ret) && arg3) {",
"if (!lock_user_struct(VERIFY_WRITE, old_act, arg3, 0))\ngoto efault;",
"old_act->_sa_handler = oact._sa_handler;",
"old_act->sa_flags = oact.sa_flags;",
"old_act->sa_mask.sig[0] = oact.sa_mask.sig[0];",
"old_act->sa_mask.sig[1] = 0;",
"old_act->sa_mask.sig[2] = 0;",
"old_act->sa_mask.sig[3] = 0;",
"unlock_user_struct(old_act, arg3, 1);",
"#else\nstruct target_old_sigaction *old_act;",
"struct target_sigaction act, oact, *pact;",
"if (arg2) {",
"if (!lock_user_struct(VERIFY_READ, old_act, arg2, 1))\ngoto efault;",
"act._sa_handler = old_act->_sa_handler;",
"target_siginitset(&act.sa_mask, old_act->sa_mask);",
"act.sa_flags = old_act->sa_flags;",
"act.sa_restorer = old_act->sa_restorer;",
"unlock_user_struct(old_act, arg2, 0);",
"pact = &act;",
"} else {",
"pact = NULL;",
"ret = get_errno(do_sigaction(arg1, pact, &oact));",
"if (!is_error(ret) && arg3) {",
"if (!lock_user_struct(VERIFY_WRITE, old_act, arg3, 0))\ngoto efault;",
"old_act->_sa_handler = oact._sa_handler;",
"old_act->sa_mask = oact.sa_mask.sig[0];",
"old_act->sa_flags = oact.sa_flags;",
"old_act->sa_restorer = oact.sa_restorer;",
"unlock_user_struct(old_act, arg3, 1);",
"#endif\n#endif\ncase TARGET_NR_rt_sigaction:\n{",
"#if defined(TARGET_ALPHA)\nstruct target_sigaction act, oact, *pact = 0;",
"struct target_rt_sigaction *rt_act;",
"if (arg4 != sizeof(target_sigset_t)) {",
"if (arg2) {",
"if (!lock_user_struct(VERIFY_READ, rt_act, arg2, 1))\ngoto efault;",
"act._sa_handler = rt_act->_sa_handler;",
"act.sa_mask = rt_act->sa_mask;",
"act.sa_flags = rt_act->sa_flags;",
"act.sa_restorer = arg5;",
"unlock_user_struct(rt_act, arg2, 0);",
"pact = &act;",
"ret = get_errno(do_sigaction(arg1, pact, &oact));",
"if (!is_error(ret) && arg3) {",
"if (!lock_user_struct(VERIFY_WRITE, rt_act, arg3, 0))\ngoto efault;",
"rt_act->_sa_handler = oact._sa_handler;",
"rt_act->sa_mask = oact.sa_mask;",
"rt_act->sa_flags = oact.sa_flags;",
"unlock_user_struct(rt_act, arg3, 1);",
"#else\nstruct target_sigaction *act;",
"struct target_sigaction *oact;",
"if (arg4 != sizeof(target_sigset_t)) {",
"if (arg2) {",
"if (!lock_user_struct(VERIFY_READ, act, arg2, 1))\ngoto efault;",
"} else",
"act = NULL;",
"if (arg3) {",
"if (!lock_user_struct(VERIFY_WRITE, oact, arg3, 0)) {",
"ret = -TARGET_EFAULT;",
"goto rt_sigaction_fail;",
"} else",
"oact = NULL;",
"ret = get_errno(do_sigaction(arg1, act, oact));",
"rt_sigaction_fail:\nif (act)\nunlock_user_struct(act, arg2, 0);",
"if (oact)\nunlock_user_struct(oact, arg3, 1);",
"#endif\n#ifdef TARGET_NR_sgetmask\ncase TARGET_NR_sgetmask:\n{",
"sigset_t cur_set;",
"abi_ulong target_set;",
"ret = do_sigprocmask(0, NULL, &cur_set);",
"if (!ret) {",
"host_to_target_old_sigset(&target_set, &cur_set);",
"ret = target_set;",
"#endif\n#ifdef TARGET_NR_ssetmask\ncase TARGET_NR_ssetmask:\n{",
"sigset_t set, oset, cur_set;",
"abi_ulong target_set = arg1;",
"ret = do_sigprocmask(0, NULL, &cur_set);",
"assert(!ret);",
"target_to_host_old_sigset(&set, &target_set);",
"sigorset(&set, &set, &cur_set);",
"ret = do_sigprocmask(SIG_SETMASK, &set, &oset);",
"if (!ret) {",
"host_to_target_old_sigset(&target_set, &oset);",
"ret = target_set;",
"#endif\n#ifdef TARGET_NR_sigprocmask\ncase TARGET_NR_sigprocmask:\n{",
"#if defined(TARGET_ALPHA)\nsigset_t set, oldset;",
"abi_ulong mask;",
"int how;",
"switch (arg1) {",
"case TARGET_SIG_BLOCK:\nhow = SIG_BLOCK;",
"case TARGET_SIG_UNBLOCK:\nhow = SIG_UNBLOCK;",
"case TARGET_SIG_SETMASK:\nhow = SIG_SETMASK;",
"default:\ngoto fail;",
"mask = arg2;",
"target_to_host_old_sigset(&set, &mask);",
"ret = do_sigprocmask(how, &set, &oldset);",
"if (!is_error(ret)) {",
"host_to_target_old_sigset(&mask, &oldset);",
"ret = mask;",
"((CPUAlphaState *)cpu_env)->ir[IR_V0] = 0;",
"#else\nsigset_t set, oldset, *set_ptr;",
"int how;",
"if (arg2) {",
"switch (arg1) {",
"case TARGET_SIG_BLOCK:\nhow = SIG_BLOCK;",
"case TARGET_SIG_UNBLOCK:\nhow = SIG_UNBLOCK;",
"case TARGET_SIG_SETMASK:\nhow = SIG_SETMASK;",
"default:\ngoto fail;",
"if (!(VAR_2 = lock_user(VERIFY_READ, arg2, sizeof(target_sigset_t), 1)))\ngoto efault;",
"target_to_host_old_sigset(&set, VAR_2);",
"unlock_user(VAR_2, arg2, 0);",
"set_ptr = &set;",
"} else {",
"how = 0;",
"set_ptr = NULL;",
"ret = do_sigprocmask(how, set_ptr, &oldset);",
"if (!is_error(ret) && arg3) {",
"if (!(VAR_2 = lock_user(VERIFY_WRITE, arg3, sizeof(target_sigset_t), 0)))\ngoto efault;",
"host_to_target_old_sigset(VAR_2, &oldset);",
"unlock_user(VAR_2, arg3, sizeof(target_sigset_t));",
"#endif\n#endif\ncase TARGET_NR_rt_sigprocmask:\n{",
"int how = arg1;",
"sigset_t set, oldset, *set_ptr;",
"if (arg4 != sizeof(target_sigset_t)) {",
"if (arg2) {",
"switch(how) {",
"case TARGET_SIG_BLOCK:\nhow = SIG_BLOCK;",
"case TARGET_SIG_UNBLOCK:\nhow = SIG_UNBLOCK;",
"case TARGET_SIG_SETMASK:\nhow = SIG_SETMASK;",
"default:\ngoto fail;",
"if (!(VAR_2 = lock_user(VERIFY_READ, arg2, sizeof(target_sigset_t), 1)))\ngoto efault;",
"target_to_host_sigset(&set, VAR_2);",
"unlock_user(VAR_2, arg2, 0);",
"set_ptr = &set;",
"} else {",
"how = 0;",
"set_ptr = NULL;",
"ret = do_sigprocmask(how, set_ptr, &oldset);",
"if (!is_error(ret) && arg3) {",
"if (!(VAR_2 = lock_user(VERIFY_WRITE, arg3, sizeof(target_sigset_t), 0)))\ngoto efault;",
"host_to_target_sigset(VAR_2, &oldset);",
"unlock_user(VAR_2, arg3, sizeof(target_sigset_t));",
"#ifdef TARGET_NR_sigpending\ncase TARGET_NR_sigpending:\n{",
"sigset_t set;",
"ret = get_errno(sigpending(&set));",
"if (!is_error(ret)) {",
"if (!(VAR_2 = lock_user(VERIFY_WRITE, arg1, sizeof(target_sigset_t), 0)))\ngoto efault;",
"host_to_target_old_sigset(VAR_2, &set);",
"unlock_user(VAR_2, arg1, sizeof(target_sigset_t));",
"#endif\ncase TARGET_NR_rt_sigpending:\n{",
"sigset_t set;",
"if (arg2 > sizeof(target_sigset_t)) {",
"ret = get_errno(sigpending(&set));",
"if (!is_error(ret)) {",
"if (!(VAR_2 = lock_user(VERIFY_WRITE, arg1, sizeof(target_sigset_t), 0)))\ngoto efault;",
"host_to_target_sigset(VAR_2, &set);",
"unlock_user(VAR_2, arg1, sizeof(target_sigset_t));",
"#ifdef TARGET_NR_sigsuspend\ncase TARGET_NR_sigsuspend:\n{",
"TaskState *ts = cpu->opaque;",
"#if defined(TARGET_ALPHA)\nabi_ulong mask = arg1;",
"target_to_host_old_sigset(&ts->sigsuspend_mask, &mask);",
"#else\nif (!(VAR_2 = lock_user(VERIFY_READ, arg1, sizeof(target_sigset_t), 1)))\ngoto efault;",
"target_to_host_old_sigset(&ts->sigsuspend_mask, VAR_2);",
"unlock_user(VAR_2, arg1, 0);",
"#endif\nret = get_errno(safe_rt_sigsuspend(&ts->sigsuspend_mask,\nSIGSET_T_SIZE));",
"if (ret != -TARGET_ERESTARTSYS) {",
"ts->in_sigsuspend = 1;",
"#endif\ncase TARGET_NR_rt_sigsuspend:\n{",
"TaskState *ts = cpu->opaque;",
"if (arg2 != sizeof(target_sigset_t)) {",
"if (!(VAR_2 = lock_user(VERIFY_READ, arg1, sizeof(target_sigset_t), 1)))\ngoto efault;",
"target_to_host_sigset(&ts->sigsuspend_mask, VAR_2);",
"unlock_user(VAR_2, arg1, 0);",
"ret = get_errno(safe_rt_sigsuspend(&ts->sigsuspend_mask,\nSIGSET_T_SIZE));",
"if (ret != -TARGET_ERESTARTSYS) {",
"ts->in_sigsuspend = 1;",
"case TARGET_NR_rt_sigtimedwait:\n{",
"sigset_t set;",
"struct timespec uts, *puts;",
"siginfo_t uinfo;",
"if (arg4 != sizeof(target_sigset_t)) {",
"if (!(VAR_2 = lock_user(VERIFY_READ, arg1, sizeof(target_sigset_t), 1)))\ngoto efault;",
"target_to_host_sigset(&set, VAR_2);",
"unlock_user(VAR_2, arg1, 0);",
"if (arg3) {",
"puts = &uts;",
"target_to_host_timespec(puts, arg3);",
"} else {",
"puts = NULL;",
"ret = get_errno(safe_rt_sigtimedwait(&set, &uinfo, puts,\nSIGSET_T_SIZE));",
"if (!is_error(ret)) {",
"if (arg2) {",
"VAR_2 = lock_user(VERIFY_WRITE, arg2, sizeof(target_siginfo_t),\n0);",
"if (!VAR_2) {",
"goto efault;",
"host_to_target_siginfo(VAR_2, &uinfo);",
"unlock_user(VAR_2, arg2, sizeof(target_siginfo_t));",
"ret = host_to_target_signal(ret);",
"case TARGET_NR_rt_sigqueueinfo:\n{",
"siginfo_t uinfo;",
"VAR_2 = lock_user(VERIFY_READ, arg3, sizeof(target_siginfo_t), 1);",
"if (!VAR_2) {",
"goto efault;",
"target_to_host_siginfo(&uinfo, VAR_2);",
"unlock_user(VAR_2, arg1, 0);",
"ret = get_errno(sys_rt_sigqueueinfo(arg1, arg2, &uinfo));",
"#ifdef TARGET_NR_sigreturn\ncase TARGET_NR_sigreturn:\nif (block_signals()) {",
"ret = -TARGET_ERESTARTSYS;",
"} else {",
"ret = do_sigreturn(cpu_env);",
"#endif\ncase TARGET_NR_rt_sigreturn:\nif (block_signals()) {",
"ret = -TARGET_ERESTARTSYS;",
"} else {",
"ret = do_rt_sigreturn(cpu_env);",
"case TARGET_NR_sethostname:\nif (!(VAR_2 = lock_user_string(arg1)))\ngoto efault;",
"ret = get_errno(sethostname(VAR_2, arg2));",
"unlock_user(VAR_2, arg1, 0);",
"case TARGET_NR_setrlimit:\n{",
"int resource = target_to_host_resource(arg1);",
"struct target_rlimit *target_rlim;",
"struct rlimit rlim;",
"if (!lock_user_struct(VERIFY_READ, target_rlim, arg2, 1))\ngoto efault;",
"rlim.rlim_cur = target_to_host_rlim(target_rlim->rlim_cur);",
"rlim.rlim_max = target_to_host_rlim(target_rlim->rlim_max);",
"unlock_user_struct(target_rlim, arg2, 0);",
"ret = get_errno(setrlimit(resource, &rlim));",
"case TARGET_NR_getrlimit:\n{",
"int resource = target_to_host_resource(arg1);",
"struct target_rlimit *target_rlim;",
"struct rlimit rlim;",
"ret = get_errno(getrlimit(resource, &rlim));",
"if (!is_error(ret)) {",
"if (!lock_user_struct(VERIFY_WRITE, target_rlim, arg2, 0))\ngoto efault;",
"target_rlim->rlim_cur = host_to_target_rlim(rlim.rlim_cur);",
"target_rlim->rlim_max = host_to_target_rlim(rlim.rlim_max);",
"unlock_user_struct(target_rlim, arg2, 1);",
"case TARGET_NR_getrusage:\n{",
"struct rusage rusage;",
"ret = get_errno(getrusage(arg1, &rusage));",
"if (!is_error(ret)) {",
"ret = host_to_target_rusage(arg2, &rusage);",
"case TARGET_NR_gettimeofday:\n{",
"struct timeval tv;",
"ret = get_errno(gettimeofday(&tv, NULL));",
"if (!is_error(ret)) {",
"if (copy_to_user_timeval(arg1, &tv))\ngoto efault;",
"case TARGET_NR_settimeofday:\n{",
"struct timeval tv, *ptv = NULL;",
"struct timezone tz, *ptz = NULL;",
"if (arg1) {",
"if (copy_from_user_timeval(&tv, arg1)) {",
"goto efault;",
"ptv = &tv;",
"if (arg2) {",
"if (copy_from_user_timezone(&tz, arg2)) {",
"goto efault;",
"ptz = &tz;",
"ret = get_errno(settimeofday(ptv, ptz));",
"#if defined(TARGET_NR_select)\ncase TARGET_NR_select:\n#if defined(TARGET_S390X) || defined(TARGET_ALPHA)\nret = do_select(arg1, arg2, arg3, arg4, arg5);",
"#else\n{",
"struct target_sel_arg_struct *sel;",
"abi_ulong inp, outp, exp, tvp;",
"long nsel;",
"if (!lock_user_struct(VERIFY_READ, sel, arg1, 1))\ngoto efault;",
"nsel = tswapal(sel->n);",
"inp = tswapal(sel->inp);",
"outp = tswapal(sel->outp);",
"exp = tswapal(sel->exp);",
"tvp = tswapal(sel->tvp);",
"unlock_user_struct(sel, arg1, 0);",
"ret = do_select(nsel, inp, outp, exp, tvp);",
"#endif\n#endif\n#ifdef TARGET_NR_pselect6\ncase TARGET_NR_pselect6:\n{",
"abi_long rfd_addr, wfd_addr, efd_addr, n, ts_addr;",
"fd_set rfds, wfds, efds;",
"fd_set *rfds_ptr, *wfds_ptr, *efds_ptr;",
"struct timespec ts, *ts_ptr;",
"sigset_t set;",
"struct {",
"sigset_t *set;",
"size_t size;",
"} sig, *sig_ptr;",
"abi_ulong arg_sigset, arg_sigsize, *arg7;",
"target_sigset_t *target_sigset;",
"n = arg1;",
"rfd_addr = arg2;",
"wfd_addr = arg3;",
"efd_addr = arg4;",
"ts_addr = arg5;",
"ret = copy_from_user_fdset_ptr(&rfds, &rfds_ptr, rfd_addr, n);",
"if (ret) {",
"goto fail;",
"ret = copy_from_user_fdset_ptr(&wfds, &wfds_ptr, wfd_addr, n);",
"if (ret) {",
"goto fail;",
"ret = copy_from_user_fdset_ptr(&efds, &efds_ptr, efd_addr, n);",
"if (ret) {",
"goto fail;",
"if (ts_addr) {",
"if (target_to_host_timespec(&ts, ts_addr)) {",
"goto efault;",
"ts_ptr = &ts;",
"} else {",
"ts_ptr = NULL;",
"if (arg6) {",
"sig_ptr = &sig;",
"sig.size = SIGSET_T_SIZE;",
"arg7 = lock_user(VERIFY_READ, arg6, sizeof(*arg7) * 2, 1);",
"if (!arg7) {",
"goto efault;",
"arg_sigset = tswapal(arg7[0]);",
"arg_sigsize = tswapal(arg7[1]);",
"unlock_user(arg7, arg6, 0);",
"if (arg_sigset) {",
"sig.set = &set;",
"if (arg_sigsize != sizeof(*target_sigset)) {",
"goto fail;",
"target_sigset = lock_user(VERIFY_READ, arg_sigset,\nsizeof(*target_sigset), 1);",
"if (!target_sigset) {",
"goto efault;",
"target_to_host_sigset(&set, target_sigset);",
"unlock_user(target_sigset, arg_sigset, 0);",
"} else {",
"sig.set = NULL;",
"} else {",
"sig_ptr = NULL;",
"ret = get_errno(safe_pselect6(n, rfds_ptr, wfds_ptr, efds_ptr,\nts_ptr, sig_ptr));",
"if (!is_error(ret)) {",
"if (rfd_addr && copy_to_user_fdset(rfd_addr, &rfds, n))\ngoto efault;",
"if (wfd_addr && copy_to_user_fdset(wfd_addr, &wfds, n))\ngoto efault;",
"if (efd_addr && copy_to_user_fdset(efd_addr, &efds, n))\ngoto efault;",
"if (ts_addr && host_to_target_timespec(ts_addr, &ts))\ngoto efault;",
"#endif\n#ifdef TARGET_NR_symlink\ncase TARGET_NR_symlink:\n{",
"void *p2;",
"VAR_2 = lock_user_string(arg1);",
"p2 = lock_user_string(arg2);",
"if (!VAR_2 || !p2)\nret = -TARGET_EFAULT;",
"else\nret = get_errno(symlink(VAR_2, p2));",
"unlock_user(p2, arg2, 0);",
"unlock_user(VAR_2, arg1, 0);",
"#endif\n#if defined(TARGET_NR_symlinkat)\ncase TARGET_NR_symlinkat:\n{",
"void *p2;",
"VAR_2 = lock_user_string(arg1);",
"p2 = lock_user_string(arg3);",
"if (!VAR_2 || !p2)\nret = -TARGET_EFAULT;",
"else\nret = get_errno(symlinkat(VAR_2, arg2, p2));",
"unlock_user(p2, arg3, 0);",
"unlock_user(VAR_2, arg1, 0);",
"#endif\n#ifdef TARGET_NR_oldlstat\ncase TARGET_NR_oldlstat:\ngoto unimplemented;",
"#endif\n#ifdef TARGET_NR_readlink\ncase TARGET_NR_readlink:\n{",
"void *p2;",
"VAR_2 = lock_user_string(arg1);",
"p2 = lock_user(VERIFY_WRITE, arg2, arg3, 0);",
"if (!VAR_2 || !p2) {",
"ret = -TARGET_EFAULT;",
"} else if (!arg3) {",
"} else if (is_proc_myself((const char *)VAR_2, \"exe\")) {",
"char real[PATH_MAX], *temp;",
"temp = realpath(exec_path, real);",
"if (temp == NULL) {",
"ret = get_errno(-1);",
"} else {",
"ret = MIN(strlen(real), arg3);",
"memcpy(p2, real, ret);",
"} else {",
"ret = get_errno(readlink(path(VAR_2), p2, arg3));",
"unlock_user(p2, arg2, ret);",
"unlock_user(VAR_2, arg1, 0);",
"#endif\n#if defined(TARGET_NR_readlinkat)\ncase TARGET_NR_readlinkat:\n{",
"void *p2;",
"VAR_2 = lock_user_string(arg2);",
"p2 = lock_user(VERIFY_WRITE, arg3, arg4, 0);",
"if (!VAR_2 || !p2) {",
"ret = -TARGET_EFAULT;",
"} else if (is_proc_myself((const char *)VAR_2, \"exe\")) {",
"char real[PATH_MAX], *temp;",
"temp = realpath(exec_path, real);",
"ret = temp == NULL ? get_errno(-1) : strlen(real) ;",
"snprintf((char *)p2, arg4, \"%s\", real);",
"} else {",
"ret = get_errno(readlinkat(arg1, path(VAR_2), p2, arg4));",
"unlock_user(p2, arg3, ret);",
"unlock_user(VAR_2, arg2, 0);",
"#endif\n#ifdef TARGET_NR_uselib\ncase TARGET_NR_uselib:\ngoto unimplemented;",
"#endif\n#ifdef TARGET_NR_swapon\ncase TARGET_NR_swapon:\nif (!(VAR_2 = lock_user_string(arg1)))\ngoto efault;",
"ret = get_errno(swapon(VAR_2, arg2));",
"unlock_user(VAR_2, arg1, 0);",
"#endif\ncase TARGET_NR_reboot:\nif (arg3 == LINUX_REBOOT_CMD_RESTART2) {",
"VAR_2 = lock_user_string(arg4);",
"if (!VAR_2) {",
"goto efault;",
"ret = get_errno(reboot(arg1, arg2, arg3, VAR_2));",
"unlock_user(VAR_2, arg4, 0);",
"} else {",
"ret = get_errno(reboot(arg1, arg2, arg3, NULL));",
"#ifdef TARGET_NR_readdir\ncase TARGET_NR_readdir:\ngoto unimplemented;",
"#endif\n#ifdef TARGET_NR_mmap\ncase TARGET_NR_mmap:\n#if (defined(TARGET_I386) && defined(TARGET_ABI32)) || \\\n(defined(TARGET_ARM) && defined(TARGET_ABI32)) || \\\ndefined(TARGET_M68K) || defined(TARGET_CRIS) || defined(TARGET_MICROBLAZE) \\\n|| defined(TARGET_S390X)\n{",
"abi_ulong *v;",
"abi_ulong v1, v2, v3, v4, v5, v6;",
"if (!(v = lock_user(VERIFY_READ, arg1, 6 * sizeof(abi_ulong), 1)))\ngoto efault;",
"v1 = tswapal(v[0]);",
"v2 = tswapal(v[1]);",
"v3 = tswapal(v[2]);",
"v4 = tswapal(v[3]);",
"v5 = tswapal(v[4]);",
"v6 = tswapal(v[5]);",
"unlock_user(v, arg1, 0);",
"ret = get_errno(target_mmap(v1, v2, v3,\ntarget_to_host_bitmask(v4, mmap_flags_tbl),\nv5, v6));",
"#else\nret = get_errno(target_mmap(arg1, arg2, arg3,\ntarget_to_host_bitmask(arg4, mmap_flags_tbl),\narg5,\narg6));",
"#endif\n#endif\n#ifdef TARGET_NR_mmap2\ncase TARGET_NR_mmap2:\n#ifndef MMAP_SHIFT\n#define MMAP_SHIFT 12\n#endif\nret = get_errno(target_mmap(arg1, arg2, arg3,\ntarget_to_host_bitmask(arg4, mmap_flags_tbl),\narg5,\narg6 << MMAP_SHIFT));",
"#endif\ncase TARGET_NR_munmap:\nret = get_errno(target_munmap(arg1, arg2));",
"case TARGET_NR_mprotect:\n{",
"TaskState *ts = cpu->opaque;",
"if ((arg3 & PROT_GROWSDOWN)\n&& arg1 >= ts->info->stack_limit\n&& arg1 <= ts->info->start_stack) {",
"arg3 &= ~PROT_GROWSDOWN;",
"arg2 = arg2 + arg1 - ts->info->stack_limit;",
"arg1 = ts->info->stack_limit;",
"ret = get_errno(target_mprotect(arg1, arg2, arg3));",
"#ifdef TARGET_NR_mremap\ncase TARGET_NR_mremap:\nret = get_errno(target_mremap(arg1, arg2, arg3, arg4, arg5));",
"#endif\n#ifdef TARGET_NR_msync\ncase TARGET_NR_msync:\nret = get_errno(msync(g2h(arg1), arg2, arg3));",
"#endif\n#ifdef TARGET_NR_mlock\ncase TARGET_NR_mlock:\nret = get_errno(mlock(g2h(arg1), arg2));",
"#endif\n#ifdef TARGET_NR_munlock\ncase TARGET_NR_munlock:\nret = get_errno(munlock(g2h(arg1), arg2));",
"#endif\n#ifdef TARGET_NR_mlockall\ncase TARGET_NR_mlockall:\nret = get_errno(mlockall(target_to_host_mlockall_arg(arg1)));",
"#endif\n#ifdef TARGET_NR_munlockall\ncase TARGET_NR_munlockall:\nret = get_errno(munlockall());",
"#endif\ncase TARGET_NR_truncate:\nif (!(VAR_2 = lock_user_string(arg1)))\ngoto efault;",
"ret = get_errno(truncate(VAR_2, arg2));",
"unlock_user(VAR_2, arg1, 0);",
"case TARGET_NR_ftruncate:\nret = get_errno(ftruncate(arg1, arg2));",
"case TARGET_NR_fchmod:\nret = get_errno(fchmod(arg1, arg2));",
"#if defined(TARGET_NR_fchmodat)\ncase TARGET_NR_fchmodat:\nif (!(VAR_2 = lock_user_string(arg2)))\ngoto efault;",
"ret = get_errno(fchmodat(arg1, VAR_2, arg3, 0));",
"unlock_user(VAR_2, arg2, 0);",
"#endif\ncase TARGET_NR_getpriority:\nerrno = 0;",
"ret = getpriority(arg1, arg2);",
"if (ret == -1 && errno != 0) {",
"ret = -host_to_target_errno(errno);",
"#ifdef TARGET_ALPHA\n((CPUAlphaState *)cpu_env)->ir[IR_V0] = 0;",
"#else\nret = 20 - ret;",
"#endif\ncase TARGET_NR_setpriority:\nret = get_errno(setpriority(arg1, arg2, arg3));",
"#ifdef TARGET_NR_profil\ncase TARGET_NR_profil:\ngoto unimplemented;",
"#endif\ncase TARGET_NR_statfs:\nif (!(VAR_2 = lock_user_string(arg1)))\ngoto efault;",
"ret = get_errno(statfs(path(VAR_2), &VAR_1));",
"unlock_user(VAR_2, arg1, 0);",
"convert_statfs:\nif (!is_error(ret)) {",
"struct target_statfs *target_stfs;",
"if (!lock_user_struct(VERIFY_WRITE, target_stfs, arg2, 0))\ngoto efault;",
"__put_user(VAR_1.f_type, &target_stfs->f_type);",
"__put_user(VAR_1.f_bsize, &target_stfs->f_bsize);",
"__put_user(VAR_1.f_blocks, &target_stfs->f_blocks);",
"__put_user(VAR_1.f_bfree, &target_stfs->f_bfree);",
"__put_user(VAR_1.f_bavail, &target_stfs->f_bavail);",
"__put_user(VAR_1.f_files, &target_stfs->f_files);",
"__put_user(VAR_1.f_ffree, &target_stfs->f_ffree);",
"__put_user(VAR_1.f_fsid.__val[0], &target_stfs->f_fsid.val[0]);",
"__put_user(VAR_1.f_fsid.__val[1], &target_stfs->f_fsid.val[1]);",
"__put_user(VAR_1.f_namelen, &target_stfs->f_namelen);",
"__put_user(VAR_1.f_frsize, &target_stfs->f_frsize);",
"memset(target_stfs->f_spare, 0, sizeof(target_stfs->f_spare));",
"unlock_user_struct(target_stfs, arg2, 1);",
"case TARGET_NR_fstatfs:\nret = get_errno(fstatfs(arg1, &VAR_1));",
"goto convert_statfs;",
"#ifdef TARGET_NR_statfs64\ncase TARGET_NR_statfs64:\nif (!(VAR_2 = lock_user_string(arg1)))\ngoto efault;",
"ret = get_errno(statfs(path(VAR_2), &VAR_1));",
"unlock_user(VAR_2, arg1, 0);",
"convert_statfs64:\nif (!is_error(ret)) {",
"struct target_statfs64 *target_stfs;",
"if (!lock_user_struct(VERIFY_WRITE, target_stfs, arg3, 0))\ngoto efault;",
"__put_user(VAR_1.f_type, &target_stfs->f_type);",
"__put_user(VAR_1.f_bsize, &target_stfs->f_bsize);",
"__put_user(VAR_1.f_blocks, &target_stfs->f_blocks);",
"__put_user(VAR_1.f_bfree, &target_stfs->f_bfree);",
"__put_user(VAR_1.f_bavail, &target_stfs->f_bavail);",
"__put_user(VAR_1.f_files, &target_stfs->f_files);",
"__put_user(VAR_1.f_ffree, &target_stfs->f_ffree);",
"__put_user(VAR_1.f_fsid.__val[0], &target_stfs->f_fsid.val[0]);",
"__put_user(VAR_1.f_fsid.__val[1], &target_stfs->f_fsid.val[1]);",
"__put_user(VAR_1.f_namelen, &target_stfs->f_namelen);",
"__put_user(VAR_1.f_frsize, &target_stfs->f_frsize);",
"memset(target_stfs->f_spare, 0, sizeof(target_stfs->f_spare));",
"unlock_user_struct(target_stfs, arg3, 1);",
"case TARGET_NR_fstatfs64:\nret = get_errno(fstatfs(arg1, &VAR_1));",
"goto convert_statfs64;",
"#endif\n#ifdef TARGET_NR_ioperm\ncase TARGET_NR_ioperm:\ngoto unimplemented;",
"#endif\n#ifdef TARGET_NR_socketcall\ncase TARGET_NR_socketcall:\nret = do_socketcall(arg1, arg2);",
"#endif\n#ifdef TARGET_NR_accept\ncase TARGET_NR_accept:\nret = do_accept4(arg1, arg2, arg3, 0);",
"#endif\n#ifdef TARGET_NR_accept4\ncase TARGET_NR_accept4:\nret = do_accept4(arg1, arg2, arg3, arg4);",
"#endif\n#ifdef TARGET_NR_bind\ncase TARGET_NR_bind:\nret = do_bind(arg1, arg2, arg3);",
"#endif\n#ifdef TARGET_NR_connect\ncase TARGET_NR_connect:\nret = do_connect(arg1, arg2, arg3);",
"#endif\n#ifdef TARGET_NR_getpeername\ncase TARGET_NR_getpeername:\nret = do_getpeername(arg1, arg2, arg3);",
"#endif\n#ifdef TARGET_NR_getsockname\ncase TARGET_NR_getsockname:\nret = do_getsockname(arg1, arg2, arg3);",
"#endif\n#ifdef TARGET_NR_getsockopt\ncase TARGET_NR_getsockopt:\nret = do_getsockopt(arg1, arg2, arg3, arg4, arg5);",
"#endif\n#ifdef TARGET_NR_listen\ncase TARGET_NR_listen:\nret = get_errno(listen(arg1, arg2));",
"#endif\n#ifdef TARGET_NR_recv\ncase TARGET_NR_recv:\nret = do_recvfrom(arg1, arg2, arg3, arg4, 0, 0);",
"#endif\n#ifdef TARGET_NR_recvfrom\ncase TARGET_NR_recvfrom:\nret = do_recvfrom(arg1, arg2, arg3, arg4, arg5, arg6);",
"#endif\n#ifdef TARGET_NR_recvmsg\ncase TARGET_NR_recvmsg:\nret = do_sendrecvmsg(arg1, arg2, arg3, 0);",
"#endif\n#ifdef TARGET_NR_send\ncase TARGET_NR_send:\nret = do_sendto(arg1, arg2, arg3, arg4, 0, 0);",
"#endif\n#ifdef TARGET_NR_sendmsg\ncase TARGET_NR_sendmsg:\nret = do_sendrecvmsg(arg1, arg2, arg3, 1);",
"#endif\n#ifdef TARGET_NR_sendmmsg\ncase TARGET_NR_sendmmsg:\nret = do_sendrecvmmsg(arg1, arg2, arg3, arg4, 1);",
"case TARGET_NR_recvmmsg:\nret = do_sendrecvmmsg(arg1, arg2, arg3, arg4, 0);",
"#endif\n#ifdef TARGET_NR_sendto\ncase TARGET_NR_sendto:\nret = do_sendto(arg1, arg2, arg3, arg4, arg5, arg6);",
"#endif\n#ifdef TARGET_NR_shutdown\ncase TARGET_NR_shutdown:\nret = get_errno(shutdown(arg1, arg2));",
"#endif\n#if defined(TARGET_NR_getrandom) && defined(__NR_getrandom)\ncase TARGET_NR_getrandom:\nVAR_2 = lock_user(VERIFY_WRITE, arg1, arg2, 0);",
"if (!VAR_2) {",
"goto efault;",
"ret = get_errno(getrandom(VAR_2, arg2, arg3));",
"unlock_user(VAR_2, arg1, ret);",
"#endif\n#ifdef TARGET_NR_socket\ncase TARGET_NR_socket:\nret = do_socket(arg1, arg2, arg3);",
"fd_trans_unregister(ret);",
"#endif\n#ifdef TARGET_NR_socketpair\ncase TARGET_NR_socketpair:\nret = do_socketpair(arg1, arg2, arg3, arg4);",
"#endif\n#ifdef TARGET_NR_setsockopt\ncase TARGET_NR_setsockopt:\nret = do_setsockopt(arg1, arg2, arg3, arg4, (socklen_t) arg5);",
"#endif\ncase TARGET_NR_syslog:\nif (!(VAR_2 = lock_user_string(arg2)))\ngoto efault;",
"ret = get_errno(sys_syslog((int)arg1, VAR_2, (int)arg3));",
"unlock_user(VAR_2, arg2, 0);",
"case TARGET_NR_setitimer:\n{",
"struct itimerval value, ovalue, *pvalue;",
"if (arg2) {",
"pvalue = &value;",
"if (copy_from_user_timeval(&pvalue->it_interval, arg2)\n|| copy_from_user_timeval(&pvalue->it_value,\narg2 + sizeof(struct target_timeval)))\ngoto efault;",
"} else {",
"pvalue = NULL;",
"ret = get_errno(setitimer(arg1, pvalue, &ovalue));",
"if (!is_error(ret) && arg3) {",
"if (copy_to_user_timeval(arg3,\n&ovalue.it_interval)\n|| copy_to_user_timeval(arg3 + sizeof(struct target_timeval),\n&ovalue.it_value))\ngoto efault;",
"case TARGET_NR_getitimer:\n{",
"struct itimerval value;",
"ret = get_errno(getitimer(arg1, &value));",
"if (!is_error(ret) && arg2) {",
"if (copy_to_user_timeval(arg2,\n&value.it_interval)\n|| copy_to_user_timeval(arg2 + sizeof(struct target_timeval),\n&value.it_value))\ngoto efault;",
"#ifdef TARGET_NR_stat\ncase TARGET_NR_stat:\nif (!(VAR_2 = lock_user_string(arg1)))\ngoto efault;",
"ret = get_errno(stat(path(VAR_2), &VAR_0));",
"unlock_user(VAR_2, arg1, 0);",
"goto do_stat;",
"#endif\n#ifdef TARGET_NR_lstat\ncase TARGET_NR_lstat:\nif (!(VAR_2 = lock_user_string(arg1)))\ngoto efault;",
"ret = get_errno(lstat(path(VAR_2), &VAR_0));",
"unlock_user(VAR_2, arg1, 0);",
"goto do_stat;",
"#endif\ncase TARGET_NR_fstat:\n{",
"ret = get_errno(fstat(arg1, &VAR_0));",
"#if defined(TARGET_NR_stat) || defined(TARGET_NR_lstat)\ndo_stat:\n#endif\nif (!is_error(ret)) {",
"struct target_stat *target_st;",
"if (!lock_user_struct(VERIFY_WRITE, target_st, arg2, 0))\ngoto efault;",
"memset(target_st, 0, sizeof(*target_st));",
"__put_user(VAR_0.st_dev, &target_st->st_dev);",
"__put_user(VAR_0.st_ino, &target_st->st_ino);",
"__put_user(VAR_0.st_mode, &target_st->st_mode);",
"__put_user(VAR_0.st_uid, &target_st->st_uid);",
"__put_user(VAR_0.st_gid, &target_st->st_gid);",
"__put_user(VAR_0.st_nlink, &target_st->st_nlink);",
"__put_user(VAR_0.st_rdev, &target_st->st_rdev);",
"__put_user(VAR_0.st_size, &target_st->st_size);",
"__put_user(VAR_0.st_blksize, &target_st->st_blksize);",
"__put_user(VAR_0.st_blocks, &target_st->st_blocks);",
"__put_user(VAR_0.st_atime, &target_st->target_st_atime);",
"__put_user(VAR_0.st_mtime, &target_st->target_st_mtime);",
"__put_user(VAR_0.st_ctime, &target_st->target_st_ctime);",
"unlock_user_struct(target_st, arg2, 1);",
"#ifdef TARGET_NR_olduname\ncase TARGET_NR_olduname:\ngoto unimplemented;",
"#endif\n#ifdef TARGET_NR_iopl\ncase TARGET_NR_iopl:\ngoto unimplemented;",
"#endif\ncase TARGET_NR_vhangup:\nret = get_errno(vhangup());",
"#ifdef TARGET_NR_idle\ncase TARGET_NR_idle:\ngoto unimplemented;",
"#endif\n#ifdef TARGET_NR_syscall\ncase TARGET_NR_syscall:\nret = FUNC_0(cpu_env, arg1 & 0xffff, arg2, arg3, arg4, arg5,\narg6, arg7, arg8, 0);",
"#endif\ncase TARGET_NR_wait4:\n{",
"int status;",
"abi_long status_ptr = arg2;",
"struct rusage rusage, *rusage_ptr;",
"abi_ulong target_rusage = arg4;",
"abi_long rusage_err;",
"if (target_rusage)\nrusage_ptr = &rusage;",
"else\nrusage_ptr = NULL;",
"ret = get_errno(safe_wait4(arg1, &status, arg3, rusage_ptr));",
"if (!is_error(ret)) {",
"if (status_ptr && ret) {",
"status = host_to_target_waitstatus(status);",
"if (put_user_s32(status, status_ptr))\ngoto efault;",
"if (target_rusage) {",
"rusage_err = host_to_target_rusage(target_rusage, &rusage);",
"if (rusage_err) {",
"ret = rusage_err;",
"#ifdef TARGET_NR_swapoff\ncase TARGET_NR_swapoff:\nif (!(VAR_2 = lock_user_string(arg1)))\ngoto efault;",
"ret = get_errno(swapoff(VAR_2));",
"unlock_user(VAR_2, arg1, 0);",
"#endif\ncase TARGET_NR_sysinfo:\n{",
"struct target_sysinfo *target_value;",
"struct sysinfo value;",
"ret = get_errno(sysinfo(&value));",
"if (!is_error(ret) && arg1)\n{",
"if (!lock_user_struct(VERIFY_WRITE, target_value, arg1, 0))\ngoto efault;",
"__put_user(value.uptime, &target_value->uptime);",
"__put_user(value.loads[0], &target_value->loads[0]);",
"__put_user(value.loads[1], &target_value->loads[1]);",
"__put_user(value.loads[2], &target_value->loads[2]);",
"__put_user(value.totalram, &target_value->totalram);",
"__put_user(value.freeram, &target_value->freeram);",
"__put_user(value.sharedram, &target_value->sharedram);",
"__put_user(value.bufferram, &target_value->bufferram);",
"__put_user(value.totalswap, &target_value->totalswap);",
"__put_user(value.freeswap, &target_value->freeswap);",
"__put_user(value.procs, &target_value->procs);",
"__put_user(value.totalhigh, &target_value->totalhigh);",
"__put_user(value.freehigh, &target_value->freehigh);",
"__put_user(value.mem_unit, &target_value->mem_unit);",
"unlock_user_struct(target_value, arg1, 1);",
"#ifdef TARGET_NR_ipc\ncase TARGET_NR_ipc:\nret = do_ipc(arg1, arg2, arg3, arg4, arg5, arg6);",
"#endif\n#ifdef TARGET_NR_semget\ncase TARGET_NR_semget:\nret = get_errno(semget(arg1, arg2, arg3));",
"#endif\n#ifdef TARGET_NR_semop\ncase TARGET_NR_semop:\nret = do_semop(arg1, arg2, arg3);",
"#endif\n#ifdef TARGET_NR_semctl\ncase TARGET_NR_semctl:\nret = do_semctl(arg1, arg2, arg3, arg4);",
"#endif\n#ifdef TARGET_NR_msgctl\ncase TARGET_NR_msgctl:\nret = do_msgctl(arg1, arg2, arg3);",
"#endif\n#ifdef TARGET_NR_msgget\ncase TARGET_NR_msgget:\nret = get_errno(msgget(arg1, arg2));",
"#endif\n#ifdef TARGET_NR_msgrcv\ncase TARGET_NR_msgrcv:\nret = do_msgrcv(arg1, arg2, arg3, arg4, arg5);",
"#endif\n#ifdef TARGET_NR_msgsnd\ncase TARGET_NR_msgsnd:\nret = do_msgsnd(arg1, arg2, arg3, arg4);",
"#endif\n#ifdef TARGET_NR_shmget\ncase TARGET_NR_shmget:\nret = get_errno(shmget(arg1, arg2, arg3));",
"#endif\n#ifdef TARGET_NR_shmctl\ncase TARGET_NR_shmctl:\nret = do_shmctl(arg1, arg2, arg3);",
"#endif\n#ifdef TARGET_NR_shmat\ncase TARGET_NR_shmat:\nret = do_shmat(arg1, arg2, arg3);",
"#endif\n#ifdef TARGET_NR_shmdt\ncase TARGET_NR_shmdt:\nret = do_shmdt(arg1);",
"#endif\ncase TARGET_NR_fsync:\nret = get_errno(fsync(arg1));",
"case TARGET_NR_clone:\n#if defined(TARGET_MICROBLAZE)\nret = get_errno(do_fork(cpu_env, arg1, arg2, arg4, arg6, arg5));",
"#elif defined(TARGET_CLONE_BACKWARDS)\nret = get_errno(do_fork(cpu_env, arg1, arg2, arg3, arg4, arg5));",
"#elif defined(TARGET_CLONE_BACKWARDS2)\nret = get_errno(do_fork(cpu_env, arg2, arg1, arg3, arg5, arg4));",
"#else\nret = get_errno(do_fork(cpu_env, arg1, arg2, arg3, arg5, arg4));",
"#endif\n#ifdef __NR_exit_group\ncase TARGET_NR_exit_group:\n#ifdef TARGET_GPROF\n_mcleanup();",
"#endif\ngdb_exit(cpu_env, arg1);",
"ret = get_errno(exit_group(arg1));",
"#endif\ncase TARGET_NR_setdomainname:\nif (!(VAR_2 = lock_user_string(arg1)))\ngoto efault;",
"ret = get_errno(setdomainname(VAR_2, arg2));",
"unlock_user(VAR_2, arg1, 0);",
"case TARGET_NR_uname:\n{",
"struct new_utsname * buf;",
"if (!lock_user_struct(VERIFY_WRITE, buf, arg1, 0))\ngoto efault;",
"ret = get_errno(sys_uname(buf));",
"if (!is_error(ret)) {",
"strcpy (buf->machine, cpu_to_uname_machine(cpu_env));",
"if (qemu_uname_release && *qemu_uname_release) {",
"g_strlcpy(buf->release, qemu_uname_release,\nsizeof(buf->release));",
"unlock_user_struct(buf, arg1, 1);",
"#ifdef TARGET_I386\ncase TARGET_NR_modify_ldt:\nret = do_modify_ldt(cpu_env, arg1, arg2, arg3);",
"#if !defined(TARGET_X86_64)\ncase TARGET_NR_vm86old:\ngoto unimplemented;",
"case TARGET_NR_vm86:\nret = do_vm86(cpu_env, arg1, arg2);",
"#endif\n#endif\ncase TARGET_NR_adjtimex:\ngoto unimplemented;",
"#ifdef TARGET_NR_create_module\ncase TARGET_NR_create_module:\n#endif\ncase TARGET_NR_init_module:\ncase TARGET_NR_delete_module:\n#ifdef TARGET_NR_get_kernel_syms\ncase TARGET_NR_get_kernel_syms:\n#endif\ngoto unimplemented;",
"case TARGET_NR_quotactl:\ngoto unimplemented;",
"case TARGET_NR_getpgid:\nret = get_errno(getpgid(arg1));",
"case TARGET_NR_fchdir:\nret = get_errno(fchdir(arg1));",
"#ifdef TARGET_NR_bdflush\ncase TARGET_NR_bdflush:\ngoto unimplemented;",
"#endif\n#ifdef TARGET_NR_sysfs\ncase TARGET_NR_sysfs:\ngoto unimplemented;",
"#endif\ncase TARGET_NR_personality:\nret = get_errno(personality(arg1));",
"#ifdef TARGET_NR_afs_syscall\ncase TARGET_NR_afs_syscall:\ngoto unimplemented;",
"#endif\n#ifdef TARGET_NR__llseek\ncase TARGET_NR__llseek:\n{",
"int64_t res;",
"#if !defined(__NR_llseek)\nres = lseek(arg1, ((uint64_t)arg2 << 32) | (abi_ulong)arg3, arg5);",
"if (res == -1) {",
"ret = get_errno(res);",
"} else {",
"ret = 0;",
"#else\nret = get_errno(_llseek(arg1, arg2, arg3, &res, arg5));",
"#endif\nif ((ret == 0) && put_user_s64(res, arg4)) {",
"goto efault;",
"#endif\n#ifdef TARGET_NR_getdents\ncase TARGET_NR_getdents:\n#ifdef __NR_getdents\n#if TARGET_ABI_BITS == 32 && HOST_LONG_BITS == 64\n{",
"struct target_dirent *target_dirp;",
"struct linux_dirent *dirp;",
"abi_long count = arg3;",
"dirp = g_try_malloc(count);",
"if (!dirp) {",
"ret = -TARGET_ENOMEM;",
"goto fail;",
"ret = get_errno(sys_getdents(arg1, dirp, count));",
"if (!is_error(ret)) {",
"struct linux_dirent *de;",
"struct target_dirent *tde;",
"int len = ret;",
"int reclen, treclen;",
"int count1, tnamelen;",
"count1 = 0;",
"de = dirp;",
"if (!(target_dirp = lock_user(VERIFY_WRITE, arg2, count, 0)))\ngoto efault;",
"tde = target_dirp;",
"while (len > 0) {",
"reclen = de->d_reclen;",
"tnamelen = reclen - offsetof(struct linux_dirent, d_name);",
"assert(tnamelen >= 0);",
"treclen = tnamelen + offsetof(struct target_dirent, d_name);",
"assert(count1 + treclen <= count);",
"tde->d_reclen = tswap16(treclen);",
"tde->d_ino = tswapal(de->d_ino);",
"tde->d_off = tswapal(de->d_off);",
"memcpy(tde->d_name, de->d_name, tnamelen);",
"de = (struct linux_dirent *)((char *)de + reclen);",
"len -= reclen;",
"tde = (struct target_dirent *)((char *)tde + treclen);",
"count1 += treclen;",
"ret = count1;",
"unlock_user(target_dirp, arg2, ret);",
"g_free(dirp);",
"#else\n{",
"struct linux_dirent *dirp;",
"abi_long count = arg3;",
"if (!(dirp = lock_user(VERIFY_WRITE, arg2, count, 0)))\ngoto efault;",
"ret = get_errno(sys_getdents(arg1, dirp, count));",
"if (!is_error(ret)) {",
"struct linux_dirent *de;",
"int len = ret;",
"int reclen;",
"de = dirp;",
"while (len > 0) {",
"reclen = de->d_reclen;",
"if (reclen > len)\nde->d_reclen = tswap16(reclen);",
"tswapls(&de->d_ino);",
"tswapls(&de->d_off);",
"de = (struct linux_dirent *)((char *)de + reclen);",
"len -= reclen;",
"unlock_user(dirp, arg2, ret);",
"#endif\n#else\n{",
"struct linux_dirent64 *dirp;",
"abi_long count = arg3;",
"dirp = lock_user(VERIFY_WRITE, arg2, count, 0);",
"if (!dirp) {",
"goto efault;",
"ret = get_errno(sys_getdents64(arg1, dirp, count));",
"if (!is_error(ret)) {",
"struct linux_dirent64 *de;",
"struct target_dirent *tde;",
"int len = ret;",
"int tlen = 0;",
"de = dirp;",
"tde = (struct target_dirent *)dirp;",
"while (len > 0) {",
"int namelen, treclen;",
"int reclen = de->d_reclen;",
"uint64_t ino = de->d_ino;",
"int64_t off = de->d_off;",
"uint8_t type = de->d_type;",
"namelen = strlen(de->d_name);",
"treclen = offsetof(struct target_dirent, d_name)\n+ namelen + 2;",
"treclen = QEMU_ALIGN_UP(treclen, sizeof(abi_long));",
"memmove(tde->d_name, de->d_name, namelen + 1);",
"tde->d_ino = tswapal(ino);",
"tde->d_off = tswapal(off);",
"tde->d_reclen = tswap16(treclen);",
"*(((char *)tde) + treclen - 1) = type;",
"de = (struct linux_dirent64 *)((char *)de + reclen);",
"tde = (struct target_dirent *)((char *)tde + treclen);",
"len -= reclen;",
"tlen += treclen;",
"ret = tlen;",
"unlock_user(dirp, arg2, ret);",
"#endif\n#endif\n#if defined(TARGET_NR_getdents64) && defined(__NR_getdents64)\ncase TARGET_NR_getdents64:\n{",
"struct linux_dirent64 *dirp;",
"abi_long count = arg3;",
"if (!(dirp = lock_user(VERIFY_WRITE, arg2, count, 0)))\ngoto efault;",
"ret = get_errno(sys_getdents64(arg1, dirp, count));",
"if (!is_error(ret)) {",
"struct linux_dirent64 *de;",
"int len = ret;",
"int reclen;",
"de = dirp;",
"while (len > 0) {",
"reclen = de->d_reclen;",
"if (reclen > len)\nde->d_reclen = tswap16(reclen);",
"tswap64s((uint64_t *)&de->d_ino);",
"tswap64s((uint64_t *)&de->d_off);",
"de = (struct linux_dirent64 *)((char *)de + reclen);",
"len -= reclen;",
"unlock_user(dirp, arg2, ret);",
"#endif\n#if defined(TARGET_NR__newselect)\ncase TARGET_NR__newselect:\nret = do_select(arg1, arg2, arg3, arg4, arg5);",
"#endif\n#if defined(TARGET_NR_poll) || defined(TARGET_NR_ppoll)\n# ifdef TARGET_NR_poll\ncase TARGET_NR_poll:\n# endif\n# ifdef TARGET_NR_ppoll\ncase TARGET_NR_ppoll:\n# endif\n{",
"struct target_pollfd *target_pfd;",
"unsigned int nfds = arg2;",
"struct pollfd *pfd;",
"unsigned int i;",
"pfd = NULL;",
"target_pfd = NULL;",
"if (nfds) {",
"target_pfd = lock_user(VERIFY_WRITE, arg1,\nsizeof(struct target_pollfd) * nfds, 1);",
"if (!target_pfd) {",
"goto efault;",
"pfd = alloca(sizeof(struct pollfd) * nfds);",
"for (i = 0; i < nfds; i++) {",
"pfd[i].fd = tswap32(target_pfd[i].fd);",
"pfd[i].events = tswap16(target_pfd[i].events);",
"switch (num) {",
"# ifdef TARGET_NR_ppoll\ncase TARGET_NR_ppoll:\n{",
"struct timespec _timeout_ts, *timeout_ts = &_timeout_ts;",
"target_sigset_t *target_set;",
"sigset_t _set, *set = &_set;",
"if (arg3) {",
"if (target_to_host_timespec(timeout_ts, arg3)) {",
"unlock_user(target_pfd, arg1, 0);",
"goto efault;",
"} else {",
"timeout_ts = NULL;",
"if (arg4) {",
"if (arg5 != sizeof(target_sigset_t)) {",
"unlock_user(target_pfd, arg1, 0);",
"target_set = lock_user(VERIFY_READ, arg4, sizeof(target_sigset_t), 1);",
"if (!target_set) {",
"unlock_user(target_pfd, arg1, 0);",
"goto efault;",
"target_to_host_sigset(set, target_set);",
"} else {",
"set = NULL;",
"ret = get_errno(safe_ppoll(pfd, nfds, timeout_ts,\nset, SIGSET_T_SIZE));",
"if (!is_error(ret) && arg3) {",
"host_to_target_timespec(arg3, timeout_ts);",
"if (arg4) {",
"unlock_user(target_set, arg4, 0);",
"# endif\n# ifdef TARGET_NR_poll\ncase TARGET_NR_poll:\n{",
"struct timespec ts, *pts;",
"if (arg3 >= 0) {",
"ts.tv_sec = arg3 / 1000;",
"ts.tv_nsec = (arg3 % 1000) * 1000000LL;",
"pts = &ts;",
"} else {",
"pts = NULL;",
"ret = get_errno(safe_ppoll(pfd, nfds, pts, NULL, 0));",
"# endif\ndefault:\ng_assert_not_reached();",
"if (!is_error(ret)) {",
"for(i = 0; i < nfds; i++) {",
"target_pfd[i].revents = tswap16(pfd[i].revents);",
"unlock_user(target_pfd, arg1, sizeof(struct target_pollfd) * nfds);",
"#endif\ncase TARGET_NR_flock:\nret = get_errno(safe_flock(arg1, arg2));",
"case TARGET_NR_readv:\n{",
"struct iovec *vec = lock_iovec(VERIFY_WRITE, arg2, arg3, 0);",
"if (vec != NULL) {",
"ret = get_errno(safe_readv(arg1, vec, arg3));",
"unlock_iovec(vec, arg2, arg3, 1);",
"} else {",
"ret = -host_to_target_errno(errno);",
"case TARGET_NR_writev:\n{",
"struct iovec *vec = lock_iovec(VERIFY_READ, arg2, arg3, 1);",
"if (vec != NULL) {",
"ret = get_errno(safe_writev(arg1, vec, arg3));",
"unlock_iovec(vec, arg2, arg3, 0);",
"} else {",
"ret = -host_to_target_errno(errno);",
"case TARGET_NR_getsid:\nret = get_errno(getsid(arg1));",
"#if defined(TARGET_NR_fdatasync)\ncase TARGET_NR_fdatasync:\nret = get_errno(fdatasync(arg1));",
"#endif\n#ifdef TARGET_NR__sysctl\ncase TARGET_NR__sysctl:\nret = -TARGET_ENOTDIR;",
"#endif\ncase TARGET_NR_sched_getaffinity:\n{",
"unsigned int mask_size;",
"unsigned long *mask;",
"if (arg2 & (sizeof(abi_ulong) - 1)) {",
"mask_size = (arg2 + (sizeof(*mask) - 1)) & ~(sizeof(*mask) - 1);",
"mask = alloca(mask_size);",
"ret = get_errno(sys_sched_getaffinity(arg1, mask_size, mask));",
"if (!is_error(ret)) {",
"if (ret > arg2) {",
"int numcpus = sysconf(_SC_NPROCESSORS_CONF);",
"if (numcpus > arg2 * 8) {",
"ret = arg2;",
"if (copy_to_user(arg3, mask, ret)) {",
"goto efault;",
"case TARGET_NR_sched_setaffinity:\n{",
"unsigned int mask_size;",
"unsigned long *mask;",
"if (arg2 & (sizeof(abi_ulong) - 1)) {",
"mask_size = (arg2 + (sizeof(*mask) - 1)) & ~(sizeof(*mask) - 1);",
"mask = alloca(mask_size);",
"if (!lock_user_struct(VERIFY_READ, VAR_2, arg3, 1)) {",
"goto efault;",
"memcpy(mask, VAR_2, arg2);",
"unlock_user_struct(VAR_2, arg2, 0);",
"ret = get_errno(sys_sched_setaffinity(arg1, mask_size, mask));",
"case TARGET_NR_sched_setparam:\n{",
"struct sched_param *target_schp;",
"struct sched_param schp;",
"if (arg2 == 0) {",
"return -TARGET_EINVAL;",
"if (!lock_user_struct(VERIFY_READ, target_schp, arg2, 1))\ngoto efault;",
"schp.sched_priority = tswap32(target_schp->sched_priority);",
"unlock_user_struct(target_schp, arg2, 0);",
"ret = get_errno(sched_setparam(arg1, &schp));",
"case TARGET_NR_sched_getparam:\n{",
"struct sched_param *target_schp;",
"struct sched_param schp;",
"if (arg2 == 0) {",
"return -TARGET_EINVAL;",
"ret = get_errno(sched_getparam(arg1, &schp));",
"if (!is_error(ret)) {",
"if (!lock_user_struct(VERIFY_WRITE, target_schp, arg2, 0))\ngoto efault;",
"target_schp->sched_priority = tswap32(schp.sched_priority);",
"unlock_user_struct(target_schp, arg2, 1);",
"case TARGET_NR_sched_setscheduler:\n{",
"struct sched_param *target_schp;",
"struct sched_param schp;",
"if (arg3 == 0) {",
"return -TARGET_EINVAL;",
"if (!lock_user_struct(VERIFY_READ, target_schp, arg3, 1))\ngoto efault;",
"schp.sched_priority = tswap32(target_schp->sched_priority);",
"unlock_user_struct(target_schp, arg3, 0);",
"ret = get_errno(sched_setscheduler(arg1, arg2, &schp));",
"case TARGET_NR_sched_getscheduler:\nret = get_errno(sched_getscheduler(arg1));",
"case TARGET_NR_sched_yield:\nret = get_errno(sched_yield());",
"case TARGET_NR_sched_get_priority_max:\nret = get_errno(sched_get_priority_max(arg1));",
"case TARGET_NR_sched_get_priority_min:\nret = get_errno(sched_get_priority_min(arg1));",
"case TARGET_NR_sched_rr_get_interval:\n{",
"struct timespec ts;",
"ret = get_errno(sched_rr_get_interval(arg1, &ts));",
"if (!is_error(ret)) {",
"ret = host_to_target_timespec(arg2, &ts);",
"case TARGET_NR_nanosleep:\n{",
"struct timespec req, rem;",
"target_to_host_timespec(&req, arg1);",
"ret = get_errno(safe_nanosleep(&req, &rem));",
"if (is_error(ret) && arg2) {",
"host_to_target_timespec(arg2, &rem);",
"#ifdef TARGET_NR_query_module\ncase TARGET_NR_query_module:\ngoto unimplemented;",
"#endif\n#ifdef TARGET_NR_nfsservctl\ncase TARGET_NR_nfsservctl:\ngoto unimplemented;",
"#endif\ncase TARGET_NR_prctl:\nswitch (arg1) {",
"case PR_GET_PDEATHSIG:\n{",
"int deathsig;",
"ret = get_errno(prctl(arg1, &deathsig, arg3, arg4, arg5));",
"if (!is_error(ret) && arg2\n&& put_user_ual(deathsig, arg2)) {",
"goto efault;",
"#ifdef PR_GET_NAME\ncase PR_GET_NAME:\n{",
"void *name = lock_user(VERIFY_WRITE, arg2, 16, 1);",
"if (!name) {",
"goto efault;",
"ret = get_errno(prctl(arg1, (unsigned long)name,\narg3, arg4, arg5));",
"unlock_user(name, arg2, 16);",
"case PR_SET_NAME:\n{",
"void *name = lock_user(VERIFY_READ, arg2, 16, 1);",
"if (!name) {",
"goto efault;",
"ret = get_errno(prctl(arg1, (unsigned long)name,\narg3, arg4, arg5));",
"unlock_user(name, arg2, 0);",
"#endif\ndefault:\nret = get_errno(prctl(arg1, arg2, arg3, arg4, arg5));",
"#ifdef TARGET_NR_arch_prctl\ncase TARGET_NR_arch_prctl:\n#if defined(TARGET_I386) && !defined(TARGET_ABI32)\nret = do_arch_prctl(cpu_env, arg1, arg2);",
"#else\ngoto unimplemented;",
"#endif\n#endif\n#ifdef TARGET_NR_pread64\ncase TARGET_NR_pread64:\nif (regpairs_aligned(cpu_env)) {",
"arg4 = arg5;",
"arg5 = arg6;",
"if (!(VAR_2 = lock_user(VERIFY_WRITE, arg2, arg3, 0)))\ngoto efault;",
"ret = get_errno(pread64(arg1, VAR_2, arg3, target_offset64(arg4, arg5)));",
"unlock_user(VAR_2, arg2, ret);",
"case TARGET_NR_pwrite64:\nif (regpairs_aligned(cpu_env)) {",
"arg4 = arg5;",
"arg5 = arg6;",
"if (!(VAR_2 = lock_user(VERIFY_READ, arg2, arg3, 1)))\ngoto efault;",
"ret = get_errno(pwrite64(arg1, VAR_2, arg3, target_offset64(arg4, arg5)));",
"unlock_user(VAR_2, arg2, 0);",
"#endif\ncase TARGET_NR_getcwd:\nif (!(VAR_2 = lock_user(VERIFY_WRITE, arg1, arg2, 0)))\ngoto efault;",
"ret = get_errno(sys_getcwd1(VAR_2, arg2));",
"unlock_user(VAR_2, arg1, ret);",
"case TARGET_NR_capget:\ncase TARGET_NR_capset:\n{",
"struct target_user_cap_header *target_header;",
"struct target_user_cap_data *target_data = NULL;",
"struct __user_cap_header_struct header;",
"struct __user_cap_data_struct data[2];",
"struct __user_cap_data_struct *dataptr = NULL;",
"int i, target_datalen;",
"int data_items = 1;",
"if (!lock_user_struct(VERIFY_WRITE, target_header, arg1, 1)) {",
"goto efault;",
"header.version = tswap32(target_header->version);",
"header.pid = tswap32(target_header->pid);",
"if (header.version != _LINUX_CAPABILITY_VERSION) {",
"data_items = 2;",
"target_datalen = sizeof(*target_data) * data_items;",
"if (arg2) {",
"if (num == TARGET_NR_capget) {",
"target_data = lock_user(VERIFY_WRITE, arg2, target_datalen, 0);",
"} else {",
"target_data = lock_user(VERIFY_READ, arg2, target_datalen, 1);",
"if (!target_data) {",
"unlock_user_struct(target_header, arg1, 0);",
"goto efault;",
"if (num == TARGET_NR_capset) {",
"for (i = 0; i < data_items; i++) {",
"data[i].effective = tswap32(target_data[i].effective);",
"data[i].permitted = tswap32(target_data[i].permitted);",
"data[i].inheritable = tswap32(target_data[i].inheritable);",
"dataptr = data;",
"if (num == TARGET_NR_capget) {",
"ret = get_errno(capget(&header, dataptr));",
"} else {",
"ret = get_errno(capset(&header, dataptr));",
"target_header->version = tswap32(header.version);",
"unlock_user_struct(target_header, arg1, 1);",
"if (arg2) {",
"if (num == TARGET_NR_capget) {",
"for (i = 0; i < data_items; i++) {",
"target_data[i].effective = tswap32(data[i].effective);",
"target_data[i].permitted = tswap32(data[i].permitted);",
"target_data[i].inheritable = tswap32(data[i].inheritable);",
"unlock_user(target_data, arg2, target_datalen);",
"} else {",
"unlock_user(target_data, arg2, 0);",
"case TARGET_NR_sigaltstack:\nret = do_sigaltstack(arg1, arg2, get_sp_from_cpustate((CPUArchState *)cpu_env));",
"#ifdef CONFIG_SENDFILE\ncase TARGET_NR_sendfile:\n{",
"off_t *offp = NULL;",
"off_t off;",
"if (arg3) {",
"ret = get_user_sal(off, arg3);",
"if (is_error(ret)) {",
"offp = &off;",
"ret = get_errno(sendfile(arg1, arg2, offp, arg4));",
"if (!is_error(ret) && arg3) {",
"abi_long ret2 = put_user_sal(off, arg3);",
"if (is_error(ret2)) {",
"ret = ret2;",
"#ifdef TARGET_NR_sendfile64\ncase TARGET_NR_sendfile64:\n{",
"off_t *offp = NULL;",
"off_t off;",
"if (arg3) {",
"ret = get_user_s64(off, arg3);",
"if (is_error(ret)) {",
"offp = &off;",
"ret = get_errno(sendfile(arg1, arg2, offp, arg4));",
"if (!is_error(ret) && arg3) {",
"abi_long ret2 = put_user_s64(off, arg3);",
"if (is_error(ret2)) {",
"ret = ret2;",
"#endif\n#else\ncase TARGET_NR_sendfile:\n#ifdef TARGET_NR_sendfile64\ncase TARGET_NR_sendfile64:\n#endif\ngoto unimplemented;",
"#endif\n#ifdef TARGET_NR_getpmsg\ncase TARGET_NR_getpmsg:\ngoto unimplemented;",
"#endif\n#ifdef TARGET_NR_putpmsg\ncase TARGET_NR_putpmsg:\ngoto unimplemented;",
"#endif\n#ifdef TARGET_NR_vfork\ncase TARGET_NR_vfork:\nret = get_errno(do_fork(cpu_env, CLONE_VFORK | CLONE_VM | SIGCHLD,\n0, 0, 0, 0));",
"#endif\n#ifdef TARGET_NR_ugetrlimit\ncase TARGET_NR_ugetrlimit:\n{",
"struct rlimit rlim;",
"int resource = target_to_host_resource(arg1);",
"ret = get_errno(getrlimit(resource, &rlim));",
"if (!is_error(ret)) {",
"struct target_rlimit *target_rlim;",
"if (!lock_user_struct(VERIFY_WRITE, target_rlim, arg2, 0))\ngoto efault;",
"target_rlim->rlim_cur = host_to_target_rlim(rlim.rlim_cur);",
"target_rlim->rlim_max = host_to_target_rlim(rlim.rlim_max);",
"unlock_user_struct(target_rlim, arg2, 1);",
"#endif\n#ifdef TARGET_NR_truncate64\ncase TARGET_NR_truncate64:\nif (!(VAR_2 = lock_user_string(arg1)))\ngoto efault;",
"ret = target_truncate64(cpu_env, VAR_2, arg2, arg3, arg4);",
"unlock_user(VAR_2, arg1, 0);",
"#endif\n#ifdef TARGET_NR_ftruncate64\ncase TARGET_NR_ftruncate64:\nret = target_ftruncate64(cpu_env, arg1, arg2, arg3, arg4);",
"#endif\n#ifdef TARGET_NR_stat64\ncase TARGET_NR_stat64:\nif (!(VAR_2 = lock_user_string(arg1)))\ngoto efault;",
"ret = get_errno(stat(path(VAR_2), &VAR_0));",
"unlock_user(VAR_2, arg1, 0);",
"if (!is_error(ret))\nret = host_to_target_stat64(cpu_env, arg2, &VAR_0);",
"#endif\n#ifdef TARGET_NR_lstat64\ncase TARGET_NR_lstat64:\nif (!(VAR_2 = lock_user_string(arg1)))\ngoto efault;",
"ret = get_errno(lstat(path(VAR_2), &VAR_0));",
"unlock_user(VAR_2, arg1, 0);",
"if (!is_error(ret))\nret = host_to_target_stat64(cpu_env, arg2, &VAR_0);",
"#endif\n#ifdef TARGET_NR_fstat64\ncase TARGET_NR_fstat64:\nret = get_errno(fstat(arg1, &VAR_0));",
"if (!is_error(ret))\nret = host_to_target_stat64(cpu_env, arg2, &VAR_0);",
"#endif\n#if (defined(TARGET_NR_fstatat64) || defined(TARGET_NR_newfstatat))\n#ifdef TARGET_NR_fstatat64\ncase TARGET_NR_fstatat64:\n#endif\n#ifdef TARGET_NR_newfstatat\ncase TARGET_NR_newfstatat:\n#endif\nif (!(VAR_2 = lock_user_string(arg2)))\ngoto efault;",
"ret = get_errno(fstatat(arg1, path(VAR_2), &VAR_0, arg4));",
"if (!is_error(ret))\nret = host_to_target_stat64(cpu_env, arg3, &VAR_0);",
"#endif\n#ifdef TARGET_NR_lchown\ncase TARGET_NR_lchown:\nif (!(VAR_2 = lock_user_string(arg1)))\ngoto efault;",
"ret = get_errno(lchown(VAR_2, low2highuid(arg2), low2highgid(arg3)));",
"unlock_user(VAR_2, arg1, 0);",
"#endif\n#ifdef TARGET_NR_getuid\ncase TARGET_NR_getuid:\nret = get_errno(high2lowuid(getuid()));",
"#endif\n#ifdef TARGET_NR_getgid\ncase TARGET_NR_getgid:\nret = get_errno(high2lowgid(getgid()));",
"#endif\n#ifdef TARGET_NR_geteuid\ncase TARGET_NR_geteuid:\nret = get_errno(high2lowuid(geteuid()));",
"#endif\n#ifdef TARGET_NR_getegid\ncase TARGET_NR_getegid:\nret = get_errno(high2lowgid(getegid()));",
"#endif\ncase TARGET_NR_setreuid:\nret = get_errno(setreuid(low2highuid(arg1), low2highuid(arg2)));",
"case TARGET_NR_setregid:\nret = get_errno(setregid(low2highgid(arg1), low2highgid(arg2)));",
"case TARGET_NR_getgroups:\n{",
"int gidsetsize = arg1;",
"target_id *target_grouplist;",
"gid_t *grouplist;",
"int i;",
"grouplist = alloca(gidsetsize * sizeof(gid_t));",
"ret = get_errno(getgroups(gidsetsize, grouplist));",
"if (gidsetsize == 0)\nif (!is_error(ret)) {",
"target_grouplist = lock_user(VERIFY_WRITE, arg2, gidsetsize * sizeof(target_id), 0);",
"if (!target_grouplist)\ngoto efault;",
"for(i = 0;i < ret; i++)",
"target_grouplist[i] = tswapid(high2lowgid(grouplist[i]));",
"unlock_user(target_grouplist, arg2, gidsetsize * sizeof(target_id));",
"case TARGET_NR_setgroups:\n{",
"int gidsetsize = arg1;",
"target_id *target_grouplist;",
"gid_t *grouplist = NULL;",
"int i;",
"if (gidsetsize) {",
"grouplist = alloca(gidsetsize * sizeof(gid_t));",
"target_grouplist = lock_user(VERIFY_READ, arg2, gidsetsize * sizeof(target_id), 1);",
"if (!target_grouplist) {",
"ret = -TARGET_EFAULT;",
"goto fail;",
"for (i = 0; i < gidsetsize; i++) {",
"grouplist[i] = low2highgid(tswapid(target_grouplist[i]));",
"unlock_user(target_grouplist, arg2, 0);",
"ret = get_errno(setgroups(gidsetsize, grouplist));",
"case TARGET_NR_fchown:\nret = get_errno(fchown(arg1, low2highuid(arg2), low2highgid(arg3)));",
"#if defined(TARGET_NR_fchownat)\ncase TARGET_NR_fchownat:\nif (!(VAR_2 = lock_user_string(arg2)))\ngoto efault;",
"ret = get_errno(fchownat(arg1, VAR_2, low2highuid(arg3),\nlow2highgid(arg4), arg5));",
"unlock_user(VAR_2, arg2, 0);",
"#endif\n#ifdef TARGET_NR_setresuid\ncase TARGET_NR_setresuid:\nret = get_errno(sys_setresuid(low2highuid(arg1),\nlow2highuid(arg2),\nlow2highuid(arg3)));",
"#endif\n#ifdef TARGET_NR_getresuid\ncase TARGET_NR_getresuid:\n{",
"uid_t ruid, euid, suid;",
"ret = get_errno(getresuid(&ruid, &euid, &suid));",
"if (!is_error(ret)) {",
"if (put_user_id(high2lowuid(ruid), arg1)\n|| put_user_id(high2lowuid(euid), arg2)\n|| put_user_id(high2lowuid(suid), arg3))\ngoto efault;",
"#endif\n#ifdef TARGET_NR_getresgid\ncase TARGET_NR_setresgid:\nret = get_errno(sys_setresgid(low2highgid(arg1),\nlow2highgid(arg2),\nlow2highgid(arg3)));",
"#endif\n#ifdef TARGET_NR_getresgid\ncase TARGET_NR_getresgid:\n{",
"gid_t rgid, egid, sgid;",
"ret = get_errno(getresgid(&rgid, &egid, &sgid));",
"if (!is_error(ret)) {",
"if (put_user_id(high2lowgid(rgid), arg1)\n|| put_user_id(high2lowgid(egid), arg2)\n|| put_user_id(high2lowgid(sgid), arg3))\ngoto efault;",
"#endif\n#ifdef TARGET_NR_chown\ncase TARGET_NR_chown:\nif (!(VAR_2 = lock_user_string(arg1)))\ngoto efault;",
"ret = get_errno(chown(VAR_2, low2highuid(arg2), low2highgid(arg3)));",
"unlock_user(VAR_2, arg1, 0);",
"#endif\ncase TARGET_NR_setuid:\nret = get_errno(sys_setuid(low2highuid(arg1)));",
"case TARGET_NR_setgid:\nret = get_errno(sys_setgid(low2highgid(arg1)));",
"case TARGET_NR_setfsuid:\nret = get_errno(setfsuid(arg1));",
"case TARGET_NR_setfsgid:\nret = get_errno(setfsgid(arg1));",
"#ifdef TARGET_NR_lchown32\ncase TARGET_NR_lchown32:\nif (!(VAR_2 = lock_user_string(arg1)))\ngoto efault;",
"ret = get_errno(lchown(VAR_2, arg2, arg3));",
"unlock_user(VAR_2, arg1, 0);",
"#endif\n#ifdef TARGET_NR_getuid32\ncase TARGET_NR_getuid32:\nret = get_errno(getuid());",
"#endif\n#if defined(TARGET_NR_getxuid) && defined(TARGET_ALPHA)\ncase TARGET_NR_getxuid:\n{",
"uid_t euid;",
"euid=geteuid();",
"((CPUAlphaState *)cpu_env)->ir[IR_A4]=euid;",
"ret = get_errno(getuid());",
"#endif\n#if defined(TARGET_NR_getxgid) && defined(TARGET_ALPHA)\ncase TARGET_NR_getxgid:\n{",
"uid_t egid;",
"egid=getegid();",
"((CPUAlphaState *)cpu_env)->ir[IR_A4]=egid;",
"ret = get_errno(getgid());",
"#endif\n#if defined(TARGET_NR_osf_getsysinfo) && defined(TARGET_ALPHA)\ncase TARGET_NR_osf_getsysinfo:\nret = -TARGET_EOPNOTSUPP;",
"switch (arg1) {",
"case TARGET_GSI_IEEE_FP_CONTROL:\n{",
"uint64_t swcr, fpcr = cpu_alpha_load_fpcr (cpu_env);",
"swcr = (fpcr >> 35) & SWCR_STATUS_MASK;",
"swcr |= (fpcr >> 36) & SWCR_MAP_DMZ;",
"swcr |= (~fpcr >> 48) & (SWCR_TRAP_ENABLE_INV\n| SWCR_TRAP_ENABLE_DZE\n| SWCR_TRAP_ENABLE_OVF);",
"swcr |= (~fpcr >> 57) & (SWCR_TRAP_ENABLE_UNF\n| SWCR_TRAP_ENABLE_INE);",
"swcr |= (fpcr >> 47) & SWCR_MAP_UMZ;",
"swcr |= (~fpcr >> 41) & SWCR_TRAP_ENABLE_DNO;",
"if (put_user_u64 (swcr, arg2))\ngoto efault;",
"ret = 0;",
"#endif\n#if defined(TARGET_NR_osf_setsysinfo) && defined(TARGET_ALPHA)\ncase TARGET_NR_osf_setsysinfo:\nret = -TARGET_EOPNOTSUPP;",
"switch (arg1) {",
"case TARGET_SSI_IEEE_FP_CONTROL:\n{",
"uint64_t swcr, fpcr, orig_fpcr;",
"if (get_user_u64 (swcr, arg2)) {",
"goto efault;",
"orig_fpcr = cpu_alpha_load_fpcr(cpu_env);",
"fpcr = orig_fpcr & FPCR_DYN_MASK;",
"fpcr |= (swcr & SWCR_STATUS_MASK) << 35;",
"fpcr |= (swcr & SWCR_MAP_DMZ) << 36;",
"fpcr |= (~swcr & (SWCR_TRAP_ENABLE_INV\n| SWCR_TRAP_ENABLE_DZE\n| SWCR_TRAP_ENABLE_OVF)) << 48;",
"fpcr |= (~swcr & (SWCR_TRAP_ENABLE_UNF\n| SWCR_TRAP_ENABLE_INE)) << 57;",
"fpcr |= (swcr & SWCR_MAP_UMZ ? FPCR_UNDZ | FPCR_UNFD : 0);",
"fpcr |= (~swcr & SWCR_TRAP_ENABLE_DNO) << 41;",
"cpu_alpha_store_fpcr(cpu_env, fpcr);",
"ret = 0;",
"case TARGET_SSI_IEEE_RAISE_EXCEPTION:\n{",
"uint64_t exc, fpcr, orig_fpcr;",
"int si_code;",
"if (get_user_u64(exc, arg2)) {",
"goto efault;",
"orig_fpcr = cpu_alpha_load_fpcr(cpu_env);",
"fpcr = orig_fpcr | ((exc & SWCR_STATUS_MASK) << 35);",
"cpu_alpha_store_fpcr(cpu_env, fpcr);",
"ret = 0;",
"fpcr &= ~(orig_fpcr & FPCR_STATUS_MASK);",
"si_code = 0;",
"if ((fpcr & (FPCR_INE | FPCR_INED)) == FPCR_INE) {",
"si_code = TARGET_FPE_FLTRES;",
"if ((fpcr & (FPCR_UNF | FPCR_UNFD)) == FPCR_UNF) {",
"si_code = TARGET_FPE_FLTUND;",
"if ((fpcr & (FPCR_OVF | FPCR_OVFD)) == FPCR_OVF) {",
"si_code = TARGET_FPE_FLTOVF;",
"if ((fpcr & (FPCR_DZE | FPCR_DZED)) == FPCR_DZE) {",
"si_code = TARGET_FPE_FLTDIV;",
"if ((fpcr & (FPCR_INV | FPCR_INVD)) == FPCR_INV) {",
"si_code = TARGET_FPE_FLTINV;",
"if (si_code != 0) {",
"target_siginfo_t info;",
"info.si_signo = SIGFPE;",
"info.si_errno = 0;",
"info.si_code = si_code;",
"info._sifields._sigfault._addr\n= ((CPUArchState *)cpu_env)->pc;",
"queue_signal((CPUArchState *)cpu_env, info.si_signo, &info);",
"#endif\n#ifdef TARGET_NR_osf_sigprocmask\ncase TARGET_NR_osf_sigprocmask:\n{",
"abi_ulong mask;",
"int how;",
"sigset_t set, oldset;",
"switch(arg1) {",
"case TARGET_SIG_BLOCK:\nhow = SIG_BLOCK;",
"case TARGET_SIG_UNBLOCK:\nhow = SIG_UNBLOCK;",
"case TARGET_SIG_SETMASK:\nhow = SIG_SETMASK;",
"default:\ngoto fail;",
"mask = arg2;",
"target_to_host_old_sigset(&set, &mask);",
"ret = do_sigprocmask(how, &set, &oldset);",
"if (!ret) {",
"host_to_target_old_sigset(&mask, &oldset);",
"ret = mask;",
"#endif\n#ifdef TARGET_NR_getgid32\ncase TARGET_NR_getgid32:\nret = get_errno(getgid());",
"#endif\n#ifdef TARGET_NR_geteuid32\ncase TARGET_NR_geteuid32:\nret = get_errno(geteuid());",
"#endif\n#ifdef TARGET_NR_getegid32\ncase TARGET_NR_getegid32:\nret = get_errno(getegid());",
"#endif\n#ifdef TARGET_NR_setreuid32\ncase TARGET_NR_setreuid32:\nret = get_errno(setreuid(arg1, arg2));",
"#endif\n#ifdef TARGET_NR_setregid32\ncase TARGET_NR_setregid32:\nret = get_errno(setregid(arg1, arg2));",
"#endif\n#ifdef TARGET_NR_getgroups32\ncase TARGET_NR_getgroups32:\n{",
"int gidsetsize = arg1;",
"uint32_t *target_grouplist;",
"gid_t *grouplist;",
"int i;",
"grouplist = alloca(gidsetsize * sizeof(gid_t));",
"ret = get_errno(getgroups(gidsetsize, grouplist));",
"if (gidsetsize == 0)\nif (!is_error(ret)) {",
"target_grouplist = lock_user(VERIFY_WRITE, arg2, gidsetsize * 4, 0);",
"if (!target_grouplist) {",
"ret = -TARGET_EFAULT;",
"goto fail;",
"for(i = 0;i < ret; i++)",
"target_grouplist[i] = tswap32(grouplist[i]);",
"unlock_user(target_grouplist, arg2, gidsetsize * 4);",
"#endif\n#ifdef TARGET_NR_setgroups32\ncase TARGET_NR_setgroups32:\n{",
"int gidsetsize = arg1;",
"uint32_t *target_grouplist;",
"gid_t *grouplist;",
"int i;",
"grouplist = alloca(gidsetsize * sizeof(gid_t));",
"target_grouplist = lock_user(VERIFY_READ, arg2, gidsetsize * 4, 1);",
"if (!target_grouplist) {",
"ret = -TARGET_EFAULT;",
"goto fail;",
"for(i = 0;i < gidsetsize; i++)",
"grouplist[i] = tswap32(target_grouplist[i]);",
"unlock_user(target_grouplist, arg2, 0);",
"ret = get_errno(setgroups(gidsetsize, grouplist));",
"#endif\n#ifdef TARGET_NR_fchown32\ncase TARGET_NR_fchown32:\nret = get_errno(fchown(arg1, arg2, arg3));",
"#endif\n#ifdef TARGET_NR_setresuid32\ncase TARGET_NR_setresuid32:\nret = get_errno(sys_setresuid(arg1, arg2, arg3));",
"#endif\n#ifdef TARGET_NR_getresuid32\ncase TARGET_NR_getresuid32:\n{",
"uid_t ruid, euid, suid;",
"ret = get_errno(getresuid(&ruid, &euid, &suid));",
"if (!is_error(ret)) {",
"if (put_user_u32(ruid, arg1)\n|| put_user_u32(euid, arg2)\n|| put_user_u32(suid, arg3))\ngoto efault;",
"#endif\n#ifdef TARGET_NR_setresgid32\ncase TARGET_NR_setresgid32:\nret = get_errno(sys_setresgid(arg1, arg2, arg3));",
"#endif\n#ifdef TARGET_NR_getresgid32\ncase TARGET_NR_getresgid32:\n{",
"gid_t rgid, egid, sgid;",
"ret = get_errno(getresgid(&rgid, &egid, &sgid));",
"if (!is_error(ret)) {",
"if (put_user_u32(rgid, arg1)\n|| put_user_u32(egid, arg2)\n|| put_user_u32(sgid, arg3))\ngoto efault;",
"#endif\n#ifdef TARGET_NR_chown32\ncase TARGET_NR_chown32:\nif (!(VAR_2 = lock_user_string(arg1)))\ngoto efault;",
"ret = get_errno(chown(VAR_2, arg2, arg3));",
"unlock_user(VAR_2, arg1, 0);",
"#endif\n#ifdef TARGET_NR_setuid32\ncase TARGET_NR_setuid32:\nret = get_errno(sys_setuid(arg1));",
"#endif\n#ifdef TARGET_NR_setgid32\ncase TARGET_NR_setgid32:\nret = get_errno(sys_setgid(arg1));",
"#endif\n#ifdef TARGET_NR_setfsuid32\ncase TARGET_NR_setfsuid32:\nret = get_errno(setfsuid(arg1));",
"#endif\n#ifdef TARGET_NR_setfsgid32\ncase TARGET_NR_setfsgid32:\nret = get_errno(setfsgid(arg1));",
"#endif\ncase TARGET_NR_pivot_root:\ngoto unimplemented;",
"#ifdef TARGET_NR_mincore\ncase TARGET_NR_mincore:\n{",
"void *a;",
"ret = -TARGET_EFAULT;",
"if (!(a = lock_user(VERIFY_READ, arg1,arg2, 0)))\ngoto efault;",
"if (!(VAR_2 = lock_user_string(arg3)))\ngoto mincore_fail;",
"ret = get_errno(mincore(a, arg2, VAR_2));",
"unlock_user(VAR_2, arg3, ret);",
"mincore_fail:\nunlock_user(a, arg1, 0);",
"#endif\n#ifdef TARGET_NR_arm_fadvise64_64\ncase TARGET_NR_arm_fadvise64_64:\nret = posix_fadvise(arg1, target_offset64(arg3, arg4),\ntarget_offset64(arg5, arg6), arg2);",
"ret = -host_to_target_errno(ret);",
"#endif\n#if TARGET_ABI_BITS == 32\n#ifdef TARGET_NR_fadvise64_64\ncase TARGET_NR_fadvise64_64:\nif (regpairs_aligned(cpu_env)) {",
"arg2 = arg3;",
"arg3 = arg4;",
"arg4 = arg5;",
"arg5 = arg6;",
"arg6 = arg7;",
"ret = -host_to_target_errno(posix_fadvise(arg1,\ntarget_offset64(arg2, arg3),\ntarget_offset64(arg4, arg5),\narg6));",
"#endif\n#ifdef TARGET_NR_fadvise64\ncase TARGET_NR_fadvise64:\nif (regpairs_aligned(cpu_env)) {",
"arg2 = arg3;",
"arg3 = arg4;",
"arg4 = arg5;",
"arg5 = arg6;",
"ret = -host_to_target_errno(posix_fadvise(arg1,\ntarget_offset64(arg2, arg3),\narg4, arg5));",
"#endif\n#else\n#if defined(TARGET_NR_fadvise64_64) || defined(TARGET_NR_fadvise64)\n#ifdef TARGET_NR_fadvise64_64\ncase TARGET_NR_fadvise64_64:\n#endif\n#ifdef TARGET_NR_fadvise64\ncase TARGET_NR_fadvise64:\n#endif\n#ifdef TARGET_S390X\nswitch (arg4) {",
"case 4: arg4 = POSIX_FADV_NOREUSE + 1; break;",
"case 5: arg4 = POSIX_FADV_NOREUSE + 2; break;",
"case 6: arg4 = POSIX_FADV_DONTNEED; break;",
"case 7: arg4 = POSIX_FADV_NOREUSE; break;",
"default: break;",
"#endif\nret = -host_to_target_errno(posix_fadvise(arg1, arg2, arg3, arg4));",
"#endif\n#endif\n#ifdef TARGET_NR_madvise\ncase TARGET_NR_madvise:\nret = get_errno(0);",
"#endif\n#if TARGET_ABI_BITS == 32\ncase TARGET_NR_fcntl64:\n{",
"int cmd;",
"struct flock64 fl;",
"from_flock64_fn *copyfrom = copy_from_user_flock64;",
"to_flock64_fn *copyto = copy_to_user_flock64;",
"#ifdef TARGET_ARM\nif (((CPUARMState *)cpu_env)->eabi) {",
"copyfrom = copy_from_user_eabi_flock64;",
"copyto = copy_to_user_eabi_flock64;",
"#endif\ncmd = target_to_host_fcntl_cmd(arg2);",
"if (cmd == -TARGET_EINVAL) {",
"ret = cmd;",
"switch(arg2) {",
"case TARGET_F_GETLK64:\nret = copyfrom(&fl, arg3);",
"if (ret) {",
"ret = get_errno(fcntl(arg1, cmd, &fl));",
"if (ret == 0) {",
"ret = copyto(arg3, &fl);",
"case TARGET_F_SETLK64:\ncase TARGET_F_SETLKW64:\nret = copyfrom(&fl, arg3);",
"if (ret) {",
"ret = get_errno(safe_fcntl(arg1, cmd, &fl));",
"default:\nret = do_fcntl(arg1, arg2, arg3);",
"#endif\n#ifdef TARGET_NR_cacheflush\ncase TARGET_NR_cacheflush:\nret = 0;",
"#endif\n#ifdef TARGET_NR_security\ncase TARGET_NR_security:\ngoto unimplemented;",
"#endif\n#ifdef TARGET_NR_getpagesize\ncase TARGET_NR_getpagesize:\nret = TARGET_PAGE_SIZE;",
"#endif\ncase TARGET_NR_gettid:\nret = get_errno(gettid());",
"#ifdef TARGET_NR_readahead\ncase TARGET_NR_readahead:\n#if TARGET_ABI_BITS == 32\nif (regpairs_aligned(cpu_env)) {",
"arg2 = arg3;",
"arg3 = arg4;",
"arg4 = arg5;",
"ret = get_errno(readahead(arg1, ((off64_t)arg3 << 32) | arg2, arg4));",
"#else\nret = get_errno(readahead(arg1, arg2, arg3));",
"#endif\n#endif\n#ifdef CONFIG_ATTR\n#ifdef TARGET_NR_setxattr\ncase TARGET_NR_listxattr:\ncase TARGET_NR_llistxattr:\n{",
"void *VAR_2, *b = 0;",
"if (arg2) {",
"b = lock_user(VERIFY_WRITE, arg2, arg3, 0);",
"if (!b) {",
"ret = -TARGET_EFAULT;",
"VAR_2 = lock_user_string(arg1);",
"if (VAR_2) {",
"if (num == TARGET_NR_listxattr) {",
"ret = get_errno(listxattr(VAR_2, b, arg3));",
"} else {",
"ret = get_errno(llistxattr(VAR_2, b, arg3));",
"} else {",
"ret = -TARGET_EFAULT;",
"unlock_user(VAR_2, arg1, 0);",
"unlock_user(b, arg2, arg3);",
"case TARGET_NR_flistxattr:\n{",
"void *b = 0;",
"if (arg2) {",
"b = lock_user(VERIFY_WRITE, arg2, arg3, 0);",
"if (!b) {",
"ret = -TARGET_EFAULT;",
"ret = get_errno(flistxattr(arg1, b, arg3));",
"unlock_user(b, arg2, arg3);",
"case TARGET_NR_setxattr:\ncase TARGET_NR_lsetxattr:\n{",
"void *VAR_2, *n, *v = 0;",
"if (arg3) {",
"v = lock_user(VERIFY_READ, arg3, arg4, 1);",
"if (!v) {",
"ret = -TARGET_EFAULT;",
"VAR_2 = lock_user_string(arg1);",
"n = lock_user_string(arg2);",
"if (VAR_2 && n) {",
"if (num == TARGET_NR_setxattr) {",
"ret = get_errno(setxattr(VAR_2, n, v, arg4, arg5));",
"} else {",
"ret = get_errno(lsetxattr(VAR_2, n, v, arg4, arg5));",
"} else {",
"ret = -TARGET_EFAULT;",
"unlock_user(VAR_2, arg1, 0);",
"unlock_user(n, arg2, 0);",
"unlock_user(v, arg3, 0);",
"case TARGET_NR_fsetxattr:\n{",
"void *n, *v = 0;",
"if (arg3) {",
"v = lock_user(VERIFY_READ, arg3, arg4, 1);",
"if (!v) {",
"ret = -TARGET_EFAULT;",
"n = lock_user_string(arg2);",
"if (n) {",
"ret = get_errno(fsetxattr(arg1, n, v, arg4, arg5));",
"} else {",
"ret = -TARGET_EFAULT;",
"unlock_user(n, arg2, 0);",
"unlock_user(v, arg3, 0);",
"case TARGET_NR_getxattr:\ncase TARGET_NR_lgetxattr:\n{",
"void *VAR_2, *n, *v = 0;",
"if (arg3) {",
"v = lock_user(VERIFY_WRITE, arg3, arg4, 0);",
"if (!v) {",
"ret = -TARGET_EFAULT;",
"VAR_2 = lock_user_string(arg1);",
"n = lock_user_string(arg2);",
"if (VAR_2 && n) {",
"if (num == TARGET_NR_getxattr) {",
"ret = get_errno(getxattr(VAR_2, n, v, arg4));",
"} else {",
"ret = get_errno(lgetxattr(VAR_2, n, v, arg4));",
"} else {",
"ret = -TARGET_EFAULT;",
"unlock_user(VAR_2, arg1, 0);",
"unlock_user(n, arg2, 0);",
"unlock_user(v, arg3, arg4);",
"case TARGET_NR_fgetxattr:\n{",
"void *n, *v = 0;",
"if (arg3) {",
"v = lock_user(VERIFY_WRITE, arg3, arg4, 0);",
"if (!v) {",
"ret = -TARGET_EFAULT;",
"n = lock_user_string(arg2);",
"if (n) {",
"ret = get_errno(fgetxattr(arg1, n, v, arg4));",
"} else {",
"ret = -TARGET_EFAULT;",
"unlock_user(n, arg2, 0);",
"unlock_user(v, arg3, arg4);",
"case TARGET_NR_removexattr:\ncase TARGET_NR_lremovexattr:\n{",
"void *VAR_2, *n;",
"VAR_2 = lock_user_string(arg1);",
"n = lock_user_string(arg2);",
"if (VAR_2 && n) {",
"if (num == TARGET_NR_removexattr) {",
"ret = get_errno(removexattr(VAR_2, n));",
"} else {",
"ret = get_errno(lremovexattr(VAR_2, n));",
"} else {",
"ret = -TARGET_EFAULT;",
"unlock_user(VAR_2, arg1, 0);",
"unlock_user(n, arg2, 0);",
"case TARGET_NR_fremovexattr:\n{",
"void *n;",
"n = lock_user_string(arg2);",
"if (n) {",
"ret = get_errno(fremovexattr(arg1, n));",
"} else {",
"ret = -TARGET_EFAULT;",
"unlock_user(n, arg2, 0);",
"#endif\n#endif\n#ifdef TARGET_NR_set_thread_area\ncase TARGET_NR_set_thread_area:\n#if defined(TARGET_MIPS)\n((CPUMIPSState *) cpu_env)->active_tc.CP0_UserLocal = arg1;",
"ret = 0;",
"#elif defined(TARGET_CRIS)\nif (arg1 & 0xff)\nelse {",
"((CPUCRISState *) cpu_env)->pregs[PR_PID] = arg1;",
"ret = 0;",
"#elif defined(TARGET_I386) && defined(TARGET_ABI32)\nret = do_set_thread_area(cpu_env, arg1);",
"#elif defined(TARGET_M68K)\n{",
"TaskState *ts = cpu->opaque;",
"ts->tp_value = arg1;",
"ret = 0;",
"#else\ngoto unimplemented_nowarn;",
"#endif\n#endif\n#ifdef TARGET_NR_get_thread_area\ncase TARGET_NR_get_thread_area:\n#if defined(TARGET_I386) && defined(TARGET_ABI32)\nret = do_get_thread_area(cpu_env, arg1);",
"#elif defined(TARGET_M68K)\n{",
"TaskState *ts = cpu->opaque;",
"ret = ts->tp_value;",
"#else\ngoto unimplemented_nowarn;",
"#endif\n#endif\n#ifdef TARGET_NR_getdomainname\ncase TARGET_NR_getdomainname:\ngoto unimplemented_nowarn;",
"#endif\n#ifdef TARGET_NR_clock_gettime\ncase TARGET_NR_clock_gettime:\n{",
"struct timespec ts;",
"ret = get_errno(clock_gettime(arg1, &ts));",
"if (!is_error(ret)) {",
"host_to_target_timespec(arg2, &ts);",
"#endif\n#ifdef TARGET_NR_clock_getres\ncase TARGET_NR_clock_getres:\n{",
"struct timespec ts;",
"ret = get_errno(clock_getres(arg1, &ts));",
"if (!is_error(ret)) {",
"host_to_target_timespec(arg2, &ts);",
"#endif\n#ifdef TARGET_NR_clock_nanosleep\ncase TARGET_NR_clock_nanosleep:\n{",
"struct timespec ts;",
"target_to_host_timespec(&ts, arg3);",
"ret = get_errno(safe_clock_nanosleep(arg1, arg2,\n&ts, arg4 ? &ts : NULL));",
"if (arg4)\nhost_to_target_timespec(arg4, &ts);",
"#if defined(TARGET_PPC)\nif (ret && ret != -TARGET_ERESTARTSYS) {",
"((CPUPPCState *)cpu_env)->crf[0] |= 1;",
"#endif\n#endif\n#if defined(TARGET_NR_set_tid_address) && defined(__NR_set_tid_address)\ncase TARGET_NR_set_tid_address:\nret = get_errno(set_tid_address((int *)g2h(arg1)));",
"#endif\ncase TARGET_NR_tkill:\nret = get_errno(safe_tkill((int)arg1, target_to_host_signal(arg2)));",
"case TARGET_NR_tgkill:\nret = get_errno(safe_tgkill((int)arg1, (int)arg2,\ntarget_to_host_signal(arg3)));",
"#ifdef TARGET_NR_set_robust_list\ncase TARGET_NR_set_robust_list:\ncase TARGET_NR_get_robust_list:\ngoto unimplemented_nowarn;",
"#endif\n#if defined(TARGET_NR_utimensat)\ncase TARGET_NR_utimensat:\n{",
"struct timespec *tsp, ts[2];",
"if (!arg3) {",
"tsp = NULL;",
"} else {",
"target_to_host_timespec(ts, arg3);",
"target_to_host_timespec(ts+1, arg3+sizeof(struct target_timespec));",
"tsp = ts;",
"if (!arg2)\nret = get_errno(sys_utimensat(arg1, NULL, tsp, arg4));",
"else {",
"if (!(VAR_2 = lock_user_string(arg2))) {",
"ret = -TARGET_EFAULT;",
"goto fail;",
"ret = get_errno(sys_utimensat(arg1, path(VAR_2), tsp, arg4));",
"unlock_user(VAR_2, arg2, 0);",
"#endif\ncase TARGET_NR_futex:\nret = do_futex(arg1, arg2, arg3, arg4, arg5, arg6);",
"#if defined(TARGET_NR_inotify_init) && defined(__NR_inotify_init)\ncase TARGET_NR_inotify_init:\nret = get_errno(sys_inotify_init());",
"#endif\n#ifdef CONFIG_INOTIFY1\n#if defined(TARGET_NR_inotify_init1) && defined(__NR_inotify_init1)\ncase TARGET_NR_inotify_init1:\nret = get_errno(sys_inotify_init1(arg1));",
"#endif\n#endif\n#if defined(TARGET_NR_inotify_add_watch) && defined(__NR_inotify_add_watch)\ncase TARGET_NR_inotify_add_watch:\nVAR_2 = lock_user_string(arg2);",
"ret = get_errno(sys_inotify_add_watch(arg1, path(VAR_2), arg3));",
"unlock_user(VAR_2, arg2, 0);",
"#endif\n#if defined(TARGET_NR_inotify_rm_watch) && defined(__NR_inotify_rm_watch)\ncase TARGET_NR_inotify_rm_watch:\nret = get_errno(sys_inotify_rm_watch(arg1, arg2));",
"#endif\n#if defined(TARGET_NR_mq_open) && defined(__NR_mq_open)\ncase TARGET_NR_mq_open:\n{",
"struct mq_attr posix_mq_attr, *attrp;",
"VAR_2 = lock_user_string(arg1 - 1);",
"if (arg4 != 0) {",
"copy_from_user_mq_attr (&posix_mq_attr, arg4);",
"attrp = &posix_mq_attr;",
"} else {",
"attrp = 0;",
"ret = get_errno(mq_open(VAR_2, arg2, arg3, attrp));",
"unlock_user (VAR_2, arg1, 0);",
"case TARGET_NR_mq_unlink:\nVAR_2 = lock_user_string(arg1 - 1);",
"ret = get_errno(mq_unlink(VAR_2));",
"unlock_user (VAR_2, arg1, 0);",
"case TARGET_NR_mq_timedsend:\n{",
"struct timespec ts;",
"VAR_2 = lock_user (VERIFY_READ, arg2, arg3, 1);",
"if (arg5 != 0) {",
"target_to_host_timespec(&ts, arg5);",
"ret = get_errno(safe_mq_timedsend(arg1, VAR_2, arg3, arg4, &ts));",
"host_to_target_timespec(arg5, &ts);",
"} else {",
"ret = get_errno(safe_mq_timedsend(arg1, VAR_2, arg3, arg4, NULL));",
"unlock_user (VAR_2, arg2, arg3);",
"case TARGET_NR_mq_timedreceive:\n{",
"struct timespec ts;",
"unsigned int prio;",
"VAR_2 = lock_user (VERIFY_READ, arg2, arg3, 1);",
"if (arg5 != 0) {",
"target_to_host_timespec(&ts, arg5);",
"ret = get_errno(safe_mq_timedreceive(arg1, VAR_2, arg3,\n&prio, &ts));",
"host_to_target_timespec(arg5, &ts);",
"} else {",
"ret = get_errno(safe_mq_timedreceive(arg1, VAR_2, arg3,\n&prio, NULL));",
"unlock_user (VAR_2, arg2, arg3);",
"if (arg4 != 0)\nput_user_u32(prio, arg4);",
"case TARGET_NR_mq_getsetattr:\n{",
"struct mq_attr posix_mq_attr_in, posix_mq_attr_out;",
"ret = 0;",
"if (arg3 != 0) {",
"ret = mq_getattr(arg1, &posix_mq_attr_out);",
"copy_to_user_mq_attr(arg3, &posix_mq_attr_out);",
"if (arg2 != 0) {",
"copy_from_user_mq_attr(&posix_mq_attr_in, arg2);",
"ret |= mq_setattr(arg1, &posix_mq_attr_in, &posix_mq_attr_out);",
"#endif\n#ifdef CONFIG_SPLICE\n#ifdef TARGET_NR_tee\ncase TARGET_NR_tee:\n{",
"ret = get_errno(tee(arg1,arg2,arg3,arg4));",
"#endif\n#ifdef TARGET_NR_splice\ncase TARGET_NR_splice:\n{",
"loff_t loff_in, loff_out;",
"loff_t *ploff_in = NULL, *ploff_out = NULL;",
"if (arg2) {",
"if (get_user_u64(loff_in, arg2)) {",
"goto efault;",
"ploff_in = &loff_in;",
"if (arg4) {",
"if (get_user_u64(loff_out, arg4)) {",
"goto efault;",
"ploff_out = &loff_out;",
"ret = get_errno(splice(arg1, ploff_in, arg3, ploff_out, arg5, arg6));",
"if (arg2) {",
"if (put_user_u64(loff_in, arg2)) {",
"goto efault;",
"if (arg4) {",
"if (put_user_u64(loff_out, arg4)) {",
"goto efault;",
"#endif\n#ifdef TARGET_NR_vmsplice\ncase TARGET_NR_vmsplice:\n{",
"struct iovec *vec = lock_iovec(VERIFY_READ, arg2, arg3, 1);",
"if (vec != NULL) {",
"ret = get_errno(vmsplice(arg1, vec, arg3, arg4));",
"unlock_iovec(vec, arg2, arg3, 0);",
"} else {",
"ret = -host_to_target_errno(errno);",
"#endif\n#endif\n#ifdef CONFIG_EVENTFD\n#if defined(TARGET_NR_eventfd)\ncase TARGET_NR_eventfd:\nret = get_errno(eventfd(arg1, 0));",
"fd_trans_unregister(ret);",
"#endif\n#if defined(TARGET_NR_eventfd2)\ncase TARGET_NR_eventfd2:\n{",
"int host_flags = arg2 & (~(TARGET_O_NONBLOCK | TARGET_O_CLOEXEC));",
"if (arg2 & TARGET_O_NONBLOCK) {",
"host_flags |= O_NONBLOCK;",
"if (arg2 & TARGET_O_CLOEXEC) {",
"host_flags |= O_CLOEXEC;",
"ret = get_errno(eventfd(arg1, host_flags));",
"fd_trans_unregister(ret);",
"#endif\n#endif\n#if defined(CONFIG_FALLOCATE) && defined(TARGET_NR_fallocate)\ncase TARGET_NR_fallocate:\n#if TARGET_ABI_BITS == 32\nret = get_errno(fallocate(arg1, arg2, target_offset64(arg3, arg4),\ntarget_offset64(arg5, arg6)));",
"#else\nret = get_errno(fallocate(arg1, arg2, arg3, arg4));",
"#endif\n#endif\n#if defined(CONFIG_SYNC_FILE_RANGE)\n#if defined(TARGET_NR_sync_file_range)\ncase TARGET_NR_sync_file_range:\n#if TARGET_ABI_BITS == 32\n#if defined(TARGET_MIPS)\nret = get_errno(sync_file_range(arg1, target_offset64(arg3, arg4),\ntarget_offset64(arg5, arg6), arg7));",
"#else\nret = get_errno(sync_file_range(arg1, target_offset64(arg2, arg3),\ntarget_offset64(arg4, arg5), arg6));",
"#endif\n#else\nret = get_errno(sync_file_range(arg1, arg2, arg3, arg4));",
"#endif\n#endif\n#if defined(TARGET_NR_sync_file_range2)\ncase TARGET_NR_sync_file_range2:\n#if TARGET_ABI_BITS == 32\nret = get_errno(sync_file_range(arg1, target_offset64(arg3, arg4),\ntarget_offset64(arg5, arg6), arg2));",
"#else\nret = get_errno(sync_file_range(arg1, arg3, arg4, arg2));",
"#endif\n#endif\n#endif\n#if defined(TARGET_NR_signalfd4)\ncase TARGET_NR_signalfd4:\nret = do_signalfd4(arg1, arg2, arg4);",
"#endif\n#if defined(TARGET_NR_signalfd)\ncase TARGET_NR_signalfd:\nret = do_signalfd4(arg1, arg2, 0);",
"#endif\n#if defined(CONFIG_EPOLL)\n#if defined(TARGET_NR_epoll_create)\ncase TARGET_NR_epoll_create:\nret = get_errno(epoll_create(arg1));",
"#endif\n#if defined(TARGET_NR_epoll_create1) && defined(CONFIG_EPOLL_CREATE1)\ncase TARGET_NR_epoll_create1:\nret = get_errno(epoll_create1(arg1));",
"#endif\n#if defined(TARGET_NR_epoll_ctl)\ncase TARGET_NR_epoll_ctl:\n{",
"struct epoll_event ep;",
"struct epoll_event *epp = 0;",
"if (arg4) {",
"struct target_epoll_event *target_ep;",
"if (!lock_user_struct(VERIFY_READ, target_ep, arg4, 1)) {",
"goto efault;",
"ep.events = tswap32(target_ep->events);",
"ep.data.u64 = tswap64(target_ep->data.u64);",
"unlock_user_struct(target_ep, arg4, 0);",
"epp = &ep;",
"ret = get_errno(epoll_ctl(arg1, arg2, arg3, epp));",
"#endif\n#if defined(TARGET_NR_epoll_wait) || defined(TARGET_NR_epoll_pwait)\n#if defined(TARGET_NR_epoll_wait)\ncase TARGET_NR_epoll_wait:\n#endif\n#if defined(TARGET_NR_epoll_pwait)\ncase TARGET_NR_epoll_pwait:\n#endif\n{",
"struct target_epoll_event *target_ep;",
"struct epoll_event *ep;",
"int epfd = arg1;",
"int maxevents = arg3;",
"int timeout = arg4;",
"if (maxevents <= 0 || maxevents > TARGET_EP_MAX_EVENTS) {",
"target_ep = lock_user(VERIFY_WRITE, arg2,\nmaxevents * sizeof(struct target_epoll_event), 1);",
"if (!target_ep) {",
"goto efault;",
"ep = alloca(maxevents * sizeof(struct epoll_event));",
"switch (num) {",
"#if defined(TARGET_NR_epoll_pwait)\ncase TARGET_NR_epoll_pwait:\n{",
"target_sigset_t *target_set;",
"sigset_t _set, *set = &_set;",
"if (arg5) {",
"if (arg6 != sizeof(target_sigset_t)) {",
"target_set = lock_user(VERIFY_READ, arg5,\nsizeof(target_sigset_t), 1);",
"if (!target_set) {",
"unlock_user(target_ep, arg2, 0);",
"goto efault;",
"target_to_host_sigset(set, target_set);",
"unlock_user(target_set, arg5, 0);",
"} else {",
"set = NULL;",
"ret = get_errno(safe_epoll_pwait(epfd, ep, maxevents, timeout,\nset, SIGSET_T_SIZE));",
"#endif\n#if defined(TARGET_NR_epoll_wait)\ncase TARGET_NR_epoll_wait:\nret = get_errno(safe_epoll_pwait(epfd, ep, maxevents, timeout,\nNULL, 0));",
"#endif\ndefault:\nret = -TARGET_ENOSYS;",
"if (!is_error(ret)) {",
"int i;",
"for (i = 0; i < ret; i++) {",
"target_ep[i].events = tswap32(ep[i].events);",
"target_ep[i].data.u64 = tswap64(ep[i].data.u64);",
"unlock_user(target_ep, arg2, ret * sizeof(struct target_epoll_event));",
"#endif\n#endif\n#ifdef TARGET_NR_prlimit64\ncase TARGET_NR_prlimit64:\n{",
"struct target_rlimit64 *target_rnew, *target_rold;",
"struct host_rlimit64 rnew, rold, *rnewp = 0;",
"int resource = target_to_host_resource(arg2);",
"if (arg3) {",
"if (!lock_user_struct(VERIFY_READ, target_rnew, arg3, 1)) {",
"goto efault;",
"rnew.rlim_cur = tswap64(target_rnew->rlim_cur);",
"rnew.rlim_max = tswap64(target_rnew->rlim_max);",
"unlock_user_struct(target_rnew, arg3, 0);",
"rnewp = &rnew;",
"ret = get_errno(sys_prlimit64(arg1, resource, rnewp, arg4 ? &rold : 0));",
"if (!is_error(ret) && arg4) {",
"if (!lock_user_struct(VERIFY_WRITE, target_rold, arg4, 1)) {",
"goto efault;",
"target_rold->rlim_cur = tswap64(rold.rlim_cur);",
"target_rold->rlim_max = tswap64(rold.rlim_max);",
"unlock_user_struct(target_rold, arg4, 1);",
"#endif\n#ifdef TARGET_NR_gethostname\ncase TARGET_NR_gethostname:\n{",
"char *name = lock_user(VERIFY_WRITE, arg1, arg2, 0);",
"if (name) {",
"ret = get_errno(gethostname(name, arg2));",
"unlock_user(name, arg1, arg2);",
"} else {",
"ret = -TARGET_EFAULT;",
"#endif\n#ifdef TARGET_NR_atomic_cmpxchg_32\ncase TARGET_NR_atomic_cmpxchg_32:\n{",
"abi_ulong mem_value;",
"if (get_user_u32(mem_value, arg6)) {",
"target_siginfo_t info;",
"info.si_signo = SIGSEGV;",
"info.si_errno = 0;",
"info.si_code = TARGET_SEGV_MAPERR;",
"info._sifields._sigfault._addr = arg6;",
"queue_signal((CPUArchState *)cpu_env, info.si_signo, &info);",
"ret = 0xdeadbeef;",
"if (mem_value == arg2)\nput_user_u32(arg1, arg6);",
"ret = mem_value;",
"#endif\n#ifdef TARGET_NR_atomic_barrier\ncase TARGET_NR_atomic_barrier:\n{",
"ret = 0;",
"#endif\n#ifdef TARGET_NR_timer_create\ncase TARGET_NR_timer_create:\n{",
"struct sigevent host_sevp = { {0}, }, *phost_sevp = NULL;",
"int clkid = arg1;",
"int timer_index = next_free_host_timer();",
"if (timer_index < 0) {",
"ret = -TARGET_EAGAIN;",
"} else {",
"timer_t *phtimer = g_posix_timers + timer_index;",
"if (arg2) {",
"phost_sevp = &host_sevp;",
"ret = target_to_host_sigevent(phost_sevp, arg2);",
"if (ret != 0) {",
"ret = get_errno(timer_create(clkid, phost_sevp, phtimer));",
"if (ret) {",
"phtimer = NULL;",
"} else {",
"if (put_user(TIMER_MAGIC | timer_index, arg3, target_timer_t)) {",
"goto efault;",
"#endif\n#ifdef TARGET_NR_timer_settime\ncase TARGET_NR_timer_settime:\n{",
"target_timer_t timerid = get_timer_id(arg1);",
"if (timerid < 0) {",
"ret = timerid;",
"} else if (arg3 == 0) {",
"} else {",
"timer_t htimer = g_posix_timers[timerid];",
"struct itimerspec hspec_new = {{0},}, hspec_old = {{0},};",
"target_to_host_itimerspec(&hspec_new, arg3);",
"ret = get_errno(\ntimer_settime(htimer, arg2, &hspec_new, &hspec_old));",
"host_to_target_itimerspec(arg2, &hspec_old);",
"#endif\n#ifdef TARGET_NR_timer_gettime\ncase TARGET_NR_timer_gettime:\n{",
"target_timer_t timerid = get_timer_id(arg1);",
"if (timerid < 0) {",
"ret = timerid;",
"} else if (!arg2) {",
"ret = -TARGET_EFAULT;",
"} else {",
"timer_t htimer = g_posix_timers[timerid];",
"struct itimerspec hspec;",
"ret = get_errno(timer_gettime(htimer, &hspec));",
"if (host_to_target_itimerspec(arg2, &hspec)) {",
"ret = -TARGET_EFAULT;",
"#endif\n#ifdef TARGET_NR_timer_getoverrun\ncase TARGET_NR_timer_getoverrun:\n{",
"target_timer_t timerid = get_timer_id(arg1);",
"if (timerid < 0) {",
"ret = timerid;",
"} else {",
"timer_t htimer = g_posix_timers[timerid];",
"ret = get_errno(timer_getoverrun(htimer));",
"fd_trans_unregister(ret);",
"#endif\n#ifdef TARGET_NR_timer_delete\ncase TARGET_NR_timer_delete:\n{",
"target_timer_t timerid = get_timer_id(arg1);",
"if (timerid < 0) {",
"ret = timerid;",
"} else {",
"timer_t htimer = g_posix_timers[timerid];",
"ret = get_errno(timer_delete(htimer));",
"g_posix_timers[timerid] = 0;",
"#endif\n#if defined(TARGET_NR_timerfd_create) && defined(CONFIG_TIMERFD)\ncase TARGET_NR_timerfd_create:\nret = get_errno(timerfd_create(arg1,\ntarget_to_host_bitmask(arg2, fcntl_flags_tbl)));",
"#endif\n#if defined(TARGET_NR_timerfd_gettime) && defined(CONFIG_TIMERFD)\ncase TARGET_NR_timerfd_gettime:\n{",
"struct itimerspec its_curr;",
"ret = get_errno(timerfd_gettime(arg1, &its_curr));",
"if (arg2 && host_to_target_itimerspec(arg2, &its_curr)) {",
"goto efault;",
"#endif\n#if defined(TARGET_NR_timerfd_settime) && defined(CONFIG_TIMERFD)\ncase TARGET_NR_timerfd_settime:\n{",
"struct itimerspec its_new, its_old, *p_new;",
"if (arg3) {",
"if (target_to_host_itimerspec(&its_new, arg3)) {",
"goto efault;",
"p_new = &its_new;",
"} else {",
"p_new = NULL;",
"ret = get_errno(timerfd_settime(arg1, arg2, p_new, &its_old));",
"if (arg4 && host_to_target_itimerspec(arg4, &its_old)) {",
"goto efault;",
"#endif\n#if defined(TARGET_NR_ioprio_get) && defined(__NR_ioprio_get)\ncase TARGET_NR_ioprio_get:\nret = get_errno(ioprio_get(arg1, arg2));",
"#endif\n#if defined(TARGET_NR_ioprio_set) && defined(__NR_ioprio_set)\ncase TARGET_NR_ioprio_set:\nret = get_errno(ioprio_set(arg1, arg2, arg3));",
"#endif\n#if defined(TARGET_NR_setns) && defined(CONFIG_SETNS)\ncase TARGET_NR_setns:\nret = get_errno(setns(arg1, arg2));",
"#endif\n#if defined(TARGET_NR_unshare) && defined(CONFIG_SETNS)\ncase TARGET_NR_unshare:\nret = get_errno(unshare(arg1));",
"#endif\ndefault:\nunimplemented:\ngemu_log(\"qemu: Unsupported syscall: %d\\n\", num);",
"#if defined(TARGET_NR_setxattr) || defined(TARGET_NR_get_thread_area) || defined(TARGET_NR_getdomainname) || defined(TARGET_NR_set_robust_list)\nunimplemented_nowarn:\n#endif\nret = -TARGET_ENOSYS;",
"fail:\n#ifdef DEBUG\ngemu_log(\" = \" TARGET_ABI_FMT_ld \"\\n\", ret);",
"#endif\nif(do_strace)\nprint_syscall_ret(num, ret);",
"trace_guest_user_syscall_ret(cpu, num, ret);",
"return ret;",
"efault:\nret = -TARGET_EFAULT;",
"goto fail;"
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | [
[
1,
2,
3,
4,
5
],
[
6
],
[
7
],
[
8
],
[
9
],
[
10
],
[
11,
16
],
[
17
],
[
18
],
[
19
],
[
20
],
[
21,
22,
23
],
[
24,
25
],
[
26,
27
],
[
28
],
[
29,
34
],
[
35
],
[
36
],
[
37
],
[
38
],
[
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,
226
],
[
237
],
[
238
],
[
239
],
[
240,
241
],
[
242,
243
],
[
244
],
[
245,
246,
247
],
[
248
],
[
249
],
[
250,
251,
252
],
[
253,
254,
255
],
[
256
],
[
257
],
[
258,
259,
260
],
[
261
],
[
262
],
[
263,
264,
265,
266
],
[
267,
268,
269,
270,
271
],
[
272
],
[
273
],
[
274,
275,
276,
277,
278
],
[
279
],
[
280
],
[
281,
282,
283,
284,
285
],
[
286
],
[
287
],
[
288,
289,
290,
291
],
[
292,
293,
294,
295
],
[
296,
297,
298
],
[
299,
301,
302
],
[
303
],
[
304,
305,
306,
307
],
[
308,
309,
310
],
[
312
],
[
313
],
[
314
],
[
315
],
[
316
],
[
317
],
[
318
],
[
319
],
[
320
],
[
321
],
[
322
],
[
323
],
[
324
],
[
325
],
[
326
],
[
327
],
[
328
],
[
329
],
[
330
],
[
331
],
[
332
],
[
337
],
[
338
],
[
339
],
[
340
],
[
341
],
[
342
],
[
343
],
[
344
],
[
345
],
[
346
],
[
347,
348,
349,
350
],
[
351
],
[
352
],
[
353,
354,
355,
356
],
[
357
],
[
358,
359
],
[
360
],
[
361,
362,
363
],
[
364,
365,
366
],
[
367,
368,
369,
370
],
[
371,
372,
373,
374
],
[
375
],
[
376
],
[
377,
378,
379,
380
],
[
381
],
[
382
],
[
383
],
[
384,
385
],
[
386
],
[
387
],
[
388
],
[
389
],
[
390
],
[
391
],
[
392,
393
],
[
394
],
[
395
],
[
396,
397,
398,
399
],
[
400
],
[
401
],
[
402,
403,
404,
405
],
[
406
],
[
407
],
[
408
],
[
409,
410
],
[
411
],
[
412
],
[
413,
414,
415,
416
],
[
417
],
[
418
],
[
419,
420,
421,
422
],
[
423
],
[
424
],
[
425
],
[
426,
427
],
[
428
],
[
429
],
[
430,
431,
432,
433
],
[
434,
435,
436,
437
],
[
438,
439,
440,
441,
442
],
[
443
],
[
444
],
[
445,
446,
447,
448,
449
],
[
450
],
[
451
],
[
452,
453,
454,
455
],
[
456,
457,
458,
459
],
[
460,
461,
462
],
[
463
],
[
464,
465
],
[
466,
467,
468
],
[
469
],
[
470
],
[
471
],
[
472,
473
],
[
474,
475
],
[
476
],
[
477
],
[
478,
479,
480,
481
],
[
482
],
[
483
],
[
484
],
[
485,
486
],
[
487,
488
],
[
489
],
[
490
],
[
491,
492,
493,
494,
495
],
[
496
],
[
497
],
[
498,
499,
500,
501,
502
],
[
503
],
[
504
],
[
505,
506,
507,
508,
509
],
[
510
],
[
511
],
[
512,
513,
514
],
[
515
],
[
516
],
[
517,
518,
519
],
[
520,
521,
522,
523,
524
],
[
525,
526,
527
],
[
528
],
[
529
],
[
530
],
[
531
],
[
532
],
[
533,
534
],
[
535
],
[
536
],
[
537
],
[
538
],
[
539,
540
],
[
541,
542,
543
],
[
544,
545,
546,
547
],
[
548,
549,
550
],
[
551
],
[
552
],
[
553,
554
],
[
555
],
[
556
],
[
557,
558,
559,
560
],
[
561
],
[
562
],
[
563,
564,
565,
566
],
[
567,
568,
569
],
[
570,
571
],
[
572,
573,
574
],
[
575,
576,
577
],
[
578,
579,
580
],
[
581,
582,
583,
584
],
[
585,
586,
587
],
[
588,
589,
590
],
[
591
],
[
592
],
[
593,
594,
595
],
[
596,
597,
598,
599
],
[
600
],
[
601
],
[
602,
603,
604,
605
],
[
606
],
[
607
],
[
608,
609,
610,
611
],
[
612,
613,
614,
615
],
[
616,
617,
618
],
[
619,
620,
621
],
[
622,
623
],
[
624
],
[
625
],
[
626,
627
],
[
628
],
[
629
],
[
630
],
[
631
],
[
632
],
[
633
],
[
634
],
[
635
],
[
636,
637
],
[
638
],
[
639
],
[
640
],
[
641
],
[
642,
643
],
[
644
],
[
645,
646
],
[
647
],
[
648
],
[
649
],
[
650
],
[
651
],
[
652
],
[
653
],
[
654
],
[
655
],
[
656,
657
],
[
658
],
[
659
],
[
660
],
[
661
],
[
662
],
[
663
],
[
664
],
[
665,
666
],
[
667
],
[
668
],
[
669,
670
],
[
671
],
[
672
],
[
673
],
[
674
],
[
675
],
[
676
],
[
677
],
[
678
],
[
679
],
[
680
],
[
681,
682
],
[
683
],
[
684
],
[
685
],
[
686
],
[
687
],
[
688,
689,
690,
691
],
[
692,
693
],
[
694
],
[
695
],
[
696
],
[
697,
698
],
[
699
],
[
700
],
[
701
],
[
702
],
[
703
],
[
704
],
[
705
],
[
706
],
[
707,
708
],
[
709
],
[
710
],
[
711
],
[
712
],
[
713,
714
],
[
715
],
[
716
],
[
717
],
[
718,
719
],
[
720
],
[
721
],
[
722
],
[
723
],
[
724
],
[
725
],
[
726
],
[
727
],
[
728
],
[
729,
730,
731
],
[
732,
733
],
[
734,
735,
736,
737
],
[
738
],
[
739
],
[
740
],
[
741
],
[
742
],
[
743
],
[
744,
745,
746,
747
],
[
748
],
[
749
],
[
755
],
[
756
],
[
757
],
[
758
],
[
759
],
[
760
],
[
761
],
[
762
],
[
763,
764,
765,
766
],
[
767,
768
],
[
769
],
[
770
],
[
771
],
[
772,
773
],
[
774,
775
],
[
776,
777
],
[
778,
779
],
[
780
],
[
781
],
[
782
],
[
783
],
[
784
],
[
785
],
[
786
],
[
787,
788
],
[
789
],
[
790
],
[
791
],
[
792,
793
],
[
794,
795
],
[
796,
797
],
[
798,
799
],
[
800,
801
],
[
802
],
[
803
],
[
804
],
[
805
],
[
806
],
[
807
],
[
808
],
[
809
],
[
810,
811
],
[
812
],
[
813
],
[
814,
815,
816,
817
],
[
818
],
[
819
],
[
820
],
[
821
],
[
822
],
[
823,
824
],
[
825,
826
],
[
827,
828
],
[
829,
830
],
[
831,
832
],
[
833
],
[
834
],
[
835
],
[
836
],
[
837
],
[
838
],
[
839
],
[
840
],
[
841,
842
],
[
843
],
[
844
],
[
845,
846,
847
],
[
848
],
[
849
],
[
850
],
[
851,
852
],
[
853
],
[
854
],
[
855,
856,
857
],
[
858
],
[
864
],
[
865
],
[
866
],
[
867,
868
],
[
869
],
[
870
],
[
871,
872,
873
],
[
874
],
[
875,
876
],
[
877
],
[
878,
879,
880
],
[
881
],
[
882
],
[
883,
884,
885
],
[
886
],
[
887
],
[
888,
889,
890
],
[
891
],
[
892
],
[
893,
894
],
[
895
],
[
896
],
[
897,
898
],
[
899
],
[
900
],
[
901,
902
],
[
903
],
[
904
],
[
905
],
[
906
],
[
907,
908
],
[
909
],
[
910
],
[
911
],
[
912
],
[
913
],
[
914
],
[
915
],
[
916,
917
],
[
918
],
[
919
],
[
920,
921
],
[
922
],
[
923
],
[
924
],
[
925
],
[
926
],
[
927,
928
],
[
929
],
[
930
],
[
931
],
[
932
],
[
933
],
[
934
],
[
935
],
[
936,
937,
938
],
[
939
],
[
940
],
[
941
],
[
942,
943,
944
],
[
945
],
[
946
],
[
947
],
[
948,
949,
950
],
[
951
],
[
952
],
[
953,
954
],
[
955
],
[
956
],
[
957
],
[
958,
959
],
[
960
],
[
961
],
[
962
],
[
963
],
[
964,
965
],
[
966
],
[
967
],
[
968
],
[
969
],
[
970
],
[
971,
972
],
[
973
],
[
974
],
[
975
],
[
976,
977
],
[
978
],
[
979
],
[
980
],
[
981
],
[
982,
983
],
[
984
],
[
985
],
[
986
],
[
987,
988
],
[
989,
990
],
[
991
],
[
992
],
[
993
],
[
994
],
[
995
],
[
996
],
[
997
],
[
998
],
[
999
],
[
1000
],
[
1001
],
[
1002,
1003,
1004,
1005
],
[
1006,
1007
],
[
1008
],
[
1009
],
[
1010
],
[
1011,
1012
],
[
1013
],
[
1014
],
[
1015
],
[
1016
],
[
1017
],
[
1018
],
[
1019
],
[
1020,
1021,
1022,
1023,
1024
],
[
1025
],
[
1026
],
[
1027
],
[
1028
],
[
1033
],
[
1034
],
[
1035
],
[
1036
],
[
1037
],
[
1038
],
[
1039
],
[
1040
],
[
1041
],
[
1042
],
[
1043
],
[
1044
],
[
1045
],
[
1046
],
[
1047
],
[
1048
],
[
1049
],
[
1050
],
[
1051
],
[
1052
],
[
1053
],
[
1058
],
[
1059
],
[
1060
],
[
1061
],
[
1062
],
[
1063
],
[
1065
],
[
1066
],
[
1067
],
[
1068
],
[
1069
],
[
1070
],
[
1071
],
[
1072
],
[
1073
],
[
1074
],
[
1075
],
[
1076
],
[
1078
],
[
1079,
1080
],
[
1081
],
[
1082
],
[
1083
],
[
1084
],
[
1085
],
[
1086
],
[
1087
],
[
1088
],
[
1089,
1090
],
[
1091
],
[
1092,
1093
],
[
1094,
1095
],
[
1096,
1097
],
[
1098,
1099
],
[
1100,
1101,
1102,
1103
],
[
1104
],
[
1105
],
[
1106
],
[
1107,
1108
],
[
1109,
1110
],
[
1111
],
[
1112
],
[
1113,
1114,
1115,
1116
],
[
1117
],
[
1118
],
[
1119
],
[
1120,
1121
],
[
1122,
1123
],
[
1124
],
[
1125
],
[
1126,
1127,
1128,
1129
],
[
1130,
1131,
1132,
1133
],
[
1134
],
[
1135
],
[
1136
],
[
1137
],
[
1138
],
[
1139
],
[
1141
],
[
1142
],
[
1143
],
[
1145
],
[
1146
],
[
1147
],
[
1150
],
[
1152
],
[
1153
],
[
1154
],
[
1155
],
[
1156
],
[
1157,
1158,
1159,
1160
],
[
1161
],
[
1162
],
[
1163
],
[
1164
],
[
1165
],
[
1166
],
[
1167
],
[
1168
],
[
1169
],
[
1170
],
[
1171
],
[
1172
],
[
1173
],
[
1174
],
[
1175,
1176,
1177,
1178
],
[
1179,
1180,
1181,
1182,
1183
],
[
1184
],
[
1185
],
[
1186,
1187,
1188
],
[
1190
],
[
1191
],
[
1192
],
[
1193
],
[
1194
],
[
1195
],
[
1196
],
[
1197,
1198,
1199
],
[
1200,
1201,
1202,
1203,
1204,
1205,
1206,
1207
],
[
1208
],
[
1209
],
[
1210,
1211
],
[
1212
],
[
1213
],
[
1214
],
[
1215
],
[
1216
],
[
1217
],
[
1218
],
[
1219,
1220,
1221
],
[
1222,
1223,
1224,
1225,
1226
],
[
1227,
1228,
1229,
1230,
1231,
1232,
1233,
1234,
1235,
1236,
1237
],
[
1238,
1239,
1240
],
[
1241,
1242
],
[
1243
],
[
1245,
1246,
1247
],
[
1248
],
[
1249
],
[
1250
],
[
1251
],
[
1252,
1253,
1254
],
[
1255,
1257,
1258,
1259
],
[
1260,
1261,
1262,
1263
],
[
1264,
1265,
1266,
1267
],
[
1268,
1269,
1270,
1271
],
[
1272,
1273,
1274,
1275
],
[
1276,
1277,
1278,
1279
],
[
1280
],
[
1281
],
[
1282,
1283
],
[
1284,
1285
],
[
1286,
1287,
1288,
1289
],
[
1290
],
[
1291
],
[
1292,
1293,
1296
],
[
1297
],
[
1298
],
[
1299
],
[
1300,
1302
],
[
1303,
1305
],
[
1306,
1307,
1308
],
[
1309,
1310,
1311
],
[
1312,
1313,
1314,
1315
],
[
1316
],
[
1317
],
[
1318,
1319
],
[
1320
],
[
1321,
1322
],
[
1323
],
[
1324
],
[
1325
],
[
1326
],
[
1327
],
[
1328
],
[
1329
],
[
1330
],
[
1331
],
[
1332
],
[
1333
],
[
1334
],
[
1335
],
[
1336,
1337
],
[
1338
],
[
1339,
1340,
1341,
1342
],
[
1343
],
[
1344
],
[
1345,
1346
],
[
1347
],
[
1348,
1349
],
[
1350
],
[
1351
],
[
1352
],
[
1353
],
[
1354
],
[
1355
],
[
1356
],
[
1357
],
[
1358
],
[
1359
],
[
1360
],
[
1361
],
[
1362
],
[
1363,
1364
],
[
1365
],
[
1366,
1367,
1368,
1369
],
[
1370,
1371,
1372,
1373
],
[
1374,
1375,
1376,
1377
],
[
1378,
1379,
1380,
1381
],
[
1382,
1383,
1384,
1385
],
[
1386,
1387,
1388,
1389
],
[
1390,
1391,
1392,
1393
],
[
1394,
1395,
1396,
1397
],
[
1398,
1399,
1400,
1401
],
[
1402,
1403,
1404,
1405
],
[
1406,
1407,
1408,
1409
],
[
1410,
1411,
1412,
1413
],
[
1414,
1415,
1416,
1417
],
[
1418,
1419,
1420,
1421
],
[
1422,
1423,
1424,
1425
],
[
1426,
1427,
1428,
1429
],
[
1430,
1431
],
[
1432,
1433,
1434,
1435
],
[
1436,
1437,
1438,
1439
],
[
1440,
1441,
1442,
1443
],
[
1444
],
[
1445
],
[
1446
],
[
1447
],
[
1448,
1449,
1450,
1451
],
[
1452
],
[
1453,
1454,
1455,
1456
],
[
1457,
1458,
1459,
1460
],
[
1461,
1462,
1463,
1464
],
[
1465
],
[
1466
],
[
1467,
1468
],
[
1469
],
[
1470
],
[
1471
],
[
1472,
1473,
1474,
1475
],
[
1476
],
[
1477
],
[
1478
],
[
1479
],
[
1480,
1481,
1482,
1483,
1484
],
[
1485,
1486
],
[
1487
],
[
1488
],
[
1489
],
[
1490,
1491,
1492,
1493,
1494
],
[
1495,
1496,
1497,
1498
],
[
1499
],
[
1500
],
[
1501
],
[
1502,
1503,
1504,
1505,
1506
],
[
1507
],
[
1508
],
[
1509
],
[
1510,
1511,
1512
],
[
1513
],
[
1514,
1515,
1516,
1517
],
[
1518
],
[
1519,
1520
],
[
1521
],
[
1522
],
[
1523
],
[
1524
],
[
1525
],
[
1526
],
[
1527
],
[
1528
],
[
1529
],
[
1530
],
[
1531
],
[
1532
],
[
1533
],
[
1534
],
[
1535
],
[
1536,
1537,
1538
],
[
1539,
1540,
1541,
1542
],
[
1543,
1544,
1545
],
[
1546,
1547,
1548
],
[
1549,
1550,
1551,
1552,
1553
],
[
1554,
1555,
1556
],
[
1557
],
[
1558
],
[
1559
],
[
1560
],
[
1561
],
[
1562,
1563
],
[
1564,
1565
],
[
1566
],
[
1567
],
[
1568
],
[
1569
],
[
1570,
1571
],
[
1572
],
[
1573
],
[
1574
],
[
1575
],
[
1576,
1577,
1578,
1579
],
[
1580
],
[
1581
],
[
1582,
1583,
1584
],
[
1585
],
[
1586
],
[
1587
],
[
1588,
1589
],
[
1590,
1591
],
[
1592
],
[
1593
],
[
1594
],
[
1595
],
[
1596
],
[
1597
],
[
1598
],
[
1599
],
[
1600
],
[
1601
],
[
1602
],
[
1603
],
[
1604
],
[
1605
],
[
1606
],
[
1607,
1608,
1609
],
[
1610,
1611,
1612,
1613
],
[
1614,
1615,
1616,
1617
],
[
1618,
1619,
1620,
1621
],
[
1622,
1623,
1624,
1625
],
[
1626,
1627,
1628,
1629
],
[
1630,
1631,
1632,
1633
],
[
1634,
1635,
1636,
1637
],
[
1638,
1639,
1640,
1641
],
[
1642,
1643,
1644,
1645
],
[
1646,
1647,
1648,
1649
],
[
1650,
1651,
1652,
1653
],
[
1654,
1655,
1656
],
[
1657,
1664,
1665
],
[
1666,
1667
],
[
1668,
1669
],
[
1670,
1671
],
[
1672,
1673,
1675,
1676,
1677
],
[
1678,
1679
],
[
1680
],
[
1681,
1682,
1683,
1684
],
[
1685
],
[
1686
],
[
1687,
1689
],
[
1690
],
[
1691,
1692
],
[
1693
],
[
1694
],
[
1697
],
[
1699
],
[
1700,
1701
],
[
1702
],
[
1703,
1704,
1705
],
[
1706,
1707,
1708
],
[
1709,
1710
],
[
1711,
1712,
1713,
1714
],
[
1715,
1716,
1717,
1718,
1719,
1720,
1721,
1722,
1723
],
[
1724,
1725
],
[
1726,
1727
],
[
1728,
1729
],
[
1730,
1731,
1732
],
[
1733,
1734,
1735,
1736
],
[
1737,
1738,
1739
],
[
1740,
1741,
1742
],
[
1743,
1744,
1745,
1746
],
[
1747
],
[
1748,
1749
],
[
1750
],
[
1751
],
[
1752
],
[
1753
],
[
1754,
1755
],
[
1756,
1757
],
[
1758
],
[
1759,
1760,
1761,
1762,
1763,
1764
],
[
1765
],
[
1766
],
[
1767
],
[
1768
],
[
1769
],
[
1770
],
[
1771
],
[
1772
],
[
1773
],
[
1774
],
[
1775
],
[
1776
],
[
1777
],
[
1778
],
[
1779
],
[
1780
],
[
1781,
1782
],
[
1783
],
[
1784
],
[
1785
],
[
1786
],
[
1787
],
[
1788
],
[
1789
],
[
1790
],
[
1791
],
[
1792
],
[
1793
],
[
1794
],
[
1795
],
[
1796
],
[
1797
],
[
1798
],
[
1799
],
[
1800
],
[
1801,
1802
],
[
1803
],
[
1804
],
[
1805,
1806
],
[
1807
],
[
1808
],
[
1809
],
[
1810
],
[
1811
],
[
1812
],
[
1813
],
[
1814
],
[
1815,
1816
],
[
1817
],
[
1818
],
[
1819
],
[
1820
],
[
1821
],
[
1822,
1823,
1825
],
[
1826
],
[
1827
],
[
1828
],
[
1829
],
[
1830
],
[
1831
],
[
1832
],
[
1838
],
[
1839
],
[
1840
],
[
1841
],
[
1842
],
[
1843
],
[
1844
],
[
1845
],
[
1846
],
[
1847
],
[
1848
],
[
1849
],
[
1850
],
[
1851,
1852
],
[
1853
],
[
1854
],
[
1855
],
[
1856
],
[
1857
],
[
1861
],
[
1862
],
[
1863
],
[
1864
],
[
1865
],
[
1866
],
[
1867
],
[
1868,
1869,
1870,
1871,
1872
],
[
1873
],
[
1874
],
[
1875,
1876
],
[
1877
],
[
1878
],
[
1879
],
[
1880
],
[
1881
],
[
1882
],
[
1883
],
[
1884
],
[
1885,
1886
],
[
1887
],
[
1888
],
[
1889
],
[
1890
],
[
1891
],
[
1892,
1893,
1894,
1895
],
[
1896,
1897,
1898,
1899,
1900,
1901,
1902,
1903,
1904
],
[
1905
],
[
1906
],
[
1907
],
[
1908
],
[
1909
],
[
1910
],
[
1911
],
[
1912,
1913
],
[
1914
],
[
1915
],
[
1916
],
[
1917
],
[
1918
],
[
1919
],
[
1920
],
[
1921,
1922,
1923
],
[
1924
],
[
1925
],
[
1926
],
[
1927
],
[
1928
],
[
1929
],
[
1930
],
[
1931
],
[
1932
],
[
1933
],
[
1934
],
[
1935
],
[
1936
],
[
1937
],
[
1938
],
[
1939
],
[
1940
],
[
1941
],
[
1942
],
[
1943,
1944
],
[
1945
],
[
1946
],
[
1947
],
[
1948
],
[
1949,
1950,
1951,
1952
],
[
1953
],
[
1954
],
[
1956
],
[
1957
],
[
1958
],
[
1959
],
[
1961
],
[
1962
],
[
1963,
1964,
1965
],
[
1966
],
[
1967
],
[
1968
],
[
1969
],
[
1970,
1971,
1974
],
[
1975,
1976
],
[
1977
],
[
1978
],
[
1979
],
[
1980
],
[
1981
],
[
1982
],
[
1983,
1984
],
[
1985
],
[
1986
],
[
1987
],
[
1988
],
[
1989
],
[
1990
],
[
1991,
1992
],
[
1993,
1994,
1995
],
[
1996,
1997,
1998,
2001
],
[
2002,
2003,
2004
],
[
2005
],
[
2006
],
[
2011
],
[
2012
],
[
2013
],
[
2014
],
[
2015
],
[
2016
],
[
2024
],
[
2025
],
[
2026
],
[
2027
],
[
2028
],
[
2029,
2030
],
[
2031
],
[
2032
],
[
2037
],
[
2038
],
[
2039
],
[
2040
],
[
2041
],
[
2042
],
[
2043
],
[
2044
],
[
2045,
2046
],
[
2047
],
[
2048
],
[
2049
],
[
2050
],
[
2051,
2052
],
[
2053
],
[
2054
],
[
2055
],
[
2056,
2057
],
[
2058
],
[
2059
],
[
2060
],
[
2061
],
[
2062
],
[
2063
],
[
2064,
2065
],
[
2066
],
[
2067
],
[
2068,
2069
],
[
2070
],
[
2071
],
[
2072
],
[
2073
],
[
2074,
2075
],
[
2076
],
[
2077
],
[
2078
],
[
2079,
2080
],
[
2081,
2082
],
[
2083,
2084
],
[
2085,
2086
],
[
2087,
2088
],
[
2089
],
[
2090
],
[
2091
],
[
2092
],
[
2093,
2094
],
[
2095
],
[
2096
],
[
2097
],
[
2098
],
[
2099
],
[
2100,
2101,
2102
],
[
2103,
2104,
2105,
2106
],
[
2107,
2108,
2109
],
[
2110,
2111
],
[
2112
],
[
2113
],
[
2114,
2115
],
[
2116
],
[
2117,
2118,
2119
],
[
2120
],
[
2121
],
[
2122
],
[
2123,
2124
],
[
2125
],
[
2126,
2127
],
[
2128
],
[
2129
],
[
2130
],
[
2131,
2132
],
[
2133
],
[
2134,
2135,
2137
],
[
2138,
2139,
2140,
2141
],
[
2142,
2143
],
[
2144,
2145,
2146,
2147,
2148
],
[
2149
],
[
2150
],
[
2151,
2152
],
[
2153
],
[
2154
],
[
2155,
2156
],
[
2157
],
[
2158
],
[
2159,
2160
],
[
2161
],
[
2162
],
[
2163,
2164,
2165,
2166
],
[
2167
],
[
2168
],
[
2169,
2170,
2171
],
[
2172
],
[
2173
],
[
2174
],
[
2175
],
[
2176
],
[
2177
],
[
2178
],
[
2179
],
[
2180
],
[
2181
],
[
2182
],
[
2183
],
[
2185
],
[
2186
],
[
2187
],
[
2188
],
[
2189
],
[
2190
],
[
2191
],
[
2192
],
[
2193
],
[
2194
],
[
2195
],
[
2196
],
[
2197
],
[
2198
],
[
2199
],
[
2200
],
[
2201
],
[
2202
],
[
2203
],
[
2204
],
[
2206
],
[
2207
],
[
2208
],
[
2209
],
[
2210
],
[
2211
],
[
2212
],
[
2213
],
[
2214
],
[
2215
],
[
2216
],
[
2217,
2218
],
[
2219,
2220,
2221
],
[
2222
],
[
2223
],
[
2224
],
[
2225
],
[
2226
],
[
2227
],
[
2228
],
[
2229
],
[
2230
],
[
2231
],
[
2232
],
[
2233,
2234,
2235
],
[
2236
],
[
2237
],
[
2238
],
[
2239
],
[
2240
],
[
2241
],
[
2242
],
[
2243
],
[
2244
],
[
2245
],
[
2246
],
[
2247,
2248,
2249,
2250,
2251,
2252,
2253
],
[
2254,
2255,
2256,
2257
],
[
2258,
2259,
2260,
2261
],
[
2262,
2263,
2264,
2265,
2266
],
[
2267,
2268,
2269,
2270
],
[
2271
],
[
2272
],
[
2273
],
[
2274
],
[
2275
],
[
2276,
2277
],
[
2278
],
[
2279
],
[
2280
],
[
2281,
2282,
2283,
2284,
2285
],
[
2286
],
[
2287
],
[
2288,
2289,
2290,
2291
],
[
2292,
2293,
2294,
2295,
2296
],
[
2297
],
[
2298
],
[
2299,
2300
],
[
2301,
2302,
2303,
2304,
2305
],
[
2306
],
[
2307
],
[
2308,
2309
],
[
2310,
2311,
2312,
2313
],
[
2314,
2315
],
[
2316,
2317,
2318,
2319,
2320,
2321,
2322,
2323,
2324,
2325
],
[
2326
],
[
2327,
2328
],
[
2329,
2330,
2331,
2332,
2333
],
[
2334
],
[
2335
],
[
2336,
2337,
2338,
2339
],
[
2340,
2341,
2342,
2343
],
[
2344,
2345,
2346,
2347
],
[
2348,
2349,
2350,
2351
],
[
2352,
2353,
2354
],
[
2355,
2356
],
[
2357,
2358
],
[
2359
],
[
2360
],
[
2361
],
[
2362
],
[
2363
],
[
2364
],
[
2365,
2366
],
[
2367
],
[
2368,
2369
],
[
2370
],
[
2371
],
[
2372
],
[
2373,
2374
],
[
2375
],
[
2376
],
[
2377
],
[
2378
],
[
2379
],
[
2380
],
[
2381
],
[
2382
],
[
2383
],
[
2384
],
[
2385
],
[
2386
],
[
2387
],
[
2388
],
[
2389,
2390
],
[
2391,
2392,
2393,
2394
],
[
2395,
2396
],
[
2397
],
[
2398,
2399,
2400,
2401,
2402,
2403
],
[
2404,
2405,
2406,
2407
],
[
2408
],
[
2409
],
[
2410
],
[
2411,
2412,
2413,
2414
],
[
2415,
2416,
2417,
2418,
2419,
2420
],
[
2421,
2422,
2423,
2424
],
[
2425
],
[
2426
],
[
2427
],
[
2428,
2429,
2430,
2431
],
[
2432,
2433,
2434,
2435,
2436
],
[
2437
],
[
2438
],
[
2439,
2440,
2441
],
[
2442,
2443
],
[
2444,
2445
],
[
2446,
2447
],
[
2448,
2449,
2450,
2451
],
[
2452
],
[
2453
],
[
2454,
2455,
2456,
2457
],
[
2458,
2459,
2461,
2462
],
[
2463
],
[
2464
],
[
2465
],
[
2466
],
[
2467,
2468,
2470,
2471
],
[
2472
],
[
2473
],
[
2474
],
[
2475
],
[
2476,
2477,
2479,
2480
],
[
2481
],
[
2482,
2483
],
[
2484
],
[
2486
],
[
2487
],
[
2488,
2489,
2490
],
[
2491,
2492
],
[
2493
],
[
2494
],
[
2495,
2496
],
[
2497
],
[
2507,
2508,
2510,
2511
],
[
2512
],
[
2513,
2514
],
[
2515
],
[
2516
],
[
2517
],
[
2518
],
[
2519
],
[
2521
],
[
2522
],
[
2523,
2524,
2525
],
[
2526,
2527
],
[
2528
],
[
2529
],
[
2530
],
[
2531
],
[
2532,
2533
],
[
2534
],
[
2535
],
[
2536
],
[
2537
],
[
2538
],
[
2540
],
[
2541
],
[
2542
],
[
2544
],
[
2547
],
[
2548
],
[
2549
],
[
2550
],
[
2551
],
[
2552
],
[
2553
],
[
2554
],
[
2555
],
[
2556
],
[
2557
],
[
2558
],
[
2559
],
[
2560
],
[
2561
],
[
2562
],
[
2563,
2564
],
[
2565
],
[
2572,
2573,
2575,
2576
],
[
2577
],
[
2578
],
[
2579
],
[
2580
],
[
2581,
2582
],
[
2583,
2584
],
[
2585,
2586
],
[
2587,
2588
],
[
2589
],
[
2590
],
[
2591
],
[
2592
],
[
2593
],
[
2594
],
[
2595,
2596,
2597,
2598
],
[
2599,
2600,
2601,
2602
],
[
2603,
2604,
2605,
2606
],
[
2607,
2608,
2609,
2610
],
[
2611,
2612,
2613,
2614
],
[
2615,
2616,
2617,
2618
],
[
2619
],
[
2620
],
[
2621
],
[
2622
],
[
2623
],
[
2624
],
[
2625,
2626
],
[
2627
],
[
2628
],
[
2629
],
[
2630
],
[
2631
],
[
2632
],
[
2633
],
[
2634,
2635,
2636,
2637
],
[
2638
],
[
2639
],
[
2640
],
[
2641
],
[
2642
],
[
2643
],
[
2644
],
[
2645
],
[
2646
],
[
2647
],
[
2648
],
[
2649
],
[
2650
],
[
2651,
2652,
2653,
2654
],
[
2655,
2656,
2657,
2658
],
[
2659,
2660,
2661,
2662
],
[
2663
],
[
2664
],
[
2665
],
[
2666,
2667,
2668,
2669
],
[
2670,
2671,
2672,
2673
],
[
2674,
2675,
2676,
2677
],
[
2678
],
[
2679
],
[
2680
],
[
2681,
2682,
2683,
2684
],
[
2685,
2686,
2687,
2688,
2689
],
[
2690
],
[
2691
],
[
2692,
2693,
2694,
2695
],
[
2696,
2697,
2698,
2699
],
[
2700,
2701,
2702,
2703
],
[
2704,
2705,
2706,
2707
],
[
2708,
2709,
2710
],
[
2711,
2712,
2713
],
[
2714
],
[
2715
],
[
2716,
2717
],
[
2718,
2719
],
[
2720
],
[
2721
],
[
2722,
2723
],
[
2724,
2725,
2726,
2733,
2734
],
[
2735
],
[
2736,
2737,
2738,
2739,
2741
],
[
2743
],
[
2744
],
[
2745
],
[
2746
],
[
2747
],
[
2748,
2749,
2750,
2751
],
[
2752,
2753,
2754,
2756
],
[
2758
],
[
2759
],
[
2760
],
[
2761
],
[
2762,
2763,
2764
],
[
2765,
2766,
2767,
2768,
2769,
2770,
2771,
2772,
2773,
2774,
2775
],
[
2776
],
[
2777
],
[
2778
],
[
2779
],
[
2780
],
[
2781,
2782
],
[
2783,
2784,
2785,
2786,
2791
],
[
2792,
2793,
2794,
2795
],
[
2796
],
[
2797
],
[
2798
],
[
2799
],
[
2800,
2801
],
[
2802
],
[
2803
],
[
2804,
2805
],
[
2806
],
[
2807
],
[
2808
],
[
2809,
2810
],
[
2811
],
[
2812
],
[
2813
],
[
2814
],
[
2815,
2816,
2817
],
[
2818
],
[
2819
],
[
2820,
2821
],
[
2822,
2823,
2824,
2826
],
[
2827,
2828,
2829,
2830
],
[
2831,
2832,
2833,
2834
],
[
2835,
2836,
2837
],
[
2838,
2839,
2840,
2841
],
[
2842
],
[
2843
],
[
2844
],
[
2845
],
[
2846,
2847
],
[
2848,
2849,
2850,
2851,
2852,
2853,
2854
],
[
2855
],
[
2856
],
[
2857
],
[
2858
],
[
2859
],
[
2860
],
[
2861
],
[
2862
],
[
2863
],
[
2864
],
[
2865
],
[
2866
],
[
2867
],
[
2868
],
[
2869
],
[
2870,
2871
],
[
2872
],
[
2873
],
[
2874
],
[
2875
],
[
2876
],
[
2877
],
[
2878
],
[
2879,
2880,
2881
],
[
2882
],
[
2883
],
[
2884
],
[
2885
],
[
2886
],
[
2887
],
[
2888
],
[
2889
],
[
2890
],
[
2891
],
[
2892
],
[
2893
],
[
2894
],
[
2895
],
[
2896
],
[
2897
],
[
2898
],
[
2899,
2900
],
[
2901
],
[
2902
],
[
2903
],
[
2904
],
[
2905
],
[
2906
],
[
2907
],
[
2908
],
[
2909
],
[
2910
],
[
2911
],
[
2912
],
[
2913,
2914,
2915
],
[
2916
],
[
2917
],
[
2918
],
[
2919
],
[
2920
],
[
2921
],
[
2922
],
[
2923
],
[
2924
],
[
2925
],
[
2926
],
[
2927
],
[
2928
],
[
2929
],
[
2930
],
[
2931
],
[
2932
],
[
2933,
2934
],
[
2935
],
[
2936
],
[
2937
],
[
2938
],
[
2939
],
[
2940
],
[
2941
],
[
2942
],
[
2943
],
[
2944
],
[
2945
],
[
2946
],
[
2947,
2948,
2949
],
[
2950
],
[
2951
],
[
2952
],
[
2953
],
[
2954
],
[
2955
],
[
2956
],
[
2957
],
[
2958
],
[
2959
],
[
2960
],
[
2961
],
[
2962,
2963
],
[
2964
],
[
2965
],
[
2966
],
[
2967
],
[
2968
],
[
2969
],
[
2970
],
[
2971,
2972,
2973,
2974,
2975,
2976
],
[
2977
],
[
2978,
2979,
2980
],
[
2981
],
[
2982
],
[
2983,
2984
],
[
2985,
2986
],
[
2987
],
[
2988
],
[
2989
],
[
2990,
2991
],
[
2992,
2993,
2994,
2995,
2996,
2997
],
[
2998,
2999
],
[
3000
],
[
3001
],
[
3002,
3003
],
[
3004,
3005,
3006,
3007,
3008
],
[
3009,
3010,
3011,
3012
],
[
3013
],
[
3014
],
[
3015
],
[
3016
],
[
3017,
3018,
3019,
3020
],
[
3021
],
[
3022
],
[
3023
],
[
3024
],
[
3025,
3026,
3027,
3028
],
[
3029
],
[
3030
],
[
3031,
3032
],
[
3033,
3034
],
[
3035,
3038
],
[
3039
],
[
3040,
3041,
3042,
3043,
3044
],
[
3045,
3046,
3047
],
[
3048,
3049,
3050
],
[
3051,
3052,
3053,
3066
],
[
3067,
3068,
3069,
3070
],
[
3071
],
[
3072
],
[
3073
],
[
3074
],
[
3075
],
[
3076
],
[
3077
],
[
3078,
3079
],
[
3080
],
[
3081
],
[
3082
],
[
3083
],
[
3084
],
[
3085
],
[
3086,
3087,
3088
],
[
3089,
3090,
3091
],
[
3092,
3093,
3094,
3095,
3096
],
[
3097,
3098,
3099,
3100,
3101
],
[
3102
],
[
3103
],
[
3104,
3105,
3106,
3107
],
[
3108,
3109,
3110,
3111
],
[
3112
],
[
3113
],
[
3114
],
[
3115
],
[
3116
],
[
3117
],
[
3118
],
[
3119
],
[
3120
],
[
3121,
3122
],
[
3123
],
[
3124
],
[
3125,
3126
],
[
3127
],
[
3128
],
[
3129
],
[
3130
],
[
3131
],
[
3132
],
[
3133
],
[
3134
],
[
3135
],
[
3136,
3137
],
[
3138
],
[
3139
],
[
3140
],
[
3141
],
[
3142
],
[
3143,
3144
],
[
3145
],
[
3146
],
[
3147,
3148
],
[
3149
],
[
3150,
3151
],
[
3155,
3156
],
[
3157
],
[
3158
],
[
3159
],
[
3160
],
[
3161
],
[
3162
],
[
3163
],
[
3164
],
[
3165,
3166,
3167,
3168,
3169
],
[
3170
],
[
3171,
3172,
3173,
3174
],
[
3175
],
[
3176
],
[
3177
],
[
3178
],
[
3179
],
[
3180
],
[
3181
],
[
3182
],
[
3183
],
[
3184
],
[
3185
],
[
3186
],
[
3187
],
[
3188
],
[
3189
],
[
3190
],
[
3191
],
[
3192,
3193,
3194,
3195
],
[
3196
],
[
3197
],
[
3198
],
[
3199
],
[
3200
],
[
3201
],
[
3202,
3203,
3204,
3205,
3206,
3207
],
[
3208
],
[
3209,
3210,
3211,
3212
],
[
3213
],
[
3214
],
[
3215
],
[
3216
],
[
3217
],
[
3218
],
[
3219
],
[
3220,
3221,
3222,
3223,
3224,
3225,
3226
],
[
3227,
3228
],
[
3229,
3230,
3231,
3232,
3233,
3234,
3235,
3236,
3237
],
[
3238,
3239,
3240
],
[
3241,
3242,
3243
],
[
3244,
3245,
3246,
3247,
3249,
3250,
3251
],
[
3252,
3253
],
[
3254,
3255,
3256,
3257,
3258,
3259
],
[
3260,
3261,
3262,
3263
],
[
3264,
3265,
3266,
3267,
3268
],
[
3269,
3270,
3271,
3272
],
[
3273,
3274,
3275,
3276
],
[
3277
],
[
3278
],
[
3279
],
[
3280
],
[
3281
],
[
3282
],
[
3283
],
[
3288
],
[
3289
],
[
3290
],
[
3291
],
[
3292,
3293,
3294,
3295,
3296,
3297,
3298,
3299,
3300
],
[
3301
],
[
3302
],
[
3303
],
[
3304
],
[
3305
],
[
3306
],
[
3307,
3308
],
[
3309
],
[
3310
],
[
3311
],
[
3312
],
[
3313,
3314,
3315
],
[
3316
],
[
3317
],
[
3318
],
[
3319
],
[
3320,
3321
],
[
3322
],
[
3323
],
[
3324
],
[
3325
],
[
3326
],
[
3327
],
[
3328
],
[
3329,
3330
],
[
3331,
3332,
3333,
3334,
3335
],
[
3336,
3337,
3338
],
[
3339
],
[
3340
],
[
3341
],
[
3342
],
[
3343
],
[
3344
],
[
3345,
3346,
3347,
3348,
3349
],
[
3351
],
[
3352
],
[
3353
],
[
3354
],
[
3355
],
[
3356
],
[
3357
],
[
3358
],
[
3359
],
[
3360
],
[
3361
],
[
3362
],
[
3363
],
[
3364
],
[
3365
],
[
3366
],
[
3367
],
[
3368,
3369,
3370,
3371
],
[
3372
],
[
3373
],
[
3374
],
[
3375
],
[
3376
],
[
3377
],
[
3378,
3379,
3380,
3381
],
[
3383
],
[
3384
],
[
3385
],
[
3386
],
[
3387
],
[
3388
],
[
3389
],
[
3390
],
[
3391
],
[
3392,
3393
],
[
3394
],
[
3395,
3396,
3397,
3398
],
[
3400
],
[
3401,
3402,
3403,
3404
],
[
3406
],
[
3407
],
[
3408
],
[
3409
],
[
3410
],
[
3411
],
[
3412
],
[
3413
],
[
3414
],
[
3415
],
[
3416
],
[
3417
],
[
3418
],
[
3419
],
[
3420
],
[
3421
],
[
3422
],
[
3423,
3424,
3425,
3426
],
[
3429
],
[
3430
],
[
3431
],
[
3432
],
[
3433
],
[
3434
],
[
3435
],
[
3436
],
[
3437,
3438
],
[
3439
],
[
3440,
3441,
3442,
3443
],
[
3445
],
[
3446
],
[
3447
],
[
3448
],
[
3449
],
[
3450
],
[
3451
],
[
3452
],
[
3453
],
[
3454
],
[
3455
],
[
3456,
3457,
3458,
3459
],
[
3461
],
[
3462
],
[
3463
],
[
3464
],
[
3465
],
[
3466
],
[
3467
],
[
3468,
3469,
3470,
3471
],
[
3473
],
[
3474
],
[
3475
],
[
3476
],
[
3477
],
[
3478
],
[
3479
],
[
3480,
3481,
3482,
3483,
3484
],
[
3485,
3486,
3487,
3488
],
[
3489
],
[
3490
],
[
3491
],
[
3492
],
[
3493,
3494,
3495,
3496
],
[
3497
],
[
3498
],
[
3499
],
[
3500
],
[
3501
],
[
3502
],
[
3503
],
[
3504
],
[
3505
],
[
3506
],
[
3507,
3508,
3509,
3510
],
[
3511,
3512,
3513,
3514
],
[
3515,
3516,
3517,
3518
],
[
3519,
3520,
3521,
3522
],
[
3523,
3524,
3525,
3526
],
[
3527,
3528,
3529,
3530
],
[
3531,
3532,
3533
],
[
3534,
3535,
3536
],
[
3537
],
[
3538
],
[
3539,
3540
],
[
3541
]
] |
21,465 | static void build_chunks(MOVTrack *trk)
{
int i;
MOVIentry *chunk= &trk->cluster[0];
uint64_t chunkSize = chunk->size;
chunk->chunkNum= 1;
trk->chunkCount= 1;
for(i=1; i<trk->entry; i++){
if(chunk->pos + chunkSize == trk->cluster[i].pos){
chunkSize += trk->cluster[i].size;
chunk->samplesInChunk += trk->cluster[i].entries;
}else{
trk->cluster[i].chunkNum = chunk->chunkNum+1;
chunk=&trk->cluster[i];
chunkSize = chunk->size;
trk->chunkCount++;
}
}
}
| false | FFmpeg | 2aadff2e44fa27664ccd1b0a63829e61bf82e939 | static void build_chunks(MOVTrack *trk)
{
int i;
MOVIentry *chunk= &trk->cluster[0];
uint64_t chunkSize = chunk->size;
chunk->chunkNum= 1;
trk->chunkCount= 1;
for(i=1; i<trk->entry; i++){
if(chunk->pos + chunkSize == trk->cluster[i].pos){
chunkSize += trk->cluster[i].size;
chunk->samplesInChunk += trk->cluster[i].entries;
}else{
trk->cluster[i].chunkNum = chunk->chunkNum+1;
chunk=&trk->cluster[i];
chunkSize = chunk->size;
trk->chunkCount++;
}
}
}
| {
"code": [],
"line_no": []
} | static void FUNC_0(MOVTrack *VAR_0)
{
int VAR_1;
MOVIentry *chunk= &VAR_0->cluster[0];
uint64_t chunkSize = chunk->size;
chunk->chunkNum= 1;
VAR_0->chunkCount= 1;
for(VAR_1=1; VAR_1<VAR_0->entry; VAR_1++){
if(chunk->pos + chunkSize == VAR_0->cluster[VAR_1].pos){
chunkSize += VAR_0->cluster[VAR_1].size;
chunk->samplesInChunk += VAR_0->cluster[VAR_1].entries;
}else{
VAR_0->cluster[VAR_1].chunkNum = chunk->chunkNum+1;
chunk=&VAR_0->cluster[VAR_1];
chunkSize = chunk->size;
VAR_0->chunkCount++;
}
}
}
| [
"static void FUNC_0(MOVTrack *VAR_0)\n{",
"int VAR_1;",
"MOVIentry *chunk= &VAR_0->cluster[0];",
"uint64_t chunkSize = chunk->size;",
"chunk->chunkNum= 1;",
"VAR_0->chunkCount= 1;",
"for(VAR_1=1; VAR_1<VAR_0->entry; VAR_1++){",
"if(chunk->pos + chunkSize == VAR_0->cluster[VAR_1].pos){",
"chunkSize += VAR_0->cluster[VAR_1].size;",
"chunk->samplesInChunk += VAR_0->cluster[VAR_1].entries;",
"}else{",
"VAR_0->cluster[VAR_1].chunkNum = chunk->chunkNum+1;",
"chunk=&VAR_0->cluster[VAR_1];",
"chunkSize = chunk->size;",
"VAR_0->chunkCount++;",
"}",
"}",
"}"
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | [
[
1,
3
],
[
5
],
[
7
],
[
9
],
[
11
],
[
13
],
[
15
],
[
17
],
[
19
],
[
21
],
[
23
],
[
25
],
[
27
],
[
29
],
[
31
],
[
33
],
[
35
],
[
37
]
] |
21,467 | static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
const AVFrame *pic, int *got_packet)
{
ProresContext *ctx = avctx->priv_data;
uint8_t *orig_buf, *buf, *slice_hdr, *slice_sizes, *tmp;
uint8_t *picture_size_pos;
PutBitContext pb;
int x, y, i, mb, q = 0;
int sizes[4] = { 0 };
int slice_hdr_size = 2 + 2 * (ctx->num_planes - 1);
int frame_size, picture_size, slice_size;
int pkt_size, ret;
uint8_t frame_flags;
*avctx->coded_frame = *pic;
avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;
avctx->coded_frame->key_frame = 1;
pkt_size = ctx->frame_size_upper_bound;
if ((ret = ff_alloc_packet(pkt, pkt_size + FF_MIN_BUFFER_SIZE)) < 0) {
av_log(avctx, AV_LOG_ERROR, "Error getting output packet.\n");
return ret;
}
orig_buf = pkt->data;
// frame atom
orig_buf += 4; // frame size
bytestream_put_be32 (&orig_buf, FRAME_ID); // frame container ID
buf = orig_buf;
// frame header
tmp = buf;
buf += 2; // frame header size will be stored here
bytestream_put_be16 (&buf, 0); // version 1
bytestream_put_buffer(&buf, ctx->vendor, 4);
bytestream_put_be16 (&buf, avctx->width);
bytestream_put_be16 (&buf, avctx->height);
frame_flags = ctx->chroma_factor << 6;
if (avctx->flags & CODEC_FLAG_INTERLACED_DCT)
frame_flags |= pic->top_field_first ? 0x04 : 0x08;
bytestream_put_byte (&buf, frame_flags);
bytestream_put_byte (&buf, 0); // reserved
bytestream_put_byte (&buf, avctx->color_primaries);
bytestream_put_byte (&buf, avctx->color_trc);
bytestream_put_byte (&buf, avctx->colorspace);
bytestream_put_byte (&buf, 0x40 | (ctx->alpha_bits >> 3));
bytestream_put_byte (&buf, 0); // reserved
if (ctx->quant_sel != QUANT_MAT_DEFAULT) {
bytestream_put_byte (&buf, 0x03); // matrix flags - both matrices are present
// luma quantisation matrix
for (i = 0; i < 64; i++)
bytestream_put_byte(&buf, ctx->quant_mat[i]);
// chroma quantisation matrix
for (i = 0; i < 64; i++)
bytestream_put_byte(&buf, ctx->quant_mat[i]);
} else {
bytestream_put_byte (&buf, 0x00); // matrix flags - default matrices are used
}
bytestream_put_be16 (&tmp, buf - orig_buf); // write back frame header size
for (ctx->cur_picture_idx = 0;
ctx->cur_picture_idx < ctx->pictures_per_frame;
ctx->cur_picture_idx++) {
// picture header
picture_size_pos = buf + 1;
bytestream_put_byte (&buf, 0x40); // picture header size (in bits)
buf += 4; // picture data size will be stored here
bytestream_put_be16 (&buf, ctx->slices_per_picture);
bytestream_put_byte (&buf, av_log2(ctx->mbs_per_slice) << 4); // slice width and height in MBs
// seek table - will be filled during slice encoding
slice_sizes = buf;
buf += ctx->slices_per_picture * 2;
// slices
if (!ctx->force_quant) {
ret = avctx->execute2(avctx, find_quant_thread, NULL, NULL,
ctx->mb_height);
if (ret)
return ret;
}
for (y = 0; y < ctx->mb_height; y++) {
int mbs_per_slice = ctx->mbs_per_slice;
for (x = mb = 0; x < ctx->mb_width; x += mbs_per_slice, mb++) {
q = ctx->force_quant ? ctx->force_quant
: ctx->slice_q[mb + y * ctx->slices_width];
while (ctx->mb_width - x < mbs_per_slice)
mbs_per_slice >>= 1;
bytestream_put_byte(&buf, slice_hdr_size << 3);
slice_hdr = buf;
buf += slice_hdr_size - 1;
init_put_bits(&pb, buf, (pkt_size - (buf - orig_buf)) * 8);
ret = encode_slice(avctx, pic, &pb, sizes, x, y, q,
mbs_per_slice);
if (ret < 0)
return ret;
bytestream_put_byte(&slice_hdr, q);
slice_size = slice_hdr_size + sizes[ctx->num_planes - 1];
for (i = 0; i < ctx->num_planes - 1; i++) {
bytestream_put_be16(&slice_hdr, sizes[i]);
slice_size += sizes[i];
}
bytestream_put_be16(&slice_sizes, slice_size);
buf += slice_size - slice_hdr_size;
}
}
if (ctx->pictures_per_frame == 1)
picture_size = buf - picture_size_pos - 6;
else
picture_size = buf - picture_size_pos + 1;
bytestream_put_be32(&picture_size_pos, picture_size);
}
orig_buf -= 8;
frame_size = buf - orig_buf;
bytestream_put_be32(&orig_buf, frame_size);
pkt->size = frame_size;
pkt->flags |= AV_PKT_FLAG_KEY;
*got_packet = 1;
return 0;
}
| true | FFmpeg | 45ce880a9b3e50cfa088f111dffaf8685bd7bc6b | static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
const AVFrame *pic, int *got_packet)
{
ProresContext *ctx = avctx->priv_data;
uint8_t *orig_buf, *buf, *slice_hdr, *slice_sizes, *tmp;
uint8_t *picture_size_pos;
PutBitContext pb;
int x, y, i, mb, q = 0;
int sizes[4] = { 0 };
int slice_hdr_size = 2 + 2 * (ctx->num_planes - 1);
int frame_size, picture_size, slice_size;
int pkt_size, ret;
uint8_t frame_flags;
*avctx->coded_frame = *pic;
avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;
avctx->coded_frame->key_frame = 1;
pkt_size = ctx->frame_size_upper_bound;
if ((ret = ff_alloc_packet(pkt, pkt_size + FF_MIN_BUFFER_SIZE)) < 0) {
av_log(avctx, AV_LOG_ERROR, "Error getting output packet.\n");
return ret;
}
orig_buf = pkt->data;
orig_buf += 4;
bytestream_put_be32 (&orig_buf, FRAME_ID);
buf = orig_buf;
tmp = buf;
buf += 2; size will be stored here
bytestream_put_be16 (&buf, 0);
bytestream_put_buffer(&buf, ctx->vendor, 4);
bytestream_put_be16 (&buf, avctx->width);
bytestream_put_be16 (&buf, avctx->height);
frame_flags = ctx->chroma_factor << 6;
if (avctx->flags & CODEC_FLAG_INTERLACED_DCT)
frame_flags |= pic->top_field_first ? 0x04 : 0x08;
bytestream_put_byte (&buf, frame_flags);
bytestream_put_byte (&buf, 0);
bytestream_put_byte (&buf, avctx->color_primaries);
bytestream_put_byte (&buf, avctx->color_trc);
bytestream_put_byte (&buf, avctx->colorspace);
bytestream_put_byte (&buf, 0x40 | (ctx->alpha_bits >> 3));
bytestream_put_byte (&buf, 0);
if (ctx->quant_sel != QUANT_MAT_DEFAULT) {
bytestream_put_byte (&buf, 0x03);
for (i = 0; i < 64; i++)
bytestream_put_byte(&buf, ctx->quant_mat[i]);
for (i = 0; i < 64; i++)
bytestream_put_byte(&buf, ctx->quant_mat[i]);
} else {
bytestream_put_byte (&buf, 0x00);
}
bytestream_put_be16 (&tmp, buf - orig_buf);
for (ctx->cur_picture_idx = 0;
ctx->cur_picture_idx < ctx->pictures_per_frame;
ctx->cur_picture_idx++) {
picture_size_pos = buf + 1;
bytestream_put_byte (&buf, 0x40); size (in bits)
buf += 4;
bytestream_put_be16 (&buf, ctx->slices_per_picture);
bytestream_put_byte (&buf, av_log2(ctx->mbs_per_slice) << 4);
slice_sizes = buf;
buf += ctx->slices_per_picture * 2;
if (!ctx->force_quant) {
ret = avctx->execute2(avctx, find_quant_thread, NULL, NULL,
ctx->mb_height);
if (ret)
return ret;
}
for (y = 0; y < ctx->mb_height; y++) {
int mbs_per_slice = ctx->mbs_per_slice;
for (x = mb = 0; x < ctx->mb_width; x += mbs_per_slice, mb++) {
q = ctx->force_quant ? ctx->force_quant
: ctx->slice_q[mb + y * ctx->slices_width];
while (ctx->mb_width - x < mbs_per_slice)
mbs_per_slice >>= 1;
bytestream_put_byte(&buf, slice_hdr_size << 3);
slice_hdr = buf;
buf += slice_hdr_size - 1;
init_put_bits(&pb, buf, (pkt_size - (buf - orig_buf)) * 8);
ret = encode_slice(avctx, pic, &pb, sizes, x, y, q,
mbs_per_slice);
if (ret < 0)
return ret;
bytestream_put_byte(&slice_hdr, q);
slice_size = slice_hdr_size + sizes[ctx->num_planes - 1];
for (i = 0; i < ctx->num_planes - 1; i++) {
bytestream_put_be16(&slice_hdr, sizes[i]);
slice_size += sizes[i];
}
bytestream_put_be16(&slice_sizes, slice_size);
buf += slice_size - slice_hdr_size;
}
}
if (ctx->pictures_per_frame == 1)
picture_size = buf - picture_size_pos - 6;
else
picture_size = buf - picture_size_pos + 1;
bytestream_put_be32(&picture_size_pos, picture_size);
}
orig_buf -= 8;
frame_size = buf - orig_buf;
bytestream_put_be32(&orig_buf, frame_size);
pkt->size = frame_size;
pkt->flags |= AV_PKT_FLAG_KEY;
*got_packet = 1;
return 0;
}
| {
"code": [
" int pkt_size, ret;"
],
"line_no": [
23
]
} | static int FUNC_0(AVCodecContext *VAR_0, AVPacket *VAR_1,
const AVFrame *VAR_2, int *VAR_3)
{
ProresContext *ctx = VAR_0->priv_data;
uint8_t *orig_buf, *buf, *slice_hdr, *slice_sizes, *tmp;
uint8_t *picture_size_pos;
PutBitContext pb;
int VAR_4, VAR_5, VAR_6, VAR_7, VAR_8 = 0;
int VAR_9[4] = { 0 };
int VAR_10 = 2 + 2 * (ctx->num_planes - 1);
int VAR_11, VAR_12, VAR_13;
int VAR_14, VAR_15;
uint8_t frame_flags;
*VAR_0->coded_frame = *VAR_2;
VAR_0->coded_frame->pict_type = AV_PICTURE_TYPE_I;
VAR_0->coded_frame->key_frame = 1;
VAR_14 = ctx->frame_size_upper_bound;
if ((VAR_15 = ff_alloc_packet(VAR_1, VAR_14 + FF_MIN_BUFFER_SIZE)) < 0) {
av_log(VAR_0, AV_LOG_ERROR, "Error getting output packet.\n");
return VAR_15;
}
orig_buf = VAR_1->data;
orig_buf += 4;
bytestream_put_be32 (&orig_buf, FRAME_ID);
buf = orig_buf;
tmp = buf;
buf += 2; size will be stored here
bytestream_put_be16 (&buf, 0);
bytestream_put_buffer(&buf, ctx->vendor, 4);
bytestream_put_be16 (&buf, VAR_0->width);
bytestream_put_be16 (&buf, VAR_0->height);
frame_flags = ctx->chroma_factor << 6;
if (VAR_0->flags & CODEC_FLAG_INTERLACED_DCT)
frame_flags |= VAR_2->top_field_first ? 0x04 : 0x08;
bytestream_put_byte (&buf, frame_flags);
bytestream_put_byte (&buf, 0);
bytestream_put_byte (&buf, VAR_0->color_primaries);
bytestream_put_byte (&buf, VAR_0->color_trc);
bytestream_put_byte (&buf, VAR_0->colorspace);
bytestream_put_byte (&buf, 0x40 | (ctx->alpha_bits >> 3));
bytestream_put_byte (&buf, 0);
if (ctx->quant_sel != QUANT_MAT_DEFAULT) {
bytestream_put_byte (&buf, 0x03);
for (VAR_6 = 0; VAR_6 < 64; VAR_6++)
bytestream_put_byte(&buf, ctx->quant_mat[VAR_6]);
for (VAR_6 = 0; VAR_6 < 64; VAR_6++)
bytestream_put_byte(&buf, ctx->quant_mat[VAR_6]);
} else {
bytestream_put_byte (&buf, 0x00);
}
bytestream_put_be16 (&tmp, buf - orig_buf);
for (ctx->cur_picture_idx = 0;
ctx->cur_picture_idx < ctx->pictures_per_frame;
ctx->cur_picture_idx++) {
picture_size_pos = buf + 1;
bytestream_put_byte (&buf, 0x40); size (in bits)
buf += 4;
bytestream_put_be16 (&buf, ctx->slices_per_picture);
bytestream_put_byte (&buf, av_log2(ctx->mbs_per_slice) << 4);
slice_sizes = buf;
buf += ctx->slices_per_picture * 2;
if (!ctx->force_quant) {
VAR_15 = VAR_0->execute2(VAR_0, find_quant_thread, NULL, NULL,
ctx->mb_height);
if (VAR_15)
return VAR_15;
}
for (VAR_5 = 0; VAR_5 < ctx->mb_height; VAR_5++) {
int mbs_per_slice = ctx->mbs_per_slice;
for (VAR_4 = VAR_7 = 0; VAR_4 < ctx->mb_width; VAR_4 += mbs_per_slice, VAR_7++) {
VAR_8 = ctx->force_quant ? ctx->force_quant
: ctx->slice_q[VAR_7 + VAR_5 * ctx->slices_width];
while (ctx->mb_width - VAR_4 < mbs_per_slice)
mbs_per_slice >>= 1;
bytestream_put_byte(&buf, VAR_10 << 3);
slice_hdr = buf;
buf += VAR_10 - 1;
init_put_bits(&pb, buf, (VAR_14 - (buf - orig_buf)) * 8);
VAR_15 = encode_slice(VAR_0, VAR_2, &pb, VAR_9, VAR_4, VAR_5, VAR_8,
mbs_per_slice);
if (VAR_15 < 0)
return VAR_15;
bytestream_put_byte(&slice_hdr, VAR_8);
VAR_13 = VAR_10 + VAR_9[ctx->num_planes - 1];
for (VAR_6 = 0; VAR_6 < ctx->num_planes - 1; VAR_6++) {
bytestream_put_be16(&slice_hdr, VAR_9[VAR_6]);
VAR_13 += VAR_9[VAR_6];
}
bytestream_put_be16(&slice_sizes, VAR_13);
buf += VAR_13 - VAR_10;
}
}
if (ctx->pictures_per_frame == 1)
VAR_12 = buf - picture_size_pos - 6;
else
VAR_12 = buf - picture_size_pos + 1;
bytestream_put_be32(&picture_size_pos, VAR_12);
}
orig_buf -= 8;
VAR_11 = buf - orig_buf;
bytestream_put_be32(&orig_buf, VAR_11);
VAR_1->size = VAR_11;
VAR_1->flags |= AV_PKT_FLAG_KEY;
*VAR_3 = 1;
return 0;
}
| [
"static int FUNC_0(AVCodecContext *VAR_0, AVPacket *VAR_1,\nconst AVFrame *VAR_2, int *VAR_3)\n{",
"ProresContext *ctx = VAR_0->priv_data;",
"uint8_t *orig_buf, *buf, *slice_hdr, *slice_sizes, *tmp;",
"uint8_t *picture_size_pos;",
"PutBitContext pb;",
"int VAR_4, VAR_5, VAR_6, VAR_7, VAR_8 = 0;",
"int VAR_9[4] = { 0 };",
"int VAR_10 = 2 + 2 * (ctx->num_planes - 1);",
"int VAR_11, VAR_12, VAR_13;",
"int VAR_14, VAR_15;",
"uint8_t frame_flags;",
"*VAR_0->coded_frame = *VAR_2;",
"VAR_0->coded_frame->pict_type = AV_PICTURE_TYPE_I;",
"VAR_0->coded_frame->key_frame = 1;",
"VAR_14 = ctx->frame_size_upper_bound;",
"if ((VAR_15 = ff_alloc_packet(VAR_1, VAR_14 + FF_MIN_BUFFER_SIZE)) < 0) {",
"av_log(VAR_0, AV_LOG_ERROR, \"Error getting output packet.\\n\");",
"return VAR_15;",
"}",
"orig_buf = VAR_1->data;",
"orig_buf += 4;",
"bytestream_put_be32 (&orig_buf, FRAME_ID);",
"buf = orig_buf;",
"tmp = buf;",
"buf += 2; size will be stored here",
"bytestream_put_be16 (&buf, 0);",
"bytestream_put_buffer(&buf, ctx->vendor, 4);",
"bytestream_put_be16 (&buf, VAR_0->width);",
"bytestream_put_be16 (&buf, VAR_0->height);",
"frame_flags = ctx->chroma_factor << 6;",
"if (VAR_0->flags & CODEC_FLAG_INTERLACED_DCT)\nframe_flags |= VAR_2->top_field_first ? 0x04 : 0x08;",
"bytestream_put_byte (&buf, frame_flags);",
"bytestream_put_byte (&buf, 0);",
"bytestream_put_byte (&buf, VAR_0->color_primaries);",
"bytestream_put_byte (&buf, VAR_0->color_trc);",
"bytestream_put_byte (&buf, VAR_0->colorspace);",
"bytestream_put_byte (&buf, 0x40 | (ctx->alpha_bits >> 3));",
"bytestream_put_byte (&buf, 0);",
"if (ctx->quant_sel != QUANT_MAT_DEFAULT) {",
"bytestream_put_byte (&buf, 0x03);",
"for (VAR_6 = 0; VAR_6 < 64; VAR_6++)",
"bytestream_put_byte(&buf, ctx->quant_mat[VAR_6]);",
"for (VAR_6 = 0; VAR_6 < 64; VAR_6++)",
"bytestream_put_byte(&buf, ctx->quant_mat[VAR_6]);",
"} else {",
"bytestream_put_byte (&buf, 0x00);",
"}",
"bytestream_put_be16 (&tmp, buf - orig_buf);",
"for (ctx->cur_picture_idx = 0;",
"ctx->cur_picture_idx < ctx->pictures_per_frame;",
"ctx->cur_picture_idx++) {",
"picture_size_pos = buf + 1;",
"bytestream_put_byte (&buf, 0x40); size (in bits)",
"buf += 4;",
"bytestream_put_be16 (&buf, ctx->slices_per_picture);",
"bytestream_put_byte (&buf, av_log2(ctx->mbs_per_slice) << 4);",
"slice_sizes = buf;",
"buf += ctx->slices_per_picture * 2;",
"if (!ctx->force_quant) {",
"VAR_15 = VAR_0->execute2(VAR_0, find_quant_thread, NULL, NULL,\nctx->mb_height);",
"if (VAR_15)\nreturn VAR_15;",
"}",
"for (VAR_5 = 0; VAR_5 < ctx->mb_height; VAR_5++) {",
"int mbs_per_slice = ctx->mbs_per_slice;",
"for (VAR_4 = VAR_7 = 0; VAR_4 < ctx->mb_width; VAR_4 += mbs_per_slice, VAR_7++) {",
"VAR_8 = ctx->force_quant ? ctx->force_quant\n: ctx->slice_q[VAR_7 + VAR_5 * ctx->slices_width];",
"while (ctx->mb_width - VAR_4 < mbs_per_slice)\nmbs_per_slice >>= 1;",
"bytestream_put_byte(&buf, VAR_10 << 3);",
"slice_hdr = buf;",
"buf += VAR_10 - 1;",
"init_put_bits(&pb, buf, (VAR_14 - (buf - orig_buf)) * 8);",
"VAR_15 = encode_slice(VAR_0, VAR_2, &pb, VAR_9, VAR_4, VAR_5, VAR_8,\nmbs_per_slice);",
"if (VAR_15 < 0)\nreturn VAR_15;",
"bytestream_put_byte(&slice_hdr, VAR_8);",
"VAR_13 = VAR_10 + VAR_9[ctx->num_planes - 1];",
"for (VAR_6 = 0; VAR_6 < ctx->num_planes - 1; VAR_6++) {",
"bytestream_put_be16(&slice_hdr, VAR_9[VAR_6]);",
"VAR_13 += VAR_9[VAR_6];",
"}",
"bytestream_put_be16(&slice_sizes, VAR_13);",
"buf += VAR_13 - VAR_10;",
"}",
"}",
"if (ctx->pictures_per_frame == 1)\nVAR_12 = buf - picture_size_pos - 6;",
"else\nVAR_12 = buf - picture_size_pos + 1;",
"bytestream_put_be32(&picture_size_pos, VAR_12);",
"}",
"orig_buf -= 8;",
"VAR_11 = buf - orig_buf;",
"bytestream_put_be32(&orig_buf, VAR_11);",
"VAR_1->size = VAR_11;",
"VAR_1->flags |= AV_PKT_FLAG_KEY;",
"*VAR_3 = 1;",
"return 0;",
"}"
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
1,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | [
[
1,
3,
5
],
[
7
],
[
9
],
[
11
],
[
13
],
[
15
],
[
17
],
[
19
],
[
21
],
[
23
],
[
25
],
[
29
],
[
31
],
[
33
],
[
37
],
[
41
],
[
43
],
[
45
],
[
47
],
[
51
],
[
57
],
[
59
],
[
61
],
[
67
],
[
69
],
[
71
],
[
73
],
[
75
],
[
77
],
[
81
],
[
83,
85
],
[
87
],
[
91
],
[
93
],
[
95
],
[
97
],
[
99
],
[
101
],
[
103
],
[
105
],
[
109
],
[
111
],
[
115
],
[
117
],
[
119
],
[
121
],
[
123
],
[
125
],
[
129
],
[
131
],
[
133
],
[
137
],
[
139
],
[
141
],
[
143
],
[
145
],
[
151
],
[
153
],
[
159
],
[
161,
163
],
[
165,
167
],
[
169
],
[
173
],
[
175
],
[
177
],
[
179,
181
],
[
185,
187
],
[
191
],
[
193
],
[
195
],
[
197
],
[
199,
201
],
[
203,
205
],
[
209
],
[
211
],
[
213
],
[
215
],
[
217
],
[
219
],
[
221
],
[
223
],
[
225
],
[
227
],
[
231,
233
],
[
235,
237
],
[
239
],
[
241
],
[
245
],
[
247
],
[
249
],
[
253
],
[
255
],
[
257
],
[
261
],
[
263
]
] |
21,469 | void ff_lag_rac_init(lag_rac *l, GetBitContext *gb, int length)
{
int i, j;
/* According to reference decoder "1st byte is garbage",
* however, it gets skipped by the call to align_get_bits()
*/
align_get_bits(gb);
l->bytestream_start =
l->bytestream = gb->buffer + get_bits_count(gb) / 8;
l->bytestream_end = l->bytestream_start + length;
l->range = 0x80;
l->low = *l->bytestream >> 1;
l->hash_shift = FFMAX(l->scale - 8, 0);
for (i = j = 0; i < 256; i++) {
unsigned r = i << l->hash_shift;
while (l->prob[j + 1] <= r)
j++;
l->range_hash[i] = j;
}
/* Add conversion factor to hash_shift so we don't have to in lag_get_rac. */
l->hash_shift += 23;
}
| true | FFmpeg | 0a82f5275f719e6e369a807720a2c3603aa0ddd9 | void ff_lag_rac_init(lag_rac *l, GetBitContext *gb, int length)
{
int i, j;
align_get_bits(gb);
l->bytestream_start =
l->bytestream = gb->buffer + get_bits_count(gb) / 8;
l->bytestream_end = l->bytestream_start + length;
l->range = 0x80;
l->low = *l->bytestream >> 1;
l->hash_shift = FFMAX(l->scale - 8, 0);
for (i = j = 0; i < 256; i++) {
unsigned r = i << l->hash_shift;
while (l->prob[j + 1] <= r)
j++;
l->range_hash[i] = j;
}
l->hash_shift += 23;
}
| {
"code": [
" int i, j;",
" l->bytestream_end = l->bytestream_start + length;"
],
"line_no": [
5,
21
]
} | void FUNC_0(lag_rac *VAR_0, GetBitContext *VAR_1, int VAR_2)
{
int VAR_3, VAR_4;
align_get_bits(VAR_1);
VAR_0->bytestream_start =
VAR_0->bytestream = VAR_1->buffer + get_bits_count(VAR_1) / 8;
VAR_0->bytestream_end = VAR_0->bytestream_start + VAR_2;
VAR_0->range = 0x80;
VAR_0->low = *VAR_0->bytestream >> 1;
VAR_0->hash_shift = FFMAX(VAR_0->scale - 8, 0);
for (VAR_3 = VAR_4 = 0; VAR_3 < 256; VAR_3++) {
unsigned VAR_5 = VAR_3 << VAR_0->hash_shift;
while (VAR_0->prob[VAR_4 + 1] <= VAR_5)
VAR_4++;
VAR_0->range_hash[VAR_3] = VAR_4;
}
VAR_0->hash_shift += 23;
}
| [
"void FUNC_0(lag_rac *VAR_0, GetBitContext *VAR_1, int VAR_2)\n{",
"int VAR_3, VAR_4;",
"align_get_bits(VAR_1);",
"VAR_0->bytestream_start =\nVAR_0->bytestream = VAR_1->buffer + get_bits_count(VAR_1) / 8;",
"VAR_0->bytestream_end = VAR_0->bytestream_start + VAR_2;",
"VAR_0->range = 0x80;",
"VAR_0->low = *VAR_0->bytestream >> 1;",
"VAR_0->hash_shift = FFMAX(VAR_0->scale - 8, 0);",
"for (VAR_3 = VAR_4 = 0; VAR_3 < 256; VAR_3++) {",
"unsigned VAR_5 = VAR_3 << VAR_0->hash_shift;",
"while (VAR_0->prob[VAR_4 + 1] <= VAR_5)\nVAR_4++;",
"VAR_0->range_hash[VAR_3] = VAR_4;",
"}",
"VAR_0->hash_shift += 23;",
"}"
] | [
0,
1,
0,
0,
1,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | [
[
1,
3
],
[
5
],
[
15
],
[
17,
19
],
[
21
],
[
25
],
[
27
],
[
29
],
[
33
],
[
35
],
[
37,
39
],
[
41
],
[
43
],
[
49
],
[
51
]
] |
21,471 | void vmstate_unregister(DeviceState *dev, const VMStateDescription *vmsd,
void *opaque)
{
SaveStateEntry *se, *new_se;
QTAILQ_FOREACH_SAFE(se, &savevm_handlers, entry, new_se) {
if (se->vmsd == vmsd && se->opaque == opaque) {
QTAILQ_REMOVE(&savevm_handlers, se, entry);
qemu_free(se);
| true | qemu | 69e58af92cf90a1a0551c73880928afa6753fa5f | void vmstate_unregister(DeviceState *dev, const VMStateDescription *vmsd,
void *opaque)
{
SaveStateEntry *se, *new_se;
QTAILQ_FOREACH_SAFE(se, &savevm_handlers, entry, new_se) {
if (se->vmsd == vmsd && se->opaque == opaque) {
QTAILQ_REMOVE(&savevm_handlers, se, entry);
qemu_free(se);
| {
"code": [],
"line_no": []
} | void FUNC_0(DeviceState *VAR_0, const VMStateDescription *VAR_1,
void *VAR_2)
{
SaveStateEntry *se, *new_se;
QTAILQ_FOREACH_SAFE(se, &savevm_handlers, entry, new_se) {
if (se->VAR_1 == VAR_1 && se->VAR_2 == VAR_2) {
QTAILQ_REMOVE(&savevm_handlers, se, entry);
qemu_free(se);
| [
"void FUNC_0(DeviceState *VAR_0, const VMStateDescription *VAR_1,\nvoid *VAR_2)\n{",
"SaveStateEntry *se, *new_se;",
"QTAILQ_FOREACH_SAFE(se, &savevm_handlers, entry, new_se) {",
"if (se->VAR_1 == VAR_1 && se->VAR_2 == VAR_2) {",
"QTAILQ_REMOVE(&savevm_handlers, se, entry);",
"qemu_free(se);"
] | [
0,
0,
0,
0,
0,
0
] | [
[
1,
3,
5
],
[
7
],
[
11
],
[
13
],
[
15
],
[
20
]
] |
21,472 | void iothread_stop_all(void)
{
Object *container = object_get_objects_root();
BlockDriverState *bs;
BdrvNextIterator it;
for (bs = bdrv_first(&it); bs; bs = bdrv_next(&it)) {
AioContext *ctx = bdrv_get_aio_context(bs);
if (ctx == qemu_get_aio_context()) {
continue;
}
aio_context_acquire(ctx);
bdrv_set_aio_context(bs, qemu_get_aio_context());
aio_context_release(ctx);
}
object_child_foreach(container, iothread_stop, NULL);
}
| true | qemu | 82d90705fe203cc6e150c10bd61f0dbe6979e8f4 | void iothread_stop_all(void)
{
Object *container = object_get_objects_root();
BlockDriverState *bs;
BdrvNextIterator it;
for (bs = bdrv_first(&it); bs; bs = bdrv_next(&it)) {
AioContext *ctx = bdrv_get_aio_context(bs);
if (ctx == qemu_get_aio_context()) {
continue;
}
aio_context_acquire(ctx);
bdrv_set_aio_context(bs, qemu_get_aio_context());
aio_context_release(ctx);
}
object_child_foreach(container, iothread_stop, NULL);
}
| {
"code": [
" object_child_foreach(container, iothread_stop, NULL);"
],
"line_no": [
33
]
} | void FUNC_0(void)
{
Object *container = object_get_objects_root();
BlockDriverState *bs;
BdrvNextIterator it;
for (bs = bdrv_first(&it); bs; bs = bdrv_next(&it)) {
AioContext *ctx = bdrv_get_aio_context(bs);
if (ctx == qemu_get_aio_context()) {
continue;
}
aio_context_acquire(ctx);
bdrv_set_aio_context(bs, qemu_get_aio_context());
aio_context_release(ctx);
}
object_child_foreach(container, iothread_stop, NULL);
}
| [
"void FUNC_0(void)\n{",
"Object *container = object_get_objects_root();",
"BlockDriverState *bs;",
"BdrvNextIterator it;",
"for (bs = bdrv_first(&it); bs; bs = bdrv_next(&it)) {",
"AioContext *ctx = bdrv_get_aio_context(bs);",
"if (ctx == qemu_get_aio_context()) {",
"continue;",
"}",
"aio_context_acquire(ctx);",
"bdrv_set_aio_context(bs, qemu_get_aio_context());",
"aio_context_release(ctx);",
"}",
"object_child_foreach(container, iothread_stop, NULL);",
"}"
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
1,
0
] | [
[
1,
3
],
[
5
],
[
7
],
[
9
],
[
13
],
[
15
],
[
17
],
[
19
],
[
21
],
[
23
],
[
25
],
[
27
],
[
29
],
[
33
],
[
35
]
] |
21,474 | int apic_get_interrupt(DeviceState *d)
{
APICState *s = DO_UPCAST(APICState, busdev.qdev, d);
int intno;
/* if the APIC is installed or enabled, we let the 8259 handle the
IRQs */
if (!s)
return -1;
if (!(s->spurious_vec & APIC_SV_ENABLE))
return -1;
/* XXX: spurious IRQ handling */
intno = get_highest_priority_int(s->irr);
if (intno < 0)
return -1;
if (s->tpr && intno <= s->tpr)
return s->spurious_vec & 0xff;
reset_bit(s->irr, intno);
set_bit(s->isr, intno);
apic_update_irq(s);
return intno;
}
| false | qemu | 0fbfbb59a9766247be20023b17eb7872e7b29323 | int apic_get_interrupt(DeviceState *d)
{
APICState *s = DO_UPCAST(APICState, busdev.qdev, d);
int intno;
if (!s)
return -1;
if (!(s->spurious_vec & APIC_SV_ENABLE))
return -1;
intno = get_highest_priority_int(s->irr);
if (intno < 0)
return -1;
if (s->tpr && intno <= s->tpr)
return s->spurious_vec & 0xff;
reset_bit(s->irr, intno);
set_bit(s->isr, intno);
apic_update_irq(s);
return intno;
}
| {
"code": [],
"line_no": []
} | int FUNC_0(DeviceState *VAR_0)
{
APICState *s = DO_UPCAST(APICState, busdev.qdev, VAR_0);
int VAR_1;
if (!s)
return -1;
if (!(s->spurious_vec & APIC_SV_ENABLE))
return -1;
VAR_1 = get_highest_priority_int(s->irr);
if (VAR_1 < 0)
return -1;
if (s->tpr && VAR_1 <= s->tpr)
return s->spurious_vec & 0xff;
reset_bit(s->irr, VAR_1);
set_bit(s->isr, VAR_1);
apic_update_irq(s);
return VAR_1;
}
| [
"int FUNC_0(DeviceState *VAR_0)\n{",
"APICState *s = DO_UPCAST(APICState, busdev.qdev, VAR_0);",
"int VAR_1;",
"if (!s)\nreturn -1;",
"if (!(s->spurious_vec & APIC_SV_ENABLE))\nreturn -1;",
"VAR_1 = get_highest_priority_int(s->irr);",
"if (VAR_1 < 0)\nreturn -1;",
"if (s->tpr && VAR_1 <= s->tpr)\nreturn s->spurious_vec & 0xff;",
"reset_bit(s->irr, VAR_1);",
"set_bit(s->isr, VAR_1);",
"apic_update_irq(s);",
"return VAR_1;",
"}"
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | [
[
1,
3
],
[
5
],
[
7
],
[
15,
17
],
[
19,
21
],
[
27
],
[
29,
31
],
[
33,
35
],
[
37
],
[
39
],
[
41
],
[
43
],
[
45
]
] |
21,475 | static inline void decode_residual_inter(AVSContext *h) {
int block;
/* get coded block pattern */
h->cbp = cbp_tab[get_ue_golomb(&h->s.gb)][1];
/* get quantizer */
if(h->cbp && !h->qp_fixed)
h->qp += get_se_golomb(&h->s.gb);
for(block=0;block<4;block++)
if(h->cbp & (1<<block))
decode_residual_block(h,&h->s.gb,inter_2dvlc,0,h->qp,
h->cy + h->luma_scan[block], h->l_stride);
decode_residual_chroma(h);
}
| false | FFmpeg | 5ca0106879079d7f82bb9335638674292794f74c | static inline void decode_residual_inter(AVSContext *h) {
int block;
h->cbp = cbp_tab[get_ue_golomb(&h->s.gb)][1];
if(h->cbp && !h->qp_fixed)
h->qp += get_se_golomb(&h->s.gb);
for(block=0;block<4;block++)
if(h->cbp & (1<<block))
decode_residual_block(h,&h->s.gb,inter_2dvlc,0,h->qp,
h->cy + h->luma_scan[block], h->l_stride);
decode_residual_chroma(h);
}
| {
"code": [],
"line_no": []
} | static inline void FUNC_0(AVSContext *VAR_0) {
int VAR_1;
VAR_0->cbp = cbp_tab[get_ue_golomb(&VAR_0->s.gb)][1];
if(VAR_0->cbp && !VAR_0->qp_fixed)
VAR_0->qp += get_se_golomb(&VAR_0->s.gb);
for(VAR_1=0;VAR_1<4;VAR_1++)
if(VAR_0->cbp & (1<<VAR_1))
decode_residual_block(VAR_0,&VAR_0->s.gb,inter_2dvlc,0,VAR_0->qp,
VAR_0->cy + VAR_0->luma_scan[VAR_1], VAR_0->l_stride);
decode_residual_chroma(VAR_0);
}
| [
"static inline void FUNC_0(AVSContext *VAR_0) {",
"int VAR_1;",
"VAR_0->cbp = cbp_tab[get_ue_golomb(&VAR_0->s.gb)][1];",
"if(VAR_0->cbp && !VAR_0->qp_fixed)\nVAR_0->qp += get_se_golomb(&VAR_0->s.gb);",
"for(VAR_1=0;VAR_1<4;VAR_1++)",
"if(VAR_0->cbp & (1<<VAR_1))\ndecode_residual_block(VAR_0,&VAR_0->s.gb,inter_2dvlc,0,VAR_0->qp,\nVAR_0->cy + VAR_0->luma_scan[VAR_1], VAR_0->l_stride);",
"decode_residual_chroma(VAR_0);",
"}"
] | [
0,
0,
0,
0,
0,
0,
0,
0
] | [
[
1
],
[
3
],
[
9
],
[
13,
15
],
[
17
],
[
19,
21,
23
],
[
25
],
[
27
]
] |
21,476 | static void pfpu_write(void *opaque, target_phys_addr_t addr, uint64_t value,
unsigned size)
{
MilkymistPFPUState *s = opaque;
trace_milkymist_pfpu_memory_write(addr, value);
addr >>= 2;
switch (addr) {
case R_CTL:
if (value & CTL_START_BUSY) {
pfpu_start(s);
}
break;
case R_MESHBASE:
case R_HMESHLAST:
case R_VMESHLAST:
case R_CODEPAGE:
case R_VERTICES:
case R_COLLISIONS:
case R_STRAYWRITES:
case R_LASTDMA:
case R_PC:
case R_DREGBASE:
case R_CODEBASE:
s->regs[addr] = value;
break;
case GPR_BEGIN ... GPR_END:
s->gp_regs[addr - GPR_BEGIN] = value;
break;
case MICROCODE_BEGIN ... MICROCODE_END:
s->microcode[get_microcode_address(s, addr)] = value;
break;
default:
error_report("milkymist_pfpu: write access to unknown register 0x"
TARGET_FMT_plx, addr << 2);
break;
}
}
| false | qemu | a8170e5e97ad17ca169c64ba87ae2f53850dab4c | static void pfpu_write(void *opaque, target_phys_addr_t addr, uint64_t value,
unsigned size)
{
MilkymistPFPUState *s = opaque;
trace_milkymist_pfpu_memory_write(addr, value);
addr >>= 2;
switch (addr) {
case R_CTL:
if (value & CTL_START_BUSY) {
pfpu_start(s);
}
break;
case R_MESHBASE:
case R_HMESHLAST:
case R_VMESHLAST:
case R_CODEPAGE:
case R_VERTICES:
case R_COLLISIONS:
case R_STRAYWRITES:
case R_LASTDMA:
case R_PC:
case R_DREGBASE:
case R_CODEBASE:
s->regs[addr] = value;
break;
case GPR_BEGIN ... GPR_END:
s->gp_regs[addr - GPR_BEGIN] = value;
break;
case MICROCODE_BEGIN ... MICROCODE_END:
s->microcode[get_microcode_address(s, addr)] = value;
break;
default:
error_report("milkymist_pfpu: write access to unknown register 0x"
TARGET_FMT_plx, addr << 2);
break;
}
}
| {
"code": [],
"line_no": []
} | static void FUNC_0(void *VAR_0, target_phys_addr_t VAR_1, uint64_t VAR_2,
unsigned VAR_3)
{
MilkymistPFPUState *s = VAR_0;
trace_milkymist_pfpu_memory_write(VAR_1, VAR_2);
VAR_1 >>= 2;
switch (VAR_1) {
case R_CTL:
if (VAR_2 & CTL_START_BUSY) {
pfpu_start(s);
}
break;
case R_MESHBASE:
case R_HMESHLAST:
case R_VMESHLAST:
case R_CODEPAGE:
case R_VERTICES:
case R_COLLISIONS:
case R_STRAYWRITES:
case R_LASTDMA:
case R_PC:
case R_DREGBASE:
case R_CODEBASE:
s->regs[VAR_1] = VAR_2;
break;
case GPR_BEGIN ... GPR_END:
s->gp_regs[VAR_1 - GPR_BEGIN] = VAR_2;
break;
case MICROCODE_BEGIN ... MICROCODE_END:
s->microcode[get_microcode_address(s, VAR_1)] = VAR_2;
break;
default:
error_report("milkymist_pfpu: write access to unknown register 0x"
TARGET_FMT_plx, VAR_1 << 2);
break;
}
}
| [
"static void FUNC_0(void *VAR_0, target_phys_addr_t VAR_1, uint64_t VAR_2,\nunsigned VAR_3)\n{",
"MilkymistPFPUState *s = VAR_0;",
"trace_milkymist_pfpu_memory_write(VAR_1, VAR_2);",
"VAR_1 >>= 2;",
"switch (VAR_1) {",
"case R_CTL:\nif (VAR_2 & CTL_START_BUSY) {",
"pfpu_start(s);",
"}",
"break;",
"case R_MESHBASE:\ncase R_HMESHLAST:\ncase R_VMESHLAST:\ncase R_CODEPAGE:\ncase R_VERTICES:\ncase R_COLLISIONS:\ncase R_STRAYWRITES:\ncase R_LASTDMA:\ncase R_PC:\ncase R_DREGBASE:\ncase R_CODEBASE:\ns->regs[VAR_1] = VAR_2;",
"break;",
"case GPR_BEGIN ... GPR_END:\ns->gp_regs[VAR_1 - GPR_BEGIN] = VAR_2;",
"break;",
"case MICROCODE_BEGIN ... MICROCODE_END:\ns->microcode[get_microcode_address(s, VAR_1)] = VAR_2;",
"break;",
"default:\nerror_report(\"milkymist_pfpu: write access to unknown register 0x\"\nTARGET_FMT_plx, VAR_1 << 2);",
"break;",
"}",
"}"
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | [
[
1,
3,
5
],
[
7
],
[
11
],
[
15
],
[
17
],
[
19,
21
],
[
23
],
[
25
],
[
27
],
[
29,
31,
33,
35,
37,
39,
41,
43,
45,
47,
49,
51
],
[
53
],
[
55,
57
],
[
59
],
[
61,
63
],
[
65
],
[
69,
71,
73
],
[
75
],
[
77
],
[
79
]
] |
21,477 | uint32_t vfio_pci_read_config(PCIDevice *pdev, uint32_t addr, int len)
{
VFIOPCIDevice *vdev = DO_UPCAST(VFIOPCIDevice, pdev, pdev);
uint32_t emu_bits = 0, emu_val = 0, phys_val = 0, val;
memcpy(&emu_bits, vdev->emulated_config_bits + addr, len);
emu_bits = le32_to_cpu(emu_bits);
if (emu_bits) {
emu_val = pci_default_read_config(pdev, addr, len);
}
if (~emu_bits & (0xffffffffU >> (32 - len * 8))) {
ssize_t ret;
ret = pread(vdev->vbasedev.fd, &phys_val, len,
vdev->config_offset + addr);
if (ret != len) {
error_report("%s(%04x:%02x:%02x.%x, 0x%x, 0x%x) failed: %m",
__func__, vdev->host.domain, vdev->host.bus,
vdev->host.slot, vdev->host.function, addr, len);
return -errno;
}
phys_val = le32_to_cpu(phys_val);
}
val = (emu_val & emu_bits) | (phys_val & ~emu_bits);
trace_vfio_pci_read_config(vdev->vbasedev.name, addr, len, val);
return val;
}
| false | qemu | 7df9381b7aa56c897e344f3bfe43bf5848bbd3e0 | uint32_t vfio_pci_read_config(PCIDevice *pdev, uint32_t addr, int len)
{
VFIOPCIDevice *vdev = DO_UPCAST(VFIOPCIDevice, pdev, pdev);
uint32_t emu_bits = 0, emu_val = 0, phys_val = 0, val;
memcpy(&emu_bits, vdev->emulated_config_bits + addr, len);
emu_bits = le32_to_cpu(emu_bits);
if (emu_bits) {
emu_val = pci_default_read_config(pdev, addr, len);
}
if (~emu_bits & (0xffffffffU >> (32 - len * 8))) {
ssize_t ret;
ret = pread(vdev->vbasedev.fd, &phys_val, len,
vdev->config_offset + addr);
if (ret != len) {
error_report("%s(%04x:%02x:%02x.%x, 0x%x, 0x%x) failed: %m",
__func__, vdev->host.domain, vdev->host.bus,
vdev->host.slot, vdev->host.function, addr, len);
return -errno;
}
phys_val = le32_to_cpu(phys_val);
}
val = (emu_val & emu_bits) | (phys_val & ~emu_bits);
trace_vfio_pci_read_config(vdev->vbasedev.name, addr, len, val);
return val;
}
| {
"code": [],
"line_no": []
} | uint32_t FUNC_0(PCIDevice *pdev, uint32_t addr, int len)
{
VFIOPCIDevice *vdev = DO_UPCAST(VFIOPCIDevice, pdev, pdev);
uint32_t emu_bits = 0, emu_val = 0, phys_val = 0, val;
memcpy(&emu_bits, vdev->emulated_config_bits + addr, len);
emu_bits = le32_to_cpu(emu_bits);
if (emu_bits) {
emu_val = pci_default_read_config(pdev, addr, len);
}
if (~emu_bits & (0xffffffffU >> (32 - len * 8))) {
ssize_t ret;
ret = pread(vdev->vbasedev.fd, &phys_val, len,
vdev->config_offset + addr);
if (ret != len) {
error_report("%s(%04x:%02x:%02x.%x, 0x%x, 0x%x) failed: %m",
__func__, vdev->host.domain, vdev->host.bus,
vdev->host.slot, vdev->host.function, addr, len);
return -errno;
}
phys_val = le32_to_cpu(phys_val);
}
val = (emu_val & emu_bits) | (phys_val & ~emu_bits);
trace_vfio_pci_read_config(vdev->vbasedev.name, addr, len, val);
return val;
}
| [
"uint32_t FUNC_0(PCIDevice *pdev, uint32_t addr, int len)\n{",
"VFIOPCIDevice *vdev = DO_UPCAST(VFIOPCIDevice, pdev, pdev);",
"uint32_t emu_bits = 0, emu_val = 0, phys_val = 0, val;",
"memcpy(&emu_bits, vdev->emulated_config_bits + addr, len);",
"emu_bits = le32_to_cpu(emu_bits);",
"if (emu_bits) {",
"emu_val = pci_default_read_config(pdev, addr, len);",
"}",
"if (~emu_bits & (0xffffffffU >> (32 - len * 8))) {",
"ssize_t ret;",
"ret = pread(vdev->vbasedev.fd, &phys_val, len,\nvdev->config_offset + addr);",
"if (ret != len) {",
"error_report(\"%s(%04x:%02x:%02x.%x, 0x%x, 0x%x) failed: %m\",\n__func__, vdev->host.domain, vdev->host.bus,\nvdev->host.slot, vdev->host.function, addr, len);",
"return -errno;",
"}",
"phys_val = le32_to_cpu(phys_val);",
"}",
"val = (emu_val & emu_bits) | (phys_val & ~emu_bits);",
"trace_vfio_pci_read_config(vdev->vbasedev.name, addr, len, val);",
"return val;",
"}"
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | [
[
1,
3
],
[
5
],
[
7
],
[
11
],
[
13
],
[
17
],
[
19
],
[
21
],
[
25
],
[
27
],
[
31,
33
],
[
35
],
[
37,
39,
41
],
[
43
],
[
45
],
[
47
],
[
49
],
[
53
],
[
57
],
[
61
],
[
63
]
] |
21,478 | static void pci_device_reset(PCIDevice *dev)
{
int r;
dev->irq_state = 0;
pci_update_irq_status(dev);
/* Clear all writeable bits */
pci_word_test_and_clear_mask(dev->config + PCI_COMMAND,
pci_get_word(dev->wmask + PCI_COMMAND));
dev->config[PCI_CACHE_LINE_SIZE] = 0x0;
dev->config[PCI_INTERRUPT_LINE] = 0x0;
for (r = 0; r < PCI_NUM_REGIONS; ++r) {
PCIIORegion *region = &dev->io_regions[r];
if (!region->size) {
continue;
}
if (!(region->type & PCI_BASE_ADDRESS_SPACE_IO) &&
region->type & PCI_BASE_ADDRESS_MEM_TYPE_64) {
pci_set_quad(dev->config + pci_bar(dev, r), region->type);
} else {
pci_set_long(dev->config + pci_bar(dev, r), region->type);
}
}
pci_update_mappings(dev);
}
| false | qemu | f9aebe2ef52ff0dcb733999f57e00a7b430303c6 | static void pci_device_reset(PCIDevice *dev)
{
int r;
dev->irq_state = 0;
pci_update_irq_status(dev);
pci_word_test_and_clear_mask(dev->config + PCI_COMMAND,
pci_get_word(dev->wmask + PCI_COMMAND));
dev->config[PCI_CACHE_LINE_SIZE] = 0x0;
dev->config[PCI_INTERRUPT_LINE] = 0x0;
for (r = 0; r < PCI_NUM_REGIONS; ++r) {
PCIIORegion *region = &dev->io_regions[r];
if (!region->size) {
continue;
}
if (!(region->type & PCI_BASE_ADDRESS_SPACE_IO) &&
region->type & PCI_BASE_ADDRESS_MEM_TYPE_64) {
pci_set_quad(dev->config + pci_bar(dev, r), region->type);
} else {
pci_set_long(dev->config + pci_bar(dev, r), region->type);
}
}
pci_update_mappings(dev);
}
| {
"code": [],
"line_no": []
} | static void FUNC_0(PCIDevice *VAR_0)
{
int VAR_1;
VAR_0->irq_state = 0;
pci_update_irq_status(VAR_0);
pci_word_test_and_clear_mask(VAR_0->config + PCI_COMMAND,
pci_get_word(VAR_0->wmask + PCI_COMMAND));
VAR_0->config[PCI_CACHE_LINE_SIZE] = 0x0;
VAR_0->config[PCI_INTERRUPT_LINE] = 0x0;
for (VAR_1 = 0; VAR_1 < PCI_NUM_REGIONS; ++VAR_1) {
PCIIORegion *region = &VAR_0->io_regions[VAR_1];
if (!region->size) {
continue;
}
if (!(region->type & PCI_BASE_ADDRESS_SPACE_IO) &&
region->type & PCI_BASE_ADDRESS_MEM_TYPE_64) {
pci_set_quad(VAR_0->config + pci_bar(VAR_0, VAR_1), region->type);
} else {
pci_set_long(VAR_0->config + pci_bar(VAR_0, VAR_1), region->type);
}
}
pci_update_mappings(VAR_0);
}
| [
"static void FUNC_0(PCIDevice *VAR_0)\n{",
"int VAR_1;",
"VAR_0->irq_state = 0;",
"pci_update_irq_status(VAR_0);",
"pci_word_test_and_clear_mask(VAR_0->config + PCI_COMMAND,\npci_get_word(VAR_0->wmask + PCI_COMMAND));",
"VAR_0->config[PCI_CACHE_LINE_SIZE] = 0x0;",
"VAR_0->config[PCI_INTERRUPT_LINE] = 0x0;",
"for (VAR_1 = 0; VAR_1 < PCI_NUM_REGIONS; ++VAR_1) {",
"PCIIORegion *region = &VAR_0->io_regions[VAR_1];",
"if (!region->size) {",
"continue;",
"}",
"if (!(region->type & PCI_BASE_ADDRESS_SPACE_IO) &&\nregion->type & PCI_BASE_ADDRESS_MEM_TYPE_64) {",
"pci_set_quad(VAR_0->config + pci_bar(VAR_0, VAR_1), region->type);",
"} else {",
"pci_set_long(VAR_0->config + pci_bar(VAR_0, VAR_1), region->type);",
"}",
"}",
"pci_update_mappings(VAR_0);",
"}"
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | [
[
1,
3
],
[
5
],
[
9
],
[
11
],
[
15,
17
],
[
19
],
[
21
],
[
23
],
[
25
],
[
27
],
[
29
],
[
31
],
[
35,
37
],
[
39
],
[
41
],
[
43
],
[
45
],
[
47
],
[
49
],
[
51
]
] |
21,479 | static void xen_set_memory(struct MemoryListener *listener,
MemoryRegionSection *section,
bool add)
{
XenIOState *state = container_of(listener, XenIOState, memory_listener);
hwaddr start_addr = section->offset_within_address_space;
ram_addr_t size = int128_get64(section->size);
bool log_dirty = memory_region_is_logging(section->mr);
hvmmem_type_t mem_type;
if (section->mr == &ram_memory) {
return;
} else {
if (add) {
xen_map_memory_section(xen_xc, xen_domid, state->ioservid,
section);
} else {
xen_unmap_memory_section(xen_xc, xen_domid, state->ioservid,
section);
}
}
if (!memory_region_is_ram(section->mr)) {
return;
}
if (log_dirty != add) {
return;
}
trace_xen_client_set_memory(start_addr, size, log_dirty);
start_addr &= TARGET_PAGE_MASK;
size = TARGET_PAGE_ALIGN(size);
if (add) {
if (!memory_region_is_rom(section->mr)) {
xen_add_to_physmap(state, start_addr, size,
section->mr, section->offset_within_region);
} else {
mem_type = HVMMEM_ram_ro;
if (xc_hvm_set_mem_type(xen_xc, xen_domid, mem_type,
start_addr >> TARGET_PAGE_BITS,
size >> TARGET_PAGE_BITS)) {
DPRINTF("xc_hvm_set_mem_type error, addr: "TARGET_FMT_plx"\n",
start_addr);
}
}
} else {
if (xen_remove_from_physmap(state, start_addr, size) < 0) {
DPRINTF("physmapping does not exist at "TARGET_FMT_plx"\n", start_addr);
}
}
}
| false | qemu | 2d1a35bef0ed96b3f23535e459c552414ccdbafd | static void xen_set_memory(struct MemoryListener *listener,
MemoryRegionSection *section,
bool add)
{
XenIOState *state = container_of(listener, XenIOState, memory_listener);
hwaddr start_addr = section->offset_within_address_space;
ram_addr_t size = int128_get64(section->size);
bool log_dirty = memory_region_is_logging(section->mr);
hvmmem_type_t mem_type;
if (section->mr == &ram_memory) {
return;
} else {
if (add) {
xen_map_memory_section(xen_xc, xen_domid, state->ioservid,
section);
} else {
xen_unmap_memory_section(xen_xc, xen_domid, state->ioservid,
section);
}
}
if (!memory_region_is_ram(section->mr)) {
return;
}
if (log_dirty != add) {
return;
}
trace_xen_client_set_memory(start_addr, size, log_dirty);
start_addr &= TARGET_PAGE_MASK;
size = TARGET_PAGE_ALIGN(size);
if (add) {
if (!memory_region_is_rom(section->mr)) {
xen_add_to_physmap(state, start_addr, size,
section->mr, section->offset_within_region);
} else {
mem_type = HVMMEM_ram_ro;
if (xc_hvm_set_mem_type(xen_xc, xen_domid, mem_type,
start_addr >> TARGET_PAGE_BITS,
size >> TARGET_PAGE_BITS)) {
DPRINTF("xc_hvm_set_mem_type error, addr: "TARGET_FMT_plx"\n",
start_addr);
}
}
} else {
if (xen_remove_from_physmap(state, start_addr, size) < 0) {
DPRINTF("physmapping does not exist at "TARGET_FMT_plx"\n", start_addr);
}
}
}
| {
"code": [],
"line_no": []
} | static void FUNC_0(struct MemoryListener *VAR_0,
MemoryRegionSection *VAR_1,
bool VAR_2)
{
XenIOState *state = container_of(VAR_0, XenIOState, memory_listener);
hwaddr start_addr = VAR_1->offset_within_address_space;
ram_addr_t size = int128_get64(VAR_1->size);
bool log_dirty = memory_region_is_logging(VAR_1->mr);
hvmmem_type_t mem_type;
if (VAR_1->mr == &ram_memory) {
return;
} else {
if (VAR_2) {
xen_map_memory_section(xen_xc, xen_domid, state->ioservid,
VAR_1);
} else {
xen_unmap_memory_section(xen_xc, xen_domid, state->ioservid,
VAR_1);
}
}
if (!memory_region_is_ram(VAR_1->mr)) {
return;
}
if (log_dirty != VAR_2) {
return;
}
trace_xen_client_set_memory(start_addr, size, log_dirty);
start_addr &= TARGET_PAGE_MASK;
size = TARGET_PAGE_ALIGN(size);
if (VAR_2) {
if (!memory_region_is_rom(VAR_1->mr)) {
xen_add_to_physmap(state, start_addr, size,
VAR_1->mr, VAR_1->offset_within_region);
} else {
mem_type = HVMMEM_ram_ro;
if (xc_hvm_set_mem_type(xen_xc, xen_domid, mem_type,
start_addr >> TARGET_PAGE_BITS,
size >> TARGET_PAGE_BITS)) {
DPRINTF("xc_hvm_set_mem_type error, addr: "TARGET_FMT_plx"\n",
start_addr);
}
}
} else {
if (xen_remove_from_physmap(state, start_addr, size) < 0) {
DPRINTF("physmapping does not exist at "TARGET_FMT_plx"\n", start_addr);
}
}
}
| [
"static void FUNC_0(struct MemoryListener *VAR_0,\nMemoryRegionSection *VAR_1,\nbool VAR_2)\n{",
"XenIOState *state = container_of(VAR_0, XenIOState, memory_listener);",
"hwaddr start_addr = VAR_1->offset_within_address_space;",
"ram_addr_t size = int128_get64(VAR_1->size);",
"bool log_dirty = memory_region_is_logging(VAR_1->mr);",
"hvmmem_type_t mem_type;",
"if (VAR_1->mr == &ram_memory) {",
"return;",
"} else {",
"if (VAR_2) {",
"xen_map_memory_section(xen_xc, xen_domid, state->ioservid,\nVAR_1);",
"} else {",
"xen_unmap_memory_section(xen_xc, xen_domid, state->ioservid,\nVAR_1);",
"}",
"}",
"if (!memory_region_is_ram(VAR_1->mr)) {",
"return;",
"}",
"if (log_dirty != VAR_2) {",
"return;",
"}",
"trace_xen_client_set_memory(start_addr, size, log_dirty);",
"start_addr &= TARGET_PAGE_MASK;",
"size = TARGET_PAGE_ALIGN(size);",
"if (VAR_2) {",
"if (!memory_region_is_rom(VAR_1->mr)) {",
"xen_add_to_physmap(state, start_addr, size,\nVAR_1->mr, VAR_1->offset_within_region);",
"} else {",
"mem_type = HVMMEM_ram_ro;",
"if (xc_hvm_set_mem_type(xen_xc, xen_domid, mem_type,\nstart_addr >> TARGET_PAGE_BITS,\nsize >> TARGET_PAGE_BITS)) {",
"DPRINTF(\"xc_hvm_set_mem_type error, addr: \"TARGET_FMT_plx\"\\n\",\nstart_addr);",
"}",
"}",
"} else {",
"if (xen_remove_from_physmap(state, start_addr, size) < 0) {",
"DPRINTF(\"physmapping does not exist at \"TARGET_FMT_plx\"\\n\", start_addr);",
"}",
"}",
"}"
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | [
[
1,
3,
5,
7
],
[
9
],
[
11
],
[
13
],
[
15
],
[
17
],
[
21
],
[
23
],
[
25
],
[
27
],
[
29,
31
],
[
33
],
[
35,
37
],
[
39
],
[
41
],
[
45
],
[
47
],
[
49
],
[
53
],
[
55
],
[
57
],
[
61
],
[
65
],
[
67
],
[
71
],
[
73
],
[
75,
77
],
[
79
],
[
81
],
[
83,
85,
87
],
[
89,
91
],
[
93
],
[
95
],
[
97
],
[
99
],
[
101
],
[
103
],
[
105
],
[
107
]
] |
21,480 | static void hmp_mouse_move(Monitor *mon, const QDict *qdict)
{
int dx, dy, dz, button;
const char *dx_str = qdict_get_str(qdict, "dx_str");
const char *dy_str = qdict_get_str(qdict, "dy_str");
const char *dz_str = qdict_get_try_str(qdict, "dz_str");
dx = strtol(dx_str, NULL, 0);
dy = strtol(dy_str, NULL, 0);
qemu_input_queue_rel(NULL, INPUT_AXIS_X, dx);
qemu_input_queue_rel(NULL, INPUT_AXIS_Y, dy);
if (dz_str) {
dz = strtol(dz_str, NULL, 0);
if (dz != 0) {
button = (dz > 0) ? INPUT_BUTTON_WHEEL_UP : INPUT_BUTTON_WHEEL_DOWN;
qemu_input_queue_btn(NULL, button, true);
qemu_input_event_sync();
qemu_input_queue_btn(NULL, button, false);
}
}
qemu_input_event_sync();
}
| false | qemu | d20a580bc0eac9d489884f6d2ed28105880532b6 | static void hmp_mouse_move(Monitor *mon, const QDict *qdict)
{
int dx, dy, dz, button;
const char *dx_str = qdict_get_str(qdict, "dx_str");
const char *dy_str = qdict_get_str(qdict, "dy_str");
const char *dz_str = qdict_get_try_str(qdict, "dz_str");
dx = strtol(dx_str, NULL, 0);
dy = strtol(dy_str, NULL, 0);
qemu_input_queue_rel(NULL, INPUT_AXIS_X, dx);
qemu_input_queue_rel(NULL, INPUT_AXIS_Y, dy);
if (dz_str) {
dz = strtol(dz_str, NULL, 0);
if (dz != 0) {
button = (dz > 0) ? INPUT_BUTTON_WHEEL_UP : INPUT_BUTTON_WHEEL_DOWN;
qemu_input_queue_btn(NULL, button, true);
qemu_input_event_sync();
qemu_input_queue_btn(NULL, button, false);
}
}
qemu_input_event_sync();
}
| {
"code": [],
"line_no": []
} | static void FUNC_0(Monitor *VAR_0, const QDict *VAR_1)
{
int VAR_2, VAR_3, VAR_4, VAR_5;
const char *VAR_6 = qdict_get_str(VAR_1, "VAR_6");
const char *VAR_7 = qdict_get_str(VAR_1, "VAR_7");
const char *VAR_8 = qdict_get_try_str(VAR_1, "VAR_8");
VAR_2 = strtol(VAR_6, NULL, 0);
VAR_3 = strtol(VAR_7, NULL, 0);
qemu_input_queue_rel(NULL, INPUT_AXIS_X, VAR_2);
qemu_input_queue_rel(NULL, INPUT_AXIS_Y, VAR_3);
if (VAR_8) {
VAR_4 = strtol(VAR_8, NULL, 0);
if (VAR_4 != 0) {
VAR_5 = (VAR_4 > 0) ? INPUT_BUTTON_WHEEL_UP : INPUT_BUTTON_WHEEL_DOWN;
qemu_input_queue_btn(NULL, VAR_5, true);
qemu_input_event_sync();
qemu_input_queue_btn(NULL, VAR_5, false);
}
}
qemu_input_event_sync();
}
| [
"static void FUNC_0(Monitor *VAR_0, const QDict *VAR_1)\n{",
"int VAR_2, VAR_3, VAR_4, VAR_5;",
"const char *VAR_6 = qdict_get_str(VAR_1, \"VAR_6\");",
"const char *VAR_7 = qdict_get_str(VAR_1, \"VAR_7\");",
"const char *VAR_8 = qdict_get_try_str(VAR_1, \"VAR_8\");",
"VAR_2 = strtol(VAR_6, NULL, 0);",
"VAR_3 = strtol(VAR_7, NULL, 0);",
"qemu_input_queue_rel(NULL, INPUT_AXIS_X, VAR_2);",
"qemu_input_queue_rel(NULL, INPUT_AXIS_Y, VAR_3);",
"if (VAR_8) {",
"VAR_4 = strtol(VAR_8, NULL, 0);",
"if (VAR_4 != 0) {",
"VAR_5 = (VAR_4 > 0) ? INPUT_BUTTON_WHEEL_UP : INPUT_BUTTON_WHEEL_DOWN;",
"qemu_input_queue_btn(NULL, VAR_5, true);",
"qemu_input_event_sync();",
"qemu_input_queue_btn(NULL, VAR_5, false);",
"}",
"}",
"qemu_input_event_sync();",
"}"
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | [
[
1,
3
],
[
5
],
[
7
],
[
9
],
[
11
],
[
15
],
[
17
],
[
19
],
[
21
],
[
25
],
[
27
],
[
29
],
[
31
],
[
33
],
[
35
],
[
37
],
[
39
],
[
41
],
[
43
],
[
45
]
] |
21,481 | static void realview_init(ram_addr_t ram_size,
const char *boot_device,
const char *kernel_filename, const char *kernel_cmdline,
const char *initrd_filename, const char *cpu_model,
enum realview_board_type board_type)
{
CPUState *env = NULL;
ram_addr_t ram_offset;
DeviceState *dev, *sysctl, *gpio2;
SysBusDevice *busdev;
qemu_irq *irqp;
qemu_irq pic[64];
qemu_irq mmc_irq[2];
PCIBus *pci_bus;
NICInfo *nd;
i2c_bus *i2c;
int n;
int done_nic = 0;
qemu_irq cpu_irq[4];
int is_mpcore = 0;
int is_pb = 0;
uint32_t proc_id = 0;
uint32_t sys_id;
ram_addr_t low_ram_size;
switch (board_type) {
case BOARD_EB:
break;
case BOARD_EB_MPCORE:
is_mpcore = 1;
break;
case BOARD_PB_A8:
is_pb = 1;
break;
case BOARD_PBX_A9:
is_mpcore = 1;
is_pb = 1;
break;
}
for (n = 0; n < smp_cpus; n++) {
env = cpu_init(cpu_model);
if (!env) {
fprintf(stderr, "Unable to find CPU definition\n");
exit(1);
}
irqp = arm_pic_init_cpu(env);
cpu_irq[n] = irqp[ARM_PIC_CPU_IRQ];
}
if (arm_feature(env, ARM_FEATURE_V7)) {
if (is_mpcore) {
proc_id = 0x0c000000;
} else {
proc_id = 0x0e000000;
}
} else if (arm_feature(env, ARM_FEATURE_V6K)) {
proc_id = 0x06000000;
} else if (arm_feature(env, ARM_FEATURE_V6)) {
proc_id = 0x04000000;
} else {
proc_id = 0x02000000;
}
if (is_pb && ram_size > 0x20000000) {
/* Core tile RAM. */
low_ram_size = ram_size - 0x20000000;
ram_size = 0x20000000;
ram_offset = qemu_ram_alloc(NULL, "realview.lowmem", low_ram_size);
cpu_register_physical_memory(0x20000000, low_ram_size,
ram_offset | IO_MEM_RAM);
}
ram_offset = qemu_ram_alloc(NULL, "realview.highmem", ram_size);
low_ram_size = ram_size;
if (low_ram_size > 0x10000000)
low_ram_size = 0x10000000;
/* SDRAM at address zero. */
cpu_register_physical_memory(0, low_ram_size, ram_offset | IO_MEM_RAM);
if (is_pb) {
/* And again at a high address. */
cpu_register_physical_memory(0x70000000, ram_size,
ram_offset | IO_MEM_RAM);
} else {
ram_size = low_ram_size;
}
sys_id = is_pb ? 0x01780500 : 0xc1400400;
sysctl = qdev_create(NULL, "realview_sysctl");
qdev_prop_set_uint32(sysctl, "sys_id", sys_id);
qdev_init_nofail(sysctl);
qdev_prop_set_uint32(sysctl, "proc_id", proc_id);
sysbus_mmio_map(sysbus_from_qdev(sysctl), 0, 0x10000000);
if (is_mpcore) {
dev = qdev_create(NULL, is_pb ? "a9mpcore_priv": "realview_mpcore");
qdev_prop_set_uint32(dev, "num-cpu", smp_cpus);
qdev_init_nofail(dev);
busdev = sysbus_from_qdev(dev);
if (is_pb) {
realview_binfo.smp_priv_base = 0x1f000000;
} else {
realview_binfo.smp_priv_base = 0x10100000;
}
sysbus_mmio_map(busdev, 0, realview_binfo.smp_priv_base);
for (n = 0; n < smp_cpus; n++) {
sysbus_connect_irq(busdev, n, cpu_irq[n]);
}
} else {
uint32_t gic_addr = is_pb ? 0x1e000000 : 0x10040000;
/* For now just create the nIRQ GIC, and ignore the others. */
dev = sysbus_create_simple("realview_gic", gic_addr, cpu_irq[0]);
}
for (n = 0; n < 64; n++) {
pic[n] = qdev_get_gpio_in(dev, n);
}
sysbus_create_simple("pl050_keyboard", 0x10006000, pic[20]);
sysbus_create_simple("pl050_mouse", 0x10007000, pic[21]);
sysbus_create_simple("pl011", 0x10009000, pic[12]);
sysbus_create_simple("pl011", 0x1000a000, pic[13]);
sysbus_create_simple("pl011", 0x1000b000, pic[14]);
sysbus_create_simple("pl011", 0x1000c000, pic[15]);
/* DMA controller is optional, apparently. */
sysbus_create_simple("pl081", 0x10030000, pic[24]);
sysbus_create_simple("sp804", 0x10011000, pic[4]);
sysbus_create_simple("sp804", 0x10012000, pic[5]);
sysbus_create_simple("pl061", 0x10013000, pic[6]);
sysbus_create_simple("pl061", 0x10014000, pic[7]);
gpio2 = sysbus_create_simple("pl061", 0x10015000, pic[8]);
sysbus_create_simple("pl111", 0x10020000, pic[23]);
dev = sysbus_create_varargs("pl181", 0x10005000, pic[17], pic[18], NULL);
/* Wire up MMC card detect and read-only signals. These have
* to go to both the PL061 GPIO and the sysctl register.
* Note that the PL181 orders these lines (readonly,inserted)
* and the PL061 has them the other way about. Also the card
* detect line is inverted.
*/
mmc_irq[0] = qemu_irq_split(
qdev_get_gpio_in(sysctl, ARM_SYSCTL_GPIO_MMC_WPROT),
qdev_get_gpio_in(gpio2, 1));
mmc_irq[1] = qemu_irq_split(
qdev_get_gpio_in(sysctl, ARM_SYSCTL_GPIO_MMC_CARDIN),
qemu_irq_invert(qdev_get_gpio_in(gpio2, 0)));
qdev_connect_gpio_out(dev, 0, mmc_irq[0]);
qdev_connect_gpio_out(dev, 1, mmc_irq[1]);
sysbus_create_simple("pl031", 0x10017000, pic[10]);
if (!is_pb) {
dev = sysbus_create_varargs("realview_pci", 0x60000000,
pic[48], pic[49], pic[50], pic[51], NULL);
pci_bus = (PCIBus *)qdev_get_child_bus(dev, "pci");
if (usb_enabled) {
usb_ohci_init_pci(pci_bus, -1);
}
n = drive_get_max_bus(IF_SCSI);
while (n >= 0) {
pci_create_simple(pci_bus, -1, "lsi53c895a");
n--;
}
}
for(n = 0; n < nb_nics; n++) {
nd = &nd_table[n];
if (!done_nic && (!nd->model ||
strcmp(nd->model, is_pb ? "lan9118" : "smc91c111") == 0)) {
if (is_pb) {
lan9118_init(nd, 0x4e000000, pic[28]);
} else {
smc91c111_init(nd, 0x4e000000, pic[28]);
}
done_nic = 1;
} else {
pci_nic_init_nofail(nd, "rtl8139", NULL);
}
}
dev = sysbus_create_simple("realview_i2c", 0x10002000, NULL);
i2c = (i2c_bus *)qdev_get_child_bus(dev, "i2c");
i2c_create_slave(i2c, "ds1338", 0x68);
/* Memory map for RealView Emulation Baseboard: */
/* 0x10000000 System registers. */
/* 0x10001000 System controller. */
/* 0x10002000 Two-Wire Serial Bus. */
/* 0x10003000 Reserved. */
/* 0x10004000 AACI. */
/* 0x10005000 MCI. */
/* 0x10006000 KMI0. */
/* 0x10007000 KMI1. */
/* 0x10008000 Character LCD. (EB) */
/* 0x10009000 UART0. */
/* 0x1000a000 UART1. */
/* 0x1000b000 UART2. */
/* 0x1000c000 UART3. */
/* 0x1000d000 SSPI. */
/* 0x1000e000 SCI. */
/* 0x1000f000 Reserved. */
/* 0x10010000 Watchdog. */
/* 0x10011000 Timer 0+1. */
/* 0x10012000 Timer 2+3. */
/* 0x10013000 GPIO 0. */
/* 0x10014000 GPIO 1. */
/* 0x10015000 GPIO 2. */
/* 0x10002000 Two-Wire Serial Bus - DVI. (PB) */
/* 0x10017000 RTC. */
/* 0x10018000 DMC. */
/* 0x10019000 PCI controller config. */
/* 0x10020000 CLCD. */
/* 0x10030000 DMA Controller. */
/* 0x10040000 GIC1. (EB) */
/* 0x10050000 GIC2. (EB) */
/* 0x10060000 GIC3. (EB) */
/* 0x10070000 GIC4. (EB) */
/* 0x10080000 SMC. */
/* 0x1e000000 GIC1. (PB) */
/* 0x1e001000 GIC2. (PB) */
/* 0x1e002000 GIC3. (PB) */
/* 0x1e003000 GIC4. (PB) */
/* 0x40000000 NOR flash. */
/* 0x44000000 DoC flash. */
/* 0x48000000 SRAM. */
/* 0x4c000000 Configuration flash. */
/* 0x4e000000 Ethernet. */
/* 0x4f000000 USB. */
/* 0x50000000 PISMO. */
/* 0x54000000 PISMO. */
/* 0x58000000 PISMO. */
/* 0x5c000000 PISMO. */
/* 0x60000000 PCI. */
/* 0x61000000 PCI Self Config. */
/* 0x62000000 PCI Config. */
/* 0x63000000 PCI IO. */
/* 0x64000000 PCI mem 0. */
/* 0x68000000 PCI mem 1. */
/* 0x6c000000 PCI mem 2. */
/* ??? Hack to map an additional page of ram for the secondary CPU
startup code. I guess this works on real hardware because the
BootROM happens to be in ROM/flash or in memory that isn't clobbered
until after Linux boots the secondary CPUs. */
ram_offset = qemu_ram_alloc(NULL, "realview.hack", 0x1000);
cpu_register_physical_memory(SMP_BOOT_ADDR, 0x1000,
ram_offset | IO_MEM_RAM);
realview_binfo.ram_size = ram_size;
realview_binfo.kernel_filename = kernel_filename;
realview_binfo.kernel_cmdline = kernel_cmdline;
realview_binfo.initrd_filename = initrd_filename;
realview_binfo.nb_cpus = smp_cpus;
realview_binfo.board_id = realview_board_id[board_type];
realview_binfo.loader_start = (board_type == BOARD_PB_A8 ? 0x70000000 : 0);
arm_load_kernel(first_cpu, &realview_binfo);
}
| false | qemu | 7d6e771f49c36f4388798ce25bde1dede40cda74 | static void realview_init(ram_addr_t ram_size,
const char *boot_device,
const char *kernel_filename, const char *kernel_cmdline,
const char *initrd_filename, const char *cpu_model,
enum realview_board_type board_type)
{
CPUState *env = NULL;
ram_addr_t ram_offset;
DeviceState *dev, *sysctl, *gpio2;
SysBusDevice *busdev;
qemu_irq *irqp;
qemu_irq pic[64];
qemu_irq mmc_irq[2];
PCIBus *pci_bus;
NICInfo *nd;
i2c_bus *i2c;
int n;
int done_nic = 0;
qemu_irq cpu_irq[4];
int is_mpcore = 0;
int is_pb = 0;
uint32_t proc_id = 0;
uint32_t sys_id;
ram_addr_t low_ram_size;
switch (board_type) {
case BOARD_EB:
break;
case BOARD_EB_MPCORE:
is_mpcore = 1;
break;
case BOARD_PB_A8:
is_pb = 1;
break;
case BOARD_PBX_A9:
is_mpcore = 1;
is_pb = 1;
break;
}
for (n = 0; n < smp_cpus; n++) {
env = cpu_init(cpu_model);
if (!env) {
fprintf(stderr, "Unable to find CPU definition\n");
exit(1);
}
irqp = arm_pic_init_cpu(env);
cpu_irq[n] = irqp[ARM_PIC_CPU_IRQ];
}
if (arm_feature(env, ARM_FEATURE_V7)) {
if (is_mpcore) {
proc_id = 0x0c000000;
} else {
proc_id = 0x0e000000;
}
} else if (arm_feature(env, ARM_FEATURE_V6K)) {
proc_id = 0x06000000;
} else if (arm_feature(env, ARM_FEATURE_V6)) {
proc_id = 0x04000000;
} else {
proc_id = 0x02000000;
}
if (is_pb && ram_size > 0x20000000) {
low_ram_size = ram_size - 0x20000000;
ram_size = 0x20000000;
ram_offset = qemu_ram_alloc(NULL, "realview.lowmem", low_ram_size);
cpu_register_physical_memory(0x20000000, low_ram_size,
ram_offset | IO_MEM_RAM);
}
ram_offset = qemu_ram_alloc(NULL, "realview.highmem", ram_size);
low_ram_size = ram_size;
if (low_ram_size > 0x10000000)
low_ram_size = 0x10000000;
cpu_register_physical_memory(0, low_ram_size, ram_offset | IO_MEM_RAM);
if (is_pb) {
cpu_register_physical_memory(0x70000000, ram_size,
ram_offset | IO_MEM_RAM);
} else {
ram_size = low_ram_size;
}
sys_id = is_pb ? 0x01780500 : 0xc1400400;
sysctl = qdev_create(NULL, "realview_sysctl");
qdev_prop_set_uint32(sysctl, "sys_id", sys_id);
qdev_init_nofail(sysctl);
qdev_prop_set_uint32(sysctl, "proc_id", proc_id);
sysbus_mmio_map(sysbus_from_qdev(sysctl), 0, 0x10000000);
if (is_mpcore) {
dev = qdev_create(NULL, is_pb ? "a9mpcore_priv": "realview_mpcore");
qdev_prop_set_uint32(dev, "num-cpu", smp_cpus);
qdev_init_nofail(dev);
busdev = sysbus_from_qdev(dev);
if (is_pb) {
realview_binfo.smp_priv_base = 0x1f000000;
} else {
realview_binfo.smp_priv_base = 0x10100000;
}
sysbus_mmio_map(busdev, 0, realview_binfo.smp_priv_base);
for (n = 0; n < smp_cpus; n++) {
sysbus_connect_irq(busdev, n, cpu_irq[n]);
}
} else {
uint32_t gic_addr = is_pb ? 0x1e000000 : 0x10040000;
dev = sysbus_create_simple("realview_gic", gic_addr, cpu_irq[0]);
}
for (n = 0; n < 64; n++) {
pic[n] = qdev_get_gpio_in(dev, n);
}
sysbus_create_simple("pl050_keyboard", 0x10006000, pic[20]);
sysbus_create_simple("pl050_mouse", 0x10007000, pic[21]);
sysbus_create_simple("pl011", 0x10009000, pic[12]);
sysbus_create_simple("pl011", 0x1000a000, pic[13]);
sysbus_create_simple("pl011", 0x1000b000, pic[14]);
sysbus_create_simple("pl011", 0x1000c000, pic[15]);
sysbus_create_simple("pl081", 0x10030000, pic[24]);
sysbus_create_simple("sp804", 0x10011000, pic[4]);
sysbus_create_simple("sp804", 0x10012000, pic[5]);
sysbus_create_simple("pl061", 0x10013000, pic[6]);
sysbus_create_simple("pl061", 0x10014000, pic[7]);
gpio2 = sysbus_create_simple("pl061", 0x10015000, pic[8]);
sysbus_create_simple("pl111", 0x10020000, pic[23]);
dev = sysbus_create_varargs("pl181", 0x10005000, pic[17], pic[18], NULL);
mmc_irq[0] = qemu_irq_split(
qdev_get_gpio_in(sysctl, ARM_SYSCTL_GPIO_MMC_WPROT),
qdev_get_gpio_in(gpio2, 1));
mmc_irq[1] = qemu_irq_split(
qdev_get_gpio_in(sysctl, ARM_SYSCTL_GPIO_MMC_CARDIN),
qemu_irq_invert(qdev_get_gpio_in(gpio2, 0)));
qdev_connect_gpio_out(dev, 0, mmc_irq[0]);
qdev_connect_gpio_out(dev, 1, mmc_irq[1]);
sysbus_create_simple("pl031", 0x10017000, pic[10]);
if (!is_pb) {
dev = sysbus_create_varargs("realview_pci", 0x60000000,
pic[48], pic[49], pic[50], pic[51], NULL);
pci_bus = (PCIBus *)qdev_get_child_bus(dev, "pci");
if (usb_enabled) {
usb_ohci_init_pci(pci_bus, -1);
}
n = drive_get_max_bus(IF_SCSI);
while (n >= 0) {
pci_create_simple(pci_bus, -1, "lsi53c895a");
n--;
}
}
for(n = 0; n < nb_nics; n++) {
nd = &nd_table[n];
if (!done_nic && (!nd->model ||
strcmp(nd->model, is_pb ? "lan9118" : "smc91c111") == 0)) {
if (is_pb) {
lan9118_init(nd, 0x4e000000, pic[28]);
} else {
smc91c111_init(nd, 0x4e000000, pic[28]);
}
done_nic = 1;
} else {
pci_nic_init_nofail(nd, "rtl8139", NULL);
}
}
dev = sysbus_create_simple("realview_i2c", 0x10002000, NULL);
i2c = (i2c_bus *)qdev_get_child_bus(dev, "i2c");
i2c_create_slave(i2c, "ds1338", 0x68);
ram_offset = qemu_ram_alloc(NULL, "realview.hack", 0x1000);
cpu_register_physical_memory(SMP_BOOT_ADDR, 0x1000,
ram_offset | IO_MEM_RAM);
realview_binfo.ram_size = ram_size;
realview_binfo.kernel_filename = kernel_filename;
realview_binfo.kernel_cmdline = kernel_cmdline;
realview_binfo.initrd_filename = initrd_filename;
realview_binfo.nb_cpus = smp_cpus;
realview_binfo.board_id = realview_board_id[board_type];
realview_binfo.loader_start = (board_type == BOARD_PB_A8 ? 0x70000000 : 0);
arm_load_kernel(first_cpu, &realview_binfo);
}
| {
"code": [],
"line_no": []
} | static void FUNC_0(ram_addr_t VAR_0,
const char *VAR_1,
const char *VAR_2, const char *VAR_3,
const char *VAR_4, const char *VAR_5,
enum realview_board_type VAR_6)
{
CPUState *env = NULL;
ram_addr_t ram_offset;
DeviceState *dev, *sysctl, *gpio2;
SysBusDevice *busdev;
qemu_irq *irqp;
qemu_irq pic[64];
qemu_irq mmc_irq[2];
PCIBus *pci_bus;
NICInfo *nd;
i2c_bus *i2c;
int VAR_7;
int VAR_8 = 0;
qemu_irq cpu_irq[4];
int VAR_9 = 0;
int VAR_10 = 0;
uint32_t proc_id = 0;
uint32_t sys_id;
ram_addr_t low_ram_size;
switch (VAR_6) {
case BOARD_EB:
break;
case BOARD_EB_MPCORE:
VAR_9 = 1;
break;
case BOARD_PB_A8:
VAR_10 = 1;
break;
case BOARD_PBX_A9:
VAR_9 = 1;
VAR_10 = 1;
break;
}
for (VAR_7 = 0; VAR_7 < smp_cpus; VAR_7++) {
env = cpu_init(VAR_5);
if (!env) {
fprintf(stderr, "Unable to find CPU definition\VAR_7");
exit(1);
}
irqp = arm_pic_init_cpu(env);
cpu_irq[VAR_7] = irqp[ARM_PIC_CPU_IRQ];
}
if (arm_feature(env, ARM_FEATURE_V7)) {
if (VAR_9) {
proc_id = 0x0c000000;
} else {
proc_id = 0x0e000000;
}
} else if (arm_feature(env, ARM_FEATURE_V6K)) {
proc_id = 0x06000000;
} else if (arm_feature(env, ARM_FEATURE_V6)) {
proc_id = 0x04000000;
} else {
proc_id = 0x02000000;
}
if (VAR_10 && VAR_0 > 0x20000000) {
low_ram_size = VAR_0 - 0x20000000;
VAR_0 = 0x20000000;
ram_offset = qemu_ram_alloc(NULL, "realview.lowmem", low_ram_size);
cpu_register_physical_memory(0x20000000, low_ram_size,
ram_offset | IO_MEM_RAM);
}
ram_offset = qemu_ram_alloc(NULL, "realview.highmem", VAR_0);
low_ram_size = VAR_0;
if (low_ram_size > 0x10000000)
low_ram_size = 0x10000000;
cpu_register_physical_memory(0, low_ram_size, ram_offset | IO_MEM_RAM);
if (VAR_10) {
cpu_register_physical_memory(0x70000000, VAR_0,
ram_offset | IO_MEM_RAM);
} else {
VAR_0 = low_ram_size;
}
sys_id = VAR_10 ? 0x01780500 : 0xc1400400;
sysctl = qdev_create(NULL, "realview_sysctl");
qdev_prop_set_uint32(sysctl, "sys_id", sys_id);
qdev_init_nofail(sysctl);
qdev_prop_set_uint32(sysctl, "proc_id", proc_id);
sysbus_mmio_map(sysbus_from_qdev(sysctl), 0, 0x10000000);
if (VAR_9) {
dev = qdev_create(NULL, VAR_10 ? "a9mpcore_priv": "realview_mpcore");
qdev_prop_set_uint32(dev, "num-cpu", smp_cpus);
qdev_init_nofail(dev);
busdev = sysbus_from_qdev(dev);
if (VAR_10) {
realview_binfo.smp_priv_base = 0x1f000000;
} else {
realview_binfo.smp_priv_base = 0x10100000;
}
sysbus_mmio_map(busdev, 0, realview_binfo.smp_priv_base);
for (VAR_7 = 0; VAR_7 < smp_cpus; VAR_7++) {
sysbus_connect_irq(busdev, VAR_7, cpu_irq[VAR_7]);
}
} else {
uint32_t gic_addr = VAR_10 ? 0x1e000000 : 0x10040000;
dev = sysbus_create_simple("realview_gic", gic_addr, cpu_irq[0]);
}
for (VAR_7 = 0; VAR_7 < 64; VAR_7++) {
pic[VAR_7] = qdev_get_gpio_in(dev, VAR_7);
}
sysbus_create_simple("pl050_keyboard", 0x10006000, pic[20]);
sysbus_create_simple("pl050_mouse", 0x10007000, pic[21]);
sysbus_create_simple("pl011", 0x10009000, pic[12]);
sysbus_create_simple("pl011", 0x1000a000, pic[13]);
sysbus_create_simple("pl011", 0x1000b000, pic[14]);
sysbus_create_simple("pl011", 0x1000c000, pic[15]);
sysbus_create_simple("pl081", 0x10030000, pic[24]);
sysbus_create_simple("sp804", 0x10011000, pic[4]);
sysbus_create_simple("sp804", 0x10012000, pic[5]);
sysbus_create_simple("pl061", 0x10013000, pic[6]);
sysbus_create_simple("pl061", 0x10014000, pic[7]);
gpio2 = sysbus_create_simple("pl061", 0x10015000, pic[8]);
sysbus_create_simple("pl111", 0x10020000, pic[23]);
dev = sysbus_create_varargs("pl181", 0x10005000, pic[17], pic[18], NULL);
mmc_irq[0] = qemu_irq_split(
qdev_get_gpio_in(sysctl, ARM_SYSCTL_GPIO_MMC_WPROT),
qdev_get_gpio_in(gpio2, 1));
mmc_irq[1] = qemu_irq_split(
qdev_get_gpio_in(sysctl, ARM_SYSCTL_GPIO_MMC_CARDIN),
qemu_irq_invert(qdev_get_gpio_in(gpio2, 0)));
qdev_connect_gpio_out(dev, 0, mmc_irq[0]);
qdev_connect_gpio_out(dev, 1, mmc_irq[1]);
sysbus_create_simple("pl031", 0x10017000, pic[10]);
if (!VAR_10) {
dev = sysbus_create_varargs("realview_pci", 0x60000000,
pic[48], pic[49], pic[50], pic[51], NULL);
pci_bus = (PCIBus *)qdev_get_child_bus(dev, "pci");
if (usb_enabled) {
usb_ohci_init_pci(pci_bus, -1);
}
VAR_7 = drive_get_max_bus(IF_SCSI);
while (VAR_7 >= 0) {
pci_create_simple(pci_bus, -1, "lsi53c895a");
VAR_7--;
}
}
for(VAR_7 = 0; VAR_7 < nb_nics; VAR_7++) {
nd = &nd_table[VAR_7];
if (!VAR_8 && (!nd->model ||
strcmp(nd->model, VAR_10 ? "lan9118" : "smc91c111") == 0)) {
if (VAR_10) {
lan9118_init(nd, 0x4e000000, pic[28]);
} else {
smc91c111_init(nd, 0x4e000000, pic[28]);
}
VAR_8 = 1;
} else {
pci_nic_init_nofail(nd, "rtl8139", NULL);
}
}
dev = sysbus_create_simple("realview_i2c", 0x10002000, NULL);
i2c = (i2c_bus *)qdev_get_child_bus(dev, "i2c");
i2c_create_slave(i2c, "ds1338", 0x68);
ram_offset = qemu_ram_alloc(NULL, "realview.hack", 0x1000);
cpu_register_physical_memory(SMP_BOOT_ADDR, 0x1000,
ram_offset | IO_MEM_RAM);
realview_binfo.VAR_0 = VAR_0;
realview_binfo.VAR_2 = VAR_2;
realview_binfo.VAR_3 = VAR_3;
realview_binfo.VAR_4 = VAR_4;
realview_binfo.nb_cpus = smp_cpus;
realview_binfo.board_id = realview_board_id[VAR_6];
realview_binfo.loader_start = (VAR_6 == BOARD_PB_A8 ? 0x70000000 : 0);
arm_load_kernel(first_cpu, &realview_binfo);
}
| [
"static void FUNC_0(ram_addr_t VAR_0,\nconst char *VAR_1,\nconst char *VAR_2, const char *VAR_3,\nconst char *VAR_4, const char *VAR_5,\nenum realview_board_type VAR_6)\n{",
"CPUState *env = NULL;",
"ram_addr_t ram_offset;",
"DeviceState *dev, *sysctl, *gpio2;",
"SysBusDevice *busdev;",
"qemu_irq *irqp;",
"qemu_irq pic[64];",
"qemu_irq mmc_irq[2];",
"PCIBus *pci_bus;",
"NICInfo *nd;",
"i2c_bus *i2c;",
"int VAR_7;",
"int VAR_8 = 0;",
"qemu_irq cpu_irq[4];",
"int VAR_9 = 0;",
"int VAR_10 = 0;",
"uint32_t proc_id = 0;",
"uint32_t sys_id;",
"ram_addr_t low_ram_size;",
"switch (VAR_6) {",
"case BOARD_EB:\nbreak;",
"case BOARD_EB_MPCORE:\nVAR_9 = 1;",
"break;",
"case BOARD_PB_A8:\nVAR_10 = 1;",
"break;",
"case BOARD_PBX_A9:\nVAR_9 = 1;",
"VAR_10 = 1;",
"break;",
"}",
"for (VAR_7 = 0; VAR_7 < smp_cpus; VAR_7++) {",
"env = cpu_init(VAR_5);",
"if (!env) {",
"fprintf(stderr, \"Unable to find CPU definition\\VAR_7\");",
"exit(1);",
"}",
"irqp = arm_pic_init_cpu(env);",
"cpu_irq[VAR_7] = irqp[ARM_PIC_CPU_IRQ];",
"}",
"if (arm_feature(env, ARM_FEATURE_V7)) {",
"if (VAR_9) {",
"proc_id = 0x0c000000;",
"} else {",
"proc_id = 0x0e000000;",
"}",
"} else if (arm_feature(env, ARM_FEATURE_V6K)) {",
"proc_id = 0x06000000;",
"} else if (arm_feature(env, ARM_FEATURE_V6)) {",
"proc_id = 0x04000000;",
"} else {",
"proc_id = 0x02000000;",
"}",
"if (VAR_10 && VAR_0 > 0x20000000) {",
"low_ram_size = VAR_0 - 0x20000000;",
"VAR_0 = 0x20000000;",
"ram_offset = qemu_ram_alloc(NULL, \"realview.lowmem\", low_ram_size);",
"cpu_register_physical_memory(0x20000000, low_ram_size,\nram_offset | IO_MEM_RAM);",
"}",
"ram_offset = qemu_ram_alloc(NULL, \"realview.highmem\", VAR_0);",
"low_ram_size = VAR_0;",
"if (low_ram_size > 0x10000000)\nlow_ram_size = 0x10000000;",
"cpu_register_physical_memory(0, low_ram_size, ram_offset | IO_MEM_RAM);",
"if (VAR_10) {",
"cpu_register_physical_memory(0x70000000, VAR_0,\nram_offset | IO_MEM_RAM);",
"} else {",
"VAR_0 = low_ram_size;",
"}",
"sys_id = VAR_10 ? 0x01780500 : 0xc1400400;",
"sysctl = qdev_create(NULL, \"realview_sysctl\");",
"qdev_prop_set_uint32(sysctl, \"sys_id\", sys_id);",
"qdev_init_nofail(sysctl);",
"qdev_prop_set_uint32(sysctl, \"proc_id\", proc_id);",
"sysbus_mmio_map(sysbus_from_qdev(sysctl), 0, 0x10000000);",
"if (VAR_9) {",
"dev = qdev_create(NULL, VAR_10 ? \"a9mpcore_priv\": \"realview_mpcore\");",
"qdev_prop_set_uint32(dev, \"num-cpu\", smp_cpus);",
"qdev_init_nofail(dev);",
"busdev = sysbus_from_qdev(dev);",
"if (VAR_10) {",
"realview_binfo.smp_priv_base = 0x1f000000;",
"} else {",
"realview_binfo.smp_priv_base = 0x10100000;",
"}",
"sysbus_mmio_map(busdev, 0, realview_binfo.smp_priv_base);",
"for (VAR_7 = 0; VAR_7 < smp_cpus; VAR_7++) {",
"sysbus_connect_irq(busdev, VAR_7, cpu_irq[VAR_7]);",
"}",
"} else {",
"uint32_t gic_addr = VAR_10 ? 0x1e000000 : 0x10040000;",
"dev = sysbus_create_simple(\"realview_gic\", gic_addr, cpu_irq[0]);",
"}",
"for (VAR_7 = 0; VAR_7 < 64; VAR_7++) {",
"pic[VAR_7] = qdev_get_gpio_in(dev, VAR_7);",
"}",
"sysbus_create_simple(\"pl050_keyboard\", 0x10006000, pic[20]);",
"sysbus_create_simple(\"pl050_mouse\", 0x10007000, pic[21]);",
"sysbus_create_simple(\"pl011\", 0x10009000, pic[12]);",
"sysbus_create_simple(\"pl011\", 0x1000a000, pic[13]);",
"sysbus_create_simple(\"pl011\", 0x1000b000, pic[14]);",
"sysbus_create_simple(\"pl011\", 0x1000c000, pic[15]);",
"sysbus_create_simple(\"pl081\", 0x10030000, pic[24]);",
"sysbus_create_simple(\"sp804\", 0x10011000, pic[4]);",
"sysbus_create_simple(\"sp804\", 0x10012000, pic[5]);",
"sysbus_create_simple(\"pl061\", 0x10013000, pic[6]);",
"sysbus_create_simple(\"pl061\", 0x10014000, pic[7]);",
"gpio2 = sysbus_create_simple(\"pl061\", 0x10015000, pic[8]);",
"sysbus_create_simple(\"pl111\", 0x10020000, pic[23]);",
"dev = sysbus_create_varargs(\"pl181\", 0x10005000, pic[17], pic[18], NULL);",
"mmc_irq[0] = qemu_irq_split(\nqdev_get_gpio_in(sysctl, ARM_SYSCTL_GPIO_MMC_WPROT),\nqdev_get_gpio_in(gpio2, 1));",
"mmc_irq[1] = qemu_irq_split(\nqdev_get_gpio_in(sysctl, ARM_SYSCTL_GPIO_MMC_CARDIN),\nqemu_irq_invert(qdev_get_gpio_in(gpio2, 0)));",
"qdev_connect_gpio_out(dev, 0, mmc_irq[0]);",
"qdev_connect_gpio_out(dev, 1, mmc_irq[1]);",
"sysbus_create_simple(\"pl031\", 0x10017000, pic[10]);",
"if (!VAR_10) {",
"dev = sysbus_create_varargs(\"realview_pci\", 0x60000000,\npic[48], pic[49], pic[50], pic[51], NULL);",
"pci_bus = (PCIBus *)qdev_get_child_bus(dev, \"pci\");",
"if (usb_enabled) {",
"usb_ohci_init_pci(pci_bus, -1);",
"}",
"VAR_7 = drive_get_max_bus(IF_SCSI);",
"while (VAR_7 >= 0) {",
"pci_create_simple(pci_bus, -1, \"lsi53c895a\");",
"VAR_7--;",
"}",
"}",
"for(VAR_7 = 0; VAR_7 < nb_nics; VAR_7++) {",
"nd = &nd_table[VAR_7];",
"if (!VAR_8 && (!nd->model ||\nstrcmp(nd->model, VAR_10 ? \"lan9118\" : \"smc91c111\") == 0)) {",
"if (VAR_10) {",
"lan9118_init(nd, 0x4e000000, pic[28]);",
"} else {",
"smc91c111_init(nd, 0x4e000000, pic[28]);",
"}",
"VAR_8 = 1;",
"} else {",
"pci_nic_init_nofail(nd, \"rtl8139\", NULL);",
"}",
"}",
"dev = sysbus_create_simple(\"realview_i2c\", 0x10002000, NULL);",
"i2c = (i2c_bus *)qdev_get_child_bus(dev, \"i2c\");",
"i2c_create_slave(i2c, \"ds1338\", 0x68);",
"ram_offset = qemu_ram_alloc(NULL, \"realview.hack\", 0x1000);",
"cpu_register_physical_memory(SMP_BOOT_ADDR, 0x1000,\nram_offset | IO_MEM_RAM);",
"realview_binfo.VAR_0 = VAR_0;",
"realview_binfo.VAR_2 = VAR_2;",
"realview_binfo.VAR_3 = VAR_3;",
"realview_binfo.VAR_4 = VAR_4;",
"realview_binfo.nb_cpus = smp_cpus;",
"realview_binfo.board_id = realview_board_id[VAR_6];",
"realview_binfo.loader_start = (VAR_6 == BOARD_PB_A8 ? 0x70000000 : 0);",
"arm_load_kernel(first_cpu, &realview_binfo);",
"}"
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | [
[
1,
3,
5,
7,
9,
11
],
[
13
],
[
15
],
[
17
],
[
19
],
[
21
],
[
23
],
[
25
],
[
27
],
[
29
],
[
31
],
[
33
],
[
35
],
[
37
],
[
39
],
[
41
],
[
43
],
[
45
],
[
47
],
[
51
],
[
53,
55
],
[
57,
59
],
[
61
],
[
63,
65
],
[
67
],
[
69,
71
],
[
73
],
[
75
],
[
77
],
[
79
],
[
81
],
[
83
],
[
85
],
[
87
],
[
89
],
[
91
],
[
93
],
[
95
],
[
97
],
[
99
],
[
101
],
[
103
],
[
105
],
[
107
],
[
109
],
[
111
],
[
113
],
[
115
],
[
117
],
[
119
],
[
121
],
[
125
],
[
129
],
[
131
],
[
133
],
[
135,
137
],
[
139
],
[
143
],
[
145
],
[
147,
149
],
[
153
],
[
155
],
[
159,
161
],
[
163
],
[
165
],
[
167
],
[
171
],
[
173
],
[
175
],
[
177
],
[
179
],
[
181
],
[
185
],
[
187
],
[
189
],
[
191
],
[
193
],
[
195
],
[
197
],
[
199
],
[
201
],
[
203
],
[
205
],
[
207
],
[
209
],
[
211
],
[
213
],
[
215
],
[
219
],
[
221
],
[
223
],
[
225
],
[
227
],
[
231
],
[
233
],
[
237
],
[
239
],
[
241
],
[
243
],
[
249
],
[
253
],
[
255
],
[
259
],
[
261
],
[
263
],
[
267
],
[
271
],
[
285,
287,
289
],
[
291,
293,
295
],
[
297
],
[
299
],
[
303
],
[
307
],
[
309,
311
],
[
313
],
[
315
],
[
317
],
[
319
],
[
321
],
[
323
],
[
325
],
[
327
],
[
329
],
[
331
],
[
333
],
[
335
],
[
339,
341
],
[
343
],
[
345
],
[
347
],
[
349
],
[
351
],
[
353
],
[
355
],
[
357
],
[
359
],
[
361
],
[
365
],
[
367
],
[
369
],
[
493
],
[
495,
497
],
[
501
],
[
503
],
[
505
],
[
507
],
[
509
],
[
511
],
[
513
],
[
515
],
[
517
]
] |
21,482 | static int intel_hda_post_load(void *opaque, int version)
{
IntelHDAState* d = opaque;
int i;
dprint(d, 1, "%s\n", __FUNCTION__);
for (i = 0; i < ARRAY_SIZE(d->st); i++) {
if (d->st[i].ctl & 0x02) {
intel_hda_parse_bdl(d, &d->st[i]);
}
}
intel_hda_update_irq(d);
return 0;
}
| false | qemu | a89f364ae8740dfc31b321eed9ee454e996dc3c1 | static int intel_hda_post_load(void *opaque, int version)
{
IntelHDAState* d = opaque;
int i;
dprint(d, 1, "%s\n", __FUNCTION__);
for (i = 0; i < ARRAY_SIZE(d->st); i++) {
if (d->st[i].ctl & 0x02) {
intel_hda_parse_bdl(d, &d->st[i]);
}
}
intel_hda_update_irq(d);
return 0;
}
| {
"code": [],
"line_no": []
} | static int FUNC_0(void *VAR_0, int VAR_1)
{
IntelHDAState* d = VAR_0;
int VAR_2;
dprint(d, 1, "%s\n", __FUNCTION__);
for (VAR_2 = 0; VAR_2 < ARRAY_SIZE(d->st); VAR_2++) {
if (d->st[VAR_2].ctl & 0x02) {
intel_hda_parse_bdl(d, &d->st[VAR_2]);
}
}
intel_hda_update_irq(d);
return 0;
}
| [
"static int FUNC_0(void *VAR_0, int VAR_1)\n{",
"IntelHDAState* d = VAR_0;",
"int VAR_2;",
"dprint(d, 1, \"%s\\n\", __FUNCTION__);",
"for (VAR_2 = 0; VAR_2 < ARRAY_SIZE(d->st); VAR_2++) {",
"if (d->st[VAR_2].ctl & 0x02) {",
"intel_hda_parse_bdl(d, &d->st[VAR_2]);",
"}",
"}",
"intel_hda_update_irq(d);",
"return 0;",
"}"
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | [
[
1,
3
],
[
5
],
[
7
],
[
11
],
[
13
],
[
15
],
[
17
],
[
19
],
[
21
],
[
23
],
[
25
],
[
27
]
] |
21,484 | int cpu_x86_handle_mmu_fault(CPUX86State *env, target_ulong addr,
int is_write1, int mmu_idx, int is_softmmu)
{
uint64_t ptep, pte;
target_ulong pde_addr, pte_addr;
int error_code, is_dirty, prot, page_size, ret, is_write, is_user;
target_phys_addr_t paddr;
uint32_t page_offset;
target_ulong vaddr, virt_addr;
is_user = mmu_idx == MMU_USER_IDX;
#if defined(DEBUG_MMU)
printf("MMU fault: addr=" TARGET_FMT_lx " w=%d u=%d eip=" TARGET_FMT_lx "\n",
addr, is_write1, is_user, env->eip);
#endif
is_write = is_write1 & 1;
if (!(env->cr[0] & CR0_PG_MASK)) {
pte = addr;
virt_addr = addr & TARGET_PAGE_MASK;
prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC;
page_size = 4096;
goto do_mapping;
}
if (env->cr[4] & CR4_PAE_MASK) {
uint64_t pde, pdpe;
target_ulong pdpe_addr;
#ifdef TARGET_X86_64
if (env->hflags & HF_LMA_MASK) {
uint64_t pml4e_addr, pml4e;
int32_t sext;
/* test virtual address sign extension */
sext = (int64_t)addr >> 47;
if (sext != 0 && sext != -1) {
env->error_code = 0;
env->exception_index = EXCP0D_GPF;
return 1;
}
pml4e_addr = ((env->cr[3] & ~0xfff) + (((addr >> 39) & 0x1ff) << 3)) &
env->a20_mask;
pml4e = ldq_phys(pml4e_addr);
if (!(pml4e & PG_PRESENT_MASK)) {
error_code = 0;
goto do_fault;
}
if (!(env->efer & MSR_EFER_NXE) && (pml4e & PG_NX_MASK)) {
error_code = PG_ERROR_RSVD_MASK;
goto do_fault;
}
if (!(pml4e & PG_ACCESSED_MASK)) {
pml4e |= PG_ACCESSED_MASK;
stl_phys_notdirty(pml4e_addr, pml4e);
}
ptep = pml4e ^ PG_NX_MASK;
pdpe_addr = ((pml4e & PHYS_ADDR_MASK) + (((addr >> 30) & 0x1ff) << 3)) &
env->a20_mask;
pdpe = ldq_phys(pdpe_addr);
if (!(pdpe & PG_PRESENT_MASK)) {
error_code = 0;
goto do_fault;
}
if (!(env->efer & MSR_EFER_NXE) && (pdpe & PG_NX_MASK)) {
error_code = PG_ERROR_RSVD_MASK;
goto do_fault;
}
ptep &= pdpe ^ PG_NX_MASK;
if (!(pdpe & PG_ACCESSED_MASK)) {
pdpe |= PG_ACCESSED_MASK;
stl_phys_notdirty(pdpe_addr, pdpe);
}
} else
#endif
{
/* XXX: load them when cr3 is loaded ? */
pdpe_addr = ((env->cr[3] & ~0x1f) + ((addr >> 27) & 0x18)) &
env->a20_mask;
pdpe = ldq_phys(pdpe_addr);
if (!(pdpe & PG_PRESENT_MASK)) {
error_code = 0;
goto do_fault;
}
ptep = PG_NX_MASK | PG_USER_MASK | PG_RW_MASK;
}
pde_addr = ((pdpe & PHYS_ADDR_MASK) + (((addr >> 21) & 0x1ff) << 3)) &
env->a20_mask;
pde = ldq_phys(pde_addr);
if (!(pde & PG_PRESENT_MASK)) {
error_code = 0;
goto do_fault;
}
if (!(env->efer & MSR_EFER_NXE) && (pde & PG_NX_MASK)) {
error_code = PG_ERROR_RSVD_MASK;
goto do_fault;
}
ptep &= pde ^ PG_NX_MASK;
if (pde & PG_PSE_MASK) {
/* 2 MB page */
page_size = 2048 * 1024;
ptep ^= PG_NX_MASK;
if ((ptep & PG_NX_MASK) && is_write1 == 2)
goto do_fault_protect;
if (is_user) {
if (!(ptep & PG_USER_MASK))
goto do_fault_protect;
if (is_write && !(ptep & PG_RW_MASK))
goto do_fault_protect;
} else {
if ((env->cr[0] & CR0_WP_MASK) &&
is_write && !(ptep & PG_RW_MASK))
goto do_fault_protect;
}
is_dirty = is_write && !(pde & PG_DIRTY_MASK);
if (!(pde & PG_ACCESSED_MASK) || is_dirty) {
pde |= PG_ACCESSED_MASK;
if (is_dirty)
pde |= PG_DIRTY_MASK;
stl_phys_notdirty(pde_addr, pde);
}
/* align to page_size */
pte = pde & ((PHYS_ADDR_MASK & ~(page_size - 1)) | 0xfff);
virt_addr = addr & ~(page_size - 1);
} else {
/* 4 KB page */
if (!(pde & PG_ACCESSED_MASK)) {
pde |= PG_ACCESSED_MASK;
stl_phys_notdirty(pde_addr, pde);
}
pte_addr = ((pde & PHYS_ADDR_MASK) + (((addr >> 12) & 0x1ff) << 3)) &
env->a20_mask;
pte = ldq_phys(pte_addr);
if (!(pte & PG_PRESENT_MASK)) {
error_code = 0;
goto do_fault;
}
if (!(env->efer & MSR_EFER_NXE) && (pte & PG_NX_MASK)) {
error_code = PG_ERROR_RSVD_MASK;
goto do_fault;
}
/* combine pde and pte nx, user and rw protections */
ptep &= pte ^ PG_NX_MASK;
ptep ^= PG_NX_MASK;
if ((ptep & PG_NX_MASK) && is_write1 == 2)
goto do_fault_protect;
if (is_user) {
if (!(ptep & PG_USER_MASK))
goto do_fault_protect;
if (is_write && !(ptep & PG_RW_MASK))
goto do_fault_protect;
} else {
if ((env->cr[0] & CR0_WP_MASK) &&
is_write && !(ptep & PG_RW_MASK))
goto do_fault_protect;
}
is_dirty = is_write && !(pte & PG_DIRTY_MASK);
if (!(pte & PG_ACCESSED_MASK) || is_dirty) {
pte |= PG_ACCESSED_MASK;
if (is_dirty)
pte |= PG_DIRTY_MASK;
stl_phys_notdirty(pte_addr, pte);
}
page_size = 4096;
virt_addr = addr & ~0xfff;
pte = pte & (PHYS_ADDR_MASK | 0xfff);
}
} else {
uint32_t pde;
/* page directory entry */
pde_addr = ((env->cr[3] & ~0xfff) + ((addr >> 20) & 0xffc)) &
env->a20_mask;
pde = ldl_phys(pde_addr);
if (!(pde & PG_PRESENT_MASK)) {
error_code = 0;
goto do_fault;
}
/* if PSE bit is set, then we use a 4MB page */
if ((pde & PG_PSE_MASK) && (env->cr[4] & CR4_PSE_MASK)) {
page_size = 4096 * 1024;
if (is_user) {
if (!(pde & PG_USER_MASK))
goto do_fault_protect;
if (is_write && !(pde & PG_RW_MASK))
goto do_fault_protect;
} else {
if ((env->cr[0] & CR0_WP_MASK) &&
is_write && !(pde & PG_RW_MASK))
goto do_fault_protect;
}
is_dirty = is_write && !(pde & PG_DIRTY_MASK);
if (!(pde & PG_ACCESSED_MASK) || is_dirty) {
pde |= PG_ACCESSED_MASK;
if (is_dirty)
pde |= PG_DIRTY_MASK;
stl_phys_notdirty(pde_addr, pde);
}
pte = pde & ~( (page_size - 1) & ~0xfff); /* align to page_size */
ptep = pte;
virt_addr = addr & ~(page_size - 1);
} else {
if (!(pde & PG_ACCESSED_MASK)) {
pde |= PG_ACCESSED_MASK;
stl_phys_notdirty(pde_addr, pde);
}
/* page directory entry */
pte_addr = ((pde & ~0xfff) + ((addr >> 10) & 0xffc)) &
env->a20_mask;
pte = ldl_phys(pte_addr);
if (!(pte & PG_PRESENT_MASK)) {
error_code = 0;
goto do_fault;
}
/* combine pde and pte user and rw protections */
ptep = pte & pde;
if (is_user) {
if (!(ptep & PG_USER_MASK))
goto do_fault_protect;
if (is_write && !(ptep & PG_RW_MASK))
goto do_fault_protect;
} else {
if ((env->cr[0] & CR0_WP_MASK) &&
is_write && !(ptep & PG_RW_MASK))
goto do_fault_protect;
}
is_dirty = is_write && !(pte & PG_DIRTY_MASK);
if (!(pte & PG_ACCESSED_MASK) || is_dirty) {
pte |= PG_ACCESSED_MASK;
if (is_dirty)
pte |= PG_DIRTY_MASK;
stl_phys_notdirty(pte_addr, pte);
}
page_size = 4096;
virt_addr = addr & ~0xfff;
}
}
/* the page can be put in the TLB */
prot = PAGE_READ;
if (!(ptep & PG_NX_MASK))
prot |= PAGE_EXEC;
if (pte & PG_DIRTY_MASK) {
/* only set write access if already dirty... otherwise wait
for dirty access */
if (is_user) {
if (ptep & PG_RW_MASK)
prot |= PAGE_WRITE;
} else {
if (!(env->cr[0] & CR0_WP_MASK) ||
(ptep & PG_RW_MASK))
prot |= PAGE_WRITE;
}
}
do_mapping:
pte = pte & env->a20_mask;
/* Even if 4MB pages, we map only one 4KB page in the cache to
avoid filling it too fast */
page_offset = (addr & TARGET_PAGE_MASK) & (page_size - 1);
paddr = (pte & TARGET_PAGE_MASK) + page_offset;
vaddr = virt_addr + page_offset;
ret = tlb_set_page_exec(env, vaddr, paddr, prot, mmu_idx, is_softmmu);
return ret;
do_fault_protect:
error_code = PG_ERROR_P_MASK;
do_fault:
error_code |= (is_write << PG_ERROR_W_BIT);
if (is_user)
error_code |= PG_ERROR_U_MASK;
if (is_write1 == 2 &&
(env->efer & MSR_EFER_NXE) &&
(env->cr[4] & CR4_PAE_MASK))
error_code |= PG_ERROR_I_D_MASK;
if (env->intercept_exceptions & (1 << EXCP0E_PAGE)) {
/* cr2 is not modified in case of exceptions */
stq_phys(env->vm_vmcb + offsetof(struct vmcb, control.exit_info_2),
addr);
} else {
env->cr[2] = addr;
}
env->error_code = error_code;
env->exception_index = EXCP0E_PAGE;
return 1;
}
| false | qemu | d4c430a80f000d722bb70287af4d4c184a8d7006 | int cpu_x86_handle_mmu_fault(CPUX86State *env, target_ulong addr,
int is_write1, int mmu_idx, int is_softmmu)
{
uint64_t ptep, pte;
target_ulong pde_addr, pte_addr;
int error_code, is_dirty, prot, page_size, ret, is_write, is_user;
target_phys_addr_t paddr;
uint32_t page_offset;
target_ulong vaddr, virt_addr;
is_user = mmu_idx == MMU_USER_IDX;
#if defined(DEBUG_MMU)
printf("MMU fault: addr=" TARGET_FMT_lx " w=%d u=%d eip=" TARGET_FMT_lx "\n",
addr, is_write1, is_user, env->eip);
#endif
is_write = is_write1 & 1;
if (!(env->cr[0] & CR0_PG_MASK)) {
pte = addr;
virt_addr = addr & TARGET_PAGE_MASK;
prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC;
page_size = 4096;
goto do_mapping;
}
if (env->cr[4] & CR4_PAE_MASK) {
uint64_t pde, pdpe;
target_ulong pdpe_addr;
#ifdef TARGET_X86_64
if (env->hflags & HF_LMA_MASK) {
uint64_t pml4e_addr, pml4e;
int32_t sext;
sext = (int64_t)addr >> 47;
if (sext != 0 && sext != -1) {
env->error_code = 0;
env->exception_index = EXCP0D_GPF;
return 1;
}
pml4e_addr = ((env->cr[3] & ~0xfff) + (((addr >> 39) & 0x1ff) << 3)) &
env->a20_mask;
pml4e = ldq_phys(pml4e_addr);
if (!(pml4e & PG_PRESENT_MASK)) {
error_code = 0;
goto do_fault;
}
if (!(env->efer & MSR_EFER_NXE) && (pml4e & PG_NX_MASK)) {
error_code = PG_ERROR_RSVD_MASK;
goto do_fault;
}
if (!(pml4e & PG_ACCESSED_MASK)) {
pml4e |= PG_ACCESSED_MASK;
stl_phys_notdirty(pml4e_addr, pml4e);
}
ptep = pml4e ^ PG_NX_MASK;
pdpe_addr = ((pml4e & PHYS_ADDR_MASK) + (((addr >> 30) & 0x1ff) << 3)) &
env->a20_mask;
pdpe = ldq_phys(pdpe_addr);
if (!(pdpe & PG_PRESENT_MASK)) {
error_code = 0;
goto do_fault;
}
if (!(env->efer & MSR_EFER_NXE) && (pdpe & PG_NX_MASK)) {
error_code = PG_ERROR_RSVD_MASK;
goto do_fault;
}
ptep &= pdpe ^ PG_NX_MASK;
if (!(pdpe & PG_ACCESSED_MASK)) {
pdpe |= PG_ACCESSED_MASK;
stl_phys_notdirty(pdpe_addr, pdpe);
}
} else
#endif
{
pdpe_addr = ((env->cr[3] & ~0x1f) + ((addr >> 27) & 0x18)) &
env->a20_mask;
pdpe = ldq_phys(pdpe_addr);
if (!(pdpe & PG_PRESENT_MASK)) {
error_code = 0;
goto do_fault;
}
ptep = PG_NX_MASK | PG_USER_MASK | PG_RW_MASK;
}
pde_addr = ((pdpe & PHYS_ADDR_MASK) + (((addr >> 21) & 0x1ff) << 3)) &
env->a20_mask;
pde = ldq_phys(pde_addr);
if (!(pde & PG_PRESENT_MASK)) {
error_code = 0;
goto do_fault;
}
if (!(env->efer & MSR_EFER_NXE) && (pde & PG_NX_MASK)) {
error_code = PG_ERROR_RSVD_MASK;
goto do_fault;
}
ptep &= pde ^ PG_NX_MASK;
if (pde & PG_PSE_MASK) {
page_size = 2048 * 1024;
ptep ^= PG_NX_MASK;
if ((ptep & PG_NX_MASK) && is_write1 == 2)
goto do_fault_protect;
if (is_user) {
if (!(ptep & PG_USER_MASK))
goto do_fault_protect;
if (is_write && !(ptep & PG_RW_MASK))
goto do_fault_protect;
} else {
if ((env->cr[0] & CR0_WP_MASK) &&
is_write && !(ptep & PG_RW_MASK))
goto do_fault_protect;
}
is_dirty = is_write && !(pde & PG_DIRTY_MASK);
if (!(pde & PG_ACCESSED_MASK) || is_dirty) {
pde |= PG_ACCESSED_MASK;
if (is_dirty)
pde |= PG_DIRTY_MASK;
stl_phys_notdirty(pde_addr, pde);
}
pte = pde & ((PHYS_ADDR_MASK & ~(page_size - 1)) | 0xfff);
virt_addr = addr & ~(page_size - 1);
} else {
if (!(pde & PG_ACCESSED_MASK)) {
pde |= PG_ACCESSED_MASK;
stl_phys_notdirty(pde_addr, pde);
}
pte_addr = ((pde & PHYS_ADDR_MASK) + (((addr >> 12) & 0x1ff) << 3)) &
env->a20_mask;
pte = ldq_phys(pte_addr);
if (!(pte & PG_PRESENT_MASK)) {
error_code = 0;
goto do_fault;
}
if (!(env->efer & MSR_EFER_NXE) && (pte & PG_NX_MASK)) {
error_code = PG_ERROR_RSVD_MASK;
goto do_fault;
}
ptep &= pte ^ PG_NX_MASK;
ptep ^= PG_NX_MASK;
if ((ptep & PG_NX_MASK) && is_write1 == 2)
goto do_fault_protect;
if (is_user) {
if (!(ptep & PG_USER_MASK))
goto do_fault_protect;
if (is_write && !(ptep & PG_RW_MASK))
goto do_fault_protect;
} else {
if ((env->cr[0] & CR0_WP_MASK) &&
is_write && !(ptep & PG_RW_MASK))
goto do_fault_protect;
}
is_dirty = is_write && !(pte & PG_DIRTY_MASK);
if (!(pte & PG_ACCESSED_MASK) || is_dirty) {
pte |= PG_ACCESSED_MASK;
if (is_dirty)
pte |= PG_DIRTY_MASK;
stl_phys_notdirty(pte_addr, pte);
}
page_size = 4096;
virt_addr = addr & ~0xfff;
pte = pte & (PHYS_ADDR_MASK | 0xfff);
}
} else {
uint32_t pde;
pde_addr = ((env->cr[3] & ~0xfff) + ((addr >> 20) & 0xffc)) &
env->a20_mask;
pde = ldl_phys(pde_addr);
if (!(pde & PG_PRESENT_MASK)) {
error_code = 0;
goto do_fault;
}
if ((pde & PG_PSE_MASK) && (env->cr[4] & CR4_PSE_MASK)) {
page_size = 4096 * 1024;
if (is_user) {
if (!(pde & PG_USER_MASK))
goto do_fault_protect;
if (is_write && !(pde & PG_RW_MASK))
goto do_fault_protect;
} else {
if ((env->cr[0] & CR0_WP_MASK) &&
is_write && !(pde & PG_RW_MASK))
goto do_fault_protect;
}
is_dirty = is_write && !(pde & PG_DIRTY_MASK);
if (!(pde & PG_ACCESSED_MASK) || is_dirty) {
pde |= PG_ACCESSED_MASK;
if (is_dirty)
pde |= PG_DIRTY_MASK;
stl_phys_notdirty(pde_addr, pde);
}
pte = pde & ~( (page_size - 1) & ~0xfff);
ptep = pte;
virt_addr = addr & ~(page_size - 1);
} else {
if (!(pde & PG_ACCESSED_MASK)) {
pde |= PG_ACCESSED_MASK;
stl_phys_notdirty(pde_addr, pde);
}
pte_addr = ((pde & ~0xfff) + ((addr >> 10) & 0xffc)) &
env->a20_mask;
pte = ldl_phys(pte_addr);
if (!(pte & PG_PRESENT_MASK)) {
error_code = 0;
goto do_fault;
}
ptep = pte & pde;
if (is_user) {
if (!(ptep & PG_USER_MASK))
goto do_fault_protect;
if (is_write && !(ptep & PG_RW_MASK))
goto do_fault_protect;
} else {
if ((env->cr[0] & CR0_WP_MASK) &&
is_write && !(ptep & PG_RW_MASK))
goto do_fault_protect;
}
is_dirty = is_write && !(pte & PG_DIRTY_MASK);
if (!(pte & PG_ACCESSED_MASK) || is_dirty) {
pte |= PG_ACCESSED_MASK;
if (is_dirty)
pte |= PG_DIRTY_MASK;
stl_phys_notdirty(pte_addr, pte);
}
page_size = 4096;
virt_addr = addr & ~0xfff;
}
}
prot = PAGE_READ;
if (!(ptep & PG_NX_MASK))
prot |= PAGE_EXEC;
if (pte & PG_DIRTY_MASK) {
if (is_user) {
if (ptep & PG_RW_MASK)
prot |= PAGE_WRITE;
} else {
if (!(env->cr[0] & CR0_WP_MASK) ||
(ptep & PG_RW_MASK))
prot |= PAGE_WRITE;
}
}
do_mapping:
pte = pte & env->a20_mask;
page_offset = (addr & TARGET_PAGE_MASK) & (page_size - 1);
paddr = (pte & TARGET_PAGE_MASK) + page_offset;
vaddr = virt_addr + page_offset;
ret = tlb_set_page_exec(env, vaddr, paddr, prot, mmu_idx, is_softmmu);
return ret;
do_fault_protect:
error_code = PG_ERROR_P_MASK;
do_fault:
error_code |= (is_write << PG_ERROR_W_BIT);
if (is_user)
error_code |= PG_ERROR_U_MASK;
if (is_write1 == 2 &&
(env->efer & MSR_EFER_NXE) &&
(env->cr[4] & CR4_PAE_MASK))
error_code |= PG_ERROR_I_D_MASK;
if (env->intercept_exceptions & (1 << EXCP0E_PAGE)) {
stq_phys(env->vm_vmcb + offsetof(struct vmcb, control.exit_info_2),
addr);
} else {
env->cr[2] = addr;
}
env->error_code = error_code;
env->exception_index = EXCP0E_PAGE;
return 1;
}
| {
"code": [],
"line_no": []
} | int FUNC_0(CPUX86State *VAR_0, target_ulong VAR_1,
int VAR_2, int VAR_3, int VAR_4)
{
uint64_t ptep, pte;
target_ulong pde_addr, pte_addr;
int VAR_5, VAR_6, VAR_7, VAR_8, VAR_9, VAR_10, VAR_11;
target_phys_addr_t paddr;
uint32_t page_offset;
target_ulong vaddr, virt_addr;
VAR_11 = VAR_3 == MMU_USER_IDX;
#if defined(DEBUG_MMU)
printf("MMU fault: VAR_1=" TARGET_FMT_lx " w=%d u=%d eip=" TARGET_FMT_lx "\n",
VAR_1, VAR_2, VAR_11, VAR_0->eip);
#endif
VAR_10 = VAR_2 & 1;
if (!(VAR_0->cr[0] & CR0_PG_MASK)) {
pte = VAR_1;
virt_addr = VAR_1 & TARGET_PAGE_MASK;
VAR_7 = PAGE_READ | PAGE_WRITE | PAGE_EXEC;
VAR_8 = 4096;
goto do_mapping;
}
if (VAR_0->cr[4] & CR4_PAE_MASK) {
uint64_t pde, pdpe;
target_ulong pdpe_addr;
#ifdef TARGET_X86_64
if (VAR_0->hflags & HF_LMA_MASK) {
uint64_t pml4e_addr, pml4e;
int32_t sext;
sext = (int64_t)VAR_1 >> 47;
if (sext != 0 && sext != -1) {
VAR_0->VAR_5 = 0;
VAR_0->exception_index = EXCP0D_GPF;
return 1;
}
pml4e_addr = ((VAR_0->cr[3] & ~0xfff) + (((VAR_1 >> 39) & 0x1ff) << 3)) &
VAR_0->a20_mask;
pml4e = ldq_phys(pml4e_addr);
if (!(pml4e & PG_PRESENT_MASK)) {
VAR_5 = 0;
goto do_fault;
}
if (!(VAR_0->efer & MSR_EFER_NXE) && (pml4e & PG_NX_MASK)) {
VAR_5 = PG_ERROR_RSVD_MASK;
goto do_fault;
}
if (!(pml4e & PG_ACCESSED_MASK)) {
pml4e |= PG_ACCESSED_MASK;
stl_phys_notdirty(pml4e_addr, pml4e);
}
ptep = pml4e ^ PG_NX_MASK;
pdpe_addr = ((pml4e & PHYS_ADDR_MASK) + (((VAR_1 >> 30) & 0x1ff) << 3)) &
VAR_0->a20_mask;
pdpe = ldq_phys(pdpe_addr);
if (!(pdpe & PG_PRESENT_MASK)) {
VAR_5 = 0;
goto do_fault;
}
if (!(VAR_0->efer & MSR_EFER_NXE) && (pdpe & PG_NX_MASK)) {
VAR_5 = PG_ERROR_RSVD_MASK;
goto do_fault;
}
ptep &= pdpe ^ PG_NX_MASK;
if (!(pdpe & PG_ACCESSED_MASK)) {
pdpe |= PG_ACCESSED_MASK;
stl_phys_notdirty(pdpe_addr, pdpe);
}
} else
#endif
{
pdpe_addr = ((VAR_0->cr[3] & ~0x1f) + ((VAR_1 >> 27) & 0x18)) &
VAR_0->a20_mask;
pdpe = ldq_phys(pdpe_addr);
if (!(pdpe & PG_PRESENT_MASK)) {
VAR_5 = 0;
goto do_fault;
}
ptep = PG_NX_MASK | PG_USER_MASK | PG_RW_MASK;
}
pde_addr = ((pdpe & PHYS_ADDR_MASK) + (((VAR_1 >> 21) & 0x1ff) << 3)) &
VAR_0->a20_mask;
pde = ldq_phys(pde_addr);
if (!(pde & PG_PRESENT_MASK)) {
VAR_5 = 0;
goto do_fault;
}
if (!(VAR_0->efer & MSR_EFER_NXE) && (pde & PG_NX_MASK)) {
VAR_5 = PG_ERROR_RSVD_MASK;
goto do_fault;
}
ptep &= pde ^ PG_NX_MASK;
if (pde & PG_PSE_MASK) {
VAR_8 = 2048 * 1024;
ptep ^= PG_NX_MASK;
if ((ptep & PG_NX_MASK) && VAR_2 == 2)
goto do_fault_protect;
if (VAR_11) {
if (!(ptep & PG_USER_MASK))
goto do_fault_protect;
if (VAR_10 && !(ptep & PG_RW_MASK))
goto do_fault_protect;
} else {
if ((VAR_0->cr[0] & CR0_WP_MASK) &&
VAR_10 && !(ptep & PG_RW_MASK))
goto do_fault_protect;
}
VAR_6 = VAR_10 && !(pde & PG_DIRTY_MASK);
if (!(pde & PG_ACCESSED_MASK) || VAR_6) {
pde |= PG_ACCESSED_MASK;
if (VAR_6)
pde |= PG_DIRTY_MASK;
stl_phys_notdirty(pde_addr, pde);
}
pte = pde & ((PHYS_ADDR_MASK & ~(VAR_8 - 1)) | 0xfff);
virt_addr = VAR_1 & ~(VAR_8 - 1);
} else {
if (!(pde & PG_ACCESSED_MASK)) {
pde |= PG_ACCESSED_MASK;
stl_phys_notdirty(pde_addr, pde);
}
pte_addr = ((pde & PHYS_ADDR_MASK) + (((VAR_1 >> 12) & 0x1ff) << 3)) &
VAR_0->a20_mask;
pte = ldq_phys(pte_addr);
if (!(pte & PG_PRESENT_MASK)) {
VAR_5 = 0;
goto do_fault;
}
if (!(VAR_0->efer & MSR_EFER_NXE) && (pte & PG_NX_MASK)) {
VAR_5 = PG_ERROR_RSVD_MASK;
goto do_fault;
}
ptep &= pte ^ PG_NX_MASK;
ptep ^= PG_NX_MASK;
if ((ptep & PG_NX_MASK) && VAR_2 == 2)
goto do_fault_protect;
if (VAR_11) {
if (!(ptep & PG_USER_MASK))
goto do_fault_protect;
if (VAR_10 && !(ptep & PG_RW_MASK))
goto do_fault_protect;
} else {
if ((VAR_0->cr[0] & CR0_WP_MASK) &&
VAR_10 && !(ptep & PG_RW_MASK))
goto do_fault_protect;
}
VAR_6 = VAR_10 && !(pte & PG_DIRTY_MASK);
if (!(pte & PG_ACCESSED_MASK) || VAR_6) {
pte |= PG_ACCESSED_MASK;
if (VAR_6)
pte |= PG_DIRTY_MASK;
stl_phys_notdirty(pte_addr, pte);
}
VAR_8 = 4096;
virt_addr = VAR_1 & ~0xfff;
pte = pte & (PHYS_ADDR_MASK | 0xfff);
}
} else {
uint32_t pde;
pde_addr = ((VAR_0->cr[3] & ~0xfff) + ((VAR_1 >> 20) & 0xffc)) &
VAR_0->a20_mask;
pde = ldl_phys(pde_addr);
if (!(pde & PG_PRESENT_MASK)) {
VAR_5 = 0;
goto do_fault;
}
if ((pde & PG_PSE_MASK) && (VAR_0->cr[4] & CR4_PSE_MASK)) {
VAR_8 = 4096 * 1024;
if (VAR_11) {
if (!(pde & PG_USER_MASK))
goto do_fault_protect;
if (VAR_10 && !(pde & PG_RW_MASK))
goto do_fault_protect;
} else {
if ((VAR_0->cr[0] & CR0_WP_MASK) &&
VAR_10 && !(pde & PG_RW_MASK))
goto do_fault_protect;
}
VAR_6 = VAR_10 && !(pde & PG_DIRTY_MASK);
if (!(pde & PG_ACCESSED_MASK) || VAR_6) {
pde |= PG_ACCESSED_MASK;
if (VAR_6)
pde |= PG_DIRTY_MASK;
stl_phys_notdirty(pde_addr, pde);
}
pte = pde & ~( (VAR_8 - 1) & ~0xfff);
ptep = pte;
virt_addr = VAR_1 & ~(VAR_8 - 1);
} else {
if (!(pde & PG_ACCESSED_MASK)) {
pde |= PG_ACCESSED_MASK;
stl_phys_notdirty(pde_addr, pde);
}
pte_addr = ((pde & ~0xfff) + ((VAR_1 >> 10) & 0xffc)) &
VAR_0->a20_mask;
pte = ldl_phys(pte_addr);
if (!(pte & PG_PRESENT_MASK)) {
VAR_5 = 0;
goto do_fault;
}
ptep = pte & pde;
if (VAR_11) {
if (!(ptep & PG_USER_MASK))
goto do_fault_protect;
if (VAR_10 && !(ptep & PG_RW_MASK))
goto do_fault_protect;
} else {
if ((VAR_0->cr[0] & CR0_WP_MASK) &&
VAR_10 && !(ptep & PG_RW_MASK))
goto do_fault_protect;
}
VAR_6 = VAR_10 && !(pte & PG_DIRTY_MASK);
if (!(pte & PG_ACCESSED_MASK) || VAR_6) {
pte |= PG_ACCESSED_MASK;
if (VAR_6)
pte |= PG_DIRTY_MASK;
stl_phys_notdirty(pte_addr, pte);
}
VAR_8 = 4096;
virt_addr = VAR_1 & ~0xfff;
}
}
VAR_7 = PAGE_READ;
if (!(ptep & PG_NX_MASK))
VAR_7 |= PAGE_EXEC;
if (pte & PG_DIRTY_MASK) {
if (VAR_11) {
if (ptep & PG_RW_MASK)
VAR_7 |= PAGE_WRITE;
} else {
if (!(VAR_0->cr[0] & CR0_WP_MASK) ||
(ptep & PG_RW_MASK))
VAR_7 |= PAGE_WRITE;
}
}
do_mapping:
pte = pte & VAR_0->a20_mask;
page_offset = (VAR_1 & TARGET_PAGE_MASK) & (VAR_8 - 1);
paddr = (pte & TARGET_PAGE_MASK) + page_offset;
vaddr = virt_addr + page_offset;
VAR_9 = tlb_set_page_exec(VAR_0, vaddr, paddr, VAR_7, VAR_3, VAR_4);
return VAR_9;
do_fault_protect:
VAR_5 = PG_ERROR_P_MASK;
do_fault:
VAR_5 |= (VAR_10 << PG_ERROR_W_BIT);
if (VAR_11)
VAR_5 |= PG_ERROR_U_MASK;
if (VAR_2 == 2 &&
(VAR_0->efer & MSR_EFER_NXE) &&
(VAR_0->cr[4] & CR4_PAE_MASK))
VAR_5 |= PG_ERROR_I_D_MASK;
if (VAR_0->intercept_exceptions & (1 << EXCP0E_PAGE)) {
stq_phys(VAR_0->vm_vmcb + offsetof(struct vmcb, control.exit_info_2),
VAR_1);
} else {
VAR_0->cr[2] = VAR_1;
}
VAR_0->VAR_5 = VAR_5;
VAR_0->exception_index = EXCP0E_PAGE;
return 1;
}
| [
"int FUNC_0(CPUX86State *VAR_0, target_ulong VAR_1,\nint VAR_2, int VAR_3, int VAR_4)\n{",
"uint64_t ptep, pte;",
"target_ulong pde_addr, pte_addr;",
"int VAR_5, VAR_6, VAR_7, VAR_8, VAR_9, VAR_10, VAR_11;",
"target_phys_addr_t paddr;",
"uint32_t page_offset;",
"target_ulong vaddr, virt_addr;",
"VAR_11 = VAR_3 == MMU_USER_IDX;",
"#if defined(DEBUG_MMU)\nprintf(\"MMU fault: VAR_1=\" TARGET_FMT_lx \" w=%d u=%d eip=\" TARGET_FMT_lx \"\\n\",\nVAR_1, VAR_2, VAR_11, VAR_0->eip);",
"#endif\nVAR_10 = VAR_2 & 1;",
"if (!(VAR_0->cr[0] & CR0_PG_MASK)) {",
"pte = VAR_1;",
"virt_addr = VAR_1 & TARGET_PAGE_MASK;",
"VAR_7 = PAGE_READ | PAGE_WRITE | PAGE_EXEC;",
"VAR_8 = 4096;",
"goto do_mapping;",
"}",
"if (VAR_0->cr[4] & CR4_PAE_MASK) {",
"uint64_t pde, pdpe;",
"target_ulong pdpe_addr;",
"#ifdef TARGET_X86_64\nif (VAR_0->hflags & HF_LMA_MASK) {",
"uint64_t pml4e_addr, pml4e;",
"int32_t sext;",
"sext = (int64_t)VAR_1 >> 47;",
"if (sext != 0 && sext != -1) {",
"VAR_0->VAR_5 = 0;",
"VAR_0->exception_index = EXCP0D_GPF;",
"return 1;",
"}",
"pml4e_addr = ((VAR_0->cr[3] & ~0xfff) + (((VAR_1 >> 39) & 0x1ff) << 3)) &\nVAR_0->a20_mask;",
"pml4e = ldq_phys(pml4e_addr);",
"if (!(pml4e & PG_PRESENT_MASK)) {",
"VAR_5 = 0;",
"goto do_fault;",
"}",
"if (!(VAR_0->efer & MSR_EFER_NXE) && (pml4e & PG_NX_MASK)) {",
"VAR_5 = PG_ERROR_RSVD_MASK;",
"goto do_fault;",
"}",
"if (!(pml4e & PG_ACCESSED_MASK)) {",
"pml4e |= PG_ACCESSED_MASK;",
"stl_phys_notdirty(pml4e_addr, pml4e);",
"}",
"ptep = pml4e ^ PG_NX_MASK;",
"pdpe_addr = ((pml4e & PHYS_ADDR_MASK) + (((VAR_1 >> 30) & 0x1ff) << 3)) &\nVAR_0->a20_mask;",
"pdpe = ldq_phys(pdpe_addr);",
"if (!(pdpe & PG_PRESENT_MASK)) {",
"VAR_5 = 0;",
"goto do_fault;",
"}",
"if (!(VAR_0->efer & MSR_EFER_NXE) && (pdpe & PG_NX_MASK)) {",
"VAR_5 = PG_ERROR_RSVD_MASK;",
"goto do_fault;",
"}",
"ptep &= pdpe ^ PG_NX_MASK;",
"if (!(pdpe & PG_ACCESSED_MASK)) {",
"pdpe |= PG_ACCESSED_MASK;",
"stl_phys_notdirty(pdpe_addr, pdpe);",
"}",
"} else",
"#endif\n{",
"pdpe_addr = ((VAR_0->cr[3] & ~0x1f) + ((VAR_1 >> 27) & 0x18)) &\nVAR_0->a20_mask;",
"pdpe = ldq_phys(pdpe_addr);",
"if (!(pdpe & PG_PRESENT_MASK)) {",
"VAR_5 = 0;",
"goto do_fault;",
"}",
"ptep = PG_NX_MASK | PG_USER_MASK | PG_RW_MASK;",
"}",
"pde_addr = ((pdpe & PHYS_ADDR_MASK) + (((VAR_1 >> 21) & 0x1ff) << 3)) &\nVAR_0->a20_mask;",
"pde = ldq_phys(pde_addr);",
"if (!(pde & PG_PRESENT_MASK)) {",
"VAR_5 = 0;",
"goto do_fault;",
"}",
"if (!(VAR_0->efer & MSR_EFER_NXE) && (pde & PG_NX_MASK)) {",
"VAR_5 = PG_ERROR_RSVD_MASK;",
"goto do_fault;",
"}",
"ptep &= pde ^ PG_NX_MASK;",
"if (pde & PG_PSE_MASK) {",
"VAR_8 = 2048 * 1024;",
"ptep ^= PG_NX_MASK;",
"if ((ptep & PG_NX_MASK) && VAR_2 == 2)\ngoto do_fault_protect;",
"if (VAR_11) {",
"if (!(ptep & PG_USER_MASK))\ngoto do_fault_protect;",
"if (VAR_10 && !(ptep & PG_RW_MASK))\ngoto do_fault_protect;",
"} else {",
"if ((VAR_0->cr[0] & CR0_WP_MASK) &&\nVAR_10 && !(ptep & PG_RW_MASK))\ngoto do_fault_protect;",
"}",
"VAR_6 = VAR_10 && !(pde & PG_DIRTY_MASK);",
"if (!(pde & PG_ACCESSED_MASK) || VAR_6) {",
"pde |= PG_ACCESSED_MASK;",
"if (VAR_6)\npde |= PG_DIRTY_MASK;",
"stl_phys_notdirty(pde_addr, pde);",
"}",
"pte = pde & ((PHYS_ADDR_MASK & ~(VAR_8 - 1)) | 0xfff);",
"virt_addr = VAR_1 & ~(VAR_8 - 1);",
"} else {",
"if (!(pde & PG_ACCESSED_MASK)) {",
"pde |= PG_ACCESSED_MASK;",
"stl_phys_notdirty(pde_addr, pde);",
"}",
"pte_addr = ((pde & PHYS_ADDR_MASK) + (((VAR_1 >> 12) & 0x1ff) << 3)) &\nVAR_0->a20_mask;",
"pte = ldq_phys(pte_addr);",
"if (!(pte & PG_PRESENT_MASK)) {",
"VAR_5 = 0;",
"goto do_fault;",
"}",
"if (!(VAR_0->efer & MSR_EFER_NXE) && (pte & PG_NX_MASK)) {",
"VAR_5 = PG_ERROR_RSVD_MASK;",
"goto do_fault;",
"}",
"ptep &= pte ^ PG_NX_MASK;",
"ptep ^= PG_NX_MASK;",
"if ((ptep & PG_NX_MASK) && VAR_2 == 2)\ngoto do_fault_protect;",
"if (VAR_11) {",
"if (!(ptep & PG_USER_MASK))\ngoto do_fault_protect;",
"if (VAR_10 && !(ptep & PG_RW_MASK))\ngoto do_fault_protect;",
"} else {",
"if ((VAR_0->cr[0] & CR0_WP_MASK) &&\nVAR_10 && !(ptep & PG_RW_MASK))\ngoto do_fault_protect;",
"}",
"VAR_6 = VAR_10 && !(pte & PG_DIRTY_MASK);",
"if (!(pte & PG_ACCESSED_MASK) || VAR_6) {",
"pte |= PG_ACCESSED_MASK;",
"if (VAR_6)\npte |= PG_DIRTY_MASK;",
"stl_phys_notdirty(pte_addr, pte);",
"}",
"VAR_8 = 4096;",
"virt_addr = VAR_1 & ~0xfff;",
"pte = pte & (PHYS_ADDR_MASK | 0xfff);",
"}",
"} else {",
"uint32_t pde;",
"pde_addr = ((VAR_0->cr[3] & ~0xfff) + ((VAR_1 >> 20) & 0xffc)) &\nVAR_0->a20_mask;",
"pde = ldl_phys(pde_addr);",
"if (!(pde & PG_PRESENT_MASK)) {",
"VAR_5 = 0;",
"goto do_fault;",
"}",
"if ((pde & PG_PSE_MASK) && (VAR_0->cr[4] & CR4_PSE_MASK)) {",
"VAR_8 = 4096 * 1024;",
"if (VAR_11) {",
"if (!(pde & PG_USER_MASK))\ngoto do_fault_protect;",
"if (VAR_10 && !(pde & PG_RW_MASK))\ngoto do_fault_protect;",
"} else {",
"if ((VAR_0->cr[0] & CR0_WP_MASK) &&\nVAR_10 && !(pde & PG_RW_MASK))\ngoto do_fault_protect;",
"}",
"VAR_6 = VAR_10 && !(pde & PG_DIRTY_MASK);",
"if (!(pde & PG_ACCESSED_MASK) || VAR_6) {",
"pde |= PG_ACCESSED_MASK;",
"if (VAR_6)\npde |= PG_DIRTY_MASK;",
"stl_phys_notdirty(pde_addr, pde);",
"}",
"pte = pde & ~( (VAR_8 - 1) & ~0xfff);",
"ptep = pte;",
"virt_addr = VAR_1 & ~(VAR_8 - 1);",
"} else {",
"if (!(pde & PG_ACCESSED_MASK)) {",
"pde |= PG_ACCESSED_MASK;",
"stl_phys_notdirty(pde_addr, pde);",
"}",
"pte_addr = ((pde & ~0xfff) + ((VAR_1 >> 10) & 0xffc)) &\nVAR_0->a20_mask;",
"pte = ldl_phys(pte_addr);",
"if (!(pte & PG_PRESENT_MASK)) {",
"VAR_5 = 0;",
"goto do_fault;",
"}",
"ptep = pte & pde;",
"if (VAR_11) {",
"if (!(ptep & PG_USER_MASK))\ngoto do_fault_protect;",
"if (VAR_10 && !(ptep & PG_RW_MASK))\ngoto do_fault_protect;",
"} else {",
"if ((VAR_0->cr[0] & CR0_WP_MASK) &&\nVAR_10 && !(ptep & PG_RW_MASK))\ngoto do_fault_protect;",
"}",
"VAR_6 = VAR_10 && !(pte & PG_DIRTY_MASK);",
"if (!(pte & PG_ACCESSED_MASK) || VAR_6) {",
"pte |= PG_ACCESSED_MASK;",
"if (VAR_6)\npte |= PG_DIRTY_MASK;",
"stl_phys_notdirty(pte_addr, pte);",
"}",
"VAR_8 = 4096;",
"virt_addr = VAR_1 & ~0xfff;",
"}",
"}",
"VAR_7 = PAGE_READ;",
"if (!(ptep & PG_NX_MASK))\nVAR_7 |= PAGE_EXEC;",
"if (pte & PG_DIRTY_MASK) {",
"if (VAR_11) {",
"if (ptep & PG_RW_MASK)\nVAR_7 |= PAGE_WRITE;",
"} else {",
"if (!(VAR_0->cr[0] & CR0_WP_MASK) ||\n(ptep & PG_RW_MASK))\nVAR_7 |= PAGE_WRITE;",
"}",
"}",
"do_mapping:\npte = pte & VAR_0->a20_mask;",
"page_offset = (VAR_1 & TARGET_PAGE_MASK) & (VAR_8 - 1);",
"paddr = (pte & TARGET_PAGE_MASK) + page_offset;",
"vaddr = virt_addr + page_offset;",
"VAR_9 = tlb_set_page_exec(VAR_0, vaddr, paddr, VAR_7, VAR_3, VAR_4);",
"return VAR_9;",
"do_fault_protect:\nVAR_5 = PG_ERROR_P_MASK;",
"do_fault:\nVAR_5 |= (VAR_10 << PG_ERROR_W_BIT);",
"if (VAR_11)\nVAR_5 |= PG_ERROR_U_MASK;",
"if (VAR_2 == 2 &&\n(VAR_0->efer & MSR_EFER_NXE) &&\n(VAR_0->cr[4] & CR4_PAE_MASK))\nVAR_5 |= PG_ERROR_I_D_MASK;",
"if (VAR_0->intercept_exceptions & (1 << EXCP0E_PAGE)) {",
"stq_phys(VAR_0->vm_vmcb + offsetof(struct vmcb, control.exit_info_2),\nVAR_1);",
"} else {",
"VAR_0->cr[2] = VAR_1;",
"}",
"VAR_0->VAR_5 = VAR_5;",
"VAR_0->exception_index = EXCP0E_PAGE;",
"return 1;",
"}"
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | [
[
1,
3,
5
],
[
7
],
[
9
],
[
11
],
[
13
],
[
15
],
[
17
],
[
21
],
[
23,
25,
27
],
[
29,
31
],
[
35
],
[
37
],
[
39
],
[
41
],
[
43
],
[
45
],
[
47
],
[
51
],
[
53
],
[
55
],
[
59,
61
],
[
63
],
[
65
],
[
71
],
[
73
],
[
75
],
[
77
],
[
79
],
[
81
],
[
85,
87
],
[
89
],
[
91
],
[
93
],
[
95
],
[
97
],
[
99
],
[
101
],
[
103
],
[
105
],
[
107
],
[
109
],
[
111
],
[
113
],
[
115
],
[
117,
119
],
[
121
],
[
123
],
[
125
],
[
127
],
[
129
],
[
131
],
[
133
],
[
135
],
[
137
],
[
139
],
[
141
],
[
143
],
[
145
],
[
147
],
[
149
],
[
151,
153
],
[
157,
159
],
[
161
],
[
163
],
[
165
],
[
167
],
[
169
],
[
171
],
[
173
],
[
177,
179
],
[
181
],
[
183
],
[
185
],
[
187
],
[
189
],
[
191
],
[
193
],
[
195
],
[
197
],
[
199
],
[
201
],
[
205
],
[
207
],
[
209,
211
],
[
213
],
[
215,
217
],
[
219,
221
],
[
223
],
[
225,
227,
229
],
[
231
],
[
233
],
[
235
],
[
237
],
[
239,
241
],
[
243
],
[
245
],
[
249
],
[
251
],
[
253
],
[
257
],
[
259
],
[
261
],
[
263
],
[
265,
267
],
[
269
],
[
271
],
[
273
],
[
275
],
[
277
],
[
279
],
[
281
],
[
283
],
[
285
],
[
289
],
[
291
],
[
293,
295
],
[
297
],
[
299,
301
],
[
303,
305
],
[
307
],
[
309,
311,
313
],
[
315
],
[
317
],
[
319
],
[
321
],
[
323,
325
],
[
327
],
[
329
],
[
331
],
[
333
],
[
335
],
[
337
],
[
339
],
[
341
],
[
347,
349
],
[
351
],
[
353
],
[
355
],
[
357
],
[
359
],
[
363
],
[
365
],
[
367
],
[
369,
371
],
[
373,
375
],
[
377
],
[
379,
381,
383
],
[
385
],
[
387
],
[
389
],
[
391
],
[
393,
395
],
[
397
],
[
399
],
[
403
],
[
405
],
[
407
],
[
409
],
[
411
],
[
413
],
[
415
],
[
417
],
[
423,
425
],
[
427
],
[
429
],
[
431
],
[
433
],
[
435
],
[
439
],
[
441
],
[
443,
445
],
[
447,
449
],
[
451
],
[
453,
455,
457
],
[
459
],
[
461
],
[
463
],
[
465
],
[
467,
469
],
[
471
],
[
473
],
[
475
],
[
477
],
[
479
],
[
481
],
[
485
],
[
487,
489
],
[
491
],
[
497
],
[
499,
501
],
[
503
],
[
505,
507,
509
],
[
511
],
[
513
],
[
515,
517
],
[
525
],
[
527
],
[
529
],
[
533
],
[
535
],
[
537,
539
],
[
541,
543
],
[
545,
547
],
[
549,
551,
553,
555
],
[
557
],
[
561,
563
],
[
565
],
[
567
],
[
569
],
[
571
],
[
573
],
[
575
],
[
577
]
] |
21,485 | static CharDriverState *qemu_chr_open_ringbuf(const char *id,
ChardevBackend *backend,
ChardevReturn *ret,
Error **errp)
{
ChardevRingbuf *opts = backend->u.ringbuf;
CharDriverState *chr;
RingBufCharDriver *d;
chr = qemu_chr_alloc();
d = g_malloc(sizeof(*d));
d->size = opts->has_size ? opts->size : 65536;
/* The size must be power of 2 */
if (d->size & (d->size - 1)) {
error_setg(errp, "size of ringbuf chardev must be power of two");
goto fail;
}
d->prod = 0;
d->cons = 0;
d->cbuf = g_malloc0(d->size);
chr->opaque = d;
chr->chr_write = ringbuf_chr_write;
chr->chr_close = ringbuf_chr_close;
return chr;
fail:
g_free(d);
g_free(chr);
return NULL;
}
| false | qemu | d0d7708ba29cbcc343364a46bff981e0ff88366f | static CharDriverState *qemu_chr_open_ringbuf(const char *id,
ChardevBackend *backend,
ChardevReturn *ret,
Error **errp)
{
ChardevRingbuf *opts = backend->u.ringbuf;
CharDriverState *chr;
RingBufCharDriver *d;
chr = qemu_chr_alloc();
d = g_malloc(sizeof(*d));
d->size = opts->has_size ? opts->size : 65536;
if (d->size & (d->size - 1)) {
error_setg(errp, "size of ringbuf chardev must be power of two");
goto fail;
}
d->prod = 0;
d->cons = 0;
d->cbuf = g_malloc0(d->size);
chr->opaque = d;
chr->chr_write = ringbuf_chr_write;
chr->chr_close = ringbuf_chr_close;
return chr;
fail:
g_free(d);
g_free(chr);
return NULL;
}
| {
"code": [],
"line_no": []
} | static CharDriverState *FUNC_0(const char *id,
ChardevBackend *backend,
ChardevReturn *ret,
Error **errp)
{
ChardevRingbuf *opts = backend->u.ringbuf;
CharDriverState *chr;
RingBufCharDriver *d;
chr = qemu_chr_alloc();
d = g_malloc(sizeof(*d));
d->size = opts->has_size ? opts->size : 65536;
if (d->size & (d->size - 1)) {
error_setg(errp, "size of ringbuf chardev must be power of two");
goto fail;
}
d->prod = 0;
d->cons = 0;
d->cbuf = g_malloc0(d->size);
chr->opaque = d;
chr->chr_write = ringbuf_chr_write;
chr->chr_close = ringbuf_chr_close;
return chr;
fail:
g_free(d);
g_free(chr);
return NULL;
}
| [
"static CharDriverState *FUNC_0(const char *id,\nChardevBackend *backend,\nChardevReturn *ret,\nError **errp)\n{",
"ChardevRingbuf *opts = backend->u.ringbuf;",
"CharDriverState *chr;",
"RingBufCharDriver *d;",
"chr = qemu_chr_alloc();",
"d = g_malloc(sizeof(*d));",
"d->size = opts->has_size ? opts->size : 65536;",
"if (d->size & (d->size - 1)) {",
"error_setg(errp, \"size of ringbuf chardev must be power of two\");",
"goto fail;",
"}",
"d->prod = 0;",
"d->cons = 0;",
"d->cbuf = g_malloc0(d->size);",
"chr->opaque = d;",
"chr->chr_write = ringbuf_chr_write;",
"chr->chr_close = ringbuf_chr_close;",
"return chr;",
"fail:\ng_free(d);",
"g_free(chr);",
"return NULL;",
"}"
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | [
[
1,
3,
5,
7,
9
],
[
11
],
[
13
],
[
15
],
[
19
],
[
21
],
[
25
],
[
31
],
[
33
],
[
35
],
[
37
],
[
41
],
[
43
],
[
45
],
[
49
],
[
51
],
[
53
],
[
57
],
[
61,
63
],
[
65
],
[
67
],
[
69
]
] |
21,486 | int avpriv_mpa_decode_header(AVCodecContext *avctx, uint32_t head, int *sample_rate, int *channels, int *frame_size, int *bit_rate)
{
MPADecodeHeader s1, *s = &s1;
if (ff_mpa_check_header(head) != 0)
return -1;
if (avpriv_mpegaudio_decode_header(s, head) != 0) {
return -1;
}
switch(s->layer) {
case 1:
avctx->codec_id = AV_CODEC_ID_MP1;
*frame_size = 384;
break;
case 2:
avctx->codec_id = AV_CODEC_ID_MP2;
*frame_size = 1152;
break;
default:
case 3:
if (avctx->codec_id != AV_CODEC_ID_MP3ADU)
avctx->codec_id = AV_CODEC_ID_MP3;
if (s->lsf)
*frame_size = 576;
else
*frame_size = 1152;
break;
}
*sample_rate = s->sample_rate;
*channels = s->nb_channels;
*bit_rate = s->bit_rate;
return s->frame_size;
}
| false | FFmpeg | 955aec3c7c7be39b659197e1ec379a09f2b7c41c | int avpriv_mpa_decode_header(AVCodecContext *avctx, uint32_t head, int *sample_rate, int *channels, int *frame_size, int *bit_rate)
{
MPADecodeHeader s1, *s = &s1;
if (ff_mpa_check_header(head) != 0)
return -1;
if (avpriv_mpegaudio_decode_header(s, head) != 0) {
return -1;
}
switch(s->layer) {
case 1:
avctx->codec_id = AV_CODEC_ID_MP1;
*frame_size = 384;
break;
case 2:
avctx->codec_id = AV_CODEC_ID_MP2;
*frame_size = 1152;
break;
default:
case 3:
if (avctx->codec_id != AV_CODEC_ID_MP3ADU)
avctx->codec_id = AV_CODEC_ID_MP3;
if (s->lsf)
*frame_size = 576;
else
*frame_size = 1152;
break;
}
*sample_rate = s->sample_rate;
*channels = s->nb_channels;
*bit_rate = s->bit_rate;
return s->frame_size;
}
| {
"code": [],
"line_no": []
} | int FUNC_0(AVCodecContext *VAR_0, uint32_t VAR_1, int *VAR_2, int *VAR_3, int *VAR_4, int *VAR_5)
{
MPADecodeHeader s1, *s = &s1;
if (ff_mpa_check_header(VAR_1) != 0)
return -1;
if (avpriv_mpegaudio_decode_header(s, VAR_1) != 0) {
return -1;
}
switch(s->layer) {
case 1:
VAR_0->codec_id = AV_CODEC_ID_MP1;
*VAR_4 = 384;
break;
case 2:
VAR_0->codec_id = AV_CODEC_ID_MP2;
*VAR_4 = 1152;
break;
default:
case 3:
if (VAR_0->codec_id != AV_CODEC_ID_MP3ADU)
VAR_0->codec_id = AV_CODEC_ID_MP3;
if (s->lsf)
*VAR_4 = 576;
else
*VAR_4 = 1152;
break;
}
*VAR_2 = s->VAR_2;
*VAR_3 = s->nb_channels;
*VAR_5 = s->VAR_5;
return s->VAR_4;
}
| [
"int FUNC_0(AVCodecContext *VAR_0, uint32_t VAR_1, int *VAR_2, int *VAR_3, int *VAR_4, int *VAR_5)\n{",
"MPADecodeHeader s1, *s = &s1;",
"if (ff_mpa_check_header(VAR_1) != 0)\nreturn -1;",
"if (avpriv_mpegaudio_decode_header(s, VAR_1) != 0) {",
"return -1;",
"}",
"switch(s->layer) {",
"case 1:\nVAR_0->codec_id = AV_CODEC_ID_MP1;",
"*VAR_4 = 384;",
"break;",
"case 2:\nVAR_0->codec_id = AV_CODEC_ID_MP2;",
"*VAR_4 = 1152;",
"break;",
"default:\ncase 3:\nif (VAR_0->codec_id != AV_CODEC_ID_MP3ADU)\nVAR_0->codec_id = AV_CODEC_ID_MP3;",
"if (s->lsf)\n*VAR_4 = 576;",
"else\n*VAR_4 = 1152;",
"break;",
"}",
"*VAR_2 = s->VAR_2;",
"*VAR_3 = s->nb_channels;",
"*VAR_5 = s->VAR_5;",
"return s->VAR_4;",
"}"
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | [
[
1,
3
],
[
5
],
[
9,
11
],
[
15
],
[
17
],
[
19
],
[
23
],
[
25,
27
],
[
29
],
[
31
],
[
33,
35
],
[
37
],
[
39
],
[
41,
43,
45,
47
],
[
49,
51
],
[
53,
55
],
[
57
],
[
59
],
[
63
],
[
65
],
[
67
],
[
69
],
[
71
]
] |
21,488 | static inline void gen_speundef (DisasContext *ctx)
{
RET_INVAL(ctx);
}
| false | qemu | e1833e1f96456fd8fc17463246fe0b2050e68efb | static inline void gen_speundef (DisasContext *ctx)
{
RET_INVAL(ctx);
}
| {
"code": [],
"line_no": []
} | static inline void FUNC_0 (DisasContext *VAR_0)
{
RET_INVAL(VAR_0);
}
| [
"static inline void FUNC_0 (DisasContext *VAR_0)\n{",
"RET_INVAL(VAR_0);",
"}"
] | [
0,
0,
0
] | [
[
1,
3
],
[
5
],
[
7
]
] |
21,489 | int kqemu_init(CPUState *env)
{
struct kqemu_init kinit;
int ret, version;
#ifdef _WIN32
DWORD temp;
#endif
if (!kqemu_allowed)
return -1;
#ifdef _WIN32
kqemu_fd = CreateFile(KQEMU_DEVICE, GENERIC_WRITE | GENERIC_READ,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,
NULL);
if (kqemu_fd == KQEMU_INVALID_FD) {
fprintf(stderr, "Could not open '%s' - QEMU acceleration layer not activated: %lu\n",
KQEMU_DEVICE, GetLastError());
return -1;
}
#else
kqemu_fd = open(KQEMU_DEVICE, O_RDWR);
if (kqemu_fd == KQEMU_INVALID_FD) {
fprintf(stderr, "Could not open '%s' - QEMU acceleration layer not activated: %s\n",
KQEMU_DEVICE, strerror(errno));
return -1;
}
#endif
version = 0;
#ifdef _WIN32
DeviceIoControl(kqemu_fd, KQEMU_GET_VERSION, NULL, 0,
&version, sizeof(version), &temp, NULL);
#else
ioctl(kqemu_fd, KQEMU_GET_VERSION, &version);
#endif
if (version != KQEMU_VERSION) {
fprintf(stderr, "Version mismatch between kqemu module and qemu (%08x %08x) - disabling kqemu use\n",
version, KQEMU_VERSION);
goto fail;
}
pages_to_flush = qemu_vmalloc(KQEMU_MAX_PAGES_TO_FLUSH *
sizeof(uint64_t));
if (!pages_to_flush)
goto fail;
ram_pages_to_update = qemu_vmalloc(KQEMU_MAX_RAM_PAGES_TO_UPDATE *
sizeof(uint64_t));
if (!ram_pages_to_update)
goto fail;
modified_ram_pages = qemu_vmalloc(KQEMU_MAX_MODIFIED_RAM_PAGES *
sizeof(uint64_t));
if (!modified_ram_pages)
goto fail;
modified_ram_pages_table =
qemu_mallocz(kqemu_phys_ram_size >> TARGET_PAGE_BITS);
if (!modified_ram_pages_table)
goto fail;
memset(&kinit, 0, sizeof(kinit)); /* set the paddings to zero */
kinit.ram_base = kqemu_phys_ram_base;
kinit.ram_size = kqemu_phys_ram_size;
kinit.ram_dirty = phys_ram_dirty;
kinit.pages_to_flush = pages_to_flush;
kinit.ram_pages_to_update = ram_pages_to_update;
kinit.modified_ram_pages = modified_ram_pages;
#ifdef _WIN32
ret = DeviceIoControl(kqemu_fd, KQEMU_INIT, &kinit, sizeof(kinit),
NULL, 0, &temp, NULL) == TRUE ? 0 : -1;
#else
ret = ioctl(kqemu_fd, KQEMU_INIT, &kinit);
#endif
if (ret < 0) {
fprintf(stderr, "Error %d while initializing QEMU acceleration layer - disabling it for now\n", ret);
fail:
kqemu_closefd(kqemu_fd);
kqemu_fd = KQEMU_INVALID_FD;
return -1;
}
kqemu_update_cpuid(env);
env->kqemu_enabled = kqemu_allowed;
nb_pages_to_flush = 0;
nb_ram_pages_to_update = 0;
qpi_init();
return 0;
}
| false | qemu | 4a1418e07bdcfaa3177739e04707ecaec75d89e1 | int kqemu_init(CPUState *env)
{
struct kqemu_init kinit;
int ret, version;
#ifdef _WIN32
DWORD temp;
#endif
if (!kqemu_allowed)
return -1;
#ifdef _WIN32
kqemu_fd = CreateFile(KQEMU_DEVICE, GENERIC_WRITE | GENERIC_READ,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,
NULL);
if (kqemu_fd == KQEMU_INVALID_FD) {
fprintf(stderr, "Could not open '%s' - QEMU acceleration layer not activated: %lu\n",
KQEMU_DEVICE, GetLastError());
return -1;
}
#else
kqemu_fd = open(KQEMU_DEVICE, O_RDWR);
if (kqemu_fd == KQEMU_INVALID_FD) {
fprintf(stderr, "Could not open '%s' - QEMU acceleration layer not activated: %s\n",
KQEMU_DEVICE, strerror(errno));
return -1;
}
#endif
version = 0;
#ifdef _WIN32
DeviceIoControl(kqemu_fd, KQEMU_GET_VERSION, NULL, 0,
&version, sizeof(version), &temp, NULL);
#else
ioctl(kqemu_fd, KQEMU_GET_VERSION, &version);
#endif
if (version != KQEMU_VERSION) {
fprintf(stderr, "Version mismatch between kqemu module and qemu (%08x %08x) - disabling kqemu use\n",
version, KQEMU_VERSION);
goto fail;
}
pages_to_flush = qemu_vmalloc(KQEMU_MAX_PAGES_TO_FLUSH *
sizeof(uint64_t));
if (!pages_to_flush)
goto fail;
ram_pages_to_update = qemu_vmalloc(KQEMU_MAX_RAM_PAGES_TO_UPDATE *
sizeof(uint64_t));
if (!ram_pages_to_update)
goto fail;
modified_ram_pages = qemu_vmalloc(KQEMU_MAX_MODIFIED_RAM_PAGES *
sizeof(uint64_t));
if (!modified_ram_pages)
goto fail;
modified_ram_pages_table =
qemu_mallocz(kqemu_phys_ram_size >> TARGET_PAGE_BITS);
if (!modified_ram_pages_table)
goto fail;
memset(&kinit, 0, sizeof(kinit));
kinit.ram_base = kqemu_phys_ram_base;
kinit.ram_size = kqemu_phys_ram_size;
kinit.ram_dirty = phys_ram_dirty;
kinit.pages_to_flush = pages_to_flush;
kinit.ram_pages_to_update = ram_pages_to_update;
kinit.modified_ram_pages = modified_ram_pages;
#ifdef _WIN32
ret = DeviceIoControl(kqemu_fd, KQEMU_INIT, &kinit, sizeof(kinit),
NULL, 0, &temp, NULL) == TRUE ? 0 : -1;
#else
ret = ioctl(kqemu_fd, KQEMU_INIT, &kinit);
#endif
if (ret < 0) {
fprintf(stderr, "Error %d while initializing QEMU acceleration layer - disabling it for now\n", ret);
fail:
kqemu_closefd(kqemu_fd);
kqemu_fd = KQEMU_INVALID_FD;
return -1;
}
kqemu_update_cpuid(env);
env->kqemu_enabled = kqemu_allowed;
nb_pages_to_flush = 0;
nb_ram_pages_to_update = 0;
qpi_init();
return 0;
}
| {
"code": [],
"line_no": []
} | int FUNC_0(CPUState *VAR_0)
{
struct FUNC_0 VAR_1;
int VAR_2, VAR_3;
#ifdef _WIN32
DWORD temp;
#endif
if (!kqemu_allowed)
return -1;
#ifdef _WIN32
kqemu_fd = CreateFile(KQEMU_DEVICE, GENERIC_WRITE | GENERIC_READ,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,
NULL);
if (kqemu_fd == KQEMU_INVALID_FD) {
fprintf(stderr, "Could not open '%s' - QEMU acceleration layer not activated: %lu\n",
KQEMU_DEVICE, GetLastError());
return -1;
}
#else
kqemu_fd = open(KQEMU_DEVICE, O_RDWR);
if (kqemu_fd == KQEMU_INVALID_FD) {
fprintf(stderr, "Could not open '%s' - QEMU acceleration layer not activated: %s\n",
KQEMU_DEVICE, strerror(errno));
return -1;
}
#endif
VAR_3 = 0;
#ifdef _WIN32
DeviceIoControl(kqemu_fd, KQEMU_GET_VERSION, NULL, 0,
&VAR_3, sizeof(VAR_3), &temp, NULL);
#else
ioctl(kqemu_fd, KQEMU_GET_VERSION, &VAR_3);
#endif
if (VAR_3 != KQEMU_VERSION) {
fprintf(stderr, "Version mismatch between kqemu module and qemu (%08x %08x) - disabling kqemu use\n",
VAR_3, KQEMU_VERSION);
goto fail;
}
pages_to_flush = qemu_vmalloc(KQEMU_MAX_PAGES_TO_FLUSH *
sizeof(uint64_t));
if (!pages_to_flush)
goto fail;
ram_pages_to_update = qemu_vmalloc(KQEMU_MAX_RAM_PAGES_TO_UPDATE *
sizeof(uint64_t));
if (!ram_pages_to_update)
goto fail;
modified_ram_pages = qemu_vmalloc(KQEMU_MAX_MODIFIED_RAM_PAGES *
sizeof(uint64_t));
if (!modified_ram_pages)
goto fail;
modified_ram_pages_table =
qemu_mallocz(kqemu_phys_ram_size >> TARGET_PAGE_BITS);
if (!modified_ram_pages_table)
goto fail;
memset(&VAR_1, 0, sizeof(VAR_1));
VAR_1.ram_base = kqemu_phys_ram_base;
VAR_1.ram_size = kqemu_phys_ram_size;
VAR_1.ram_dirty = phys_ram_dirty;
VAR_1.pages_to_flush = pages_to_flush;
VAR_1.ram_pages_to_update = ram_pages_to_update;
VAR_1.modified_ram_pages = modified_ram_pages;
#ifdef _WIN32
VAR_2 = DeviceIoControl(kqemu_fd, KQEMU_INIT, &VAR_1, sizeof(VAR_1),
NULL, 0, &temp, NULL) == TRUE ? 0 : -1;
#else
VAR_2 = ioctl(kqemu_fd, KQEMU_INIT, &VAR_1);
#endif
if (VAR_2 < 0) {
fprintf(stderr, "Error %d while initializing QEMU acceleration layer - disabling it for now\n", VAR_2);
fail:
kqemu_closefd(kqemu_fd);
kqemu_fd = KQEMU_INVALID_FD;
return -1;
}
kqemu_update_cpuid(VAR_0);
VAR_0->kqemu_enabled = kqemu_allowed;
nb_pages_to_flush = 0;
nb_ram_pages_to_update = 0;
qpi_init();
return 0;
}
| [
"int FUNC_0(CPUState *VAR_0)\n{",
"struct FUNC_0 VAR_1;",
"int VAR_2, VAR_3;",
"#ifdef _WIN32\nDWORD temp;",
"#endif\nif (!kqemu_allowed)\nreturn -1;",
"#ifdef _WIN32\nkqemu_fd = CreateFile(KQEMU_DEVICE, GENERIC_WRITE | GENERIC_READ,\nFILE_SHARE_READ | FILE_SHARE_WRITE,\nNULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,\nNULL);",
"if (kqemu_fd == KQEMU_INVALID_FD) {",
"fprintf(stderr, \"Could not open '%s' - QEMU acceleration layer not activated: %lu\\n\",\nKQEMU_DEVICE, GetLastError());",
"return -1;",
"}",
"#else\nkqemu_fd = open(KQEMU_DEVICE, O_RDWR);",
"if (kqemu_fd == KQEMU_INVALID_FD) {",
"fprintf(stderr, \"Could not open '%s' - QEMU acceleration layer not activated: %s\\n\",\nKQEMU_DEVICE, strerror(errno));",
"return -1;",
"}",
"#endif\nVAR_3 = 0;",
"#ifdef _WIN32\nDeviceIoControl(kqemu_fd, KQEMU_GET_VERSION, NULL, 0,\n&VAR_3, sizeof(VAR_3), &temp, NULL);",
"#else\nioctl(kqemu_fd, KQEMU_GET_VERSION, &VAR_3);",
"#endif\nif (VAR_3 != KQEMU_VERSION) {",
"fprintf(stderr, \"Version mismatch between kqemu module and qemu (%08x %08x) - disabling kqemu use\\n\",\nVAR_3, KQEMU_VERSION);",
"goto fail;",
"}",
"pages_to_flush = qemu_vmalloc(KQEMU_MAX_PAGES_TO_FLUSH *\nsizeof(uint64_t));",
"if (!pages_to_flush)\ngoto fail;",
"ram_pages_to_update = qemu_vmalloc(KQEMU_MAX_RAM_PAGES_TO_UPDATE *\nsizeof(uint64_t));",
"if (!ram_pages_to_update)\ngoto fail;",
"modified_ram_pages = qemu_vmalloc(KQEMU_MAX_MODIFIED_RAM_PAGES *\nsizeof(uint64_t));",
"if (!modified_ram_pages)\ngoto fail;",
"modified_ram_pages_table =\nqemu_mallocz(kqemu_phys_ram_size >> TARGET_PAGE_BITS);",
"if (!modified_ram_pages_table)\ngoto fail;",
"memset(&VAR_1, 0, sizeof(VAR_1));",
"VAR_1.ram_base = kqemu_phys_ram_base;",
"VAR_1.ram_size = kqemu_phys_ram_size;",
"VAR_1.ram_dirty = phys_ram_dirty;",
"VAR_1.pages_to_flush = pages_to_flush;",
"VAR_1.ram_pages_to_update = ram_pages_to_update;",
"VAR_1.modified_ram_pages = modified_ram_pages;",
"#ifdef _WIN32\nVAR_2 = DeviceIoControl(kqemu_fd, KQEMU_INIT, &VAR_1, sizeof(VAR_1),\nNULL, 0, &temp, NULL) == TRUE ? 0 : -1;",
"#else\nVAR_2 = ioctl(kqemu_fd, KQEMU_INIT, &VAR_1);",
"#endif\nif (VAR_2 < 0) {",
"fprintf(stderr, \"Error %d while initializing QEMU acceleration layer - disabling it for now\\n\", VAR_2);",
"fail:\nkqemu_closefd(kqemu_fd);",
"kqemu_fd = KQEMU_INVALID_FD;",
"return -1;",
"}",
"kqemu_update_cpuid(VAR_0);",
"VAR_0->kqemu_enabled = kqemu_allowed;",
"nb_pages_to_flush = 0;",
"nb_ram_pages_to_update = 0;",
"qpi_init();",
"return 0;",
"}"
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | [
[
1,
3
],
[
5
],
[
7
],
[
9,
11
],
[
13,
17,
19
],
[
23,
25,
27,
29,
31
],
[
33
],
[
35,
37
],
[
39
],
[
41
],
[
43,
45
],
[
47
],
[
49,
51
],
[
53
],
[
55
],
[
57,
59
],
[
61,
63,
65
],
[
67,
69
],
[
71,
73
],
[
75,
77
],
[
79
],
[
81
],
[
85,
87
],
[
89,
91
],
[
95,
97
],
[
99,
101
],
[
105,
107
],
[
109,
111
],
[
113,
115
],
[
117,
119
],
[
123
],
[
125
],
[
127
],
[
129
],
[
131
],
[
133
],
[
135
],
[
137,
139,
141
],
[
143,
145
],
[
147,
149
],
[
151
],
[
153,
155
],
[
157
],
[
159
],
[
161
],
[
163
],
[
165
],
[
167
],
[
169
],
[
173
],
[
175
],
[
177
]
] |
21,490 | POWERPC_FAMILY(POWER9)(ObjectClass *oc, void *data)
{
DeviceClass *dc = DEVICE_CLASS(oc);
PowerPCCPUClass *pcc = POWERPC_CPU_CLASS(oc);
dc->fw_name = "PowerPC,POWER9";
dc->desc = "POWER9";
dc->props = powerpc_servercpu_properties;
pcc->pvr_match = ppc_pvr_match_power9;
pcc->pcr_mask = PCR_COMPAT_2_05 | PCR_COMPAT_2_06 | PCR_COMPAT_2_07;
pcc->pcr_supported = PCR_COMPAT_3_00 | PCR_COMPAT_2_07 | PCR_COMPAT_2_06 |
PCR_COMPAT_2_05;
pcc->init_proc = init_proc_POWER9;
pcc->check_pow = check_pow_nocheck;
pcc->insns_flags = PPC_INSNS_BASE | PPC_ISEL | PPC_STRING | PPC_MFTB |
PPC_FLOAT | PPC_FLOAT_FSEL | PPC_FLOAT_FRES |
PPC_FLOAT_FSQRT | PPC_FLOAT_FRSQRTE |
PPC_FLOAT_FRSQRTES |
PPC_FLOAT_STFIWX |
PPC_FLOAT_EXT |
PPC_CACHE | PPC_CACHE_ICBI | PPC_CACHE_DCBZ |
PPC_MEM_SYNC | PPC_MEM_EIEIO |
PPC_MEM_TLBIE | PPC_MEM_TLBSYNC |
PPC_64B | PPC_64BX | PPC_ALTIVEC |
PPC_SEGMENT_64B | PPC_SLBI |
PPC_POPCNTB | PPC_POPCNTWD |
PPC_CILDST;
pcc->insns_flags2 = PPC2_VSX | PPC2_VSX207 | PPC2_DFP | PPC2_DBRX |
PPC2_PERM_ISA206 | PPC2_DIVE_ISA206 |
PPC2_ATOMIC_ISA206 | PPC2_FP_CVT_ISA206 |
PPC2_FP_TST_ISA206 | PPC2_BCTAR_ISA207 |
PPC2_LSQ_ISA207 | PPC2_ALTIVEC_207 |
PPC2_ISA205 | PPC2_ISA207S | PPC2_FP_CVT_S64 |
PPC2_TM | PPC2_PM_ISA206 | PPC2_ISA300;
pcc->msr_mask = (1ull << MSR_SF) |
(1ull << MSR_TM) |
(1ull << MSR_VR) |
(1ull << MSR_VSX) |
(1ull << MSR_EE) |
(1ull << MSR_PR) |
(1ull << MSR_FP) |
(1ull << MSR_ME) |
(1ull << MSR_FE0) |
(1ull << MSR_SE) |
(1ull << MSR_DE) |
(1ull << MSR_FE1) |
(1ull << MSR_IR) |
(1ull << MSR_DR) |
(1ull << MSR_PMM) |
(1ull << MSR_RI) |
(1ull << MSR_LE);
pcc->mmu_model = POWERPC_MMU_3_00;
#if defined(CONFIG_SOFTMMU)
pcc->handle_mmu_fault = ppc_hash64_handle_mmu_fault;
/* segment page size remain the same */
pcc->sps = &POWER7_POWER8_sps;
#endif
pcc->excp_model = POWERPC_EXCP_POWER8;
pcc->bus_model = PPC_FLAGS_INPUT_POWER7;
pcc->bfd_mach = bfd_mach_ppc64;
pcc->flags = POWERPC_FLAG_VRE | POWERPC_FLAG_SE |
POWERPC_FLAG_BE | POWERPC_FLAG_PMM |
POWERPC_FLAG_BUS_CLK | POWERPC_FLAG_CFAR |
POWERPC_FLAG_VSX | POWERPC_FLAG_TM;
pcc->l1_dcache_size = 0x8000;
pcc->l1_icache_size = 0x8000;
pcc->interrupts_big_endian = ppc_cpu_interrupts_big_endian_lpcr;
}
| false | qemu | b2899495e3bd467adb9ef195655407cd58a97ded | POWERPC_FAMILY(POWER9)(ObjectClass *oc, void *data)
{
DeviceClass *dc = DEVICE_CLASS(oc);
PowerPCCPUClass *pcc = POWERPC_CPU_CLASS(oc);
dc->fw_name = "PowerPC,POWER9";
dc->desc = "POWER9";
dc->props = powerpc_servercpu_properties;
pcc->pvr_match = ppc_pvr_match_power9;
pcc->pcr_mask = PCR_COMPAT_2_05 | PCR_COMPAT_2_06 | PCR_COMPAT_2_07;
pcc->pcr_supported = PCR_COMPAT_3_00 | PCR_COMPAT_2_07 | PCR_COMPAT_2_06 |
PCR_COMPAT_2_05;
pcc->init_proc = init_proc_POWER9;
pcc->check_pow = check_pow_nocheck;
pcc->insns_flags = PPC_INSNS_BASE | PPC_ISEL | PPC_STRING | PPC_MFTB |
PPC_FLOAT | PPC_FLOAT_FSEL | PPC_FLOAT_FRES |
PPC_FLOAT_FSQRT | PPC_FLOAT_FRSQRTE |
PPC_FLOAT_FRSQRTES |
PPC_FLOAT_STFIWX |
PPC_FLOAT_EXT |
PPC_CACHE | PPC_CACHE_ICBI | PPC_CACHE_DCBZ |
PPC_MEM_SYNC | PPC_MEM_EIEIO |
PPC_MEM_TLBIE | PPC_MEM_TLBSYNC |
PPC_64B | PPC_64BX | PPC_ALTIVEC |
PPC_SEGMENT_64B | PPC_SLBI |
PPC_POPCNTB | PPC_POPCNTWD |
PPC_CILDST;
pcc->insns_flags2 = PPC2_VSX | PPC2_VSX207 | PPC2_DFP | PPC2_DBRX |
PPC2_PERM_ISA206 | PPC2_DIVE_ISA206 |
PPC2_ATOMIC_ISA206 | PPC2_FP_CVT_ISA206 |
PPC2_FP_TST_ISA206 | PPC2_BCTAR_ISA207 |
PPC2_LSQ_ISA207 | PPC2_ALTIVEC_207 |
PPC2_ISA205 | PPC2_ISA207S | PPC2_FP_CVT_S64 |
PPC2_TM | PPC2_PM_ISA206 | PPC2_ISA300;
pcc->msr_mask = (1ull << MSR_SF) |
(1ull << MSR_TM) |
(1ull << MSR_VR) |
(1ull << MSR_VSX) |
(1ull << MSR_EE) |
(1ull << MSR_PR) |
(1ull << MSR_FP) |
(1ull << MSR_ME) |
(1ull << MSR_FE0) |
(1ull << MSR_SE) |
(1ull << MSR_DE) |
(1ull << MSR_FE1) |
(1ull << MSR_IR) |
(1ull << MSR_DR) |
(1ull << MSR_PMM) |
(1ull << MSR_RI) |
(1ull << MSR_LE);
pcc->mmu_model = POWERPC_MMU_3_00;
#if defined(CONFIG_SOFTMMU)
pcc->handle_mmu_fault = ppc_hash64_handle_mmu_fault;
pcc->sps = &POWER7_POWER8_sps;
#endif
pcc->excp_model = POWERPC_EXCP_POWER8;
pcc->bus_model = PPC_FLAGS_INPUT_POWER7;
pcc->bfd_mach = bfd_mach_ppc64;
pcc->flags = POWERPC_FLAG_VRE | POWERPC_FLAG_SE |
POWERPC_FLAG_BE | POWERPC_FLAG_PMM |
POWERPC_FLAG_BUS_CLK | POWERPC_FLAG_CFAR |
POWERPC_FLAG_VSX | POWERPC_FLAG_TM;
pcc->l1_dcache_size = 0x8000;
pcc->l1_icache_size = 0x8000;
pcc->interrupts_big_endian = ppc_cpu_interrupts_big_endian_lpcr;
}
| {
"code": [],
"line_no": []
} | FUNC_0(POWER9)(ObjectClass *oc, void *data)
{
DeviceClass *dc = DEVICE_CLASS(oc);
PowerPCCPUClass *pcc = POWERPC_CPU_CLASS(oc);
dc->fw_name = "PowerPC,POWER9";
dc->desc = "POWER9";
dc->props = powerpc_servercpu_properties;
pcc->pvr_match = ppc_pvr_match_power9;
pcc->pcr_mask = PCR_COMPAT_2_05 | PCR_COMPAT_2_06 | PCR_COMPAT_2_07;
pcc->pcr_supported = PCR_COMPAT_3_00 | PCR_COMPAT_2_07 | PCR_COMPAT_2_06 |
PCR_COMPAT_2_05;
pcc->init_proc = init_proc_POWER9;
pcc->check_pow = check_pow_nocheck;
pcc->insns_flags = PPC_INSNS_BASE | PPC_ISEL | PPC_STRING | PPC_MFTB |
PPC_FLOAT | PPC_FLOAT_FSEL | PPC_FLOAT_FRES |
PPC_FLOAT_FSQRT | PPC_FLOAT_FRSQRTE |
PPC_FLOAT_FRSQRTES |
PPC_FLOAT_STFIWX |
PPC_FLOAT_EXT |
PPC_CACHE | PPC_CACHE_ICBI | PPC_CACHE_DCBZ |
PPC_MEM_SYNC | PPC_MEM_EIEIO |
PPC_MEM_TLBIE | PPC_MEM_TLBSYNC |
PPC_64B | PPC_64BX | PPC_ALTIVEC |
PPC_SEGMENT_64B | PPC_SLBI |
PPC_POPCNTB | PPC_POPCNTWD |
PPC_CILDST;
pcc->insns_flags2 = PPC2_VSX | PPC2_VSX207 | PPC2_DFP | PPC2_DBRX |
PPC2_PERM_ISA206 | PPC2_DIVE_ISA206 |
PPC2_ATOMIC_ISA206 | PPC2_FP_CVT_ISA206 |
PPC2_FP_TST_ISA206 | PPC2_BCTAR_ISA207 |
PPC2_LSQ_ISA207 | PPC2_ALTIVEC_207 |
PPC2_ISA205 | PPC2_ISA207S | PPC2_FP_CVT_S64 |
PPC2_TM | PPC2_PM_ISA206 | PPC2_ISA300;
pcc->msr_mask = (1ull << MSR_SF) |
(1ull << MSR_TM) |
(1ull << MSR_VR) |
(1ull << MSR_VSX) |
(1ull << MSR_EE) |
(1ull << MSR_PR) |
(1ull << MSR_FP) |
(1ull << MSR_ME) |
(1ull << MSR_FE0) |
(1ull << MSR_SE) |
(1ull << MSR_DE) |
(1ull << MSR_FE1) |
(1ull << MSR_IR) |
(1ull << MSR_DR) |
(1ull << MSR_PMM) |
(1ull << MSR_RI) |
(1ull << MSR_LE);
pcc->mmu_model = POWERPC_MMU_3_00;
#if defined(CONFIG_SOFTMMU)
pcc->handle_mmu_fault = ppc_hash64_handle_mmu_fault;
pcc->sps = &POWER7_POWER8_sps;
#endif
pcc->excp_model = POWERPC_EXCP_POWER8;
pcc->bus_model = PPC_FLAGS_INPUT_POWER7;
pcc->bfd_mach = bfd_mach_ppc64;
pcc->flags = POWERPC_FLAG_VRE | POWERPC_FLAG_SE |
POWERPC_FLAG_BE | POWERPC_FLAG_PMM |
POWERPC_FLAG_BUS_CLK | POWERPC_FLAG_CFAR |
POWERPC_FLAG_VSX | POWERPC_FLAG_TM;
pcc->l1_dcache_size = 0x8000;
pcc->l1_icache_size = 0x8000;
pcc->interrupts_big_endian = ppc_cpu_interrupts_big_endian_lpcr;
}
| [
"FUNC_0(POWER9)(ObjectClass *oc, void *data)\n{",
"DeviceClass *dc = DEVICE_CLASS(oc);",
"PowerPCCPUClass *pcc = POWERPC_CPU_CLASS(oc);",
"dc->fw_name = \"PowerPC,POWER9\";",
"dc->desc = \"POWER9\";",
"dc->props = powerpc_servercpu_properties;",
"pcc->pvr_match = ppc_pvr_match_power9;",
"pcc->pcr_mask = PCR_COMPAT_2_05 | PCR_COMPAT_2_06 | PCR_COMPAT_2_07;",
"pcc->pcr_supported = PCR_COMPAT_3_00 | PCR_COMPAT_2_07 | PCR_COMPAT_2_06 |\nPCR_COMPAT_2_05;",
"pcc->init_proc = init_proc_POWER9;",
"pcc->check_pow = check_pow_nocheck;",
"pcc->insns_flags = PPC_INSNS_BASE | PPC_ISEL | PPC_STRING | PPC_MFTB |\nPPC_FLOAT | PPC_FLOAT_FSEL | PPC_FLOAT_FRES |\nPPC_FLOAT_FSQRT | PPC_FLOAT_FRSQRTE |\nPPC_FLOAT_FRSQRTES |\nPPC_FLOAT_STFIWX |\nPPC_FLOAT_EXT |\nPPC_CACHE | PPC_CACHE_ICBI | PPC_CACHE_DCBZ |\nPPC_MEM_SYNC | PPC_MEM_EIEIO |\nPPC_MEM_TLBIE | PPC_MEM_TLBSYNC |\nPPC_64B | PPC_64BX | PPC_ALTIVEC |\nPPC_SEGMENT_64B | PPC_SLBI |\nPPC_POPCNTB | PPC_POPCNTWD |\nPPC_CILDST;",
"pcc->insns_flags2 = PPC2_VSX | PPC2_VSX207 | PPC2_DFP | PPC2_DBRX |\nPPC2_PERM_ISA206 | PPC2_DIVE_ISA206 |\nPPC2_ATOMIC_ISA206 | PPC2_FP_CVT_ISA206 |\nPPC2_FP_TST_ISA206 | PPC2_BCTAR_ISA207 |\nPPC2_LSQ_ISA207 | PPC2_ALTIVEC_207 |\nPPC2_ISA205 | PPC2_ISA207S | PPC2_FP_CVT_S64 |\nPPC2_TM | PPC2_PM_ISA206 | PPC2_ISA300;",
"pcc->msr_mask = (1ull << MSR_SF) |\n(1ull << MSR_TM) |\n(1ull << MSR_VR) |\n(1ull << MSR_VSX) |\n(1ull << MSR_EE) |\n(1ull << MSR_PR) |\n(1ull << MSR_FP) |\n(1ull << MSR_ME) |\n(1ull << MSR_FE0) |\n(1ull << MSR_SE) |\n(1ull << MSR_DE) |\n(1ull << MSR_FE1) |\n(1ull << MSR_IR) |\n(1ull << MSR_DR) |\n(1ull << MSR_PMM) |\n(1ull << MSR_RI) |\n(1ull << MSR_LE);",
"pcc->mmu_model = POWERPC_MMU_3_00;",
"#if defined(CONFIG_SOFTMMU)\npcc->handle_mmu_fault = ppc_hash64_handle_mmu_fault;",
"pcc->sps = &POWER7_POWER8_sps;",
"#endif\npcc->excp_model = POWERPC_EXCP_POWER8;",
"pcc->bus_model = PPC_FLAGS_INPUT_POWER7;",
"pcc->bfd_mach = bfd_mach_ppc64;",
"pcc->flags = POWERPC_FLAG_VRE | POWERPC_FLAG_SE |\nPOWERPC_FLAG_BE | POWERPC_FLAG_PMM |\nPOWERPC_FLAG_BUS_CLK | POWERPC_FLAG_CFAR |\nPOWERPC_FLAG_VSX | POWERPC_FLAG_TM;",
"pcc->l1_dcache_size = 0x8000;",
"pcc->l1_icache_size = 0x8000;",
"pcc->interrupts_big_endian = ppc_cpu_interrupts_big_endian_lpcr;",
"}"
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | [
[
1,
3
],
[
5
],
[
7
],
[
11
],
[
13
],
[
15
],
[
17
],
[
19
],
[
21,
23
],
[
25
],
[
27
],
[
29,
31,
33,
35,
37,
39,
41,
43,
45,
47,
49,
51,
53
],
[
55,
57,
59,
61,
63,
65,
67
],
[
69,
71,
73,
75,
77,
79,
81,
83,
85,
87,
89,
91,
93,
95,
97,
99,
101
],
[
103
],
[
105,
107
],
[
111
],
[
113,
115
],
[
117
],
[
119
],
[
121,
123,
125,
127
],
[
129
],
[
131
],
[
133
],
[
135
]
] |
21,491 | int cpu_get_dump_info(ArchDumpInfo *info,
const GuestPhysBlockList *guest_phys_blocks)
{
bool lma = false;
GuestPhysBlock *block;
#ifdef TARGET_X86_64
X86CPU *first_x86_cpu = X86_CPU(first_cpu);
lma = !!(first_x86_cpu->env.hflags & HF_LMA_MASK);
#endif
if (lma) {
info->d_machine = EM_X86_64;
} else {
info->d_machine = EM_386;
}
info->d_endian = ELFDATA2LSB;
if (lma) {
info->d_class = ELFCLASS64;
} else {
info->d_class = ELFCLASS32;
QTAILQ_FOREACH(block, &guest_phys_blocks->head, next) {
if (block->target_end > UINT_MAX) {
/* The memory size is greater than 4G */
info->d_class = ELFCLASS64;
break;
}
}
}
return 0;
}
| false | qemu | fd5d23babf9838c1b099a9e8020e778aac0ebb4d | int cpu_get_dump_info(ArchDumpInfo *info,
const GuestPhysBlockList *guest_phys_blocks)
{
bool lma = false;
GuestPhysBlock *block;
#ifdef TARGET_X86_64
X86CPU *first_x86_cpu = X86_CPU(first_cpu);
lma = !!(first_x86_cpu->env.hflags & HF_LMA_MASK);
#endif
if (lma) {
info->d_machine = EM_X86_64;
} else {
info->d_machine = EM_386;
}
info->d_endian = ELFDATA2LSB;
if (lma) {
info->d_class = ELFCLASS64;
} else {
info->d_class = ELFCLASS32;
QTAILQ_FOREACH(block, &guest_phys_blocks->head, next) {
if (block->target_end > UINT_MAX) {
info->d_class = ELFCLASS64;
break;
}
}
}
return 0;
}
| {
"code": [],
"line_no": []
} | int FUNC_0(ArchDumpInfo *VAR_0,
const GuestPhysBlockList *VAR_1)
{
bool lma = false;
GuestPhysBlock *block;
#ifdef TARGET_X86_64
X86CPU *first_x86_cpu = X86_CPU(first_cpu);
lma = !!(first_x86_cpu->env.hflags & HF_LMA_MASK);
#endif
if (lma) {
VAR_0->d_machine = EM_X86_64;
} else {
VAR_0->d_machine = EM_386;
}
VAR_0->d_endian = ELFDATA2LSB;
if (lma) {
VAR_0->d_class = ELFCLASS64;
} else {
VAR_0->d_class = ELFCLASS32;
QTAILQ_FOREACH(block, &VAR_1->head, next) {
if (block->target_end > UINT_MAX) {
VAR_0->d_class = ELFCLASS64;
break;
}
}
}
return 0;
}
| [
"int FUNC_0(ArchDumpInfo *VAR_0,\nconst GuestPhysBlockList *VAR_1)\n{",
"bool lma = false;",
"GuestPhysBlock *block;",
"#ifdef TARGET_X86_64\nX86CPU *first_x86_cpu = X86_CPU(first_cpu);",
"lma = !!(first_x86_cpu->env.hflags & HF_LMA_MASK);",
"#endif\nif (lma) {",
"VAR_0->d_machine = EM_X86_64;",
"} else {",
"VAR_0->d_machine = EM_386;",
"}",
"VAR_0->d_endian = ELFDATA2LSB;",
"if (lma) {",
"VAR_0->d_class = ELFCLASS64;",
"} else {",
"VAR_0->d_class = ELFCLASS32;",
"QTAILQ_FOREACH(block, &VAR_1->head, next) {",
"if (block->target_end > UINT_MAX) {",
"VAR_0->d_class = ELFCLASS64;",
"break;",
"}",
"}",
"}",
"return 0;",
"}"
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | [
[
1,
3,
5
],
[
7
],
[
9
],
[
13,
15
],
[
19
],
[
21,
25
],
[
27
],
[
29
],
[
31
],
[
33
],
[
35
],
[
39
],
[
41
],
[
43
],
[
45
],
[
49
],
[
51
],
[
55
],
[
57
],
[
59
],
[
61
],
[
63
],
[
67
],
[
69
]
] |
21,493 | static void handler_audit(Monitor *mon, const mon_cmd_t *cmd, int ret)
{
if (ret && !monitor_has_error(mon)) {
/*
* If it returns failure, it must have passed on error.
*
* Action: Report an internal error to the client if in QMP.
*/
if (monitor_ctrl_mode(mon)) {
qerror_report(QERR_UNDEFINED_ERROR);
}
MON_DEBUG("command '%s' returned failure but did not pass an error\n",
cmd->name);
}
#ifdef CONFIG_DEBUG_MONITOR
if (!ret && monitor_has_error(mon)) {
/*
* If it returns success, it must not have passed an error.
*
* Action: Report the passed error to the client.
*/
MON_DEBUG("command '%s' returned success but passed an error\n",
cmd->name);
}
if (mon_print_count_get(mon) > 0 && strcmp(cmd->name, "info") != 0) {
/*
* Handlers should not call Monitor print functions.
*
* Action: Ignore them in QMP.
*
* (XXX: we don't check any 'info' or 'query' command here
* because the user print function _is_ called by do_info(), hence
* we will trigger this check. This problem will go away when we
* make 'query' commands real and kill do_info())
*/
MON_DEBUG("command '%s' called print functions %d time(s)\n",
cmd->name, mon_print_count_get(mon));
}
#endif
}
| false | qemu | cde0fc7544ca590c83f349d4dcccf375d55d6042 | static void handler_audit(Monitor *mon, const mon_cmd_t *cmd, int ret)
{
if (ret && !monitor_has_error(mon)) {
if (monitor_ctrl_mode(mon)) {
qerror_report(QERR_UNDEFINED_ERROR);
}
MON_DEBUG("command '%s' returned failure but did not pass an error\n",
cmd->name);
}
#ifdef CONFIG_DEBUG_MONITOR
if (!ret && monitor_has_error(mon)) {
MON_DEBUG("command '%s' returned success but passed an error\n",
cmd->name);
}
if (mon_print_count_get(mon) > 0 && strcmp(cmd->name, "info") != 0) {
MON_DEBUG("command '%s' called print functions %d time(s)\n",
cmd->name, mon_print_count_get(mon));
}
#endif
}
| {
"code": [],
"line_no": []
} | static void FUNC_0(Monitor *VAR_0, const mon_cmd_t *VAR_1, int VAR_2)
{
if (VAR_2 && !monitor_has_error(VAR_0)) {
if (monitor_ctrl_mode(VAR_0)) {
qerror_report(QERR_UNDEFINED_ERROR);
}
MON_DEBUG("command '%s' returned failure but did not pass an error\n",
VAR_1->name);
}
#ifdef CONFIG_DEBUG_MONITOR
if (!VAR_2 && monitor_has_error(VAR_0)) {
MON_DEBUG("command '%s' returned success but passed an error\n",
VAR_1->name);
}
if (mon_print_count_get(VAR_0) > 0 && strcmp(VAR_1->name, "info") != 0) {
MON_DEBUG("command '%s' called print functions %d time(s)\n",
VAR_1->name, mon_print_count_get(VAR_0));
}
#endif
}
| [
"static void FUNC_0(Monitor *VAR_0, const mon_cmd_t *VAR_1, int VAR_2)\n{",
"if (VAR_2 && !monitor_has_error(VAR_0)) {",
"if (monitor_ctrl_mode(VAR_0)) {",
"qerror_report(QERR_UNDEFINED_ERROR);",
"}",
"MON_DEBUG(\"command '%s' returned failure but did not pass an error\\n\",\nVAR_1->name);",
"}",
"#ifdef CONFIG_DEBUG_MONITOR\nif (!VAR_2 && monitor_has_error(VAR_0)) {",
"MON_DEBUG(\"command '%s' returned success but passed an error\\n\",\nVAR_1->name);",
"}",
"if (mon_print_count_get(VAR_0) > 0 && strcmp(VAR_1->name, \"info\") != 0) {",
"MON_DEBUG(\"command '%s' called print functions %d time(s)\\n\",\nVAR_1->name, mon_print_count_get(VAR_0));",
"}",
"#endif\n}"
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | [
[
1,
3
],
[
5
],
[
17
],
[
19
],
[
21
],
[
23,
25
],
[
27
],
[
31,
33
],
[
45,
47
],
[
49
],
[
53
],
[
75,
77
],
[
79
],
[
81,
83
]
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.