2007-03-09 05:40:41 -07:00
|
|
|
/*
|
|
|
|
* Server-side /proc support for Solaris
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007 Alexandre Julliard
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "ntstatus.h"
|
|
|
|
#define WIN32_NO_STATUS
|
|
|
|
#include "winternl.h"
|
|
|
|
|
|
|
|
#include "file.h"
|
|
|
|
#include "process.h"
|
|
|
|
#include "thread.h"
|
|
|
|
|
|
|
|
#ifdef USE_PROCFS
|
|
|
|
|
2009-09-01 08:39:51 -07:00
|
|
|
/* procfs doesn't support large files */
|
|
|
|
# undef _FILE_OFFSET_BITS
|
|
|
|
# define _FILE_OFFSET_BITS 32
|
2007-03-09 05:40:41 -07:00
|
|
|
#include <procfs.h>
|
|
|
|
|
|
|
|
static int open_proc_as( struct process *process, int flags )
|
|
|
|
{
|
|
|
|
char buffer[32];
|
|
|
|
int fd;
|
|
|
|
|
2008-07-10 11:15:15 -07:00
|
|
|
if (process->unix_pid == -1)
|
|
|
|
{
|
|
|
|
set_error( STATUS_ACCESS_DENIED );
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2024-03-19 15:15:58 -07:00
|
|
|
snprintf( buffer, sizeof(buffer), "/proc/%u/as", process->unix_pid );
|
2008-07-10 11:15:15 -07:00
|
|
|
if ((fd = open( buffer, flags )) == -1)
|
|
|
|
{
|
|
|
|
if (errno == ENOENT) /* probably got killed */
|
|
|
|
{
|
|
|
|
process->unix_pid = -1;
|
|
|
|
set_error( STATUS_ACCESS_DENIED );
|
|
|
|
}
|
|
|
|
else file_set_error();
|
|
|
|
}
|
2007-03-09 05:40:41 -07:00
|
|
|
return fd;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int open_proc_lwpctl( struct thread *thread )
|
|
|
|
{
|
|
|
|
char buffer[48];
|
|
|
|
int fd;
|
|
|
|
|
2008-07-10 11:15:15 -07:00
|
|
|
if (thread->unix_pid == -1) return -1;
|
|
|
|
|
2024-03-19 15:15:58 -07:00
|
|
|
snprintf( buffer, sizeof(buffer), "/proc/%u/lwp/%u/lwpctl", thread->unix_pid, thread->unix_tid );
|
2008-07-10 11:15:15 -07:00
|
|
|
if ((fd = open( buffer, O_WRONLY )) == -1)
|
|
|
|
{
|
|
|
|
if (errno == ENOENT) /* probably got killed */
|
|
|
|
thread->unix_pid = thread->unix_tid = -1;
|
|
|
|
else
|
|
|
|
file_set_error();
|
|
|
|
}
|
2007-03-09 05:40:41 -07:00
|
|
|
return fd;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* handle a SIGCHLD signal */
|
|
|
|
void sigchld_callback(void)
|
|
|
|
{
|
|
|
|
assert( 0 ); /* should only be called when using ptrace */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* initialize the process tracing mechanism */
|
|
|
|
void init_tracing_mechanism(void)
|
|
|
|
{
|
|
|
|
/* no initialization needed */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* initialize the per-process tracing mechanism */
|
|
|
|
void init_process_tracing( struct process *process )
|
|
|
|
{
|
|
|
|
/* setup is done on-demand */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* terminate the per-process tracing mechanism */
|
|
|
|
void finish_process_tracing( struct process *process )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/* send a Unix signal to a specific thread */
|
|
|
|
int send_thread_signal( struct thread *thread, int sig )
|
|
|
|
{
|
|
|
|
int fd = open_proc_lwpctl( thread );
|
|
|
|
long kill[2];
|
|
|
|
ssize_t ret;
|
|
|
|
|
|
|
|
if (fd == -1) return 0;
|
|
|
|
|
|
|
|
kill[0] = PCKILL;
|
|
|
|
kill[1] = sig;
|
|
|
|
ret = write( fd, kill, sizeof(kill) );
|
|
|
|
close( fd );
|
|
|
|
return (ret == sizeof(kill));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* read data from a process memory space */
|
2008-12-30 06:11:58 -07:00
|
|
|
int read_process_memory( struct process *process, client_ptr_t ptr, size_t size, char *dest )
|
2007-03-09 05:40:41 -07:00
|
|
|
{
|
|
|
|
ssize_t ret;
|
2008-12-30 06:11:58 -07:00
|
|
|
int fd;
|
2007-03-09 05:40:41 -07:00
|
|
|
|
2008-12-30 06:11:58 -07:00
|
|
|
if ((off_t)ptr != ptr)
|
|
|
|
{
|
|
|
|
set_error( STATUS_ACCESS_DENIED );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((fd = open_proc_as( process, O_RDONLY )) == -1) return 0;
|
2007-03-09 05:40:41 -07:00
|
|
|
|
|
|
|
ret = pread( fd, dest, size, (off_t)ptr );
|
|
|
|
close( fd );
|
|
|
|
if (ret == size) return 1;
|
|
|
|
|
|
|
|
if (ret == -1) file_set_error();
|
|
|
|
else set_error( STATUS_ACCESS_VIOLATION );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* write data to a process memory space */
|
2008-12-30 06:11:58 -07:00
|
|
|
int write_process_memory( struct process *process, client_ptr_t ptr, size_t size, const char *src )
|
2007-03-09 05:40:41 -07:00
|
|
|
{
|
|
|
|
ssize_t ret;
|
2008-12-30 06:11:58 -07:00
|
|
|
int fd;
|
2007-03-09 05:40:41 -07:00
|
|
|
|
2008-12-30 06:11:58 -07:00
|
|
|
if ((off_t)ptr != ptr)
|
|
|
|
{
|
|
|
|
set_error( STATUS_ACCESS_DENIED );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-10-22 06:09:51 -07:00
|
|
|
if ((fd = open_proc_as( process, O_WRONLY )) == -1) return 0;
|
2007-03-09 05:40:41 -07:00
|
|
|
|
|
|
|
ret = pwrite( fd, src, size, (off_t)ptr );
|
|
|
|
close( fd );
|
|
|
|
if (ret == size) return 1;
|
|
|
|
|
|
|
|
if (ret == -1) file_set_error();
|
|
|
|
else set_error( STATUS_ACCESS_VIOLATION );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* retrieve an LDT selector entry */
|
|
|
|
void get_selector_entry( struct thread *thread, int entry, unsigned int *base,
|
|
|
|
unsigned int *limit, unsigned char *flags )
|
|
|
|
{
|
|
|
|
ssize_t ret;
|
2008-12-30 14:47:48 -07:00
|
|
|
off_t pos = thread->process->ldt_copy;
|
|
|
|
int fd;
|
2007-03-09 05:40:41 -07:00
|
|
|
|
2008-12-30 14:47:48 -07:00
|
|
|
if (!pos)
|
|
|
|
{
|
|
|
|
set_error( STATUS_ACCESS_DENIED );
|
2009-01-30 06:04:56 -07:00
|
|
|
return;
|
2008-12-30 14:47:48 -07:00
|
|
|
}
|
|
|
|
if ((fd = open_proc_as( thread->process, O_RDONLY )) == -1) return;
|
2007-03-09 05:40:41 -07:00
|
|
|
|
|
|
|
ret = pread( fd, base, sizeof(*base), pos + entry*sizeof(int) );
|
|
|
|
if (ret != sizeof(*base)) goto error;
|
|
|
|
ret = pread( fd, limit, sizeof(*limit), pos + (8192 + entry)*sizeof(int) );
|
|
|
|
if (ret != sizeof(*limit)) goto error;
|
|
|
|
ret = pread( fd, flags, sizeof(*flags), pos + 2*8192*sizeof(int) + entry );
|
|
|
|
if (ret != sizeof(*flags)) goto error;
|
|
|
|
close( fd );
|
|
|
|
return;
|
|
|
|
|
|
|
|
error:
|
|
|
|
if (ret == -1) file_set_error();
|
|
|
|
else set_error( STATUS_ACCESS_VIOLATION );
|
|
|
|
close( fd );
|
|
|
|
}
|
|
|
|
|
2017-07-27 01:50:41 -07:00
|
|
|
/* initialize registers in new thread if necessary */
|
|
|
|
void init_thread_context( struct thread *thread )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-03-09 05:40:41 -07:00
|
|
|
/* retrieve the thread registers */
|
2009-04-08 10:38:02 -07:00
|
|
|
void get_thread_context( struct thread *thread, context_t *context, unsigned int flags )
|
2007-03-09 05:40:41 -07:00
|
|
|
{
|
|
|
|
/* FIXME: get debug registers */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* set the thread registers */
|
2009-04-08 10:38:02 -07:00
|
|
|
void set_thread_context( struct thread *thread, const context_t *context, unsigned int flags )
|
2007-03-09 05:40:41 -07:00
|
|
|
{
|
|
|
|
/* FIXME: set debug registers */
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* USE_PROCFS */
|