183
179
#define __NR_sys_uname __NR_uname
184
#define __NR_sys_faccessat __NR_faccessat
185
#define __NR_sys_fchmodat __NR_fchmodat
186
#define __NR_sys_fchownat __NR_fchownat
187
#define __NR_sys_fstatat64 __NR_fstatat64
188
#define __NR_sys_futimesat __NR_futimesat
189
180
#define __NR_sys_getcwd1 __NR_getcwd
190
181
#define __NR_sys_getdents __NR_getdents
191
182
#define __NR_sys_getdents64 __NR_getdents64
192
183
#define __NR_sys_getpriority __NR_getpriority
193
#define __NR_sys_linkat __NR_linkat
194
#define __NR_sys_mkdirat __NR_mkdirat
195
#define __NR_sys_mknodat __NR_mknodat
196
#define __NR_sys_newfstatat __NR_newfstatat
197
#define __NR_sys_openat __NR_openat
198
#define __NR_sys_readlinkat __NR_readlinkat
199
#define __NR_sys_renameat __NR_renameat
200
184
#define __NR_sys_rt_sigqueueinfo __NR_rt_sigqueueinfo
201
#define __NR_sys_symlinkat __NR_symlinkat
202
185
#define __NR_sys_syslog __NR_syslog
203
186
#define __NR_sys_tgkill __NR_tgkill
204
187
#define __NR_sys_tkill __NR_tkill
205
#define __NR_sys_unlinkat __NR_unlinkat
206
#define __NR_sys_utimensat __NR_utimensat
207
188
#define __NR_sys_futex __NR_futex
208
189
#define __NR_sys_inotify_init __NR_inotify_init
209
190
#define __NR_sys_inotify_add_watch __NR_inotify_add_watch
336
318
return strlen(buf)+1;
341
* Host system seems to have atfile syscall stubs available. We
342
* now enable them one by one as specified by target syscall_nr.h.
345
#ifdef TARGET_NR_faccessat
346
static int sys_faccessat(int dirfd, const char *pathname, int mode)
348
return (faccessat(dirfd, pathname, mode, 0));
351
#ifdef TARGET_NR_fchmodat
352
static int sys_fchmodat(int dirfd, const char *pathname, mode_t mode)
354
return (fchmodat(dirfd, pathname, mode, 0));
357
#if defined(TARGET_NR_fchownat)
358
static int sys_fchownat(int dirfd, const char *pathname, uid_t owner,
359
gid_t group, int flags)
361
return (fchownat(dirfd, pathname, owner, group, flags));
364
#ifdef __NR_fstatat64
365
static int sys_fstatat64(int dirfd, const char *pathname, struct stat *buf,
368
return (fstatat(dirfd, pathname, buf, flags));
371
#ifdef __NR_newfstatat
372
static int sys_newfstatat(int dirfd, const char *pathname, struct stat *buf,
375
return (fstatat(dirfd, pathname, buf, flags));
378
#ifdef TARGET_NR_futimesat
379
static int sys_futimesat(int dirfd, const char *pathname,
380
const struct timeval times[2])
382
return (futimesat(dirfd, pathname, times));
385
#ifdef TARGET_NR_linkat
386
static int sys_linkat(int olddirfd, const char *oldpath,
387
int newdirfd, const char *newpath, int flags)
389
return (linkat(olddirfd, oldpath, newdirfd, newpath, flags));
392
#ifdef TARGET_NR_mkdirat
393
static int sys_mkdirat(int dirfd, const char *pathname, mode_t mode)
395
return (mkdirat(dirfd, pathname, mode));
398
#ifdef TARGET_NR_mknodat
399
static int sys_mknodat(int dirfd, const char *pathname, mode_t mode,
402
return (mknodat(dirfd, pathname, mode, dev));
405
321
#ifdef TARGET_NR_openat
406
322
static int sys_openat(int dirfd, const char *pathname, int flags, mode_t mode)
415
331
return (openat(dirfd, pathname, flags));
418
#ifdef TARGET_NR_readlinkat
419
static int sys_readlinkat(int dirfd, const char *pathname, char *buf, size_t bufsiz)
421
return (readlinkat(dirfd, pathname, buf, bufsiz));
424
#ifdef TARGET_NR_renameat
425
static int sys_renameat(int olddirfd, const char *oldpath,
426
int newdirfd, const char *newpath)
428
return (renameat(olddirfd, oldpath, newdirfd, newpath));
431
#ifdef TARGET_NR_symlinkat
432
static int sys_symlinkat(const char *oldpath, int newdirfd, const char *newpath)
434
return (symlinkat(oldpath, newdirfd, newpath));
437
#ifdef TARGET_NR_unlinkat
438
static int sys_unlinkat(int dirfd, const char *pathname, int flags)
440
return (unlinkat(dirfd, pathname, flags));
443
#else /* !CONFIG_ATFILE */
446
* Try direct syscalls instead
448
#if defined(TARGET_NR_faccessat) && defined(__NR_faccessat)
449
_syscall3(int,sys_faccessat,int,dirfd,const char *,pathname,int,mode)
451
#if defined(TARGET_NR_fchmodat) && defined(__NR_fchmodat)
452
_syscall3(int,sys_fchmodat,int,dirfd,const char *,pathname, mode_t,mode)
454
#if defined(TARGET_NR_fchownat) && defined(__NR_fchownat)
455
_syscall5(int,sys_fchownat,int,dirfd,const char *,pathname,
456
uid_t,owner,gid_t,group,int,flags)
458
#if (defined(TARGET_NR_fstatat64) || defined(TARGET_NR_newfstatat)) && \
459
defined(__NR_fstatat64)
460
_syscall4(int,sys_fstatat64,int,dirfd,const char *,pathname,
461
struct stat *,buf,int,flags)
463
#if defined(TARGET_NR_futimesat) && defined(__NR_futimesat)
464
_syscall3(int,sys_futimesat,int,dirfd,const char *,pathname,
465
const struct timeval *,times)
467
#if (defined(TARGET_NR_newfstatat) || defined(TARGET_NR_fstatat64) ) && \
468
defined(__NR_newfstatat)
469
_syscall4(int,sys_newfstatat,int,dirfd,const char *,pathname,
470
struct stat *,buf,int,flags)
472
#if defined(TARGET_NR_linkat) && defined(__NR_linkat)
473
_syscall5(int,sys_linkat,int,olddirfd,const char *,oldpath,
474
int,newdirfd,const char *,newpath,int,flags)
476
#if defined(TARGET_NR_mkdirat) && defined(__NR_mkdirat)
477
_syscall3(int,sys_mkdirat,int,dirfd,const char *,pathname,mode_t,mode)
479
#if defined(TARGET_NR_mknodat) && defined(__NR_mknodat)
480
_syscall4(int,sys_mknodat,int,dirfd,const char *,pathname,
481
mode_t,mode,dev_t,dev)
483
#if defined(TARGET_NR_openat) && defined(__NR_openat)
484
_syscall4(int,sys_openat,int,dirfd,const char *,pathname,int,flags,mode_t,mode)
486
#if defined(TARGET_NR_readlinkat) && defined(__NR_readlinkat)
487
_syscall4(int,sys_readlinkat,int,dirfd,const char *,pathname,
488
char *,buf,size_t,bufsize)
490
#if defined(TARGET_NR_renameat) && defined(__NR_renameat)
491
_syscall4(int,sys_renameat,int,olddirfd,const char *,oldpath,
492
int,newdirfd,const char *,newpath)
494
#if defined(TARGET_NR_symlinkat) && defined(__NR_symlinkat)
495
_syscall3(int,sys_symlinkat,const char *,oldpath,
496
int,newdirfd,const char *,newpath)
498
#if defined(TARGET_NR_unlinkat) && defined(__NR_unlinkat)
499
_syscall3(int,sys_unlinkat,int,dirfd,const char *,pathname,int,flags)
502
#endif /* CONFIG_ATFILE */
335
#ifdef TARGET_NR_utimensat
504
336
#ifdef CONFIG_UTIMENSAT
505
337
static int sys_utimensat(int dirfd, const char *pathname,
506
338
const struct timespec times[2], int flags)
3566
static abi_long do_ioctl_rt(const IOCTLEntry *ie, uint8_t *buf_temp,
3567
int fd, abi_long cmd, abi_long arg)
3569
const argtype *arg_type = ie->arg_type;
3570
const StructEntry *se;
3571
const argtype *field_types;
3572
const int *dst_offsets, *src_offsets;
3575
abi_ulong *target_rt_dev_ptr;
3576
unsigned long *host_rt_dev_ptr;
3580
assert(ie->access == IOC_W);
3581
assert(*arg_type == TYPE_PTR);
3583
assert(*arg_type == TYPE_STRUCT);
3584
target_size = thunk_type_size(arg_type, 0);
3585
argptr = lock_user(VERIFY_READ, arg, target_size, 1);
3587
return -TARGET_EFAULT;
3590
assert(*arg_type == (int)STRUCT_rtentry);
3591
se = struct_entries + *arg_type++;
3592
assert(se->convert[0] == NULL);
3593
/* convert struct here to be able to catch rt_dev string */
3594
field_types = se->field_types;
3595
dst_offsets = se->field_offsets[THUNK_HOST];
3596
src_offsets = se->field_offsets[THUNK_TARGET];
3597
for (i = 0; i < se->nb_fields; i++) {
3598
if (dst_offsets[i] == offsetof(struct rtentry, rt_dev)) {
3599
assert(*field_types == TYPE_PTRVOID);
3600
target_rt_dev_ptr = (abi_ulong *)(argptr + src_offsets[i]);
3601
host_rt_dev_ptr = (unsigned long *)(buf_temp + dst_offsets[i]);
3602
if (*target_rt_dev_ptr != 0) {
3603
*host_rt_dev_ptr = (unsigned long)lock_user_string(
3604
tswapal(*target_rt_dev_ptr));
3605
if (!*host_rt_dev_ptr) {
3606
unlock_user(argptr, arg, 0);
3607
return -TARGET_EFAULT;
3610
*host_rt_dev_ptr = 0;
3615
field_types = thunk_convert(buf_temp + dst_offsets[i],
3616
argptr + src_offsets[i],
3617
field_types, THUNK_HOST);
3619
unlock_user(argptr, arg, 0);
3621
ret = get_errno(ioctl(fd, ie->host_cmd, buf_temp));
3622
if (*host_rt_dev_ptr != 0) {
3623
unlock_user((void *)*host_rt_dev_ptr,
3624
*target_rt_dev_ptr, 0);
3717
3629
static IOCTLEntry ioctl_entries[] = {
3718
3630
#define IOCTL(cmd, access, ...) \
3719
3631
{ TARGET_ ## cmd, cmd, #cmd, access, 0, { __VA_ARGS__ } },
5208
5109
case TARGET_NR_exit:
5209
#ifdef CONFIG_USE_NPTL
5210
/* In old applications this may be used to implement _exit(2).
5211
However in threaded applictions it is used for thread termination,
5212
and _exit_group is used for application termination.
5213
Do thread termination if we have more then one thread. */
5214
/* FIXME: This probably breaks if a signal arrives. We should probably
5215
be disabling signals. */
5216
if (first_cpu->next_cpu) {
5218
CPUArchState **lastp;
5110
/* In old applications this may be used to implement _exit(2).
5111
However in threaded applictions it is used for thread termination,
5112
and _exit_group is used for application termination.
5113
Do thread termination if we have more then one thread. */
5114
/* FIXME: This probably breaks if a signal arrives. We should probably
5115
be disabling signals. */
5116
if (first_cpu->next_cpu) {
5224
while (p && p != (CPUArchState *)cpu_env) {
5225
lastp = &p->next_cpu;
5228
/* If we didn't find the CPU for this thread then something is
5232
/* Remove the CPU from the list. */
5233
*lastp = p->next_cpu;
5235
ts = ((CPUArchState *)cpu_env)->opaque;
5236
if (ts->child_tidptr) {
5237
put_user_u32(0, ts->child_tidptr);
5238
sys_futex(g2h(ts->child_tidptr), FUTEX_WAKE, INT_MAX,
5242
object_unref(OBJECT(ENV_GET_CPU(cpu_env)));
5124
while (p && p != cpu) {
5125
lastp = &p->next_cpu;
5128
/* If we didn't find the CPU for this thread then something is
5133
/* Remove the CPU from the list. */
5134
*lastp = p->next_cpu;
5136
ts = ((CPUArchState *)cpu_env)->opaque;
5137
if (ts->child_tidptr) {
5138
put_user_u32(0, ts->child_tidptr);
5139
sys_futex(g2h(ts->child_tidptr), FUTEX_WAKE, INT_MAX,
5143
object_unref(OBJECT(ENV_GET_CPU(cpu_env)));
5247
5147
#ifdef TARGET_GPROF
6426
6326
case TARGET_NR_readlink:
6429
6329
p = lock_user_string(arg1);
6430
6330
p2 = lock_user(VERIFY_WRITE, arg2, arg3, 0);
6432
6332
ret = -TARGET_EFAULT;
6434
if (strncmp((const char *)p, "/proc/self/exe", 14) == 0) {
6435
char real[PATH_MAX];
6436
temp = realpath(exec_path,real);
6437
ret = (temp==NULL) ? get_errno(-1) : strlen(real) ;
6438
snprintf((char *)p2, arg3, "%s", real);
6441
ret = get_errno(readlink(path(p), p2, arg3));
6333
} else if (is_proc_myself((const char *)p, "exe")) {
6334
char real[PATH_MAX], *temp;
6335
temp = realpath(exec_path, real);
6336
ret = temp == NULL ? get_errno(-1) : strlen(real) ;
6337
snprintf((char *)p2, arg3, "%s", real);
6339
ret = get_errno(readlink(path(p), p2, arg3));
6443
6341
unlock_user(p2, arg2, ret);
6444
6342
unlock_user(p, arg1, 0);
6447
#if defined(TARGET_NR_readlinkat) && defined(__NR_readlinkat)
6345
#if defined(TARGET_NR_readlinkat)
6448
6346
case TARGET_NR_readlinkat:
6451
6349
p = lock_user_string(arg2);
6452
6350
p2 = lock_user(VERIFY_WRITE, arg3, arg4, 0);
6454
ret = -TARGET_EFAULT;
6456
ret = get_errno(sys_readlinkat(arg1, path(p), p2, arg4));
6352
ret = -TARGET_EFAULT;
6353
} else if (is_proc_myself((const char *)p, "exe")) {
6354
char real[PATH_MAX], *temp;
6355
temp = realpath(exec_path, real);
6356
ret = temp == NULL ? get_errno(-1) : strlen(real) ;
6357
snprintf((char *)p2, arg4, "%s", real);
6359
ret = get_errno(readlinkat(arg1, path(p), p2, arg4));
6457
6361
unlock_user(p2, arg3, ret);
6458
6362
unlock_user(p, arg2, 0);
7009
6913
ret = get_errno(fsync(arg1));
7011
6915
case TARGET_NR_clone:
7012
#if defined(TARGET_SH4) || defined(TARGET_ALPHA)
7013
ret = get_errno(do_fork(cpu_env, arg1, arg2, arg3, arg5, arg4));
7014
#elif defined(TARGET_CRIS)
7015
ret = get_errno(do_fork(cpu_env, arg2, arg1, arg3, arg4, arg5));
7016
#elif defined(TARGET_MICROBLAZE)
6916
/* Linux manages to have three different orderings for its
6917
* arguments to clone(); the BACKWARDS and BACKWARDS2 defines
6918
* match the kernel's CONFIG_CLONE_* settings.
6919
* Microblaze is further special in that it uses a sixth
6920
* implicit argument to clone for the TLS pointer.
6922
#if defined(TARGET_MICROBLAZE)
7017
6923
ret = get_errno(do_fork(cpu_env, arg1, arg2, arg4, arg6, arg5));
7018
#elif defined(TARGET_S390X)
6924
#elif defined(TARGET_CLONE_BACKWARDS)
6925
ret = get_errno(do_fork(cpu_env, arg1, arg2, arg3, arg4, arg5));
6926
#elif defined(TARGET_CLONE_BACKWARDS2)
7019
6927
ret = get_errno(do_fork(cpu_env, arg2, arg1, arg3, arg5, arg4));
7021
ret = get_errno(do_fork(cpu_env, arg1, arg2, arg3, arg4, arg5));
6929
ret = get_errno(do_fork(cpu_env, arg1, arg2, arg3, arg5, arg4));
7024
6932
#ifdef __NR_exit_group
7195
7104
unlock_user(dirp, arg2, ret);
7108
/* Implement getdents in terms of getdents64 */
7110
struct linux_dirent64 *dirp;
7111
abi_long count = arg3;
7113
dirp = lock_user(VERIFY_WRITE, arg2, count, 0);
7117
ret = get_errno(sys_getdents64(arg1, dirp, count));
7118
if (!is_error(ret)) {
7119
/* Convert the dirent64 structs to target dirent. We do this
7120
* in-place, since we can guarantee that a target_dirent is no
7121
* larger than a dirent64; however this means we have to be
7122
* careful to read everything before writing in the new format.
7124
struct linux_dirent64 *de;
7125
struct target_dirent *tde;
7130
tde = (struct target_dirent *)dirp;
7132
int namelen, treclen;
7133
int reclen = de->d_reclen;
7134
uint64_t ino = de->d_ino;
7135
int64_t off = de->d_off;
7136
uint8_t type = de->d_type;
7138
namelen = strlen(de->d_name);
7139
treclen = offsetof(struct target_dirent, d_name)
7141
treclen = QEMU_ALIGN_UP(treclen, sizeof(abi_long));
7143
memmove(tde->d_name, de->d_name, namelen + 1);
7144
tde->d_ino = tswapal(ino);
7145
tde->d_off = tswapal(off);
7146
tde->d_reclen = tswap16(treclen);
7147
/* The target_dirent type is in what was formerly a padding
7148
* byte at the end of the structure:
7150
*(((char *)tde) + treclen - 1) = type;
7152
de = (struct linux_dirent64 *)((char *)de + reclen);
7153
tde = (struct target_dirent *)((char *)tde + treclen);
7159
unlock_user(dirp, arg2, ret);
7199
7163
#if defined(TARGET_NR_getdents64) && defined(__NR_getdents64)
7200
7164
case TARGET_NR_getdents64: