173
189
extern int getresgid(gid_t *, gid_t *, gid_t *);
174
190
extern int setgroups(int, gid_t *);
193
* This list is the union of errno values overridden in asm-<arch>/errno.h
194
* minus the errnos that are not actually generic to all archs.
196
static uint16_t host_to_target_errno_table[1200] = {
197
[EIDRM] = TARGET_EIDRM,
198
[ECHRNG] = TARGET_ECHRNG,
199
[EL2NSYNC] = TARGET_EL2NSYNC,
200
[EL3HLT] = TARGET_EL3HLT,
201
[EL3RST] = TARGET_EL3RST,
202
[ELNRNG] = TARGET_ELNRNG,
203
[EUNATCH] = TARGET_EUNATCH,
204
[ENOCSI] = TARGET_ENOCSI,
205
[EL2HLT] = TARGET_EL2HLT,
206
[EDEADLK] = TARGET_EDEADLK,
207
[ENOLCK] = TARGET_ENOLCK,
208
[EBADE] = TARGET_EBADE,
209
[EBADR] = TARGET_EBADR,
210
[EXFULL] = TARGET_EXFULL,
211
[ENOANO] = TARGET_ENOANO,
212
[EBADRQC] = TARGET_EBADRQC,
213
[EBADSLT] = TARGET_EBADSLT,
214
[EBFONT] = TARGET_EBFONT,
215
[ENOSTR] = TARGET_ENOSTR,
216
[ENODATA] = TARGET_ENODATA,
217
[ETIME] = TARGET_ETIME,
218
[ENOSR] = TARGET_ENOSR,
219
[ENONET] = TARGET_ENONET,
220
[ENOPKG] = TARGET_ENOPKG,
221
[EREMOTE] = TARGET_EREMOTE,
222
[ENOLINK] = TARGET_ENOLINK,
223
[EADV] = TARGET_EADV,
224
[ESRMNT] = TARGET_ESRMNT,
225
[ECOMM] = TARGET_ECOMM,
226
[EPROTO] = TARGET_EPROTO,
227
[EDOTDOT] = TARGET_EDOTDOT,
228
[EMULTIHOP] = TARGET_EMULTIHOP,
229
[EBADMSG] = TARGET_EBADMSG,
230
[ENAMETOOLONG] = TARGET_ENAMETOOLONG,
231
[EOVERFLOW] = TARGET_EOVERFLOW,
232
[ENOTUNIQ] = TARGET_ENOTUNIQ,
233
[EBADFD] = TARGET_EBADFD,
234
[EREMCHG] = TARGET_EREMCHG,
235
[ELIBACC] = TARGET_ELIBACC,
236
[ELIBBAD] = TARGET_ELIBBAD,
237
[ELIBSCN] = TARGET_ELIBSCN,
238
[ELIBMAX] = TARGET_ELIBMAX,
239
[ELIBEXEC] = TARGET_ELIBEXEC,
240
[EILSEQ] = TARGET_EILSEQ,
241
[ENOSYS] = TARGET_ENOSYS,
242
[ELOOP] = TARGET_ELOOP,
243
[ERESTART] = TARGET_ERESTART,
244
[ESTRPIPE] = TARGET_ESTRPIPE,
245
[ENOTEMPTY] = TARGET_ENOTEMPTY,
246
[EUSERS] = TARGET_EUSERS,
247
[ENOTSOCK] = TARGET_ENOTSOCK,
248
[EDESTADDRREQ] = TARGET_EDESTADDRREQ,
249
[EMSGSIZE] = TARGET_EMSGSIZE,
250
[EPROTOTYPE] = TARGET_EPROTOTYPE,
251
[ENOPROTOOPT] = TARGET_ENOPROTOOPT,
252
[EPROTONOSUPPORT] = TARGET_EPROTONOSUPPORT,
253
[ESOCKTNOSUPPORT] = TARGET_ESOCKTNOSUPPORT,
254
[EOPNOTSUPP] = TARGET_EOPNOTSUPP,
255
[EPFNOSUPPORT] = TARGET_EPFNOSUPPORT,
256
[EAFNOSUPPORT] = TARGET_EAFNOSUPPORT,
257
[EADDRINUSE] = TARGET_EADDRINUSE,
258
[EADDRNOTAVAIL] = TARGET_EADDRNOTAVAIL,
259
[ENETDOWN] = TARGET_ENETDOWN,
260
[ENETUNREACH] = TARGET_ENETUNREACH,
261
[ENETRESET] = TARGET_ENETRESET,
262
[ECONNABORTED] = TARGET_ECONNABORTED,
263
[ECONNRESET] = TARGET_ECONNRESET,
264
[ENOBUFS] = TARGET_ENOBUFS,
265
[EISCONN] = TARGET_EISCONN,
266
[ENOTCONN] = TARGET_ENOTCONN,
267
[EUCLEAN] = TARGET_EUCLEAN,
268
[ENOTNAM] = TARGET_ENOTNAM,
269
[ENAVAIL] = TARGET_ENAVAIL,
270
[EISNAM] = TARGET_EISNAM,
271
[EREMOTEIO] = TARGET_EREMOTEIO,
272
[ESHUTDOWN] = TARGET_ESHUTDOWN,
273
[ETOOMANYREFS] = TARGET_ETOOMANYREFS,
274
[ETIMEDOUT] = TARGET_ETIMEDOUT,
275
[ECONNREFUSED] = TARGET_ECONNREFUSED,
276
[EHOSTDOWN] = TARGET_EHOSTDOWN,
277
[EHOSTUNREACH] = TARGET_EHOSTUNREACH,
278
[EALREADY] = TARGET_EALREADY,
279
[EINPROGRESS] = TARGET_EINPROGRESS,
280
[ESTALE] = TARGET_ESTALE,
281
[ECANCELED] = TARGET_ECANCELED,
282
[ENOMEDIUM] = TARGET_ENOMEDIUM,
283
[EMEDIUMTYPE] = TARGET_EMEDIUMTYPE,
285
[ENOKEY] = TARGET_ENOKEY,
288
[EKEYEXPIRED] = TARGET_EKEYEXPIRED,
291
[EKEYREVOKED] = TARGET_EKEYREVOKED,
294
[EKEYREJECTED] = TARGET_EKEYREJECTED,
297
[EOWNERDEAD] = TARGET_EOWNERDEAD,
299
#ifdef ENOTRECOVERABLE
300
[ENOTRECOVERABLE] = TARGET_ENOTRECOVERABLE,
304
static inline int host_to_target_errno(int err)
306
if(host_to_target_errno_table[err])
307
return host_to_target_errno_table[err];
176
311
static inline long get_errno(long ret)
314
return -host_to_target_errno(errno);
1116
1251
} shm_regions[N_SHM_REGIONS];
1253
struct target_ipc_perm
1260
unsigned short int mode;
1261
unsigned short int __pad1;
1262
unsigned short int __seq;
1263
unsigned short int __pad2;
1264
target_ulong __unused1;
1265
target_ulong __unused2;
1268
struct target_semid_ds
1270
struct target_ipc_perm sem_perm;
1271
target_ulong sem_otime;
1272
target_ulong __unused1;
1273
target_ulong sem_ctime;
1274
target_ulong __unused2;
1275
target_ulong sem_nsems;
1276
target_ulong __unused3;
1277
target_ulong __unused4;
1280
static inline void target_to_host_ipc_perm(struct ipc_perm *host_ip,
1281
target_ulong target_addr)
1283
struct target_ipc_perm *target_ip;
1284
struct target_semid_ds *target_sd;
1286
lock_user_struct(target_sd, target_addr, 1);
1287
target_ip=&(target_sd->sem_perm);
1288
host_ip->__key = tswapl(target_ip->__key);
1289
host_ip->uid = tswapl(target_ip->uid);
1290
host_ip->gid = tswapl(target_ip->gid);
1291
host_ip->cuid = tswapl(target_ip->cuid);
1292
host_ip->cgid = tswapl(target_ip->cgid);
1293
host_ip->mode = tswapl(target_ip->mode);
1294
unlock_user_struct(target_sd, target_addr, 0);
1297
static inline void host_to_target_ipc_perm(target_ulong target_addr,
1298
struct ipc_perm *host_ip)
1300
struct target_ipc_perm *target_ip;
1301
struct target_semid_ds *target_sd;
1303
lock_user_struct(target_sd, target_addr, 0);
1304
target_ip = &(target_sd->sem_perm);
1305
target_ip->__key = tswapl(host_ip->__key);
1306
target_ip->uid = tswapl(host_ip->uid);
1307
target_ip->gid = tswapl(host_ip->gid);
1308
target_ip->cuid = tswapl(host_ip->cuid);
1309
target_ip->cgid = tswapl(host_ip->cgid);
1310
target_ip->mode = tswapl(host_ip->mode);
1311
unlock_user_struct(target_sd, target_addr, 1);
1314
static inline void target_to_host_semid_ds(struct semid_ds *host_sd,
1315
target_ulong target_addr)
1317
struct target_semid_ds *target_sd;
1319
lock_user_struct(target_sd, target_addr, 1);
1320
target_to_host_ipc_perm(&(host_sd->sem_perm),target_addr);
1321
host_sd->sem_nsems = tswapl(target_sd->sem_nsems);
1322
host_sd->sem_otime = tswapl(target_sd->sem_otime);
1323
host_sd->sem_ctime = tswapl(target_sd->sem_ctime);
1324
unlock_user_struct(target_sd, target_addr, 0);
1327
static inline void host_to_target_semid_ds(target_ulong target_addr,
1328
struct semid_ds *host_sd)
1330
struct target_semid_ds *target_sd;
1332
lock_user_struct(target_sd, target_addr, 0);
1333
host_to_target_ipc_perm(target_addr,&(host_sd->sem_perm));
1334
target_sd->sem_nsems = tswapl(host_sd->sem_nsems);
1335
target_sd->sem_otime = tswapl(host_sd->sem_otime);
1336
target_sd->sem_ctime = tswapl(host_sd->sem_ctime);
1337
unlock_user_struct(target_sd, target_addr, 1);
1120
struct senid_ds *buf;
1342
struct semid_ds *buf;
1121
1343
unsigned short *array;
1346
union target_semun {
1349
unsigned short int *array;
1352
static inline void target_to_host_semun(unsigned long cmd,
1353
union semun *host_su,
1354
target_ulong target_addr,
1355
struct semid_ds *ds)
1357
union target_semun *target_su;
1362
lock_user_struct(target_su, target_addr, 1);
1363
target_to_host_semid_ds(ds,target_su->buf);
1365
unlock_user_struct(target_su, target_addr, 0);
1369
lock_user_struct(target_su, target_addr, 1);
1370
host_su->val = tswapl(target_su->val);
1371
unlock_user_struct(target_su, target_addr, 0);
1375
lock_user_struct(target_su, target_addr, 1);
1376
*host_su->array = tswap16(*target_su->array);
1377
unlock_user_struct(target_su, target_addr, 0);
1380
gemu_log("semun operation not fully supported: %d\n", (int)cmd);
1384
static inline void host_to_target_semun(unsigned long cmd,
1385
target_ulong target_addr,
1386
union semun *host_su,
1387
struct semid_ds *ds)
1389
union target_semun *target_su;
1394
lock_user_struct(target_su, target_addr, 0);
1395
host_to_target_semid_ds(target_su->buf,ds);
1396
unlock_user_struct(target_su, target_addr, 1);
1400
lock_user_struct(target_su, target_addr, 0);
1401
target_su->val = tswapl(host_su->val);
1402
unlock_user_struct(target_su, target_addr, 1);
1406
lock_user_struct(target_su, target_addr, 0);
1407
*target_su->array = tswap16(*host_su->array);
1408
unlock_user_struct(target_su, target_addr, 1);
1411
gemu_log("semun operation not fully supported: %d\n", (int)cmd);
1415
static inline long do_semctl(long first, long second, long third, long ptr)
1418
struct semid_ds dsarg;
1419
int cmd = third&0xff;
1424
target_to_host_semun(cmd,&arg,ptr,&dsarg);
1425
ret = get_errno(semctl(first, second, cmd, arg));
1426
host_to_target_semun(cmd,ptr,&arg,&dsarg);
1429
target_to_host_semun(cmd,&arg,ptr,&dsarg);
1430
ret = get_errno(semctl(first, second, cmd, arg));
1431
host_to_target_semun(cmd,ptr,&arg,&dsarg);
1434
target_to_host_semun(cmd,&arg,ptr,&dsarg);
1435
ret = get_errno(semctl(first, second, cmd, arg));
1436
host_to_target_semun(cmd,ptr,&arg,&dsarg);
1439
target_to_host_semun(cmd,&arg,ptr,&dsarg);
1440
ret = get_errno(semctl(first, second, cmd, arg));
1441
host_to_target_semun(cmd,ptr,&arg,&dsarg);
1444
target_to_host_semun(cmd,&arg,ptr,&dsarg);
1445
ret = get_errno(semctl(first, second, cmd, arg));
1446
host_to_target_semun(cmd,ptr,&arg,&dsarg);
1449
target_to_host_semun(cmd,&arg,ptr,&dsarg);
1450
ret = get_errno(semctl(first, second, cmd, arg));
1451
host_to_target_semun(cmd,ptr,&arg,&dsarg);
1454
ret = get_errno(semctl(first, second, cmd, arg));
1460
struct target_msqid_ds
1462
struct target_ipc_perm msg_perm;
1463
target_ulong msg_stime;
1464
target_ulong __unused1;
1465
target_ulong msg_rtime;
1466
target_ulong __unused2;
1467
target_ulong msg_ctime;
1468
target_ulong __unused3;
1469
target_ulong __msg_cbytes;
1470
target_ulong msg_qnum;
1471
target_ulong msg_qbytes;
1472
target_ulong msg_lspid;
1473
target_ulong msg_lrpid;
1474
target_ulong __unused4;
1475
target_ulong __unused5;
1478
static inline void target_to_host_msqid_ds(struct msqid_ds *host_md,
1479
target_ulong target_addr)
1481
struct target_msqid_ds *target_md;
1483
lock_user_struct(target_md, target_addr, 1);
1484
target_to_host_ipc_perm(&(host_md->msg_perm),target_addr);
1485
host_md->msg_stime = tswapl(target_md->msg_stime);
1486
host_md->msg_rtime = tswapl(target_md->msg_rtime);
1487
host_md->msg_ctime = tswapl(target_md->msg_ctime);
1488
host_md->__msg_cbytes = tswapl(target_md->__msg_cbytes);
1489
host_md->msg_qnum = tswapl(target_md->msg_qnum);
1490
host_md->msg_qbytes = tswapl(target_md->msg_qbytes);
1491
host_md->msg_lspid = tswapl(target_md->msg_lspid);
1492
host_md->msg_lrpid = tswapl(target_md->msg_lrpid);
1493
unlock_user_struct(target_md, target_addr, 0);
1496
static inline void host_to_target_msqid_ds(target_ulong target_addr,
1497
struct msqid_ds *host_md)
1499
struct target_msqid_ds *target_md;
1501
lock_user_struct(target_md, target_addr, 0);
1502
host_to_target_ipc_perm(target_addr,&(host_md->msg_perm));
1503
target_md->msg_stime = tswapl(host_md->msg_stime);
1504
target_md->msg_rtime = tswapl(host_md->msg_rtime);
1505
target_md->msg_ctime = tswapl(host_md->msg_ctime);
1506
target_md->__msg_cbytes = tswapl(host_md->__msg_cbytes);
1507
target_md->msg_qnum = tswapl(host_md->msg_qnum);
1508
target_md->msg_qbytes = tswapl(host_md->msg_qbytes);
1509
target_md->msg_lspid = tswapl(host_md->msg_lspid);
1510
target_md->msg_lrpid = tswapl(host_md->msg_lrpid);
1511
unlock_user_struct(target_md, target_addr, 1);
1514
static inline long do_msgctl(long first, long second, long ptr)
1516
struct msqid_ds dsarg;
1517
int cmd = second&0xff;
1522
target_to_host_msqid_ds(&dsarg,ptr);
1523
ret = get_errno(msgctl(first, cmd, &dsarg));
1524
host_to_target_msqid_ds(ptr,&dsarg);
1526
ret = get_errno(msgctl(first, cmd, &dsarg));
1531
struct target_msgbuf {
1536
static inline long do_msgsnd(long msqid, long msgp, long msgsz, long msgflg)
1538
struct target_msgbuf *target_mb;
1539
struct msgbuf *host_mb;
1542
lock_user_struct(target_mb,msgp,0);
1543
host_mb = malloc(msgsz+sizeof(long));
1544
host_mb->mtype = tswapl(target_mb->mtype);
1545
memcpy(host_mb->mtext,target_mb->mtext,msgsz);
1546
ret = get_errno(msgsnd(msqid, host_mb, msgsz, msgflg));
1548
unlock_user_struct(target_mb, msgp, 0);
1553
static inline long do_msgrcv(long msqid, long msgp, long msgsz, long msgtype, long msgflg)
1555
struct target_msgbuf *target_mb;
1556
struct msgbuf *host_mb;
1559
lock_user_struct(target_mb, msgp, 0);
1560
host_mb = malloc(msgsz+sizeof(long));
1561
ret = get_errno(msgrcv(msqid, host_mb, msgsz, 1, msgflg));
1563
memcpy(target_mb->mtext, host_mb->mtext, ret);
1564
target_mb->mtype = tswapl(host_mb->mtype);
1566
unlock_user_struct(target_mb, msgp, 0);
1124
1571
/* ??? This only works with linear mappings. */
1125
1572
static long do_ipc(long call, long first, long second, long third,
1126
1573
long ptr, long fifth)