mirror of
https://github.com/RGBCube/serenity
synced 2025-07-23 09:37:34 +00:00
Kernel: Don't disable interrupts to access the system hostname.
This commit is contained in:
parent
458706c4cf
commit
2e663eda36
3 changed files with 18 additions and 16 deletions
|
@ -33,18 +33,7 @@ static const dword default_userspace_stack_size = 65536;
|
||||||
static pid_t next_pid;
|
static pid_t next_pid;
|
||||||
InlineLinkedList<Process>* g_processes;
|
InlineLinkedList<Process>* g_processes;
|
||||||
static String* s_hostname;
|
static String* s_hostname;
|
||||||
|
static Lock* s_hostname_lock;
|
||||||
static String& hostname_storage(InterruptDisabler&)
|
|
||||||
{
|
|
||||||
ASSERT(s_hostname);
|
|
||||||
return *s_hostname;
|
|
||||||
}
|
|
||||||
|
|
||||||
static String get_hostname()
|
|
||||||
{
|
|
||||||
InterruptDisabler disabler;
|
|
||||||
return hostname_storage(disabler).isolated_copy();
|
|
||||||
}
|
|
||||||
|
|
||||||
CoolGlobals* g_cool_globals;
|
CoolGlobals* g_cool_globals;
|
||||||
|
|
||||||
|
@ -56,6 +45,7 @@ void Process::initialize()
|
||||||
next_pid = 0;
|
next_pid = 0;
|
||||||
g_processes = new InlineLinkedList<Process>;
|
g_processes = new InlineLinkedList<Process>;
|
||||||
s_hostname = new String("courage");
|
s_hostname = new String("courage");
|
||||||
|
s_hostname_lock = new Lock;
|
||||||
Scheduler::initialize();
|
Scheduler::initialize();
|
||||||
initialize_gui_statics();
|
initialize_gui_statics();
|
||||||
}
|
}
|
||||||
|
@ -216,10 +206,10 @@ int Process::sys$gethostname(char* buffer, size_t size)
|
||||||
{
|
{
|
||||||
if (!validate_write(buffer, size))
|
if (!validate_write(buffer, size))
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
auto hostname = get_hostname();
|
LOCKER(*s_hostname_lock);
|
||||||
if (size < (hostname.length() + 1))
|
if (size < (s_hostname->length() + 1))
|
||||||
return -ENAMETOOLONG;
|
return -ENAMETOOLONG;
|
||||||
memcpy(buffer, hostname.characters(), size);
|
strcpy(buffer, s_hostname->characters());
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1398,7 +1388,8 @@ int Process::sys$uname(utsname* buf)
|
||||||
strcpy(buf->release, "1.0-dev");
|
strcpy(buf->release, "1.0-dev");
|
||||||
strcpy(buf->version, "FIXME");
|
strcpy(buf->version, "FIXME");
|
||||||
strcpy(buf->machine, "i386");
|
strcpy(buf->machine, "i386");
|
||||||
strcpy(buf->nodename, get_hostname().characters());
|
LOCKER(*s_hostname_lock);
|
||||||
|
strncpy(buf->nodename, s_hostname->characters(), sizeof(utsname::nodename));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,16 @@ void strcpy(char* dest, const char *src)
|
||||||
while ((*dest++ = *src++) != '\0');
|
while ((*dest++ = *src++) != '\0');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char* strncpy(char* dest, const char* src, size_t n)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
for (i = 0; i < n && src[i] != '\0'; ++i)
|
||||||
|
dest[i] = src[i];
|
||||||
|
for ( ; i < n; ++i)
|
||||||
|
dest[i] = '\0';
|
||||||
|
return dest;
|
||||||
|
}
|
||||||
|
|
||||||
void* memset(void* dest_ptr, byte c, dword n)
|
void* memset(void* dest_ptr, byte c, dword n)
|
||||||
{
|
{
|
||||||
dword dest = (dword)dest_ptr;
|
dword dest = (dword)dest_ptr;
|
||||||
|
|
|
@ -6,6 +6,7 @@ extern "C" {
|
||||||
|
|
||||||
void memcpy(void*, const void*, dword);
|
void memcpy(void*, const void*, dword);
|
||||||
void strcpy(char*, const char*);
|
void strcpy(char*, const char*);
|
||||||
|
char* strncpy(char*, const char*, size_t);
|
||||||
int strcmp(char const*, const char*);
|
int strcmp(char const*, const char*);
|
||||||
size_t strlen(const char*);
|
size_t strlen(const char*);
|
||||||
void *memset(void*, byte, dword);
|
void *memset(void*, byte, dword);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue