Replace memset with std fill

This commit is contained in:
Baptiste Wicht 2013-12-09 18:38:53 +01:00
parent ab5369b15a
commit fc1a82ab97
5 changed files with 28 additions and 18 deletions

View File

@ -12,7 +12,7 @@
namespace paging {
const int PAGE_SIZE = 4096;
constexpr const int PAGE_SIZE = 4096;
void* physical_address(void* virt);
bool page_present(void* virt);

View File

@ -10,6 +10,26 @@
#include "types.hpp"
namespace std {
template<typename ForwardIterator, typename T>
void fill(ForwardIterator it, ForwardIterator end, const T& value){
while(it != end){
*it = value;
++it;
}
}
template<typename ForwardIterator, typename T>
void fill_n(ForwardIterator it, size_t n, const T& value){
while(n--){
*it = value;
++it;
}
}
} //end of namespace std
template<typename CharT>
struct basic_string;
typedef basic_string<char> string;
@ -20,7 +40,6 @@ uint64_t parse(const string& str);
uint64_t str_len(const char* a);
void memset(void * ptr, uint8_t value, size_t num);
int memcmp(const void* s1, const void* s2, size_t n);
void memcopy(void* destination, const void* source, size_t n);

View File

@ -19,17 +19,18 @@ typedef pt_t* pdt_t;
typedef pdt_t* pdpt_t;
typedef pdpt_t* pml4t_t;
constexpr int PRESENT = 0x1;
constexpr int WRITEABLE = 0x2;
constexpr int USER = 0x4;
constexpr const int PRESENT = 0x1;
constexpr const int WRITEABLE = 0x2;
constexpr const int USER = 0x4;
//Memory from 0x70000 can be used for pages
uintptr_t last_page = 0x73000;
uintptr_t init_new_page(){
auto new_page = last_page + paging::PAGE_SIZE;
auto it = reinterpret_cast<size_t*>(new_page);
memset(reinterpret_cast<void*>(new_page), 0, paging::PAGE_SIZE);
std::fill(it, it + paging::PAGE_SIZE / sizeof(size_t), 0);
last_page = new_page;

View File

@ -25,9 +25,9 @@
namespace {
#ifdef CONFIG_HISTORY
static constexpr bool History = true;
static constexpr const bool History = true;
#else
static constexpr bool History = false;
static constexpr const bool History = false;
#endif
vector<string> history;

View File

@ -8,16 +8,6 @@
#include "utils.hpp"
#include "string.hpp"
void memset(void* ptr, unsigned char value, size_t num){
auto p = static_cast<unsigned char*>(ptr);
--p;
while(num--){
*++p = value;
}
}
int memcmp(const void* s1, const void* s2, size_t n){
auto p1 = static_cast<const unsigned char*>(s1);
auto p2 = static_cast<const unsigned char*>(s2);