mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 14:12:44 +00:00 
			
		
		
		
	 2a78bf8596
			
		
	
	
		2a78bf8596
		
	
	
	
	
		
			
			The Process::Handler type has KResultOr<FlatPtr> as its return type. Using a different return type with an equally-sized template parameter sort of works but breaks once that condition is no longer true, e.g. for KResultOr<int> on x86_64. Ideally the syscall handlers would also take FlatPtrs as their args so we can get rid of the reinterpret_cast for the function pointer but I didn't quite feel like cleaning that up as well.
		
			
				
	
	
		
			42 lines
		
	
	
	
		
			1.1 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			42 lines
		
	
	
	
		
			1.1 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| /*
 | |
|  * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
 | |
|  *
 | |
|  * SPDX-License-Identifier: BSD-2-Clause
 | |
|  */
 | |
| 
 | |
| #include <Kernel/Process.h>
 | |
| 
 | |
| namespace Kernel {
 | |
| 
 | |
| extern String* g_hostname;
 | |
| extern Lock* g_hostname_lock;
 | |
| 
 | |
| KResultOr<FlatPtr> Process::sys$gethostname(Userspace<char*> buffer, size_t size)
 | |
| {
 | |
|     REQUIRE_PROMISE(stdio);
 | |
|     if (size > NumericLimits<ssize_t>::max())
 | |
|         return EINVAL;
 | |
|     Locker locker(*g_hostname_lock, Lock::Mode::Shared);
 | |
|     if (size < (g_hostname->length() + 1))
 | |
|         return ENAMETOOLONG;
 | |
|     if (!copy_to_user(buffer, g_hostname->characters(), g_hostname->length() + 1))
 | |
|         return EFAULT;
 | |
|     return 0;
 | |
| }
 | |
| 
 | |
| KResultOr<FlatPtr> Process::sys$sethostname(Userspace<const char*> hostname, size_t length)
 | |
| {
 | |
|     REQUIRE_NO_PROMISES;
 | |
|     if (!is_superuser())
 | |
|         return EPERM;
 | |
|     Locker locker(*g_hostname_lock, Lock::Mode::Exclusive);
 | |
|     if (length > 64)
 | |
|         return ENAMETOOLONG;
 | |
|     auto copied_hostname = copy_string_from_user(hostname, length);
 | |
|     if (copied_hostname.is_null())
 | |
|         return EFAULT;
 | |
|     *g_hostname = move(copied_hostname);
 | |
|     return 0;
 | |
| }
 | |
| 
 | |
| }
 |