/* set the thread x86 registers */ void set_thread_context( struct thread *thread, const context_t *context, unsigned int flags ) { int pid = get_ptrace_tid(thread); struct dbreg dbregs; /* all other regs are handled on the client side */ assert( flags == SERVER_CTX_DEBUG_REGISTERS ); if (!suspend_for_ptrace( thread )) return; #ifdef DBREG_DRX /* needed for FreeBSD, the structure fields have changed under 5.x */ DBREG_DRX((&dbregs), 0) = context->debug.i386_regs.dr0; DBREG_DRX((&dbregs), 1) = context->debug.i386_regs.dr1; DBREG_DRX((&dbregs), 2) = context->debug.i386_regs.dr2; DBREG_DRX((&dbregs), 3) = context->debug.i386_regs.dr3; DBREG_DRX((&dbregs), 4) = 0; DBREG_DRX((&dbregs), 5) = 0; DBREG_DRX((&dbregs), 6) = context->debug.i386_regs.dr6; DBREG_DRX((&dbregs), 7) = context->debug.i386_regs.dr7; #else dbregs.dr0 = context->debug.i386_regs.dr0; dbregs.dr1 = context->debug.i386_regs.dr1; dbregs.dr2 = context->debug.i386_regs.dr2; dbregs.dr3 = context->debug.i386_regs.dr3; dbregs.dr4 = 0; dbregs.dr5 = 0; dbregs.dr6 = context->debug.i386_regs.dr6; dbregs.dr7 = context->debug.i386_regs.dr7; #endif if (ptrace( PTRACE_SETDBREGS, pid, (caddr_t) &dbregs, 0 ) == -1) file_set_error(); else if (thread->context) thread->context->debug.i386_regs = context->debug.i386_regs; /* update the cached values */ resume_after_ptrace( thread ); }
/* retrieve the thread x86 registers */ void get_thread_context( struct thread *thread, context_t *context, unsigned int flags ) { int pid = get_ptrace_tid(thread); struct dbreg dbregs; /* all other regs are handled on the client side */ assert( flags == SERVER_CTX_DEBUG_REGISTERS ); if (!suspend_for_ptrace( thread )) return; if (ptrace( PTRACE_GETDBREGS, pid, (caddr_t) &dbregs, 0 ) == -1) file_set_error(); else { #ifdef DBREG_DRX /* needed for FreeBSD, the structure fields have changed under 5.x */ context->debug.i386_regs.dr0 = DBREG_DRX((&dbregs), 0); context->debug.i386_regs.dr1 = DBREG_DRX((&dbregs), 1); context->debug.i386_regs.dr2 = DBREG_DRX((&dbregs), 2); context->debug.i386_regs.dr3 = DBREG_DRX((&dbregs), 3); context->debug.i386_regs.dr6 = DBREG_DRX((&dbregs), 6); context->debug.i386_regs.dr7 = DBREG_DRX((&dbregs), 7); #else context->debug.i386_regs.dr0 = dbregs.dr0; context->debug.i386_regs.dr1 = dbregs.dr1; context->debug.i386_regs.dr2 = dbregs.dr2; context->debug.i386_regs.dr3 = dbregs.dr3; context->debug.i386_regs.dr6 = dbregs.dr6; context->debug.i386_regs.dr7 = dbregs.dr7; #endif context->flags |= SERVER_CTX_DEBUG_REGISTERS; } resume_after_ptrace( thread ); }
/* if the function fails the fd is closed */ struct file *create_file_for_fd( int fd, unsigned int access, unsigned int sharing ) { struct file *file; struct stat st; if (fstat( fd, &st ) == -1) { file_set_error(); close( fd ); return NULL; } if (!(file = alloc_object( &file_ops ))) { close( fd ); return NULL; } file->mode = st.st_mode; file->access = default_fd_map_access( &file->obj, access ); if (!(file->fd = create_anonymous_fd( &file_fd_ops, fd, &file->obj, FILE_SYNCHRONOUS_IO_NONALERT ))) { release_object( file ); return NULL; } allow_fd_caching( file->fd ); return file; }
static int file_flush( struct fd *fd, struct async *async ) { int unix_fd = get_unix_fd( fd ); if (unix_fd != -1 && fsync( unix_fd ) == -1) { file_set_error(); return 0; } return 1; }
/* read a long from a thread address space */ static long read_thread_long( struct thread *thread, long *addr, long *data ) { errno = 0; *data = ptrace( PTRACE_PEEKDATA, get_ptrace_pid(thread), (caddr_t)addr, 0 ); if ( *data == -1 && errno) { file_set_error(); return -1; } return 0; }
/* set the thread x86 registers */ void set_thread_context( struct thread *thread, const context_t *context, unsigned int flags ) { int pid = get_ptrace_tid( thread ); /* all other regs are handled on the client side */ assert( flags == SERVER_CTX_DEBUG_REGISTERS ); if (!suspend_for_ptrace( thread )) return; switch (context->cpu) { case CPU_x86: /* Linux 2.6.33+ does DR0-DR3 alignment validation, so it has to know LEN bits first */ if (ptrace( PTRACE_POKEUSER, pid, DR_OFFSET(7), context->debug.i386_regs.dr7 & 0xffff0000 ) == -1) goto error; if (ptrace( PTRACE_POKEUSER, pid, DR_OFFSET(0), context->debug.i386_regs.dr0 ) == -1) goto error; if (thread->context) thread->context->debug.i386_regs.dr0 = context->debug.i386_regs.dr0; if (ptrace( PTRACE_POKEUSER, pid, DR_OFFSET(1), context->debug.i386_regs.dr1 ) == -1) goto error; if (thread->context) thread->context->debug.i386_regs.dr1 = context->debug.i386_regs.dr1; if (ptrace( PTRACE_POKEUSER, pid, DR_OFFSET(2), context->debug.i386_regs.dr2 ) == -1) goto error; if (thread->context) thread->context->debug.i386_regs.dr2 = context->debug.i386_regs.dr2; if (ptrace( PTRACE_POKEUSER, pid, DR_OFFSET(3), context->debug.i386_regs.dr3 ) == -1) goto error; if (thread->context) thread->context->debug.i386_regs.dr3 = context->debug.i386_regs.dr3; if (ptrace( PTRACE_POKEUSER, pid, DR_OFFSET(6), context->debug.i386_regs.dr6 ) == -1) goto error; if (thread->context) thread->context->debug.i386_regs.dr6 = context->debug.i386_regs.dr6; /* Linux 2.6.33+ needs enable bits set briefly to update value returned by PEEKUSER later */ ptrace( PTRACE_POKEUSER, pid, DR_OFFSET(7), context->debug.i386_regs.dr7 | 0x55 ); if (ptrace( PTRACE_POKEUSER, pid, DR_OFFSET(7), context->debug.i386_regs.dr7 ) == -1) goto error; if (thread->context) thread->context->debug.i386_regs.dr7 = context->debug.i386_regs.dr7; break; case CPU_x86_64: if (ptrace( PTRACE_POKEUSER, pid, DR_OFFSET(7), context->debug.x86_64_regs.dr7 & 0xffff0000 ) == -1) goto error; if (ptrace( PTRACE_POKEUSER, pid, DR_OFFSET(0), context->debug.x86_64_regs.dr0 ) == -1) goto error; if (thread->context) thread->context->debug.x86_64_regs.dr0 = context->debug.x86_64_regs.dr0; if (ptrace( PTRACE_POKEUSER, pid, DR_OFFSET(1), context->debug.x86_64_regs.dr1 ) == -1) goto error; if (thread->context) thread->context->debug.x86_64_regs.dr1 = context->debug.x86_64_regs.dr1; if (ptrace( PTRACE_POKEUSER, pid, DR_OFFSET(2), context->debug.x86_64_regs.dr2 ) == -1) goto error; if (thread->context) thread->context->debug.x86_64_regs.dr2 = context->debug.x86_64_regs.dr2; if (ptrace( PTRACE_POKEUSER, pid, DR_OFFSET(3), context->debug.x86_64_regs.dr3 ) == -1) goto error; if (thread->context) thread->context->debug.x86_64_regs.dr3 = context->debug.x86_64_regs.dr3; if (ptrace( PTRACE_POKEUSER, pid, DR_OFFSET(6), context->debug.x86_64_regs.dr6 ) == -1) goto error; if (thread->context) thread->context->debug.x86_64_regs.dr6 = context->debug.x86_64_regs.dr6; ptrace( PTRACE_POKEUSER, pid, DR_OFFSET(7), context->debug.x86_64_regs.dr7 | 0x55 ); if (ptrace( PTRACE_POKEUSER, pid, DR_OFFSET(7), context->debug.x86_64_regs.dr7 ) == -1) goto error; if (thread->context) thread->context->debug.x86_64_regs.dr7 = context->debug.x86_64_regs.dr7; break; default: set_error( STATUS_INVALID_PARAMETER ); } resume_after_ptrace( thread ); return; error: file_set_error(); resume_after_ptrace( thread ); }
static int file_flush( struct fd *fd, struct event **event ) { int ret = 0, unix_fd = get_unix_fd( fd ); if (unix_fd != -1) { ret = (fsync( unix_fd ) != -1); if (!ret) file_set_error(); } return ret; }
/* write a long to a thread address space */ static long write_thread_long( struct thread *thread, long *addr, long data, unsigned long mask ) { long res; if (mask != ~0ul) { if (read_thread_long( thread, addr, &res ) == -1) return -1; data = (data & mask) | (res & ~mask); } if ((res = ptrace( PTRACE_POKEDATA, get_ptrace_pid(thread), (caddr_t)addr, data )) == -1) file_set_error(); return res; }
static int file_set_sd( struct object *obj, const struct security_descriptor *sd, unsigned int set_info ) { struct file *file = (struct file *)obj; const SID *owner; struct stat st; mode_t mode; int unix_fd; assert( obj->ops == &file_ops ); unix_fd = get_file_unix_fd( file ); if (unix_fd == -1 || fstat( unix_fd, &st ) == -1) return 1; if (set_info & OWNER_SECURITY_INFORMATION) { owner = sd_get_owner( sd ); if (!owner) { set_error( STATUS_INVALID_SECURITY_DESCR ); return 0; } if (!obj->sd || !security_equal_sid( owner, sd_get_owner( obj->sd ) )) { /* FIXME: get Unix uid and call fchown */ } } else if (obj->sd) owner = sd_get_owner( obj->sd ); else owner = token_get_user( current->process->token ); /* group and sacl not supported */ if (set_info & DACL_SECURITY_INFORMATION) { /* keep the bits that we don't map to access rights in the ACL */ mode = st.st_mode & (S_ISUID|S_ISGID|S_ISVTX); mode |= sd_to_mode( sd, owner ); if (((st.st_mode ^ mode) & (S_IRWXU|S_IRWXG|S_IRWXO)) && fchmod( unix_fd, mode ) == -1) { file_set_error(); return 0; } } return 1; }
/* try to grow the file to the specified size */ int grow_file( struct file *file, file_pos_t size ) { struct stat st; int unix_fd = get_file_unix_fd( file ); if (unix_fd == -1) return 0; if (fstat( unix_fd, &st ) == -1) { file_set_error(); return 0; } if (st.st_size >= size) return 1; /* already large enough */ return extend_file( file, size ); }
/* create a temp file for anonymous mappings */ struct file *create_temp_file( int access ) { char tmpfn[16]; int fd; sprintf( tmpfn, "anonmap.XXXXXX" ); /* create it in the server directory */ fd = mkstemps( tmpfn, 0 ); if (fd == -1) { file_set_error(); return NULL; } unlink( tmpfn ); return create_file_for_fd( fd, access, 0 ); }
/* set the thread x86 registers */ void set_thread_context( struct thread *thread, const context_t *context, unsigned int flags ) { int pid = get_ptrace_tid( thread ); /* all other regs are handled on the client side */ assert( flags == SERVER_CTX_DEBUG_REGISTERS ); if (!suspend_for_ptrace( thread )) return; switch (context->cpu) { case CPU_x86: if (ptrace( PTRACE_POKEUSER, pid, DR_OFFSET(0), context->debug.i386_regs.dr0 ) == -1) goto error; if (thread->context) thread->context->debug.i386_regs.dr0 = context->debug.i386_regs.dr0; if (ptrace( PTRACE_POKEUSER, pid, DR_OFFSET(1), context->debug.i386_regs.dr1 ) == -1) goto error; if (thread->context) thread->context->debug.i386_regs.dr1 = context->debug.i386_regs.dr1; if (ptrace( PTRACE_POKEUSER, pid, DR_OFFSET(2), context->debug.i386_regs.dr2 ) == -1) goto error; if (thread->context) thread->context->debug.i386_regs.dr2 = context->debug.i386_regs.dr2; if (ptrace( PTRACE_POKEUSER, pid, DR_OFFSET(3), context->debug.i386_regs.dr3 ) == -1) goto error; if (thread->context) thread->context->debug.i386_regs.dr3 = context->debug.i386_regs.dr3; if (ptrace( PTRACE_POKEUSER, pid, DR_OFFSET(6), context->debug.i386_regs.dr6 ) == -1) goto error; if (thread->context) thread->context->debug.i386_regs.dr6 = context->debug.i386_regs.dr6; if (ptrace( PTRACE_POKEUSER, pid, DR_OFFSET(7), context->debug.i386_regs.dr7 ) == -1) goto error; if (thread->context) thread->context->debug.i386_regs.dr7 = context->debug.i386_regs.dr7; break; case CPU_x86_64: if (ptrace( PTRACE_POKEUSER, pid, DR_OFFSET(0), context->debug.x86_64_regs.dr0 ) == -1) goto error; if (thread->context) thread->context->debug.x86_64_regs.dr0 = context->debug.x86_64_regs.dr0; if (ptrace( PTRACE_POKEUSER, pid, DR_OFFSET(1), context->debug.x86_64_regs.dr1 ) == -1) goto error; if (thread->context) thread->context->debug.x86_64_regs.dr1 = context->debug.x86_64_regs.dr1; if (ptrace( PTRACE_POKEUSER, pid, DR_OFFSET(2), context->debug.x86_64_regs.dr2 ) == -1) goto error; if (thread->context) thread->context->debug.x86_64_regs.dr2 = context->debug.x86_64_regs.dr2; if (ptrace( PTRACE_POKEUSER, pid, DR_OFFSET(3), context->debug.x86_64_regs.dr3 ) == -1) goto error; if (thread->context) thread->context->debug.x86_64_regs.dr3 = context->debug.x86_64_regs.dr3; if (ptrace( PTRACE_POKEUSER, pid, DR_OFFSET(6), context->debug.x86_64_regs.dr6 ) == -1) goto error; if (thread->context) thread->context->debug.x86_64_regs.dr6 = context->debug.x86_64_regs.dr6; if (ptrace( PTRACE_POKEUSER, pid, DR_OFFSET(7), context->debug.x86_64_regs.dr7 ) == -1) goto error; if (thread->context) thread->context->debug.x86_64_regs.dr7 = context->debug.x86_64_regs.dr7; break; default: set_error( STATUS_INVALID_PARAMETER ); } resume_after_ptrace( thread ); return; error: file_set_error(); resume_after_ptrace( thread ); }
/* retrieve the thread x86 registers */ void get_thread_context( struct thread *thread, context_t *context, unsigned int flags ) { int i, pid = get_ptrace_tid(thread); long data[8]; /* all other regs are handled on the client side */ assert( flags == SERVER_CTX_DEBUG_REGISTERS ); if (!suspend_for_ptrace( thread )) return; for (i = 0; i < 8; i++) { if (i == 4 || i == 5) continue; errno = 0; data[i] = ptrace( PTRACE_PEEKUSER, pid, DR_OFFSET(i), 0 ); if ((data[i] == -1) && errno) { file_set_error(); goto done; } } switch (context->cpu) { case CPU_x86: context->debug.i386_regs.dr0 = data[0]; context->debug.i386_regs.dr1 = data[1]; context->debug.i386_regs.dr2 = data[2]; context->debug.i386_regs.dr3 = data[3]; context->debug.i386_regs.dr6 = data[6]; context->debug.i386_regs.dr7 = data[7]; break; case CPU_x86_64: context->debug.x86_64_regs.dr0 = data[0]; context->debug.x86_64_regs.dr1 = data[1]; context->debug.x86_64_regs.dr2 = data[2]; context->debug.x86_64_regs.dr3 = data[3]; context->debug.x86_64_regs.dr6 = data[6]; context->debug.x86_64_regs.dr7 = data[7]; break; default: set_error( STATUS_INVALID_PARAMETER ); goto done; } context->flags |= SERVER_CTX_DEBUG_REGISTERS; done: resume_after_ptrace( thread ); }
/* create a temp file for anonymous mappings */ static int create_temp_file( file_pos_t size ) { char tmpfn[16]; int fd; sprintf( tmpfn, "anonmap.XXXXXX" ); /* create it in the server directory */ fd = mkstemps( tmpfn, 0 ); if (fd != -1) { if (!grow_file( fd, size )) { close( fd ); fd = -1; } unlink( tmpfn ); } else file_set_error(); return fd; }
/* extend a file beyond the current end of file */ static int grow_file( int unix_fd, file_pos_t new_size ) { static const char zero; off_t size = new_size; if (sizeof(new_size) > sizeof(size) && size != new_size) { set_error( STATUS_INVALID_PARAMETER ); return 0; } /* extend the file one byte beyond the requested size and then truncate it */ /* this should work around ftruncate implementations that can't extend files */ if (pwrite( unix_fd, &zero, 1, size ) != -1) { ftruncate( unix_fd, size ); return 1; } file_set_error(); return 0; }
/* create a temp file for anonymous mappings */ static int create_temp_file( file_pos_t size ) { static int temp_dir_fd = -1; char tmpfn[] = "anonmap.XXXXXX"; int fd; if (temp_dir_fd == -1) { temp_dir_fd = server_dir_fd; if (!check_current_dir_for_exec()) { /* the server dir is noexec, try the config dir instead */ fchdir( config_dir_fd ); if (check_current_dir_for_exec()) temp_dir_fd = config_dir_fd; else /* neither works, fall back to server dir */ fchdir( server_dir_fd ); } } else if (temp_dir_fd != server_dir_fd) fchdir( temp_dir_fd ); fd = mkstemps( tmpfn, 0 ); if (fd != -1) { if (!grow_file( fd, size )) { close( fd ); fd = -1; } unlink( tmpfn ); } else file_set_error(); if (temp_dir_fd != server_dir_fd) fchdir( server_dir_fd ); return fd; }
/* create a file by duplicating an fd object */ struct file *create_file_for_fd_obj( struct fd *fd, unsigned int access, unsigned int sharing ) { struct file *file; struct stat st; if (fstat( get_unix_fd(fd), &st ) == -1) { file_set_error(); return NULL; } if ((file = alloc_object( &file_ops ))) { file->mode = st.st_mode; file->access = default_fd_map_access( &file->obj, access ); if (!(file->fd = dup_fd_object( fd, access, sharing, FILE_SYNCHRONOUS_IO_NONALERT ))) { release_object( file ); return NULL; } set_fd_user( file->fd, &file_fd_ops, &file->obj ); } return file; }
int set_file_sd( struct object *obj, struct fd *fd, const struct security_descriptor *sd, unsigned int set_info ) { struct security_descriptor *tmp_sd = NULL; int unix_fd = get_unix_fd( fd ); const SID *owner, *group; struct stat st; mode_t mode; int ret = 1; if (unix_fd == -1 || fstat( unix_fd, &st ) == -1) return 1; if (!(set_info & PROTECTED_DACL_SECURITY_INFORMATION)) { char *child_name = fd_get_unix_name( fd ); if (child_name) { struct security_descriptor *parent_sd; parent_sd = file_get_parent_sd( NULL, child_name, strlen(child_name), S_ISDIR(st.st_mode) ); free( child_name ); if (parent_sd) { tmp_sd = file_combine_sds( parent_sd, sd ); if (tmp_sd) sd = tmp_sd; /* only used combined sd if successful */ free( parent_sd ); } } } if (set_info & OWNER_SECURITY_INFORMATION) { owner = sd_get_owner( sd ); if (!owner) { set_error( STATUS_INVALID_SECURITY_DESCR ); ret = 0; goto err; } if (!obj->sd || !security_equal_sid( owner, sd_get_owner( obj->sd ) )) { /* FIXME: get Unix uid and call fchown */ } } else if (obj->sd) owner = sd_get_owner( obj->sd ); else owner = token_get_user( current->process->token ); if (set_info & GROUP_SECURITY_INFORMATION) { group = sd_get_group( sd ); if (!group) { set_error( STATUS_INVALID_SECURITY_DESCR ); ret = 0; goto err; } if (!obj->sd || !security_equal_sid( group, sd_get_group( obj->sd ) )) { /* FIXME: get Unix uid and call fchown */ } } else if (obj->sd) group = sd_get_group( obj->sd ); else group = token_get_primary_group( current->process->token ); /* group and sacl not supported */ if (set_info & DACL_SECURITY_INFORMATION) { /* keep the bits that we don't map to access rights in the ACL */ mode = st.st_mode & (S_ISUID|S_ISGID|S_ISVTX); mode |= sd_to_mode( sd, owner ); set_xattr_sd( unix_fd, sd, owner, group ); if (((st.st_mode ^ mode) & (S_IRWXU|S_IRWXG|S_IRWXO)) && fchmod( unix_fd, mode ) == -1) { file_set_error(); ret = 0; } } err: free( tmp_sd ); return ret; }
static void file_flush( struct fd *fd, struct event **event ) { int unix_fd = get_unix_fd( fd ); if (unix_fd != -1 && fsync( unix_fd ) == -1) file_set_error(); }
/* set a thread context */ static void set_thread_context_ptrace( struct thread *thread, unsigned int flags, const CONTEXT *context ) { int pid = get_ptrace_pid(thread); if (flags & CONTEXT_FULL) { if (flags & CONTEXT_INTEGER) { IREG(0); IREG(1); IREG(2); IREG(3); IREG(4); IREG(5); IREG(6); IREG(7); IREG(8); IREG(9); IREG(10); IREG(11); IREG(12); IREG(13); IREG(14); IREG(15); IREG(16); IREG(17); IREG(18); IREG(19); IREG(20); IREG(21); IREG(22); IREG(23); IREG(24); IREG(25); IREG(26); IREG(27); IREG(28); IREG(29); IREG(30); IREG(31); XREG(37,Xer); XREG(38,Cr); } if (flags & CONTEXT_CONTROL) { XREG(32,Iar); XREG(33,Msr); XREG(35,Ctr); XREG(36,Lr); } } if (flags & CONTEXT_FLOATING_POINT) { FREG(0); FREG(1); FREG(2); FREG(3); FREG(4); FREG(5); FREG(6); FREG(7); FREG(8); FREG(9); FREG(10); FREG(11); FREG(12); FREG(13); FREG(14); FREG(15); FREG(16); FREG(17); FREG(18); FREG(19); FREG(20); FREG(21); FREG(22); FREG(23); FREG(24); FREG(25); FREG(26); FREG(27); FREG(28); FREG(29); FREG(30); FREG(31); #undef FREG XREG((48+32*2),Fpscr); } return; error: file_set_error(); }
/* retrieve a thread context */ static void get_thread_context_ptrace( struct thread *thread, unsigned int flags, CONTEXT *context ) { int pid = get_ptrace_pid(thread); if (flags & CONTEXT_INTEGER) { #define XREG(x,y) if (ptrace( PTRACE_PEEKUSER, pid, (void*)(x<<2), &context->y) == -1) goto error; #define IREG(x) if (ptrace( PTRACE_PEEKUSER, pid, (void*)(x<<2), &context->Gpr##x) == -1) goto error; IREG(0); IREG(1); IREG(2); IREG(3); IREG(4); IREG(5); IREG(6); IREG(7); IREG(8); IREG(9); IREG(10); IREG(11); IREG(12); IREG(13); IREG(14); IREG(15); IREG(16); IREG(17); IREG(18); IREG(19); IREG(20); IREG(21); IREG(22); IREG(23); IREG(24); IREG(25); IREG(26); IREG(27); IREG(28); IREG(29); IREG(30); IREG(31); #undef IREG XREG(37,Xer); XREG(38,Cr); context->ContextFlags |= CONTEXT_INTEGER; } if (flags & CONTEXT_CONTROL) { XREG(32,Iar); XREG(33,Msr); XREG(35,Ctr); XREG(36,Lr); /* 36 is LNK ... probably Lr ? */ context->ContextFlags |= CONTEXT_CONTROL; } if (flags & CONTEXT_FLOATING_POINT) { #define FREG(x) if (ptrace( PTRACE_PEEKUSER, pid, (void*)((48+x*2)<<2), &context->Fpr##x) == -1) goto error; FREG(0); FREG(1); FREG(2); FREG(3); FREG(4); FREG(5); FREG(6); FREG(7); FREG(8); FREG(9); FREG(10); FREG(11); FREG(12); FREG(13); FREG(14); FREG(15); FREG(16); FREG(17); FREG(18); FREG(19); FREG(20); FREG(21); FREG(22); FREG(23); FREG(24); FREG(25); FREG(26); FREG(27); FREG(28); FREG(29); FREG(30); FREG(31); XREG((48+32*2),Fpscr); context->ContextFlags |= CONTEXT_FLOATING_POINT; } return; error: file_set_error(); }
static obj_handle_t file_flush( struct fd *fd, const async_data_t *async, int blocking ) { int unix_fd = get_unix_fd( fd ); if (unix_fd != -1 && fsync( unix_fd ) == -1) file_set_error(); return 0; }
static struct object *create_mapping( struct object *root, const struct unicode_str *name, unsigned int attr, mem_size_t size, unsigned int flags, obj_handle_t handle, unsigned int file_access, const struct security_descriptor *sd ) { struct mapping *mapping; struct file *file; struct fd *fd; int unix_fd; struct stat st; if (!page_mask) page_mask = sysconf( _SC_PAGESIZE ) - 1; if (!(mapping = create_named_object( root, &mapping_ops, name, attr, sd ))) return NULL; if (get_error() == STATUS_OBJECT_NAME_EXISTS) return &mapping->obj; /* Nothing else to do */ mapping->size = size; mapping->fd = NULL; mapping->shared = NULL; mapping->committed = NULL; if (!(mapping->flags = get_mapping_flags( handle, flags ))) goto error; if (handle) { const unsigned int sharing = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE; unsigned int mapping_access = FILE_MAPPING_ACCESS; if (!(file = get_file_obj( current->process, handle, file_access ))) goto error; fd = get_obj_fd( (struct object *)file ); /* file sharing rules for mappings are different so we use magic the access rights */ if (flags & SEC_IMAGE) mapping_access |= FILE_MAPPING_IMAGE; else if (file_access & FILE_WRITE_DATA) mapping_access |= FILE_MAPPING_WRITE; if (!(mapping->fd = get_fd_object_for_mapping( fd, mapping_access, sharing ))) { mapping->fd = dup_fd_object( fd, mapping_access, sharing, FILE_SYNCHRONOUS_IO_NONALERT ); if (mapping->fd) set_fd_user( mapping->fd, &mapping_fd_ops, NULL ); } release_object( file ); release_object( fd ); if (!mapping->fd) goto error; if ((unix_fd = get_unix_fd( mapping->fd )) == -1) goto error; if (fstat( unix_fd, &st ) == -1) { file_set_error(); goto error; } if (flags & SEC_IMAGE) { unsigned int err = get_image_params( mapping, st.st_size, unix_fd ); if (!err) return &mapping->obj; set_error( err ); goto error; } if (!mapping->size) { if (!(mapping->size = st.st_size)) { set_error( STATUS_MAPPED_FILE_SIZE_ZERO ); goto error; } } else if (st.st_size < mapping->size) { if (!(file_access & FILE_WRITE_DATA)) { set_error( STATUS_SECTION_TOO_BIG ); goto error; } if (!grow_file( unix_fd, mapping->size )) goto error; } } else /* Anonymous mapping (no associated file) */ { if (!mapping->size) { set_error( STATUS_INVALID_PARAMETER ); goto error; } if ((flags & SEC_RESERVE) && !(mapping->committed = create_ranges())) goto error; mapping->size = (mapping->size + page_mask) & ~((mem_size_t)page_mask); if ((unix_fd = create_temp_file( mapping->size )) == -1) goto error; if (!(mapping->fd = create_anonymous_fd( &mapping_fd_ops, unix_fd, &mapping->obj, FILE_SYNCHRONOUS_IO_NONALERT ))) goto error; allow_fd_caching( mapping->fd ); } return &mapping->obj; error: release_object( mapping ); return NULL; }